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