1193267Sjkim/******************************************************************************
2193267Sjkim *
3193267Sjkim * Module Name: osunixxf - UNIX OSL interfaces
4193267Sjkim *
5193267Sjkim *****************************************************************************/
6193267Sjkim
7316303Sjkim/******************************************************************************
8316303Sjkim *
9316303Sjkim * 1. Copyright Notice
10316303Sjkim *
11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12193267Sjkim * All rights reserved.
13193267Sjkim *
14316303Sjkim * 2. License
15316303Sjkim *
16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17316303Sjkim * rights. You may have additional license terms from the party that provided
18316303Sjkim * you this software, covering your right to use that party's intellectual
19316303Sjkim * property rights.
20316303Sjkim *
21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an
23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered
26316303Sjkim * Code in any form, with the right to sublicense such rights; and
27316303Sjkim *
28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29316303Sjkim * license (with the right to sublicense), under only those claims of Intel
30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright
33316303Sjkim * license, and in no event shall the patent license extend to any additions
34316303Sjkim * to or modifications of the Original Intel Code. No other license or right
35316303Sjkim * is granted directly or by implication, estoppel or otherwise;
36316303Sjkim *
37316303Sjkim * The above copyright and patent license is granted only if the following
38316303Sjkim * conditions are met:
39316303Sjkim *
40316303Sjkim * 3. Conditions
41316303Sjkim *
42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43316303Sjkim * Redistribution of source code of any substantial portion of the Covered
44316303Sjkim * Code or modification with rights to further distribute source must include
45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition,
47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered
49316303Sjkim * Code and the date of any change. Licensee must include in that file the
50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee
51316303Sjkim * must include a prominent statement that the modification is derived,
52316303Sjkim * directly or indirectly, from Original Intel Code.
53316303Sjkim *
54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55316303Sjkim * Redistribution of source code of any substantial portion of the Covered
56316303Sjkim * Code or modification without rights to further distribute source must
57316303Sjkim * include the following Disclaimer and Export Compliance provision in the
58316303Sjkim * documentation and/or other materials provided with distribution. In
59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any
60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the
61316303Sjkim * license from Licensee to its licensee is limited to the intellectual
62316303Sjkim * property embodied in the software Licensee provides to its licensee, and
63316303Sjkim * not to intellectual property embodied in modifications its licensee may
64316303Sjkim * make.
65316303Sjkim *
66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the
68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69316303Sjkim * provision in the documentation and/or other materials provided with the
70316303Sjkim * distribution.
71316303Sjkim *
72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73316303Sjkim * Intel Code.
74316303Sjkim *
75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77316303Sjkim * other dealings in products derived from or relating to the Covered Code
78316303Sjkim * without prior written authorization from Intel.
79316303Sjkim *
80316303Sjkim * 4. Disclaimer and Export Compliance
81316303Sjkim *
82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88316303Sjkim * PARTICULAR PURPOSE.
89316303Sjkim *
90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97316303Sjkim * LIMITED REMEDY.
98316303Sjkim *
99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100316303Sjkim * software or system incorporating such software without first obtaining any
101316303Sjkim * required license or other approval from the U. S. Department of Commerce or
102316303Sjkim * any other agency or department of the United States Government. In the
103316303Sjkim * event Licensee exports any such software from the United States or
104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall
105316303Sjkim * ensure that the distribution and export/re-export of the software is in
106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109316303Sjkim * software, or service, directly or indirectly, to any country for which the
110316303Sjkim * United States government or any agency thereof requires an export license,
111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining
112316303Sjkim * such license, approval or letter.
113316303Sjkim *
114316303Sjkim *****************************************************************************
115316303Sjkim *
116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
117316303Sjkim * following license:
118316303Sjkim *
119217355Sjkim * Redistribution and use in source and binary forms, with or without
120217355Sjkim * modification, are permitted provided that the following conditions
121217355Sjkim * are met:
122217355Sjkim * 1. Redistributions of source code must retain the above copyright
123217355Sjkim *    notice, this list of conditions, and the following disclaimer,
124217355Sjkim *    without modification.
125217355Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126217355Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
127217355Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
128217355Sjkim *    including a substantially similar Disclaimer requirement for further
129217355Sjkim *    binary redistribution.
130217355Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
131217355Sjkim *    of any contributors may be used to endorse or promote products derived
132217355Sjkim *    from this software without specific prior written permission.
133193267Sjkim *
134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145316303Sjkim *
146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
147217355Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
148217355Sjkim * Software Foundation.
149193267Sjkim *
150316303Sjkim *****************************************************************************/
151193267Sjkim
152193267Sjkim/*
153213800Sjkim * These interfaces are required in order to compile the ASL compiler and the
154213800Sjkim * various ACPICA tools under Linux or other Unix-like system.
155193267Sjkim */
156228110Sjkim#include <contrib/dev/acpica/include/acpi.h>
157228110Sjkim#include <contrib/dev/acpica/include/accommon.h>
158228110Sjkim#include <contrib/dev/acpica/include/amlcode.h>
159228110Sjkim#include <contrib/dev/acpica/include/acparser.h>
160228110Sjkim#include <contrib/dev/acpica/include/acdebug.h>
161223480Sjkim
162193267Sjkim#include <stdio.h>
163193267Sjkim#include <stdlib.h>
164193267Sjkim#include <stdarg.h>
165193267Sjkim#include <unistd.h>
166193267Sjkim#include <sys/time.h>
167193267Sjkim#include <semaphore.h>
168193267Sjkim#include <pthread.h>
169209734Sjkim#include <errno.h>
170193267Sjkim
171193267Sjkim#define _COMPONENT          ACPI_OS_SERVICES
172193267Sjkim        ACPI_MODULE_NAME    ("osunixxf")
173193267Sjkim
174193267Sjkim
175193267Sjkim/* Upcalls to AcpiExec */
176193267Sjkim
177193267Sjkimvoid
178193267SjkimAeTableOverride (
179193267Sjkim    ACPI_TABLE_HEADER       *ExistingTable,
180193267Sjkim    ACPI_TABLE_HEADER       **NewTable);
181193267Sjkim
182193267Sjkimtypedef void* (*PTHREAD_CALLBACK) (void *);
183193267Sjkim
184245582Sjkim/* Buffer used by AcpiOsVprintf */
185245582Sjkim
186272444Sjkim#define ACPI_VPRINTF_BUFFER_SIZE    512
187272444Sjkim#define _ASCII_NEWLINE              '\n'
188245582Sjkim
189272444Sjkim/* Terminal support for AcpiExec only */
190193267Sjkim
191272444Sjkim#ifdef ACPI_EXEC_APP
192272444Sjkim#include <termios.h>
193272444Sjkim
194272444Sjkimstruct termios              OriginalTermAttributes;
195272444Sjkimint                         TermAttributesWereSet = 0;
196272444Sjkim
197272444SjkimACPI_STATUS
198272444SjkimAcpiUtReadLine (
199272444Sjkim    char                    *Buffer,
200272444Sjkim    UINT32                  BufferLength,
201272444Sjkim    UINT32                  *BytesRead);
202272444Sjkim
203272444Sjkimstatic void
204272444SjkimOsEnterLineEditMode (
205272444Sjkim    void);
206272444Sjkim
207272444Sjkimstatic void
208272444SjkimOsExitLineEditMode (
209272444Sjkim    void);
210272444Sjkim
211272444Sjkim
212193267Sjkim/******************************************************************************
213193267Sjkim *
214272444Sjkim * FUNCTION:    OsEnterLineEditMode, OsExitLineEditMode
215272444Sjkim *
216272444Sjkim * PARAMETERS:  None
217272444Sjkim *
218272444Sjkim * RETURN:      None
219272444Sjkim *
220272444Sjkim * DESCRIPTION: Enter/Exit the raw character input mode for the terminal.
221272444Sjkim *
222272444Sjkim * Interactive line-editing support for the AML debugger. Used with the
223272444Sjkim * common/acgetline module.
224272444Sjkim *
225272444Sjkim * readline() is not used because of non-portability. It is not available
226272444Sjkim * on all systems, and if it is, often the package must be manually installed.
227272444Sjkim *
228272444Sjkim * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line
229272444Sjkim * editing that we need in AcpiOsGetLine.
230272444Sjkim *
231272444Sjkim * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these
232272444Sjkim * calls will also work:
233272444Sjkim *     For OsEnterLineEditMode: system ("stty cbreak -echo")
234272444Sjkim *     For OsExitLineEditMode:  system ("stty cooked echo")
235272444Sjkim *
236272444Sjkim *****************************************************************************/
237272444Sjkim
238272444Sjkimstatic void
239272444SjkimOsEnterLineEditMode (
240272444Sjkim    void)
241272444Sjkim{
242272444Sjkim    struct termios          LocalTermAttributes;
243272444Sjkim
244272444Sjkim
245272444Sjkim    TermAttributesWereSet = 0;
246272444Sjkim
247272444Sjkim    /* STDIN must be a terminal */
248272444Sjkim
249272444Sjkim    if (!isatty (STDIN_FILENO))
250272444Sjkim    {
251272444Sjkim        return;
252272444Sjkim    }
253272444Sjkim
254272444Sjkim    /* Get and keep the original attributes */
255272444Sjkim
256272444Sjkim    if (tcgetattr (STDIN_FILENO, &OriginalTermAttributes))
257272444Sjkim    {
258272444Sjkim        fprintf (stderr, "Could not get terminal attributes!\n");
259272444Sjkim        return;
260272444Sjkim    }
261272444Sjkim
262272444Sjkim    /* Set the new attributes to enable raw character input */
263272444Sjkim
264272444Sjkim    memcpy (&LocalTermAttributes, &OriginalTermAttributes,
265272444Sjkim        sizeof (struct termios));
266272444Sjkim
267272444Sjkim    LocalTermAttributes.c_lflag &= ~(ICANON | ECHO);
268272444Sjkim    LocalTermAttributes.c_cc[VMIN] = 1;
269272444Sjkim    LocalTermAttributes.c_cc[VTIME] = 0;
270272444Sjkim
271272444Sjkim    if (tcsetattr (STDIN_FILENO, TCSANOW, &LocalTermAttributes))
272272444Sjkim    {
273272444Sjkim        fprintf (stderr, "Could not set terminal attributes!\n");
274272444Sjkim        return;
275272444Sjkim    }
276272444Sjkim
277272444Sjkim    TermAttributesWereSet = 1;
278272444Sjkim}
279272444Sjkim
280272444Sjkim
281272444Sjkimstatic void
282272444SjkimOsExitLineEditMode (
283272444Sjkim    void)
284272444Sjkim{
285272444Sjkim
286272444Sjkim    if (!TermAttributesWereSet)
287272444Sjkim    {
288272444Sjkim        return;
289272444Sjkim    }
290272444Sjkim
291272444Sjkim    /* Set terminal attributes back to the original values */
292272444Sjkim
293272444Sjkim    if (tcsetattr (STDIN_FILENO, TCSANOW, &OriginalTermAttributes))
294272444Sjkim    {
295272444Sjkim        fprintf (stderr, "Could not restore terminal attributes!\n");
296272444Sjkim    }
297272444Sjkim}
298272444Sjkim
299272444Sjkim
300272444Sjkim#else
301272444Sjkim
302272444Sjkim/* These functions are not needed for other ACPICA utilities */
303272444Sjkim
304272444Sjkim#define OsEnterLineEditMode()
305272444Sjkim#define OsExitLineEditMode()
306272444Sjkim#endif
307272444Sjkim
308272444Sjkim
309272444Sjkim/******************************************************************************
310272444Sjkim *
311193267Sjkim * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
312193267Sjkim *
313193267Sjkim * PARAMETERS:  None
314193267Sjkim *
315193267Sjkim * RETURN:      Status
316193267Sjkim *
317272444Sjkim * DESCRIPTION: Initialize and terminate this module.
318193267Sjkim *
319193267Sjkim *****************************************************************************/
320193267Sjkim
321193267SjkimACPI_STATUS
322213800SjkimAcpiOsInitialize (
323213800Sjkim    void)
324193267Sjkim{
325272444Sjkim    ACPI_STATUS            Status;
326193267Sjkim
327272444Sjkim
328193267Sjkim    AcpiGbl_OutputFile = stdout;
329272444Sjkim
330272444Sjkim    OsEnterLineEditMode ();
331272444Sjkim
332272444Sjkim    Status = AcpiOsCreateLock (&AcpiGbl_PrintLock);
333272444Sjkim    if (ACPI_FAILURE (Status))
334272444Sjkim    {
335272444Sjkim        return (Status);
336272444Sjkim    }
337272444Sjkim
338193267Sjkim    return (AE_OK);
339193267Sjkim}
340193267Sjkim
341193267SjkimACPI_STATUS
342213800SjkimAcpiOsTerminate (
343213800Sjkim    void)
344193267Sjkim{
345193267Sjkim
346272444Sjkim    OsExitLineEditMode ();
347193267Sjkim    return (AE_OK);
348193267Sjkim}
349193267Sjkim
350193267Sjkim
351272444Sjkim#ifndef ACPI_USE_NATIVE_RSDP_POINTER
352193267Sjkim/******************************************************************************
353193267Sjkim *
354193267Sjkim * FUNCTION:    AcpiOsGetRootPointer
355193267Sjkim *
356193267Sjkim * PARAMETERS:  None
357193267Sjkim *
358193267Sjkim * RETURN:      RSDP physical address
359193267Sjkim *
360213800Sjkim * DESCRIPTION: Gets the ACPI root pointer (RSDP)
361193267Sjkim *
362193267Sjkim *****************************************************************************/
363193267Sjkim
364193267SjkimACPI_PHYSICAL_ADDRESS
365193267SjkimAcpiOsGetRootPointer (
366193267Sjkim    void)
367193267Sjkim{
368193267Sjkim
369272444Sjkim    return (0);
370193267Sjkim}
371272444Sjkim#endif
372193267Sjkim
373193267Sjkim
374193267Sjkim/******************************************************************************
375193267Sjkim *
376193267Sjkim * FUNCTION:    AcpiOsPredefinedOverride
377193267Sjkim *
378213800Sjkim * PARAMETERS:  InitVal             - Initial value of the predefined object
379213800Sjkim *              NewVal              - The new value for the object
380193267Sjkim *
381213800Sjkim * RETURN:      Status, pointer to value. Null pointer returned if not
382193267Sjkim *              overriding.
383193267Sjkim *
384193267Sjkim * DESCRIPTION: Allow the OS to override predefined names
385193267Sjkim *
386193267Sjkim *****************************************************************************/
387193267Sjkim
388193267SjkimACPI_STATUS
389193267SjkimAcpiOsPredefinedOverride (
390193267Sjkim    const ACPI_PREDEFINED_NAMES *InitVal,
391193267Sjkim    ACPI_STRING                 *NewVal)
392193267Sjkim{
393193267Sjkim
394193267Sjkim    if (!InitVal || !NewVal)
395193267Sjkim    {
396193267Sjkim        return (AE_BAD_PARAMETER);
397193267Sjkim    }
398193267Sjkim
399193267Sjkim    *NewVal = NULL;
400193267Sjkim    return (AE_OK);
401193267Sjkim}
402193267Sjkim
403193267Sjkim
404193267Sjkim/******************************************************************************
405193267Sjkim *
406193267Sjkim * FUNCTION:    AcpiOsTableOverride
407193267Sjkim *
408213800Sjkim * PARAMETERS:  ExistingTable       - Header of current table (probably
409213800Sjkim *                                    firmware)
410213800Sjkim *              NewTable            - Where an entire new table is returned.
411193267Sjkim *
412213800Sjkim * RETURN:      Status, pointer to new table. Null pointer returned if no
413193267Sjkim *              table is available to override
414193267Sjkim *
415193267Sjkim * DESCRIPTION: Return a different version of a table if one is available
416193267Sjkim *
417193267Sjkim *****************************************************************************/
418193267Sjkim
419193267SjkimACPI_STATUS
420193267SjkimAcpiOsTableOverride (
421193267Sjkim    ACPI_TABLE_HEADER       *ExistingTable,
422193267Sjkim    ACPI_TABLE_HEADER       **NewTable)
423193267Sjkim{
424193267Sjkim
425193267Sjkim    if (!ExistingTable || !NewTable)
426193267Sjkim    {
427193267Sjkim        return (AE_BAD_PARAMETER);
428193267Sjkim    }
429193267Sjkim
430193267Sjkim    *NewTable = NULL;
431193267Sjkim
432193267Sjkim#ifdef ACPI_EXEC_APP
433193267Sjkim
434193267Sjkim    AeTableOverride (ExistingTable, NewTable);
435193267Sjkim    return (AE_OK);
436193267Sjkim#else
437193267Sjkim
438193267Sjkim    return (AE_NO_ACPI_TABLES);
439193267Sjkim#endif
440193267Sjkim}
441193267Sjkim
442193267Sjkim
443193267Sjkim/******************************************************************************
444193267Sjkim *
445231844Sjkim * FUNCTION:    AcpiOsPhysicalTableOverride
446231844Sjkim *
447231844Sjkim * PARAMETERS:  ExistingTable       - Header of current table (probably firmware)
448231844Sjkim *              NewAddress          - Where new table address is returned
449231844Sjkim *                                    (Physical address)
450231844Sjkim *              NewTableLength      - Where new table length is returned
451231844Sjkim *
452231844Sjkim * RETURN:      Status, address/length of new table. Null pointer returned
453231844Sjkim *              if no table is available to override.
454231844Sjkim *
455231844Sjkim * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
456231844Sjkim *
457231844Sjkim *****************************************************************************/
458231844Sjkim
459231844SjkimACPI_STATUS
460231844SjkimAcpiOsPhysicalTableOverride (
461231844Sjkim    ACPI_TABLE_HEADER       *ExistingTable,
462231844Sjkim    ACPI_PHYSICAL_ADDRESS   *NewAddress,
463231844Sjkim    UINT32                  *NewTableLength)
464231844Sjkim{
465231844Sjkim
466231844Sjkim    return (AE_SUPPORT);
467231844Sjkim}
468231844Sjkim
469231844Sjkim
470231844Sjkim/******************************************************************************
471231844Sjkim *
472316303Sjkim * FUNCTION:    AcpiOsEnterSleep
473316303Sjkim *
474316303Sjkim * PARAMETERS:  SleepState          - Which sleep state to enter
475316303Sjkim *              RegaValue           - Register A value
476316303Sjkim *              RegbValue           - Register B value
477316303Sjkim *
478316303Sjkim * RETURN:      Status
479316303Sjkim *
480316303Sjkim * DESCRIPTION: A hook before writing sleep registers to enter the sleep
481316303Sjkim *              state. Return AE_CTRL_TERMINATE to skip further sleep register
482316303Sjkim *              writes.
483316303Sjkim *
484316303Sjkim *****************************************************************************/
485316303Sjkim
486316303SjkimACPI_STATUS
487316303SjkimAcpiOsEnterSleep (
488316303Sjkim    UINT8                   SleepState,
489316303Sjkim    UINT32                  RegaValue,
490316303Sjkim    UINT32                  RegbValue)
491316303Sjkim{
492316303Sjkim
493316303Sjkim    return (AE_OK);
494316303Sjkim}
495316303Sjkim
496316303Sjkim
497316303Sjkim/******************************************************************************
498316303Sjkim *
499193267Sjkim * FUNCTION:    AcpiOsRedirectOutput
500193267Sjkim *
501193267Sjkim * PARAMETERS:  Destination         - An open file handle/pointer
502193267Sjkim *
503193267Sjkim * RETURN:      None
504193267Sjkim *
505193267Sjkim * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
506193267Sjkim *
507193267Sjkim *****************************************************************************/
508193267Sjkim
509193267Sjkimvoid
510193267SjkimAcpiOsRedirectOutput (
511193267Sjkim    void                    *Destination)
512193267Sjkim{
513193267Sjkim
514193267Sjkim    AcpiGbl_OutputFile = Destination;
515193267Sjkim}
516193267Sjkim
517193267Sjkim
518193267Sjkim/******************************************************************************
519193267Sjkim *
520193267Sjkim * FUNCTION:    AcpiOsPrintf
521193267Sjkim *
522213800Sjkim * PARAMETERS:  fmt, ...            - Standard printf format
523193267Sjkim *
524193267Sjkim * RETURN:      None
525193267Sjkim *
526245582Sjkim * DESCRIPTION: Formatted output. Note: very similar to AcpiOsVprintf
527245582Sjkim *              (performance), changes should be tracked in both functions.
528193267Sjkim *
529193267Sjkim *****************************************************************************/
530193267Sjkim
531193267Sjkimvoid ACPI_INTERNAL_VAR_XFACE
532193267SjkimAcpiOsPrintf (
533193267Sjkim    const char              *Fmt,
534193267Sjkim    ...)
535193267Sjkim{
536193267Sjkim    va_list                 Args;
537245582Sjkim    UINT8                   Flags;
538193267Sjkim
539193267Sjkim
540245582Sjkim    Flags = AcpiGbl_DbOutputFlags;
541245582Sjkim    if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
542245582Sjkim    {
543245582Sjkim        /* Output is directable to either a file (if open) or the console */
544245582Sjkim
545245582Sjkim        if (AcpiGbl_DebugFile)
546245582Sjkim        {
547245582Sjkim            /* Output file is open, send the output there */
548245582Sjkim
549245582Sjkim            va_start (Args, Fmt);
550245582Sjkim            vfprintf (AcpiGbl_DebugFile, Fmt, Args);
551245582Sjkim            va_end (Args);
552245582Sjkim        }
553245582Sjkim        else
554245582Sjkim        {
555245582Sjkim            /* No redirection, send output to console (once only!) */
556245582Sjkim
557245582Sjkim            Flags |= ACPI_DB_CONSOLE_OUTPUT;
558245582Sjkim        }
559245582Sjkim    }
560245582Sjkim
561245582Sjkim    if (Flags & ACPI_DB_CONSOLE_OUTPUT)
562245582Sjkim    {
563245582Sjkim        va_start (Args, Fmt);
564245582Sjkim        vfprintf (AcpiGbl_OutputFile, Fmt, Args);
565245582Sjkim        va_end (Args);
566245582Sjkim    }
567193267Sjkim}
568193267Sjkim
569193267Sjkim
570193267Sjkim/******************************************************************************
571193267Sjkim *
572193267Sjkim * FUNCTION:    AcpiOsVprintf
573193267Sjkim *
574213800Sjkim * PARAMETERS:  fmt                 - Standard printf format
575213800Sjkim *              args                - Argument list
576193267Sjkim *
577193267Sjkim * RETURN:      None
578193267Sjkim *
579245582Sjkim * DESCRIPTION: Formatted output with argument list pointer. Note: very
580245582Sjkim *              similar to AcpiOsPrintf, changes should be tracked in both
581245582Sjkim *              functions.
582193267Sjkim *
583193267Sjkim *****************************************************************************/
584193267Sjkim
585193267Sjkimvoid
586193267SjkimAcpiOsVprintf (
587193267Sjkim    const char              *Fmt,
588193267Sjkim    va_list                 Args)
589193267Sjkim{
590193267Sjkim    UINT8                   Flags;
591245582Sjkim    char                    Buffer[ACPI_VPRINTF_BUFFER_SIZE];
592193267Sjkim
593193267Sjkim
594245582Sjkim    /*
595245582Sjkim     * We build the output string in a local buffer because we may be
596245582Sjkim     * outputting the buffer twice. Using vfprintf is problematic because
597245582Sjkim     * some implementations modify the args pointer/structure during
598245582Sjkim     * execution. Thus, we use the local buffer for portability.
599245582Sjkim     *
600245582Sjkim     * Note: Since this module is intended for use by the various ACPICA
601245582Sjkim     * utilities/applications, we can safely declare the buffer on the stack.
602245582Sjkim     * Also, This function is used for relatively small error messages only.
603245582Sjkim     */
604245582Sjkim    vsnprintf (Buffer, ACPI_VPRINTF_BUFFER_SIZE, Fmt, Args);
605245582Sjkim
606193267Sjkim    Flags = AcpiGbl_DbOutputFlags;
607193267Sjkim    if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
608193267Sjkim    {
609193267Sjkim        /* Output is directable to either a file (if open) or the console */
610193267Sjkim
611193267Sjkim        if (AcpiGbl_DebugFile)
612193267Sjkim        {
613193267Sjkim            /* Output file is open, send the output there */
614193267Sjkim
615245582Sjkim            fputs (Buffer, AcpiGbl_DebugFile);
616193267Sjkim        }
617193267Sjkim        else
618193267Sjkim        {
619193267Sjkim            /* No redirection, send output to console (once only!) */
620193267Sjkim
621193267Sjkim            Flags |= ACPI_DB_CONSOLE_OUTPUT;
622193267Sjkim        }
623193267Sjkim    }
624193267Sjkim
625193267Sjkim    if (Flags & ACPI_DB_CONSOLE_OUTPUT)
626193267Sjkim    {
627245582Sjkim        fputs (Buffer, AcpiGbl_OutputFile);
628193267Sjkim    }
629193267Sjkim}
630193267Sjkim
631193267Sjkim
632272444Sjkim#ifndef ACPI_EXEC_APP
633193267Sjkim/******************************************************************************
634193267Sjkim *
635193267Sjkim * FUNCTION:    AcpiOsGetLine
636193267Sjkim *
637222538Sjkim * PARAMETERS:  Buffer              - Where to return the command line
638222538Sjkim *              BufferLength        - Maximum length of Buffer
639222538Sjkim *              BytesRead           - Where the actual byte count is returned
640193267Sjkim *
641222538Sjkim * RETURN:      Status and actual bytes read
642193267Sjkim *
643272444Sjkim * DESCRIPTION: Get the next input line from the terminal. NOTE: For the
644272444Sjkim *              AcpiExec utility, we use the acgetline module instead to
645272444Sjkim *              provide line-editing and history support.
646193267Sjkim *
647193267Sjkim *****************************************************************************/
648193267Sjkim
649222538SjkimACPI_STATUS
650193267SjkimAcpiOsGetLine (
651222538Sjkim    char                    *Buffer,
652222538Sjkim    UINT32                  BufferLength,
653222538Sjkim    UINT32                  *BytesRead)
654193267Sjkim{
655272444Sjkim    int                     InputChar;
656272444Sjkim    UINT32                  EndOfLine;
657193267Sjkim
658193267Sjkim
659272444Sjkim    /* Standard AcpiOsGetLine for all utilities except AcpiExec */
660272444Sjkim
661272444Sjkim    for (EndOfLine = 0; ; EndOfLine++)
662193267Sjkim    {
663272444Sjkim        if (EndOfLine >= BufferLength)
664222538Sjkim        {
665222538Sjkim            return (AE_BUFFER_OVERFLOW);
666222538Sjkim        }
667222538Sjkim
668272444Sjkim        if ((InputChar = getchar ()) == EOF)
669239340Sjkim        {
670239340Sjkim            return (AE_ERROR);
671239340Sjkim        }
672239340Sjkim
673272444Sjkim        if (!InputChar || InputChar == _ASCII_NEWLINE)
674193267Sjkim        {
675193267Sjkim            break;
676193267Sjkim        }
677193267Sjkim
678272444Sjkim        Buffer[EndOfLine] = (char) InputChar;
679193267Sjkim    }
680193267Sjkim
681193267Sjkim    /* Null terminate the buffer */
682193267Sjkim
683272444Sjkim    Buffer[EndOfLine] = 0;
684193267Sjkim
685193267Sjkim    /* Return the number of bytes in the string */
686193267Sjkim
687222538Sjkim    if (BytesRead)
688222538Sjkim    {
689272444Sjkim        *BytesRead = EndOfLine;
690222538Sjkim    }
691272444Sjkim
692222538Sjkim    return (AE_OK);
693193267Sjkim}
694272444Sjkim#endif
695193267Sjkim
696213800Sjkim
697272444Sjkim#ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
698193267Sjkim/******************************************************************************
699193267Sjkim *
700193267Sjkim * FUNCTION:    AcpiOsMapMemory
701193267Sjkim *
702213800Sjkim * PARAMETERS:  where               - Physical address of memory to be mapped
703213800Sjkim *              length              - How much memory to map
704193267Sjkim *
705213800Sjkim * RETURN:      Pointer to mapped memory. Null on error.
706193267Sjkim *
707193267Sjkim * DESCRIPTION: Map physical memory into caller's address space
708193267Sjkim *
709193267Sjkim *****************************************************************************/
710193267Sjkim
711193267Sjkimvoid *
712193267SjkimAcpiOsMapMemory (
713193267Sjkim    ACPI_PHYSICAL_ADDRESS   where,
714193267Sjkim    ACPI_SIZE               length)
715193267Sjkim{
716193267Sjkim
717193267Sjkim    return (ACPI_TO_POINTER ((ACPI_SIZE) where));
718193267Sjkim}
719193267Sjkim
720193267Sjkim
721193267Sjkim/******************************************************************************
722193267Sjkim *
723193267Sjkim * FUNCTION:    AcpiOsUnmapMemory
724193267Sjkim *
725213800Sjkim * PARAMETERS:  where               - Logical address of memory to be unmapped
726213800Sjkim *              length              - How much memory to unmap
727193267Sjkim *
728193267Sjkim * RETURN:      None.
729193267Sjkim *
730213800Sjkim * DESCRIPTION: Delete a previously created mapping. Where and Length must
731193267Sjkim *              correspond to a previous mapping exactly.
732193267Sjkim *
733193267Sjkim *****************************************************************************/
734193267Sjkim
735193267Sjkimvoid
736193267SjkimAcpiOsUnmapMemory (
737193267Sjkim    void                    *where,
738193267Sjkim    ACPI_SIZE               length)
739193267Sjkim{
740193267Sjkim
741193267Sjkim    return;
742193267Sjkim}
743272444Sjkim#endif
744193267Sjkim
745193267Sjkim
746193267Sjkim/******************************************************************************
747193267Sjkim *
748193267Sjkim * FUNCTION:    AcpiOsAllocate
749193267Sjkim *
750213800Sjkim * PARAMETERS:  Size                - Amount to allocate, in bytes
751193267Sjkim *
752213800Sjkim * RETURN:      Pointer to the new allocation. Null on error.
753193267Sjkim *
754213800Sjkim * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
755193267Sjkim *
756193267Sjkim *****************************************************************************/
757193267Sjkim
758193267Sjkimvoid *
759193267SjkimAcpiOsAllocate (
760193267Sjkim    ACPI_SIZE               size)
761193267Sjkim{
762193267Sjkim    void                    *Mem;
763193267Sjkim
764193267Sjkim
765193267Sjkim    Mem = (void *) malloc ((size_t) size);
766193267Sjkim    return (Mem);
767193267Sjkim}
768193267Sjkim
769193267Sjkim
770272444Sjkim#ifdef USE_NATIVE_ALLOCATE_ZEROED
771193267Sjkim/******************************************************************************
772193267Sjkim *
773272444Sjkim * FUNCTION:    AcpiOsAllocateZeroed
774272444Sjkim *
775272444Sjkim * PARAMETERS:  Size                - Amount to allocate, in bytes
776272444Sjkim *
777272444Sjkim * RETURN:      Pointer to the new allocation. Null on error.
778272444Sjkim *
779272444Sjkim * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
780272444Sjkim *
781272444Sjkim *****************************************************************************/
782272444Sjkim
783272444Sjkimvoid *
784272444SjkimAcpiOsAllocateZeroed (
785272444Sjkim    ACPI_SIZE               size)
786272444Sjkim{
787272444Sjkim    void                    *Mem;
788272444Sjkim
789272444Sjkim
790272444Sjkim    Mem = (void *) calloc (1, (size_t) size);
791272444Sjkim    return (Mem);
792272444Sjkim}
793272444Sjkim#endif
794272444Sjkim
795272444Sjkim
796272444Sjkim/******************************************************************************
797272444Sjkim *
798193267Sjkim * FUNCTION:    AcpiOsFree
799193267Sjkim *
800213800Sjkim * PARAMETERS:  mem                 - Pointer to previously allocated memory
801193267Sjkim *
802193267Sjkim * RETURN:      None.
803193267Sjkim *
804193267Sjkim * DESCRIPTION: Free memory allocated via AcpiOsAllocate
805193267Sjkim *
806193267Sjkim *****************************************************************************/
807193267Sjkim
808193267Sjkimvoid
809193267SjkimAcpiOsFree (
810193267Sjkim    void                    *mem)
811193267Sjkim{
812193267Sjkim
813193267Sjkim    free (mem);
814193267Sjkim}
815193267Sjkim
816193267Sjkim
817213800Sjkim#ifdef ACPI_SINGLE_THREADED
818193267Sjkim/******************************************************************************
819193267Sjkim *
820213800Sjkim * FUNCTION:    Semaphore stub functions
821213800Sjkim *
822213800Sjkim * DESCRIPTION: Stub functions used for single-thread applications that do
823213800Sjkim *              not require semaphore synchronization. Full implementations
824213800Sjkim *              of these functions appear after the stubs.
825213800Sjkim *
826213800Sjkim *****************************************************************************/
827213800Sjkim
828213800SjkimACPI_STATUS
829213800SjkimAcpiOsCreateSemaphore (
830213800Sjkim    UINT32              MaxUnits,
831213800Sjkim    UINT32              InitialUnits,
832213800Sjkim    ACPI_HANDLE         *OutHandle)
833213800Sjkim{
834213800Sjkim    *OutHandle = (ACPI_HANDLE) 1;
835213800Sjkim    return (AE_OK);
836213800Sjkim}
837213800Sjkim
838213800SjkimACPI_STATUS
839213800SjkimAcpiOsDeleteSemaphore (
840213800Sjkim    ACPI_HANDLE         Handle)
841213800Sjkim{
842213800Sjkim    return (AE_OK);
843213800Sjkim}
844213800Sjkim
845213800SjkimACPI_STATUS
846213800SjkimAcpiOsWaitSemaphore (
847213800Sjkim    ACPI_HANDLE         Handle,
848213800Sjkim    UINT32              Units,
849213800Sjkim    UINT16              Timeout)
850213800Sjkim{
851213800Sjkim    return (AE_OK);
852213800Sjkim}
853213800Sjkim
854213800SjkimACPI_STATUS
855213800SjkimAcpiOsSignalSemaphore (
856213800Sjkim    ACPI_HANDLE         Handle,
857213800Sjkim    UINT32              Units)
858213800Sjkim{
859213800Sjkim    return (AE_OK);
860213800Sjkim}
861213800Sjkim
862213800Sjkim#else
863213800Sjkim/******************************************************************************
864213800Sjkim *
865193267Sjkim * FUNCTION:    AcpiOsCreateSemaphore
866193267Sjkim *
867193267Sjkim * PARAMETERS:  InitialUnits        - Units to be assigned to the new semaphore
868193267Sjkim *              OutHandle           - Where a handle will be returned
869193267Sjkim *
870193267Sjkim * RETURN:      Status
871193267Sjkim *
872193267Sjkim * DESCRIPTION: Create an OS semaphore
873193267Sjkim *
874193267Sjkim *****************************************************************************/
875193267Sjkim
876193267SjkimACPI_STATUS
877193267SjkimAcpiOsCreateSemaphore (
878193267Sjkim    UINT32              MaxUnits,
879193267Sjkim    UINT32              InitialUnits,
880193267Sjkim    ACPI_HANDLE         *OutHandle)
881193267Sjkim{
882193267Sjkim    sem_t               *Sem;
883193267Sjkim
884193267Sjkim
885193267Sjkim    if (!OutHandle)
886193267Sjkim    {
887193267Sjkim        return (AE_BAD_PARAMETER);
888193267Sjkim    }
889193267Sjkim
890209734Sjkim#ifdef __APPLE__
891209734Sjkim    {
892316303Sjkim        static int      SemaphoreCount = 0;
893316303Sjkim        char            SemaphoreName[32];
894213800Sjkim
895316303Sjkim        snprintf (SemaphoreName, sizeof (SemaphoreName), "acpi_sem_%d",
896316303Sjkim            SemaphoreCount++);
897316303Sjkim        printf ("%s\n", SemaphoreName);
898213800Sjkim        Sem = sem_open (SemaphoreName, O_EXCL|O_CREAT, 0755, InitialUnits);
899213800Sjkim        if (!Sem)
900213800Sjkim        {
901213800Sjkim            return (AE_NO_MEMORY);
902213800Sjkim        }
903213800Sjkim        sem_unlink (SemaphoreName); /* This just deletes the name */
904209734Sjkim    }
905209734Sjkim
906209734Sjkim#else
907193267Sjkim    Sem = AcpiOsAllocate (sizeof (sem_t));
908193267Sjkim    if (!Sem)
909193267Sjkim    {
910193267Sjkim        return (AE_NO_MEMORY);
911193267Sjkim    }
912193267Sjkim
913193267Sjkim    if (sem_init (Sem, 0, InitialUnits) == -1)
914193267Sjkim    {
915193267Sjkim        AcpiOsFree (Sem);
916193267Sjkim        return (AE_BAD_PARAMETER);
917193267Sjkim    }
918209734Sjkim#endif
919193267Sjkim
920193267Sjkim    *OutHandle = (ACPI_HANDLE) Sem;
921193267Sjkim    return (AE_OK);
922193267Sjkim}
923193267Sjkim
924193267Sjkim
925193267Sjkim/******************************************************************************
926193267Sjkim *
927193267Sjkim * FUNCTION:    AcpiOsDeleteSemaphore
928193267Sjkim *
929193267Sjkim * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
930193267Sjkim *
931193267Sjkim * RETURN:      Status
932193267Sjkim *
933193267Sjkim * DESCRIPTION: Delete an OS semaphore
934193267Sjkim *
935193267Sjkim *****************************************************************************/
936193267Sjkim
937193267SjkimACPI_STATUS
938193267SjkimAcpiOsDeleteSemaphore (
939193267Sjkim    ACPI_HANDLE         Handle)
940193267Sjkim{
941193267Sjkim    sem_t               *Sem = (sem_t *) Handle;
942193267Sjkim
943193267Sjkim
944193267Sjkim    if (!Sem)
945193267Sjkim    {
946193267Sjkim        return (AE_BAD_PARAMETER);
947193267Sjkim    }
948193267Sjkim
949316303Sjkim#ifdef __APPLE__
950316303Sjkim    if (sem_close (Sem) == -1)
951316303Sjkim    {
952316303Sjkim        return (AE_BAD_PARAMETER);
953316303Sjkim    }
954316303Sjkim#else
955193267Sjkim    if (sem_destroy (Sem) == -1)
956193267Sjkim    {
957193267Sjkim        return (AE_BAD_PARAMETER);
958193267Sjkim    }
959316303Sjkim#endif
960193267Sjkim
961193267Sjkim    return (AE_OK);
962193267Sjkim}
963193267Sjkim
964193267Sjkim
965193267Sjkim/******************************************************************************
966193267Sjkim *
967193267Sjkim * FUNCTION:    AcpiOsWaitSemaphore
968193267Sjkim *
969193267Sjkim * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
970193267Sjkim *              Units               - How many units to wait for
971245582Sjkim *              MsecTimeout         - How long to wait (milliseconds)
972193267Sjkim *
973193267Sjkim * RETURN:      Status
974193267Sjkim *
975193267Sjkim * DESCRIPTION: Wait for units
976193267Sjkim *
977193267Sjkim *****************************************************************************/
978193267Sjkim
979193267SjkimACPI_STATUS
980193267SjkimAcpiOsWaitSemaphore (
981193267Sjkim    ACPI_HANDLE         Handle,
982193267Sjkim    UINT32              Units,
983245582Sjkim    UINT16              MsecTimeout)
984193267Sjkim{
985193267Sjkim    ACPI_STATUS         Status = AE_OK;
986193267Sjkim    sem_t               *Sem = (sem_t *) Handle;
987322877Sjkim    int                 RetVal;
988245582Sjkim#ifndef ACPI_USE_ALTERNATE_TIMEOUT
989245582Sjkim    struct timespec     Time;
990245582Sjkim#endif
991193267Sjkim
992193267Sjkim
993193267Sjkim    if (!Sem)
994193267Sjkim    {
995193267Sjkim        return (AE_BAD_PARAMETER);
996193267Sjkim    }
997193267Sjkim
998245582Sjkim    switch (MsecTimeout)
999193267Sjkim    {
1000193267Sjkim    /*
1001193267Sjkim     * No Wait:
1002193267Sjkim     * --------
1003193267Sjkim     * A zero timeout value indicates that we shouldn't wait - just
1004193267Sjkim     * acquire the semaphore if available otherwise return AE_TIME
1005193267Sjkim     * (a.k.a. 'would block').
1006193267Sjkim     */
1007193267Sjkim    case 0:
1008193267Sjkim
1009193267Sjkim        if (sem_trywait(Sem) == -1)
1010193267Sjkim        {
1011193267Sjkim            Status = (AE_TIME);
1012193267Sjkim        }
1013193267Sjkim        break;
1014193267Sjkim
1015193267Sjkim    /* Wait Indefinitely */
1016193267Sjkim
1017193267Sjkim    case ACPI_WAIT_FOREVER:
1018193267Sjkim
1019322877Sjkim        while (((RetVal = sem_wait (Sem)) == -1) && (errno == EINTR))
1020193267Sjkim        {
1021322877Sjkim            continue;   /* Restart if interrupted */
1022322877Sjkim        }
1023322877Sjkim        if (RetVal != 0)
1024322877Sjkim        {
1025193267Sjkim            Status = (AE_TIME);
1026193267Sjkim        }
1027193267Sjkim        break;
1028193267Sjkim
1029322877Sjkim
1030245582Sjkim    /* Wait with MsecTimeout */
1031193267Sjkim
1032193267Sjkim    default:
1033193267Sjkim
1034193267Sjkim#ifdef ACPI_USE_ALTERNATE_TIMEOUT
1035193267Sjkim        /*
1036193267Sjkim         * Alternate timeout mechanism for environments where
1037193267Sjkim         * sem_timedwait is not available or does not work properly.
1038193267Sjkim         */
1039245582Sjkim        while (MsecTimeout)
1040193267Sjkim        {
1041193267Sjkim            if (sem_trywait (Sem) == 0)
1042193267Sjkim            {
1043193267Sjkim                /* Got the semaphore */
1044193267Sjkim                return (AE_OK);
1045193267Sjkim            }
1046245582Sjkim
1047245582Sjkim            if (MsecTimeout >= 10)
1048245582Sjkim            {
1049245582Sjkim                MsecTimeout -= 10;
1050245582Sjkim                usleep (10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */
1051245582Sjkim            }
1052245582Sjkim            else
1053245582Sjkim            {
1054245582Sjkim                MsecTimeout--;
1055245582Sjkim                usleep (ACPI_USEC_PER_MSEC); /* one millisecond */
1056245582Sjkim            }
1057193267Sjkim        }
1058193267Sjkim        Status = (AE_TIME);
1059193267Sjkim#else
1060245582Sjkim        /*
1061245582Sjkim         * The interface to sem_timedwait is an absolute time, so we need to
1062245582Sjkim         * get the current time, then add in the millisecond Timeout value.
1063245582Sjkim         */
1064245582Sjkim        if (clock_gettime (CLOCK_REALTIME, &Time) == -1)
1065245582Sjkim        {
1066245582Sjkim            perror ("clock_gettime");
1067245582Sjkim            return (AE_TIME);
1068245582Sjkim        }
1069193267Sjkim
1070245582Sjkim        Time.tv_sec += (MsecTimeout / ACPI_MSEC_PER_SEC);
1071245582Sjkim        Time.tv_nsec += ((MsecTimeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC);
1072245582Sjkim
1073245582Sjkim        /* Handle nanosecond overflow (field must be less than one second) */
1074245582Sjkim
1075245582Sjkim        if (Time.tv_nsec >= ACPI_NSEC_PER_SEC)
1076193267Sjkim        {
1077245582Sjkim            Time.tv_sec += (Time.tv_nsec / ACPI_NSEC_PER_SEC);
1078245582Sjkim            Time.tv_nsec = (Time.tv_nsec % ACPI_NSEC_PER_SEC);
1079245582Sjkim        }
1080245582Sjkim
1081245582Sjkim        while (((RetVal = sem_timedwait (Sem, &Time)) == -1) && (errno == EINTR))
1082245582Sjkim        {
1083322877Sjkim            continue;   /* Restart if interrupted */
1084322877Sjkim
1085245582Sjkim        }
1086245582Sjkim
1087245582Sjkim        if (RetVal != 0)
1088245582Sjkim        {
1089245582Sjkim            if (errno != ETIMEDOUT)
1090245582Sjkim            {
1091245582Sjkim                perror ("sem_timedwait");
1092245582Sjkim            }
1093193267Sjkim            Status = (AE_TIME);
1094193267Sjkim        }
1095193267Sjkim#endif
1096193267Sjkim        break;
1097193267Sjkim    }
1098193267Sjkim
1099193267Sjkim    return (Status);
1100193267Sjkim}
1101193267Sjkim
1102193267Sjkim
1103193267Sjkim/******************************************************************************
1104193267Sjkim *
1105193267Sjkim * FUNCTION:    AcpiOsSignalSemaphore
1106193267Sjkim *
1107193267Sjkim * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
1108193267Sjkim *              Units               - Number of units to send
1109193267Sjkim *
1110193267Sjkim * RETURN:      Status
1111193267Sjkim *
1112193267Sjkim * DESCRIPTION: Send units
1113193267Sjkim *
1114193267Sjkim *****************************************************************************/
1115193267Sjkim
1116193267SjkimACPI_STATUS
1117193267SjkimAcpiOsSignalSemaphore (
1118193267Sjkim    ACPI_HANDLE         Handle,
1119193267Sjkim    UINT32              Units)
1120193267Sjkim{
1121193267Sjkim    sem_t               *Sem = (sem_t *)Handle;
1122193267Sjkim
1123193267Sjkim
1124193267Sjkim    if (!Sem)
1125193267Sjkim    {
1126193267Sjkim        return (AE_BAD_PARAMETER);
1127193267Sjkim    }
1128193267Sjkim
1129193267Sjkim    if (sem_post (Sem) == -1)
1130193267Sjkim    {
1131193267Sjkim        return (AE_LIMIT);
1132193267Sjkim    }
1133193267Sjkim
1134193267Sjkim    return (AE_OK);
1135193267Sjkim}
1136193267Sjkim
1137213800Sjkim#endif /* ACPI_SINGLE_THREADED */
1138193267Sjkim
1139213800Sjkim
1140193267Sjkim/******************************************************************************
1141193267Sjkim *
1142193267Sjkim * FUNCTION:    Spinlock interfaces
1143193267Sjkim *
1144193267Sjkim * DESCRIPTION: Map these interfaces to semaphore interfaces
1145193267Sjkim *
1146193267Sjkim *****************************************************************************/
1147193267Sjkim
1148193267SjkimACPI_STATUS
1149193267SjkimAcpiOsCreateLock (
1150193267Sjkim    ACPI_SPINLOCK           *OutHandle)
1151193267Sjkim{
1152193267Sjkim
1153193267Sjkim    return (AcpiOsCreateSemaphore (1, 1, OutHandle));
1154193267Sjkim}
1155193267Sjkim
1156193267Sjkim
1157193267Sjkimvoid
1158193267SjkimAcpiOsDeleteLock (
1159193267Sjkim    ACPI_SPINLOCK           Handle)
1160193267Sjkim{
1161193267Sjkim    AcpiOsDeleteSemaphore (Handle);
1162193267Sjkim}
1163193267Sjkim
1164193267Sjkim
1165193267SjkimACPI_CPU_FLAGS
1166193267SjkimAcpiOsAcquireLock (
1167193267Sjkim    ACPI_HANDLE             Handle)
1168193267Sjkim{
1169193267Sjkim    AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
1170193267Sjkim    return (0);
1171193267Sjkim}
1172193267Sjkim
1173193267Sjkim
1174193267Sjkimvoid
1175193267SjkimAcpiOsReleaseLock (
1176193267Sjkim    ACPI_SPINLOCK           Handle,
1177193267Sjkim    ACPI_CPU_FLAGS          Flags)
1178193267Sjkim{
1179193267Sjkim    AcpiOsSignalSemaphore (Handle, 1);
1180193267Sjkim}
1181193267Sjkim
1182193267Sjkim
1183193267Sjkim/******************************************************************************
1184193267Sjkim *
1185193267Sjkim * FUNCTION:    AcpiOsInstallInterruptHandler
1186193267Sjkim *
1187213800Sjkim * PARAMETERS:  InterruptNumber     - Level handler should respond to.
1188213800Sjkim *              Isr                 - Address of the ACPI interrupt handler
1189213800Sjkim *              ExceptPtr           - Where status is returned
1190193267Sjkim *
1191193267Sjkim * RETURN:      Handle to the newly installed handler.
1192193267Sjkim *
1193213800Sjkim * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
1194193267Sjkim *              OS-independent handler.
1195193267Sjkim *
1196193267Sjkim *****************************************************************************/
1197193267Sjkim
1198193267SjkimUINT32
1199193267SjkimAcpiOsInstallInterruptHandler (
1200193267Sjkim    UINT32                  InterruptNumber,
1201193267Sjkim    ACPI_OSD_HANDLER        ServiceRoutine,
1202193267Sjkim    void                    *Context)
1203193267Sjkim{
1204193267Sjkim
1205193267Sjkim    return (AE_OK);
1206193267Sjkim}
1207193267Sjkim
1208193267Sjkim
1209193267Sjkim/******************************************************************************
1210193267Sjkim *
1211193267Sjkim * FUNCTION:    AcpiOsRemoveInterruptHandler
1212193267Sjkim *
1213213800Sjkim * PARAMETERS:  Handle              - Returned when handler was installed
1214193267Sjkim *
1215193267Sjkim * RETURN:      Status
1216193267Sjkim *
1217193267Sjkim * DESCRIPTION: Uninstalls an interrupt handler.
1218193267Sjkim *
1219193267Sjkim *****************************************************************************/
1220193267Sjkim
1221193267SjkimACPI_STATUS
1222193267SjkimAcpiOsRemoveInterruptHandler (
1223193267Sjkim    UINT32                  InterruptNumber,
1224193267Sjkim    ACPI_OSD_HANDLER        ServiceRoutine)
1225193267Sjkim{
1226193267Sjkim
1227193267Sjkim    return (AE_OK);
1228193267Sjkim}
1229193267Sjkim
1230193267Sjkim
1231193267Sjkim/******************************************************************************
1232193267Sjkim *
1233193267Sjkim * FUNCTION:    AcpiOsStall
1234193267Sjkim *
1235213800Sjkim * PARAMETERS:  microseconds        - Time to sleep
1236193267Sjkim *
1237193267Sjkim * RETURN:      Blocks until sleep is completed.
1238193267Sjkim *
1239193267Sjkim * DESCRIPTION: Sleep at microsecond granularity
1240193267Sjkim *
1241193267Sjkim *****************************************************************************/
1242193267Sjkim
1243193267Sjkimvoid
1244193267SjkimAcpiOsStall (
1245193267Sjkim    UINT32                  microseconds)
1246193267Sjkim{
1247193267Sjkim
1248193267Sjkim    if (microseconds)
1249193267Sjkim    {
1250193267Sjkim        usleep (microseconds);
1251193267Sjkim    }
1252193267Sjkim}
1253193267Sjkim
1254193267Sjkim
1255193267Sjkim/******************************************************************************
1256193267Sjkim *
1257193267Sjkim * FUNCTION:    AcpiOsSleep
1258193267Sjkim *
1259213800Sjkim * PARAMETERS:  milliseconds        - Time to sleep
1260193267Sjkim *
1261193267Sjkim * RETURN:      Blocks until sleep is completed.
1262193267Sjkim *
1263193267Sjkim * DESCRIPTION: Sleep at millisecond granularity
1264193267Sjkim *
1265193267Sjkim *****************************************************************************/
1266193267Sjkim
1267193267Sjkimvoid
1268193267SjkimAcpiOsSleep (
1269202766Sjkim    UINT64                  milliseconds)
1270193267Sjkim{
1271193267Sjkim
1272245582Sjkim    /* Sleep for whole seconds */
1273193267Sjkim
1274245582Sjkim    sleep (milliseconds / ACPI_MSEC_PER_SEC);
1275245582Sjkim
1276193267Sjkim    /*
1277245582Sjkim     * Sleep for remaining microseconds.
1278245582Sjkim     * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second).
1279193267Sjkim     */
1280245582Sjkim    usleep ((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC);
1281193267Sjkim}
1282193267Sjkim
1283213800Sjkim
1284193267Sjkim/******************************************************************************
1285193267Sjkim *
1286193267Sjkim * FUNCTION:    AcpiOsGetTimer
1287193267Sjkim *
1288193267Sjkim * PARAMETERS:  None
1289193267Sjkim *
1290193267Sjkim * RETURN:      Current time in 100 nanosecond units
1291193267Sjkim *
1292193267Sjkim * DESCRIPTION: Get the current system time
1293193267Sjkim *
1294193267Sjkim *****************************************************************************/
1295193267Sjkim
1296193267SjkimUINT64
1297213800SjkimAcpiOsGetTimer (
1298213800Sjkim    void)
1299193267Sjkim{
1300193267Sjkim    struct timeval          time;
1301193267Sjkim
1302193267Sjkim
1303245582Sjkim    /* This timer has sufficient resolution for user-space application code */
1304245582Sjkim
1305193267Sjkim    gettimeofday (&time, NULL);
1306193267Sjkim
1307245582Sjkim    /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */
1308193267Sjkim
1309245582Sjkim    return (((UINT64) time.tv_sec * ACPI_100NSEC_PER_SEC) +
1310245582Sjkim            ((UINT64) time.tv_usec * ACPI_100NSEC_PER_USEC));
1311193267Sjkim}
1312193267Sjkim
1313193267Sjkim
1314193267Sjkim/******************************************************************************
1315193267Sjkim *
1316193267Sjkim * FUNCTION:    AcpiOsReadPciConfiguration
1317193267Sjkim *
1318213800Sjkim * PARAMETERS:  PciId               - Seg/Bus/Dev
1319272444Sjkim *              PciRegister         - Device Register
1320213800Sjkim *              Value               - Buffer where value is placed
1321213800Sjkim *              Width               - Number of bits
1322193267Sjkim *
1323193267Sjkim * RETURN:      Status
1324193267Sjkim *
1325193267Sjkim * DESCRIPTION: Read data from PCI configuration space
1326193267Sjkim *
1327193267Sjkim *****************************************************************************/
1328193267Sjkim
1329193267SjkimACPI_STATUS
1330193267SjkimAcpiOsReadPciConfiguration (
1331193267Sjkim    ACPI_PCI_ID             *PciId,
1332272444Sjkim    UINT32                  PciRegister,
1333210944Sjkim    UINT64                  *Value,
1334193267Sjkim    UINT32                  Width)
1335193267Sjkim{
1336193267Sjkim
1337254745Sjkim    *Value = 0;
1338193267Sjkim    return (AE_OK);
1339193267Sjkim}
1340193267Sjkim
1341193267Sjkim
1342193267Sjkim/******************************************************************************
1343193267Sjkim *
1344193267Sjkim * FUNCTION:    AcpiOsWritePciConfiguration
1345193267Sjkim *
1346213800Sjkim * PARAMETERS:  PciId               - Seg/Bus/Dev
1347272444Sjkim *              PciRegister         - Device Register
1348213800Sjkim *              Value               - Value to be written
1349213800Sjkim *              Width               - Number of bits
1350193267Sjkim *
1351193267Sjkim * RETURN:      Status.
1352193267Sjkim *
1353193267Sjkim * DESCRIPTION: Write data to PCI configuration space
1354193267Sjkim *
1355193267Sjkim *****************************************************************************/
1356193267Sjkim
1357193267SjkimACPI_STATUS
1358193267SjkimAcpiOsWritePciConfiguration (
1359193267Sjkim    ACPI_PCI_ID             *PciId,
1360272444Sjkim    UINT32                  PciRegister,
1361202766Sjkim    UINT64                  Value,
1362193267Sjkim    UINT32                  Width)
1363193267Sjkim{
1364193267Sjkim
1365193267Sjkim    return (AE_OK);
1366193267Sjkim}
1367193267Sjkim
1368193267Sjkim
1369193267Sjkim/******************************************************************************
1370193267Sjkim *
1371193267Sjkim * FUNCTION:    AcpiOsReadPort
1372193267Sjkim *
1373213800Sjkim * PARAMETERS:  Address             - Address of I/O port/register to read
1374213800Sjkim *              Value               - Where value is placed
1375213800Sjkim *              Width               - Number of bits
1376193267Sjkim *
1377193267Sjkim * RETURN:      Value read from port
1378193267Sjkim *
1379193267Sjkim * DESCRIPTION: Read data from an I/O port or register
1380193267Sjkim *
1381193267Sjkim *****************************************************************************/
1382193267Sjkim
1383193267SjkimACPI_STATUS
1384193267SjkimAcpiOsReadPort (
1385193267Sjkim    ACPI_IO_ADDRESS         Address,
1386193267Sjkim    UINT32                  *Value,
1387193267Sjkim    UINT32                  Width)
1388193267Sjkim{
1389193267Sjkim
1390193267Sjkim    switch (Width)
1391193267Sjkim    {
1392193267Sjkim    case 8:
1393250838Sjkim
1394193267Sjkim        *Value = 0xFF;
1395193267Sjkim        break;
1396193267Sjkim
1397193267Sjkim    case 16:
1398250838Sjkim
1399193267Sjkim        *Value = 0xFFFF;
1400193267Sjkim        break;
1401193267Sjkim
1402193267Sjkim    case 32:
1403250838Sjkim
1404193267Sjkim        *Value = 0xFFFFFFFF;
1405193267Sjkim        break;
1406193267Sjkim
1407193267Sjkim    default:
1408250838Sjkim
1409193267Sjkim        return (AE_BAD_PARAMETER);
1410193267Sjkim    }
1411193267Sjkim
1412193267Sjkim    return (AE_OK);
1413193267Sjkim}
1414193267Sjkim
1415193267Sjkim
1416193267Sjkim/******************************************************************************
1417193267Sjkim *
1418193267Sjkim * FUNCTION:    AcpiOsWritePort
1419193267Sjkim *
1420213800Sjkim * PARAMETERS:  Address             - Address of I/O port/register to write
1421213800Sjkim *              Value               - Value to write
1422213800Sjkim *              Width               - Number of bits
1423193267Sjkim *
1424193267Sjkim * RETURN:      None
1425193267Sjkim *
1426193267Sjkim * DESCRIPTION: Write data to an I/O port or register
1427193267Sjkim *
1428193267Sjkim *****************************************************************************/
1429193267Sjkim
1430193267SjkimACPI_STATUS
1431193267SjkimAcpiOsWritePort (
1432193267Sjkim    ACPI_IO_ADDRESS         Address,
1433193267Sjkim    UINT32                  Value,
1434193267Sjkim    UINT32                  Width)
1435193267Sjkim{
1436193267Sjkim
1437193267Sjkim    return (AE_OK);
1438193267Sjkim}
1439193267Sjkim
1440193267Sjkim
1441193267Sjkim/******************************************************************************
1442193267Sjkim *
1443193267Sjkim * FUNCTION:    AcpiOsReadMemory
1444193267Sjkim *
1445213800Sjkim * PARAMETERS:  Address             - Physical Memory Address to read
1446213800Sjkim *              Value               - Where value is placed
1447231844Sjkim *              Width               - Number of bits (8,16,32, or 64)
1448193267Sjkim *
1449231844Sjkim * RETURN:      Value read from physical memory address. Always returned
1450231844Sjkim *              as a 64-bit integer, regardless of the read width.
1451193267Sjkim *
1452193267Sjkim * DESCRIPTION: Read data from a physical memory address
1453193267Sjkim *
1454193267Sjkim *****************************************************************************/
1455193267Sjkim
1456193267SjkimACPI_STATUS
1457193267SjkimAcpiOsReadMemory (
1458193267Sjkim    ACPI_PHYSICAL_ADDRESS   Address,
1459231844Sjkim    UINT64                  *Value,
1460193267Sjkim    UINT32                  Width)
1461193267Sjkim{
1462193267Sjkim
1463193267Sjkim    switch (Width)
1464193267Sjkim    {
1465193267Sjkim    case 8:
1466193267Sjkim    case 16:
1467193267Sjkim    case 32:
1468231844Sjkim    case 64:
1469250838Sjkim
1470193267Sjkim        *Value = 0;
1471193267Sjkim        break;
1472193267Sjkim
1473193267Sjkim    default:
1474250838Sjkim
1475193267Sjkim        return (AE_BAD_PARAMETER);
1476193267Sjkim    }
1477193267Sjkim    return (AE_OK);
1478193267Sjkim}
1479193267Sjkim
1480193267Sjkim
1481193267Sjkim/******************************************************************************
1482193267Sjkim *
1483193267Sjkim * FUNCTION:    AcpiOsWriteMemory
1484193267Sjkim *
1485213800Sjkim * PARAMETERS:  Address             - Physical Memory Address to write
1486213800Sjkim *              Value               - Value to write
1487231844Sjkim *              Width               - Number of bits (8,16,32, or 64)
1488193267Sjkim *
1489193267Sjkim * RETURN:      None
1490193267Sjkim *
1491193267Sjkim * DESCRIPTION: Write data to a physical memory address
1492193267Sjkim *
1493193267Sjkim *****************************************************************************/
1494193267Sjkim
1495193267SjkimACPI_STATUS
1496193267SjkimAcpiOsWriteMemory (
1497193267Sjkim    ACPI_PHYSICAL_ADDRESS   Address,
1498231844Sjkim    UINT64                  Value,
1499193267Sjkim    UINT32                  Width)
1500193267Sjkim{
1501193267Sjkim
1502193267Sjkim    return (AE_OK);
1503193267Sjkim}
1504193267Sjkim
1505193267Sjkim
1506193267Sjkim/******************************************************************************
1507193267Sjkim *
1508193267Sjkim * FUNCTION:    AcpiOsReadable
1509193267Sjkim *
1510193267Sjkim * PARAMETERS:  Pointer             - Area to be verified
1511193267Sjkim *              Length              - Size of area
1512193267Sjkim *
1513193267Sjkim * RETURN:      TRUE if readable for entire length
1514193267Sjkim *
1515193267Sjkim * DESCRIPTION: Verify that a pointer is valid for reading
1516193267Sjkim *
1517193267Sjkim *****************************************************************************/
1518193267Sjkim
1519193267SjkimBOOLEAN
1520193267SjkimAcpiOsReadable (
1521193267Sjkim    void                    *Pointer,
1522193267Sjkim    ACPI_SIZE               Length)
1523193267Sjkim{
1524193267Sjkim
1525193267Sjkim    return (TRUE);
1526193267Sjkim}
1527193267Sjkim
1528193267Sjkim
1529193267Sjkim/******************************************************************************
1530193267Sjkim *
1531193267Sjkim * FUNCTION:    AcpiOsWritable
1532193267Sjkim *
1533193267Sjkim * PARAMETERS:  Pointer             - Area to be verified
1534193267Sjkim *              Length              - Size of area
1535193267Sjkim *
1536193267Sjkim * RETURN:      TRUE if writable for entire length
1537193267Sjkim *
1538193267Sjkim * DESCRIPTION: Verify that a pointer is valid for writing
1539193267Sjkim *
1540193267Sjkim *****************************************************************************/
1541193267Sjkim
1542193267SjkimBOOLEAN
1543193267SjkimAcpiOsWritable (
1544193267Sjkim    void                    *Pointer,
1545193267Sjkim    ACPI_SIZE               Length)
1546193267Sjkim{
1547193267Sjkim
1548193267Sjkim    return (TRUE);
1549193267Sjkim}
1550193267Sjkim
1551193267Sjkim
1552193267Sjkim/******************************************************************************
1553193267Sjkim *
1554223480Sjkim * FUNCTION:    AcpiOsSignal
1555223480Sjkim *
1556272444Sjkim * PARAMETERS:  Function            - ACPI A signal function code
1557223480Sjkim *              Info                - Pointer to function-dependent structure
1558223480Sjkim *
1559223480Sjkim * RETURN:      Status
1560223480Sjkim *
1561223480Sjkim * DESCRIPTION: Miscellaneous functions. Example implementation only.
1562223480Sjkim *
1563223480Sjkim *****************************************************************************/
1564223480Sjkim
1565223480SjkimACPI_STATUS
1566223480SjkimAcpiOsSignal (
1567223480Sjkim    UINT32                  Function,
1568223480Sjkim    void                    *Info)
1569223480Sjkim{
1570223480Sjkim
1571223480Sjkim    switch (Function)
1572223480Sjkim    {
1573223480Sjkim    case ACPI_SIGNAL_FATAL:
1574250838Sjkim
1575223480Sjkim        break;
1576223480Sjkim
1577223480Sjkim    case ACPI_SIGNAL_BREAKPOINT:
1578250838Sjkim
1579223480Sjkim        break;
1580223480Sjkim
1581223480Sjkim    default:
1582250838Sjkim
1583223480Sjkim        break;
1584223480Sjkim    }
1585223480Sjkim
1586223480Sjkim    return (AE_OK);
1587223480Sjkim}
1588223480Sjkim
1589223480Sjkim/* Optional multi-thread support */
1590223480Sjkim
1591223480Sjkim#ifndef ACPI_SINGLE_THREADED
1592223480Sjkim/******************************************************************************
1593223480Sjkim *
1594193267Sjkim * FUNCTION:    AcpiOsGetThreadId
1595193267Sjkim *
1596193267Sjkim * PARAMETERS:  None
1597193267Sjkim *
1598193267Sjkim * RETURN:      Id of the running thread
1599193267Sjkim *
1600213800Sjkim * DESCRIPTION: Get the ID of the current (running) thread
1601193267Sjkim *
1602193267Sjkim *****************************************************************************/
1603193267Sjkim
1604193267SjkimACPI_THREAD_ID
1605212700SjkimAcpiOsGetThreadId (
1606212700Sjkim    void)
1607193267Sjkim{
1608227896Sjkim    pthread_t               thread;
1609193267Sjkim
1610227896Sjkim
1611227896Sjkim    thread = pthread_self();
1612227896Sjkim    return (ACPI_CAST_PTHREAD_T (thread));
1613193267Sjkim}
1614193267Sjkim
1615193267Sjkim
1616193267Sjkim/******************************************************************************
1617193267Sjkim *
1618223480Sjkim * FUNCTION:    AcpiOsExecute
1619193267Sjkim *
1620223480Sjkim * PARAMETERS:  Type                - Type of execution
1621223480Sjkim *              Function            - Address of the function to execute
1622223480Sjkim *              Context             - Passed as a parameter to the function
1623193267Sjkim *
1624223480Sjkim * RETURN:      Status.
1625193267Sjkim *
1626223480Sjkim * DESCRIPTION: Execute a new thread
1627193267Sjkim *
1628193267Sjkim *****************************************************************************/
1629193267Sjkim
1630193267SjkimACPI_STATUS
1631223480SjkimAcpiOsExecute (
1632223480Sjkim    ACPI_EXECUTE_TYPE       Type,
1633223480Sjkim    ACPI_OSD_EXEC_CALLBACK  Function,
1634223480Sjkim    void                    *Context)
1635193267Sjkim{
1636223480Sjkim    pthread_t               thread;
1637223480Sjkim    int                     ret;
1638193267Sjkim
1639223480Sjkim
1640223480Sjkim    ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context);
1641223480Sjkim    if (ret)
1642193267Sjkim    {
1643223480Sjkim        AcpiOsPrintf("Create thread failed");
1644193267Sjkim    }
1645223480Sjkim    return (0);
1646223480Sjkim}
1647193267Sjkim
1648272444Sjkim#else /* ACPI_SINGLE_THREADED */
1649272444SjkimACPI_THREAD_ID
1650272444SjkimAcpiOsGetThreadId (
1651272444Sjkim    void)
1652272444Sjkim{
1653272444Sjkim    return (1);
1654272444Sjkim}
1655272444Sjkim
1656272444SjkimACPI_STATUS
1657272444SjkimAcpiOsExecute (
1658272444Sjkim    ACPI_EXECUTE_TYPE       Type,
1659272444Sjkim    ACPI_OSD_EXEC_CALLBACK  Function,
1660272444Sjkim    void                    *Context)
1661272444Sjkim{
1662272444Sjkim
1663272444Sjkim    Function (Context);
1664272444Sjkim
1665272444Sjkim    return (AE_OK);
1666272444Sjkim}
1667272444Sjkim
1668223480Sjkim#endif /* ACPI_SINGLE_THREADED */
1669235945Sjkim
1670235945Sjkim
1671235945Sjkim/******************************************************************************
1672235945Sjkim *
1673235945Sjkim * FUNCTION:    AcpiOsWaitEventsComplete
1674235945Sjkim *
1675235945Sjkim * PARAMETERS:  None
1676235945Sjkim *
1677235945Sjkim * RETURN:      None
1678235945Sjkim *
1679235945Sjkim * DESCRIPTION: Wait for all asynchronous events to complete. This
1680235945Sjkim *              implementation does nothing.
1681235945Sjkim *
1682235945Sjkim *****************************************************************************/
1683235945Sjkim
1684235945Sjkimvoid
1685235945SjkimAcpiOsWaitEventsComplete (
1686235945Sjkim    void)
1687235945Sjkim{
1688235945Sjkim    return;
1689235945Sjkim}
1690