1 /******************************************************************************
3 * Module Name: osunixxf - UNIX OSL interfaces
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2004, 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>
130 #include "acparser.h"
133 #define _COMPONENT ACPI_OS_SERVICES
134 ACPI_MODULE_NAME ("osunixxf")
137 extern FILE *AcpiGbl_DebugFile;
138 FILE *AcpiGbl_OutputFile;
141 /******************************************************************************
143 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate
149 * DESCRIPTION: Init and terminate. Nothing to do.
151 *****************************************************************************/
154 AcpiOsInitialize (void)
156 AcpiGbl_OutputFile = stdout;
163 AcpiOsTerminate (void)
169 /******************************************************************************
171 * FUNCTION: AcpiOsGetRootPointer
173 * PARAMETERS: Flags - Logical or physical addressing mode
174 * Address - Where the address is returned
178 * DESCRIPTION: Gets the root pointer (RSDP)
180 *****************************************************************************/
183 AcpiOsGetRootPointer (
185 ACPI_POINTER *Address)
192 /******************************************************************************
194 * FUNCTION: AcpiOsPredefinedOverride
196 * PARAMETERS: InitVal - Initial value of the predefined object
197 * NewVal - The new value for the object
199 * RETURN: Status, pointer to value. Null pointer returned if not
202 * DESCRIPTION: Allow the OS to override predefined names
204 *****************************************************************************/
207 AcpiOsPredefinedOverride (
208 const ACPI_PREDEFINED_NAMES *InitVal,
212 if (!InitVal || !NewVal)
214 return (AE_BAD_PARAMETER);
222 /******************************************************************************
224 * FUNCTION: AcpiOsTableOverride
226 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
227 * NewTable - Where an entire new table is returned.
229 * RETURN: Status, pointer to new table. Null pointer returned if no
230 * table is available to override
232 * DESCRIPTION: Return a different version of a table if one is available
234 *****************************************************************************/
237 AcpiOsTableOverride (
238 ACPI_TABLE_HEADER *ExistingTable,
239 ACPI_TABLE_HEADER **NewTable)
241 if (!ExistingTable || !NewTable)
243 return (AE_BAD_PARAMETER);
246 /* TODO: Add table-getting code here */
248 return (AE_NO_ACPI_TABLES);
252 /******************************************************************************
254 * FUNCTION: AcpiOsReadable
256 * PARAMETERS: Pointer - Area to be verified
257 * Length - Size of area
259 * RETURN: TRUE if readable for entire length
261 * DESCRIPTION: Verify that a pointer is valid for reading
263 *****************************************************************************/
275 /******************************************************************************
277 * FUNCTION: AcpiOsWritable
279 * PARAMETERS: Pointer - Area to be verified
280 * Length - Size of area
282 * RETURN: TRUE if writable for entire length
284 * DESCRIPTION: Verify that a pointer is valid for writing
286 *****************************************************************************/
298 /******************************************************************************
300 * FUNCTION: AcpiOsRedirectOutput
302 * PARAMETERS: Destination - An open file handle/pointer
306 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
308 *****************************************************************************/
311 AcpiOsRedirectOutput (
315 AcpiGbl_OutputFile = Destination;
319 /******************************************************************************
321 * FUNCTION: AcpiOsPrintf
323 * PARAMETERS: fmt, ... Standard printf format
327 * DESCRIPTION: Formatted output
329 *****************************************************************************/
331 void ACPI_INTERNAL_VAR_XFACE
339 va_start (Args, Fmt);
341 AcpiOsVprintf (Fmt, Args);
348 /******************************************************************************
350 * FUNCTION: AcpiOsVprintf
352 * PARAMETERS: fmt Standard printf format
357 * DESCRIPTION: Formatted output with argument list pointer
359 *****************************************************************************/
370 Flags = AcpiGbl_DbOutputFlags;
371 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
373 /* Output is directable to either a file (if open) or the console */
375 if (AcpiGbl_DebugFile)
377 /* Output file is open, send the output there */
379 Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
383 /* No redirection, send output to console (once only!) */
385 Flags |= ACPI_DB_CONSOLE_OUTPUT;
389 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
391 Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
398 /******************************************************************************
400 * FUNCTION: AcpiOsGetLine
402 * PARAMETERS: fmt Standard printf format
405 * RETURN: Actual bytes read
407 * DESCRIPTION: Formatted input with argument list pointer
409 *****************************************************************************/
421 scanf ("%1c", &Temp);
422 if (!Temp || Temp == '\n')
430 /* Null terminate the buffer */
434 /* Return the number of bytes in the string */
439 /******************************************************************************
441 * FUNCTION: AcpiOsMapMemory
443 * PARAMETERS: where Physical address of memory to be mapped
444 * length How much memory to map
445 * there Logical address of mapped memory
447 * RETURN: Pointer to mapped memory. Null on error.
449 * DESCRIPTION: Map physical memory into caller's address space
451 *****************************************************************************/
455 ACPI_PHYSICAL_ADDRESS where,
459 *there = ACPI_TO_POINTER (where);
465 /******************************************************************************
467 * FUNCTION: AcpiOsUnmapMemory
469 * PARAMETERS: where Logical address of memory to be unmapped
470 * length How much memory to unmap
474 * DESCRIPTION: Delete a previously created mapping. Where and Length must
475 * correspond to a previous mapping exactly.
477 *****************************************************************************/
489 /******************************************************************************
491 * FUNCTION: AcpiOsAllocate
493 * PARAMETERS: Size Amount to allocate, in bytes
495 * RETURN: Pointer to the new allocation. Null on error.
497 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
499 *****************************************************************************/
508 Mem = (void *) malloc ((size_t) size);
514 /******************************************************************************
516 * FUNCTION: AcpiOsFree
518 * PARAMETERS: mem Pointer to previously allocated memory
522 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
524 *****************************************************************************/
536 /******************************************************************************
538 * FUNCTION: AcpiOsCreateSemaphore
540 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore
541 * OutHandle - Where a handle will be returned
545 * DESCRIPTION: Create an OS semaphore
547 *****************************************************************************/
550 AcpiOsCreateSemaphore (
553 ACPI_HANDLE *OutHandle)
557 *OutHandle = (ACPI_HANDLE) 1;
561 /******************************************************************************
563 * FUNCTION: AcpiOsDeleteSemaphore
565 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
569 * DESCRIPTION: Delete an OS semaphore
571 *****************************************************************************/
574 AcpiOsDeleteSemaphore (
580 return AE_BAD_PARAMETER;
587 /******************************************************************************
589 * FUNCTION: AcpiOsWaitSemaphore
591 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
592 * Units - How many units to wait for
593 * Timeout - How long to wait
597 * DESCRIPTION: Wait for units
599 *****************************************************************************/
602 AcpiOsWaitSemaphore (
613 /******************************************************************************
615 * FUNCTION: AcpiOsSignalSemaphore
617 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
618 * Units - Number of units to send
622 * DESCRIPTION: Send units
624 *****************************************************************************/
627 AcpiOsSignalSemaphore (
639 ACPI_HANDLE *OutHandle)
642 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
649 AcpiOsDeleteSemaphore (Handle);
658 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
667 AcpiOsSignalSemaphore (Handle, 1);
671 /******************************************************************************
673 * FUNCTION: AcpiOsInstallInterruptHandler
675 * PARAMETERS: InterruptNumber Level handler should respond to.
676 * Isr Address of the ACPI interrupt handler
677 * ExceptPtr Where status is returned
679 * RETURN: Handle to the newly installed handler.
681 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
682 * OS-independent handler.
684 *****************************************************************************/
687 AcpiOsInstallInterruptHandler (
688 UINT32 InterruptNumber,
689 OSD_HANDLER ServiceRoutine,
698 /******************************************************************************
700 * FUNCTION: AcpiOsRemoveInterruptHandler
702 * PARAMETERS: Handle Returned when handler was installed
706 * DESCRIPTION: Uninstalls an interrupt handler.
708 *****************************************************************************/
711 AcpiOsRemoveInterruptHandler (
712 UINT32 InterruptNumber,
713 OSD_HANDLER ServiceRoutine)
720 /******************************************************************************
722 * FUNCTION: AcpiOsQueueForExecution
724 * PARAMETERS: Priority - Requested execution priority
725 * Function - Address of the function to execute
726 * Context - Passed as a parameter to the function
730 * DESCRIPTION: Sleep at microsecond granularity
732 *****************************************************************************/
735 AcpiOsQueueForExecution (
737 OSD_EXECUTION_CALLBACK Function,
741 // _beginthread (Function, (unsigned) 0, Context);
746 /******************************************************************************
748 * FUNCTION: AcpiOsBreakpoint
750 * PARAMETERS: Msg Message to print
754 * DESCRIPTION: Print a message and break to the debugger.
756 *****************************************************************************/
763 /* Print the message and do an INT 3 */
767 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Msg);
771 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
779 /******************************************************************************
781 * FUNCTION: AcpiOsSleepUsec
783 * PARAMETERS: microseconds To sleep
785 * RETURN: Blocks until sleep is completed.
787 * DESCRIPTION: Sleep at microsecond granularity
789 *****************************************************************************/
798 usleep (microseconds);
804 /******************************************************************************
806 * FUNCTION: AcpiOsSleep
808 * PARAMETERS: seconds To sleep
809 * milliseconds To sleep
811 * RETURN: Blocks until sleep is completed.
813 * DESCRIPTION: Sleep at second/millisecond granularity
815 *****************************************************************************/
823 sleep (seconds + (milliseconds / 1000)); /* Sleep for whole seconds */
826 * Arg to usleep() must be less than 1,000,000 (1 second)
828 usleep ((milliseconds % 1000) * 1000); /* Sleep for remaining usecs */
833 /******************************************************************************
835 * FUNCTION: AcpiOsGetTimer
839 * RETURN: Current time in milliseconds
841 * DESCRIPTION: Get the current system time (in milliseconds).
843 *****************************************************************************/
846 AcpiOsGetTimer (void)
850 gettimeofday(&time, NULL);
852 return ((time.tv_sec/1000) + (time.tv_usec*1000));
856 /******************************************************************************
858 * FUNCTION: AcpiOsReadPciConfiguration
860 * PARAMETERS: PciId Seg/Bus/Dev
861 * Register Device Register
862 * Value Buffer where value is placed
863 * Width Number of bits
867 * DESCRIPTION: Read data from PCI configuration space
869 *****************************************************************************/
872 AcpiOsReadPciConfiguration (
883 /******************************************************************************
885 * FUNCTION: AcpiOsWritePciConfiguration
887 * PARAMETERS: PciId Seg/Bus/Dev
888 * Register Device Register
889 * Value Value to be written
890 * Width Number of bits
894 * DESCRIPTION: Write data to PCI configuration space
896 *****************************************************************************/
899 AcpiOsWritePciConfiguration (
909 /* TEMPORARY STUB FUNCTION */
920 /******************************************************************************
922 * FUNCTION: AcpiOsReadPort
924 * PARAMETERS: Address Address of I/O port/register to read
925 * Value Where value is placed
926 * Width Number of bits
928 * RETURN: Value read from port
930 * DESCRIPTION: Read data from an I/O port or register
932 *****************************************************************************/
936 ACPI_IO_ADDRESS Address,
960 /******************************************************************************
962 * FUNCTION: AcpiOsWritePort
964 * PARAMETERS: Address Address of I/O port/register to write
965 * Value Value to write
966 * Width Number of bits
970 * DESCRIPTION: Write data to an I/O port or register
972 *****************************************************************************/
976 ACPI_IO_ADDRESS Address,
985 /******************************************************************************
987 * FUNCTION: AcpiOsReadMemory
989 * PARAMETERS: Address Physical Memory Address to read
990 * Value Where value is placed
991 * Width Number of bits
993 * RETURN: Value read from physical memory address
995 * DESCRIPTION: Read data from a physical memory address
997 *****************************************************************************/
1001 ACPI_PHYSICAL_ADDRESS Address,
1015 return (AE_BAD_PARAMETER);
1022 /******************************************************************************
1024 * FUNCTION: AcpiOsWriteMemory
1026 * PARAMETERS: Address Physical Memory Address to write
1027 * Value Value to write
1028 * Width Number of bits
1032 * DESCRIPTION: Write data to a physical memory address
1034 *****************************************************************************/
1038 ACPI_PHYSICAL_ADDRESS Address,
1048 AcpiOsGetThreadId(void)
1054 /******************************************************************************
1056 * FUNCTION: AcpiOsSignal
1058 * PARAMETERS: Function ACPI CA signal function code
1059 * Info Pointer to function-dependent structure
1063 * DESCRIPTION: Miscellaneous functions
1065 *****************************************************************************/
1075 case ACPI_SIGNAL_FATAL:
1078 case ACPI_SIGNAL_BREAKPOINT:
1082 AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Info);
1086 AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");