Home | History | Annotate | Line # | Download | only in service_layers
osunixxf.c revision 1.1.1.3
      1 /******************************************************************************
      2  *
      3  * Module Name: osunixxf - UNIX OSL interfaces
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2011, Intel Corp.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions, and the following disclaimer,
     16  *    without modification.
     17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  *    including a substantially similar Disclaimer requirement for further
     21  *    binary redistribution.
     22  * 3. Neither the names of the above-listed copyright holders nor the names
     23  *    of any contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * Alternatively, this software may be distributed under the terms of the
     27  * GNU General Public License ("GPL") version 2 as published by the Free
     28  * Software Foundation.
     29  *
     30  * NO WARRANTY
     31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGES.
     42  */
     43 
     44 
     45 /*
     46  * These interfaces are required in order to compile the ASL compiler and the
     47  * various ACPICA tools under Linux or other Unix-like system.
     48  *
     49  * Note: Use #define __APPLE__ for OS X generation.
     50  */
     51 #include "acpi.h"
     52 #include "accommon.h"
     53 #include "amlcode.h"
     54 #include "acparser.h"
     55 #include "acdebug.h"
     56 
     57 #include <stdio.h>
     58 #include <stdlib.h>
     59 #include <stdarg.h>
     60 #include <unistd.h>
     61 #include <sys/time.h>
     62 #include <semaphore.h>
     63 #include <pthread.h>
     64 #include <errno.h>
     65 
     66 #define _COMPONENT          ACPI_OS_SERVICES
     67         ACPI_MODULE_NAME    ("osunixxf")
     68 
     69 
     70 extern FILE                    *AcpiGbl_DebugFile;
     71 FILE                           *AcpiGbl_OutputFile;
     72 
     73 
     74 /* Upcalls to AcpiExec */
     75 
     76 ACPI_PHYSICAL_ADDRESS
     77 AeLocalGetRootPointer (
     78     void);
     79 
     80 void
     81 AeTableOverride (
     82     ACPI_TABLE_HEADER       *ExistingTable,
     83     ACPI_TABLE_HEADER       **NewTable);
     84 
     85 typedef void* (*PTHREAD_CALLBACK) (void *);
     86 
     87 /* Apple-specific */
     88 
     89 #ifdef __APPLE__
     90 #define sem_destroy         sem_close
     91 #endif
     92 
     93 
     94 /******************************************************************************
     95  *
     96  * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
     97  *
     98  * PARAMETERS:  None
     99  *
    100  * RETURN:      Status
    101  *
    102  * DESCRIPTION: Init and terminate. Nothing to do.
    103  *
    104  *****************************************************************************/
    105 
    106 ACPI_STATUS
    107 AcpiOsInitialize (
    108     void)
    109 {
    110 
    111     AcpiGbl_OutputFile = stdout;
    112     return (AE_OK);
    113 }
    114 
    115 
    116 ACPI_STATUS
    117 AcpiOsTerminate (
    118     void)
    119 {
    120 
    121     return (AE_OK);
    122 }
    123 
    124 
    125 /******************************************************************************
    126  *
    127  * FUNCTION:    AcpiOsGetRootPointer
    128  *
    129  * PARAMETERS:  None
    130  *
    131  * RETURN:      RSDP physical address
    132  *
    133  * DESCRIPTION: Gets the ACPI root pointer (RSDP)
    134  *
    135  *****************************************************************************/
    136 
    137 ACPI_PHYSICAL_ADDRESS
    138 AcpiOsGetRootPointer (
    139     void)
    140 {
    141 
    142     return (AeLocalGetRootPointer ());
    143 }
    144 
    145 
    146 /******************************************************************************
    147  *
    148  * FUNCTION:    AcpiOsPredefinedOverride
    149  *
    150  * PARAMETERS:  InitVal             - Initial value of the predefined object
    151  *              NewVal              - The new value for the object
    152  *
    153  * RETURN:      Status, pointer to value. Null pointer returned if not
    154  *              overriding.
    155  *
    156  * DESCRIPTION: Allow the OS to override predefined names
    157  *
    158  *****************************************************************************/
    159 
    160 ACPI_STATUS
    161 AcpiOsPredefinedOverride (
    162     const ACPI_PREDEFINED_NAMES *InitVal,
    163     ACPI_STRING                 *NewVal)
    164 {
    165 
    166     if (!InitVal || !NewVal)
    167     {
    168         return (AE_BAD_PARAMETER);
    169     }
    170 
    171     *NewVal = NULL;
    172     return (AE_OK);
    173 }
    174 
    175 
    176 /******************************************************************************
    177  *
    178  * FUNCTION:    AcpiOsTableOverride
    179  *
    180  * PARAMETERS:  ExistingTable       - Header of current table (probably
    181  *                                    firmware)
    182  *              NewTable            - Where an entire new table is returned.
    183  *
    184  * RETURN:      Status, pointer to new table. Null pointer returned if no
    185  *              table is available to override
    186  *
    187  * DESCRIPTION: Return a different version of a table if one is available
    188  *
    189  *****************************************************************************/
    190 
    191 ACPI_STATUS
    192 AcpiOsTableOverride (
    193     ACPI_TABLE_HEADER       *ExistingTable,
    194     ACPI_TABLE_HEADER       **NewTable)
    195 {
    196 
    197     if (!ExistingTable || !NewTable)
    198     {
    199         return (AE_BAD_PARAMETER);
    200     }
    201 
    202     *NewTable = NULL;
    203 
    204 #ifdef ACPI_EXEC_APP
    205 
    206     AeTableOverride (ExistingTable, NewTable);
    207     return (AE_OK);
    208 #else
    209 
    210     return (AE_NO_ACPI_TABLES);
    211 #endif
    212 }
    213 
    214 
    215 /******************************************************************************
    216  *
    217  * FUNCTION:    AcpiOsRedirectOutput
    218  *
    219  * PARAMETERS:  Destination         - An open file handle/pointer
    220  *
    221  * RETURN:      None
    222  *
    223  * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
    224  *
    225  *****************************************************************************/
    226 
    227 void
    228 AcpiOsRedirectOutput (
    229     void                    *Destination)
    230 {
    231 
    232     AcpiGbl_OutputFile = Destination;
    233 }
    234 
    235 
    236 /******************************************************************************
    237  *
    238  * FUNCTION:    AcpiOsPrintf
    239  *
    240  * PARAMETERS:  fmt, ...            - Standard printf format
    241  *
    242  * RETURN:      None
    243  *
    244  * DESCRIPTION: Formatted output
    245  *
    246  *****************************************************************************/
    247 
    248 void ACPI_INTERNAL_VAR_XFACE
    249 AcpiOsPrintf (
    250     const char              *Fmt,
    251     ...)
    252 {
    253     va_list                 Args;
    254 
    255 
    256     va_start (Args, Fmt);
    257     AcpiOsVprintf (Fmt, Args);
    258     va_end (Args);
    259 }
    260 
    261 
    262 /******************************************************************************
    263  *
    264  * FUNCTION:    AcpiOsVprintf
    265  *
    266  * PARAMETERS:  fmt                 - Standard printf format
    267  *              args                - Argument list
    268  *
    269  * RETURN:      None
    270  *
    271  * DESCRIPTION: Formatted output with argument list pointer
    272  *
    273  *****************************************************************************/
    274 
    275 void
    276 AcpiOsVprintf (
    277     const char              *Fmt,
    278     va_list                 Args)
    279 {
    280     INT32                   Count = 0;
    281     UINT8                   Flags;
    282 
    283 
    284     Flags = AcpiGbl_DbOutputFlags;
    285     if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
    286     {
    287         /* Output is directable to either a file (if open) or the console */
    288 
    289         if (AcpiGbl_DebugFile)
    290         {
    291             /* Output file is open, send the output there */
    292 
    293             Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
    294         }
    295         else
    296         {
    297             /* No redirection, send output to console (once only!) */
    298 
    299             Flags |= ACPI_DB_CONSOLE_OUTPUT;
    300         }
    301     }
    302 
    303     if (Flags & ACPI_DB_CONSOLE_OUTPUT)
    304     {
    305         Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
    306     }
    307 }
    308 
    309 
    310 /******************************************************************************
    311  *
    312  * FUNCTION:    AcpiOsGetLine
    313  *
    314  * PARAMETERS:  Buffer              - Where to return the command line
    315  *              BufferLength        - Maximum length of Buffer
    316  *              BytesRead           - Where the actual byte count is returned
    317  *
    318  * RETURN:      Status and actual bytes read
    319  *
    320  * DESCRIPTION: Formatted input with argument list pointer
    321  *
    322  *****************************************************************************/
    323 
    324 ACPI_STATUS
    325 AcpiOsGetLine (
    326     char                    *Buffer,
    327     UINT32                  BufferLength,
    328     UINT32                  *BytesRead)
    329 {
    330     UINT8                   Temp;
    331     UINT32                  i;
    332 
    333 
    334     for (i = 0; ; i++)
    335     {
    336         if (i >= BufferLength)
    337         {
    338             return (AE_BUFFER_OVERFLOW);
    339         }
    340 
    341         scanf ("%1c", &Temp);
    342         if (!Temp || Temp == '\n')
    343         {
    344             break;
    345         }
    346 
    347         Buffer [i] = Temp;
    348     }
    349 
    350     /* Null terminate the buffer */
    351 
    352     Buffer [i] = 0;
    353 
    354     /* Return the number of bytes in the string */
    355 
    356     if (BytesRead)
    357     {
    358         *BytesRead = i;
    359     }
    360     return (AE_OK);
    361 }
    362 
    363 
    364 /******************************************************************************
    365  *
    366  * FUNCTION:    AcpiOsMapMemory
    367  *
    368  * PARAMETERS:  where               - Physical address of memory to be mapped
    369  *              length              - How much memory to map
    370  *
    371  * RETURN:      Pointer to mapped memory. Null on error.
    372  *
    373  * DESCRIPTION: Map physical memory into caller's address space
    374  *
    375  *****************************************************************************/
    376 
    377 void *
    378 AcpiOsMapMemory (
    379     ACPI_PHYSICAL_ADDRESS   where,
    380     ACPI_SIZE               length)
    381 {
    382 
    383     return (ACPI_TO_POINTER ((ACPI_SIZE) where));
    384 }
    385 
    386 
    387 /******************************************************************************
    388  *
    389  * FUNCTION:    AcpiOsUnmapMemory
    390  *
    391  * PARAMETERS:  where               - Logical address of memory to be unmapped
    392  *              length              - How much memory to unmap
    393  *
    394  * RETURN:      None.
    395  *
    396  * DESCRIPTION: Delete a previously created mapping. Where and Length must
    397  *              correspond to a previous mapping exactly.
    398  *
    399  *****************************************************************************/
    400 
    401 void
    402 AcpiOsUnmapMemory (
    403     void                    *where,
    404     ACPI_SIZE               length)
    405 {
    406 
    407     return;
    408 }
    409 
    410 
    411 /******************************************************************************
    412  *
    413  * FUNCTION:    AcpiOsAllocate
    414  *
    415  * PARAMETERS:  Size                - Amount to allocate, in bytes
    416  *
    417  * RETURN:      Pointer to the new allocation. Null on error.
    418  *
    419  * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
    420  *
    421  *****************************************************************************/
    422 
    423 void *
    424 AcpiOsAllocate (
    425     ACPI_SIZE               size)
    426 {
    427     void                    *Mem;
    428 
    429 
    430     Mem = (void *) malloc ((size_t) size);
    431     return (Mem);
    432 }
    433 
    434 
    435 /******************************************************************************
    436  *
    437  * FUNCTION:    AcpiOsFree
    438  *
    439  * PARAMETERS:  mem                 - Pointer to previously allocated memory
    440  *
    441  * RETURN:      None.
    442  *
    443  * DESCRIPTION: Free memory allocated via AcpiOsAllocate
    444  *
    445  *****************************************************************************/
    446 
    447 void
    448 AcpiOsFree (
    449     void                    *mem)
    450 {
    451 
    452     free (mem);
    453 }
    454 
    455 
    456 #ifdef ACPI_SINGLE_THREADED
    457 /******************************************************************************
    458  *
    459  * FUNCTION:    Semaphore stub functions
    460  *
    461  * DESCRIPTION: Stub functions used for single-thread applications that do
    462  *              not require semaphore synchronization. Full implementations
    463  *              of these functions appear after the stubs.
    464  *
    465  *****************************************************************************/
    466 
    467 ACPI_STATUS
    468 AcpiOsCreateSemaphore (
    469     UINT32              MaxUnits,
    470     UINT32              InitialUnits,
    471     ACPI_HANDLE         *OutHandle)
    472 {
    473     *OutHandle = (ACPI_HANDLE) 1;
    474     return (AE_OK);
    475 }
    476 
    477 ACPI_STATUS
    478 AcpiOsDeleteSemaphore (
    479     ACPI_HANDLE         Handle)
    480 {
    481     return (AE_OK);
    482 }
    483 
    484 ACPI_STATUS
    485 AcpiOsWaitSemaphore (
    486     ACPI_HANDLE         Handle,
    487     UINT32              Units,
    488     UINT16              Timeout)
    489 {
    490     return (AE_OK);
    491 }
    492 
    493 ACPI_STATUS
    494 AcpiOsSignalSemaphore (
    495     ACPI_HANDLE         Handle,
    496     UINT32              Units)
    497 {
    498     return (AE_OK);
    499 }
    500 
    501 #else
    502 /******************************************************************************
    503  *
    504  * FUNCTION:    AcpiOsCreateSemaphore
    505  *
    506  * PARAMETERS:  InitialUnits        - Units to be assigned to the new semaphore
    507  *              OutHandle           - Where a handle will be returned
    508  *
    509  * RETURN:      Status
    510  *
    511  * DESCRIPTION: Create an OS semaphore
    512  *
    513  *****************************************************************************/
    514 
    515 ACPI_STATUS
    516 AcpiOsCreateSemaphore (
    517     UINT32              MaxUnits,
    518     UINT32              InitialUnits,
    519     ACPI_HANDLE         *OutHandle)
    520 {
    521     sem_t               *Sem;
    522 
    523 
    524     if (!OutHandle)
    525     {
    526         return (AE_BAD_PARAMETER);
    527     }
    528 
    529 #ifdef __APPLE__
    530     {
    531         char            *SemaphoreName = tmpnam (NULL);
    532 
    533         Sem = sem_open (SemaphoreName, O_EXCL|O_CREAT, 0755, InitialUnits);
    534         if (!Sem)
    535         {
    536             return (AE_NO_MEMORY);
    537         }
    538         sem_unlink (SemaphoreName); /* This just deletes the name */
    539     }
    540 
    541 #else
    542     Sem = AcpiOsAllocate (sizeof (sem_t));
    543     if (!Sem)
    544     {
    545         return (AE_NO_MEMORY);
    546     }
    547 
    548     if (sem_init (Sem, 0, InitialUnits) == -1)
    549     {
    550         AcpiOsFree (Sem);
    551         return (AE_BAD_PARAMETER);
    552     }
    553 #endif
    554 
    555     *OutHandle = (ACPI_HANDLE) Sem;
    556     return (AE_OK);
    557 }
    558 
    559 
    560 /******************************************************************************
    561  *
    562  * FUNCTION:    AcpiOsDeleteSemaphore
    563  *
    564  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
    565  *
    566  * RETURN:      Status
    567  *
    568  * DESCRIPTION: Delete an OS semaphore
    569  *
    570  *****************************************************************************/
    571 
    572 ACPI_STATUS
    573 AcpiOsDeleteSemaphore (
    574     ACPI_HANDLE         Handle)
    575 {
    576     sem_t               *Sem = (sem_t *) Handle;
    577 
    578 
    579     if (!Sem)
    580     {
    581         return (AE_BAD_PARAMETER);
    582     }
    583 
    584     if (sem_destroy (Sem) == -1)
    585     {
    586         return (AE_BAD_PARAMETER);
    587     }
    588 
    589     return (AE_OK);
    590 }
    591 
    592 
    593 /******************************************************************************
    594  *
    595  * FUNCTION:    AcpiOsWaitSemaphore
    596  *
    597  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
    598  *              Units               - How many units to wait for
    599  *              Timeout             - How long to wait
    600  *
    601  * RETURN:      Status
    602  *
    603  * DESCRIPTION: Wait for units
    604  *
    605  *****************************************************************************/
    606 
    607 ACPI_STATUS
    608 AcpiOsWaitSemaphore (
    609     ACPI_HANDLE         Handle,
    610     UINT32              Units,
    611     UINT16              Timeout)
    612 {
    613     ACPI_STATUS         Status = AE_OK;
    614     sem_t               *Sem = (sem_t *) Handle;
    615     struct timespec     T;
    616 
    617 
    618     if (!Sem)
    619     {
    620         return (AE_BAD_PARAMETER);
    621     }
    622 
    623     switch (Timeout)
    624     {
    625     /*
    626      * No Wait:
    627      * --------
    628      * A zero timeout value indicates that we shouldn't wait - just
    629      * acquire the semaphore if available otherwise return AE_TIME
    630      * (a.k.a. 'would block').
    631      */
    632     case 0:
    633 
    634         if (sem_trywait(Sem) == -1)
    635         {
    636             Status = (AE_TIME);
    637         }
    638         break;
    639 
    640     /* Wait Indefinitely */
    641 
    642     case ACPI_WAIT_FOREVER:
    643 
    644         if (sem_wait (Sem))
    645         {
    646             Status = (AE_TIME);
    647         }
    648         break;
    649 
    650     /* Wait with Timeout */
    651 
    652     default:
    653 
    654         T.tv_sec = Timeout / 1000;
    655         T.tv_nsec = (Timeout - (T.tv_sec * 1000)) * 1000000;
    656 
    657 #ifdef ACPI_USE_ALTERNATE_TIMEOUT
    658         /*
    659          * Alternate timeout mechanism for environments where
    660          * sem_timedwait is not available or does not work properly.
    661          */
    662         while (Timeout)
    663         {
    664             if (sem_trywait (Sem) == 0)
    665             {
    666                 /* Got the semaphore */
    667                 return (AE_OK);
    668             }
    669             usleep (1000);  /* one millisecond */
    670             Timeout--;
    671         }
    672         Status = (AE_TIME);
    673 #else
    674 
    675         if (sem_timedwait (Sem, &T))
    676         {
    677             Status = (AE_TIME);
    678         }
    679 #endif
    680 
    681         break;
    682     }
    683 
    684     return (Status);
    685 }
    686 
    687 
    688 /******************************************************************************
    689  *
    690  * FUNCTION:    AcpiOsSignalSemaphore
    691  *
    692  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
    693  *              Units               - Number of units to send
    694  *
    695  * RETURN:      Status
    696  *
    697  * DESCRIPTION: Send units
    698  *
    699  *****************************************************************************/
    700 
    701 ACPI_STATUS
    702 AcpiOsSignalSemaphore (
    703     ACPI_HANDLE         Handle,
    704     UINT32              Units)
    705 {
    706     sem_t               *Sem = (sem_t *)Handle;
    707 
    708 
    709     if (!Sem)
    710     {
    711         return (AE_BAD_PARAMETER);
    712     }
    713 
    714     if (sem_post (Sem) == -1)
    715     {
    716         return (AE_LIMIT);
    717     }
    718 
    719     return (AE_OK);
    720 }
    721 
    722 #endif /* ACPI_SINGLE_THREADED */
    723 
    724 
    725 /******************************************************************************
    726  *
    727  * FUNCTION:    Spinlock interfaces
    728  *
    729  * DESCRIPTION: Map these interfaces to semaphore interfaces
    730  *
    731  *****************************************************************************/
    732 
    733 ACPI_STATUS
    734 AcpiOsCreateLock (
    735     ACPI_SPINLOCK           *OutHandle)
    736 {
    737 
    738     return (AcpiOsCreateSemaphore (1, 1, OutHandle));
    739 }
    740 
    741 
    742 void
    743 AcpiOsDeleteLock (
    744     ACPI_SPINLOCK           Handle)
    745 {
    746     AcpiOsDeleteSemaphore (Handle);
    747 }
    748 
    749 
    750 ACPI_CPU_FLAGS
    751 AcpiOsAcquireLock (
    752     ACPI_HANDLE             Handle)
    753 {
    754     AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
    755     return (0);
    756 }
    757 
    758 
    759 void
    760 AcpiOsReleaseLock (
    761     ACPI_SPINLOCK           Handle,
    762     ACPI_CPU_FLAGS          Flags)
    763 {
    764     AcpiOsSignalSemaphore (Handle, 1);
    765 }
    766 
    767 
    768 /******************************************************************************
    769  *
    770  * FUNCTION:    AcpiOsInstallInterruptHandler
    771  *
    772  * PARAMETERS:  InterruptNumber     - Level handler should respond to.
    773  *              Isr                 - Address of the ACPI interrupt handler
    774  *              ExceptPtr           - Where status is returned
    775  *
    776  * RETURN:      Handle to the newly installed handler.
    777  *
    778  * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
    779  *              OS-independent handler.
    780  *
    781  *****************************************************************************/
    782 
    783 UINT32
    784 AcpiOsInstallInterruptHandler (
    785     UINT32                  InterruptNumber,
    786     ACPI_OSD_HANDLER        ServiceRoutine,
    787     void                    *Context)
    788 {
    789 
    790     return (AE_OK);
    791 }
    792 
    793 
    794 /******************************************************************************
    795  *
    796  * FUNCTION:    AcpiOsRemoveInterruptHandler
    797  *
    798  * PARAMETERS:  Handle              - Returned when handler was installed
    799  *
    800  * RETURN:      Status
    801  *
    802  * DESCRIPTION: Uninstalls an interrupt handler.
    803  *
    804  *****************************************************************************/
    805 
    806 ACPI_STATUS
    807 AcpiOsRemoveInterruptHandler (
    808     UINT32                  InterruptNumber,
    809     ACPI_OSD_HANDLER        ServiceRoutine)
    810 {
    811 
    812     return (AE_OK);
    813 }
    814 
    815 
    816 /******************************************************************************
    817  *
    818  * FUNCTION:    AcpiOsStall
    819  *
    820  * PARAMETERS:  microseconds        - Time to sleep
    821  *
    822  * RETURN:      Blocks until sleep is completed.
    823  *
    824  * DESCRIPTION: Sleep at microsecond granularity
    825  *
    826  *****************************************************************************/
    827 
    828 void
    829 AcpiOsStall (
    830     UINT32                  microseconds)
    831 {
    832 
    833     if (microseconds)
    834     {
    835         usleep (microseconds);
    836     }
    837 }
    838 
    839 
    840 /******************************************************************************
    841  *
    842  * FUNCTION:    AcpiOsSleep
    843  *
    844  * PARAMETERS:  milliseconds        - Time to sleep
    845  *
    846  * RETURN:      Blocks until sleep is completed.
    847  *
    848  * DESCRIPTION: Sleep at millisecond granularity
    849  *
    850  *****************************************************************************/
    851 
    852 void
    853 AcpiOsSleep (
    854     UINT64                  milliseconds)
    855 {
    856 
    857     sleep (milliseconds / 1000);    /* Sleep for whole seconds */
    858 
    859     /*
    860      * Arg to usleep() must be less than 1,000,000 (1 second)
    861      */
    862     usleep ((milliseconds % 1000) * 1000);      /* Sleep for remaining usecs */
    863 }
    864 
    865 
    866 /******************************************************************************
    867  *
    868  * FUNCTION:    AcpiOsGetTimer
    869  *
    870  * PARAMETERS:  None
    871  *
    872  * RETURN:      Current time in 100 nanosecond units
    873  *
    874  * DESCRIPTION: Get the current system time
    875  *
    876  *****************************************************************************/
    877 
    878 UINT64
    879 AcpiOsGetTimer (
    880     void)
    881 {
    882     struct timeval          time;
    883 
    884 
    885     gettimeofday (&time, NULL);
    886 
    887     /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
    888 
    889     return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10));
    890 }
    891 
    892 
    893 /******************************************************************************
    894  *
    895  * FUNCTION:    AcpiOsReadPciConfiguration
    896  *
    897  * PARAMETERS:  PciId               - Seg/Bus/Dev
    898  *              Register            - Device Register
    899  *              Value               - Buffer where value is placed
    900  *              Width               - Number of bits
    901  *
    902  * RETURN:      Status
    903  *
    904  * DESCRIPTION: Read data from PCI configuration space
    905  *
    906  *****************************************************************************/
    907 
    908 ACPI_STATUS
    909 AcpiOsReadPciConfiguration (
    910     ACPI_PCI_ID             *PciId,
    911     UINT32                  Register,
    912     UINT64                  *Value,
    913     UINT32                  Width)
    914 {
    915 
    916     return (AE_OK);
    917 }
    918 
    919 
    920 /******************************************************************************
    921  *
    922  * FUNCTION:    AcpiOsWritePciConfiguration
    923  *
    924  * PARAMETERS:  PciId               - Seg/Bus/Dev
    925  *              Register            - Device Register
    926  *              Value               - Value to be written
    927  *              Width               - Number of bits
    928  *
    929  * RETURN:      Status.
    930  *
    931  * DESCRIPTION: Write data to PCI configuration space
    932  *
    933  *****************************************************************************/
    934 
    935 ACPI_STATUS
    936 AcpiOsWritePciConfiguration (
    937     ACPI_PCI_ID             *PciId,
    938     UINT32                  Register,
    939     UINT64                  Value,
    940     UINT32                  Width)
    941 {
    942 
    943     return (AE_OK);
    944 }
    945 
    946 
    947 /******************************************************************************
    948  *
    949  * FUNCTION:    AcpiOsReadPort
    950  *
    951  * PARAMETERS:  Address             - Address of I/O port/register to read
    952  *              Value               - Where value is placed
    953  *              Width               - Number of bits
    954  *
    955  * RETURN:      Value read from port
    956  *
    957  * DESCRIPTION: Read data from an I/O port or register
    958  *
    959  *****************************************************************************/
    960 
    961 ACPI_STATUS
    962 AcpiOsReadPort (
    963     ACPI_IO_ADDRESS         Address,
    964     UINT32                  *Value,
    965     UINT32                  Width)
    966 {
    967 
    968     switch (Width)
    969     {
    970     case 8:
    971         *Value = 0xFF;
    972         break;
    973 
    974     case 16:
    975         *Value = 0xFFFF;
    976         break;
    977 
    978     case 32:
    979         *Value = 0xFFFFFFFF;
    980         break;
    981 
    982     default:
    983         return (AE_BAD_PARAMETER);
    984     }
    985 
    986     return (AE_OK);
    987 }
    988 
    989 
    990 /******************************************************************************
    991  *
    992  * FUNCTION:    AcpiOsWritePort
    993  *
    994  * PARAMETERS:  Address             - Address of I/O port/register to write
    995  *              Value               - Value to write
    996  *              Width               - Number of bits
    997  *
    998  * RETURN:      None
    999  *
   1000  * DESCRIPTION: Write data to an I/O port or register
   1001  *
   1002  *****************************************************************************/
   1003 
   1004 ACPI_STATUS
   1005 AcpiOsWritePort (
   1006     ACPI_IO_ADDRESS         Address,
   1007     UINT32                  Value,
   1008     UINT32                  Width)
   1009 {
   1010 
   1011     return (AE_OK);
   1012 }
   1013 
   1014 
   1015 /******************************************************************************
   1016  *
   1017  * FUNCTION:    AcpiOsReadMemory
   1018  *
   1019  * PARAMETERS:  Address             - Physical Memory Address to read
   1020  *              Value               - Where value is placed
   1021  *              Width               - Number of bits
   1022  *
   1023  * RETURN:      Value read from physical memory address
   1024  *
   1025  * DESCRIPTION: Read data from a physical memory address
   1026  *
   1027  *****************************************************************************/
   1028 
   1029 ACPI_STATUS
   1030 AcpiOsReadMemory (
   1031     ACPI_PHYSICAL_ADDRESS   Address,
   1032     UINT32                  *Value,
   1033     UINT32                  Width)
   1034 {
   1035 
   1036     switch (Width)
   1037     {
   1038     case 8:
   1039     case 16:
   1040     case 32:
   1041         *Value = 0;
   1042         break;
   1043 
   1044     default:
   1045         return (AE_BAD_PARAMETER);
   1046     }
   1047     return (AE_OK);
   1048 }
   1049 
   1050 
   1051 /******************************************************************************
   1052  *
   1053  * FUNCTION:    AcpiOsWriteMemory
   1054  *
   1055  * PARAMETERS:  Address             - Physical Memory Address to write
   1056  *              Value               - Value to write
   1057  *              Width               - Number of bits
   1058  *
   1059  * RETURN:      None
   1060  *
   1061  * DESCRIPTION: Write data to a physical memory address
   1062  *
   1063  *****************************************************************************/
   1064 
   1065 ACPI_STATUS
   1066 AcpiOsWriteMemory (
   1067     ACPI_PHYSICAL_ADDRESS   Address,
   1068     UINT32                  Value,
   1069     UINT32                  Width)
   1070 {
   1071 
   1072     return (AE_OK);
   1073 }
   1074 
   1075 
   1076 /******************************************************************************
   1077  *
   1078  * FUNCTION:    AcpiOsReadable
   1079  *
   1080  * PARAMETERS:  Pointer             - Area to be verified
   1081  *              Length              - Size of area
   1082  *
   1083  * RETURN:      TRUE if readable for entire length
   1084  *
   1085  * DESCRIPTION: Verify that a pointer is valid for reading
   1086  *
   1087  *****************************************************************************/
   1088 
   1089 BOOLEAN
   1090 AcpiOsReadable (
   1091     void                    *Pointer,
   1092     ACPI_SIZE               Length)
   1093 {
   1094 
   1095     return (TRUE);
   1096 }
   1097 
   1098 
   1099 /******************************************************************************
   1100  *
   1101  * FUNCTION:    AcpiOsWritable
   1102  *
   1103  * PARAMETERS:  Pointer             - Area to be verified
   1104  *              Length              - Size of area
   1105  *
   1106  * RETURN:      TRUE if writable for entire length
   1107  *
   1108  * DESCRIPTION: Verify that a pointer is valid for writing
   1109  *
   1110  *****************************************************************************/
   1111 
   1112 BOOLEAN
   1113 AcpiOsWritable (
   1114     void                    *Pointer,
   1115     ACPI_SIZE               Length)
   1116 {
   1117 
   1118     return (TRUE);
   1119 }
   1120 
   1121 
   1122 /******************************************************************************
   1123  *
   1124  * FUNCTION:    AcpiOsSignal
   1125  *
   1126  * PARAMETERS:  Function            - ACPI CA signal function code
   1127  *              Info                - Pointer to function-dependent structure
   1128  *
   1129  * RETURN:      Status
   1130  *
   1131  * DESCRIPTION: Miscellaneous functions. Example implementation only.
   1132  *
   1133  *****************************************************************************/
   1134 
   1135 ACPI_STATUS
   1136 AcpiOsSignal (
   1137     UINT32                  Function,
   1138     void                    *Info)
   1139 {
   1140 
   1141     switch (Function)
   1142     {
   1143     case ACPI_SIGNAL_FATAL:
   1144         break;
   1145 
   1146     case ACPI_SIGNAL_BREAKPOINT:
   1147         break;
   1148 
   1149     default:
   1150         break;
   1151     }
   1152 
   1153     return (AE_OK);
   1154 }
   1155 
   1156 /* Optional multi-thread support */
   1157 
   1158 #ifndef ACPI_SINGLE_THREADED
   1159 /******************************************************************************
   1160  *
   1161  * FUNCTION:    AcpiOsGetThreadId
   1162  *
   1163  * PARAMETERS:  None
   1164  *
   1165  * RETURN:      Id of the running thread
   1166  *
   1167  * DESCRIPTION: Get the ID of the current (running) thread
   1168  *
   1169  *****************************************************************************/
   1170 
   1171 ACPI_THREAD_ID
   1172 AcpiOsGetThreadId (
   1173     void)
   1174 {
   1175 
   1176     return (ACPI_CAST_PTHREAD_T (pthread_self()));
   1177 }
   1178 
   1179 
   1180 /******************************************************************************
   1181  *
   1182  * FUNCTION:    AcpiOsExecute
   1183  *
   1184  * PARAMETERS:  Type                - Type of execution
   1185  *              Function            - Address of the function to execute
   1186  *              Context             - Passed as a parameter to the function
   1187  *
   1188  * RETURN:      Status.
   1189  *
   1190  * DESCRIPTION: Execute a new thread
   1191  *
   1192  *****************************************************************************/
   1193 
   1194 ACPI_STATUS
   1195 AcpiOsExecute (
   1196     ACPI_EXECUTE_TYPE       Type,
   1197     ACPI_OSD_EXEC_CALLBACK  Function,
   1198     void                    *Context)
   1199 {
   1200     pthread_t               thread;
   1201     int                     ret;
   1202 
   1203 
   1204     ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context);
   1205     if (ret)
   1206     {
   1207         AcpiOsPrintf("Create thread failed");
   1208     }
   1209     return (0);
   1210 }
   1211 
   1212 #endif /* ACPI_SINGLE_THREADED */
   1213