1 /******************************************************************************
2  *
3  * Module Name: oswinxf - Windows OSL
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2021, 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 #include "acpi.h"
153 #include "accommon.h"
154 
155 #ifdef WIN32
156 #pragma warning(disable:4115)   /* warning C4115: named type definition in parentheses (caused by rpcasync.h> */
157 
158 #include <windows.h>
159 #include <winbase.h>
160 
161 #elif WIN64
162 #include <windowsx.h>
163 #endif
164 
165 #include <stdio.h>
166 #include <stdlib.h>
167 #include <stdarg.h>
168 #include <process.h>
169 #include <time.h>
170 
171 #define _COMPONENT          ACPI_OS_SERVICES
172         ACPI_MODULE_NAME    ("oswinxf")
173 
174 
175 UINT64                      TimerFrequency;
176 char                        TableName[ACPI_NAMESEG_SIZE + 1];
177 
178 #define ACPI_OS_DEBUG_TIMEOUT   30000 /* 30 seconds */
179 
180 
181 /* Upcalls to AcpiExec application */
182 
183 void
184 AeTableOverride (
185     ACPI_TABLE_HEADER       *ExistingTable,
186     ACPI_TABLE_HEADER       **NewTable);
187 
188 /*
189  * Real semaphores are only used for a multi-threaded application
190  */
191 #ifndef ACPI_SINGLE_THREADED
192 
193 /* Semaphore information structure */
194 
195 typedef struct acpi_os_semaphore_info
196 {
197     UINT16                  MaxUnits;
198     UINT16                  CurrentUnits;
199     void                    *OsHandle;
200 
201 } ACPI_OS_SEMAPHORE_INFO;
202 
203 /* Need enough semaphores to run the large aslts suite */
204 
205 #define ACPI_OS_MAX_SEMAPHORES  256
206 
207 ACPI_OS_SEMAPHORE_INFO          AcpiGbl_Semaphores[ACPI_OS_MAX_SEMAPHORES];
208 
209 #endif /* ACPI_SINGLE_THREADED */
210 
211 /******************************************************************************
212  *
213  * FUNCTION:    AcpiOsTerminate
214  *
215  * PARAMETERS:  None
216  *
217  * RETURN:      Status
218  *
219  * DESCRIPTION: Nothing to do for windows
220  *
221  *****************************************************************************/
222 
223 ACPI_STATUS
224 AcpiOsTerminate (
225     void)
226 {
227     return (AE_OK);
228 }
229 
230 
231 /******************************************************************************
232  *
233  * FUNCTION:    AcpiOsInitialize
234  *
235  * PARAMETERS:  None
236  *
237  * RETURN:      Status
238  *
239  * DESCRIPTION: Init this OSL
240  *
241  *****************************************************************************/
242 
243 ACPI_STATUS
244 AcpiOsInitialize (
245     void)
246 {
247     ACPI_STATUS             Status;
248     LARGE_INTEGER           LocalTimerFrequency;
249 
250 
251 #ifndef ACPI_SINGLE_THREADED
252     /* Clear the semaphore info array */
253 
254     memset (AcpiGbl_Semaphores, 0x00, sizeof (AcpiGbl_Semaphores));
255 #endif
256 
257     AcpiGbl_OutputFile = stdout;
258 
259     /* Get the timer frequency for use in AcpiOsGetTimer */
260 
261     TimerFrequency = 0;
262     if (QueryPerformanceFrequency (&LocalTimerFrequency))
263     {
264         /* Frequency is in ticks per second */
265 
266         TimerFrequency = LocalTimerFrequency.QuadPart;
267     }
268 
269     Status = AcpiOsCreateLock (&AcpiGbl_PrintLock);
270     if (ACPI_FAILURE (Status))
271     {
272         return (Status);
273     }
274 
275     return (AE_OK);
276 }
277 
278 
279 #ifndef ACPI_USE_NATIVE_RSDP_POINTER
280 /******************************************************************************
281  *
282  * FUNCTION:    AcpiOsGetRootPointer
283  *
284  * PARAMETERS:  None
285  *
286  * RETURN:      RSDP physical address
287  *
288  * DESCRIPTION: Gets the root pointer (RSDP)
289  *
290  *****************************************************************************/
291 
292 ACPI_PHYSICAL_ADDRESS
293 AcpiOsGetRootPointer (
294     void)
295 {
296 
297     return (0);
298 }
299 #endif
300 
301 
302 /******************************************************************************
303  *
304  * FUNCTION:    AcpiOsPredefinedOverride
305  *
306  * PARAMETERS:  InitVal             - Initial value of the predefined object
307  *              NewVal              - The new value for the object
308  *
309  * RETURN:      Status, pointer to value. Null pointer returned if not
310  *              overriding.
311  *
312  * DESCRIPTION: Allow the OS to override predefined names
313  *
314  *****************************************************************************/
315 
316 ACPI_STATUS
317 AcpiOsPredefinedOverride (
318     const ACPI_PREDEFINED_NAMES *InitVal,
319     ACPI_STRING                 *NewVal)
320 {
321 
322     if (!InitVal || !NewVal)
323     {
324         return (AE_BAD_PARAMETER);
325     }
326 
327     *NewVal = NULL;
328     return (AE_OK);
329 }
330 
331 
332 /******************************************************************************
333  *
334  * FUNCTION:    AcpiOsTableOverride
335  *
336  * PARAMETERS:  ExistingTable       - Header of current table (probably firmware)
337  *              NewTable            - Where an entire new table is returned.
338  *
339  * RETURN:      Status, pointer to new table. Null pointer returned if no
340  *              table is available to override
341  *
342  * DESCRIPTION: Return a different version of a table if one is available
343  *
344  *****************************************************************************/
345 
346 ACPI_STATUS
347 AcpiOsTableOverride (
348     ACPI_TABLE_HEADER       *ExistingTable,
349     ACPI_TABLE_HEADER       **NewTable)
350 {
351 
352     if (!ExistingTable || !NewTable)
353     {
354         return (AE_BAD_PARAMETER);
355     }
356 
357     *NewTable = NULL;
358 
359 
360 #ifdef ACPI_EXEC_APP
361 
362     /* Call back up to AcpiExec */
363 
364     AeTableOverride (ExistingTable, NewTable);
365 #endif
366 
367     return (AE_OK);
368 }
369 
370 
371 /******************************************************************************
372  *
373  * FUNCTION:    AcpiOsPhysicalTableOverride
374  *
375  * PARAMETERS:  ExistingTable       - Header of current table (probably firmware)
376  *              NewAddress          - Where new table address is returned
377  *                                    (Physical address)
378  *              NewTableLength      - Where new table length is returned
379  *
380  * RETURN:      Status, address/length of new table. Null pointer returned
381  *              if no table is available to override.
382  *
383  * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
384  *
385  *****************************************************************************/
386 
387 ACPI_STATUS
388 AcpiOsPhysicalTableOverride (
389     ACPI_TABLE_HEADER       *ExistingTable,
390     ACPI_PHYSICAL_ADDRESS   *NewAddress,
391     UINT32                  *NewTableLength)
392 {
393 
394     return (AE_SUPPORT);
395 }
396 
397 
398 /******************************************************************************
399  *
400  * FUNCTION:    AcpiOsEnterSleep
401  *
402  * PARAMETERS:  SleepState          - Which sleep state to enter
403  *              RegaValue           - Register A value
404  *              RegbValue           - Register B value
405  *
406  * RETURN:      Status
407  *
408  * DESCRIPTION: A hook before writing sleep registers to enter the sleep
409  *              state. Return AE_CTRL_SKIP to skip further sleep register
410  *              writes.
411  *
412  *****************************************************************************/
413 
414 ACPI_STATUS
415 AcpiOsEnterSleep (
416     UINT8                   SleepState,
417     UINT32                  RegaValue,
418     UINT32                  RegbValue)
419 {
420 
421     return (AE_OK);
422 }
423 
424 
425 /******************************************************************************
426  *
427  * FUNCTION:    AcpiOsGetTimer
428  *
429  * PARAMETERS:  None
430  *
431  * RETURN:      Current ticks in 100-nanosecond units
432  *
433  * DESCRIPTION: Get the value of a system timer
434  *
435  ******************************************************************************/
436 
437 UINT64
438 AcpiOsGetTimer (
439     void)
440 {
441     LARGE_INTEGER           Timer;
442 
443 
444     /* Attempt to use hi-granularity timer first */
445 
446     if (TimerFrequency &&
447         QueryPerformanceCounter (&Timer))
448     {
449         /* Convert to 100 nanosecond ticks */
450 
451         return ((UINT64) ((Timer.QuadPart * (UINT64) ACPI_100NSEC_PER_SEC) /
452             TimerFrequency));
453     }
454 
455     /* Fall back to the lo-granularity timer */
456 
457     else
458     {
459         /* Convert milliseconds to 100 nanosecond ticks */
460 
461         return (GetTickCount64() * ACPI_100NSEC_PER_MSEC);
462     }
463 }
464 
465 
466 /******************************************************************************
467  *
468  * FUNCTION:    AcpiOsReadable
469  *
470  * PARAMETERS:  Pointer             - Area to be verified
471  *              Length              - Size of area
472  *
473  * RETURN:      TRUE if readable for entire length
474  *
475  * DESCRIPTION: Verify that a pointer is valid for reading
476  *
477  *****************************************************************************/
478 
479 BOOLEAN
480 AcpiOsReadable (
481     void                    *Pointer,
482     ACPI_SIZE               Length)
483 {
484 
485     return ((BOOLEAN) !IsBadReadPtr (Pointer, Length));
486 }
487 
488 
489 /******************************************************************************
490  *
491  * FUNCTION:    AcpiOsWritable
492  *
493  * PARAMETERS:  Pointer             - Area to be verified
494  *              Length              - Size of area
495  *
496  * RETURN:      TRUE if writable for entire length
497  *
498  * DESCRIPTION: Verify that a pointer is valid for writing
499  *
500  *****************************************************************************/
501 
502 BOOLEAN
503 AcpiOsWritable (
504     void                    *Pointer,
505     ACPI_SIZE               Length)
506 {
507 
508     return ((BOOLEAN) !IsBadWritePtr (Pointer, Length));
509 }
510 
511 
512 /******************************************************************************
513  *
514  * FUNCTION:    AcpiOsRedirectOutput
515  *
516  * PARAMETERS:  Destination         - An open file handle/pointer
517  *
518  * RETURN:      None
519  *
520  * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
521  *
522  *****************************************************************************/
523 
524 void
525 AcpiOsRedirectOutput (
526     void                    *Destination)
527 {
528 
529     AcpiGbl_OutputFile = Destination;
530 }
531 
532 
533 /******************************************************************************
534  *
535  * FUNCTION:    AcpiOsPrintf
536  *
537  * PARAMETERS:  Fmt, ...            - Standard printf format
538  *
539  * RETURN:      None
540  *
541  * DESCRIPTION: Formatted output
542  *
543  *****************************************************************************/
544 
545 void ACPI_INTERNAL_VAR_XFACE
546 AcpiOsPrintf (
547     const char              *Fmt,
548     ...)
549 {
550     va_list                 Args;
551     UINT8                   Flags;
552 
553 
554     Flags = AcpiGbl_DbOutputFlags;
555     if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
556     {
557         /* Output is directable to either a file (if open) or the console */
558 
559         if (AcpiGbl_DebugFile)
560         {
561             /* Output file is open, send the output there */
562 
563             va_start (Args, Fmt);
564             vfprintf (AcpiGbl_DebugFile, Fmt, Args);
565             va_end (Args);
566         }
567         else
568         {
569             /* No redirection, send output to console (once only!) */
570 
571             Flags |= ACPI_DB_CONSOLE_OUTPUT;
572         }
573     }
574 
575     if (Flags & ACPI_DB_CONSOLE_OUTPUT)
576     {
577         va_start (Args, Fmt);
578         vfprintf (AcpiGbl_OutputFile, Fmt, Args);
579         va_end (Args);
580     }
581 
582     return;
583 }
584 
585 
586 /******************************************************************************
587  *
588  * FUNCTION:    AcpiOsVprintf
589  *
590  * PARAMETERS:  Fmt                 - Standard printf format
591  *              Args                - Argument list
592  *
593  * RETURN:      None
594  *
595  * DESCRIPTION: Formatted output with argument list pointer
596  *
597  *****************************************************************************/
598 
599 void
600 AcpiOsVprintf (
601     const char              *Fmt,
602     va_list                 Args)
603 {
604     INT32                   Count = 0;
605     UINT8                   Flags;
606 
607 
608     Flags = AcpiGbl_DbOutputFlags;
609     if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
610     {
611         /* Output is directable to either a file (if open) or the console */
612 
613         if (AcpiGbl_DebugFile)
614         {
615             /* Output file is open, send the output there */
616 
617             Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
618         }
619         else
620         {
621             /* No redirection, send output to console (once only!) */
622 
623             Flags |= ACPI_DB_CONSOLE_OUTPUT;
624         }
625     }
626 
627     if (Flags & ACPI_DB_CONSOLE_OUTPUT)
628     {
629         Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
630     }
631 
632     return;
633 }
634 
635 
636 /******************************************************************************
637  *
638  * FUNCTION:    AcpiOsGetLine
639  *
640  * PARAMETERS:  Buffer              - Where to return the command line
641  *              BufferLength        - Maximum length of Buffer
642  *              BytesRead           - Where the actual byte count is returned
643  *
644  * RETURN:      Status and actual bytes read
645  *
646  * DESCRIPTION: Formatted input with argument list pointer
647  *
648  *****************************************************************************/
649 
650 ACPI_STATUS
651 AcpiOsGetLine (
652     char                    *Buffer,
653     UINT32                  BufferLength,
654     UINT32                  *BytesRead)
655 {
656     int                     Temp;
657     UINT32                  i;
658 
659 
660     for (i = 0; ; i++)
661     {
662         if (i >= BufferLength)
663         {
664             return (AE_BUFFER_OVERFLOW);
665         }
666 
667         if ((Temp = getchar ()) == EOF)
668         {
669             return (AE_ERROR);
670         }
671 
672         if (!Temp || Temp == '\n')
673         {
674             break;
675         }
676 
677         Buffer [i] = (char) Temp;
678     }
679 
680     /* Null terminate the buffer */
681 
682     Buffer [i] = 0;
683 
684     /* Return the number of bytes in the string */
685 
686     if (BytesRead)
687     {
688         *BytesRead = i;
689     }
690 
691     return (AE_OK);
692 }
693 
694 
695 #ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
696 /******************************************************************************
697  *
698  * FUNCTION:    AcpiOsMapMemory
699  *
700  * PARAMETERS:  Where               - Physical address of memory to be mapped
701  *              Length              - How much memory to map
702  *
703  * RETURN:      Pointer to mapped memory. Null on error.
704  *
705  * DESCRIPTION: Map physical memory into caller's address space
706  *
707  *****************************************************************************/
708 
709 void *
710 AcpiOsMapMemory (
711     ACPI_PHYSICAL_ADDRESS   Where,
712     ACPI_SIZE               Length)
713 {
714 
715     return (ACPI_TO_POINTER ((ACPI_SIZE) Where));
716 }
717 
718 
719 /******************************************************************************
720  *
721  * FUNCTION:    AcpiOsUnmapMemory
722  *
723  * PARAMETERS:  Where               - Logical address of memory to be unmapped
724  *              Length              - How much memory to unmap
725  *
726  * RETURN:      None.
727  *
728  * DESCRIPTION: Delete a previously created mapping. Where and Length must
729  *              correspond to a previous mapping exactly.
730  *
731  *****************************************************************************/
732 
733 void
734 AcpiOsUnmapMemory (
735     void                    *Where,
736     ACPI_SIZE               Length)
737 {
738 
739     return;
740 }
741 #endif
742 
743 
744 /******************************************************************************
745  *
746  * FUNCTION:    AcpiOsAllocate
747  *
748  * PARAMETERS:  Size                - Amount to allocate, in bytes
749  *
750  * RETURN:      Pointer to the new allocation. Null on error.
751  *
752  * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
753  *
754  *****************************************************************************/
755 
756 void *
757 AcpiOsAllocate (
758     ACPI_SIZE               Size)
759 {
760     void                    *Mem;
761 
762 
763     Mem = (void *) malloc ((size_t) Size);
764     return (Mem);
765 }
766 
767 
768 #ifdef USE_NATIVE_ALLOCATE_ZEROED
769 /******************************************************************************
770  *
771  * FUNCTION:    AcpiOsAllocateZeroed
772  *
773  * PARAMETERS:  Size                - Amount to allocate, in bytes
774  *
775  * RETURN:      Pointer to the new allocation. Null on error.
776  *
777  * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
778  *
779  *****************************************************************************/
780 
781 void *
782 AcpiOsAllocateZeroed (
783     ACPI_SIZE               Size)
784 {
785     void                    *Mem;
786 
787 
788     Mem = (void *) calloc (1, (size_t) Size);
789     return (Mem);
790 }
791 #endif
792 
793 
794 /******************************************************************************
795  *
796  * FUNCTION:    AcpiOsFree
797  *
798  * PARAMETERS:  Mem                 - Pointer to previously allocated memory
799  *
800  * RETURN:      None.
801  *
802  * DESCRIPTION: Free memory allocated via AcpiOsAllocate
803  *
804  *****************************************************************************/
805 
806 void
807 AcpiOsFree (
808     void                    *Mem)
809 {
810 
811     free (Mem);
812 }
813 
814 
815 #ifdef ACPI_SINGLE_THREADED
816 /******************************************************************************
817  *
818  * FUNCTION:    Semaphore stub functions
819  *
820  * DESCRIPTION: Stub functions used for single-thread applications that do
821  *              not require semaphore synchronization. Full implementations
822  *              of these functions appear after the stubs.
823  *
824  *****************************************************************************/
825 
826 ACPI_STATUS
827 AcpiOsCreateSemaphore (
828     UINT32              MaxUnits,
829     UINT32              InitialUnits,
830     ACPI_HANDLE         *OutHandle)
831 {
832     *OutHandle = (ACPI_HANDLE) 1;
833     return (AE_OK);
834 }
835 
836 ACPI_STATUS
837 AcpiOsDeleteSemaphore (
838     ACPI_HANDLE         Handle)
839 {
840     return (AE_OK);
841 }
842 
843 ACPI_STATUS
844 AcpiOsWaitSemaphore (
845     ACPI_HANDLE         Handle,
846     UINT32              Units,
847     UINT16              Timeout)
848 {
849     return (AE_OK);
850 }
851 
852 ACPI_STATUS
853 AcpiOsSignalSemaphore (
854     ACPI_HANDLE         Handle,
855     UINT32              Units)
856 {
857     return (AE_OK);
858 }
859 
860 #else
861 /******************************************************************************
862  *
863  * FUNCTION:    AcpiOsCreateSemaphore
864  *
865  * PARAMETERS:  MaxUnits            - Maximum units that can be sent
866  *              InitialUnits        - Units to be assigned to the new semaphore
867  *              OutHandle           - Where a handle will be returned
868  *
869  * RETURN:      Status
870  *
871  * DESCRIPTION: Create an OS semaphore
872  *
873  *****************************************************************************/
874 
875 ACPI_STATUS
876 AcpiOsCreateSemaphore (
877     UINT32              MaxUnits,
878     UINT32              InitialUnits,
879     ACPI_SEMAPHORE      *OutHandle)
880 {
881     void                *Mutex;
882     UINT32              i;
883 
884     ACPI_FUNCTION_NAME (OsCreateSemaphore);
885 
886 
887     if (MaxUnits == ACPI_UINT32_MAX)
888     {
889         MaxUnits = 255;
890     }
891 
892     if (InitialUnits == ACPI_UINT32_MAX)
893     {
894         InitialUnits = MaxUnits;
895     }
896 
897     if (InitialUnits > MaxUnits)
898     {
899         return (AE_BAD_PARAMETER);
900     }
901 
902     /* Find an empty slot */
903 
904     for (i = 0; i < ACPI_OS_MAX_SEMAPHORES; i++)
905     {
906         if (!AcpiGbl_Semaphores[i].OsHandle)
907         {
908             break;
909         }
910     }
911     if (i >= ACPI_OS_MAX_SEMAPHORES)
912     {
913         ACPI_EXCEPTION ((AE_INFO, AE_LIMIT,
914             "Reached max semaphores (%u), could not create",
915             ACPI_OS_MAX_SEMAPHORES));
916         return (AE_LIMIT);
917     }
918 
919     /* Create an OS semaphore */
920 
921     Mutex = CreateSemaphore (NULL, InitialUnits, MaxUnits, NULL);
922     if (!Mutex)
923     {
924         ACPI_ERROR ((AE_INFO, "Could not create semaphore"));
925         return (AE_NO_MEMORY);
926     }
927 
928     AcpiGbl_Semaphores[i].MaxUnits = (UINT16) MaxUnits;
929     AcpiGbl_Semaphores[i].CurrentUnits = (UINT16) InitialUnits;
930     AcpiGbl_Semaphores[i].OsHandle = Mutex;
931 
932     ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
933         "Handle=%u, Max=%u, Current=%u, OsHandle=%p\n",
934         i, MaxUnits, InitialUnits, Mutex));
935 
936     *OutHandle = (void *) i;
937     return (AE_OK);
938 }
939 
940 
941 /******************************************************************************
942  *
943  * FUNCTION:    AcpiOsDeleteSemaphore
944  *
945  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
946  *
947  * RETURN:      Status
948  *
949  * DESCRIPTION: Delete an OS semaphore
950  *
951  *****************************************************************************/
952 
953 ACPI_STATUS
954 AcpiOsDeleteSemaphore (
955     ACPI_SEMAPHORE      Handle)
956 {
957     UINT32              Index = (UINT32) Handle;
958 
959 
960     if ((Index >= ACPI_OS_MAX_SEMAPHORES) ||
961         !AcpiGbl_Semaphores[Index].OsHandle)
962     {
963         return (AE_BAD_PARAMETER);
964     }
965 
966     CloseHandle (AcpiGbl_Semaphores[Index].OsHandle);
967     AcpiGbl_Semaphores[Index].OsHandle = NULL;
968     return (AE_OK);
969 }
970 
971 
972 /******************************************************************************
973  *
974  * FUNCTION:    AcpiOsWaitSemaphore
975  *
976  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
977  *              Units               - How many units to wait for
978  *              Timeout             - How long to wait
979  *
980  * RETURN:      Status
981  *
982  * DESCRIPTION: Wait for units
983  *
984  *****************************************************************************/
985 
986 ACPI_STATUS
987 AcpiOsWaitSemaphore (
988     ACPI_SEMAPHORE      Handle,
989     UINT32              Units,
990     UINT16              Timeout)
991 {
992     UINT32              Index = (UINT32) Handle;
993     UINT32              WaitStatus;
994     UINT32              OsTimeout = Timeout;
995 
996 
997     ACPI_FUNCTION_ENTRY ();
998 
999 
1000     if ((Index >= ACPI_OS_MAX_SEMAPHORES) ||
1001         !AcpiGbl_Semaphores[Index].OsHandle)
1002     {
1003         return (AE_BAD_PARAMETER);
1004     }
1005 
1006     if (Units > 1)
1007     {
1008         printf ("WaitSemaphore: Attempt to receive %u units\n", Units);
1009         return (AE_NOT_IMPLEMENTED);
1010     }
1011 
1012     if (Timeout == ACPI_WAIT_FOREVER)
1013     {
1014         OsTimeout = INFINITE;
1015         if (AcpiGbl_DebugTimeout)
1016         {
1017             /* The debug timeout will prevent hang conditions */
1018 
1019             OsTimeout = ACPI_OS_DEBUG_TIMEOUT;
1020         }
1021     }
1022     else
1023     {
1024         /* Add 10ms to account for clock tick granularity */
1025 
1026         OsTimeout += 10;
1027     }
1028 
1029     WaitStatus = WaitForSingleObject (
1030         AcpiGbl_Semaphores[Index].OsHandle, OsTimeout);
1031     if (WaitStatus == WAIT_TIMEOUT)
1032     {
1033         if (AcpiGbl_DebugTimeout)
1034         {
1035             ACPI_EXCEPTION ((AE_INFO, AE_TIME,
1036                 "Debug timeout on semaphore 0x%04X (%ums)\n",
1037                 Index, ACPI_OS_DEBUG_TIMEOUT));
1038         }
1039 
1040         return (AE_TIME);
1041     }
1042 
1043     if (AcpiGbl_Semaphores[Index].CurrentUnits == 0)
1044     {
1045         ACPI_ERROR ((AE_INFO,
1046             "%s - No unit received. Timeout 0x%X, OS_Status 0x%X",
1047             AcpiUtGetMutexName (Index), Timeout, WaitStatus));
1048 
1049         return (AE_OK);
1050     }
1051 
1052     AcpiGbl_Semaphores[Index].CurrentUnits--;
1053     return (AE_OK);
1054 }
1055 
1056 
1057 /******************************************************************************
1058  *
1059  * FUNCTION:    AcpiOsSignalSemaphore
1060  *
1061  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
1062  *              Units               - Number of units to send
1063  *
1064  * RETURN:      Status
1065  *
1066  * DESCRIPTION: Send units
1067  *
1068  *****************************************************************************/
1069 
1070 ACPI_STATUS
1071 AcpiOsSignalSemaphore (
1072     ACPI_SEMAPHORE      Handle,
1073     UINT32              Units)
1074 {
1075     UINT32              Index = (UINT32) Handle;
1076 
1077 
1078     ACPI_FUNCTION_ENTRY ();
1079 
1080 
1081     if (Index >= ACPI_OS_MAX_SEMAPHORES)
1082     {
1083         printf ("SignalSemaphore: Index/Handle out of range: %2.2X\n", Index);
1084         return (AE_BAD_PARAMETER);
1085     }
1086 
1087     if (!AcpiGbl_Semaphores[Index].OsHandle)
1088     {
1089         printf ("SignalSemaphore: Null OS handle, Index %2.2X\n", Index);
1090         return (AE_BAD_PARAMETER);
1091     }
1092 
1093     if (Units > 1)
1094     {
1095         printf ("SignalSemaphore: Attempt to signal %u units, Index %2.2X\n", Units, Index);
1096         return (AE_NOT_IMPLEMENTED);
1097     }
1098 
1099     if ((AcpiGbl_Semaphores[Index].CurrentUnits + 1) >
1100         AcpiGbl_Semaphores[Index].MaxUnits)
1101     {
1102         ACPI_ERROR ((AE_INFO,
1103             "Oversignalled semaphore[%u]! Current %u Max %u",
1104             Index, AcpiGbl_Semaphores[Index].CurrentUnits,
1105             AcpiGbl_Semaphores[Index].MaxUnits));
1106 
1107         return (AE_LIMIT);
1108     }
1109 
1110     AcpiGbl_Semaphores[Index].CurrentUnits++;
1111     ReleaseSemaphore (AcpiGbl_Semaphores[Index].OsHandle, Units, NULL);
1112 
1113     return (AE_OK);
1114 }
1115 
1116 #endif /* ACPI_SINGLE_THREADED */
1117 
1118 
1119 /******************************************************************************
1120  *
1121  * FUNCTION:    Spinlock interfaces
1122  *
1123  * DESCRIPTION: Map these interfaces to semaphore interfaces
1124  *
1125  *****************************************************************************/
1126 
1127 ACPI_STATUS
1128 AcpiOsCreateLock (
1129     ACPI_SPINLOCK           *OutHandle)
1130 {
1131     return (AcpiOsCreateSemaphore (1, 1, OutHandle));
1132 }
1133 
1134 void
1135 AcpiOsDeleteLock (
1136     ACPI_SPINLOCK           Handle)
1137 {
1138     AcpiOsDeleteSemaphore (Handle);
1139 }
1140 
1141 ACPI_CPU_FLAGS
1142 AcpiOsAcquireLock (
1143     ACPI_SPINLOCK           Handle)
1144 {
1145     AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
1146     return (0);
1147 }
1148 
1149 void
1150 AcpiOsReleaseLock (
1151     ACPI_SPINLOCK           Handle,
1152     ACPI_CPU_FLAGS          Flags)
1153 {
1154     AcpiOsSignalSemaphore (Handle, 1);
1155 }
1156 
1157 
1158 #if ACPI_FUTURE_IMPLEMENTATION
1159 
1160 /* Mutex interfaces, just implement with a semaphore */
1161 
1162 ACPI_STATUS
1163 AcpiOsCreateMutex (
1164     ACPI_MUTEX              *OutHandle)
1165 {
1166     return (AcpiOsCreateSemaphore (1, 1, OutHandle));
1167 }
1168 
1169 void
1170 AcpiOsDeleteMutex (
1171     ACPI_MUTEX              Handle)
1172 {
1173     AcpiOsDeleteSemaphore (Handle);
1174 }
1175 
1176 ACPI_STATUS
1177 AcpiOsAcquireMutex (
1178     ACPI_MUTEX              Handle,
1179     UINT16                  Timeout)
1180 {
1181     AcpiOsWaitSemaphore (Handle, 1, Timeout);
1182     return (0);
1183 }
1184 
1185 void
1186 AcpiOsReleaseMutex (
1187     ACPI_MUTEX              Handle)
1188 {
1189     AcpiOsSignalSemaphore (Handle, 1);
1190 }
1191 #endif
1192 
1193 
1194 /******************************************************************************
1195  *
1196  * FUNCTION:    AcpiOsInstallInterruptHandler
1197  *
1198  * PARAMETERS:  InterruptNumber     - Level handler should respond to.
1199  *              ServiceRoutine      - Address of the ACPI interrupt handler
1200  *              Context             - User context
1201  *
1202  * RETURN:      Handle to the newly installed handler.
1203  *
1204  * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
1205  *              OS-independent handler.
1206  *
1207  *****************************************************************************/
1208 
1209 UINT32
1210 AcpiOsInstallInterruptHandler (
1211     UINT32                  InterruptNumber,
1212     ACPI_OSD_HANDLER        ServiceRoutine,
1213     void                    *Context)
1214 {
1215 
1216     return (AE_OK);
1217 }
1218 
1219 
1220 /******************************************************************************
1221  *
1222  * FUNCTION:    AcpiOsRemoveInterruptHandler
1223  *
1224  * PARAMETERS:  Handle              - Returned when handler was installed
1225  *
1226  * RETURN:      Status
1227  *
1228  * DESCRIPTION: Uninstalls an interrupt handler.
1229  *
1230  *****************************************************************************/
1231 
1232 ACPI_STATUS
1233 AcpiOsRemoveInterruptHandler (
1234     UINT32                  InterruptNumber,
1235     ACPI_OSD_HANDLER        ServiceRoutine)
1236 {
1237 
1238     return (AE_OK);
1239 }
1240 
1241 
1242 /******************************************************************************
1243  *
1244  * FUNCTION:    AcpiOsStall
1245  *
1246  * PARAMETERS:  Microseconds        - Time to stall
1247  *
1248  * RETURN:      None. Blocks until stall is completed.
1249  *
1250  * DESCRIPTION: Sleep at microsecond granularity
1251  *
1252  *****************************************************************************/
1253 
1254 void
1255 AcpiOsStall (
1256     UINT32                  Microseconds)
1257 {
1258 
1259     Sleep ((Microseconds / ACPI_USEC_PER_MSEC) + 1);
1260     return;
1261 }
1262 
1263 
1264 /******************************************************************************
1265  *
1266  * FUNCTION:    AcpiOsSleep
1267  *
1268  * PARAMETERS:  Milliseconds        - Time to sleep
1269  *
1270  * RETURN:      None. Blocks until sleep is completed.
1271  *
1272  * DESCRIPTION: Sleep at millisecond granularity
1273  *
1274  *****************************************************************************/
1275 
1276 void
1277 AcpiOsSleep (
1278     UINT64                  Milliseconds)
1279 {
1280 
1281     /* Add 10ms to account for clock tick granularity */
1282 
1283     Sleep (((unsigned long) Milliseconds) + 10);
1284     return;
1285 }
1286 
1287 
1288 /******************************************************************************
1289  *
1290  * FUNCTION:    AcpiOsReadPciConfiguration
1291  *
1292  * PARAMETERS:  PciId               - Seg/Bus/Dev
1293  *              Register            - Device Register
1294  *              Value               - Buffer where value is placed
1295  *              Width               - Number of bits
1296  *
1297  * RETURN:      Status
1298  *
1299  * DESCRIPTION: Read data from PCI configuration space
1300  *
1301  *****************************************************************************/
1302 
1303 ACPI_STATUS
1304 AcpiOsReadPciConfiguration (
1305     ACPI_PCI_ID             *PciId,
1306     UINT32                  Register,
1307     UINT64                  *Value,
1308     UINT32                  Width)
1309 {
1310 
1311     *Value = 0;
1312     return (AE_OK);
1313 }
1314 
1315 
1316 /******************************************************************************
1317  *
1318  * FUNCTION:    AcpiOsWritePciConfiguration
1319  *
1320  * PARAMETERS:  PciId               - Seg/Bus/Dev
1321  *              Register            - Device Register
1322  *              Value               - Value to be written
1323  *              Width               - Number of bits
1324  *
1325  * RETURN:      Status
1326  *
1327  * DESCRIPTION: Write data to PCI configuration space
1328  *
1329  *****************************************************************************/
1330 
1331 ACPI_STATUS
1332 AcpiOsWritePciConfiguration (
1333     ACPI_PCI_ID             *PciId,
1334     UINT32                  Register,
1335     UINT64                  Value,
1336     UINT32                  Width)
1337 {
1338 
1339     return (AE_OK);
1340 }
1341 
1342 
1343 /******************************************************************************
1344  *
1345  * FUNCTION:    AcpiOsReadPort
1346  *
1347  * PARAMETERS:  Address             - Address of I/O port/register to read
1348  *              Value               - Where value is placed
1349  *              Width               - Number of bits
1350  *
1351  * RETURN:      Value read from port
1352  *
1353  * DESCRIPTION: Read data from an I/O port or register
1354  *
1355  *****************************************************************************/
1356 
1357 ACPI_STATUS
1358 AcpiOsReadPort (
1359     ACPI_IO_ADDRESS         Address,
1360     UINT32                  *Value,
1361     UINT32                  Width)
1362 {
1363     ACPI_FUNCTION_NAME (OsReadPort);
1364 
1365 
1366     switch (Width)
1367     {
1368     case 8:
1369 
1370         *Value = 0xFF;
1371         break;
1372 
1373     case 16:
1374 
1375         *Value = 0xFFFF;
1376         break;
1377 
1378     case 32:
1379 
1380         *Value = 0xFFFFFFFF;
1381         break;
1382 
1383     default:
1384 
1385         ACPI_ERROR ((AE_INFO, "Bad width parameter: %X", Width));
1386         return (AE_BAD_PARAMETER);
1387     }
1388 
1389     return (AE_OK);
1390 }
1391 
1392 
1393 /******************************************************************************
1394  *
1395  * FUNCTION:    AcpiOsWritePort
1396  *
1397  * PARAMETERS:  Address             - Address of I/O port/register to write
1398  *              Value               - Value to write
1399  *              Width               - Number of bits
1400  *
1401  * RETURN:      None
1402  *
1403  * DESCRIPTION: Write data to an I/O port or register
1404  *
1405  *****************************************************************************/
1406 
1407 ACPI_STATUS
1408 AcpiOsWritePort (
1409     ACPI_IO_ADDRESS         Address,
1410     UINT32                  Value,
1411     UINT32                  Width)
1412 {
1413     ACPI_FUNCTION_NAME (OsWritePort);
1414 
1415 
1416     if ((Width == 8) || (Width == 16) || (Width == 32))
1417     {
1418         return (AE_OK);
1419     }
1420 
1421     ACPI_ERROR ((AE_INFO, "Bad width parameter: %X", Width));
1422     return (AE_BAD_PARAMETER);
1423 }
1424 
1425 
1426 /******************************************************************************
1427  *
1428  * FUNCTION:    AcpiOsReadMemory
1429  *
1430  * PARAMETERS:  Address             - Physical Memory Address to read
1431  *              Value               - Where value is placed
1432  *              Width               - Number of bits (8,16,32, or 64)
1433  *
1434  * RETURN:      Value read from physical memory address. Always returned
1435  *              as a 64-bit integer, regardless of the read width.
1436  *
1437  * DESCRIPTION: Read data from a physical memory address
1438  *
1439  *****************************************************************************/
1440 
1441 ACPI_STATUS
1442 AcpiOsReadMemory (
1443     ACPI_PHYSICAL_ADDRESS   Address,
1444     UINT64                  *Value,
1445     UINT32                  Width)
1446 {
1447 
1448     switch (Width)
1449     {
1450     case 8:
1451     case 16:
1452     case 32:
1453     case 64:
1454 
1455         *Value = 0;
1456         break;
1457 
1458     default:
1459 
1460         return (AE_BAD_PARAMETER);
1461         break;
1462     }
1463 
1464     return (AE_OK);
1465 }
1466 
1467 
1468 /******************************************************************************
1469  *
1470  * FUNCTION:    AcpiOsWriteMemory
1471  *
1472  * PARAMETERS:  Address             - Physical Memory Address to write
1473  *              Value               - Value to write
1474  *              Width               - Number of bits (8,16,32, or 64)
1475  *
1476  * RETURN:      None
1477  *
1478  * DESCRIPTION: Write data to a physical memory address
1479  *
1480  *****************************************************************************/
1481 
1482 ACPI_STATUS
1483 AcpiOsWriteMemory (
1484     ACPI_PHYSICAL_ADDRESS   Address,
1485     UINT64                  Value,
1486     UINT32                  Width)
1487 {
1488 
1489     return (AE_OK);
1490 }
1491 
1492 
1493 /******************************************************************************
1494  *
1495  * FUNCTION:    AcpiOsSignal
1496  *
1497  * PARAMETERS:  Function            - ACPICA signal function code
1498  *              Info                - Pointer to function-dependent structure
1499  *
1500  * RETURN:      Status
1501  *
1502  * DESCRIPTION: Miscellaneous functions. Example implementation only.
1503  *
1504  *****************************************************************************/
1505 
1506 ACPI_STATUS
1507 AcpiOsSignal (
1508     UINT32                  Function,
1509     void                    *Info)
1510 {
1511 
1512     switch (Function)
1513     {
1514     case ACPI_SIGNAL_FATAL:
1515 
1516         break;
1517 
1518     case ACPI_SIGNAL_BREAKPOINT:
1519 
1520         break;
1521 
1522     default:
1523 
1524         break;
1525     }
1526 
1527     return (AE_OK);
1528 }
1529 
1530 
1531 /******************************************************************************
1532  *
1533  * FUNCTION:    Local cache interfaces
1534  *
1535  * DESCRIPTION: Implements cache interfaces via malloc/free for testing
1536  *              purposes only.
1537  *
1538  *****************************************************************************/
1539 
1540 #ifndef ACPI_USE_LOCAL_CACHE
1541 
1542 ACPI_STATUS
1543 AcpiOsCreateCache (
1544     char                    *CacheName,
1545     UINT16                  ObjectSize,
1546     UINT16                  MaxDepth,
1547     ACPI_CACHE_T            **ReturnCache)
1548 {
1549     ACPI_MEMORY_LIST        *NewCache;
1550 
1551 
1552     NewCache = malloc (sizeof (ACPI_MEMORY_LIST));
1553     if (!NewCache)
1554     {
1555         return (AE_NO_MEMORY);
1556     }
1557 
1558     memset (NewCache, 0, sizeof (ACPI_MEMORY_LIST));
1559     NewCache->ListName = CacheName;
1560     NewCache->ObjectSize = ObjectSize;
1561     NewCache->MaxDepth = MaxDepth;
1562 
1563     *ReturnCache = (ACPI_CACHE_T) NewCache;
1564     return (AE_OK);
1565 }
1566 
1567 ACPI_STATUS
1568 AcpiOsDeleteCache (
1569     ACPI_CACHE_T            *Cache)
1570 {
1571     free (Cache);
1572     return (AE_OK);
1573 }
1574 
1575 ACPI_STATUS
1576 AcpiOsPurgeCache (
1577     ACPI_CACHE_T            *Cache)
1578 {
1579     return (AE_OK);
1580 }
1581 
1582 void *
1583 AcpiOsAcquireObject (
1584     ACPI_CACHE_T            *Cache)
1585 {
1586     void                    *NewObject;
1587 
1588     NewObject = malloc (((ACPI_MEMORY_LIST *) Cache)->ObjectSize);
1589     memset (NewObject, 0, ((ACPI_MEMORY_LIST *) Cache)->ObjectSize);
1590 
1591     return (NewObject);
1592 }
1593 
1594 ACPI_STATUS
1595 AcpiOsReleaseObject (
1596     ACPI_CACHE_T            *Cache,
1597     void                    *Object)
1598 {
1599     free (Object);
1600     return (AE_OK);
1601 }
1602 
1603 #endif /* ACPI_USE_LOCAL_CACHE */
1604 
1605 
1606 /* Optional multi-thread support */
1607 
1608 #ifndef ACPI_SINGLE_THREADED
1609 /******************************************************************************
1610  *
1611  * FUNCTION:    AcpiOsGetThreadId
1612  *
1613  * PARAMETERS:  None
1614  *
1615  * RETURN:      Id of the running thread
1616  *
1617  * DESCRIPTION: Get the Id of the current (running) thread
1618  *
1619  *****************************************************************************/
1620 
1621 ACPI_THREAD_ID
1622 AcpiOsGetThreadId (
1623     void)
1624 {
1625     DWORD                   ThreadId;
1626 
1627     /* Ensure ID is never 0 */
1628 
1629     ThreadId = GetCurrentThreadId ();
1630     return ((ACPI_THREAD_ID) (ThreadId + 1));
1631 }
1632 
1633 
1634 /******************************************************************************
1635  *
1636  * FUNCTION:    AcpiOsExecute
1637  *
1638  * PARAMETERS:  Type                - Type of execution
1639  *              Function            - Address of the function to execute
1640  *              Context             - Passed as a parameter to the function
1641  *
1642  * RETURN:      Status
1643  *
1644  * DESCRIPTION: Execute a new thread
1645  *
1646  *****************************************************************************/
1647 
1648 ACPI_STATUS
1649 AcpiOsExecute (
1650     ACPI_EXECUTE_TYPE       Type,
1651     ACPI_OSD_EXEC_CALLBACK  Function,
1652     void                    *Context)
1653 {
1654 
1655     _beginthread (Function, (unsigned) 0, Context);
1656     return (0);
1657 }
1658 
1659 #else /* ACPI_SINGLE_THREADED */
1660 ACPI_THREAD_ID
1661 AcpiOsGetThreadId (
1662     void)
1663 {
1664     return (1);
1665 }
1666 
1667 ACPI_STATUS
1668 AcpiOsExecute (
1669     ACPI_EXECUTE_TYPE       Type,
1670     ACPI_OSD_EXEC_CALLBACK  Function,
1671     void                    *Context)
1672 {
1673 
1674     Function (Context);
1675     return (AE_OK);
1676 }
1677 
1678 #endif /* ACPI_SINGLE_THREADED */
1679 
1680 
1681 /******************************************************************************
1682  *
1683  * FUNCTION:    AcpiOsWaitEventsComplete
1684  *
1685  * PARAMETERS:  None
1686  *
1687  * RETURN:      None
1688  *
1689  * DESCRIPTION: Wait for all asynchronous events to complete. This
1690  *              implementation does nothing.
1691  *
1692  *****************************************************************************/
1693 
1694 void
1695 AcpiOsWaitEventsComplete (
1696     void)
1697 {
1698 
1699     return;
1700 }
1701