1 /******************************************************************************
3 * Module Name: osunixxf - UNIX OSL interfaces
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2005, 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
126 #include <sys/time.h>
128 #include <contrib/dev/acpica/acpi.h>
129 #include <contrib/dev/acpica/amlcode.h>
130 #include <contrib/dev/acpica/acparser.h>
131 #include <contrib/dev/acpica/acdebug.h>
133 #include <contrib/dev/acpica/compiler/aslcompiler.h>
135 #define _COMPONENT ACPI_OS_SERVICES
136 ACPI_MODULE_NAME ("osunixxf")
139 extern FILE *AcpiGbl_DebugFile;
140 FILE *AcpiGbl_OutputFile;
143 /******************************************************************************
145 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate
151 * DESCRIPTION: Init and terminate. Nothing to do.
153 *****************************************************************************/
156 AcpiOsInitialize (void)
158 AcpiGbl_OutputFile = stdout;
165 AcpiOsTerminate (void)
171 /******************************************************************************
173 * FUNCTION: AcpiOsGetRootPointer
175 * PARAMETERS: Flags - Logical or physical addressing mode
176 * Address - Where the address is returned
180 * DESCRIPTION: Gets the root pointer (RSDP)
182 *****************************************************************************/
185 AcpiOsGetRootPointer (
187 ACPI_POINTER *Address)
190 return (AeLocalGetRootPointer(Flags, (ACPI_PHYSICAL_ADDRESS *) Address));
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
204 * DESCRIPTION: Allow the OS to override predefined names
206 *****************************************************************************/
209 AcpiOsPredefinedOverride (
210 const ACPI_PREDEFINED_NAMES *InitVal,
214 if (!InitVal || !NewVal)
216 return (AE_BAD_PARAMETER);
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 *****************************************************************************/
239 AcpiOsTableOverride (
240 ACPI_TABLE_HEADER *ExistingTable,
241 ACPI_TABLE_HEADER **NewTable)
244 if (!ExistingTable || !NewTable)
246 return (AE_BAD_PARAMETER);
253 /* This code exercises the table override mechanism in the core */
255 if (!ACPI_STRNCMP (ExistingTable->Signature, DSDT_SIG, ACPI_NAME_SIZE))
257 /* override DSDT with itself */
259 *NewTable = AcpiGbl_DbTablePtr;
263 return AE_NO_ACPI_TABLES;
268 /******************************************************************************
270 * FUNCTION: AcpiOsReadable
272 * PARAMETERS: Pointer - Area to be verified
273 * Length - Size of area
275 * RETURN: TRUE if readable for entire length
277 * DESCRIPTION: Verify that a pointer is valid for reading
279 *****************************************************************************/
291 /******************************************************************************
293 * FUNCTION: AcpiOsWritable
295 * PARAMETERS: Pointer - Area to be verified
296 * Length - Size of area
298 * RETURN: TRUE if writable for entire length
300 * DESCRIPTION: Verify that a pointer is valid for writing
302 *****************************************************************************/
314 /******************************************************************************
316 * FUNCTION: AcpiOsRedirectOutput
318 * PARAMETERS: Destination - An open file handle/pointer
322 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
324 *****************************************************************************/
327 AcpiOsRedirectOutput (
331 AcpiGbl_OutputFile = Destination;
335 /******************************************************************************
337 * FUNCTION: AcpiOsPrintf
339 * PARAMETERS: fmt, ... Standard printf format
343 * DESCRIPTION: Formatted output
345 *****************************************************************************/
347 void ACPI_INTERNAL_VAR_XFACE
355 va_start (Args, Fmt);
357 AcpiOsVprintf (Fmt, Args);
364 /******************************************************************************
366 * FUNCTION: AcpiOsVprintf
368 * PARAMETERS: fmt Standard printf format
373 * DESCRIPTION: Formatted output with argument list pointer
375 *****************************************************************************/
386 Flags = AcpiGbl_DbOutputFlags;
387 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
389 /* Output is directable to either a file (if open) or the console */
391 if (AcpiGbl_DebugFile)
393 /* Output file is open, send the output there */
395 Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
399 /* No redirection, send output to console (once only!) */
401 Flags |= ACPI_DB_CONSOLE_OUTPUT;
405 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
407 Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
414 /******************************************************************************
416 * FUNCTION: AcpiOsGetLine
418 * PARAMETERS: fmt Standard printf format
421 * RETURN: Actual bytes read
423 * DESCRIPTION: Formatted input with argument list pointer
425 *****************************************************************************/
437 scanf ("%1c", &Temp);
438 if (!Temp || Temp == '\n')
446 /* Null terminate the buffer */
450 /* Return the number of bytes in the string */
455 /******************************************************************************
457 * FUNCTION: AcpiOsMapMemory
459 * PARAMETERS: where Physical address of memory to be mapped
460 * length How much memory to map
461 * there Logical address of mapped memory
463 * RETURN: Pointer to mapped memory. Null on error.
465 * DESCRIPTION: Map physical memory into caller's address space
467 *****************************************************************************/
471 ACPI_PHYSICAL_ADDRESS where,
475 *there = ACPI_TO_POINTER (where);
481 /******************************************************************************
483 * FUNCTION: AcpiOsUnmapMemory
485 * PARAMETERS: where Logical address of memory to be unmapped
486 * length How much memory to unmap
490 * DESCRIPTION: Delete a previously created mapping. Where and Length must
491 * correspond to a previous mapping exactly.
493 *****************************************************************************/
505 /******************************************************************************
507 * FUNCTION: AcpiOsAllocate
509 * PARAMETERS: Size Amount to allocate, in bytes
511 * RETURN: Pointer to the new allocation. Null on error.
513 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
515 *****************************************************************************/
524 Mem = (void *) malloc ((size_t) size);
530 /******************************************************************************
532 * FUNCTION: AcpiOsFree
534 * PARAMETERS: mem Pointer to previously allocated memory
538 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
540 *****************************************************************************/
552 /******************************************************************************
554 * FUNCTION: AcpiOsCreateSemaphore
556 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore
557 * OutHandle - Where a handle will be returned
561 * DESCRIPTION: Create an OS semaphore
563 *****************************************************************************/
566 AcpiOsCreateSemaphore (
569 ACPI_HANDLE *OutHandle)
573 *OutHandle = (ACPI_HANDLE) 1;
577 /******************************************************************************
579 * FUNCTION: AcpiOsDeleteSemaphore
581 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
585 * DESCRIPTION: Delete an OS semaphore
587 *****************************************************************************/
590 AcpiOsDeleteSemaphore (
596 return AE_BAD_PARAMETER;
603 /******************************************************************************
605 * FUNCTION: AcpiOsWaitSemaphore
607 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
608 * Units - How many units to wait for
609 * Timeout - How long to wait
613 * DESCRIPTION: Wait for units
615 *****************************************************************************/
618 AcpiOsWaitSemaphore (
629 /******************************************************************************
631 * FUNCTION: AcpiOsSignalSemaphore
633 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
634 * Units - Number of units to send
638 * DESCRIPTION: Send units
640 *****************************************************************************/
643 AcpiOsSignalSemaphore (
655 ACPI_HANDLE *OutHandle)
658 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
665 AcpiOsDeleteSemaphore (Handle);
673 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
681 ACPI_NATIVE_UINT Flags)
683 AcpiOsSignalSemaphore (Handle, 1);
687 /******************************************************************************
689 * FUNCTION: AcpiOsInstallInterruptHandler
691 * PARAMETERS: InterruptNumber Level handler should respond to.
692 * Isr Address of the ACPI interrupt handler
693 * ExceptPtr Where status is returned
695 * RETURN: Handle to the newly installed handler.
697 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
698 * OS-independent handler.
700 *****************************************************************************/
703 AcpiOsInstallInterruptHandler (
704 UINT32 InterruptNumber,
705 ACPI_OSD_HANDLER ServiceRoutine,
714 /******************************************************************************
716 * FUNCTION: AcpiOsRemoveInterruptHandler
718 * PARAMETERS: Handle Returned when handler was installed
722 * DESCRIPTION: Uninstalls an interrupt handler.
724 *****************************************************************************/
727 AcpiOsRemoveInterruptHandler (
728 UINT32 InterruptNumber,
729 ACPI_OSD_HANDLER ServiceRoutine)
736 /******************************************************************************
738 * FUNCTION: AcpiOsQueueForExecution
740 * PARAMETERS: Priority - Requested execution priority
741 * Function - Address of the function to execute
742 * Context - Passed as a parameter to the function
746 * DESCRIPTION: Sleep at microsecond granularity
748 *****************************************************************************/
751 AcpiOsQueueForExecution (
753 ACPI_OSD_EXEC_CALLBACK Function,
757 // _beginthread (Function, (unsigned) 0, Context);
762 /******************************************************************************
764 * FUNCTION: AcpiOsBreakpoint
766 * PARAMETERS: Msg Message to print
770 * DESCRIPTION: Print a message and break to the debugger.
772 *****************************************************************************/
779 /* Print the message and do an INT 3 */
783 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Msg);
787 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
795 /******************************************************************************
797 * FUNCTION: AcpiOsStall
799 * PARAMETERS: microseconds To sleep
801 * RETURN: Blocks until sleep is completed.
803 * DESCRIPTION: Sleep at microsecond granularity
805 *****************************************************************************/
814 usleep (microseconds);
820 /******************************************************************************
822 * FUNCTION: AcpiOsSleep
824 * PARAMETERS: milliseconds To sleep
826 * RETURN: Blocks until sleep is completed.
828 * DESCRIPTION: Sleep at millisecond granularity
830 *****************************************************************************/
834 ACPI_INTEGER milliseconds)
837 sleep (milliseconds / 1000); /* Sleep for whole seconds */
840 * Arg to usleep() must be less than 1,000,000 (1 second)
842 usleep ((milliseconds % 1000) * 1000); /* Sleep for remaining usecs */
847 /******************************************************************************
849 * FUNCTION: AcpiOsGetTimer
853 * RETURN: Current time in 100 nanosecond units
855 * DESCRIPTION: Get the current system time
857 *****************************************************************************/
860 AcpiOsGetTimer (void)
864 gettimeofday(&time, NULL);
866 /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
868 return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10));
872 /******************************************************************************
874 * FUNCTION: AcpiOsReadPciConfiguration
876 * PARAMETERS: PciId Seg/Bus/Dev
877 * Register Device Register
878 * Value Buffer where value is placed
879 * Width Number of bits
883 * DESCRIPTION: Read data from PCI configuration space
885 *****************************************************************************/
888 AcpiOsReadPciConfiguration (
899 /******************************************************************************
901 * FUNCTION: AcpiOsWritePciConfiguration
903 * PARAMETERS: PciId Seg/Bus/Dev
904 * Register Device Register
905 * Value Value to be written
906 * Width Number of bits
910 * DESCRIPTION: Write data to PCI configuration space
912 *****************************************************************************/
915 AcpiOsWritePciConfiguration (
925 /* TEMPORARY STUB FUNCTION */
936 /******************************************************************************
938 * FUNCTION: AcpiOsReadPort
940 * PARAMETERS: Address Address of I/O port/register to read
941 * Value Where value is placed
942 * Width Number of bits
944 * RETURN: Value read from port
946 * DESCRIPTION: Read data from an I/O port or register
948 *****************************************************************************/
952 ACPI_IO_ADDRESS Address,
976 /******************************************************************************
978 * FUNCTION: AcpiOsWritePort
980 * PARAMETERS: Address Address of I/O port/register to write
981 * Value Value to write
982 * Width Number of bits
986 * DESCRIPTION: Write data to an I/O port or register
988 *****************************************************************************/
992 ACPI_IO_ADDRESS Address,
1001 /******************************************************************************
1003 * FUNCTION: AcpiOsReadMemory
1005 * PARAMETERS: Address Physical Memory Address to read
1006 * Value Where value is placed
1007 * Width Number of bits
1009 * RETURN: Value read from physical memory address
1011 * DESCRIPTION: Read data from a physical memory address
1013 *****************************************************************************/
1017 ACPI_PHYSICAL_ADDRESS Address,
1031 return (AE_BAD_PARAMETER);
1038 /******************************************************************************
1040 * FUNCTION: AcpiOsWriteMemory
1042 * PARAMETERS: Address Physical Memory Address to write
1043 * Value Value to write
1044 * Width Number of bits
1048 * DESCRIPTION: Write data to a physical memory address
1050 *****************************************************************************/
1054 ACPI_PHYSICAL_ADDRESS Address,
1064 AcpiOsGetThreadId(void)
1070 /******************************************************************************
1072 * FUNCTION: AcpiOsSignal
1074 * PARAMETERS: Function ACPI CA signal function code
1075 * Info Pointer to function-dependent structure
1079 * DESCRIPTION: Miscellaneous functions
1081 *****************************************************************************/
1091 case ACPI_SIGNAL_FATAL:
1094 case ACPI_SIGNAL_BREAKPOINT:
1098 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Info);
1102 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");