i386/identcpu.c: Add VIA Nano support
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / os_specific / service_layers / oswinxf.c
blob693934528e2387887f8a5ad69ef3cddceed08a3f
1 /******************************************************************************
3 * Module Name: oswinxf - Windows OSL
4 * $Revision: 1.86 $
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13 * All rights reserved.
15 * 2. License
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
41 * 3. Conditions
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
119 * These interfaces are required in order to link to the ACPI subsystem
120 * parser. They are called during the execution of the parser, and all
121 * map directly to Clibrary calls.
124 #ifdef WIN32
125 #pragma warning(disable:4115) /* warning C4115: named type definition in parentheses (caused by rpcasync.h> */
127 #include <windows.h>
128 #include <winbase.h>
129 #endif
131 #ifdef WIN64
132 #include <windowsx.h>
133 #endif
135 #include <stdio.h>
136 #include <stdlib.h>
137 #include <stdarg.h>
138 #include <process.h>
139 #include <time.h>
141 #include "acpi.h"
142 #include "acdebug.h"
144 #define _COMPONENT ACPI_OS_SERVICES
145 ACPI_MODULE_NAME ("oswinxf")
148 #define NUM_SEMAPHORES 128
150 typedef struct semaphore_entry
152 UINT16 MaxUnits;
153 UINT16 CurrentUnits;
154 void *OsHandle;
155 } SEMAPHORE_ENTRY;
158 SEMAPHORE_ENTRY AcpiGbl_Semaphores[NUM_SEMAPHORES];
159 extern FILE *AcpiGbl_DebugFile;
161 ACPI_PHYSICAL_ADDRESS
162 AeLocalGetRootPointer (
163 void);
165 FILE *AcpiGbl_OutputFile;
166 UINT64 TimerFrequency;
169 /******************************************************************************
171 * FUNCTION: OsTerminate
173 * PARAMETERS: None
175 * RETURN: None
177 * DESCRIPTION: Nothing to do for windows
179 *****************************************************************************/
181 ACPI_STATUS
182 AcpiOsTerminate (void)
184 return AE_OK;
188 #ifndef ACPI_EXEC_APP
189 /* Used by both iASL and AcpiDump applications */
191 CHAR s[500];
193 /******************************************************************************
195 * FUNCTION: OsGetTable
197 * PARAMETERS: None
199 * RETURN: Pointer to the table. NULL if failure
201 * DESCRIPTION: Get an ACPI table from the Windows registry.
203 *****************************************************************************/
205 ACPI_TABLE_HEADER *
206 OsGetTable (
207 char *TableName)
209 HKEY Handle = NULL;
210 ULONG i;
211 LONG Status;
212 ULONG Type;
213 ULONG NameSize;
214 ULONG DataSize;
215 HKEY SubKey;
216 ACPI_TABLE_HEADER *Buffer;
217 char *Signature = TableName;
220 /* Get a handle to the DSDT key */
222 while (1)
224 ACPI_STRCPY (s, "HARDWARE\\ACPI\\");
225 ACPI_STRCAT (s, Signature);
227 Status = RegOpenKeyEx (HKEY_LOCAL_MACHINE, s,
228 0L, KEY_ALL_ACCESS, &Handle);
230 if (Status != ERROR_SUCCESS)
233 * Somewhere along the way, MS changed the registry entry for
234 * the FADT from
235 * HARDWARE/ACPI/FACP to
236 * HARDWARE/ACPI/FADT.
238 * This code allows for both.
240 if (ACPI_COMPARE_NAME (Signature, "FACP"))
242 Signature = "FADT";
244 else
246 AcpiOsPrintf ("Could not find %s in registry at %s\n", TableName, s);
247 return (NULL);
250 else
252 break;
256 /* Actual table is down a couple of levels */
258 for (i = 0; ;)
260 Status = RegEnumKey (Handle, i, s, sizeof(s));
261 i += 1;
262 if (Status == ERROR_NO_MORE_ITEMS)
264 break;
267 Status = RegOpenKey (Handle, s, &SubKey);
268 if (Status != ERROR_SUCCESS)
270 AcpiOsPrintf ("Could not open %s entry\n", TableName);
271 return (NULL);
274 RegCloseKey (Handle);
275 Handle = SubKey;
276 i = 0;
279 /* Find the table entry */
281 for (i = 0; ;)
283 NameSize = sizeof (s);
284 Status = RegEnumValue (Handle, i, s, &NameSize,
285 NULL, &Type, NULL, 0 );
286 if (Status != ERROR_SUCCESS)
288 AcpiOsPrintf ("Could not get %s registry entry\n", TableName);
289 return (NULL);
292 if (Type == REG_BINARY)
294 break;
296 i += 1;
299 /* Get the size of the table */
301 Status = RegQueryValueEx (Handle, s, NULL, NULL, NULL, &DataSize);
302 if (Status != ERROR_SUCCESS)
304 AcpiOsPrintf ("Could not read the %s table size\n", TableName);
305 return (NULL);
308 /* Allocate a new buffer for the table */
310 Buffer = AcpiOsAllocate (DataSize);
311 if (!Buffer)
313 goto Cleanup;
316 /* Get the actual table from the registry */
318 Status = RegQueryValueEx (Handle, s, NULL, NULL, (UCHAR *) Buffer, &DataSize);
319 if (Status != ERROR_SUCCESS)
321 AcpiOsPrintf ("Could not read %s data\n", TableName);
322 return (NULL);
325 Cleanup:
326 RegCloseKey (Handle);
327 return (Buffer);
330 #endif
332 /******************************************************************************
334 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate
336 * PARAMETERS: None
338 * RETURN: Status
340 * DESCRIPTION: Init this OSL
342 *****************************************************************************/
344 ACPI_STATUS
345 AcpiOsInitialize (void)
347 UINT32 i;
348 LARGE_INTEGER LocalTimerFrequency;
351 AcpiGbl_OutputFile = stdout;
353 for (i = 0; i < NUM_SEMAPHORES; i++)
355 AcpiGbl_Semaphores[i].OsHandle = NULL;
358 TimerFrequency = 0;
359 if (QueryPerformanceFrequency (&LocalTimerFrequency))
361 /* Frequency is in ticks per second */
363 TimerFrequency = LocalTimerFrequency.QuadPart;
366 return AE_OK;
370 /******************************************************************************
372 * FUNCTION: AcpiOsGetRootPointer
374 * PARAMETERS: None
376 * RETURN: RSDP physical address
378 * DESCRIPTION: Gets the root pointer (RSDP)
380 *****************************************************************************/
382 ACPI_PHYSICAL_ADDRESS
383 AcpiOsGetRootPointer (
384 void)
387 return (AeLocalGetRootPointer ());
391 /******************************************************************************
393 * FUNCTION: AcpiOsPredefinedOverride
395 * PARAMETERS: InitVal - Initial value of the predefined object
396 * NewVal - The new value for the object
398 * RETURN: Status, pointer to value. Null pointer returned if not
399 * overriding.
401 * DESCRIPTION: Allow the OS to override predefined names
403 *****************************************************************************/
405 ACPI_STATUS
406 AcpiOsPredefinedOverride (
407 const ACPI_PREDEFINED_NAMES *InitVal,
408 ACPI_STRING *NewVal)
411 if (!InitVal || !NewVal)
413 return (AE_BAD_PARAMETER);
416 *NewVal = NULL;
417 return (AE_OK);
421 /******************************************************************************
423 * FUNCTION: AcpiOsTableOverride
425 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
426 * NewTable - Where an entire new table is returned.
428 * RETURN: Status, pointer to new table. Null pointer returned if no
429 * table is available to override
431 * DESCRIPTION: Return a different version of a table if one is available
433 *****************************************************************************/
435 ACPI_STATUS
436 AcpiOsTableOverride (
437 ACPI_TABLE_HEADER *ExistingTable,
438 ACPI_TABLE_HEADER **NewTable)
440 #ifndef ACPI_EXEC_APP
441 char TableName[ACPI_NAME_SIZE + 1];
442 #endif
445 if (!ExistingTable || !NewTable)
447 return (AE_BAD_PARAMETER);
450 *NewTable = NULL;
453 #ifdef ACPI_EXEC_APP
455 /* This code exercises the table override mechanism in the core */
457 if (ACPI_COMPARE_NAME (ExistingTable->Signature, ACPI_SIG_DSDT))
459 /* override DSDT with itself */
461 *NewTable = AcpiGbl_DbTablePtr;
464 #else
466 /* Construct a null-terminated string from table signature */
468 TableName[ACPI_NAME_SIZE] = 0;
469 ACPI_STRNCPY (TableName, ExistingTable->Signature, ACPI_NAME_SIZE);
471 *NewTable = OsGetTable (TableName);
472 if (*NewTable)
474 AcpiOsPrintf ("%s obtained from registry, %d bytes\n",
475 TableName, (*NewTable)->Length);
477 else
479 AcpiOsPrintf ("Could not read %s from registry\n", TableName);
481 #endif
483 return (AE_OK);
487 /******************************************************************************
489 * FUNCTION: AcpiOsGetTimer
491 * PARAMETERS: None
493 * RETURN: Current ticks in 100-nanosecond units
495 * DESCRIPTION: Get the value of a system timer
497 ******************************************************************************/
499 UINT64
500 AcpiOsGetTimer (
501 void)
503 LARGE_INTEGER Timer;
506 // return ((UINT64) GetTickCount() * 10000);
508 /* Attempt to use hi-granularity timer first */
510 if (TimerFrequency &&
511 QueryPerformanceCounter (&Timer))
513 /* Convert to 100 nanosecond ticks */
515 return ((UINT64) ((Timer.QuadPart * (UINT64) 10000000) / TimerFrequency));
518 /* Fall back to the lo-granularity timer */
520 else
522 /* Convert milliseconds to 100 nanosecond ticks */
524 return ((UINT64) GetTickCount() * 10000);
529 /******************************************************************************
531 * FUNCTION: AcpiOsReadable
533 * PARAMETERS: Pointer - Area to be verified
534 * Length - Size of area
536 * RETURN: TRUE if readable for entire length
538 * DESCRIPTION: Verify that a pointer is valid for reading
540 *****************************************************************************/
542 BOOLEAN
543 AcpiOsReadable (
544 void *Pointer,
545 ACPI_SIZE Length)
548 return ((BOOLEAN) !IsBadReadPtr (Pointer, Length));
552 /******************************************************************************
554 * FUNCTION: AcpiOsWritable
556 * PARAMETERS: Pointer - Area to be verified
557 * Length - Size of area
559 * RETURN: TRUE if writable for entire length
561 * DESCRIPTION: Verify that a pointer is valid for writing
563 *****************************************************************************/
565 BOOLEAN
566 AcpiOsWritable (
567 void *Pointer,
568 ACPI_SIZE Length)
571 return ((BOOLEAN) !IsBadWritePtr (Pointer, Length));
575 /******************************************************************************
577 * FUNCTION: AcpiOsRedirectOutput
579 * PARAMETERS: Destination - An open file handle/pointer
581 * RETURN: None
583 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
585 *****************************************************************************/
587 void
588 AcpiOsRedirectOutput (
589 void *Destination)
592 AcpiGbl_OutputFile = Destination;
596 /******************************************************************************
598 * FUNCTION: AcpiOsPrintf
600 * PARAMETERS: fmt, ... Standard printf format
602 * RETURN: None
604 * DESCRIPTION: Formatted output
606 *****************************************************************************/
608 void ACPI_INTERNAL_VAR_XFACE
609 AcpiOsPrintf (
610 const char *Fmt,
611 ...)
613 va_list Args;
616 va_start (Args, Fmt);
618 AcpiOsVprintf (Fmt, Args);
620 va_end (Args);
621 return;
625 /******************************************************************************
627 * FUNCTION: AcpiOsVprintf
629 * PARAMETERS: fmt Standard printf format
630 * args Argument list
632 * RETURN: None
634 * DESCRIPTION: Formatted output with argument list pointer
636 *****************************************************************************/
638 void
639 AcpiOsVprintf (
640 const char *Fmt,
641 va_list Args)
643 INT32 Count = 0;
644 UINT8 Flags;
647 Flags = AcpiGbl_DbOutputFlags;
648 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
650 /* Output is directable to either a file (if open) or the console */
652 if (AcpiGbl_DebugFile)
654 /* Output file is open, send the output there */
656 Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
658 else
660 /* No redirection, send output to console (once only!) */
662 Flags |= ACPI_DB_CONSOLE_OUTPUT;
666 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
668 Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
671 return;
675 /******************************************************************************
677 * FUNCTION: AcpiOsGetLine
679 * PARAMETERS: fmt Standard printf format
680 * args Argument list
682 * RETURN: Actual bytes read
684 * DESCRIPTION: Formatted input with argument list pointer
686 *****************************************************************************/
688 UINT32
689 AcpiOsGetLine (
690 char *Buffer)
692 char Temp;
693 UINT32 i;
696 for (i = 0; ; i++)
698 scanf ("%1c", &Temp);
699 if (!Temp || Temp == '\n')
701 break;
704 Buffer [i] = Temp;
707 /* Null terminate the buffer */
709 Buffer [i] = 0;
711 /* Return the number of bytes in the string */
713 return (i);
716 /******************************************************************************
718 * FUNCTION: AcpiOsMapMemory
720 * PARAMETERS: where Physical address of memory to be mapped
721 * length How much memory to map
723 * RETURN: Pointer to mapped memory. Null on error.
725 * DESCRIPTION: Map physical memory into caller's address space
727 *****************************************************************************/
729 void *
730 AcpiOsMapMemory (
731 ACPI_PHYSICAL_ADDRESS where,
732 ACPI_SIZE length)
735 return (ACPI_TO_POINTER ((ACPI_NATIVE_UINT) where));
739 /******************************************************************************
741 * FUNCTION: AcpiOsUnmapMemory
743 * PARAMETERS: where Logical address of memory to be unmapped
744 * length How much memory to unmap
746 * RETURN: None.
748 * DESCRIPTION: Delete a previously created mapping. Where and Length must
749 * correspond to a previous mapping exactly.
751 *****************************************************************************/
753 void
754 AcpiOsUnmapMemory (
755 void *where,
756 ACPI_SIZE length)
759 return;
763 /******************************************************************************
765 * FUNCTION: AcpiOsAllocate
767 * PARAMETERS: Size Amount to allocate, in bytes
769 * RETURN: Pointer to the new allocation. Null on error.
771 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
773 *****************************************************************************/
775 void *
776 AcpiOsAllocate (
777 ACPI_SIZE size)
779 void *Mem;
782 Mem = (void *) malloc ((size_t) size);
784 return Mem;
788 /******************************************************************************
790 * FUNCTION: AcpiOsFree
792 * PARAMETERS: mem Pointer to previously allocated memory
794 * RETURN: None.
796 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
798 *****************************************************************************/
800 void
801 AcpiOsFree (
802 void *Mem)
805 free (Mem);
809 /******************************************************************************
811 * FUNCTION: AcpiOsCreateSemaphore
813 * PARAMETERS: MaxUnits - Maximum units that can be sent
814 * InitialUnits - Units to be assigned to the new semaphore
815 * OutHandle - Where a handle will be returned
817 * RETURN: Status
819 * DESCRIPTION: Create an OS semaphore
821 *****************************************************************************/
823 ACPI_STATUS
824 AcpiOsCreateSemaphore (
825 UINT32 MaxUnits,
826 UINT32 InitialUnits,
827 ACPI_SEMAPHORE *OutHandle)
829 #ifdef _MULTI_THREADED
830 void *Mutex;
831 UINT32 i;
833 ACPI_FUNCTION_NAME (OsCreateSemaphore);
834 #endif
837 if (MaxUnits == ACPI_UINT32_MAX)
839 MaxUnits = 255;
842 if (InitialUnits == ACPI_UINT32_MAX)
844 InitialUnits = MaxUnits;
847 if (InitialUnits > MaxUnits)
849 return AE_BAD_PARAMETER;
852 #ifdef _MULTI_THREADED
854 /* Find an empty slot */
856 for (i = 0; i < NUM_SEMAPHORES; i++)
858 if (!AcpiGbl_Semaphores[i].OsHandle)
860 break;
863 if (i >= NUM_SEMAPHORES)
865 return AE_LIMIT;
868 /* Create an OS semaphore */
870 Mutex = CreateSemaphore (NULL, InitialUnits, MaxUnits, NULL);
871 if (!Mutex)
873 ACPI_ERROR ((AE_INFO, "Could not create semaphore"));
874 return AE_NO_MEMORY;
877 AcpiGbl_Semaphores[i].MaxUnits = (UINT16) MaxUnits;
878 AcpiGbl_Semaphores[i].CurrentUnits = (UINT16) InitialUnits;
879 AcpiGbl_Semaphores[i].OsHandle = Mutex;
881 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Handle=%d, Max=%d, Current=%d, OsHandle=%p\n",
882 i, MaxUnits, InitialUnits, Mutex));
884 *OutHandle = (void *) i;
885 #endif
887 return AE_OK;
890 /******************************************************************************
892 * FUNCTION: AcpiOsDeleteSemaphore
894 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
896 * RETURN: Status
898 * DESCRIPTION: Delete an OS semaphore
900 *****************************************************************************/
902 ACPI_STATUS
903 AcpiOsDeleteSemaphore (
904 ACPI_SEMAPHORE Handle)
906 UINT32 Index = (UINT32) Handle;
909 if ((Index >= NUM_SEMAPHORES) ||
910 !AcpiGbl_Semaphores[Index].OsHandle)
912 return AE_BAD_PARAMETER;
916 #ifdef _MULTI_THREADED
918 CloseHandle (AcpiGbl_Semaphores[Index].OsHandle);
919 AcpiGbl_Semaphores[Index].OsHandle = NULL;
920 #endif
922 return AE_OK;
926 /******************************************************************************
928 * FUNCTION: AcpiOsWaitSemaphore
930 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
931 * Units - How many units to wait for
932 * Timeout - How long to wait
934 * RETURN: Status
936 * DESCRIPTION: Wait for units
938 *****************************************************************************/
940 ACPI_STATUS
941 AcpiOsWaitSemaphore (
942 ACPI_SEMAPHORE Handle,
943 UINT32 Units,
944 UINT16 Timeout)
946 #ifdef _MULTI_THREADED
947 UINT32 Index = (UINT32) Handle;
948 UINT32 WaitStatus;
949 UINT32 OsTimeout = Timeout;
952 ACPI_FUNCTION_ENTRY ();
955 if ((Index >= NUM_SEMAPHORES) ||
956 !AcpiGbl_Semaphores[Index].OsHandle)
958 return AE_BAD_PARAMETER;
961 if (Units > 1)
963 printf ("WaitSemaphore: Attempt to receive %d units\n", Units);
964 return AE_NOT_IMPLEMENTED;
968 /* TBD: Make this a command line option so that we can catch
969 * synchronization deadlocks
971 if (Timeout == INFINITE)
972 Timeout = 400000;
975 if (Timeout == ACPI_WAIT_FOREVER)
977 OsTimeout = INFINITE;
979 else
981 /* Add 10ms to account for clock tick granularity */
983 OsTimeout += 10;
986 WaitStatus = WaitForSingleObject (AcpiGbl_Semaphores[Index].OsHandle, OsTimeout);
987 if (WaitStatus == WAIT_TIMEOUT)
989 /* Make optional -- wait of 0 is used to detect if unit is available
990 ACPI_ERROR ((AE_INFO, "Timeout on semaphore %d",
991 Handle));
993 return AE_TIME;
996 if (AcpiGbl_Semaphores[Index].CurrentUnits == 0)
998 ACPI_ERROR ((AE_INFO, "%s - No unit received. Timeout %X, OSstatus 0x%X",
999 AcpiUtGetMutexName (Index), Timeout, WaitStatus));
1001 return AE_OK;
1004 AcpiGbl_Semaphores[Index].CurrentUnits--;
1005 #endif
1007 return AE_OK;
1011 /******************************************************************************
1013 * FUNCTION: AcpiOsSignalSemaphore
1015 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
1016 * Units - Number of units to send
1018 * RETURN: Status
1020 * DESCRIPTION: Send units
1022 *****************************************************************************/
1024 ACPI_STATUS
1025 AcpiOsSignalSemaphore (
1026 ACPI_SEMAPHORE Handle,
1027 UINT32 Units)
1029 #ifdef _MULTI_THREADED
1031 UINT32 Index = (UINT32) Handle;
1034 ACPI_FUNCTION_ENTRY ();
1037 if (Index >= NUM_SEMAPHORES)
1039 printf ("SignalSemaphore: Index/Handle out of range: %2.2X\n", Index);
1040 return AE_BAD_PARAMETER;
1043 if (!AcpiGbl_Semaphores[Index].OsHandle)
1045 printf ("SignalSemaphore: Null OS handle, Index %2.2X\n", Index);
1046 return AE_BAD_PARAMETER;
1049 if (Units > 1)
1051 printf ("SignalSemaphore: Attempt to signal %d units, Index %2.2X\n", Units, Index);
1052 return AE_NOT_IMPLEMENTED;
1055 if ((AcpiGbl_Semaphores[Index].CurrentUnits + 1) >
1056 AcpiGbl_Semaphores[Index].MaxUnits)
1058 ACPI_ERROR ((AE_INFO,
1059 "Oversignalled semaphore[%d]! Current %d Max %d",
1060 Index, AcpiGbl_Semaphores[Index].CurrentUnits,
1061 AcpiGbl_Semaphores[Index].MaxUnits));
1063 return (AE_LIMIT);
1066 AcpiGbl_Semaphores[Index].CurrentUnits++;
1067 ReleaseSemaphore (AcpiGbl_Semaphores[Index].OsHandle, Units, NULL);
1069 #endif
1071 return (AE_OK);
1075 /* Spinlock interfaces, just implement with a semaphore */
1077 ACPI_STATUS
1078 AcpiOsCreateLock (
1079 ACPI_SPINLOCK *OutHandle)
1081 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
1084 void
1085 AcpiOsDeleteLock (
1086 ACPI_SPINLOCK Handle)
1088 AcpiOsDeleteSemaphore (Handle);
1091 ACPI_CPU_FLAGS
1092 AcpiOsAcquireLock (
1093 ACPI_SPINLOCK Handle)
1095 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
1096 return (0);
1099 void
1100 AcpiOsReleaseLock (
1101 ACPI_SPINLOCK Handle,
1102 ACPI_CPU_FLAGS Flags)
1104 AcpiOsSignalSemaphore (Handle, 1);
1108 #if ACPI_FUTURE_IMPLEMENTATION
1110 /* Mutex interfaces, just implement with a semaphore */
1112 ACPI_STATUS
1113 AcpiOsCreateMutex (
1114 ACPI_MUTEX *OutHandle)
1116 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
1119 void
1120 AcpiOsDeleteMutex (
1121 ACPI_MUTEX Handle)
1123 AcpiOsDeleteSemaphore (Handle);
1126 ACPI_STATUS
1127 AcpiOsAcquireMutex (
1128 ACPI_MUTEX Handle,
1129 UINT16 Timeout)
1131 AcpiOsWaitSemaphore (Handle, 1, Timeout);
1132 return (0);
1135 void
1136 AcpiOsReleaseMutex (
1137 ACPI_MUTEX Handle)
1139 AcpiOsSignalSemaphore (Handle, 1);
1141 #endif
1144 /******************************************************************************
1146 * FUNCTION: AcpiOsInstallInterruptHandler
1148 * PARAMETERS: InterruptNumber Level handler should respond to.
1149 * Isr Address of the ACPI interrupt handler
1150 * ExceptPtr Where status is returned
1152 * RETURN: Handle to the newly installed handler.
1154 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
1155 * OS-independent handler.
1157 *****************************************************************************/
1159 UINT32
1160 AcpiOsInstallInterruptHandler (
1161 UINT32 InterruptNumber,
1162 ACPI_OSD_HANDLER ServiceRoutine,
1163 void *Context)
1166 return AE_OK;
1170 /******************************************************************************
1172 * FUNCTION: AcpiOsRemoveInterruptHandler
1174 * PARAMETERS: Handle Returned when handler was installed
1176 * RETURN: Status
1178 * DESCRIPTION: Uninstalls an interrupt handler.
1180 *****************************************************************************/
1182 ACPI_STATUS
1183 AcpiOsRemoveInterruptHandler (
1184 UINT32 InterruptNumber,
1185 ACPI_OSD_HANDLER ServiceRoutine)
1188 return AE_OK;
1192 /******************************************************************************
1194 * FUNCTION: AcpiOsGetThreadId
1196 * PARAMETERS: None
1198 * RETURN: Id of the running thread
1200 * DESCRIPTION: Get the Id of the current (running) thread
1202 *****************************************************************************/
1204 ACPI_THREAD_ID
1205 AcpiOsGetThreadId (
1206 void)
1208 DWORD ThreadId;
1210 /* Ensure ID is never 0 */
1212 ThreadId = GetCurrentThreadId ();
1213 return (ThreadId + 1);
1217 /******************************************************************************
1219 * FUNCTION: AcpiOsExecute
1221 * PARAMETERS: Type - Type of execution
1222 * Function - Address of the function to execute
1223 * Context - Passed as a parameter to the function
1225 * RETURN: Status
1227 * DESCRIPTION: Execute a new thread
1229 *****************************************************************************/
1231 ACPI_STATUS
1232 AcpiOsExecute (
1233 ACPI_EXECUTE_TYPE Type,
1234 ACPI_OSD_EXEC_CALLBACK Function,
1235 void *Context)
1238 #ifdef _MULTI_THREADED
1239 _beginthread (Function, (unsigned) 0, Context);
1240 #endif
1242 return 0;
1246 /******************************************************************************
1248 * FUNCTION: AcpiOsStall
1250 * PARAMETERS: microseconds To sleep
1252 * RETURN: Blocks until sleep is completed.
1254 * DESCRIPTION: Sleep at microsecond granularity
1256 *****************************************************************************/
1258 void
1259 AcpiOsStall (
1260 UINT32 microseconds)
1263 Sleep ((microseconds / 1000) + 1);
1264 return;
1268 /******************************************************************************
1270 * FUNCTION: AcpiOsSleep
1272 * PARAMETERS: milliseconds To sleep
1274 * RETURN: Blocks until sleep is completed.
1276 * DESCRIPTION: Sleep at millisecond granularity
1278 *****************************************************************************/
1280 void
1281 AcpiOsSleep (
1282 ACPI_INTEGER milliseconds)
1285 /* Add 10ms to account for clock tick granularity */
1287 Sleep (((unsigned long) milliseconds) + 10);
1288 return;
1292 /******************************************************************************
1294 * FUNCTION: AcpiOsValidateInterface
1296 * PARAMETERS: Interface - Requested interface to be validated
1298 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
1300 * DESCRIPTION: Match an interface string to the interfaces supported by the
1301 * host. Strings originate from an AML call to the _OSI method.
1303 *****************************************************************************/
1305 ACPI_STATUS
1306 AcpiOsValidateInterface (
1307 char *Interface)
1310 return (AE_SUPPORT);
1314 /******************************************************************************
1316 * FUNCTION: AcpiOsValidateAddress
1318 * PARAMETERS: SpaceId - ACPI space ID
1319 * Address - Physical address
1320 * Length - Address length
1322 * RETURN: AE_OK if Address/Length is valid for the SpaceId. Otherwise,
1323 * should return AE_AML_ILLEGAL_ADDRESS.
1325 * DESCRIPTION: Validate a system address via the host OS. Used to validate
1326 * the addresses accessed by AML operation regions.
1328 *****************************************************************************/
1330 ACPI_STATUS
1331 AcpiOsValidateAddress (
1332 UINT8 SpaceId,
1333 ACPI_PHYSICAL_ADDRESS Address,
1334 ACPI_SIZE Length)
1337 return (AE_OK);
1341 /******************************************************************************
1343 * FUNCTION: AcpiOsReadPciConfiguration
1345 * PARAMETERS: PciId Seg/Bus/Dev
1346 * Register Device Register
1347 * Value Buffer where value is placed
1348 * Width Number of bits
1350 * RETURN: Status
1352 * DESCRIPTION: Read data from PCI configuration space
1354 *****************************************************************************/
1356 ACPI_STATUS
1357 AcpiOsReadPciConfiguration (
1358 ACPI_PCI_ID *PciId,
1359 UINT32 Register,
1360 void *Value,
1361 UINT32 Width)
1364 return (AE_OK);
1368 /******************************************************************************
1370 * FUNCTION: AcpiOsWritePciConfiguration
1372 * PARAMETERS: PciId Seg/Bus/Dev
1373 * Register Device Register
1374 * Value Value to be written
1375 * Width Number of bits
1377 * RETURN: Status.
1379 * DESCRIPTION: Write data to PCI configuration space
1381 *****************************************************************************/
1383 ACPI_STATUS
1384 AcpiOsWritePciConfiguration (
1385 ACPI_PCI_ID *PciId,
1386 UINT32 Register,
1387 ACPI_INTEGER Value,
1388 UINT32 Width)
1391 return (AE_OK);
1394 /* TEMPORARY STUB FUNCTION */
1395 void
1396 AcpiOsDerivePciId(
1397 ACPI_HANDLE rhandle,
1398 ACPI_HANDLE chandle,
1399 ACPI_PCI_ID **PciId)
1402 return;
1406 /******************************************************************************
1408 * FUNCTION: AcpiOsReadPort
1410 * PARAMETERS: Address Address of I/O port/register to read
1411 * Value Where value is placed
1412 * Width Number of bits
1414 * RETURN: Value read from port
1416 * DESCRIPTION: Read data from an I/O port or register
1418 *****************************************************************************/
1420 ACPI_STATUS
1421 AcpiOsReadPort (
1422 ACPI_IO_ADDRESS Address,
1423 UINT32 *Value,
1424 UINT32 Width)
1427 switch (Width)
1429 case 8:
1430 *Value = 0xFF;
1431 break;
1433 case 16:
1434 *Value = 0xFFFF;
1435 break;
1437 case 32:
1438 *Value = 0xFFFFFFFF;
1439 break;
1441 default:
1442 return (AE_BAD_PARAMETER);
1445 return (AE_OK);
1449 /******************************************************************************
1451 * FUNCTION: AcpiOsWritePort
1453 * PARAMETERS: Address Address of I/O port/register to write
1454 * Value Value to write
1455 * Width Number of bits
1457 * RETURN: None
1459 * DESCRIPTION: Write data to an I/O port or register
1461 *****************************************************************************/
1463 ACPI_STATUS
1464 AcpiOsWritePort (
1465 ACPI_IO_ADDRESS Address,
1466 UINT32 Value,
1467 UINT32 Width)
1470 return (AE_OK);
1474 /******************************************************************************
1476 * FUNCTION: AcpiOsReadMemory
1478 * PARAMETERS: Address Physical Memory Address to read
1479 * Value Where value is placed
1480 * Width Number of bits
1482 * RETURN: Value read from physical memory address. Always returned
1483 * as a 32-bit integer, regardless of the read width.
1485 * DESCRIPTION: Read data from a physical memory address
1487 *****************************************************************************/
1489 ACPI_STATUS
1490 AcpiOsReadMemory (
1491 ACPI_PHYSICAL_ADDRESS Address,
1492 UINT32 *Value,
1493 UINT32 Width)
1496 switch (Width)
1498 case 8:
1499 case 16:
1500 case 32:
1501 *Value = 0;
1502 break;
1504 default:
1505 return (AE_BAD_PARAMETER);
1506 break;
1509 return (AE_OK);
1513 /******************************************************************************
1515 * FUNCTION: AcpiOsWriteMemory
1517 * PARAMETERS: Address Physical Memory Address to write
1518 * Value Value to write
1519 * Width Number of bits
1521 * RETURN: None
1523 * DESCRIPTION: Write data to a physical memory address
1525 *****************************************************************************/
1527 ACPI_STATUS
1528 AcpiOsWriteMemory (
1529 ACPI_PHYSICAL_ADDRESS Address,
1530 UINT32 Value,
1531 UINT32 Width)
1534 return (AE_OK);
1538 /******************************************************************************
1540 * FUNCTION: AcpiOsSignal
1542 * PARAMETERS: Function ACPI CA signal function code
1543 * Info Pointer to function-dependent structure
1545 * RETURN: Status
1547 * DESCRIPTION: Miscellaneous functions
1549 *****************************************************************************/
1551 ACPI_STATUS
1552 AcpiOsSignal (
1553 UINT32 Function,
1554 void *Info)
1557 switch (Function)
1559 case ACPI_SIGNAL_FATAL:
1560 break;
1562 case ACPI_SIGNAL_BREAKPOINT:
1564 if (Info)
1566 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Info);
1568 else
1570 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
1573 break;
1576 return (AE_OK);