]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/osunixxf.c
Merge ACPICA 20100806.
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / osunixxf.c
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 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 <contrib/dev/acpica/include/acpi.h>
134 #include <contrib/dev/acpica/include/accommon.h>
135 #include <contrib/dev/acpica/include/amlcode.h>
136 #include <contrib/dev/acpica/include/acparser.h>
137 #include <contrib/dev/acpica/include/acdebug.h>
138
139 #define _COMPONENT          ACPI_OS_SERVICES
140         ACPI_MODULE_NAME    ("osunixxf")
141
142
143 extern FILE                    *AcpiGbl_DebugFile;
144 FILE                           *AcpiGbl_OutputFile;
145
146
147 /* Upcalls to AcpiExec */
148
149 ACPI_PHYSICAL_ADDRESS
150 AeLocalGetRootPointer (
151     void);
152
153 void
154 AeTableOverride (
155     ACPI_TABLE_HEADER       *ExistingTable,
156     ACPI_TABLE_HEADER       **NewTable);
157
158 typedef 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
173 ACPI_STATUS
174 AcpiOsInitialize (void)
175 {
176
177     AcpiGbl_OutputFile = stdout;
178     return (AE_OK);
179 }
180
181
182 ACPI_STATUS
183 AcpiOsTerminate (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
202 ACPI_PHYSICAL_ADDRESS
203 AcpiOsGetRootPointer (
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
225 ACPI_STATUS
226 AcpiOsPredefinedOverride (
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
255 ACPI_STATUS
256 AcpiOsTableOverride (
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
291 void
292 AcpiOsRedirectOutput (
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
312 void ACPI_INTERNAL_VAR_XFACE
313 AcpiOsPrintf (
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
339 void
340 AcpiOsVprintf (
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
387 UINT32
388 AcpiOsGetLine (
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
428 void *
429 AcpiOsMapMemory (
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
452 void
453 AcpiOsUnmapMemory (
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
474 void *
475 AcpiOsAllocate (
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
498 void
499 AcpiOsFree (
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
520 ACPI_STATUS
521 AcpiOsCreateSemaphore (
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
572 ACPI_STATUS
573 AcpiOsDeleteSemaphore (
574     ACPI_HANDLE         Handle)
575 {
576     sem_t               *Sem = (sem_t *) Handle;
577
578
579     if (!Sem)
580     {
581         return (AE_BAD_PARAMETER);
582     }
583
584     if (sem_destroy (Sem) == -1)
585     {
586         return (AE_BAD_PARAMETER);
587     }
588
589     return (AE_OK);
590 }
591
592
593 /******************************************************************************
594  *
595  * FUNCTION:    AcpiOsWaitSemaphore
596  *
597  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
598  *              Units               - How many units to wait for
599  *              Timeout             - How long to wait
600  *
601  * RETURN:      Status
602  *
603  * DESCRIPTION: Wait for units
604  *
605  *****************************************************************************/
606
607 ACPI_STATUS
608 AcpiOsWaitSemaphore (
609     ACPI_HANDLE         Handle,
610     UINT32              Units,
611     UINT16              Timeout)
612 {
613     ACPI_STATUS         Status = AE_OK;
614     sem_t               *Sem = (sem_t *) Handle;
615     struct timespec     T;
616
617
618     if (!Sem)
619     {
620         return (AE_BAD_PARAMETER);
621     }
622
623     switch (Timeout)
624     {
625     /*
626      * No Wait:
627      * --------
628      * A zero timeout value indicates that we shouldn't wait - just
629      * acquire the semaphore if available otherwise return AE_TIME
630      * (a.k.a. 'would block').
631      */
632     case 0:
633
634         if (sem_trywait(Sem) == -1)
635         {
636             Status = (AE_TIME);
637         }
638         break;
639
640     /* Wait Indefinitely */
641
642     case ACPI_WAIT_FOREVER:
643
644         if (sem_wait (Sem))
645         {
646             Status = (AE_TIME);
647         }
648         break;
649
650     /* Wait with Timeout */
651
652     default:
653
654         T.tv_sec = Timeout / 1000;
655         T.tv_nsec = (Timeout - (T.tv_sec * 1000)) * 1000000;
656
657 #ifdef ACPI_USE_ALTERNATE_TIMEOUT
658         /*
659          * Alternate timeout mechanism for environments where
660          * sem_timedwait is not available or does not work properly.
661          */
662         while (Timeout)
663         {
664             if (sem_trywait (Sem) == 0)
665             {
666                 /* Got the semaphore */
667                 return (AE_OK);
668             }
669             usleep (1000);  /* one millisecond */
670             Timeout--;
671         }
672         Status = (AE_TIME);
673 #else
674
675         if (sem_timedwait (Sem, &T))
676         {
677             Status = (AE_TIME);
678         }
679 #endif
680
681         break;
682     }
683
684     return (Status);
685 }
686
687
688 /******************************************************************************
689  *
690  * FUNCTION:    AcpiOsSignalSemaphore
691  *
692  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
693  *              Units               - Number of units to send
694  *
695  * RETURN:      Status
696  *
697  * DESCRIPTION: Send units
698  *
699  *****************************************************************************/
700
701 ACPI_STATUS
702 AcpiOsSignalSemaphore (
703     ACPI_HANDLE         Handle,
704     UINT32              Units)
705 {
706     sem_t               *Sem = (sem_t *)Handle;
707
708
709     if (!Sem)
710     {
711         return (AE_BAD_PARAMETER);
712     }
713
714     if (sem_post (Sem) == -1)
715     {
716         return (AE_LIMIT);
717     }
718
719     return (AE_OK);
720 }
721
722
723 /******************************************************************************
724  *
725  * FUNCTION:    Spinlock interfaces
726  *
727  * DESCRIPTION: Map these interfaces to semaphore interfaces
728  *
729  *****************************************************************************/
730
731 ACPI_STATUS
732 AcpiOsCreateLock (
733     ACPI_SPINLOCK           *OutHandle)
734 {
735
736     return (AcpiOsCreateSemaphore (1, 1, OutHandle));
737 }
738
739
740 void
741 AcpiOsDeleteLock (
742     ACPI_SPINLOCK           Handle)
743 {
744     AcpiOsDeleteSemaphore (Handle);
745 }
746
747
748 ACPI_CPU_FLAGS
749 AcpiOsAcquireLock (
750     ACPI_HANDLE             Handle)
751 {
752     AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
753     return (0);
754 }
755
756
757 void
758 AcpiOsReleaseLock (
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
781 UINT32
782 AcpiOsInstallInterruptHandler (
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
804 ACPI_STATUS
805 AcpiOsRemoveInterruptHandler (
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
828 ACPI_STATUS
829 AcpiOsExecute (
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
859 void
860 AcpiOsStall (
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
883 void
884 AcpiOsSleep (
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
908 UINT64
909 AcpiOsGetTimer (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
937 ACPI_STATUS
938 AcpiOsReadPciConfiguration (
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
964 ACPI_STATUS
965 AcpiOsWritePciConfiguration (
966     ACPI_PCI_ID             *PciId,
967     UINT32                  Register,
968     UINT64                  Value,
969     UINT32                  Width)
970 {
971
972     return (AE_OK);
973 }
974
975 /* TEMPORARY STUB FUNCTION */
976 void
977 AcpiOsDerivePciId(
978     ACPI_HANDLE             Device,
979     ACPI_HANDLE             Region,
980     ACPI_PCI_ID             **PciId)
981 {
982
983 }
984
985
986 /******************************************************************************
987  *
988  * FUNCTION:    AcpiOsReadPort
989  *
990  * PARAMETERS:  Address             Address of I/O port/register to read
991  *              Value               Where value is placed
992  *              Width               Number of bits
993  *
994  * RETURN:      Value read from port
995  *
996  * DESCRIPTION: Read data from an I/O port or register
997  *
998  *****************************************************************************/
999
1000 ACPI_STATUS
1001 AcpiOsReadPort (
1002     ACPI_IO_ADDRESS         Address,
1003     UINT32                  *Value,
1004     UINT32                  Width)
1005 {
1006
1007     switch (Width)
1008     {
1009     case 8:
1010         *Value = 0xFF;
1011         break;
1012
1013     case 16:
1014         *Value = 0xFFFF;
1015         break;
1016
1017     case 32:
1018         *Value = 0xFFFFFFFF;
1019         break;
1020
1021     default:
1022         return (AE_BAD_PARAMETER);
1023     }
1024
1025     return (AE_OK);
1026 }
1027
1028
1029 /******************************************************************************
1030  *
1031  * FUNCTION:    AcpiOsWritePort
1032  *
1033  * PARAMETERS:  Address             Address of I/O port/register to write
1034  *              Value               Value to write
1035  *              Width               Number of bits
1036  *
1037  * RETURN:      None
1038  *
1039  * DESCRIPTION: Write data to an I/O port or register
1040  *
1041  *****************************************************************************/
1042
1043 ACPI_STATUS
1044 AcpiOsWritePort (
1045     ACPI_IO_ADDRESS         Address,
1046     UINT32                  Value,
1047     UINT32                  Width)
1048 {
1049
1050     return (AE_OK);
1051 }
1052
1053
1054 /******************************************************************************
1055  *
1056  * FUNCTION:    AcpiOsReadMemory
1057  *
1058  * PARAMETERS:  Address             Physical Memory Address to read
1059  *              Value               Where value is placed
1060  *              Width               Number of bits
1061  *
1062  * RETURN:      Value read from physical memory address
1063  *
1064  * DESCRIPTION: Read data from a physical memory address
1065  *
1066  *****************************************************************************/
1067
1068 ACPI_STATUS
1069 AcpiOsReadMemory (
1070     ACPI_PHYSICAL_ADDRESS   Address,
1071     UINT32                  *Value,
1072     UINT32                  Width)
1073 {
1074
1075     switch (Width)
1076     {
1077     case 8:
1078     case 16:
1079     case 32:
1080         *Value = 0;
1081         break;
1082
1083     default:
1084         return (AE_BAD_PARAMETER);
1085     }
1086     return (AE_OK);
1087 }
1088
1089
1090 /******************************************************************************
1091  *
1092  * FUNCTION:    AcpiOsWriteMemory
1093  *
1094  * PARAMETERS:  Address             Physical Memory Address to write
1095  *              Value               Value to write
1096  *              Width               Number of bits
1097  *
1098  * RETURN:      None
1099  *
1100  * DESCRIPTION: Write data to a physical memory address
1101  *
1102  *****************************************************************************/
1103
1104 ACPI_STATUS
1105 AcpiOsWriteMemory (
1106     ACPI_PHYSICAL_ADDRESS   Address,
1107     UINT32                  Value,
1108     UINT32                  Width)
1109 {
1110
1111     return (AE_OK);
1112 }
1113
1114
1115 /******************************************************************************
1116  *
1117  * FUNCTION:    AcpiOsReadable
1118  *
1119  * PARAMETERS:  Pointer             - Area to be verified
1120  *              Length              - Size of area
1121  *
1122  * RETURN:      TRUE if readable for entire length
1123  *
1124  * DESCRIPTION: Verify that a pointer is valid for reading
1125  *
1126  *****************************************************************************/
1127
1128 BOOLEAN
1129 AcpiOsReadable (
1130     void                    *Pointer,
1131     ACPI_SIZE               Length)
1132 {
1133
1134     return (TRUE);
1135 }
1136
1137
1138 /******************************************************************************
1139  *
1140  * FUNCTION:    AcpiOsWritable
1141  *
1142  * PARAMETERS:  Pointer             - Area to be verified
1143  *              Length              - Size of area
1144  *
1145  * RETURN:      TRUE if writable for entire length
1146  *
1147  * DESCRIPTION: Verify that a pointer is valid for writing
1148  *
1149  *****************************************************************************/
1150
1151 BOOLEAN
1152 AcpiOsWritable (
1153     void                    *Pointer,
1154     ACPI_SIZE               Length)
1155 {
1156
1157     return (TRUE);
1158 }
1159
1160
1161 /******************************************************************************
1162  *
1163  * FUNCTION:    AcpiOsGetThreadId
1164  *
1165  * PARAMETERS:  None
1166  *
1167  * RETURN:      Id of the running thread
1168  *
1169  * DESCRIPTION: Get the Id of the current (running) thread
1170  *
1171  * NOTE:        The environment header should contain this line:
1172  *                  #define ACPI_THREAD_ID pthread_t
1173  *
1174  *****************************************************************************/
1175
1176 ACPI_THREAD_ID
1177 AcpiOsGetThreadId (void)
1178 {
1179
1180     return (pthread_self ());
1181 }
1182
1183
1184 /******************************************************************************
1185  *
1186  * FUNCTION:    AcpiOsSignal
1187  *
1188  * PARAMETERS:  Function            ACPI CA signal function code
1189  *              Info                Pointer to function-dependent structure
1190  *
1191  * RETURN:      Status
1192  *
1193  * DESCRIPTION: Miscellaneous functions. Example implementation only.
1194  *
1195  *****************************************************************************/
1196
1197 ACPI_STATUS
1198 AcpiOsSignal (
1199     UINT32                  Function,
1200     void                    *Info)
1201 {
1202
1203     switch (Function)
1204     {
1205     case ACPI_SIGNAL_FATAL:
1206         break;
1207
1208     case ACPI_SIGNAL_BREAKPOINT:
1209         break;
1210
1211     default:
1212         break;
1213     }
1214
1215     return (AE_OK);
1216 }
1217
1218