1 /******************************************************************************
3 * Module Name: osdosxf - DOS 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 link to the ACPI subsystem
119 * parser. They are called during the execution of the parser, and all
120 * map directly to Clibrary calls.
124 #pragma warning(disable:4115) /* warning C4115: named type definition in parentheses (caused by rpcasync.h> */
134 #include "acparser.h"
138 #define _COMPONENT ACPI_OS_SERVICES
139 ACPI_MODULE_NAME ("adosd")
142 extern FILE *AcpiGbl_DebugFile;
143 FILE *AcpiGbl_OutputFile = stdout;
146 AeLocalGetRootPointer (
148 ACPI_POINTER *Address);
156 /******************************************************************************
158 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate
164 * DESCRIPTION: Init and terminate. Nothing to do.
166 *****************************************************************************/
169 AcpiOsInitialize (void)
176 AcpiOsTerminate (void)
182 /******************************************************************************
184 * FUNCTION: AcpiOsGetRootPointer
186 * PARAMETERS: Flags - Logical/Physical addressing
187 * PhysicalAddress - of the RSDP
191 * DESCRIPTION: Returns the RSDP
193 *****************************************************************************/
196 AcpiOsGetRootPointer (
198 ACPI_POINTER *Address)
202 Status = AeLocalGetRootPointer (Flags, Address);
203 printf ("Root Pointer: %p\n", Address->Pointer.Logical);
208 /******************************************************************************
210 * FUNCTION: AcpiOsPredefinedOverride
212 * PARAMETERS: InitVal - Initial value of the predefined object
213 * NewVal - The new value for the object
215 * RETURN: Status, pointer to value. Null pointer returned if not
218 * DESCRIPTION: Allow the OS to override predefined names
220 *****************************************************************************/
223 AcpiOsPredefinedOverride (
224 const ACPI_PREDEFINED_NAMES *InitVal,
228 if (!InitVal || !NewVal)
230 return (AE_BAD_PARAMETER);
238 /******************************************************************************
240 * FUNCTION: AcpiOsTableOverride
242 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
243 * NewTable - Where an entire new table is returned.
245 * RETURN: Status, pointer to new table. Null pointer returned if no
246 * table is available to override
248 * DESCRIPTION: Return a different version of a table if one is available
250 *****************************************************************************/
253 AcpiOsTableOverride (
254 ACPI_TABLE_HEADER *ExistingTable,
255 ACPI_TABLE_HEADER **NewTable)
257 #ifndef ACPI_EXEC_APP
265 if (!ExistingTable || !NewTable)
267 return (AE_BAD_PARAMETER);
276 ACPI_STRNCPY (Signature, ExistingTable->Signature, ACPI_NAME_SIZE);
278 /* Correct signature for FADT is "FACP" */
280 if (ACPI_COMPARE_NAME (Signature, "FADT"))
282 ACPI_STRNCPY (Signature, ACPI_SIG_FADT, ACPI_NAME_SIZE);
285 Status = AfFindTable (Signature, &NewTablePtr, &TableLength);
290 *NewTable = (ACPI_TABLE_HEADER *) NewTablePtr;
291 AcpiOsPrintf ("[%4.4s] obtained from memory, %d bytes\n",
292 (char *) &ExistingTable->Signature, (UINT32) (*NewTable)->Length);
299 /******************************************************************************
301 * FUNCTION: AcpiOsReadable
303 * PARAMETERS: Pointer - Area to be verified
304 * Length - Size of area
306 * RETURN: TRUE if readable for entire length
308 * DESCRIPTION: Verify that a pointer is valid for reading
310 *****************************************************************************/
322 /******************************************************************************
324 * FUNCTION: AcpiOsWritable
326 * PARAMETERS: Pointer - Area to be verified
327 * Length - Size of area
329 * RETURN: TRUE if writable for entire length
331 * DESCRIPTION: Verify that a pointer is valid for writing
333 *****************************************************************************/
345 /******************************************************************************
347 * FUNCTION: AcpiOslDoFormat
349 * PARAMETERS: fmt, ... Standard printf format
353 * DESCRIPTION: Replace %X with %lX everywhere.
355 *****************************************************************************/
357 static char NewFmt[256];
364 const char *Old = Fmt;
376 if (*Fmt == 'x' || *Fmt == 'X')
378 memcpy (New, "lX", 2);
386 memcpy (New, "ld", 2);
394 memcpy (New, "lu", 2);
400 if (!ACPI_STRNCMP (Fmt, "2.2d", 4))
402 memcpy (New, "2.2ld", 5);
408 if (!ACPI_STRNCMP (Fmt, "2d", 2))
410 memcpy (New, "2ld", 3);
416 if (!ACPI_STRNCMP (Fmt, "8.8X", 4))
418 memcpy (New, "8.8lX", 5);
424 if (!ACPI_STRNCMP (Fmt, "5.5X", 4))
426 memcpy (New, "5.5lX", 5);
432 if (!ACPI_STRNCMP (Fmt, "4.4X", 4))
434 memcpy (New, "4.4lX", 5);
440 if (!ACPI_STRNCMP (Fmt, "2.2X", 4))
442 memcpy (New, "2.2lX", 5);
448 if (!ACPI_STRNCMP (Fmt, ".8X", 3))
450 memcpy (New, ".8lX", 4);
456 if (!ACPI_STRNCMP (Fmt, ".4X", 3))
458 memcpy (New, ".4lX", 4);
464 if (!ACPI_STRNCMP (Fmt, ".2X", 3))
466 memcpy (New, ".2lX", 4);
472 if (!ACPI_STRNCMP (Fmt, "2X", 2))
474 memcpy (New, "2lX", 3);
480 if (!ACPI_STRNCMP (Fmt, "02X", 2))
482 memcpy (New, "02lX", 4);
494 /******************************************************************************
496 * FUNCTION: AcpiOsRedirectOutput
498 * PARAMETERS: Destination - An open file handle/pointer
502 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
504 *****************************************************************************/
507 AcpiOsRedirectOutput (
511 AcpiGbl_OutputFile = Destination;
515 /******************************************************************************
517 * FUNCTION: AcpiOsPrintf
519 * PARAMETERS: fmt, ... Standard printf format
523 * DESCRIPTION: Formatted output
525 *****************************************************************************/
527 void ACPI_INTERNAL_VAR_XFACE
535 va_start (Args, Fmt);
537 AcpiOsVprintf (Fmt, Args);
544 /******************************************************************************
546 * FUNCTION: AcpiOsVprintf
548 * PARAMETERS: fmt Standard printf format
553 * DESCRIPTION: Formatted output with argument list pointer
555 *****************************************************************************/
566 AcpiOslDoFormat (Fmt);
568 Flags = AcpiGbl_DbOutputFlags;
569 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
571 /* Output is directable to either a file (if open) or the console */
573 if (AcpiGbl_DebugFile)
575 /* Output file is open, send the output there */
577 Count = vfprintf (AcpiGbl_DebugFile, NewFmt, Args);
581 /* No redirection, send output to console (once only!) */
583 Flags |= ACPI_DB_CONSOLE_OUTPUT;
587 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
589 Count = vfprintf (AcpiGbl_OutputFile, NewFmt, Args);
596 /******************************************************************************
598 * FUNCTION: AcpiOsGetLine
600 * PARAMETERS: fmt Standard printf format
603 * RETURN: Actual bytes read
605 * DESCRIPTION: Formatted input with argument list pointer
607 *****************************************************************************/
619 scanf ("%1c", &Temp);
620 if (!Temp || Temp == '\n')
628 /* Null terminate the buffer */
632 /* Return the number of bytes in the string */
637 /******************************************************************************
639 * FUNCTION: AcpiOsMapMemory
641 * PARAMETERS: where Physical address of memory to be mapped
642 * length How much memory to map
643 * there Logical address of mapped memory
645 * RETURN: Pointer to mapped memory. Null on error.
647 * DESCRIPTION: Map physical memory into caller's address space
649 *****************************************************************************/
653 ACPI_PHYSICAL_ADDRESS where,
663 /******************************************************************************
665 * FUNCTION: AcpiOsUnmapMemory
667 * PARAMETERS: where Logical address of memory to be unmapped
668 * length How much memory to unmap
672 * DESCRIPTION: Delete a previously created mapping. Where and Length must
673 * correspond to a previous mapping exactly.
675 *****************************************************************************/
687 /******************************************************************************
689 * FUNCTION: AcpiOsAllocate
691 * PARAMETERS: Size Amount to allocate, in bytes
693 * RETURN: Pointer to the new allocation. Null on error.
695 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
697 *****************************************************************************/
699 UINT32 TotalAllocations;
709 Mem = (void *) malloc ((size_t) size);
712 ACPI_ERROR ((AE_INFO,
713 "Could not allocate memory of size %X\n (total allocations/size, %X/%X)",
714 (UINT32) size, TotalAllocations, TotalSize));
723 /******************************************************************************
725 * FUNCTION: AcpiOsFree
727 * PARAMETERS: mem Pointer to previously allocated memory
731 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
733 *****************************************************************************/
745 /******************************************************************************
747 * FUNCTION: AcpiOsCreateSemaphore
749 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore
750 * OutHandle - Where a handle will be returned
754 * DESCRIPTION: Create an OS semaphore
756 *****************************************************************************/
759 AcpiOsCreateSemaphore (
762 ACPI_HANDLE *OutHandle)
767 Sem = AcpiOsAllocate (sizeof (DOS_SEMAPHORE));
770 return (AE_NO_MEMORY);
773 Sem->Units = InitialUnits;
778 /******************************************************************************
780 * FUNCTION: AcpiOsDeleteSemaphore
782 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
786 * DESCRIPTION: Delete an OS semaphore
788 *****************************************************************************/
791 AcpiOsDeleteSemaphore (
797 return AE_BAD_PARAMETER;
805 /******************************************************************************
807 * FUNCTION: AcpiOsWaitSemaphore
809 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
810 * Units - How many units to wait for
811 * Timeout - How long to wait
815 * DESCRIPTION: Wait for units
817 *****************************************************************************/
820 AcpiOsWaitSemaphore (
829 return AE_BAD_PARAMETER;
844 /******************************************************************************
846 * FUNCTION: AcpiOsSignalSemaphore
848 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
849 * Units - Number of units to send
853 * DESCRIPTION: Send units
855 *****************************************************************************/
858 AcpiOsSignalSemaphore (
866 return AE_BAD_PARAMETER;
877 ACPI_SPINLOCK *OutHandle);
880 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
885 ACPI_SPINLOCK Handle)
887 AcpiOsDeleteSemaphore (Handle);
893 ACPI_SPINLOCK Handle)
895 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
902 ACPI_SPINLOCK Handle,
903 ACPI_CPU_FLAGS Flags)
905 AcpiOsSignalSemaphore (Handle, 1);
909 /******************************************************************************
911 * FUNCTION: AcpiOsInstallInterruptHandler
913 * PARAMETERS: InterruptNumber Level handler should respond to.
914 * Isr Address of the ACPI interrupt handler
915 * ExceptPtr Where status is returned
917 * RETURN: Handle to the newly installed handler.
919 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
920 * OS-independent handler.
922 *****************************************************************************/
925 AcpiOsInstallInterruptHandler (
926 UINT32 InterruptNumber,
927 ACPI_OSD_HANDLER ServiceRoutine,
936 /******************************************************************************
938 * FUNCTION: AcpiOsRemoveInterruptHandler
940 * PARAMETERS: Handle Returned when handler was installed
944 * DESCRIPTION: Uninstalls an interrupt handler.
946 *****************************************************************************/
949 AcpiOsRemoveInterruptHandler (
950 UINT32 InterruptNumber,
951 ACPI_OSD_HANDLER ServiceRoutine)
958 /******************************************************************************
960 * FUNCTION: AcpiOsGetThreadId
964 * RETURN: Id of the running thread
966 * DESCRIPTION: Get the Id of the current (running) thread
968 *****************************************************************************/
975 /* Only one thread! */
982 /******************************************************************************
984 * FUNCTION: AcpiOsExecute
986 * PARAMETERS: Type - Type of execution
987 * Function - Address of the function to execute
988 * Context - Passed as a parameter to the function
992 * DESCRIPTION: Execute a new thread
994 *****************************************************************************/
998 ACPI_EXECUTE_TYPE Type,
999 ACPI_OSD_EXEC_CALLBACK Function,
1007 /******************************************************************************
1009 * FUNCTION: AcpiOsBreakpoint
1011 * PARAMETERS: Msg Message to print
1015 * DESCRIPTION: Print a message and break to the debugger.
1017 *****************************************************************************/
1024 /* Print the message and do an INT 3 */
1028 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Msg);
1032 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
1040 /******************************************************************************
1042 * FUNCTION: AcpiOsStall
1044 * PARAMETERS: microseconds To sleep
1046 * RETURN: Blocks until sleep is completed.
1048 * DESCRIPTION: Sleep at microsecond granularity
1050 *****************************************************************************/
1054 UINT32 microseconds)
1061 /******************************************************************************
1063 * FUNCTION: AcpiOsSleep
1065 * PARAMETERS: milliseconds To sleep
1067 * RETURN: Blocks until sleep is completed.
1069 * DESCRIPTION: Sleep at millisecond granularity
1071 *****************************************************************************/
1075 ACPI_INTEGER milliseconds)
1082 /******************************************************************************
1084 * FUNCTION: AcpiOsGetTimer
1088 * RETURN: Current time in 100 nanosecond units
1090 * DESCRIPTION: Get the current system time
1092 *****************************************************************************/
1095 AcpiOsGetTimer (void)
1105 /******************************************************************************
1107 * FUNCTION: AcpiOsValidateInterface
1109 * PARAMETERS: Interface - Requested interface to be validated
1111 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1113 * DESCRIPTION: Match an interface string to the interfaces supported by the
1114 * host. Strings originate from an AML call to the _OSI method.
1116 *****************************************************************************/
1119 AcpiOsValidateInterface (
1123 return (AE_SUPPORT);
1127 /******************************************************************************
1129 * FUNCTION: AcpiOsValidateAddress
1131 * PARAMETERS: SpaceId - ACPI space ID
1132 * Address - Physical address
1133 * Length - Address length
1135 * RETURN: AE_OK if Address/Length is valid for the SpaceId. Otherwise,
1136 * should return AE_AML_ILLEGAL_ADDRESS.
1138 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1139 * the addresses accessed by AML operation regions.
1141 *****************************************************************************/
1144 AcpiOsValidateAddress (
1146 ACPI_PHYSICAL_ADDRESS Address,
1154 /******************************************************************************
1156 * FUNCTION: AcpiOsReadPciConfiguration
1158 * PARAMETERS: PciId Seg/Bus/Dev
1159 * Register Device Register
1160 * Value Buffer where value is placed
1161 * Width Number of bits
1165 * DESCRIPTION: Read data from PCI configuration space
1167 *****************************************************************************/
1170 AcpiOsReadPciConfiguration (
1181 /******************************************************************************
1183 * FUNCTION: AcpiOsWritePciConfiguration
1185 * PARAMETERS: PciId Seg/Bus/Dev
1186 * Register Device Register
1187 * Value Value to be written
1188 * Width Number of bits
1192 * DESCRIPTION: Write data to PCI configuration space
1194 *****************************************************************************/
1197 AcpiOsWritePciConfiguration (
1207 /* TEMPORARY STUB FUNCTION */
1210 ACPI_HANDLE rhandle,
1211 ACPI_HANDLE chandle,
1212 ACPI_PCI_ID **PciId)
1218 /******************************************************************************
1220 * FUNCTION: AcpiOsReadPort
1222 * PARAMETERS: Address Address of I/O port/register to read
1223 * Value Where value is placed
1224 * Width Number of bits
1226 * RETURN: Value read from port
1228 * DESCRIPTION: Read data from an I/O port or register
1230 *****************************************************************************/
1234 ACPI_IO_ADDRESS Address,
1250 *Value = 0xFFFFFFFF;
1258 /******************************************************************************
1260 * FUNCTION: AcpiOsWritePort
1262 * PARAMETERS: Address Address of I/O port/register to write
1263 * Value Value to write
1264 * Width Number of bits
1268 * DESCRIPTION: Write data to an I/O port or register
1270 *****************************************************************************/
1274 ACPI_IO_ADDRESS Address,
1283 /******************************************************************************
1285 * FUNCTION: AcpiOsReadMemory
1287 * PARAMETERS: Address Physical Memory Address to read
1288 * Value Where value is placed
1289 * Width Number of bits
1291 * RETURN: Value read from physical memory address
1293 * DESCRIPTION: Read data from a physical memory address
1295 *****************************************************************************/
1299 ACPI_PHYSICAL_ADDRESS Address,
1313 return (AE_BAD_PARAMETER);
1321 /******************************************************************************
1323 * FUNCTION: AcpiOsWriteMemory
1325 * PARAMETERS: Address Physical Memory Address to write
1326 * Value Value to write
1327 * Width Number of bits
1331 * DESCRIPTION: Write data to a physical memory address
1333 *****************************************************************************/
1337 ACPI_PHYSICAL_ADDRESS Address,
1346 /******************************************************************************
1348 * FUNCTION: AcpiOsSignal
1350 * PARAMETERS: Function ACPI CA signal function code
1351 * Info Pointer to function-dependent structure
1355 * DESCRIPTION: Miscellaneous functions
1357 *****************************************************************************/