Subversion Repositories Kolibri OS

Rev

Rev 2187 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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