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 - 2017, 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  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 /*
153  * These interfaces are required in order to compile the ASL compiler and the
154  * various ACPICA tools under Linux or other Unix-like system.
155  */
156 #include "acpi.h"
157 #include "accommon.h"
158 #include "amlcode.h"
159 #include "acparser.h"
160 #include "acdebug.h"
161 
162 #include <stdio.h>
163 #include <stdlib.h>
164 #include <stdarg.h>
165 #include <unistd.h>
166 #include <sys/time.h>
167 #include <semaphore.h>
168 #include <pthread.h>
169 #include <errno.h>
170 
171 #define _COMPONENT          ACPI_OS_SERVICES
172         ACPI_MODULE_NAME    ("osunixxf")
173 
174 
175 /* Upcalls to AcpiExec */
176 
177 void
178 AeTableOverride (
179     ACPI_TABLE_HEADER       *ExistingTable,
180     ACPI_TABLE_HEADER       **NewTable);
181 
182 typedef void* (*PTHREAD_CALLBACK) (void *);
183 
184 /* Buffer used by AcpiOsVprintf */
185 
186 #define ACPI_VPRINTF_BUFFER_SIZE    512
187 #define _ASCII_NEWLINE              '\n'
188 
189 /* Terminal support for AcpiExec only */
190 
191 #ifdef ACPI_EXEC_APP
192 #include <termios.h>
193 
194 struct termios              OriginalTermAttributes;
195 int                         TermAttributesWereSet = 0;
196 
197 ACPI_STATUS
198 AcpiUtReadLine (
199     char                    *Buffer,
200     UINT32                  BufferLength,
201     UINT32                  *BytesRead);
202 
203 static void
204 OsEnterLineEditMode (
205     void);
206 
207 static void
208 OsExitLineEditMode (
209     void);
210 
211 
212 /******************************************************************************
213  *
214  * FUNCTION:    OsEnterLineEditMode, OsExitLineEditMode
215  *
216  * PARAMETERS:  None
217  *
218  * RETURN:      None
219  *
220  * DESCRIPTION: Enter/Exit the raw character input mode for the terminal.
221  *
222  * Interactive line-editing support for the AML debugger. Used with the
223  * common/acgetline module.
224  *
225  * readline() is not used because of non-portability. It is not available
226  * on all systems, and if it is, often the package must be manually installed.
227  *
228  * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line
229  * editing that we need in AcpiOsGetLine.
230  *
231  * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these
232  * calls will also work:
233  *     For OsEnterLineEditMode: system ("stty cbreak -echo")
234  *     For OsExitLineEditMode:  system ("stty cooked echo")
235  *
236  *****************************************************************************/
237 
238 static void
239 OsEnterLineEditMode (
240     void)
241 {
242     struct termios          LocalTermAttributes;
243 
244 
245     TermAttributesWereSet = 0;
246 
247     /* STDIN must be a terminal */
248 
249     if (!isatty (STDIN_FILENO))
250     {
251         return;
252     }
253 
254     /* Get and keep the original attributes */
255 
256     if (tcgetattr (STDIN_FILENO, &OriginalTermAttributes))
257     {
258         fprintf (stderr, "Could not get terminal attributes!\n");
259         return;
260     }
261 
262     /* Set the new attributes to enable raw character input */
263 
264     memcpy (&LocalTermAttributes, &OriginalTermAttributes,
265         sizeof (struct termios));
266 
267     LocalTermAttributes.c_lflag &= ~(ICANON | ECHO);
268     LocalTermAttributes.c_cc[VMIN] = 1;
269     LocalTermAttributes.c_cc[VTIME] = 0;
270 
271     if (tcsetattr (STDIN_FILENO, TCSANOW, &LocalTermAttributes))
272     {
273         fprintf (stderr, "Could not set terminal attributes!\n");
274         return;
275     }
276 
277     TermAttributesWereSet = 1;
278 }
279 
280 
281 static void
282 OsExitLineEditMode (
283     void)
284 {
285 
286     if (!TermAttributesWereSet)
287     {
288         return;
289     }
290 
291     /* Set terminal attributes back to the original values */
292 
293     if (tcsetattr (STDIN_FILENO, TCSANOW, &OriginalTermAttributes))
294     {
295         fprintf (stderr, "Could not restore terminal attributes!\n");
296     }
297 }
298 
299 
300 #else
301 
302 /* These functions are not needed for other ACPICA utilities */
303 
304 #define OsEnterLineEditMode()
305 #define OsExitLineEditMode()
306 #endif
307 
308 
309 /******************************************************************************
310  *
311  * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
312  *
313  * PARAMETERS:  None
314  *
315  * RETURN:      Status
316  *
317  * DESCRIPTION: Initialize and terminate this module.
318  *
319  *****************************************************************************/
320 
321 ACPI_STATUS
322 AcpiOsInitialize (
323     void)
324 {
325     ACPI_STATUS            Status;
326 
327 
328     AcpiGbl_OutputFile = stdout;
329 
330     OsEnterLineEditMode ();
331 
332     Status = AcpiOsCreateLock (&AcpiGbl_PrintLock);
333     if (ACPI_FAILURE (Status))
334     {
335         return (Status);
336     }
337 
338     return (AE_OK);
339 }
340 
341 ACPI_STATUS
342 AcpiOsTerminate (
343     void)
344 {
345 
346     OsExitLineEditMode ();
347     return (AE_OK);
348 }
349 
350 
351 #ifndef ACPI_USE_NATIVE_RSDP_POINTER
352 /******************************************************************************
353  *
354  * FUNCTION:    AcpiOsGetRootPointer
355  *
356  * PARAMETERS:  None
357  *
358  * RETURN:      RSDP physical address
359  *
360  * DESCRIPTION: Gets the ACPI root pointer (RSDP)
361  *
362  *****************************************************************************/
363 
364 ACPI_PHYSICAL_ADDRESS
365 AcpiOsGetRootPointer (
366     void)
367 {
368 
369     return (0);
370 }
371 #endif
372 
373 
374 /******************************************************************************
375  *
376  * FUNCTION:    AcpiOsPredefinedOverride
377  *
378  * PARAMETERS:  InitVal             - Initial value of the predefined object
379  *              NewVal              - The new value for the object
380  *
381  * RETURN:      Status, pointer to value. Null pointer returned if not
382  *              overriding.
383  *
384  * DESCRIPTION: Allow the OS to override predefined names
385  *
386  *****************************************************************************/
387 
388 ACPI_STATUS
389 AcpiOsPredefinedOverride (
390     const ACPI_PREDEFINED_NAMES *InitVal,
391     ACPI_STRING                 *NewVal)
392 {
393 
394     if (!InitVal || !NewVal)
395     {
396         return (AE_BAD_PARAMETER);
397     }
398 
399     *NewVal = NULL;
400     return (AE_OK);
401 }
402 
403 
404 /******************************************************************************
405  *
406  * FUNCTION:    AcpiOsTableOverride
407  *
408  * PARAMETERS:  ExistingTable       - Header of current table (probably
409  *                                    firmware)
410  *              NewTable            - Where an entire new table is returned.
411  *
412  * RETURN:      Status, pointer to new table. Null pointer returned if no
413  *              table is available to override
414  *
415  * DESCRIPTION: Return a different version of a table if one is available
416  *
417  *****************************************************************************/
418 
419 ACPI_STATUS
420 AcpiOsTableOverride (
421     ACPI_TABLE_HEADER       *ExistingTable,
422     ACPI_TABLE_HEADER       **NewTable)
423 {
424 
425     if (!ExistingTable || !NewTable)
426     {
427         return (AE_BAD_PARAMETER);
428     }
429 
430     *NewTable = NULL;
431 
432 #ifdef ACPI_EXEC_APP
433 
434     AeTableOverride (ExistingTable, NewTable);
435     return (AE_OK);
436 #else
437 
438     return (AE_NO_ACPI_TABLES);
439 #endif
440 }
441 
442 
443 /******************************************************************************
444  *
445  * FUNCTION:    AcpiOsPhysicalTableOverride
446  *
447  * PARAMETERS:  ExistingTable       - Header of current table (probably firmware)
448  *              NewAddress          - Where new table address is returned
449  *                                    (Physical address)
450  *              NewTableLength      - Where new table length is returned
451  *
452  * RETURN:      Status, address/length of new table. Null pointer returned
453  *              if no table is available to override.
454  *
455  * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
456  *
457  *****************************************************************************/
458 
459 ACPI_STATUS
460 AcpiOsPhysicalTableOverride (
461     ACPI_TABLE_HEADER       *ExistingTable,
462     ACPI_PHYSICAL_ADDRESS   *NewAddress,
463     UINT32                  *NewTableLength)
464 {
465 
466     return (AE_SUPPORT);
467 }
468 
469 
470 /******************************************************************************
471  *
472  * FUNCTION:    AcpiOsEnterSleep
473  *
474  * PARAMETERS:  SleepState          - Which sleep state to enter
475  *              RegaValue           - Register A value
476  *              RegbValue           - Register B value
477  *
478  * RETURN:      Status
479  *
480  * DESCRIPTION: A hook before writing sleep registers to enter the sleep
481  *              state. Return AE_CTRL_TERMINATE to skip further sleep register
482  *              writes.
483  *
484  *****************************************************************************/
485 
486 ACPI_STATUS
487 AcpiOsEnterSleep (
488     UINT8                   SleepState,
489     UINT32                  RegaValue,
490     UINT32                  RegbValue)
491 {
492 
493     return (AE_OK);
494 }
495 
496 
497 /******************************************************************************
498  *
499  * FUNCTION:    AcpiOsRedirectOutput
500  *
501  * PARAMETERS:  Destination         - An open file handle/pointer
502  *
503  * RETURN:      None
504  *
505  * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
506  *
507  *****************************************************************************/
508 
509 void
510 AcpiOsRedirectOutput (
511     void                    *Destination)
512 {
513 
514     AcpiGbl_OutputFile = Destination;
515 }
516 
517 
518 /******************************************************************************
519  *
520  * FUNCTION:    AcpiOsPrintf
521  *
522  * PARAMETERS:  fmt, ...            - Standard printf format
523  *
524  * RETURN:      None
525  *
526  * DESCRIPTION: Formatted output. Note: very similar to AcpiOsVprintf
527  *              (performance), changes should be tracked in both functions.
528  *
529  *****************************************************************************/
530 
531 void ACPI_INTERNAL_VAR_XFACE
532 AcpiOsPrintf (
533     const char              *Fmt,
534     ...)
535 {
536     va_list                 Args;
537     UINT8                   Flags;
538 
539 
540     Flags = AcpiGbl_DbOutputFlags;
541     if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
542     {
543         /* Output is directable to either a file (if open) or the console */
544 
545         if (AcpiGbl_DebugFile)
546         {
547             /* Output file is open, send the output there */
548 
549             va_start (Args, Fmt);
550             vfprintf (AcpiGbl_DebugFile, Fmt, Args);
551             va_end (Args);
552         }
553         else
554         {
555             /* No redirection, send output to console (once only!) */
556 
557             Flags |= ACPI_DB_CONSOLE_OUTPUT;
558         }
559     }
560 
561     if (Flags & ACPI_DB_CONSOLE_OUTPUT)
562     {
563         va_start (Args, Fmt);
564         vfprintf (AcpiGbl_OutputFile, Fmt, Args);
565         va_end (Args);
566     }
567 }
568 
569 
570 /******************************************************************************
571  *
572  * FUNCTION:    AcpiOsVprintf
573  *
574  * PARAMETERS:  fmt                 - Standard printf format
575  *              args                - Argument list
576  *
577  * RETURN:      None
578  *
579  * DESCRIPTION: Formatted output with argument list pointer. Note: very
580  *              similar to AcpiOsPrintf, changes should be tracked in both
581  *              functions.
582  *
583  *****************************************************************************/
584 
585 void
586 AcpiOsVprintf (
587     const char              *Fmt,
588     va_list                 Args)
589 {
590     UINT8                   Flags;
591     char                    Buffer[ACPI_VPRINTF_BUFFER_SIZE];
592 
593 
594     /*
595      * We build the output string in a local buffer because we may be
596      * outputting the buffer twice. Using vfprintf is problematic because
597      * some implementations modify the args pointer/structure during
598      * execution. Thus, we use the local buffer for portability.
599      *
600      * Note: Since this module is intended for use by the various ACPICA
601      * utilities/applications, we can safely declare the buffer on the stack.
602      * Also, This function is used for relatively small error messages only.
603      */
604     vsnprintf (Buffer, ACPI_VPRINTF_BUFFER_SIZE, Fmt, Args);
605 
606     Flags = AcpiGbl_DbOutputFlags;
607     if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
608     {
609         /* Output is directable to either a file (if open) or the console */
610 
611         if (AcpiGbl_DebugFile)
612         {
613             /* Output file is open, send the output there */
614 
615             fputs (Buffer, AcpiGbl_DebugFile);
616         }
617         else
618         {
619             /* No redirection, send output to console (once only!) */
620 
621             Flags |= ACPI_DB_CONSOLE_OUTPUT;
622         }
623     }
624 
625     if (Flags & ACPI_DB_CONSOLE_OUTPUT)
626     {
627         fputs (Buffer, AcpiGbl_OutputFile);
628     }
629 }
630 
631 
632 #ifndef ACPI_EXEC_APP
633 /******************************************************************************
634  *
635  * FUNCTION:    AcpiOsGetLine
636  *
637  * PARAMETERS:  Buffer              - Where to return the command line
638  *              BufferLength        - Maximum length of Buffer
639  *              BytesRead           - Where the actual byte count is returned
640  *
641  * RETURN:      Status and actual bytes read
642  *
643  * DESCRIPTION: Get the next input line from the terminal. NOTE: For the
644  *              AcpiExec utility, we use the acgetline module instead to
645  *              provide line-editing and history support.
646  *
647  *****************************************************************************/
648 
649 ACPI_STATUS
650 AcpiOsGetLine (
651     char                    *Buffer,
652     UINT32                  BufferLength,
653     UINT32                  *BytesRead)
654 {
655     int                     InputChar;
656     UINT32                  EndOfLine;
657 
658 
659     /* Standard AcpiOsGetLine for all utilities except AcpiExec */
660 
661     for (EndOfLine = 0; ; EndOfLine++)
662     {
663         if (EndOfLine >= BufferLength)
664         {
665             return (AE_BUFFER_OVERFLOW);
666         }
667 
668         if ((InputChar = getchar ()) == EOF)
669         {
670             return (AE_ERROR);
671         }
672 
673         if (!InputChar || InputChar == _ASCII_NEWLINE)
674         {
675             break;
676         }
677 
678         Buffer[EndOfLine] = (char) InputChar;
679     }
680 
681     /* Null terminate the buffer */
682 
683     Buffer[EndOfLine] = 0;
684 
685     /* Return the number of bytes in the string */
686 
687     if (BytesRead)
688     {
689         *BytesRead = EndOfLine;
690     }
691 
692     return (AE_OK);
693 }
694 #endif
695 
696 
697 #ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
698 /******************************************************************************
699  *
700  * FUNCTION:    AcpiOsMapMemory
701  *
702  * PARAMETERS:  where               - Physical address of memory to be mapped
703  *              length              - How much memory to map
704  *
705  * RETURN:      Pointer to mapped memory. Null on error.
706  *
707  * DESCRIPTION: Map physical memory into caller's address space
708  *
709  *****************************************************************************/
710 
711 void *
712 AcpiOsMapMemory (
713     ACPI_PHYSICAL_ADDRESS   where,
714     ACPI_SIZE               length)
715 {
716 
717     return (ACPI_TO_POINTER ((ACPI_SIZE) where));
718 }
719 
720 
721 /******************************************************************************
722  *
723  * FUNCTION:    AcpiOsUnmapMemory
724  *
725  * PARAMETERS:  where               - Logical address of memory to be unmapped
726  *              length              - How much memory to unmap
727  *
728  * RETURN:      None.
729  *
730  * DESCRIPTION: Delete a previously created mapping. Where and Length must
731  *              correspond to a previous mapping exactly.
732  *
733  *****************************************************************************/
734 
735 void
736 AcpiOsUnmapMemory (
737     void                    *where,
738     ACPI_SIZE               length)
739 {
740 
741     return;
742 }
743 #endif
744 
745 
746 /******************************************************************************
747  *
748  * FUNCTION:    AcpiOsAllocate
749  *
750  * PARAMETERS:  Size                - Amount to allocate, in bytes
751  *
752  * RETURN:      Pointer to the new allocation. Null on error.
753  *
754  * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
755  *
756  *****************************************************************************/
757 
758 void *
759 AcpiOsAllocate (
760     ACPI_SIZE               size)
761 {
762     void                    *Mem;
763 
764 
765     Mem = (void *) malloc ((size_t) size);
766     return (Mem);
767 }
768 
769 
770 #ifdef USE_NATIVE_ALLOCATE_ZEROED
771 /******************************************************************************
772  *
773  * FUNCTION:    AcpiOsAllocateZeroed
774  *
775  * PARAMETERS:  Size                - Amount to allocate, in bytes
776  *
777  * RETURN:      Pointer to the new allocation. Null on error.
778  *
779  * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
780  *
781  *****************************************************************************/
782 
783 void *
784 AcpiOsAllocateZeroed (
785     ACPI_SIZE               size)
786 {
787     void                    *Mem;
788 
789 
790     Mem = (void *) calloc (1, (size_t) size);
791     return (Mem);
792 }
793 #endif
794 
795 
796 /******************************************************************************
797  *
798  * FUNCTION:    AcpiOsFree
799  *
800  * PARAMETERS:  mem                 - Pointer to previously allocated memory
801  *
802  * RETURN:      None.
803  *
804  * DESCRIPTION: Free memory allocated via AcpiOsAllocate
805  *
806  *****************************************************************************/
807 
808 void
809 AcpiOsFree (
810     void                    *mem)
811 {
812 
813     free (mem);
814 }
815 
816 
817 #ifdef ACPI_SINGLE_THREADED
818 /******************************************************************************
819  *
820  * FUNCTION:    Semaphore stub functions
821  *
822  * DESCRIPTION: Stub functions used for single-thread applications that do
823  *              not require semaphore synchronization. Full implementations
824  *              of these functions appear after the stubs.
825  *
826  *****************************************************************************/
827 
828 ACPI_STATUS
829 AcpiOsCreateSemaphore (
830     UINT32              MaxUnits,
831     UINT32              InitialUnits,
832     ACPI_HANDLE         *OutHandle)
833 {
834     *OutHandle = (ACPI_HANDLE) 1;
835     return (AE_OK);
836 }
837 
838 ACPI_STATUS
839 AcpiOsDeleteSemaphore (
840     ACPI_HANDLE         Handle)
841 {
842     return (AE_OK);
843 }
844 
845 ACPI_STATUS
846 AcpiOsWaitSemaphore (
847     ACPI_HANDLE         Handle,
848     UINT32              Units,
849     UINT16              Timeout)
850 {
851     return (AE_OK);
852 }
853 
854 ACPI_STATUS
855 AcpiOsSignalSemaphore (
856     ACPI_HANDLE         Handle,
857     UINT32              Units)
858 {
859     return (AE_OK);
860 }
861 
862 #else
863 /******************************************************************************
864  *
865  * FUNCTION:    AcpiOsCreateSemaphore
866  *
867  * PARAMETERS:  InitialUnits        - Units to be assigned to the new semaphore
868  *              OutHandle           - Where a handle will be returned
869  *
870  * RETURN:      Status
871  *
872  * DESCRIPTION: Create an OS semaphore
873  *
874  *****************************************************************************/
875 
876 ACPI_STATUS
877 AcpiOsCreateSemaphore (
878     UINT32              MaxUnits,
879     UINT32              InitialUnits,
880     ACPI_HANDLE         *OutHandle)
881 {
882     sem_t               *Sem;
883 
884 
885     if (!OutHandle)
886     {
887         return (AE_BAD_PARAMETER);
888     }
889 
890 #ifdef __APPLE__
891     {
892         static int      SemaphoreCount = 0;
893         char            SemaphoreName[32];
894 
895         snprintf (SemaphoreName, sizeof (SemaphoreName), "acpi_sem_%d",
896             SemaphoreCount++);
897         printf ("%s\n", SemaphoreName);
898         Sem = sem_open (SemaphoreName, O_EXCL|O_CREAT, 0755, InitialUnits);
899         if (!Sem)
900         {
901             return (AE_NO_MEMORY);
902         }
903         sem_unlink (SemaphoreName); /* This just deletes the name */
904     }
905 
906 #else
907     Sem = AcpiOsAllocate (sizeof (sem_t));
908     if (!Sem)
909     {
910         return (AE_NO_MEMORY);
911     }
912 
913     if (sem_init (Sem, 0, InitialUnits) == -1)
914     {
915         AcpiOsFree (Sem);
916         return (AE_BAD_PARAMETER);
917     }
918 #endif
919 
920     *OutHandle = (ACPI_HANDLE) Sem;
921     return (AE_OK);
922 }
923 
924 
925 /******************************************************************************
926  *
927  * FUNCTION:    AcpiOsDeleteSemaphore
928  *
929  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
930  *
931  * RETURN:      Status
932  *
933  * DESCRIPTION: Delete an OS semaphore
934  *
935  *****************************************************************************/
936 
937 ACPI_STATUS
938 AcpiOsDeleteSemaphore (
939     ACPI_HANDLE         Handle)
940 {
941     sem_t               *Sem = (sem_t *) Handle;
942 
943 
944     if (!Sem)
945     {
946         return (AE_BAD_PARAMETER);
947     }
948 
949 #ifdef __APPLE__
950     if (sem_close (Sem) == -1)
951     {
952         return (AE_BAD_PARAMETER);
953     }
954 #else
955     if (sem_destroy (Sem) == -1)
956     {
957         return (AE_BAD_PARAMETER);
958     }
959 #endif
960 
961     return (AE_OK);
962 }
963 
964 
965 /******************************************************************************
966  *
967  * FUNCTION:    AcpiOsWaitSemaphore
968  *
969  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
970  *              Units               - How many units to wait for
971  *              MsecTimeout         - How long to wait (milliseconds)
972  *
973  * RETURN:      Status
974  *
975  * DESCRIPTION: Wait for units
976  *
977  *****************************************************************************/
978 
979 ACPI_STATUS
980 AcpiOsWaitSemaphore (
981     ACPI_HANDLE         Handle,
982     UINT32              Units,
983     UINT16              MsecTimeout)
984 {
985     ACPI_STATUS         Status = AE_OK;
986     sem_t               *Sem = (sem_t *) Handle;
987 #ifndef ACPI_USE_ALTERNATE_TIMEOUT
988     struct timespec     Time;
989     int                 RetVal;
990 #endif
991 
992 
993     if (!Sem)
994     {
995         return (AE_BAD_PARAMETER);
996     }
997 
998     switch (MsecTimeout)
999     {
1000     /*
1001      * No Wait:
1002      * --------
1003      * A zero timeout value indicates that we shouldn't wait - just
1004      * acquire the semaphore if available otherwise return AE_TIME
1005      * (a.k.a. 'would block').
1006      */
1007     case 0:
1008 
1009         if (sem_trywait(Sem) == -1)
1010         {
1011             Status = (AE_TIME);
1012         }
1013         break;
1014 
1015     /* Wait Indefinitely */
1016 
1017     case ACPI_WAIT_FOREVER:
1018 
1019         if (sem_wait (Sem))
1020         {
1021             Status = (AE_TIME);
1022         }
1023         break;
1024 
1025     /* Wait with MsecTimeout */
1026 
1027     default:
1028 
1029 #ifdef ACPI_USE_ALTERNATE_TIMEOUT
1030         /*
1031          * Alternate timeout mechanism for environments where
1032          * sem_timedwait is not available or does not work properly.
1033          */
1034         while (MsecTimeout)
1035         {
1036             if (sem_trywait (Sem) == 0)
1037             {
1038                 /* Got the semaphore */
1039                 return (AE_OK);
1040             }
1041 
1042             if (MsecTimeout >= 10)
1043             {
1044                 MsecTimeout -= 10;
1045                 usleep (10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */
1046             }
1047             else
1048             {
1049                 MsecTimeout--;
1050                 usleep (ACPI_USEC_PER_MSEC); /* one millisecond */
1051             }
1052         }
1053         Status = (AE_TIME);
1054 #else
1055         /*
1056          * The interface to sem_timedwait is an absolute time, so we need to
1057          * get the current time, then add in the millisecond Timeout value.
1058          */
1059         if (clock_gettime (CLOCK_REALTIME, &Time) == -1)
1060         {
1061             perror ("clock_gettime");
1062             return (AE_TIME);
1063         }
1064 
1065         Time.tv_sec += (MsecTimeout / ACPI_MSEC_PER_SEC);
1066         Time.tv_nsec += ((MsecTimeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC);
1067 
1068         /* Handle nanosecond overflow (field must be less than one second) */
1069 
1070         if (Time.tv_nsec >= ACPI_NSEC_PER_SEC)
1071         {
1072             Time.tv_sec += (Time.tv_nsec / ACPI_NSEC_PER_SEC);
1073             Time.tv_nsec = (Time.tv_nsec % ACPI_NSEC_PER_SEC);
1074         }
1075 
1076         while (((RetVal = sem_timedwait (Sem, &Time)) == -1) && (errno == EINTR))
1077         {
1078             continue;
1079         }
1080 
1081         if (RetVal != 0)
1082         {
1083             if (errno != ETIMEDOUT)
1084             {
1085                 perror ("sem_timedwait");
1086             }
1087             Status = (AE_TIME);
1088         }
1089 #endif
1090         break;
1091     }
1092 
1093     return (Status);
1094 }
1095 
1096 
1097 /******************************************************************************
1098  *
1099  * FUNCTION:    AcpiOsSignalSemaphore
1100  *
1101  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
1102  *              Units               - Number of units to send
1103  *
1104  * RETURN:      Status
1105  *
1106  * DESCRIPTION: Send units
1107  *
1108  *****************************************************************************/
1109 
1110 ACPI_STATUS
1111 AcpiOsSignalSemaphore (
1112     ACPI_HANDLE         Handle,
1113     UINT32              Units)
1114 {
1115     sem_t               *Sem = (sem_t *)Handle;
1116 
1117 
1118     if (!Sem)
1119     {
1120         return (AE_BAD_PARAMETER);
1121     }
1122 
1123     if (sem_post (Sem) == -1)
1124     {
1125         return (AE_LIMIT);
1126     }
1127 
1128     return (AE_OK);
1129 }
1130 
1131 #endif /* ACPI_SINGLE_THREADED */
1132 
1133 
1134 /******************************************************************************
1135  *
1136  * FUNCTION:    Spinlock interfaces
1137  *
1138  * DESCRIPTION: Map these interfaces to semaphore interfaces
1139  *
1140  *****************************************************************************/
1141 
1142 ACPI_STATUS
1143 AcpiOsCreateLock (
1144     ACPI_SPINLOCK           *OutHandle)
1145 {
1146 
1147     return (AcpiOsCreateSemaphore (1, 1, OutHandle));
1148 }
1149 
1150 
1151 void
1152 AcpiOsDeleteLock (
1153     ACPI_SPINLOCK           Handle)
1154 {
1155     AcpiOsDeleteSemaphore (Handle);
1156 }
1157 
1158 
1159 ACPI_CPU_FLAGS
1160 AcpiOsAcquireLock (
1161     ACPI_HANDLE             Handle)
1162 {
1163     AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
1164     return (0);
1165 }
1166 
1167 
1168 void
1169 AcpiOsReleaseLock (
1170     ACPI_SPINLOCK           Handle,
1171     ACPI_CPU_FLAGS          Flags)
1172 {
1173     AcpiOsSignalSemaphore (Handle, 1);
1174 }
1175 
1176 
1177 /******************************************************************************
1178  *
1179  * FUNCTION:    AcpiOsInstallInterruptHandler
1180  *
1181  * PARAMETERS:  InterruptNumber     - Level handler should respond to.
1182  *              Isr                 - Address of the ACPI interrupt handler
1183  *              ExceptPtr           - Where status is returned
1184  *
1185  * RETURN:      Handle to the newly installed handler.
1186  *
1187  * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
1188  *              OS-independent handler.
1189  *
1190  *****************************************************************************/
1191 
1192 UINT32
1193 AcpiOsInstallInterruptHandler (
1194     UINT32                  InterruptNumber,
1195     ACPI_OSD_HANDLER        ServiceRoutine,
1196     void                    *Context)
1197 {
1198 
1199     return (AE_OK);
1200 }
1201 
1202 
1203 /******************************************************************************
1204  *
1205  * FUNCTION:    AcpiOsRemoveInterruptHandler
1206  *
1207  * PARAMETERS:  Handle              - Returned when handler was installed
1208  *
1209  * RETURN:      Status
1210  *
1211  * DESCRIPTION: Uninstalls an interrupt handler.
1212  *
1213  *****************************************************************************/
1214 
1215 ACPI_STATUS
1216 AcpiOsRemoveInterruptHandler (
1217     UINT32                  InterruptNumber,
1218     ACPI_OSD_HANDLER        ServiceRoutine)
1219 {
1220 
1221     return (AE_OK);
1222 }
1223 
1224 
1225 /******************************************************************************
1226  *
1227  * FUNCTION:    AcpiOsStall
1228  *
1229  * PARAMETERS:  microseconds        - Time to sleep
1230  *
1231  * RETURN:      Blocks until sleep is completed.
1232  *
1233  * DESCRIPTION: Sleep at microsecond granularity
1234  *
1235  *****************************************************************************/
1236 
1237 void
1238 AcpiOsStall (
1239     UINT32                  microseconds)
1240 {
1241 
1242     if (microseconds)
1243     {
1244         usleep (microseconds);
1245     }
1246 }
1247 
1248 
1249 /******************************************************************************
1250  *
1251  * FUNCTION:    AcpiOsSleep
1252  *
1253  * PARAMETERS:  milliseconds        - Time to sleep
1254  *
1255  * RETURN:      Blocks until sleep is completed.
1256  *
1257  * DESCRIPTION: Sleep at millisecond granularity
1258  *
1259  *****************************************************************************/
1260 
1261 void
1262 AcpiOsSleep (
1263     UINT64                  milliseconds)
1264 {
1265 
1266     /* Sleep for whole seconds */
1267 
1268     sleep (milliseconds / ACPI_MSEC_PER_SEC);
1269 
1270     /*
1271      * Sleep for remaining microseconds.
1272      * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second).
1273      */
1274     usleep ((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC);
1275 }
1276 
1277 
1278 /******************************************************************************
1279  *
1280  * FUNCTION:    AcpiOsGetTimer
1281  *
1282  * PARAMETERS:  None
1283  *
1284  * RETURN:      Current time in 100 nanosecond units
1285  *
1286  * DESCRIPTION: Get the current system time
1287  *
1288  *****************************************************************************/
1289 
1290 UINT64
1291 AcpiOsGetTimer (
1292     void)
1293 {
1294     struct timeval          time;
1295 
1296 
1297     /* This timer has sufficient resolution for user-space application code */
1298 
1299     gettimeofday (&time, NULL);
1300 
1301     /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */
1302 
1303     return (((UINT64) time.tv_sec * ACPI_100NSEC_PER_SEC) +
1304             ((UINT64) time.tv_usec * ACPI_100NSEC_PER_USEC));
1305 }
1306 
1307 
1308 /******************************************************************************
1309  *
1310  * FUNCTION:    AcpiOsReadPciConfiguration
1311  *
1312  * PARAMETERS:  PciId               - Seg/Bus/Dev
1313  *              PciRegister         - Device Register
1314  *              Value               - Buffer where value is placed
1315  *              Width               - Number of bits
1316  *
1317  * RETURN:      Status
1318  *
1319  * DESCRIPTION: Read data from PCI configuration space
1320  *
1321  *****************************************************************************/
1322 
1323 ACPI_STATUS
1324 AcpiOsReadPciConfiguration (
1325     ACPI_PCI_ID             *PciId,
1326     UINT32                  PciRegister,
1327     UINT64                  *Value,
1328     UINT32                  Width)
1329 {
1330 
1331     *Value = 0;
1332     return (AE_OK);
1333 }
1334 
1335 
1336 /******************************************************************************
1337  *
1338  * FUNCTION:    AcpiOsWritePciConfiguration
1339  *
1340  * PARAMETERS:  PciId               - Seg/Bus/Dev
1341  *              PciRegister         - Device Register
1342  *              Value               - Value to be written
1343  *              Width               - Number of bits
1344  *
1345  * RETURN:      Status.
1346  *
1347  * DESCRIPTION: Write data to PCI configuration space
1348  *
1349  *****************************************************************************/
1350 
1351 ACPI_STATUS
1352 AcpiOsWritePciConfiguration (
1353     ACPI_PCI_ID             *PciId,
1354     UINT32                  PciRegister,
1355     UINT64                  Value,
1356     UINT32                  Width)
1357 {
1358 
1359     return (AE_OK);
1360 }
1361 
1362 
1363 /******************************************************************************
1364  *
1365  * FUNCTION:    AcpiOsReadPort
1366  *
1367  * PARAMETERS:  Address             - Address of I/O port/register to read
1368  *              Value               - Where value is placed
1369  *              Width               - Number of bits
1370  *
1371  * RETURN:      Value read from port
1372  *
1373  * DESCRIPTION: Read data from an I/O port or register
1374  *
1375  *****************************************************************************/
1376 
1377 ACPI_STATUS
1378 AcpiOsReadPort (
1379     ACPI_IO_ADDRESS         Address,
1380     UINT32                  *Value,
1381     UINT32                  Width)
1382 {
1383 
1384     switch (Width)
1385     {
1386     case 8:
1387 
1388         *Value = 0xFF;
1389         break;
1390 
1391     case 16:
1392 
1393         *Value = 0xFFFF;
1394         break;
1395 
1396     case 32:
1397 
1398         *Value = 0xFFFFFFFF;
1399         break;
1400 
1401     default:
1402 
1403         return (AE_BAD_PARAMETER);
1404     }
1405 
1406     return (AE_OK);
1407 }
1408 
1409 
1410 /******************************************************************************
1411  *
1412  * FUNCTION:    AcpiOsWritePort
1413  *
1414  * PARAMETERS:  Address             - Address of I/O port/register to write
1415  *              Value               - Value to write
1416  *              Width               - Number of bits
1417  *
1418  * RETURN:      None
1419  *
1420  * DESCRIPTION: Write data to an I/O port or register
1421  *
1422  *****************************************************************************/
1423 
1424 ACPI_STATUS
1425 AcpiOsWritePort (
1426     ACPI_IO_ADDRESS         Address,
1427     UINT32                  Value,
1428     UINT32                  Width)
1429 {
1430 
1431     return (AE_OK);
1432 }
1433 
1434 
1435 /******************************************************************************
1436  *
1437  * FUNCTION:    AcpiOsReadMemory
1438  *
1439  * PARAMETERS:  Address             - Physical Memory Address to read
1440  *              Value               - Where value is placed
1441  *              Width               - Number of bits (8,16,32, or 64)
1442  *
1443  * RETURN:      Value read from physical memory address. Always returned
1444  *              as a 64-bit integer, regardless of the read width.
1445  *
1446  * DESCRIPTION: Read data from a physical memory address
1447  *
1448  *****************************************************************************/
1449 
1450 ACPI_STATUS
1451 AcpiOsReadMemory (
1452     ACPI_PHYSICAL_ADDRESS   Address,
1453     UINT64                  *Value,
1454     UINT32                  Width)
1455 {
1456 
1457     switch (Width)
1458     {
1459     case 8:
1460     case 16:
1461     case 32:
1462     case 64:
1463 
1464         *Value = 0;
1465         break;
1466 
1467     default:
1468 
1469         return (AE_BAD_PARAMETER);
1470     }
1471     return (AE_OK);
1472 }
1473 
1474 
1475 /******************************************************************************
1476  *
1477  * FUNCTION:    AcpiOsWriteMemory
1478  *
1479  * PARAMETERS:  Address             - Physical Memory Address to write
1480  *              Value               - Value to write
1481  *              Width               - Number of bits (8,16,32, or 64)
1482  *
1483  * RETURN:      None
1484  *
1485  * DESCRIPTION: Write data to a physical memory address
1486  *
1487  *****************************************************************************/
1488 
1489 ACPI_STATUS
1490 AcpiOsWriteMemory (
1491     ACPI_PHYSICAL_ADDRESS   Address,
1492     UINT64                  Value,
1493     UINT32                  Width)
1494 {
1495 
1496     return (AE_OK);
1497 }
1498 
1499 
1500 /******************************************************************************
1501  *
1502  * FUNCTION:    AcpiOsReadable
1503  *
1504  * PARAMETERS:  Pointer             - Area to be verified
1505  *              Length              - Size of area
1506  *
1507  * RETURN:      TRUE if readable for entire length
1508  *
1509  * DESCRIPTION: Verify that a pointer is valid for reading
1510  *
1511  *****************************************************************************/
1512 
1513 BOOLEAN
1514 AcpiOsReadable (
1515     void                    *Pointer,
1516     ACPI_SIZE               Length)
1517 {
1518 
1519     return (TRUE);
1520 }
1521 
1522 
1523 /******************************************************************************
1524  *
1525  * FUNCTION:    AcpiOsWritable
1526  *
1527  * PARAMETERS:  Pointer             - Area to be verified
1528  *              Length              - Size of area
1529  *
1530  * RETURN:      TRUE if writable for entire length
1531  *
1532  * DESCRIPTION: Verify that a pointer is valid for writing
1533  *
1534  *****************************************************************************/
1535 
1536 BOOLEAN
1537 AcpiOsWritable (
1538     void                    *Pointer,
1539     ACPI_SIZE               Length)
1540 {
1541 
1542     return (TRUE);
1543 }
1544 
1545 
1546 /******************************************************************************
1547  *
1548  * FUNCTION:    AcpiOsSignal
1549  *
1550  * PARAMETERS:  Function            - ACPI A signal function code
1551  *              Info                - Pointer to function-dependent structure
1552  *
1553  * RETURN:      Status
1554  *
1555  * DESCRIPTION: Miscellaneous functions. Example implementation only.
1556  *
1557  *****************************************************************************/
1558 
1559 ACPI_STATUS
1560 AcpiOsSignal (
1561     UINT32                  Function,
1562     void                    *Info)
1563 {
1564 
1565     switch (Function)
1566     {
1567     case ACPI_SIGNAL_FATAL:
1568 
1569         break;
1570 
1571     case ACPI_SIGNAL_BREAKPOINT:
1572 
1573         break;
1574 
1575     default:
1576 
1577         break;
1578     }
1579 
1580     return (AE_OK);
1581 }
1582 
1583 /* Optional multi-thread support */
1584 
1585 #ifndef ACPI_SINGLE_THREADED
1586 /******************************************************************************
1587  *
1588  * FUNCTION:    AcpiOsGetThreadId
1589  *
1590  * PARAMETERS:  None
1591  *
1592  * RETURN:      Id of the running thread
1593  *
1594  * DESCRIPTION: Get the ID of the current (running) thread
1595  *
1596  *****************************************************************************/
1597 
1598 ACPI_THREAD_ID
1599 AcpiOsGetThreadId (
1600     void)
1601 {
1602     pthread_t               thread;
1603 
1604 
1605     thread = pthread_self();
1606     return (ACPI_CAST_PTHREAD_T (thread));
1607 }
1608 
1609 
1610 /******************************************************************************
1611  *
1612  * FUNCTION:    AcpiOsExecute
1613  *
1614  * PARAMETERS:  Type                - Type of execution
1615  *              Function            - Address of the function to execute
1616  *              Context             - Passed as a parameter to the function
1617  *
1618  * RETURN:      Status.
1619  *
1620  * DESCRIPTION: Execute a new thread
1621  *
1622  *****************************************************************************/
1623 
1624 ACPI_STATUS
1625 AcpiOsExecute (
1626     ACPI_EXECUTE_TYPE       Type,
1627     ACPI_OSD_EXEC_CALLBACK  Function,
1628     void                    *Context)
1629 {
1630     pthread_t               thread;
1631     int                     ret;
1632 
1633 
1634     ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context);
1635     if (ret)
1636     {
1637         AcpiOsPrintf("Create thread failed");
1638     }
1639     return (0);
1640 }
1641 
1642 #else /* ACPI_SINGLE_THREADED */
1643 ACPI_THREAD_ID
1644 AcpiOsGetThreadId (
1645     void)
1646 {
1647     return (1);
1648 }
1649 
1650 ACPI_STATUS
1651 AcpiOsExecute (
1652     ACPI_EXECUTE_TYPE       Type,
1653     ACPI_OSD_EXEC_CALLBACK  Function,
1654     void                    *Context)
1655 {
1656 
1657     Function (Context);
1658 
1659     return (AE_OK);
1660 }
1661 
1662 #endif /* ACPI_SINGLE_THREADED */
1663 
1664 
1665 /******************************************************************************
1666  *
1667  * FUNCTION:    AcpiOsWaitEventsComplete
1668  *
1669  * PARAMETERS:  None
1670  *
1671  * RETURN:      None
1672  *
1673  * DESCRIPTION: Wait for all asynchronous events to complete. This
1674  *              implementation does nothing.
1675  *
1676  *****************************************************************************/
1677 
1678 void
1679 AcpiOsWaitEventsComplete (
1680     void)
1681 {
1682     return;
1683 }
1684