Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / os_specific / service_layers / oswinxf.c
blob697fd45082c5012ae50fe02d6ea58db5e8311d3a
1 /******************************************************************************
3 * Module Name: oswinxf - Windows OSL
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "acpi.h"
45 #include "accommon.h"
47 #ifdef WIN32
48 #pragma warning(disable:4115) /* warning C4115: named type definition in parentheses (caused by rpcasync.h> */
50 #include <windows.h>
51 #include <winbase.h>
53 #elif WIN64
54 #include <windowsx.h>
55 #endif
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <stdarg.h>
60 #include <process.h>
61 #include <time.h>
63 #define _COMPONENT ACPI_OS_SERVICES
64 ACPI_MODULE_NAME ("oswinxf")
67 extern FILE *AcpiGbl_DebugFile;
69 FILE *AcpiGbl_OutputFile;
70 UINT64 TimerFrequency;
71 char TableName[ACPI_NAME_SIZE + 1];
73 #define ACPI_OS_DEBUG_TIMEOUT 30000 /* 30 seconds */
76 /* Upcalls to AcpiExec application */
78 ACPI_PHYSICAL_ADDRESS
79 AeLocalGetRootPointer (
80 void);
82 void
83 AeTableOverride (
84 ACPI_TABLE_HEADER *ExistingTable,
85 ACPI_TABLE_HEADER **NewTable);
88 * Real semaphores are only used for a multi-threaded application
90 #ifndef ACPI_SINGLE_THREADED
92 /* Semaphore information structure */
94 typedef struct acpi_os_semaphore_info
96 UINT16 MaxUnits;
97 UINT16 CurrentUnits;
98 void *OsHandle;
100 } ACPI_OS_SEMAPHORE_INFO;
102 /* Need enough semaphores to run the large aslts suite */
104 #define ACPI_OS_MAX_SEMAPHORES 256
106 ACPI_OS_SEMAPHORE_INFO AcpiGbl_Semaphores[ACPI_OS_MAX_SEMAPHORES];
108 #endif /* ACPI_SINGLE_THREADED */
110 BOOLEAN AcpiGbl_DebugTimeout = FALSE;
112 /******************************************************************************
114 * FUNCTION: AcpiOsTerminate
116 * PARAMETERS: None
118 * RETURN: Status
120 * DESCRIPTION: Nothing to do for windows
122 *****************************************************************************/
124 ACPI_STATUS
125 AcpiOsTerminate (
126 void)
128 return (AE_OK);
132 /******************************************************************************
134 * FUNCTION: AcpiOsInitialize
136 * PARAMETERS: None
138 * RETURN: Status
140 * DESCRIPTION: Init this OSL
142 *****************************************************************************/
144 ACPI_STATUS
145 AcpiOsInitialize (
146 void)
148 LARGE_INTEGER LocalTimerFrequency;
151 #ifndef ACPI_SINGLE_THREADED
152 /* Clear the semaphore info array */
154 memset (AcpiGbl_Semaphores, 0x00, sizeof (AcpiGbl_Semaphores));
155 #endif
157 AcpiGbl_OutputFile = stdout;
159 /* Get the timer frequency for use in AcpiOsGetTimer */
161 TimerFrequency = 0;
162 if (QueryPerformanceFrequency (&LocalTimerFrequency))
164 /* Frequency is in ticks per second */
166 TimerFrequency = LocalTimerFrequency.QuadPart;
169 return (AE_OK);
173 /******************************************************************************
175 * FUNCTION: AcpiOsGetRootPointer
177 * PARAMETERS: None
179 * RETURN: RSDP physical address
181 * DESCRIPTION: Gets the root pointer (RSDP)
183 *****************************************************************************/
185 ACPI_PHYSICAL_ADDRESS
186 AcpiOsGetRootPointer (
187 void)
190 return (AeLocalGetRootPointer ());
194 /******************************************************************************
196 * FUNCTION: AcpiOsPredefinedOverride
198 * PARAMETERS: InitVal - Initial value of the predefined object
199 * NewVal - The new value for the object
201 * RETURN: Status, pointer to value. Null pointer returned if not
202 * overriding.
204 * DESCRIPTION: Allow the OS to override predefined names
206 *****************************************************************************/
208 ACPI_STATUS
209 AcpiOsPredefinedOverride (
210 const ACPI_PREDEFINED_NAMES *InitVal,
211 ACPI_STRING *NewVal)
214 if (!InitVal || !NewVal)
216 return (AE_BAD_PARAMETER);
219 *NewVal = NULL;
220 return (AE_OK);
224 /******************************************************************************
226 * FUNCTION: AcpiOsTableOverride
228 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
229 * NewTable - Where an entire new table is returned.
231 * RETURN: Status, pointer to new table. Null pointer returned if no
232 * table is available to override
234 * DESCRIPTION: Return a different version of a table if one is available
236 *****************************************************************************/
238 ACPI_STATUS
239 AcpiOsTableOverride (
240 ACPI_TABLE_HEADER *ExistingTable,
241 ACPI_TABLE_HEADER **NewTable)
243 #ifdef ACPI_ASL_COMPILER
244 ACPI_STATUS Status;
245 ACPI_PHYSICAL_ADDRESS Address;
246 #endif
248 if (!ExistingTable || !NewTable)
250 return (AE_BAD_PARAMETER);
253 *NewTable = NULL;
256 #ifdef ACPI_EXEC_APP
258 /* Call back up to AcpiExec */
260 AeTableOverride (ExistingTable, NewTable);
261 #endif
264 #ifdef ACPI_ASL_COMPILER
266 /* Attempt to get the table from the registry */
268 /* Construct a null-terminated string from table signature */
270 ACPI_MOVE_NAME (TableName, ExistingTable->Signature);
271 TableName[ACPI_NAME_SIZE] = 0;
273 Status = AcpiOsGetTableByName (TableName, 0, NewTable, &Address);
274 if (ACPI_SUCCESS (Status))
276 AcpiOsPrintf ("Table [%s] obtained from registry, %u bytes\n",
277 TableName, (*NewTable)->Length);
279 else
281 AcpiOsPrintf ("Could not read table %s from registry (%s)\n",
282 TableName, AcpiFormatException (Status));
284 #endif
286 return (AE_OK);
290 /******************************************************************************
292 * FUNCTION: AcpiOsPhysicalTableOverride
294 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
295 * NewAddress - Where new table address is returned
296 * (Physical address)
297 * NewTableLength - Where new table length is returned
299 * RETURN: Status, address/length of new table. Null pointer returned
300 * if no table is available to override.
302 * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
304 *****************************************************************************/
306 ACPI_STATUS
307 AcpiOsPhysicalTableOverride (
308 ACPI_TABLE_HEADER *ExistingTable,
309 ACPI_PHYSICAL_ADDRESS *NewAddress,
310 UINT32 *NewTableLength)
313 return (AE_SUPPORT);
317 /******************************************************************************
319 * FUNCTION: AcpiOsGetTimer
321 * PARAMETERS: None
323 * RETURN: Current ticks in 100-nanosecond units
325 * DESCRIPTION: Get the value of a system timer
327 ******************************************************************************/
329 UINT64
330 AcpiOsGetTimer (
331 void)
333 LARGE_INTEGER Timer;
336 /* Attempt to use hi-granularity timer first */
338 if (TimerFrequency &&
339 QueryPerformanceCounter (&Timer))
341 /* Convert to 100 nanosecond ticks */
343 return ((UINT64) ((Timer.QuadPart * (UINT64) ACPI_100NSEC_PER_SEC) /
344 TimerFrequency));
347 /* Fall back to the lo-granularity timer */
349 else
351 /* Convert milliseconds to 100 nanosecond ticks */
353 return ((UINT64) GetTickCount() * ACPI_100NSEC_PER_MSEC);
358 /******************************************************************************
360 * FUNCTION: AcpiOsReadable
362 * PARAMETERS: Pointer - Area to be verified
363 * Length - Size of area
365 * RETURN: TRUE if readable for entire length
367 * DESCRIPTION: Verify that a pointer is valid for reading
369 *****************************************************************************/
371 BOOLEAN
372 AcpiOsReadable (
373 void *Pointer,
374 ACPI_SIZE Length)
377 return ((BOOLEAN) !IsBadReadPtr (Pointer, Length));
381 /******************************************************************************
383 * FUNCTION: AcpiOsWritable
385 * PARAMETERS: Pointer - Area to be verified
386 * Length - Size of area
388 * RETURN: TRUE if writable for entire length
390 * DESCRIPTION: Verify that a pointer is valid for writing
392 *****************************************************************************/
394 BOOLEAN
395 AcpiOsWritable (
396 void *Pointer,
397 ACPI_SIZE Length)
400 return ((BOOLEAN) !IsBadWritePtr (Pointer, Length));
404 /******************************************************************************
406 * FUNCTION: AcpiOsRedirectOutput
408 * PARAMETERS: Destination - An open file handle/pointer
410 * RETURN: None
412 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
414 *****************************************************************************/
416 void
417 AcpiOsRedirectOutput (
418 void *Destination)
421 AcpiGbl_OutputFile = Destination;
425 /******************************************************************************
427 * FUNCTION: AcpiOsPrintf
429 * PARAMETERS: Fmt, ... - Standard printf format
431 * RETURN: None
433 * DESCRIPTION: Formatted output
435 *****************************************************************************/
437 void ACPI_INTERNAL_VAR_XFACE
438 AcpiOsPrintf (
439 const char *Fmt,
440 ...)
442 va_list Args;
443 UINT8 Flags;
446 Flags = AcpiGbl_DbOutputFlags;
447 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
449 /* Output is directable to either a file (if open) or the console */
451 if (AcpiGbl_DebugFile)
453 /* Output file is open, send the output there */
455 va_start (Args, Fmt);
456 vfprintf (AcpiGbl_DebugFile, Fmt, Args);
457 va_end (Args);
459 else
461 /* No redirection, send output to console (once only!) */
463 Flags |= ACPI_DB_CONSOLE_OUTPUT;
467 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
469 va_start (Args, Fmt);
470 vfprintf (AcpiGbl_OutputFile, Fmt, Args);
471 va_end (Args);
474 return;
478 /******************************************************************************
480 * FUNCTION: AcpiOsVprintf
482 * PARAMETERS: Fmt - Standard printf format
483 * Args - Argument list
485 * RETURN: None
487 * DESCRIPTION: Formatted output with argument list pointer
489 *****************************************************************************/
491 void
492 AcpiOsVprintf (
493 const char *Fmt,
494 va_list Args)
496 INT32 Count = 0;
497 UINT8 Flags;
500 Flags = AcpiGbl_DbOutputFlags;
501 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
503 /* Output is directable to either a file (if open) or the console */
505 if (AcpiGbl_DebugFile)
507 /* Output file is open, send the output there */
509 Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
511 else
513 /* No redirection, send output to console (once only!) */
515 Flags |= ACPI_DB_CONSOLE_OUTPUT;
519 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
521 Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
524 return;
528 /******************************************************************************
530 * FUNCTION: AcpiOsGetLine
532 * PARAMETERS: Buffer - Where to return the command line
533 * BufferLength - Maximum length of Buffer
534 * BytesRead - Where the actual byte count is returned
536 * RETURN: Status and actual bytes read
538 * DESCRIPTION: Formatted input with argument list pointer
540 *****************************************************************************/
542 ACPI_STATUS
543 AcpiOsGetLine (
544 char *Buffer,
545 UINT32 BufferLength,
546 UINT32 *BytesRead)
548 int Temp;
549 UINT32 i;
552 for (i = 0; ; i++)
554 if (i >= BufferLength)
556 return (AE_BUFFER_OVERFLOW);
559 if ((Temp = getchar ()) == EOF)
561 return (AE_ERROR);
564 if (!Temp || Temp == '\n')
566 break;
569 Buffer [i] = (char) Temp;
572 /* Null terminate the buffer */
574 Buffer [i] = 0;
576 /* Return the number of bytes in the string */
578 if (BytesRead)
580 *BytesRead = i;
582 return (AE_OK);
586 /******************************************************************************
588 * FUNCTION: AcpiOsMapMemory
590 * PARAMETERS: Where - Physical address of memory to be mapped
591 * Length - How much memory to map
593 * RETURN: Pointer to mapped memory. Null on error.
595 * DESCRIPTION: Map physical memory into caller's address space
597 *****************************************************************************/
599 void *
600 AcpiOsMapMemory (
601 ACPI_PHYSICAL_ADDRESS Where,
602 ACPI_SIZE Length)
605 return (ACPI_TO_POINTER ((ACPI_SIZE) Where));
609 /******************************************************************************
611 * FUNCTION: AcpiOsUnmapMemory
613 * PARAMETERS: Where - Logical address of memory to be unmapped
614 * Length - How much memory to unmap
616 * RETURN: None.
618 * DESCRIPTION: Delete a previously created mapping. Where and Length must
619 * correspond to a previous mapping exactly.
621 *****************************************************************************/
623 void
624 AcpiOsUnmapMemory (
625 void *Where,
626 ACPI_SIZE Length)
629 return;
633 /******************************************************************************
635 * FUNCTION: AcpiOsAllocate
637 * PARAMETERS: Size - Amount to allocate, in bytes
639 * RETURN: Pointer to the new allocation. Null on error.
641 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
643 *****************************************************************************/
645 void *
646 AcpiOsAllocate (
647 ACPI_SIZE Size)
649 void *Mem;
652 Mem = (void *) malloc ((size_t) Size);
654 return (Mem);
658 /******************************************************************************
660 * FUNCTION: AcpiOsFree
662 * PARAMETERS: Mem - Pointer to previously allocated memory
664 * RETURN: None.
666 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
668 *****************************************************************************/
670 void
671 AcpiOsFree (
672 void *Mem)
675 free (Mem);
679 #ifdef ACPI_SINGLE_THREADED
680 /******************************************************************************
682 * FUNCTION: Semaphore stub functions
684 * DESCRIPTION: Stub functions used for single-thread applications that do
685 * not require semaphore synchronization. Full implementations
686 * of these functions appear after the stubs.
688 *****************************************************************************/
690 ACPI_STATUS
691 AcpiOsCreateSemaphore (
692 UINT32 MaxUnits,
693 UINT32 InitialUnits,
694 ACPI_HANDLE *OutHandle)
696 *OutHandle = (ACPI_HANDLE) 1;
697 return (AE_OK);
700 ACPI_STATUS
701 AcpiOsDeleteSemaphore (
702 ACPI_HANDLE Handle)
704 return (AE_OK);
707 ACPI_STATUS
708 AcpiOsWaitSemaphore (
709 ACPI_HANDLE Handle,
710 UINT32 Units,
711 UINT16 Timeout)
713 return (AE_OK);
716 ACPI_STATUS
717 AcpiOsSignalSemaphore (
718 ACPI_HANDLE Handle,
719 UINT32 Units)
721 return (AE_OK);
724 #else
725 /******************************************************************************
727 * FUNCTION: AcpiOsCreateSemaphore
729 * PARAMETERS: MaxUnits - Maximum units that can be sent
730 * InitialUnits - Units to be assigned to the new semaphore
731 * OutHandle - Where a handle will be returned
733 * RETURN: Status
735 * DESCRIPTION: Create an OS semaphore
737 *****************************************************************************/
739 ACPI_STATUS
740 AcpiOsCreateSemaphore (
741 UINT32 MaxUnits,
742 UINT32 InitialUnits,
743 ACPI_SEMAPHORE *OutHandle)
745 void *Mutex;
746 UINT32 i;
748 ACPI_FUNCTION_NAME (OsCreateSemaphore);
751 if (MaxUnits == ACPI_UINT32_MAX)
753 MaxUnits = 255;
756 if (InitialUnits == ACPI_UINT32_MAX)
758 InitialUnits = MaxUnits;
761 if (InitialUnits > MaxUnits)
763 return (AE_BAD_PARAMETER);
766 /* Find an empty slot */
768 for (i = 0; i < ACPI_OS_MAX_SEMAPHORES; i++)
770 if (!AcpiGbl_Semaphores[i].OsHandle)
772 break;
775 if (i >= ACPI_OS_MAX_SEMAPHORES)
777 ACPI_EXCEPTION ((AE_INFO, AE_LIMIT,
778 "Reached max semaphores (%u), could not create", ACPI_OS_MAX_SEMAPHORES));
779 return (AE_LIMIT);
782 /* Create an OS semaphore */
784 Mutex = CreateSemaphore (NULL, InitialUnits, MaxUnits, NULL);
785 if (!Mutex)
787 ACPI_ERROR ((AE_INFO, "Could not create semaphore"));
788 return (AE_NO_MEMORY);
791 AcpiGbl_Semaphores[i].MaxUnits = (UINT16) MaxUnits;
792 AcpiGbl_Semaphores[i].CurrentUnits = (UINT16) InitialUnits;
793 AcpiGbl_Semaphores[i].OsHandle = Mutex;
795 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Handle=%u, Max=%u, Current=%u, OsHandle=%p\n",
796 i, MaxUnits, InitialUnits, Mutex));
798 *OutHandle = (void *) i;
799 return (AE_OK);
803 /******************************************************************************
805 * FUNCTION: AcpiOsDeleteSemaphore
807 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
809 * RETURN: Status
811 * DESCRIPTION: Delete an OS semaphore
813 *****************************************************************************/
815 ACPI_STATUS
816 AcpiOsDeleteSemaphore (
817 ACPI_SEMAPHORE Handle)
819 UINT32 Index = (UINT32) Handle;
822 if ((Index >= ACPI_OS_MAX_SEMAPHORES) ||
823 !AcpiGbl_Semaphores[Index].OsHandle)
825 return (AE_BAD_PARAMETER);
828 CloseHandle (AcpiGbl_Semaphores[Index].OsHandle);
829 AcpiGbl_Semaphores[Index].OsHandle = NULL;
830 return (AE_OK);
834 /******************************************************************************
836 * FUNCTION: AcpiOsWaitSemaphore
838 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
839 * Units - How many units to wait for
840 * Timeout - How long to wait
842 * RETURN: Status
844 * DESCRIPTION: Wait for units
846 *****************************************************************************/
848 ACPI_STATUS
849 AcpiOsWaitSemaphore (
850 ACPI_SEMAPHORE Handle,
851 UINT32 Units,
852 UINT16 Timeout)
854 UINT32 Index = (UINT32) Handle;
855 UINT32 WaitStatus;
856 UINT32 OsTimeout = Timeout;
859 ACPI_FUNCTION_ENTRY ();
862 if ((Index >= ACPI_OS_MAX_SEMAPHORES) ||
863 !AcpiGbl_Semaphores[Index].OsHandle)
865 return (AE_BAD_PARAMETER);
868 if (Units > 1)
870 printf ("WaitSemaphore: Attempt to receive %u units\n", Units);
871 return (AE_NOT_IMPLEMENTED);
874 if (Timeout == ACPI_WAIT_FOREVER)
876 OsTimeout = INFINITE;
877 if (AcpiGbl_DebugTimeout)
879 /* The debug timeout will prevent hang conditions */
881 OsTimeout = ACPI_OS_DEBUG_TIMEOUT;
884 else
886 /* Add 10ms to account for clock tick granularity */
888 OsTimeout += 10;
891 WaitStatus = WaitForSingleObject (AcpiGbl_Semaphores[Index].OsHandle, OsTimeout);
892 if (WaitStatus == WAIT_TIMEOUT)
894 if (AcpiGbl_DebugTimeout)
896 ACPI_EXCEPTION ((AE_INFO, AE_TIME,
897 "Debug timeout on semaphore 0x%04X (%ums)\n",
898 Index, ACPI_OS_DEBUG_TIMEOUT));
900 return (AE_TIME);
903 if (AcpiGbl_Semaphores[Index].CurrentUnits == 0)
905 ACPI_ERROR ((AE_INFO, "%s - No unit received. Timeout 0x%X, OS_Status 0x%X",
906 AcpiUtGetMutexName (Index), Timeout, WaitStatus));
908 return (AE_OK);
911 AcpiGbl_Semaphores[Index].CurrentUnits--;
912 return (AE_OK);
916 /******************************************************************************
918 * FUNCTION: AcpiOsSignalSemaphore
920 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
921 * Units - Number of units to send
923 * RETURN: Status
925 * DESCRIPTION: Send units
927 *****************************************************************************/
929 ACPI_STATUS
930 AcpiOsSignalSemaphore (
931 ACPI_SEMAPHORE Handle,
932 UINT32 Units)
934 UINT32 Index = (UINT32) Handle;
937 ACPI_FUNCTION_ENTRY ();
940 if (Index >= ACPI_OS_MAX_SEMAPHORES)
942 printf ("SignalSemaphore: Index/Handle out of range: %2.2X\n", Index);
943 return (AE_BAD_PARAMETER);
946 if (!AcpiGbl_Semaphores[Index].OsHandle)
948 printf ("SignalSemaphore: Null OS handle, Index %2.2X\n", Index);
949 return (AE_BAD_PARAMETER);
952 if (Units > 1)
954 printf ("SignalSemaphore: Attempt to signal %u units, Index %2.2X\n", Units, Index);
955 return (AE_NOT_IMPLEMENTED);
958 if ((AcpiGbl_Semaphores[Index].CurrentUnits + 1) >
959 AcpiGbl_Semaphores[Index].MaxUnits)
961 ACPI_ERROR ((AE_INFO,
962 "Oversignalled semaphore[%u]! Current %u Max %u",
963 Index, AcpiGbl_Semaphores[Index].CurrentUnits,
964 AcpiGbl_Semaphores[Index].MaxUnits));
966 return (AE_LIMIT);
969 AcpiGbl_Semaphores[Index].CurrentUnits++;
970 ReleaseSemaphore (AcpiGbl_Semaphores[Index].OsHandle, Units, NULL);
972 return (AE_OK);
975 #endif /* ACPI_SINGLE_THREADED */
978 /******************************************************************************
980 * FUNCTION: Spinlock interfaces
982 * DESCRIPTION: Map these interfaces to semaphore interfaces
984 *****************************************************************************/
986 ACPI_STATUS
987 AcpiOsCreateLock (
988 ACPI_SPINLOCK *OutHandle)
990 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
993 void
994 AcpiOsDeleteLock (
995 ACPI_SPINLOCK Handle)
997 AcpiOsDeleteSemaphore (Handle);
1000 ACPI_CPU_FLAGS
1001 AcpiOsAcquireLock (
1002 ACPI_SPINLOCK Handle)
1004 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
1005 return (0);
1008 void
1009 AcpiOsReleaseLock (
1010 ACPI_SPINLOCK Handle,
1011 ACPI_CPU_FLAGS Flags)
1013 AcpiOsSignalSemaphore (Handle, 1);
1017 #if ACPI_FUTURE_IMPLEMENTATION
1019 /* Mutex interfaces, just implement with a semaphore */
1021 ACPI_STATUS
1022 AcpiOsCreateMutex (
1023 ACPI_MUTEX *OutHandle)
1025 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
1028 void
1029 AcpiOsDeleteMutex (
1030 ACPI_MUTEX Handle)
1032 AcpiOsDeleteSemaphore (Handle);
1035 ACPI_STATUS
1036 AcpiOsAcquireMutex (
1037 ACPI_MUTEX Handle,
1038 UINT16 Timeout)
1040 AcpiOsWaitSemaphore (Handle, 1, Timeout);
1041 return (0);
1044 void
1045 AcpiOsReleaseMutex (
1046 ACPI_MUTEX Handle)
1048 AcpiOsSignalSemaphore (Handle, 1);
1050 #endif
1053 /******************************************************************************
1055 * FUNCTION: AcpiOsInstallInterruptHandler
1057 * PARAMETERS: InterruptNumber - Level handler should respond to.
1058 * ServiceRoutine - Address of the ACPI interrupt handler
1059 * Context - User context
1061 * RETURN: Handle to the newly installed handler.
1063 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
1064 * OS-independent handler.
1066 *****************************************************************************/
1068 UINT32
1069 AcpiOsInstallInterruptHandler (
1070 UINT32 InterruptNumber,
1071 ACPI_OSD_HANDLER ServiceRoutine,
1072 void *Context)
1075 return (AE_OK);
1079 /******************************************************************************
1081 * FUNCTION: AcpiOsRemoveInterruptHandler
1083 * PARAMETERS: Handle - Returned when handler was installed
1085 * RETURN: Status
1087 * DESCRIPTION: Uninstalls an interrupt handler.
1089 *****************************************************************************/
1091 ACPI_STATUS
1092 AcpiOsRemoveInterruptHandler (
1093 UINT32 InterruptNumber,
1094 ACPI_OSD_HANDLER ServiceRoutine)
1097 return (AE_OK);
1101 /******************************************************************************
1103 * FUNCTION: AcpiOsStall
1105 * PARAMETERS: Microseconds - Time to stall
1107 * RETURN: None. Blocks until stall is completed.
1109 * DESCRIPTION: Sleep at microsecond granularity
1111 *****************************************************************************/
1113 void
1114 AcpiOsStall (
1115 UINT32 Microseconds)
1118 Sleep ((Microseconds / ACPI_USEC_PER_MSEC) + 1);
1119 return;
1123 /******************************************************************************
1125 * FUNCTION: AcpiOsSleep
1127 * PARAMETERS: Milliseconds - Time to sleep
1129 * RETURN: None. Blocks until sleep is completed.
1131 * DESCRIPTION: Sleep at millisecond granularity
1133 *****************************************************************************/
1135 void
1136 AcpiOsSleep (
1137 UINT64 Milliseconds)
1140 /* Add 10ms to account for clock tick granularity */
1142 Sleep (((unsigned long) Milliseconds) + 10);
1143 return;
1147 /******************************************************************************
1149 * FUNCTION: AcpiOsReadPciConfiguration
1151 * PARAMETERS: PciId - Seg/Bus/Dev
1152 * Register - Device Register
1153 * Value - Buffer where value is placed
1154 * Width - Number of bits
1156 * RETURN: Status
1158 * DESCRIPTION: Read data from PCI configuration space
1160 *****************************************************************************/
1162 ACPI_STATUS
1163 AcpiOsReadPciConfiguration (
1164 ACPI_PCI_ID *PciId,
1165 UINT32 Register,
1166 UINT64 *Value,
1167 UINT32 Width)
1170 *Value = 0;
1171 return (AE_OK);
1175 /******************************************************************************
1177 * FUNCTION: AcpiOsWritePciConfiguration
1179 * PARAMETERS: PciId - Seg/Bus/Dev
1180 * Register - Device Register
1181 * Value - Value to be written
1182 * Width - Number of bits
1184 * RETURN: Status
1186 * DESCRIPTION: Write data to PCI configuration space
1188 *****************************************************************************/
1190 ACPI_STATUS
1191 AcpiOsWritePciConfiguration (
1192 ACPI_PCI_ID *PciId,
1193 UINT32 Register,
1194 UINT64 Value,
1195 UINT32 Width)
1198 return (AE_OK);
1202 /******************************************************************************
1204 * FUNCTION: AcpiOsReadPort
1206 * PARAMETERS: Address - Address of I/O port/register to read
1207 * Value - Where value is placed
1208 * Width - Number of bits
1210 * RETURN: Value read from port
1212 * DESCRIPTION: Read data from an I/O port or register
1214 *****************************************************************************/
1216 ACPI_STATUS
1217 AcpiOsReadPort (
1218 ACPI_IO_ADDRESS Address,
1219 UINT32 *Value,
1220 UINT32 Width)
1222 ACPI_FUNCTION_NAME (OsReadPort);
1225 switch (Width)
1227 case 8:
1229 *Value = 0xFF;
1230 break;
1232 case 16:
1234 *Value = 0xFFFF;
1235 break;
1237 case 32:
1239 *Value = 0xFFFFFFFF;
1240 break;
1242 default:
1244 ACPI_ERROR ((AE_INFO, "Bad width parameter: %X", Width));
1245 return (AE_BAD_PARAMETER);
1248 return (AE_OK);
1252 /******************************************************************************
1254 * FUNCTION: AcpiOsWritePort
1256 * PARAMETERS: Address - Address of I/O port/register to write
1257 * Value - Value to write
1258 * Width - Number of bits
1260 * RETURN: None
1262 * DESCRIPTION: Write data to an I/O port or register
1264 *****************************************************************************/
1266 ACPI_STATUS
1267 AcpiOsWritePort (
1268 ACPI_IO_ADDRESS Address,
1269 UINT32 Value,
1270 UINT32 Width)
1272 ACPI_FUNCTION_NAME (OsWritePort);
1275 if ((Width == 8) || (Width == 16) || (Width == 32))
1277 return (AE_OK);
1280 ACPI_ERROR ((AE_INFO, "Bad width parameter: %X", Width));
1281 return (AE_BAD_PARAMETER);
1285 /******************************************************************************
1287 * FUNCTION: AcpiOsReadMemory
1289 * PARAMETERS: Address - Physical Memory Address to read
1290 * Value - Where value is placed
1291 * Width - Number of bits (8,16,32, or 64)
1293 * RETURN: Value read from physical memory address. Always returned
1294 * as a 64-bit integer, regardless of the read width.
1296 * DESCRIPTION: Read data from a physical memory address
1298 *****************************************************************************/
1300 ACPI_STATUS
1301 AcpiOsReadMemory (
1302 ACPI_PHYSICAL_ADDRESS Address,
1303 UINT64 *Value,
1304 UINT32 Width)
1307 switch (Width)
1309 case 8:
1310 case 16:
1311 case 32:
1312 case 64:
1314 *Value = 0;
1315 break;
1317 default:
1319 return (AE_BAD_PARAMETER);
1320 break;
1323 return (AE_OK);
1327 /******************************************************************************
1329 * FUNCTION: AcpiOsWriteMemory
1331 * PARAMETERS: Address - Physical Memory Address to write
1332 * Value - Value to write
1333 * Width - Number of bits (8,16,32, or 64)
1335 * RETURN: None
1337 * DESCRIPTION: Write data to a physical memory address
1339 *****************************************************************************/
1341 ACPI_STATUS
1342 AcpiOsWriteMemory (
1343 ACPI_PHYSICAL_ADDRESS Address,
1344 UINT64 Value,
1345 UINT32 Width)
1348 return (AE_OK);
1352 /******************************************************************************
1354 * FUNCTION: AcpiOsSignal
1356 * PARAMETERS: Function - ACPI CA signal function code
1357 * Info - Pointer to function-dependent structure
1359 * RETURN: Status
1361 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1363 *****************************************************************************/
1365 ACPI_STATUS
1366 AcpiOsSignal (
1367 UINT32 Function,
1368 void *Info)
1371 switch (Function)
1373 case ACPI_SIGNAL_FATAL:
1375 break;
1377 case ACPI_SIGNAL_BREAKPOINT:
1379 break;
1381 default:
1383 break;
1386 return (AE_OK);
1390 /******************************************************************************
1392 * FUNCTION: Local cache interfaces
1394 * DESCRIPTION: Implements cache interfaces via malloc/free for testing
1395 * purposes only.
1397 *****************************************************************************/
1399 #ifndef ACPI_USE_LOCAL_CACHE
1401 ACPI_STATUS
1402 AcpiOsCreateCache (
1403 char *CacheName,
1404 UINT16 ObjectSize,
1405 UINT16 MaxDepth,
1406 ACPI_CACHE_T **ReturnCache)
1408 ACPI_MEMORY_LIST *NewCache;
1411 NewCache = malloc (sizeof (ACPI_MEMORY_LIST));
1412 if (!NewCache)
1414 return (AE_NO_MEMORY);
1417 memset (NewCache, 0, sizeof (ACPI_MEMORY_LIST));
1418 NewCache->ListName = CacheName;
1419 NewCache->ObjectSize = ObjectSize;
1420 NewCache->MaxDepth = MaxDepth;
1422 *ReturnCache = (ACPI_CACHE_T) NewCache;
1423 return (AE_OK);
1426 ACPI_STATUS
1427 AcpiOsDeleteCache (
1428 ACPI_CACHE_T *Cache)
1430 free (Cache);
1431 return (AE_OK);
1434 ACPI_STATUS
1435 AcpiOsPurgeCache (
1436 ACPI_CACHE_T *Cache)
1438 return (AE_OK);
1441 void *
1442 AcpiOsAcquireObject (
1443 ACPI_CACHE_T *Cache)
1445 void *NewObject;
1447 NewObject = malloc (((ACPI_MEMORY_LIST *) Cache)->ObjectSize);
1448 memset (NewObject, 0, ((ACPI_MEMORY_LIST *) Cache)->ObjectSize);
1450 return (NewObject);
1453 ACPI_STATUS
1454 AcpiOsReleaseObject (
1455 ACPI_CACHE_T *Cache,
1456 void *Object)
1458 free (Object);
1459 return (AE_OK);
1462 #endif /* ACPI_USE_LOCAL_CACHE */
1465 /* Optional multi-thread support */
1467 #ifndef ACPI_SINGLE_THREADED
1468 /******************************************************************************
1470 * FUNCTION: AcpiOsGetThreadId
1472 * PARAMETERS: None
1474 * RETURN: Id of the running thread
1476 * DESCRIPTION: Get the Id of the current (running) thread
1478 *****************************************************************************/
1480 ACPI_THREAD_ID
1481 AcpiOsGetThreadId (
1482 void)
1484 DWORD ThreadId;
1486 /* Ensure ID is never 0 */
1488 ThreadId = GetCurrentThreadId ();
1489 return ((ACPI_THREAD_ID) (ThreadId + 1));
1493 /******************************************************************************
1495 * FUNCTION: AcpiOsExecute
1497 * PARAMETERS: Type - Type of execution
1498 * Function - Address of the function to execute
1499 * Context - Passed as a parameter to the function
1501 * RETURN: Status
1503 * DESCRIPTION: Execute a new thread
1505 *****************************************************************************/
1507 ACPI_STATUS
1508 AcpiOsExecute (
1509 ACPI_EXECUTE_TYPE Type,
1510 ACPI_OSD_EXEC_CALLBACK Function,
1511 void *Context)
1514 _beginthread (Function, (unsigned) 0, Context);
1515 return (0);
1518 #endif /* ACPI_SINGLE_THREADED */
1521 /******************************************************************************
1523 * FUNCTION: AcpiOsWaitEventsComplete
1525 * PARAMETERS: None
1527 * RETURN: None
1529 * DESCRIPTION: Wait for all asynchronous events to complete. This
1530 * implementation does nothing.
1532 *****************************************************************************/
1534 void
1535 AcpiOsWaitEventsComplete (
1536 void)
1538 return;