1 /******************************************************************************
3 * Module Name: osunixxf - UNIX OSL interfaces
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 * These interfaces are required in order to compile the ASL compiler and the
154 * various ACPICA tools under Linux or other Unix-like system.
157 #include "accommon.h"
159 #include "acparser.h"
166 #include <sys/time.h>
167 #include <semaphore.h>
171 #define _COMPONENT ACPI_OS_SERVICES
172 ACPI_MODULE_NAME ("osunixxf")
175 /* Upcalls to AcpiExec */
179 ACPI_TABLE_HEADER *ExistingTable,
180 ACPI_TABLE_HEADER **NewTable);
182 typedef void* (*PTHREAD_CALLBACK) (void *);
184 /* Buffer used by AcpiOsVprintf */
186 #define ACPI_VPRINTF_BUFFER_SIZE 512
187 #define _ASCII_NEWLINE '\n'
189 /* Terminal support for AcpiExec only */
194 struct termios OriginalTermAttributes;
195 int TermAttributesWereSet = 0;
204 OsEnterLineEditMode (
212 /******************************************************************************
214 * FUNCTION: OsEnterLineEditMode, OsExitLineEditMode
220 * DESCRIPTION: Enter/Exit the raw character input mode for the terminal.
222 * Interactive line-editing support for the AML debugger. Used with the
223 * common/acgetline module.
225 * readline() is not used because of non-portability. It is not available
226 * on all systems, and if it is, often the package must be manually installed.
228 * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line
229 * editing that we need in AcpiOsGetLine.
231 * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these
232 * calls will also work:
233 * For OsEnterLineEditMode: system ("stty cbreak -echo")
234 * For OsExitLineEditMode: system ("stty cooked echo")
236 *****************************************************************************/
239 OsEnterLineEditMode (
242 struct termios LocalTermAttributes;
245 TermAttributesWereSet = 0;
247 /* STDIN must be a terminal */
249 if (!isatty (STDIN_FILENO))
254 /* Get and keep the original attributes */
256 if (tcgetattr (STDIN_FILENO, &OriginalTermAttributes))
258 fprintf (stderr, "Could not get terminal attributes!\n");
262 /* Set the new attributes to enable raw character input */
264 memcpy (&LocalTermAttributes, &OriginalTermAttributes,
265 sizeof (struct termios));
267 LocalTermAttributes.c_lflag &= ~(ICANON | ECHO);
268 LocalTermAttributes.c_cc[VMIN] = 1;
269 LocalTermAttributes.c_cc[VTIME] = 0;
271 if (tcsetattr (STDIN_FILENO, TCSANOW, &LocalTermAttributes))
273 fprintf (stderr, "Could not set terminal attributes!\n");
277 TermAttributesWereSet = 1;
286 if (!TermAttributesWereSet)
291 /* Set terminal attributes back to the original values */
293 if (tcsetattr (STDIN_FILENO, TCSANOW, &OriginalTermAttributes))
295 fprintf (stderr, "Could not restore terminal attributes!\n");
302 /* These functions are not needed for other ACPICA utilities */
304 #define OsEnterLineEditMode()
305 #define OsExitLineEditMode()
309 /******************************************************************************
311 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate
317 * DESCRIPTION: Initialize and terminate this module.
319 *****************************************************************************/
328 AcpiGbl_OutputFile = stdout;
330 OsEnterLineEditMode ();
332 Status = AcpiOsCreateLock (&AcpiGbl_PrintLock);
333 if (ACPI_FAILURE (Status))
346 OsExitLineEditMode ();
351 #ifndef ACPI_USE_NATIVE_RSDP_POINTER
352 /******************************************************************************
354 * FUNCTION: AcpiOsGetRootPointer
358 * RETURN: RSDP physical address
360 * DESCRIPTION: Gets the ACPI root pointer (RSDP)
362 *****************************************************************************/
364 ACPI_PHYSICAL_ADDRESS
365 AcpiOsGetRootPointer (
374 /******************************************************************************
376 * FUNCTION: AcpiOsPredefinedOverride
378 * PARAMETERS: InitVal - Initial value of the predefined object
379 * NewVal - The new value for the object
381 * RETURN: Status, pointer to value. Null pointer returned if not
384 * DESCRIPTION: Allow the OS to override predefined names
386 *****************************************************************************/
389 AcpiOsPredefinedOverride (
390 const ACPI_PREDEFINED_NAMES *InitVal,
394 if (!InitVal || !NewVal)
396 return (AE_BAD_PARAMETER);
404 /******************************************************************************
406 * FUNCTION: AcpiOsTableOverride
408 * PARAMETERS: ExistingTable - Header of current table (probably
410 * NewTable - Where an entire new table is returned.
412 * RETURN: Status, pointer to new table. Null pointer returned if no
413 * table is available to override
415 * DESCRIPTION: Return a different version of a table if one is available
417 *****************************************************************************/
420 AcpiOsTableOverride (
421 ACPI_TABLE_HEADER *ExistingTable,
422 ACPI_TABLE_HEADER **NewTable)
425 if (!ExistingTable || !NewTable)
427 return (AE_BAD_PARAMETER);
434 AeTableOverride (ExistingTable, NewTable);
438 return (AE_NO_ACPI_TABLES);
443 /******************************************************************************
445 * FUNCTION: AcpiOsPhysicalTableOverride
447 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
448 * NewAddress - Where new table address is returned
450 * NewTableLength - Where new table length is returned
452 * RETURN: Status, address/length of new table. Null pointer returned
453 * if no table is available to override.
455 * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
457 *****************************************************************************/
460 AcpiOsPhysicalTableOverride (
461 ACPI_TABLE_HEADER *ExistingTable,
462 ACPI_PHYSICAL_ADDRESS *NewAddress,
463 UINT32 *NewTableLength)
470 /******************************************************************************
472 * FUNCTION: AcpiOsEnterSleep
474 * PARAMETERS: SleepState - Which sleep state to enter
475 * RegaValue - Register A value
476 * RegbValue - Register B value
480 * DESCRIPTION: A hook before writing sleep registers to enter the sleep
481 * state. Return AE_CTRL_TERMINATE to skip further sleep register
484 *****************************************************************************/
497 /******************************************************************************
499 * FUNCTION: AcpiOsRedirectOutput
501 * PARAMETERS: Destination - An open file handle/pointer
505 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
507 *****************************************************************************/
510 AcpiOsRedirectOutput (
514 AcpiGbl_OutputFile = Destination;
518 /******************************************************************************
520 * FUNCTION: AcpiOsPrintf
522 * PARAMETERS: fmt, ... - Standard printf format
526 * DESCRIPTION: Formatted output. Note: very similar to AcpiOsVprintf
527 * (performance), changes should be tracked in both functions.
529 *****************************************************************************/
531 void ACPI_INTERNAL_VAR_XFACE
540 Flags = AcpiGbl_DbOutputFlags;
541 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
543 /* Output is directable to either a file (if open) or the console */
545 if (AcpiGbl_DebugFile)
547 /* Output file is open, send the output there */
549 va_start (Args, Fmt);
550 vfprintf (AcpiGbl_DebugFile, Fmt, Args);
555 /* No redirection, send output to console (once only!) */
557 Flags |= ACPI_DB_CONSOLE_OUTPUT;
561 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
563 va_start (Args, Fmt);
564 vfprintf (AcpiGbl_OutputFile, Fmt, Args);
570 /******************************************************************************
572 * FUNCTION: AcpiOsVprintf
574 * PARAMETERS: fmt - Standard printf format
575 * args - Argument list
579 * DESCRIPTION: Formatted output with argument list pointer. Note: very
580 * similar to AcpiOsPrintf, changes should be tracked in both
583 *****************************************************************************/
591 char Buffer[ACPI_VPRINTF_BUFFER_SIZE];
595 * We build the output string in a local buffer because we may be
596 * outputting the buffer twice. Using vfprintf is problematic because
597 * some implementations modify the args pointer/structure during
598 * execution. Thus, we use the local buffer for portability.
600 * Note: Since this module is intended for use by the various ACPICA
601 * utilities/applications, we can safely declare the buffer on the stack.
602 * Also, This function is used for relatively small error messages only.
604 vsnprintf (Buffer, ACPI_VPRINTF_BUFFER_SIZE, Fmt, Args);
606 Flags = AcpiGbl_DbOutputFlags;
607 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
609 /* Output is directable to either a file (if open) or the console */
611 if (AcpiGbl_DebugFile)
613 /* Output file is open, send the output there */
615 fputs (Buffer, AcpiGbl_DebugFile);
619 /* No redirection, send output to console (once only!) */
621 Flags |= ACPI_DB_CONSOLE_OUTPUT;
625 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
627 fputs (Buffer, AcpiGbl_OutputFile);
632 #ifndef ACPI_EXEC_APP
633 /******************************************************************************
635 * FUNCTION: AcpiOsGetLine
637 * PARAMETERS: Buffer - Where to return the command line
638 * BufferLength - Maximum length of Buffer
639 * BytesRead - Where the actual byte count is returned
641 * RETURN: Status and actual bytes read
643 * DESCRIPTION: Get the next input line from the terminal. NOTE: For the
644 * AcpiExec utility, we use the acgetline module instead to
645 * provide line-editing and history support.
647 *****************************************************************************/
659 /* Standard AcpiOsGetLine for all utilities except AcpiExec */
661 for (EndOfLine = 0; ; EndOfLine++)
663 if (EndOfLine >= BufferLength)
665 return (AE_BUFFER_OVERFLOW);
668 if ((InputChar = getchar ()) == EOF)
673 if (!InputChar || InputChar == _ASCII_NEWLINE)
678 Buffer[EndOfLine] = (char) InputChar;
681 /* Null terminate the buffer */
683 Buffer[EndOfLine] = 0;
685 /* Return the number of bytes in the string */
689 *BytesRead = EndOfLine;
697 #ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
698 /******************************************************************************
700 * FUNCTION: AcpiOsMapMemory
702 * PARAMETERS: where - Physical address of memory to be mapped
703 * length - How much memory to map
705 * RETURN: Pointer to mapped memory. Null on error.
707 * DESCRIPTION: Map physical memory into caller's address space
709 *****************************************************************************/
713 ACPI_PHYSICAL_ADDRESS where,
717 return (ACPI_TO_POINTER ((ACPI_SIZE) where));
721 /******************************************************************************
723 * FUNCTION: AcpiOsUnmapMemory
725 * PARAMETERS: where - Logical address of memory to be unmapped
726 * length - How much memory to unmap
730 * DESCRIPTION: Delete a previously created mapping. Where and Length must
731 * correspond to a previous mapping exactly.
733 *****************************************************************************/
746 /******************************************************************************
748 * FUNCTION: AcpiOsAllocate
750 * PARAMETERS: Size - Amount to allocate, in bytes
752 * RETURN: Pointer to the new allocation. Null on error.
754 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
756 *****************************************************************************/
765 Mem = (void *) malloc ((size_t) size);
770 #ifdef USE_NATIVE_ALLOCATE_ZEROED
771 /******************************************************************************
773 * FUNCTION: AcpiOsAllocateZeroed
775 * PARAMETERS: Size - Amount to allocate, in bytes
777 * RETURN: Pointer to the new allocation. Null on error.
779 * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
781 *****************************************************************************/
784 AcpiOsAllocateZeroed (
790 Mem = (void *) calloc (1, (size_t) size);
796 /******************************************************************************
798 * FUNCTION: AcpiOsFree
800 * PARAMETERS: mem - Pointer to previously allocated memory
804 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
806 *****************************************************************************/
817 #ifdef ACPI_SINGLE_THREADED
818 /******************************************************************************
820 * FUNCTION: Semaphore stub functions
822 * DESCRIPTION: Stub functions used for single-thread applications that do
823 * not require semaphore synchronization. Full implementations
824 * of these functions appear after the stubs.
826 *****************************************************************************/
829 AcpiOsCreateSemaphore (
832 ACPI_HANDLE *OutHandle)
834 *OutHandle = (ACPI_HANDLE) 1;
839 AcpiOsDeleteSemaphore (
846 AcpiOsWaitSemaphore (
855 AcpiOsSignalSemaphore (
863 /******************************************************************************
865 * FUNCTION: AcpiOsCreateSemaphore
867 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore
868 * OutHandle - Where a handle will be returned
872 * DESCRIPTION: Create an OS semaphore
874 *****************************************************************************/
877 AcpiOsCreateSemaphore (
880 ACPI_HANDLE *OutHandle)
887 return (AE_BAD_PARAMETER);
892 static int SemaphoreCount = 0;
893 char SemaphoreName[32];
895 snprintf (SemaphoreName, sizeof (SemaphoreName), "acpi_sem_%d",
897 printf ("%s\n", SemaphoreName);
898 Sem = sem_open (SemaphoreName, O_EXCL|O_CREAT, 0755, InitialUnits);
901 return (AE_NO_MEMORY);
903 sem_unlink (SemaphoreName); /* This just deletes the name */
907 Sem = AcpiOsAllocate (sizeof (sem_t));
910 return (AE_NO_MEMORY);
913 if (sem_init (Sem, 0, InitialUnits) == -1)
916 return (AE_BAD_PARAMETER);
920 *OutHandle = (ACPI_HANDLE) Sem;
925 /******************************************************************************
927 * FUNCTION: AcpiOsDeleteSemaphore
929 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
933 * DESCRIPTION: Delete an OS semaphore
935 *****************************************************************************/
938 AcpiOsDeleteSemaphore (
941 sem_t *Sem = (sem_t *) Handle;
946 return (AE_BAD_PARAMETER);
950 if (sem_close (Sem) == -1)
952 return (AE_BAD_PARAMETER);
955 if (sem_destroy (Sem) == -1)
957 return (AE_BAD_PARAMETER);
965 /******************************************************************************
967 * FUNCTION: AcpiOsWaitSemaphore
969 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
970 * Units - How many units to wait for
971 * MsecTimeout - How long to wait (milliseconds)
975 * DESCRIPTION: Wait for units
977 *****************************************************************************/
980 AcpiOsWaitSemaphore (
985 ACPI_STATUS Status = AE_OK;
986 sem_t *Sem = (sem_t *) Handle;
988 #ifndef ACPI_USE_ALTERNATE_TIMEOUT
989 struct timespec Time;
995 return (AE_BAD_PARAMETER);
1003 * A zero timeout value indicates that we shouldn't wait - just
1004 * acquire the semaphore if available otherwise return AE_TIME
1005 * (a.k.a. 'would block').
1009 if (sem_trywait(Sem) == -1)
1015 /* Wait Indefinitely */
1017 case ACPI_WAIT_FOREVER:
1019 while (((RetVal = sem_wait (Sem)) == -1) && (errno == EINTR))
1021 continue; /* Restart if interrupted */
1030 /* Wait with MsecTimeout */
1034 #ifdef ACPI_USE_ALTERNATE_TIMEOUT
1036 * Alternate timeout mechanism for environments where
1037 * sem_timedwait is not available or does not work properly.
1041 if (sem_trywait (Sem) == 0)
1043 /* Got the semaphore */
1047 if (MsecTimeout >= 10)
1050 usleep (10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */
1055 usleep (ACPI_USEC_PER_MSEC); /* one millisecond */
1061 * The interface to sem_timedwait is an absolute time, so we need to
1062 * get the current time, then add in the millisecond Timeout value.
1064 if (clock_gettime (CLOCK_REALTIME, &Time) == -1)
1066 perror ("clock_gettime");
1070 Time.tv_sec += (MsecTimeout / ACPI_MSEC_PER_SEC);
1071 Time.tv_nsec += ((MsecTimeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC);
1073 /* Handle nanosecond overflow (field must be less than one second) */
1075 if (Time.tv_nsec >= ACPI_NSEC_PER_SEC)
1077 Time.tv_sec += (Time.tv_nsec / ACPI_NSEC_PER_SEC);
1078 Time.tv_nsec = (Time.tv_nsec % ACPI_NSEC_PER_SEC);
1081 while (((RetVal = sem_timedwait (Sem, &Time)) == -1) && (errno == EINTR))
1083 continue; /* Restart if interrupted */
1089 if (errno != ETIMEDOUT)
1091 perror ("sem_timedwait");
1103 /******************************************************************************
1105 * FUNCTION: AcpiOsSignalSemaphore
1107 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
1108 * Units - Number of units to send
1112 * DESCRIPTION: Send units
1114 *****************************************************************************/
1117 AcpiOsSignalSemaphore (
1121 sem_t *Sem = (sem_t *)Handle;
1126 return (AE_BAD_PARAMETER);
1129 if (sem_post (Sem) == -1)
1137 #endif /* ACPI_SINGLE_THREADED */
1140 /******************************************************************************
1142 * FUNCTION: Spinlock interfaces
1144 * DESCRIPTION: Map these interfaces to semaphore interfaces
1146 *****************************************************************************/
1150 ACPI_SPINLOCK *OutHandle)
1153 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
1159 ACPI_SPINLOCK Handle)
1161 AcpiOsDeleteSemaphore (Handle);
1169 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
1176 ACPI_SPINLOCK Handle,
1177 ACPI_CPU_FLAGS Flags)
1179 AcpiOsSignalSemaphore (Handle, 1);
1183 /******************************************************************************
1185 * FUNCTION: AcpiOsInstallInterruptHandler
1187 * PARAMETERS: InterruptNumber - Level handler should respond to.
1188 * Isr - Address of the ACPI interrupt handler
1189 * ExceptPtr - Where status is returned
1191 * RETURN: Handle to the newly installed handler.
1193 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
1194 * OS-independent handler.
1196 *****************************************************************************/
1199 AcpiOsInstallInterruptHandler (
1200 UINT32 InterruptNumber,
1201 ACPI_OSD_HANDLER ServiceRoutine,
1209 /******************************************************************************
1211 * FUNCTION: AcpiOsRemoveInterruptHandler
1213 * PARAMETERS: Handle - Returned when handler was installed
1217 * DESCRIPTION: Uninstalls an interrupt handler.
1219 *****************************************************************************/
1222 AcpiOsRemoveInterruptHandler (
1223 UINT32 InterruptNumber,
1224 ACPI_OSD_HANDLER ServiceRoutine)
1231 /******************************************************************************
1233 * FUNCTION: AcpiOsStall
1235 * PARAMETERS: microseconds - Time to sleep
1237 * RETURN: Blocks until sleep is completed.
1239 * DESCRIPTION: Sleep at microsecond granularity
1241 *****************************************************************************/
1245 UINT32 microseconds)
1250 usleep (microseconds);
1255 /******************************************************************************
1257 * FUNCTION: AcpiOsSleep
1259 * PARAMETERS: milliseconds - Time to sleep
1261 * RETURN: Blocks until sleep is completed.
1263 * DESCRIPTION: Sleep at millisecond granularity
1265 *****************************************************************************/
1269 UINT64 milliseconds)
1272 /* Sleep for whole seconds */
1274 sleep (milliseconds / ACPI_MSEC_PER_SEC);
1277 * Sleep for remaining microseconds.
1278 * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second).
1280 usleep ((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC);
1284 /******************************************************************************
1286 * FUNCTION: AcpiOsGetTimer
1290 * RETURN: Current time in 100 nanosecond units
1292 * DESCRIPTION: Get the current system time
1294 *****************************************************************************/
1300 struct timeval time;
1303 /* This timer has sufficient resolution for user-space application code */
1305 gettimeofday (&time, NULL);
1307 /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */
1309 return (((UINT64) time.tv_sec * ACPI_100NSEC_PER_SEC) +
1310 ((UINT64) time.tv_usec * ACPI_100NSEC_PER_USEC));
1314 /******************************************************************************
1316 * FUNCTION: AcpiOsReadPciConfiguration
1318 * PARAMETERS: PciId - Seg/Bus/Dev
1319 * PciRegister - Device Register
1320 * Value - Buffer where value is placed
1321 * Width - Number of bits
1325 * DESCRIPTION: Read data from PCI configuration space
1327 *****************************************************************************/
1330 AcpiOsReadPciConfiguration (
1342 /******************************************************************************
1344 * FUNCTION: AcpiOsWritePciConfiguration
1346 * PARAMETERS: PciId - Seg/Bus/Dev
1347 * PciRegister - Device Register
1348 * Value - Value to be written
1349 * Width - Number of bits
1353 * DESCRIPTION: Write data to PCI configuration space
1355 *****************************************************************************/
1358 AcpiOsWritePciConfiguration (
1369 /******************************************************************************
1371 * FUNCTION: AcpiOsReadPort
1373 * PARAMETERS: Address - Address of I/O port/register to read
1374 * Value - Where value is placed
1375 * Width - Number of bits
1377 * RETURN: Value read from port
1379 * DESCRIPTION: Read data from an I/O port or register
1381 *****************************************************************************/
1385 ACPI_IO_ADDRESS Address,
1404 *Value = 0xFFFFFFFF;
1409 return (AE_BAD_PARAMETER);
1416 /******************************************************************************
1418 * FUNCTION: AcpiOsWritePort
1420 * PARAMETERS: Address - Address of I/O port/register to write
1421 * Value - Value to write
1422 * Width - Number of bits
1426 * DESCRIPTION: Write data to an I/O port or register
1428 *****************************************************************************/
1432 ACPI_IO_ADDRESS Address,
1441 /******************************************************************************
1443 * FUNCTION: AcpiOsReadMemory
1445 * PARAMETERS: Address - Physical Memory Address to read
1446 * Value - Where value is placed
1447 * Width - Number of bits (8,16,32, or 64)
1449 * RETURN: Value read from physical memory address. Always returned
1450 * as a 64-bit integer, regardless of the read width.
1452 * DESCRIPTION: Read data from a physical memory address
1454 *****************************************************************************/
1458 ACPI_PHYSICAL_ADDRESS Address,
1475 return (AE_BAD_PARAMETER);
1481 /******************************************************************************
1483 * FUNCTION: AcpiOsWriteMemory
1485 * PARAMETERS: Address - Physical Memory Address to write
1486 * Value - Value to write
1487 * Width - Number of bits (8,16,32, or 64)
1491 * DESCRIPTION: Write data to a physical memory address
1493 *****************************************************************************/
1497 ACPI_PHYSICAL_ADDRESS Address,
1506 /******************************************************************************
1508 * FUNCTION: AcpiOsReadable
1510 * PARAMETERS: Pointer - Area to be verified
1511 * Length - Size of area
1513 * RETURN: TRUE if readable for entire length
1515 * DESCRIPTION: Verify that a pointer is valid for reading
1517 *****************************************************************************/
1529 /******************************************************************************
1531 * FUNCTION: AcpiOsWritable
1533 * PARAMETERS: Pointer - Area to be verified
1534 * Length - Size of area
1536 * RETURN: TRUE if writable for entire length
1538 * DESCRIPTION: Verify that a pointer is valid for writing
1540 *****************************************************************************/
1552 /******************************************************************************
1554 * FUNCTION: AcpiOsSignal
1556 * PARAMETERS: Function - ACPI A signal function code
1557 * Info - Pointer to function-dependent structure
1561 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1563 *****************************************************************************/
1573 case ACPI_SIGNAL_FATAL:
1577 case ACPI_SIGNAL_BREAKPOINT:
1589 /* Optional multi-thread support */
1591 #ifndef ACPI_SINGLE_THREADED
1592 /******************************************************************************
1594 * FUNCTION: AcpiOsGetThreadId
1598 * RETURN: Id of the running thread
1600 * DESCRIPTION: Get the ID of the current (running) thread
1602 *****************************************************************************/
1611 thread = pthread_self();
1612 return (ACPI_CAST_PTHREAD_T (thread));
1616 /******************************************************************************
1618 * FUNCTION: AcpiOsExecute
1620 * PARAMETERS: Type - Type of execution
1621 * Function - Address of the function to execute
1622 * Context - Passed as a parameter to the function
1626 * DESCRIPTION: Execute a new thread
1628 *****************************************************************************/
1632 ACPI_EXECUTE_TYPE Type,
1633 ACPI_OSD_EXEC_CALLBACK Function,
1640 ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context);
1643 AcpiOsPrintf("Create thread failed");
1648 #else /* ACPI_SINGLE_THREADED */
1658 ACPI_EXECUTE_TYPE Type,
1659 ACPI_OSD_EXEC_CALLBACK Function,
1668 #endif /* ACPI_SINGLE_THREADED */
1671 /******************************************************************************
1673 * FUNCTION: AcpiOsWaitEventsComplete
1679 * DESCRIPTION: Wait for all asynchronous events to complete. This
1680 * implementation does nothing.
1682 *****************************************************************************/
1685 AcpiOsWaitEventsComplete (