1 /******************************************************************************
3 * Module Name: osunixxf - UNIX OSL interfaces
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2006, 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
;
140 ACPI_PHYSICAL_ADDRESS
141 AeLocalGetRootPointer (
145 /******************************************************************************
147 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate
153 * DESCRIPTION: Init and terminate. Nothing to do.
155 *****************************************************************************/
158 AcpiOsInitialize (void)
160 AcpiGbl_OutputFile
= stdout
;
167 AcpiOsTerminate (void)
173 /******************************************************************************
175 * FUNCTION: AcpiOsGetRootPointer
179 * RETURN: RSDP physical address
181 * DESCRIPTION: Gets the root pointer (RSDP)
183 *****************************************************************************/
185 ACPI_PHYSICAL_ADDRESS
186 AcpiOsGetRootPointer (
190 return (AeLocalGetRootPointer ());
194 /******************************************************************************
196 * FUNCTION: AcpiOsPredefinedOverride
198 * PARAMETERS: InitVal - Initial value of the predefined object
199 * NewVal - The new value for the object
201 * RETURN: Status, pointer to value. Null pointer returned if not
204 * DESCRIPTION: Allow the OS to override predefined names
206 *****************************************************************************/
209 AcpiOsPredefinedOverride (
210 const ACPI_PREDEFINED_NAMES
*InitVal
,
214 if (!InitVal
|| !NewVal
)
216 return (AE_BAD_PARAMETER
);
224 /******************************************************************************
226 * FUNCTION: AcpiOsTableOverride
228 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
229 * NewTable - Where an entire new table is returned.
231 * RETURN: Status, pointer to new table. Null pointer returned if no
232 * table is available to override
234 * DESCRIPTION: Return a different version of a table if one is available
236 *****************************************************************************/
239 AcpiOsTableOverride (
240 ACPI_TABLE_HEADER
*ExistingTable
,
241 ACPI_TABLE_HEADER
**NewTable
)
244 if (!ExistingTable
|| !NewTable
)
246 return (AE_BAD_PARAMETER
);
253 /* This code exercises the table override mechanism in the core */
255 if (ACPI_COMPARE_NAME (ExistingTable
->Signature
, ACPI_SIG_DSDT
))
257 /* override DSDT with itself */
259 *NewTable
= AcpiGbl_DbTablePtr
;
263 return AE_NO_ACPI_TABLES
;
268 /******************************************************************************
270 * FUNCTION: AcpiOsReadable
272 * PARAMETERS: Pointer - Area to be verified
273 * Length - Size of area
275 * RETURN: TRUE if readable for entire length
277 * DESCRIPTION: Verify that a pointer is valid for reading
279 *****************************************************************************/
291 /******************************************************************************
293 * FUNCTION: AcpiOsWritable
295 * PARAMETERS: Pointer - Area to be verified
296 * Length - Size of area
298 * RETURN: TRUE if writable for entire length
300 * DESCRIPTION: Verify that a pointer is valid for writing
302 *****************************************************************************/
314 /******************************************************************************
316 * FUNCTION: AcpiOsRedirectOutput
318 * PARAMETERS: Destination - An open file handle/pointer
322 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
324 *****************************************************************************/
327 AcpiOsRedirectOutput (
331 AcpiGbl_OutputFile
= Destination
;
335 /******************************************************************************
337 * FUNCTION: AcpiOsPrintf
339 * PARAMETERS: fmt, ... Standard printf format
343 * DESCRIPTION: Formatted output
345 *****************************************************************************/
347 void ACPI_INTERNAL_VAR_XFACE
355 va_start (Args
, Fmt
);
357 AcpiOsVprintf (Fmt
, Args
);
364 /******************************************************************************
366 * FUNCTION: AcpiOsVprintf
368 * PARAMETERS: fmt Standard printf format
373 * DESCRIPTION: Formatted output with argument list pointer
375 *****************************************************************************/
386 Flags
= AcpiGbl_DbOutputFlags
;
387 if (Flags
& ACPI_DB_REDIRECTABLE_OUTPUT
)
389 /* Output is directable to either a file (if open) or the console */
391 if (AcpiGbl_DebugFile
)
393 /* Output file is open, send the output there */
395 Count
= vfprintf (AcpiGbl_DebugFile
, Fmt
, Args
);
399 /* No redirection, send output to console (once only!) */
401 Flags
|= ACPI_DB_CONSOLE_OUTPUT
;
405 if (Flags
& ACPI_DB_CONSOLE_OUTPUT
)
407 Count
= vfprintf (AcpiGbl_OutputFile
, Fmt
, Args
);
414 /******************************************************************************
416 * FUNCTION: AcpiOsGetLine
418 * PARAMETERS: fmt Standard printf format
421 * RETURN: Actual bytes read
423 * DESCRIPTION: Formatted input with argument list pointer
425 *****************************************************************************/
437 scanf ("%1c", &Temp
);
438 if (!Temp
|| Temp
== '\n')
446 /* Null terminate the buffer */
450 /* Return the number of bytes in the string */
455 /******************************************************************************
457 * FUNCTION: AcpiOsMapMemory
459 * PARAMETERS: where Physical address of memory to be mapped
460 * length How much memory to map
462 * RETURN: Pointer to mapped memory. Null on error.
464 * DESCRIPTION: Map physical memory into caller's address space
466 *****************************************************************************/
470 ACPI_PHYSICAL_ADDRESS where
,
474 return (ACPI_TO_POINTER ((ACPI_NATIVE_UINT
) where
));
478 /******************************************************************************
480 * FUNCTION: AcpiOsUnmapMemory
482 * PARAMETERS: where Logical address of memory to be unmapped
483 * length How much memory to unmap
487 * DESCRIPTION: Delete a previously created mapping. Where and Length must
488 * correspond to a previous mapping exactly.
490 *****************************************************************************/
502 /******************************************************************************
504 * FUNCTION: AcpiOsAllocate
506 * PARAMETERS: Size Amount to allocate, in bytes
508 * RETURN: Pointer to the new allocation. Null on error.
510 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
512 *****************************************************************************/
521 Mem
= (void *) malloc ((size_t) size
);
527 /******************************************************************************
529 * FUNCTION: AcpiOsFree
531 * PARAMETERS: mem Pointer to previously allocated memory
535 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
537 *****************************************************************************/
549 /******************************************************************************
551 * FUNCTION: AcpiOsCreateSemaphore
553 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore
554 * OutHandle - Where a handle will be returned
558 * DESCRIPTION: Create an OS semaphore
560 *****************************************************************************/
563 AcpiOsCreateSemaphore (
566 ACPI_HANDLE
*OutHandle
)
570 *OutHandle
= (ACPI_HANDLE
) 1;
574 /******************************************************************************
576 * FUNCTION: AcpiOsDeleteSemaphore
578 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
582 * DESCRIPTION: Delete an OS semaphore
584 *****************************************************************************/
587 AcpiOsDeleteSemaphore (
593 return AE_BAD_PARAMETER
;
600 /******************************************************************************
602 * FUNCTION: AcpiOsWaitSemaphore
604 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
605 * Units - How many units to wait for
606 * Timeout - How long to wait
610 * DESCRIPTION: Wait for units
612 *****************************************************************************/
615 AcpiOsWaitSemaphore (
626 /******************************************************************************
628 * FUNCTION: AcpiOsSignalSemaphore
630 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
631 * Units - Number of units to send
635 * DESCRIPTION: Send units
637 *****************************************************************************/
640 AcpiOsSignalSemaphore (
652 ACPI_SPINLOCK
*OutHandle
)
655 return (AcpiOsCreateSemaphore (1, 1, OutHandle
));
660 ACPI_SPINLOCK Handle
)
662 AcpiOsDeleteSemaphore (Handle
);
670 AcpiOsWaitSemaphore (Handle
, 1, 0xFFFF);
677 ACPI_SPINLOCK Handle
,
678 ACPI_CPU_FLAGS Flags
)
680 AcpiOsSignalSemaphore (Handle
, 1);
684 /******************************************************************************
686 * FUNCTION: AcpiOsInstallInterruptHandler
688 * PARAMETERS: InterruptNumber Level handler should respond to.
689 * Isr Address of the ACPI interrupt handler
690 * ExceptPtr Where status is returned
692 * RETURN: Handle to the newly installed handler.
694 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
695 * OS-independent handler.
697 *****************************************************************************/
700 AcpiOsInstallInterruptHandler (
701 UINT32 InterruptNumber
,
702 ACPI_OSD_HANDLER ServiceRoutine
,
711 /******************************************************************************
713 * FUNCTION: AcpiOsRemoveInterruptHandler
715 * PARAMETERS: Handle Returned when handler was installed
719 * DESCRIPTION: Uninstalls an interrupt handler.
721 *****************************************************************************/
724 AcpiOsRemoveInterruptHandler (
725 UINT32 InterruptNumber
,
726 ACPI_OSD_HANDLER ServiceRoutine
)
733 /******************************************************************************
735 * FUNCTION: AcpiOsExecute
737 * PARAMETERS: Type - Type of execution
738 * Function - Address of the function to execute
739 * Context - Passed as a parameter to the function
743 * DESCRIPTION: Execute a new thread
745 *****************************************************************************/
749 ACPI_EXECUTE_TYPE Type
,
750 ACPI_OSD_EXEC_CALLBACK Function
,
754 // _beginthread (Function, (unsigned) 0, Context);
759 /******************************************************************************
761 * FUNCTION: AcpiOsBreakpoint
763 * PARAMETERS: Msg Message to print
767 * DESCRIPTION: Print a message and break to the debugger.
769 *****************************************************************************/
778 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Msg
);
782 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
789 /******************************************************************************
791 * FUNCTION: AcpiOsStall
793 * PARAMETERS: microseconds To sleep
795 * RETURN: Blocks until sleep is completed.
797 * DESCRIPTION: Sleep at microsecond granularity
799 *****************************************************************************/
808 usleep (microseconds
);
814 /******************************************************************************
816 * FUNCTION: AcpiOsSleep
818 * PARAMETERS: milliseconds To sleep
820 * RETURN: Blocks until sleep is completed.
822 * DESCRIPTION: Sleep at millisecond granularity
824 *****************************************************************************/
828 ACPI_INTEGER milliseconds
)
831 sleep (milliseconds
/ 1000); /* Sleep for whole seconds */
834 * Arg to usleep() must be less than 1,000,000 (1 second)
836 usleep ((milliseconds
% 1000) * 1000); /* Sleep for remaining usecs */
841 /******************************************************************************
843 * FUNCTION: AcpiOsGetTimer
847 * RETURN: Current time in 100 nanosecond units
849 * DESCRIPTION: Get the current system time
851 *****************************************************************************/
854 AcpiOsGetTimer (void)
858 gettimeofday(&time
, NULL
);
860 /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
862 return (((UINT64
) time
.tv_sec
* 10000000) + ((UINT64
) time
.tv_usec
* 10));
866 /******************************************************************************
868 * FUNCTION: AcpiOsValidateInterface
870 * PARAMETERS: Interface - Requested interface to be validated
872 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
874 * DESCRIPTION: Match an interface string to the interfaces supported by the
875 * host. Strings originate from an AML call to the _OSI method.
877 *****************************************************************************/
880 AcpiOsValidateInterface (
888 /******************************************************************************
890 * FUNCTION: AcpiOsValidateAddress
892 * PARAMETERS: SpaceId - ACPI space ID
893 * Address - Physical address
894 * Length - Address length
896 * RETURN: AE_OK if Address/Length is valid for the SpaceId. Otherwise,
897 * should return AE_AML_ILLEGAL_ADDRESS.
899 * DESCRIPTION: Validate a system address via the host OS. Used to validate
900 * the addresses accessed by AML operation regions.
902 *****************************************************************************/
905 AcpiOsValidateAddress (
907 ACPI_PHYSICAL_ADDRESS Address
,
915 /******************************************************************************
917 * FUNCTION: AcpiOsReadPciConfiguration
919 * PARAMETERS: PciId Seg/Bus/Dev
920 * Register Device Register
921 * Value Buffer where value is placed
922 * Width Number of bits
926 * DESCRIPTION: Read data from PCI configuration space
928 *****************************************************************************/
931 AcpiOsReadPciConfiguration (
942 /******************************************************************************
944 * FUNCTION: AcpiOsWritePciConfiguration
946 * PARAMETERS: PciId Seg/Bus/Dev
947 * Register Device Register
948 * Value Value to be written
949 * Width Number of bits
953 * DESCRIPTION: Write data to PCI configuration space
955 *****************************************************************************/
958 AcpiOsWritePciConfiguration (
968 /* TEMPORARY STUB FUNCTION */
979 /******************************************************************************
981 * FUNCTION: AcpiOsReadPort
983 * PARAMETERS: Address Address of I/O port/register to read
984 * Value Where value is placed
985 * Width Number of bits
987 * RETURN: Value read from port
989 * DESCRIPTION: Read data from an I/O port or register
991 *****************************************************************************/
995 ACPI_IO_ADDRESS Address
,
1011 *Value
= 0xFFFFFFFF;
1019 /******************************************************************************
1021 * FUNCTION: AcpiOsWritePort
1023 * PARAMETERS: Address Address of I/O port/register to write
1024 * Value Value to write
1025 * Width Number of bits
1029 * DESCRIPTION: Write data to an I/O port or register
1031 *****************************************************************************/
1035 ACPI_IO_ADDRESS Address
,
1044 /******************************************************************************
1046 * FUNCTION: AcpiOsReadMemory
1048 * PARAMETERS: Address Physical Memory Address to read
1049 * Value Where value is placed
1050 * Width Number of bits
1052 * RETURN: Value read from physical memory address
1054 * DESCRIPTION: Read data from a physical memory address
1056 *****************************************************************************/
1060 ACPI_PHYSICAL_ADDRESS Address
,
1074 return (AE_BAD_PARAMETER
);
1081 /******************************************************************************
1083 * FUNCTION: AcpiOsWriteMemory
1085 * PARAMETERS: Address Physical Memory Address to write
1086 * Value Value to write
1087 * Width Number of bits
1091 * DESCRIPTION: Write data to a physical memory address
1093 *****************************************************************************/
1097 ACPI_PHYSICAL_ADDRESS Address
,
1107 AcpiOsGetThreadId(void)
1113 /******************************************************************************
1115 * FUNCTION: AcpiOsSignal
1117 * PARAMETERS: Function ACPI CA signal function code
1118 * Info Pointer to function-dependent structure
1122 * DESCRIPTION: Miscellaneous functions
1124 *****************************************************************************/
1134 case ACPI_SIGNAL_FATAL
:
1137 case ACPI_SIGNAL_BREAKPOINT
:
1141 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Info
);
1145 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");