osunixxf.c revision 212700
1687Sjoehw/******************************************************************************
2687Sjoehw *
3687Sjoehw * Module Name: osunixxf - UNIX OSL interfaces
4687Sjoehw *
5687Sjoehw *****************************************************************************/
6687Sjoehw
7687Sjoehw/******************************************************************************
8687Sjoehw *
9687Sjoehw * 1. Copyright Notice
10687Sjoehw *
11687Sjoehw * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12687Sjoehw * All rights reserved.
13687Sjoehw *
14687Sjoehw * 2. License
15687Sjoehw *
16687Sjoehw * 2.1. This is your license from Intel Corp. under its intellectual property
17687Sjoehw * rights.  You may have additional license terms from the party that provided
18687Sjoehw * you this software, covering your right to use that party's intellectual
19687Sjoehw * property rights.
20687Sjoehw *
21687Sjoehw * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22687Sjoehw * copy of the source code appearing in this file ("Covered Code") an
23687Sjoehw * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24687Sjoehw * base code distributed originally by Intel ("Original Intel Code") to copy,
25687Sjoehw * make derivatives, distribute, use and display any portion of the Covered
26687Sjoehw * Code in any form, with the right to sublicense such rights; and
27687Sjoehw *
28687Sjoehw * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29687Sjoehw * license (with the right to sublicense), under only those claims of Intel
30687Sjoehw * patents that are infringed by the Original Intel Code, to make, use, sell,
31687Sjoehw * offer to sell, and import the Covered Code and derivative works thereof
32687Sjoehw * solely to the minimum extent necessary to exercise the above copyright
33687Sjoehw * license, and in no event shall the patent license extend to any additions
34687Sjoehw * to or modifications of the Original Intel Code.  No other license or right
35687Sjoehw * is granted directly or by implication, estoppel or otherwise;
36687Sjoehw *
37687Sjoehw * The above copyright and patent license is granted only if the following
38687Sjoehw * conditions are met:
39687Sjoehw *
40687Sjoehw * 3. Conditions
41687Sjoehw *
42687Sjoehw * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43687Sjoehw * Redistribution of source code of any substantial portion of the Covered
44687Sjoehw * Code or modification with rights to further distribute source must include
45687Sjoehw * the above Copyright Notice, the above License, this list of Conditions,
46687Sjoehw * and the following Disclaimer and Export Compliance provision.  In addition,
47687Sjoehw * Licensee must cause all Covered Code to which Licensee contributes to
48687Sjoehw * contain a file documenting the changes Licensee made to create that Covered
49687Sjoehw * Code and the date of any change.  Licensee must include in that file the
50687Sjoehw * documentation of any changes made by any predecessor Licensee.  Licensee
51687Sjoehw * must include a prominent statement that the modification is derived,
52687Sjoehw * directly or indirectly, from Original Intel Code.
53687Sjoehw *
54687Sjoehw * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55687Sjoehw * Redistribution of source code of any substantial portion of the Covered
56687Sjoehw * Code or modification without rights to further distribute source must
57687Sjoehw * include the following Disclaimer and Export Compliance provision in the
58687Sjoehw * documentation and/or other materials provided with distribution.  In
59687Sjoehw * addition, Licensee may not authorize further sublicense of source of any
60687Sjoehw * portion of the Covered Code, and must include terms to the effect that the
61687Sjoehw * license from Licensee to its licensee is limited to the intellectual
62687Sjoehw * property embodied in the software Licensee provides to its licensee, and
63687Sjoehw * not to intellectual property embodied in modifications its licensee may
64687Sjoehw * make.
65687Sjoehw *
66687Sjoehw * 3.3. Redistribution of Executable. Redistribution in executable form of any
67687Sjoehw * substantial portion of the Covered Code or modification must reproduce the
68687Sjoehw * above Copyright Notice, and the following Disclaimer and Export Compliance
69687Sjoehw * provision in the documentation and/or other materials provided with the
70687Sjoehw * distribution.
71687Sjoehw *
72687Sjoehw * 3.4. Intel retains all right, title, and interest in and to the Original
73687Sjoehw * Intel Code.
74687Sjoehw *
75687Sjoehw * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76687Sjoehw * Intel shall be used in advertising or otherwise to promote the sale, use or
77687Sjoehw * other dealings in products derived from or relating to the Covered Code
78687Sjoehw * without prior written authorization from Intel.
79687Sjoehw *
80687Sjoehw * 4. Disclaimer and Export Compliance
81687Sjoehw *
82687Sjoehw * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83687Sjoehw * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84687Sjoehw * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85687Sjoehw * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86687Sjoehw * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87687Sjoehw * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88687Sjoehw * 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
117/*
118 * These interfaces are required in order to compile the ASL compiler under
119 * Linux or other Unix-like system.
120 *
121 * Note: Use #define __APPLE__ for OS X generation.
122 */
123
124#include <stdio.h>
125#include <stdlib.h>
126#include <stdarg.h>
127#include <unistd.h>
128#include <sys/time.h>
129#include <semaphore.h>
130#include <pthread.h>
131#include <errno.h>
132
133#include "acpi.h"
134#include "accommon.h"
135#include "amlcode.h"
136#include "acparser.h"
137#include "acdebug.h"
138
139#define _COMPONENT          ACPI_OS_SERVICES
140        ACPI_MODULE_NAME    ("osunixxf")
141
142
143extern FILE                    *AcpiGbl_DebugFile;
144FILE                           *AcpiGbl_OutputFile;
145
146
147/* Upcalls to AcpiExec */
148
149ACPI_PHYSICAL_ADDRESS
150AeLocalGetRootPointer (
151    void);
152
153void
154AeTableOverride (
155    ACPI_TABLE_HEADER       *ExistingTable,
156    ACPI_TABLE_HEADER       **NewTable);
157
158typedef void* (*PTHREAD_CALLBACK) (void *);
159
160
161/******************************************************************************
162 *
163 * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
164 *
165 * PARAMETERS:  None
166 *
167 * RETURN:      Status
168 *
169 * DESCRIPTION: Init and terminate.  Nothing to do.
170 *
171 *****************************************************************************/
172
173ACPI_STATUS
174AcpiOsInitialize (void)
175{
176
177    AcpiGbl_OutputFile = stdout;
178    return (AE_OK);
179}
180
181
182ACPI_STATUS
183AcpiOsTerminate (void)
184{
185
186    return (AE_OK);
187}
188
189
190/******************************************************************************
191 *
192 * FUNCTION:    AcpiOsGetRootPointer
193 *
194 * PARAMETERS:  None
195 *
196 * RETURN:      RSDP physical address
197 *
198 * DESCRIPTION: Gets the root pointer (RSDP)
199 *
200 *****************************************************************************/
201
202ACPI_PHYSICAL_ADDRESS
203AcpiOsGetRootPointer (
204    void)
205{
206
207    return (AeLocalGetRootPointer ());
208}
209
210
211/******************************************************************************
212 *
213 * FUNCTION:    AcpiOsPredefinedOverride
214 *
215 * PARAMETERS:  InitVal     - Initial value of the predefined object
216 *              NewVal      - The new value for the object
217 *
218 * RETURN:      Status, pointer to value.  Null pointer returned if not
219 *              overriding.
220 *
221 * DESCRIPTION: Allow the OS to override predefined names
222 *
223 *****************************************************************************/
224
225ACPI_STATUS
226AcpiOsPredefinedOverride (
227    const ACPI_PREDEFINED_NAMES *InitVal,
228    ACPI_STRING                 *NewVal)
229{
230
231    if (!InitVal || !NewVal)
232    {
233        return (AE_BAD_PARAMETER);
234    }
235
236    *NewVal = NULL;
237    return (AE_OK);
238}
239
240
241/******************************************************************************
242 *
243 * FUNCTION:    AcpiOsTableOverride
244 *
245 * PARAMETERS:  ExistingTable   - Header of current table (probably firmware)
246 *              NewTable        - Where an entire new table is returned.
247 *
248 * RETURN:      Status, pointer to new table.  Null pointer returned if no
249 *              table is available to override
250 *
251 * DESCRIPTION: Return a different version of a table if one is available
252 *
253 *****************************************************************************/
254
255ACPI_STATUS
256AcpiOsTableOverride (
257    ACPI_TABLE_HEADER       *ExistingTable,
258    ACPI_TABLE_HEADER       **NewTable)
259{
260
261    if (!ExistingTable || !NewTable)
262    {
263        return (AE_BAD_PARAMETER);
264    }
265
266    *NewTable = NULL;
267
268#ifdef ACPI_EXEC_APP
269
270    AeTableOverride (ExistingTable, NewTable);
271    return (AE_OK);
272#else
273
274    return (AE_NO_ACPI_TABLES);
275#endif
276}
277
278
279/******************************************************************************
280 *
281 * FUNCTION:    AcpiOsRedirectOutput
282 *
283 * PARAMETERS:  Destination         - An open file handle/pointer
284 *
285 * RETURN:      None
286 *
287 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
288 *
289 *****************************************************************************/
290
291void
292AcpiOsRedirectOutput (
293    void                    *Destination)
294{
295
296    AcpiGbl_OutputFile = Destination;
297}
298
299
300/******************************************************************************
301 *
302 * FUNCTION:    AcpiOsPrintf
303 *
304 * PARAMETERS:  fmt, ...            Standard printf format
305 *
306 * RETURN:      None
307 *
308 * DESCRIPTION: Formatted output
309 *
310 *****************************************************************************/
311
312void ACPI_INTERNAL_VAR_XFACE
313AcpiOsPrintf (
314    const char              *Fmt,
315    ...)
316{
317    va_list                 Args;
318
319
320    va_start (Args, Fmt);
321    AcpiOsVprintf (Fmt, Args);
322    va_end (Args);
323}
324
325
326/******************************************************************************
327 *
328 * FUNCTION:    AcpiOsVprintf
329 *
330 * PARAMETERS:  fmt                 Standard printf format
331 *              args                Argument list
332 *
333 * RETURN:      None
334 *
335 * DESCRIPTION: Formatted output with argument list pointer
336 *
337 *****************************************************************************/
338
339void
340AcpiOsVprintf (
341    const char              *Fmt,
342    va_list                 Args)
343{
344    INT32                   Count = 0;
345    UINT8                   Flags;
346
347
348    Flags = AcpiGbl_DbOutputFlags;
349    if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
350    {
351        /* Output is directable to either a file (if open) or the console */
352
353        if (AcpiGbl_DebugFile)
354        {
355            /* Output file is open, send the output there */
356
357            Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
358        }
359        else
360        {
361            /* No redirection, send output to console (once only!) */
362
363            Flags |= ACPI_DB_CONSOLE_OUTPUT;
364        }
365    }
366
367    if (Flags & ACPI_DB_CONSOLE_OUTPUT)
368    {
369        Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
370    }
371}
372
373
374/******************************************************************************
375 *
376 * FUNCTION:    AcpiOsGetLine
377 *
378 * PARAMETERS:  fmt                 Standard printf format
379 *              args                Argument list
380 *
381 * RETURN:      Actual bytes read
382 *
383 * DESCRIPTION: Formatted input with argument list pointer
384 *
385 *****************************************************************************/
386
387UINT32
388AcpiOsGetLine (
389    char                    *Buffer)
390{
391    UINT8                   Temp;
392    UINT32                  i;
393
394
395    for (i = 0; ; i++)
396    {
397        scanf ("%1c", &Temp);
398        if (!Temp || Temp == '\n')
399        {
400            break;
401        }
402
403        Buffer [i] = Temp;
404    }
405
406    /* Null terminate the buffer */
407
408    Buffer [i] = 0;
409
410    /* Return the number of bytes in the string */
411
412    return (i);
413}
414
415/******************************************************************************
416 *
417 * FUNCTION:    AcpiOsMapMemory
418 *
419 * PARAMETERS:  where               Physical address of memory to be mapped
420 *              length              How much memory to map
421 *
422 * RETURN:      Pointer to mapped memory.  Null on error.
423 *
424 * DESCRIPTION: Map physical memory into caller's address space
425 *
426 *****************************************************************************/
427
428void *
429AcpiOsMapMemory (
430    ACPI_PHYSICAL_ADDRESS   where,
431    ACPI_SIZE               length)
432{
433
434    return (ACPI_TO_POINTER ((ACPI_SIZE) where));
435}
436
437
438/******************************************************************************
439 *
440 * FUNCTION:    AcpiOsUnmapMemory
441 *
442 * PARAMETERS:  where               Logical address of memory to be unmapped
443 *              length              How much memory to unmap
444 *
445 * RETURN:      None.
446 *
447 * DESCRIPTION: Delete a previously created mapping.  Where and Length must
448 *              correspond to a previous mapping exactly.
449 *
450 *****************************************************************************/
451
452void
453AcpiOsUnmapMemory (
454    void                    *where,
455    ACPI_SIZE               length)
456{
457
458    return;
459}
460
461
462/******************************************************************************
463 *
464 * FUNCTION:    AcpiOsAllocate
465 *
466 * PARAMETERS:  Size                Amount to allocate, in bytes
467 *
468 * RETURN:      Pointer to the new allocation.  Null on error.
469 *
470 * DESCRIPTION: Allocate memory.  Algorithm is dependent on the OS.
471 *
472 *****************************************************************************/
473
474void *
475AcpiOsAllocate (
476    ACPI_SIZE               size)
477{
478    void                    *Mem;
479
480
481    Mem = (void *) malloc ((size_t) size);
482    return (Mem);
483}
484
485
486/******************************************************************************
487 *
488 * FUNCTION:    AcpiOsFree
489 *
490 * PARAMETERS:  mem                 Pointer to previously allocated memory
491 *
492 * RETURN:      None.
493 *
494 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
495 *
496 *****************************************************************************/
497
498void
499AcpiOsFree (
500    void                    *mem)
501{
502
503    free (mem);
504}
505
506
507/******************************************************************************
508 *
509 * FUNCTION:    AcpiOsCreateSemaphore
510 *
511 * PARAMETERS:  InitialUnits        - Units to be assigned to the new semaphore
512 *              OutHandle           - Where a handle will be returned
513 *
514 * RETURN:      Status
515 *
516 * DESCRIPTION: Create an OS semaphore
517 *
518 *****************************************************************************/
519
520ACPI_STATUS
521AcpiOsCreateSemaphore (
522    UINT32              MaxUnits,
523    UINT32              InitialUnits,
524    ACPI_HANDLE         *OutHandle)
525{
526    sem_t               *Sem;
527
528
529    if (!OutHandle)
530    {
531        return (AE_BAD_PARAMETER);
532    }
533
534#ifdef __APPLE__
535    Sem = sem_open (tmpnam (NULL), O_EXCL|O_CREAT, 0755, InitialUnits);
536    if (!Sem)
537    {
538        return (AE_NO_MEMORY);
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
572ACPI_STATUS
573AcpiOsDeleteSemaphore (
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
607ACPI_STATUS
608AcpiOsWaitSemaphore (
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
701ACPI_STATUS
702AcpiOsSignalSemaphore (
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
723/******************************************************************************
724 *
725 * FUNCTION:    Spinlock interfaces
726 *
727 * DESCRIPTION: Map these interfaces to semaphore interfaces
728 *
729 *****************************************************************************/
730
731ACPI_STATUS
732AcpiOsCreateLock (
733    ACPI_SPINLOCK           *OutHandle)
734{
735
736    return (AcpiOsCreateSemaphore (1, 1, OutHandle));
737}
738
739
740void
741AcpiOsDeleteLock (
742    ACPI_SPINLOCK           Handle)
743{
744    AcpiOsDeleteSemaphore (Handle);
745}
746
747
748ACPI_CPU_FLAGS
749AcpiOsAcquireLock (
750    ACPI_HANDLE             Handle)
751{
752    AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
753    return (0);
754}
755
756
757void
758AcpiOsReleaseLock (
759    ACPI_SPINLOCK           Handle,
760    ACPI_CPU_FLAGS          Flags)
761{
762    AcpiOsSignalSemaphore (Handle, 1);
763}
764
765
766/******************************************************************************
767 *
768 * FUNCTION:    AcpiOsInstallInterruptHandler
769 *
770 * PARAMETERS:  InterruptNumber     Level handler should respond to.
771 *              Isr                 Address of the ACPI interrupt handler
772 *              ExceptPtr           Where status is returned
773 *
774 * RETURN:      Handle to the newly installed handler.
775 *
776 * DESCRIPTION: Install an interrupt handler.  Used to install the ACPI
777 *              OS-independent handler.
778 *
779 *****************************************************************************/
780
781UINT32
782AcpiOsInstallInterruptHandler (
783    UINT32                  InterruptNumber,
784    ACPI_OSD_HANDLER        ServiceRoutine,
785    void                    *Context)
786{
787
788    return (AE_OK);
789}
790
791
792/******************************************************************************
793 *
794 * FUNCTION:    AcpiOsRemoveInterruptHandler
795 *
796 * PARAMETERS:  Handle              Returned when handler was installed
797 *
798 * RETURN:      Status
799 *
800 * DESCRIPTION: Uninstalls an interrupt handler.
801 *
802 *****************************************************************************/
803
804ACPI_STATUS
805AcpiOsRemoveInterruptHandler (
806    UINT32                  InterruptNumber,
807    ACPI_OSD_HANDLER        ServiceRoutine)
808{
809
810    return (AE_OK);
811}
812
813
814/******************************************************************************
815 *
816 * FUNCTION:    AcpiOsExecute
817 *
818 * PARAMETERS:  Type            - Type of execution
819 *              Function        - Address of the function to execute
820 *              Context         - Passed as a parameter to the function
821 *
822 * RETURN:      Status.
823 *
824 * DESCRIPTION: Execute a new thread
825 *
826 *****************************************************************************/
827
828ACPI_STATUS
829AcpiOsExecute (
830    ACPI_EXECUTE_TYPE       Type,
831    ACPI_OSD_EXEC_CALLBACK  Function,
832    void                    *Context)
833{
834    pthread_t               thread;
835    int                     ret;
836
837
838    ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context);
839    if (ret)
840    {
841        AcpiOsPrintf("Create thread failed");
842    }
843    return (0);
844}
845
846
847/******************************************************************************
848 *
849 * FUNCTION:    AcpiOsStall
850 *
851 * PARAMETERS:  microseconds        To sleep
852 *
853 * RETURN:      Blocks until sleep is completed.
854 *
855 * DESCRIPTION: Sleep at microsecond granularity
856 *
857 *****************************************************************************/
858
859void
860AcpiOsStall (
861    UINT32                  microseconds)
862{
863
864    if (microseconds)
865    {
866        usleep (microseconds);
867    }
868}
869
870
871/******************************************************************************
872 *
873 * FUNCTION:    AcpiOsSleep
874 *
875 * PARAMETERS:  milliseconds        To sleep
876 *
877 * RETURN:      Blocks until sleep is completed.
878 *
879 * DESCRIPTION: Sleep at millisecond granularity
880 *
881 *****************************************************************************/
882
883void
884AcpiOsSleep (
885    UINT64                  milliseconds)
886{
887
888    sleep (milliseconds / 1000);    /* Sleep for whole seconds */
889
890    /*
891     * Arg to usleep() must be less than 1,000,000 (1 second)
892     */
893    usleep ((milliseconds % 1000) * 1000);      /* Sleep for remaining usecs */
894}
895
896/******************************************************************************
897 *
898 * FUNCTION:    AcpiOsGetTimer
899 *
900 * PARAMETERS:  None
901 *
902 * RETURN:      Current time in 100 nanosecond units
903 *
904 * DESCRIPTION: Get the current system time
905 *
906 *****************************************************************************/
907
908UINT64
909AcpiOsGetTimer (void)
910{
911    struct timeval          time;
912
913
914    gettimeofday (&time, NULL);
915
916    /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
917
918    return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10));
919}
920
921
922/******************************************************************************
923 *
924 * FUNCTION:    AcpiOsReadPciConfiguration
925 *
926 * PARAMETERS:  PciId               Seg/Bus/Dev
927 *              Register            Device Register
928 *              Value               Buffer where value is placed
929 *              Width               Number of bits
930 *
931 * RETURN:      Status
932 *
933 * DESCRIPTION: Read data from PCI configuration space
934 *
935 *****************************************************************************/
936
937ACPI_STATUS
938AcpiOsReadPciConfiguration (
939    ACPI_PCI_ID             *PciId,
940    UINT32                  Register,
941    UINT64                  *Value,
942    UINT32                  Width)
943{
944
945    return (AE_OK);
946}
947
948
949/******************************************************************************
950 *
951 * FUNCTION:    AcpiOsWritePciConfiguration
952 *
953 * PARAMETERS:  PciId               Seg/Bus/Dev
954 *              Register            Device Register
955 *              Value               Value to be written
956 *              Width               Number of bits
957 *
958 * RETURN:      Status.
959 *
960 * DESCRIPTION: Write data to PCI configuration space
961 *
962 *****************************************************************************/
963
964ACPI_STATUS
965AcpiOsWritePciConfiguration (
966    ACPI_PCI_ID             *PciId,
967    UINT32                  Register,
968    UINT64                  Value,
969    UINT32                  Width)
970{
971
972    return (AE_OK);
973}
974
975
976/******************************************************************************
977 *
978 * FUNCTION:    AcpiOsReadPort
979 *
980 * PARAMETERS:  Address             Address of I/O port/register to read
981 *              Value               Where value is placed
982 *              Width               Number of bits
983 *
984 * RETURN:      Value read from port
985 *
986 * DESCRIPTION: Read data from an I/O port or register
987 *
988 *****************************************************************************/
989
990ACPI_STATUS
991AcpiOsReadPort (
992    ACPI_IO_ADDRESS         Address,
993    UINT32                  *Value,
994    UINT32                  Width)
995{
996
997    switch (Width)
998    {
999    case 8:
1000        *Value = 0xFF;
1001        break;
1002
1003    case 16:
1004        *Value = 0xFFFF;
1005        break;
1006
1007    case 32:
1008        *Value = 0xFFFFFFFF;
1009        break;
1010
1011    default:
1012        return (AE_BAD_PARAMETER);
1013    }
1014
1015    return (AE_OK);
1016}
1017
1018
1019/******************************************************************************
1020 *
1021 * FUNCTION:    AcpiOsWritePort
1022 *
1023 * PARAMETERS:  Address             Address of I/O port/register to write
1024 *              Value               Value to write
1025 *              Width               Number of bits
1026 *
1027 * RETURN:      None
1028 *
1029 * DESCRIPTION: Write data to an I/O port or register
1030 *
1031 *****************************************************************************/
1032
1033ACPI_STATUS
1034AcpiOsWritePort (
1035    ACPI_IO_ADDRESS         Address,
1036    UINT32                  Value,
1037    UINT32                  Width)
1038{
1039
1040    return (AE_OK);
1041}
1042
1043
1044/******************************************************************************
1045 *
1046 * FUNCTION:    AcpiOsReadMemory
1047 *
1048 * PARAMETERS:  Address             Physical Memory Address to read
1049 *              Value               Where value is placed
1050 *              Width               Number of bits
1051 *
1052 * RETURN:      Value read from physical memory address
1053 *
1054 * DESCRIPTION: Read data from a physical memory address
1055 *
1056 *****************************************************************************/
1057
1058ACPI_STATUS
1059AcpiOsReadMemory (
1060    ACPI_PHYSICAL_ADDRESS   Address,
1061    UINT32                  *Value,
1062    UINT32                  Width)
1063{
1064
1065    switch (Width)
1066    {
1067    case 8:
1068    case 16:
1069    case 32:
1070        *Value = 0;
1071        break;
1072
1073    default:
1074        return (AE_BAD_PARAMETER);
1075    }
1076    return (AE_OK);
1077}
1078
1079
1080/******************************************************************************
1081 *
1082 * FUNCTION:    AcpiOsWriteMemory
1083 *
1084 * PARAMETERS:  Address             Physical Memory Address to write
1085 *              Value               Value to write
1086 *              Width               Number of bits
1087 *
1088 * RETURN:      None
1089 *
1090 * DESCRIPTION: Write data to a physical memory address
1091 *
1092 *****************************************************************************/
1093
1094ACPI_STATUS
1095AcpiOsWriteMemory (
1096    ACPI_PHYSICAL_ADDRESS   Address,
1097    UINT32                  Value,
1098    UINT32                  Width)
1099{
1100
1101    return (AE_OK);
1102}
1103
1104
1105/******************************************************************************
1106 *
1107 * FUNCTION:    AcpiOsReadable
1108 *
1109 * PARAMETERS:  Pointer             - Area to be verified
1110 *              Length              - Size of area
1111 *
1112 * RETURN:      TRUE if readable for entire length
1113 *
1114 * DESCRIPTION: Verify that a pointer is valid for reading
1115 *
1116 *****************************************************************************/
1117
1118BOOLEAN
1119AcpiOsReadable (
1120    void                    *Pointer,
1121    ACPI_SIZE               Length)
1122{
1123
1124    return (TRUE);
1125}
1126
1127
1128/******************************************************************************
1129 *
1130 * FUNCTION:    AcpiOsWritable
1131 *
1132 * PARAMETERS:  Pointer             - Area to be verified
1133 *              Length              - Size of area
1134 *
1135 * RETURN:      TRUE if writable for entire length
1136 *
1137 * DESCRIPTION: Verify that a pointer is valid for writing
1138 *
1139 *****************************************************************************/
1140
1141BOOLEAN
1142AcpiOsWritable (
1143    void                    *Pointer,
1144    ACPI_SIZE               Length)
1145{
1146
1147    return (TRUE);
1148}
1149
1150
1151/******************************************************************************
1152 *
1153 * FUNCTION:    AcpiOsGetThreadId
1154 *
1155 * PARAMETERS:  None
1156 *
1157 * RETURN:      Id of the running thread
1158 *
1159 * DESCRIPTION: Get the Id of the current (running) thread
1160 *
1161 *****************************************************************************/
1162
1163ACPI_THREAD_ID
1164AcpiOsGetThreadId (
1165    void)
1166{
1167
1168    return (ACPI_CAST_PTHREAD_T (pthread_self()));
1169}
1170
1171
1172/******************************************************************************
1173 *
1174 * FUNCTION:    AcpiOsSignal
1175 *
1176 * PARAMETERS:  Function            ACPI CA signal function code
1177 *              Info                Pointer to function-dependent structure
1178 *
1179 * RETURN:      Status
1180 *
1181 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1182 *
1183 *****************************************************************************/
1184
1185ACPI_STATUS
1186AcpiOsSignal (
1187    UINT32                  Function,
1188    void                    *Info)
1189{
1190
1191    switch (Function)
1192    {
1193    case ACPI_SIGNAL_FATAL:
1194        break;
1195
1196    case ACPI_SIGNAL_BREAKPOINT:
1197        break;
1198
1199    default:
1200        break;
1201    }
1202
1203    return (AE_OK);
1204}
1205
1206
1207