1 /******************************************************************************
3 * Module Name: osunixxf - UNIX OSL interfaces
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
118 * These interfaces are required in order to compile the ASL compiler under
126 #include <sys/time.h>
130 #include "acparser.h"
133 #define _COMPONENT ACPI_OS_SERVICES
134 ACPI_MODULE_NAME ("osunixxf")
137 extern FILE *AcpiGbl_DebugFile;
138 FILE *AcpiGbl_OutputFile;
141 /******************************************************************************
143 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate
149 * DESCRIPTION: Init and terminate. Nothing to do.
151 *****************************************************************************/
154 AcpiOsInitialize (void)
156 AcpiGbl_OutputFile = stdout;
163 AcpiOsTerminate (void)
169 /******************************************************************************
171 * FUNCTION: AcpiOsGetRootPointer
173 * PARAMETERS: Flags - Logical or physical addressing mode
174 * Address - Where the address is returned
178 * DESCRIPTION: Gets the root pointer (RSDP)
180 *****************************************************************************/
183 AcpiOsGetRootPointer (
185 ACPI_POINTER *Address)
189 /* The supporting code for this is not yet available.
190 * Return to the old situation for now.
192 return (AeLocalGetRootPointer(Flags, Address));
200 /******************************************************************************
202 * FUNCTION: AcpiOsPredefinedOverride
204 * PARAMETERS: InitVal - Initial value of the predefined object
205 * NewVal - The new value for the object
207 * RETURN: Status, pointer to value. Null pointer returned if not
210 * DESCRIPTION: Allow the OS to override predefined names
212 *****************************************************************************/
215 AcpiOsPredefinedOverride (
216 const ACPI_PREDEFINED_NAMES *InitVal,
220 if (!InitVal || !NewVal)
222 return (AE_BAD_PARAMETER);
230 /******************************************************************************
232 * FUNCTION: AcpiOsTableOverride
234 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
235 * NewTable - Where an entire new table is returned.
237 * RETURN: Status, pointer to new table. Null pointer returned if no
238 * table is available to override
240 * DESCRIPTION: Return a different version of a table if one is available
242 *****************************************************************************/
245 AcpiOsTableOverride (
246 ACPI_TABLE_HEADER *ExistingTable,
247 ACPI_TABLE_HEADER **NewTable)
250 if (!ExistingTable || !NewTable)
252 return (AE_BAD_PARAMETER);
257 #ifdef _ACPI_EXEC_APP
259 /* This code exercises the table override mechanism in the core */
261 if (!ACPI_STRNCMP (ExistingTable->Signature, DSDT_SIG, ACPI_NAME_SIZE))
263 /* override DSDT with itself */
265 *NewTable = AcpiGbl_DbTablePtr;
269 return AE_NO_ACPI_TABLES;
274 /******************************************************************************
276 * FUNCTION: AcpiOsReadable
278 * PARAMETERS: Pointer - Area to be verified
279 * Length - Size of area
281 * RETURN: TRUE if readable for entire length
283 * DESCRIPTION: Verify that a pointer is valid for reading
285 *****************************************************************************/
297 /******************************************************************************
299 * FUNCTION: AcpiOsWritable
301 * PARAMETERS: Pointer - Area to be verified
302 * Length - Size of area
304 * RETURN: TRUE if writable for entire length
306 * DESCRIPTION: Verify that a pointer is valid for writing
308 *****************************************************************************/
320 /******************************************************************************
322 * FUNCTION: AcpiOsRedirectOutput
324 * PARAMETERS: Destination - An open file handle/pointer
328 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
330 *****************************************************************************/
333 AcpiOsRedirectOutput (
337 AcpiGbl_OutputFile = Destination;
341 /******************************************************************************
343 * FUNCTION: AcpiOsPrintf
345 * PARAMETERS: fmt, ... Standard printf format
349 * DESCRIPTION: Formatted output
351 *****************************************************************************/
353 void ACPI_INTERNAL_VAR_XFACE
361 va_start (Args, Fmt);
363 AcpiOsVprintf (Fmt, Args);
370 /******************************************************************************
372 * FUNCTION: AcpiOsVprintf
374 * PARAMETERS: fmt Standard printf format
379 * DESCRIPTION: Formatted output with argument list pointer
381 *****************************************************************************/
392 Flags = AcpiGbl_DbOutputFlags;
393 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
395 /* Output is directable to either a file (if open) or the console */
397 if (AcpiGbl_DebugFile)
399 /* Output file is open, send the output there */
401 Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
405 /* No redirection, send output to console (once only!) */
407 Flags |= ACPI_DB_CONSOLE_OUTPUT;
411 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
413 Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
420 /******************************************************************************
422 * FUNCTION: AcpiOsGetLine
424 * PARAMETERS: fmt Standard printf format
427 * RETURN: Actual bytes read
429 * DESCRIPTION: Formatted input with argument list pointer
431 *****************************************************************************/
443 scanf ("%1c", &Temp);
444 if (!Temp || Temp == '\n')
452 /* Null terminate the buffer */
456 /* Return the number of bytes in the string */
461 /******************************************************************************
463 * FUNCTION: AcpiOsMapMemory
465 * PARAMETERS: where Physical address of memory to be mapped
466 * length How much memory to map
467 * there Logical address of mapped memory
469 * RETURN: Pointer to mapped memory. Null on error.
471 * DESCRIPTION: Map physical memory into caller's address space
473 *****************************************************************************/
477 ACPI_PHYSICAL_ADDRESS where,
481 *there = ACPI_TO_POINTER (where);
487 /******************************************************************************
489 * FUNCTION: AcpiOsUnmapMemory
491 * PARAMETERS: where Logical address of memory to be unmapped
492 * length How much memory to unmap
496 * DESCRIPTION: Delete a previously created mapping. Where and Length must
497 * correspond to a previous mapping exactly.
499 *****************************************************************************/
511 /******************************************************************************
513 * FUNCTION: AcpiOsAllocate
515 * PARAMETERS: Size Amount to allocate, in bytes
517 * RETURN: Pointer to the new allocation. Null on error.
519 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
521 *****************************************************************************/
530 Mem = (void *) malloc ((size_t) size);
536 /******************************************************************************
538 * FUNCTION: AcpiOsFree
540 * PARAMETERS: mem Pointer to previously allocated memory
544 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
546 *****************************************************************************/
558 /******************************************************************************
560 * FUNCTION: AcpiOsCreateSemaphore
562 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore
563 * OutHandle - Where a handle will be returned
567 * DESCRIPTION: Create an OS semaphore
569 *****************************************************************************/
572 AcpiOsCreateSemaphore (
575 ACPI_HANDLE *OutHandle)
579 *OutHandle = (ACPI_HANDLE) 1;
583 /******************************************************************************
585 * FUNCTION: AcpiOsDeleteSemaphore
587 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
591 * DESCRIPTION: Delete an OS semaphore
593 *****************************************************************************/
596 AcpiOsDeleteSemaphore (
602 return AE_BAD_PARAMETER;
609 /******************************************************************************
611 * FUNCTION: AcpiOsWaitSemaphore
613 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
614 * Units - How many units to wait for
615 * Timeout - How long to wait
619 * DESCRIPTION: Wait for units
621 *****************************************************************************/
624 AcpiOsWaitSemaphore (
635 /******************************************************************************
637 * FUNCTION: AcpiOsSignalSemaphore
639 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
640 * Units - Number of units to send
644 * DESCRIPTION: Send units
646 *****************************************************************************/
649 AcpiOsSignalSemaphore (
661 ACPI_HANDLE *OutHandle)
664 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
671 AcpiOsDeleteSemaphore (Handle);
680 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
689 AcpiOsSignalSemaphore (Handle, 1);
693 /******************************************************************************
695 * FUNCTION: AcpiOsInstallInterruptHandler
697 * PARAMETERS: InterruptNumber Level handler should respond to.
698 * Isr Address of the ACPI interrupt handler
699 * ExceptPtr Where status is returned
701 * RETURN: Handle to the newly installed handler.
703 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
704 * OS-independent handler.
706 *****************************************************************************/
709 AcpiOsInstallInterruptHandler (
710 UINT32 InterruptNumber,
711 ACPI_OSD_HANDLER ServiceRoutine,
720 /******************************************************************************
722 * FUNCTION: AcpiOsRemoveInterruptHandler
724 * PARAMETERS: Handle Returned when handler was installed
728 * DESCRIPTION: Uninstalls an interrupt handler.
730 *****************************************************************************/
733 AcpiOsRemoveInterruptHandler (
734 UINT32 InterruptNumber,
735 ACPI_OSD_HANDLER ServiceRoutine)
742 /******************************************************************************
744 * FUNCTION: AcpiOsQueueForExecution
746 * PARAMETERS: Priority - Requested execution priority
747 * Function - Address of the function to execute
748 * Context - Passed as a parameter to the function
752 * DESCRIPTION: Sleep at microsecond granularity
754 *****************************************************************************/
757 AcpiOsQueueForExecution (
759 ACPI_OSD_EXEC_CALLBACK Function,
763 // _beginthread (Function, (unsigned) 0, Context);
768 /******************************************************************************
770 * FUNCTION: AcpiOsBreakpoint
772 * PARAMETERS: Msg Message to print
776 * DESCRIPTION: Print a message and break to the debugger.
778 *****************************************************************************/
785 /* Print the message and do an INT 3 */
789 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Msg);
793 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
801 /******************************************************************************
803 * FUNCTION: AcpiOsStall
805 * PARAMETERS: microseconds To sleep
807 * RETURN: Blocks until sleep is completed.
809 * DESCRIPTION: Sleep at microsecond granularity
811 *****************************************************************************/
820 usleep (microseconds);
826 /******************************************************************************
828 * FUNCTION: AcpiOsSleep
830 * PARAMETERS: milliseconds To sleep
832 * RETURN: Blocks until sleep is completed.
834 * DESCRIPTION: Sleep at millisecond granularity
836 *****************************************************************************/
840 ACPI_INTEGER milliseconds)
843 sleep (milliseconds / 1000); /* Sleep for whole seconds */
846 * Arg to usleep() must be less than 1,000,000 (1 second)
848 usleep ((milliseconds % 1000) * 1000); /* Sleep for remaining usecs */
853 /******************************************************************************
855 * FUNCTION: AcpiOsGetTimer
859 * RETURN: Current time in 100 nanosecond units
861 * DESCRIPTION: Get the current system time
863 *****************************************************************************/
866 AcpiOsGetTimer (void)
870 gettimeofday(&time, NULL);
872 /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
874 return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10));
878 /******************************************************************************
880 * FUNCTION: AcpiOsReadPciConfiguration
882 * PARAMETERS: PciId Seg/Bus/Dev
883 * Register Device Register
884 * Value Buffer where value is placed
885 * Width Number of bits
889 * DESCRIPTION: Read data from PCI configuration space
891 *****************************************************************************/
894 AcpiOsReadPciConfiguration (
905 /******************************************************************************
907 * FUNCTION: AcpiOsWritePciConfiguration
909 * PARAMETERS: PciId Seg/Bus/Dev
910 * Register Device Register
911 * Value Value to be written
912 * Width Number of bits
916 * DESCRIPTION: Write data to PCI configuration space
918 *****************************************************************************/
921 AcpiOsWritePciConfiguration (
931 /* TEMPORARY STUB FUNCTION */
942 /******************************************************************************
944 * FUNCTION: AcpiOsReadPort
946 * PARAMETERS: Address Address of I/O port/register to read
947 * Value Where value is placed
948 * Width Number of bits
950 * RETURN: Value read from port
952 * DESCRIPTION: Read data from an I/O port or register
954 *****************************************************************************/
958 ACPI_IO_ADDRESS Address,
982 /******************************************************************************
984 * FUNCTION: AcpiOsWritePort
986 * PARAMETERS: Address Address of I/O port/register to write
987 * Value Value to write
988 * Width Number of bits
992 * DESCRIPTION: Write data to an I/O port or register
994 *****************************************************************************/
998 ACPI_IO_ADDRESS Address,
1007 /******************************************************************************
1009 * FUNCTION: AcpiOsReadMemory
1011 * PARAMETERS: Address Physical Memory Address to read
1012 * Value Where value is placed
1013 * Width Number of bits
1015 * RETURN: Value read from physical memory address
1017 * DESCRIPTION: Read data from a physical memory address
1019 *****************************************************************************/
1023 ACPI_PHYSICAL_ADDRESS Address,
1037 return (AE_BAD_PARAMETER);
1044 /******************************************************************************
1046 * FUNCTION: AcpiOsWriteMemory
1048 * PARAMETERS: Address Physical Memory Address to write
1049 * Value Value to write
1050 * Width Number of bits
1054 * DESCRIPTION: Write data to a physical memory address
1056 *****************************************************************************/
1060 ACPI_PHYSICAL_ADDRESS Address,
1070 AcpiOsGetThreadId(void)
1076 /******************************************************************************
1078 * FUNCTION: AcpiOsSignal
1080 * PARAMETERS: Function ACPI CA signal function code
1081 * Info Pointer to function-dependent structure
1085 * DESCRIPTION: Miscellaneous functions
1087 *****************************************************************************/
1097 case ACPI_SIGNAL_FATAL:
1100 case ACPI_SIGNAL_BREAKPOINT:
1104 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Info);
1108 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");