1 /******************************************************************************
3 * Module Name: osunixxf - UNIX OSL interfaces
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
118 * These interfaces are required in order to compile the ASL compiler under
119 * Linux or other Unix-like system.
126 #include <sys/time.h>
127 #include <semaphore.h>
131 #include "accommon.h"
133 #include "acparser.h"
136 #define _COMPONENT ACPI_OS_SERVICES
137 ACPI_MODULE_NAME ("osunixxf")
140 extern FILE *AcpiGbl_DebugFile
;
141 FILE *AcpiGbl_OutputFile
;
144 /* Upcalls to AcpiExec */
146 ACPI_PHYSICAL_ADDRESS
147 AeLocalGetRootPointer (
152 ACPI_TABLE_HEADER
*ExistingTable
,
153 ACPI_TABLE_HEADER
**NewTable
);
155 typedef void* (*PTHREAD_CALLBACK
) (void *);
158 /******************************************************************************
160 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate
166 * DESCRIPTION: Init and terminate. Nothing to do.
168 *****************************************************************************/
171 AcpiOsInitialize (void)
174 AcpiGbl_OutputFile
= stdout
;
180 AcpiOsTerminate (void)
187 /******************************************************************************
189 * FUNCTION: AcpiOsGetRootPointer
193 * RETURN: RSDP physical address
195 * DESCRIPTION: Gets the root pointer (RSDP)
197 *****************************************************************************/
199 ACPI_PHYSICAL_ADDRESS
200 AcpiOsGetRootPointer (
204 return (AeLocalGetRootPointer ());
208 /******************************************************************************
210 * FUNCTION: AcpiOsPredefinedOverride
212 * PARAMETERS: InitVal - Initial value of the predefined object
213 * NewVal - The new value for the object
215 * RETURN: Status, pointer to value. Null pointer returned if not
218 * DESCRIPTION: Allow the OS to override predefined names
220 *****************************************************************************/
223 AcpiOsPredefinedOverride (
224 const ACPI_PREDEFINED_NAMES
*InitVal
,
228 if (!InitVal
|| !NewVal
)
230 return (AE_BAD_PARAMETER
);
238 /******************************************************************************
240 * FUNCTION: AcpiOsTableOverride
242 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
243 * NewTable - Where an entire new table is returned.
245 * RETURN: Status, pointer to new table. Null pointer returned if no
246 * table is available to override
248 * DESCRIPTION: Return a different version of a table if one is available
250 *****************************************************************************/
253 AcpiOsTableOverride (
254 ACPI_TABLE_HEADER
*ExistingTable
,
255 ACPI_TABLE_HEADER
**NewTable
)
258 if (!ExistingTable
|| !NewTable
)
260 return (AE_BAD_PARAMETER
);
267 AeTableOverride (ExistingTable
, NewTable
);
271 return (AE_NO_ACPI_TABLES
);
276 /******************************************************************************
278 * FUNCTION: AcpiOsRedirectOutput
280 * PARAMETERS: Destination - An open file handle/pointer
284 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
286 *****************************************************************************/
289 AcpiOsRedirectOutput (
293 AcpiGbl_OutputFile
= Destination
;
297 /******************************************************************************
299 * FUNCTION: AcpiOsPrintf
301 * PARAMETERS: fmt, ... Standard printf format
305 * DESCRIPTION: Formatted output
307 *****************************************************************************/
309 void ACPI_INTERNAL_VAR_XFACE
317 va_start (Args
, Fmt
);
318 AcpiOsVprintf (Fmt
, Args
);
323 /******************************************************************************
325 * FUNCTION: AcpiOsVprintf
327 * PARAMETERS: fmt Standard printf format
332 * DESCRIPTION: Formatted output with argument list pointer
334 *****************************************************************************/
345 Flags
= AcpiGbl_DbOutputFlags
;
346 if (Flags
& ACPI_DB_REDIRECTABLE_OUTPUT
)
348 /* Output is directable to either a file (if open) or the console */
350 if (AcpiGbl_DebugFile
)
352 /* Output file is open, send the output there */
354 Count
= vfprintf (AcpiGbl_DebugFile
, Fmt
, Args
);
358 /* No redirection, send output to console (once only!) */
360 Flags
|= ACPI_DB_CONSOLE_OUTPUT
;
364 if (Flags
& ACPI_DB_CONSOLE_OUTPUT
)
366 Count
= vfprintf (AcpiGbl_OutputFile
, Fmt
, Args
);
371 /******************************************************************************
373 * FUNCTION: AcpiOsGetLine
375 * PARAMETERS: fmt Standard printf format
378 * RETURN: Actual bytes read
380 * DESCRIPTION: Formatted input with argument list pointer
382 *****************************************************************************/
394 scanf ("%1c", &Temp
);
395 if (!Temp
|| Temp
== '\n')
403 /* Null terminate the buffer */
407 /* Return the number of bytes in the string */
412 /******************************************************************************
414 * FUNCTION: AcpiOsMapMemory
416 * PARAMETERS: where Physical address of memory to be mapped
417 * length How much memory to map
419 * RETURN: Pointer to mapped memory. Null on error.
421 * DESCRIPTION: Map physical memory into caller's address space
423 *****************************************************************************/
427 ACPI_PHYSICAL_ADDRESS where
,
431 return (ACPI_TO_POINTER ((ACPI_SIZE
) where
));
435 /******************************************************************************
437 * FUNCTION: AcpiOsUnmapMemory
439 * PARAMETERS: where Logical address of memory to be unmapped
440 * length How much memory to unmap
444 * DESCRIPTION: Delete a previously created mapping. Where and Length must
445 * correspond to a previous mapping exactly.
447 *****************************************************************************/
459 /******************************************************************************
461 * FUNCTION: AcpiOsAllocate
463 * PARAMETERS: Size Amount to allocate, in bytes
465 * RETURN: Pointer to the new allocation. Null on error.
467 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
469 *****************************************************************************/
478 Mem
= (void *) malloc ((size_t) size
);
483 /******************************************************************************
485 * FUNCTION: AcpiOsFree
487 * PARAMETERS: mem Pointer to previously allocated memory
491 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
493 *****************************************************************************/
504 /******************************************************************************
506 * FUNCTION: AcpiOsCreateSemaphore
508 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore
509 * OutHandle - Where a handle will be returned
513 * DESCRIPTION: Create an OS semaphore
515 *****************************************************************************/
518 AcpiOsCreateSemaphore (
521 ACPI_HANDLE
*OutHandle
)
528 return (AE_BAD_PARAMETER
);
531 Sem
= AcpiOsAllocate (sizeof (sem_t
));
535 return (AE_NO_MEMORY
);
538 if (sem_init (Sem
, 0, InitialUnits
) == -1)
541 return (AE_BAD_PARAMETER
);
544 *OutHandle
= (ACPI_HANDLE
) Sem
;
549 /******************************************************************************
551 * FUNCTION: AcpiOsDeleteSemaphore
553 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
557 * DESCRIPTION: Delete an OS semaphore
559 *****************************************************************************/
562 AcpiOsDeleteSemaphore (
565 sem_t
*Sem
= (sem_t
*) Handle
;
570 return (AE_BAD_PARAMETER
);
573 if (sem_destroy (Sem
) == -1)
575 return (AE_BAD_PARAMETER
);
582 /******************************************************************************
584 * FUNCTION: AcpiOsWaitSemaphore
586 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
587 * Units - How many units to wait for
588 * Timeout - How long to wait
592 * DESCRIPTION: Wait for units
594 *****************************************************************************/
597 AcpiOsWaitSemaphore (
602 ACPI_STATUS Status
= AE_OK
;
603 sem_t
*Sem
= (sem_t
*) Handle
;
609 return (AE_BAD_PARAMETER
);
617 * A zero timeout value indicates that we shouldn't wait - just
618 * acquire the semaphore if available otherwise return AE_TIME
619 * (a.k.a. 'would block').
623 if (sem_trywait(Sem
) == -1)
629 /* Wait Indefinitely */
631 case ACPI_WAIT_FOREVER
:
639 /* Wait with Timeout */
643 T
.tv_sec
= Timeout
/ 1000;
644 T
.tv_nsec
= (Timeout
- (T
.tv_sec
* 1000)) * 1000000;
646 #ifdef ACPI_USE_ALTERNATE_TIMEOUT
648 * Alternate timeout mechanism for environments where
649 * sem_timedwait is not available or does not work properly.
653 if (sem_trywait (Sem
) == 0)
655 /* Got the semaphore */
658 usleep (1000); /* one millisecond */
664 if (sem_timedwait (Sem
, &T
))
677 /******************************************************************************
679 * FUNCTION: AcpiOsSignalSemaphore
681 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
682 * Units - Number of units to send
686 * DESCRIPTION: Send units
688 *****************************************************************************/
691 AcpiOsSignalSemaphore (
695 sem_t
*Sem
= (sem_t
*)Handle
;
700 return (AE_BAD_PARAMETER
);
703 if (sem_post (Sem
) == -1)
712 /******************************************************************************
714 * FUNCTION: Spinlock interfaces
716 * DESCRIPTION: Map these interfaces to semaphore interfaces
718 *****************************************************************************/
722 ACPI_SPINLOCK
*OutHandle
)
725 return (AcpiOsCreateSemaphore (1, 1, OutHandle
));
731 ACPI_SPINLOCK Handle
)
733 AcpiOsDeleteSemaphore (Handle
);
741 AcpiOsWaitSemaphore (Handle
, 1, 0xFFFF);
748 ACPI_SPINLOCK Handle
,
749 ACPI_CPU_FLAGS Flags
)
751 AcpiOsSignalSemaphore (Handle
, 1);
755 /******************************************************************************
757 * FUNCTION: AcpiOsInstallInterruptHandler
759 * PARAMETERS: InterruptNumber Level handler should respond to.
760 * Isr Address of the ACPI interrupt handler
761 * ExceptPtr Where status is returned
763 * RETURN: Handle to the newly installed handler.
765 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
766 * OS-independent handler.
768 *****************************************************************************/
771 AcpiOsInstallInterruptHandler (
772 UINT32 InterruptNumber
,
773 ACPI_OSD_HANDLER ServiceRoutine
,
781 /******************************************************************************
783 * FUNCTION: AcpiOsRemoveInterruptHandler
785 * PARAMETERS: Handle Returned when handler was installed
789 * DESCRIPTION: Uninstalls an interrupt handler.
791 *****************************************************************************/
794 AcpiOsRemoveInterruptHandler (
795 UINT32 InterruptNumber
,
796 ACPI_OSD_HANDLER ServiceRoutine
)
803 /******************************************************************************
805 * FUNCTION: AcpiOsExecute
807 * PARAMETERS: Type - Type of execution
808 * Function - Address of the function to execute
809 * Context - Passed as a parameter to the function
813 * DESCRIPTION: Execute a new thread
815 *****************************************************************************/
819 ACPI_EXECUTE_TYPE Type
,
820 ACPI_OSD_EXEC_CALLBACK Function
,
827 ret
= pthread_create (&thread
, NULL
, (PTHREAD_CALLBACK
) Function
, Context
);
830 AcpiOsPrintf("Create thread failed");
836 /******************************************************************************
838 * FUNCTION: AcpiOsStall
840 * PARAMETERS: microseconds To sleep
842 * RETURN: Blocks until sleep is completed.
844 * DESCRIPTION: Sleep at microsecond granularity
846 *****************************************************************************/
855 usleep (microseconds
);
860 /******************************************************************************
862 * FUNCTION: AcpiOsSleep
864 * PARAMETERS: milliseconds To sleep
866 * RETURN: Blocks until sleep is completed.
868 * DESCRIPTION: Sleep at millisecond granularity
870 *****************************************************************************/
874 ACPI_INTEGER milliseconds
)
877 sleep (milliseconds
/ 1000); /* Sleep for whole seconds */
880 * Arg to usleep() must be less than 1,000,000 (1 second)
882 usleep ((milliseconds
% 1000) * 1000); /* Sleep for remaining usecs */
885 /******************************************************************************
887 * FUNCTION: AcpiOsGetTimer
891 * RETURN: Current time in 100 nanosecond units
893 * DESCRIPTION: Get the current system time
895 *****************************************************************************/
898 AcpiOsGetTimer (void)
903 gettimeofday (&time
, NULL
);
905 /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
907 return (((UINT64
) time
.tv_sec
* 10000000) + ((UINT64
) time
.tv_usec
* 10));
911 /******************************************************************************
913 * FUNCTION: AcpiOsValidateInterface
915 * PARAMETERS: Interface - Requested interface to be validated
917 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
919 * DESCRIPTION: Match an interface string to the interfaces supported by the
920 * host. Strings originate from an AML call to the _OSI method.
922 *****************************************************************************/
925 AcpiOsValidateInterface (
933 /******************************************************************************
935 * FUNCTION: AcpiOsReadPciConfiguration
937 * PARAMETERS: PciId Seg/Bus/Dev
938 * Register Device Register
939 * Value Buffer where value is placed
940 * Width Number of bits
944 * DESCRIPTION: Read data from PCI configuration space
946 *****************************************************************************/
949 AcpiOsReadPciConfiguration (
960 /******************************************************************************
962 * FUNCTION: AcpiOsWritePciConfiguration
964 * PARAMETERS: PciId Seg/Bus/Dev
965 * Register Device Register
966 * Value Value to be written
967 * Width Number of bits
971 * DESCRIPTION: Write data to PCI configuration space
973 *****************************************************************************/
976 AcpiOsWritePciConfiguration (
986 /* TEMPORARY STUB FUNCTION */
997 /******************************************************************************
999 * FUNCTION: AcpiOsReadPort
1001 * PARAMETERS: Address Address of I/O port/register to read
1002 * Value Where value is placed
1003 * Width Number of bits
1005 * RETURN: Value read from port
1007 * DESCRIPTION: Read data from an I/O port or register
1009 *****************************************************************************/
1013 ACPI_IO_ADDRESS Address
,
1029 *Value
= 0xFFFFFFFF;
1033 return (AE_BAD_PARAMETER
);
1040 /******************************************************************************
1042 * FUNCTION: AcpiOsWritePort
1044 * PARAMETERS: Address Address of I/O port/register to write
1045 * Value Value to write
1046 * Width Number of bits
1050 * DESCRIPTION: Write data to an I/O port or register
1052 *****************************************************************************/
1056 ACPI_IO_ADDRESS Address
,
1065 /******************************************************************************
1067 * FUNCTION: AcpiOsReadMemory
1069 * PARAMETERS: Address Physical Memory Address to read
1070 * Value Where value is placed
1071 * Width Number of bits
1073 * RETURN: Value read from physical memory address
1075 * DESCRIPTION: Read data from a physical memory address
1077 *****************************************************************************/
1081 ACPI_PHYSICAL_ADDRESS Address
,
1095 return (AE_BAD_PARAMETER
);
1101 /******************************************************************************
1103 * FUNCTION: AcpiOsWriteMemory
1105 * PARAMETERS: Address Physical Memory Address to write
1106 * Value Value to write
1107 * Width Number of bits
1111 * DESCRIPTION: Write data to a physical memory address
1113 *****************************************************************************/
1117 ACPI_PHYSICAL_ADDRESS Address
,
1126 /******************************************************************************
1128 * FUNCTION: AcpiOsReadable
1130 * PARAMETERS: Pointer - Area to be verified
1131 * Length - Size of area
1133 * RETURN: TRUE if readable for entire length
1135 * DESCRIPTION: Verify that a pointer is valid for reading
1137 *****************************************************************************/
1149 /******************************************************************************
1151 * FUNCTION: AcpiOsWritable
1153 * PARAMETERS: Pointer - Area to be verified
1154 * Length - Size of area
1156 * RETURN: TRUE if writable for entire length
1158 * DESCRIPTION: Verify that a pointer is valid for writing
1160 *****************************************************************************/
1172 /******************************************************************************
1174 * FUNCTION: AcpiOsGetThreadId
1178 * RETURN: Id of the running thread
1180 * DESCRIPTION: Get the Id of the current (running) thread
1182 * NOTE: The environment header should contain this line:
1183 * #define ACPI_THREAD_ID pthread_t
1185 *****************************************************************************/
1188 AcpiOsGetThreadId (void)
1191 return (pthread_self ());
1195 /******************************************************************************
1197 * FUNCTION: AcpiOsSignal
1199 * PARAMETERS: Function ACPI CA signal function code
1200 * Info Pointer to function-dependent structure
1204 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1206 *****************************************************************************/
1216 case ACPI_SIGNAL_FATAL
:
1219 case ACPI_SIGNAL_BREAKPOINT
: