1 /******************************************************************************
3 * Module Name: oswinxf - Windows OSL
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, 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 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
153 #include "accommon.h"
156 #pragma warning(disable:4115) /* warning C4115: named type definition in parentheses (caused by rpcasync.h> */
162 #include <windowsx.h>
171 #define _COMPONENT ACPI_OS_SERVICES
172 ACPI_MODULE_NAME ("oswinxf")
175 UINT64 TimerFrequency;
176 char TableName[ACPI_NAMESEG_SIZE + 1];
178 #define ACPI_OS_DEBUG_TIMEOUT 30000 /* 30 seconds */
181 /* Upcalls to AcpiExec application */
185 ACPI_TABLE_HEADER *ExistingTable,
186 ACPI_TABLE_HEADER **NewTable);
189 * Real semaphores are only used for a multi-threaded application
191 #ifndef ACPI_SINGLE_THREADED
193 /* Semaphore information structure */
195 typedef struct acpi_os_semaphore_info
201 } ACPI_OS_SEMAPHORE_INFO;
203 /* Need enough semaphores to run the large aslts suite */
205 #define ACPI_OS_MAX_SEMAPHORES 256
207 ACPI_OS_SEMAPHORE_INFO AcpiGbl_Semaphores[ACPI_OS_MAX_SEMAPHORES];
209 #endif /* ACPI_SINGLE_THREADED */
211 /******************************************************************************
213 * FUNCTION: AcpiOsTerminate
219 * DESCRIPTION: Nothing to do for windows
221 *****************************************************************************/
231 /******************************************************************************
233 * FUNCTION: AcpiOsInitialize
239 * DESCRIPTION: Init this OSL
241 *****************************************************************************/
248 LARGE_INTEGER LocalTimerFrequency;
251 #ifndef ACPI_SINGLE_THREADED
252 /* Clear the semaphore info array */
254 memset (AcpiGbl_Semaphores, 0x00, sizeof (AcpiGbl_Semaphores));
257 AcpiGbl_OutputFile = stdout;
259 /* Get the timer frequency for use in AcpiOsGetTimer */
262 if (QueryPerformanceFrequency (&LocalTimerFrequency))
264 /* Frequency is in ticks per second */
266 TimerFrequency = LocalTimerFrequency.QuadPart;
269 Status = AcpiOsCreateLock (&AcpiGbl_PrintLock);
270 if (ACPI_FAILURE (Status))
279 #ifndef ACPI_USE_NATIVE_RSDP_POINTER
280 /******************************************************************************
282 * FUNCTION: AcpiOsGetRootPointer
286 * RETURN: RSDP physical address
288 * DESCRIPTION: Gets the root pointer (RSDP)
290 *****************************************************************************/
292 ACPI_PHYSICAL_ADDRESS
293 AcpiOsGetRootPointer (
302 /******************************************************************************
304 * FUNCTION: AcpiOsPredefinedOverride
306 * PARAMETERS: InitVal - Initial value of the predefined object
307 * NewVal - The new value for the object
309 * RETURN: Status, pointer to value. Null pointer returned if not
312 * DESCRIPTION: Allow the OS to override predefined names
314 *****************************************************************************/
317 AcpiOsPredefinedOverride (
318 const ACPI_PREDEFINED_NAMES *InitVal,
322 if (!InitVal || !NewVal)
324 return (AE_BAD_PARAMETER);
332 /******************************************************************************
334 * FUNCTION: AcpiOsTableOverride
336 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
337 * NewTable - Where an entire new table is returned.
339 * RETURN: Status, pointer to new table. Null pointer returned if no
340 * table is available to override
342 * DESCRIPTION: Return a different version of a table if one is available
344 *****************************************************************************/
347 AcpiOsTableOverride (
348 ACPI_TABLE_HEADER *ExistingTable,
349 ACPI_TABLE_HEADER **NewTable)
352 if (!ExistingTable || !NewTable)
354 return (AE_BAD_PARAMETER);
362 /* Call back up to AcpiExec */
364 AeTableOverride (ExistingTable, NewTable);
371 /******************************************************************************
373 * FUNCTION: AcpiOsPhysicalTableOverride
375 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
376 * NewAddress - Where new table address is returned
378 * NewTableLength - Where new table length is returned
380 * RETURN: Status, address/length of new table. Null pointer returned
381 * if no table is available to override.
383 * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
385 *****************************************************************************/
388 AcpiOsPhysicalTableOverride (
389 ACPI_TABLE_HEADER *ExistingTable,
390 ACPI_PHYSICAL_ADDRESS *NewAddress,
391 UINT32 *NewTableLength)
398 /******************************************************************************
400 * FUNCTION: AcpiOsEnterSleep
402 * PARAMETERS: SleepState - Which sleep state to enter
403 * RegaValue - Register A value
404 * RegbValue - Register B value
408 * DESCRIPTION: A hook before writing sleep registers to enter the sleep
409 * state. Return AE_CTRL_SKIP to skip further sleep register
412 *****************************************************************************/
425 /******************************************************************************
427 * FUNCTION: AcpiOsGetTimer
431 * RETURN: Current ticks in 100-nanosecond units
433 * DESCRIPTION: Get the value of a system timer
435 ******************************************************************************/
444 /* Attempt to use hi-granularity timer first */
446 if (TimerFrequency &&
447 QueryPerformanceCounter (&Timer))
449 /* Convert to 100 nanosecond ticks */
451 return ((UINT64) ((Timer.QuadPart * (UINT64) ACPI_100NSEC_PER_SEC) /
455 /* Fall back to the lo-granularity timer */
459 /* Convert milliseconds to 100 nanosecond ticks */
461 return ((UINT64) GetTickCount() * ACPI_100NSEC_PER_MSEC);
466 /******************************************************************************
468 * FUNCTION: AcpiOsReadable
470 * PARAMETERS: Pointer - Area to be verified
471 * Length - Size of area
473 * RETURN: TRUE if readable for entire length
475 * DESCRIPTION: Verify that a pointer is valid for reading
477 *****************************************************************************/
485 return ((BOOLEAN) !IsBadReadPtr (Pointer, Length));
489 /******************************************************************************
491 * FUNCTION: AcpiOsWritable
493 * PARAMETERS: Pointer - Area to be verified
494 * Length - Size of area
496 * RETURN: TRUE if writable for entire length
498 * DESCRIPTION: Verify that a pointer is valid for writing
500 *****************************************************************************/
508 return ((BOOLEAN) !IsBadWritePtr (Pointer, Length));
512 /******************************************************************************
514 * FUNCTION: AcpiOsRedirectOutput
516 * PARAMETERS: Destination - An open file handle/pointer
520 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
522 *****************************************************************************/
525 AcpiOsRedirectOutput (
529 AcpiGbl_OutputFile = Destination;
533 /******************************************************************************
535 * FUNCTION: AcpiOsPrintf
537 * PARAMETERS: Fmt, ... - Standard printf format
541 * DESCRIPTION: Formatted output
543 *****************************************************************************/
545 void ACPI_INTERNAL_VAR_XFACE
554 Flags = AcpiGbl_DbOutputFlags;
555 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
557 /* Output is directable to either a file (if open) or the console */
559 if (AcpiGbl_DebugFile)
561 /* Output file is open, send the output there */
563 va_start (Args, Fmt);
564 vfprintf (AcpiGbl_DebugFile, Fmt, Args);
569 /* No redirection, send output to console (once only!) */
571 Flags |= ACPI_DB_CONSOLE_OUTPUT;
575 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
577 va_start (Args, Fmt);
578 vfprintf (AcpiGbl_OutputFile, Fmt, Args);
586 /******************************************************************************
588 * FUNCTION: AcpiOsVprintf
590 * PARAMETERS: Fmt - Standard printf format
591 * Args - Argument list
595 * DESCRIPTION: Formatted output with argument list pointer
597 *****************************************************************************/
608 Flags = AcpiGbl_DbOutputFlags;
609 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
611 /* Output is directable to either a file (if open) or the console */
613 if (AcpiGbl_DebugFile)
615 /* Output file is open, send the output there */
617 Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
621 /* No redirection, send output to console (once only!) */
623 Flags |= ACPI_DB_CONSOLE_OUTPUT;
627 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
629 Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
636 /******************************************************************************
638 * FUNCTION: AcpiOsGetLine
640 * PARAMETERS: Buffer - Where to return the command line
641 * BufferLength - Maximum length of Buffer
642 * BytesRead - Where the actual byte count is returned
644 * RETURN: Status and actual bytes read
646 * DESCRIPTION: Formatted input with argument list pointer
648 *****************************************************************************/
662 if (i >= BufferLength)
664 return (AE_BUFFER_OVERFLOW);
667 if ((Temp = getchar ()) == EOF)
672 if (!Temp || Temp == '\n')
677 Buffer [i] = (char) Temp;
680 /* Null terminate the buffer */
684 /* Return the number of bytes in the string */
695 #ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
696 /******************************************************************************
698 * FUNCTION: AcpiOsMapMemory
700 * PARAMETERS: Where - Physical address of memory to be mapped
701 * Length - How much memory to map
703 * RETURN: Pointer to mapped memory. Null on error.
705 * DESCRIPTION: Map physical memory into caller's address space
707 *****************************************************************************/
711 ACPI_PHYSICAL_ADDRESS Where,
715 return (ACPI_TO_POINTER ((ACPI_SIZE) Where));
719 /******************************************************************************
721 * FUNCTION: AcpiOsUnmapMemory
723 * PARAMETERS: Where - Logical address of memory to be unmapped
724 * Length - How much memory to unmap
728 * DESCRIPTION: Delete a previously created mapping. Where and Length must
729 * correspond to a previous mapping exactly.
731 *****************************************************************************/
744 /******************************************************************************
746 * FUNCTION: AcpiOsAllocate
748 * PARAMETERS: Size - Amount to allocate, in bytes
750 * RETURN: Pointer to the new allocation. Null on error.
752 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
754 *****************************************************************************/
763 Mem = (void *) malloc ((size_t) Size);
768 #ifdef USE_NATIVE_ALLOCATE_ZEROED
769 /******************************************************************************
771 * FUNCTION: AcpiOsAllocateZeroed
773 * PARAMETERS: Size - Amount to allocate, in bytes
775 * RETURN: Pointer to the new allocation. Null on error.
777 * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
779 *****************************************************************************/
782 AcpiOsAllocateZeroed (
788 Mem = (void *) calloc (1, (size_t) Size);
794 /******************************************************************************
796 * FUNCTION: AcpiOsFree
798 * PARAMETERS: Mem - Pointer to previously allocated memory
802 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
804 *****************************************************************************/
815 #ifdef ACPI_SINGLE_THREADED
816 /******************************************************************************
818 * FUNCTION: Semaphore stub functions
820 * DESCRIPTION: Stub functions used for single-thread applications that do
821 * not require semaphore synchronization. Full implementations
822 * of these functions appear after the stubs.
824 *****************************************************************************/
827 AcpiOsCreateSemaphore (
830 ACPI_HANDLE *OutHandle)
832 *OutHandle = (ACPI_HANDLE) 1;
837 AcpiOsDeleteSemaphore (
844 AcpiOsWaitSemaphore (
853 AcpiOsSignalSemaphore (
861 /******************************************************************************
863 * FUNCTION: AcpiOsCreateSemaphore
865 * PARAMETERS: MaxUnits - Maximum units that can be sent
866 * InitialUnits - Units to be assigned to the new semaphore
867 * OutHandle - Where a handle will be returned
871 * DESCRIPTION: Create an OS semaphore
873 *****************************************************************************/
876 AcpiOsCreateSemaphore (
879 ACPI_SEMAPHORE *OutHandle)
884 ACPI_FUNCTION_NAME (OsCreateSemaphore);
887 if (MaxUnits == ACPI_UINT32_MAX)
892 if (InitialUnits == ACPI_UINT32_MAX)
894 InitialUnits = MaxUnits;
897 if (InitialUnits > MaxUnits)
899 return (AE_BAD_PARAMETER);
902 /* Find an empty slot */
904 for (i = 0; i < ACPI_OS_MAX_SEMAPHORES; i++)
906 if (!AcpiGbl_Semaphores[i].OsHandle)
911 if (i >= ACPI_OS_MAX_SEMAPHORES)
913 ACPI_EXCEPTION ((AE_INFO, AE_LIMIT,
914 "Reached max semaphores (%u), could not create",
915 ACPI_OS_MAX_SEMAPHORES));
919 /* Create an OS semaphore */
921 Mutex = CreateSemaphore (NULL, InitialUnits, MaxUnits, NULL);
924 ACPI_ERROR ((AE_INFO, "Could not create semaphore"));
925 return (AE_NO_MEMORY);
928 AcpiGbl_Semaphores[i].MaxUnits = (UINT16) MaxUnits;
929 AcpiGbl_Semaphores[i].CurrentUnits = (UINT16) InitialUnits;
930 AcpiGbl_Semaphores[i].OsHandle = Mutex;
932 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
933 "Handle=%u, Max=%u, Current=%u, OsHandle=%p\n",
934 i, MaxUnits, InitialUnits, Mutex));
936 *OutHandle = (void *) i;
941 /******************************************************************************
943 * FUNCTION: AcpiOsDeleteSemaphore
945 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
949 * DESCRIPTION: Delete an OS semaphore
951 *****************************************************************************/
954 AcpiOsDeleteSemaphore (
955 ACPI_SEMAPHORE Handle)
957 UINT32 Index = (UINT32) Handle;
960 if ((Index >= ACPI_OS_MAX_SEMAPHORES) ||
961 !AcpiGbl_Semaphores[Index].OsHandle)
963 return (AE_BAD_PARAMETER);
966 CloseHandle (AcpiGbl_Semaphores[Index].OsHandle);
967 AcpiGbl_Semaphores[Index].OsHandle = NULL;
972 /******************************************************************************
974 * FUNCTION: AcpiOsWaitSemaphore
976 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
977 * Units - How many units to wait for
978 * Timeout - How long to wait
982 * DESCRIPTION: Wait for units
984 *****************************************************************************/
987 AcpiOsWaitSemaphore (
988 ACPI_SEMAPHORE Handle,
992 UINT32 Index = (UINT32) Handle;
994 UINT32 OsTimeout = Timeout;
997 ACPI_FUNCTION_ENTRY ();
1000 if ((Index >= ACPI_OS_MAX_SEMAPHORES) ||
1001 !AcpiGbl_Semaphores[Index].OsHandle)
1003 return (AE_BAD_PARAMETER);
1008 printf ("WaitSemaphore: Attempt to receive %u units\n", Units);
1009 return (AE_NOT_IMPLEMENTED);
1012 if (Timeout == ACPI_WAIT_FOREVER)
1014 OsTimeout = INFINITE;
1015 if (AcpiGbl_DebugTimeout)
1017 /* The debug timeout will prevent hang conditions */
1019 OsTimeout = ACPI_OS_DEBUG_TIMEOUT;
1024 /* Add 10ms to account for clock tick granularity */
1029 WaitStatus = WaitForSingleObject (
1030 AcpiGbl_Semaphores[Index].OsHandle, OsTimeout);
1031 if (WaitStatus == WAIT_TIMEOUT)
1033 if (AcpiGbl_DebugTimeout)
1035 ACPI_EXCEPTION ((AE_INFO, AE_TIME,
1036 "Debug timeout on semaphore 0x%04X (%ums)\n",
1037 Index, ACPI_OS_DEBUG_TIMEOUT));
1043 if (AcpiGbl_Semaphores[Index].CurrentUnits == 0)
1045 ACPI_ERROR ((AE_INFO,
1046 "%s - No unit received. Timeout 0x%X, OS_Status 0x%X",
1047 AcpiUtGetMutexName (Index), Timeout, WaitStatus));
1052 AcpiGbl_Semaphores[Index].CurrentUnits--;
1057 /******************************************************************************
1059 * FUNCTION: AcpiOsSignalSemaphore
1061 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
1062 * Units - Number of units to send
1066 * DESCRIPTION: Send units
1068 *****************************************************************************/
1071 AcpiOsSignalSemaphore (
1072 ACPI_SEMAPHORE Handle,
1075 UINT32 Index = (UINT32) Handle;
1078 ACPI_FUNCTION_ENTRY ();
1081 if (Index >= ACPI_OS_MAX_SEMAPHORES)
1083 printf ("SignalSemaphore: Index/Handle out of range: %2.2X\n", Index);
1084 return (AE_BAD_PARAMETER);
1087 if (!AcpiGbl_Semaphores[Index].OsHandle)
1089 printf ("SignalSemaphore: Null OS handle, Index %2.2X\n", Index);
1090 return (AE_BAD_PARAMETER);
1095 printf ("SignalSemaphore: Attempt to signal %u units, Index %2.2X\n", Units, Index);
1096 return (AE_NOT_IMPLEMENTED);
1099 if ((AcpiGbl_Semaphores[Index].CurrentUnits + 1) >
1100 AcpiGbl_Semaphores[Index].MaxUnits)
1102 ACPI_ERROR ((AE_INFO,
1103 "Oversignalled semaphore[%u]! Current %u Max %u",
1104 Index, AcpiGbl_Semaphores[Index].CurrentUnits,
1105 AcpiGbl_Semaphores[Index].MaxUnits));
1110 AcpiGbl_Semaphores[Index].CurrentUnits++;
1111 ReleaseSemaphore (AcpiGbl_Semaphores[Index].OsHandle, Units, NULL);
1116 #endif /* ACPI_SINGLE_THREADED */
1119 /******************************************************************************
1121 * FUNCTION: Spinlock interfaces
1123 * DESCRIPTION: Map these interfaces to semaphore interfaces
1125 *****************************************************************************/
1129 ACPI_SPINLOCK *OutHandle)
1131 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
1136 ACPI_SPINLOCK Handle)
1138 AcpiOsDeleteSemaphore (Handle);
1143 ACPI_SPINLOCK Handle)
1145 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
1151 ACPI_SPINLOCK Handle,
1152 ACPI_CPU_FLAGS Flags)
1154 AcpiOsSignalSemaphore (Handle, 1);
1158 #if ACPI_FUTURE_IMPLEMENTATION
1160 /* Mutex interfaces, just implement with a semaphore */
1164 ACPI_MUTEX *OutHandle)
1166 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
1173 AcpiOsDeleteSemaphore (Handle);
1177 AcpiOsAcquireMutex (
1181 AcpiOsWaitSemaphore (Handle, 1, Timeout);
1186 AcpiOsReleaseMutex (
1189 AcpiOsSignalSemaphore (Handle, 1);
1194 /******************************************************************************
1196 * FUNCTION: AcpiOsInstallInterruptHandler
1198 * PARAMETERS: InterruptNumber - Level handler should respond to.
1199 * ServiceRoutine - Address of the ACPI interrupt handler
1200 * Context - User context
1202 * RETURN: Handle to the newly installed handler.
1204 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
1205 * OS-independent handler.
1207 *****************************************************************************/
1210 AcpiOsInstallInterruptHandler (
1211 UINT32 InterruptNumber,
1212 ACPI_OSD_HANDLER ServiceRoutine,
1220 /******************************************************************************
1222 * FUNCTION: AcpiOsRemoveInterruptHandler
1224 * PARAMETERS: Handle - Returned when handler was installed
1228 * DESCRIPTION: Uninstalls an interrupt handler.
1230 *****************************************************************************/
1233 AcpiOsRemoveInterruptHandler (
1234 UINT32 InterruptNumber,
1235 ACPI_OSD_HANDLER ServiceRoutine)
1242 /******************************************************************************
1244 * FUNCTION: AcpiOsStall
1246 * PARAMETERS: Microseconds - Time to stall
1248 * RETURN: None. Blocks until stall is completed.
1250 * DESCRIPTION: Sleep at microsecond granularity
1252 *****************************************************************************/
1256 UINT32 Microseconds)
1259 Sleep ((Microseconds / ACPI_USEC_PER_MSEC) + 1);
1264 /******************************************************************************
1266 * FUNCTION: AcpiOsSleep
1268 * PARAMETERS: Milliseconds - Time to sleep
1270 * RETURN: None. Blocks until sleep is completed.
1272 * DESCRIPTION: Sleep at millisecond granularity
1274 *****************************************************************************/
1278 UINT64 Milliseconds)
1281 /* Add 10ms to account for clock tick granularity */
1283 Sleep (((unsigned long) Milliseconds) + 10);
1288 /******************************************************************************
1290 * FUNCTION: AcpiOsReadPciConfiguration
1292 * PARAMETERS: PciId - Seg/Bus/Dev
1293 * Register - Device Register
1294 * Value - Buffer where value is placed
1295 * Width - Number of bits
1299 * DESCRIPTION: Read data from PCI configuration space
1301 *****************************************************************************/
1304 AcpiOsReadPciConfiguration (
1316 /******************************************************************************
1318 * FUNCTION: AcpiOsWritePciConfiguration
1320 * PARAMETERS: PciId - Seg/Bus/Dev
1321 * Register - Device Register
1322 * Value - Value to be written
1323 * Width - Number of bits
1327 * DESCRIPTION: Write data to PCI configuration space
1329 *****************************************************************************/
1332 AcpiOsWritePciConfiguration (
1343 /******************************************************************************
1345 * FUNCTION: AcpiOsReadPort
1347 * PARAMETERS: Address - Address of I/O port/register to read
1348 * Value - Where value is placed
1349 * Width - Number of bits
1351 * RETURN: Value read from port
1353 * DESCRIPTION: Read data from an I/O port or register
1355 *****************************************************************************/
1359 ACPI_IO_ADDRESS Address,
1363 ACPI_FUNCTION_NAME (OsReadPort);
1380 *Value = 0xFFFFFFFF;
1385 ACPI_ERROR ((AE_INFO, "Bad width parameter: %X", Width));
1386 return (AE_BAD_PARAMETER);
1393 /******************************************************************************
1395 * FUNCTION: AcpiOsWritePort
1397 * PARAMETERS: Address - Address of I/O port/register to write
1398 * Value - Value to write
1399 * Width - Number of bits
1403 * DESCRIPTION: Write data to an I/O port or register
1405 *****************************************************************************/
1409 ACPI_IO_ADDRESS Address,
1413 ACPI_FUNCTION_NAME (OsWritePort);
1416 if ((Width == 8) || (Width == 16) || (Width == 32))
1421 ACPI_ERROR ((AE_INFO, "Bad width parameter: %X", Width));
1422 return (AE_BAD_PARAMETER);
1426 /******************************************************************************
1428 * FUNCTION: AcpiOsReadMemory
1430 * PARAMETERS: Address - Physical Memory Address to read
1431 * Value - Where value is placed
1432 * Width - Number of bits (8,16,32, or 64)
1434 * RETURN: Value read from physical memory address. Always returned
1435 * as a 64-bit integer, regardless of the read width.
1437 * DESCRIPTION: Read data from a physical memory address
1439 *****************************************************************************/
1443 ACPI_PHYSICAL_ADDRESS Address,
1460 return (AE_BAD_PARAMETER);
1468 /******************************************************************************
1470 * FUNCTION: AcpiOsWriteMemory
1472 * PARAMETERS: Address - Physical Memory Address to write
1473 * Value - Value to write
1474 * Width - Number of bits (8,16,32, or 64)
1478 * DESCRIPTION: Write data to a physical memory address
1480 *****************************************************************************/
1484 ACPI_PHYSICAL_ADDRESS Address,
1493 /******************************************************************************
1495 * FUNCTION: AcpiOsSignal
1497 * PARAMETERS: Function - ACPICA signal function code
1498 * Info - Pointer to function-dependent structure
1502 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1504 *****************************************************************************/
1514 case ACPI_SIGNAL_FATAL:
1518 case ACPI_SIGNAL_BREAKPOINT:
1531 /******************************************************************************
1533 * FUNCTION: Local cache interfaces
1535 * DESCRIPTION: Implements cache interfaces via malloc/free for testing
1538 *****************************************************************************/
1540 #ifndef ACPI_USE_LOCAL_CACHE
1547 ACPI_CACHE_T **ReturnCache)
1549 ACPI_MEMORY_LIST *NewCache;
1552 NewCache = malloc (sizeof (ACPI_MEMORY_LIST));
1555 return (AE_NO_MEMORY);
1558 memset (NewCache, 0, sizeof (ACPI_MEMORY_LIST));
1559 NewCache->ListName = CacheName;
1560 NewCache->ObjectSize = ObjectSize;
1561 NewCache->MaxDepth = MaxDepth;
1563 *ReturnCache = (ACPI_CACHE_T) NewCache;
1569 ACPI_CACHE_T *Cache)
1577 ACPI_CACHE_T *Cache)
1583 AcpiOsAcquireObject (
1584 ACPI_CACHE_T *Cache)
1588 NewObject = malloc (((ACPI_MEMORY_LIST *) Cache)->ObjectSize);
1589 memset (NewObject, 0, ((ACPI_MEMORY_LIST *) Cache)->ObjectSize);
1595 AcpiOsReleaseObject (
1596 ACPI_CACHE_T *Cache,
1603 #endif /* ACPI_USE_LOCAL_CACHE */
1606 /* Optional multi-thread support */
1608 #ifndef ACPI_SINGLE_THREADED
1609 /******************************************************************************
1611 * FUNCTION: AcpiOsGetThreadId
1615 * RETURN: Id of the running thread
1617 * DESCRIPTION: Get the Id of the current (running) thread
1619 *****************************************************************************/
1627 /* Ensure ID is never 0 */
1629 ThreadId = GetCurrentThreadId ();
1630 return ((ACPI_THREAD_ID) (ThreadId + 1));
1634 /******************************************************************************
1636 * FUNCTION: AcpiOsExecute
1638 * PARAMETERS: Type - Type of execution
1639 * Function - Address of the function to execute
1640 * Context - Passed as a parameter to the function
1644 * DESCRIPTION: Execute a new thread
1646 *****************************************************************************/
1650 ACPI_EXECUTE_TYPE Type,
1651 ACPI_OSD_EXEC_CALLBACK Function,
1655 _beginthread (Function, (unsigned) 0, Context);
1659 #else /* ACPI_SINGLE_THREADED */
1669 ACPI_EXECUTE_TYPE Type,
1670 ACPI_OSD_EXEC_CALLBACK Function,
1678 #endif /* ACPI_SINGLE_THREADED */
1681 /******************************************************************************
1683 * FUNCTION: AcpiOsWaitEventsComplete
1689 * DESCRIPTION: Wait for all asynchronous events to complete. This
1690 * implementation does nothing.
1692 *****************************************************************************/
1695 AcpiOsWaitEventsComplete (