Merge from vendor branch INTEL_ACPICA:
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / os_specific / service_layers / osdosxf.c
1 /******************************************************************************
2  *
3  * Module Name: osdosxf - DOS OSL interfaces
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights.  You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code.  No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision.  In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change.  Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee.  Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution.  In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government.  In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115
116
117 /*
118  * These interfaces are required in order to link to the ACPI subsystem
119  * parser.  They are called during the execution of the parser, and all
120  * map directly to Clibrary calls.
121  */
122
123
124 #pragma warning(disable:4115)   /* warning C4115: named type definition in parentheses (caused by rpcasync.h> */
125
126 #include <stdio.h>
127 #include <stdlib.h>
128 #include <stdarg.h>
129 #include <process.h>
130 #include <conio.h>
131
132 #include "acpi.h"
133 #include "amlcode.h"
134 #include "acparser.h"
135 #include "acdebug.h"
136 #include "16bit.h"
137
138 #define _COMPONENT          ACPI_OS_SERVICES
139         ACPI_MODULE_NAME    ("adosd")
140
141
142 extern FILE                    *AcpiGbl_DebugFile;
143 FILE                           *AcpiGbl_OutputFile = stdout;
144
145 ACPI_STATUS
146 AeLocalGetRootPointer (
147     UINT32                  Flags,
148     ACPI_POINTER            *Address);
149
150 typedef struct
151 {
152     UINT32                  Units;
153 } DOS_SEMAPHORE;
154
155
156 /******************************************************************************
157  *
158  * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
159  *
160  * PARAMETERS:  None
161  *
162  * RETURN:      Status
163  *
164  * DESCRIPTION: Init and terminate.  Nothing to do.
165  *
166  *****************************************************************************/
167
168 ACPI_STATUS
169 AcpiOsInitialize (void)
170 {
171     return AE_OK;
172 }
173
174
175 ACPI_STATUS
176 AcpiOsTerminate (void)
177 {
178     return AE_OK;
179 }
180
181
182 /******************************************************************************
183  *
184  * FUNCTION:    AcpiOsGetRootPointer
185  *
186  * PARAMETERS:  Flags               - Logical/Physical addressing
187  *              PhysicalAddress     - of the RSDP
188  *
189  * RETURN:      Status
190  *
191  * DESCRIPTION: Returns the RSDP
192  *
193  *****************************************************************************/
194
195 ACPI_STATUS
196 AcpiOsGetRootPointer (
197     UINT32                  Flags,
198     ACPI_POINTER           *Address)
199 {
200     ACPI_STATUS            Status;
201
202     Status = AeLocalGetRootPointer (Flags, Address);
203     printf ("Root Pointer: %p\n", Address->Pointer.Logical);
204     return (Status);
205 }
206
207
208 /******************************************************************************
209  *
210  * FUNCTION:    AcpiOsPredefinedOverride
211  *
212  * PARAMETERS:  InitVal     - Initial value of the predefined object
213  *              NewVal      - The new value for the object
214  *
215  * RETURN:      Status, pointer to value.  Null pointer returned if not
216  *              overriding.
217  *
218  * DESCRIPTION: Allow the OS to override predefined names
219  *
220  *****************************************************************************/
221
222 ACPI_STATUS
223 AcpiOsPredefinedOverride (
224     const ACPI_PREDEFINED_NAMES *InitVal,
225     ACPI_STRING                 *NewVal)
226 {
227
228     if (!InitVal || !NewVal)
229     {
230         return (AE_BAD_PARAMETER);
231     }
232
233     *NewVal = NULL;
234     return (AE_OK);
235 }
236
237
238 /******************************************************************************
239  *
240  * FUNCTION:    AcpiOsTableOverride
241  *
242  * PARAMETERS:  ExistingTable   - Header of current table (probably firmware)
243  *              NewTable        - Where an entire new table is returned.
244  *
245  * RETURN:      Status, pointer to new table.  Null pointer returned if no
246  *              table is available to override
247  *
248  * DESCRIPTION: Return a different version of a table if one is available
249  *
250  *****************************************************************************/
251
252 ACPI_STATUS
253 AcpiOsTableOverride (
254     ACPI_TABLE_HEADER       *ExistingTable,
255     ACPI_TABLE_HEADER       **NewTable)
256 {
257 #ifndef ACPI_EXEC_APP
258     UINT8                   *NewTablePtr;
259     UINT32                  TableLength;
260     ACPI_STATUS             Status;
261     char                    Signature[4];
262 #endif
263
264
265     if (!ExistingTable || !NewTable)
266     {
267         return (AE_BAD_PARAMETER);
268     }
269
270 #ifdef ACPI_EXEC_APP
271     *NewTable = NULL;
272     return (AE_OK);
273
274 #else
275
276     ACPI_STRNCPY (Signature, ExistingTable->Signature, ACPI_NAME_SIZE);
277
278     /* Correct signature for FADT is "FACP" */
279
280     if (ACPI_COMPARE_NAME (Signature, "FADT"))
281     {
282         ACPI_STRNCPY (Signature, ACPI_SIG_FADT, ACPI_NAME_SIZE);
283     }
284
285     Status = AfFindTable (Signature, &NewTablePtr, &TableLength);
286
287     *NewTable = NULL;
288     if (Status == AE_OK)
289     {
290         *NewTable = (ACPI_TABLE_HEADER *) NewTablePtr;
291         AcpiOsPrintf ("[%4.4s] obtained from memory, %d bytes\n",
292             (char *) &ExistingTable->Signature, (UINT32) (*NewTable)->Length);
293     }
294     return (Status);
295 #endif
296 }
297
298
299 /******************************************************************************
300  *
301  * FUNCTION:    AcpiOsReadable
302  *
303  * PARAMETERS:  Pointer             - Area to be verified
304  *              Length              - Size of area
305  *
306  * RETURN:      TRUE if readable for entire length
307  *
308  * DESCRIPTION: Verify that a pointer is valid for reading
309  *
310  *****************************************************************************/
311
312 BOOLEAN
313 AcpiOsReadable (
314     void                    *Pointer,
315     ACPI_SIZE               Length)
316 {
317
318     return (TRUE);
319 }
320
321
322 /******************************************************************************
323  *
324  * FUNCTION:    AcpiOsWritable
325  *
326  * PARAMETERS:  Pointer             - Area to be verified
327  *              Length              - Size of area
328  *
329  * RETURN:      TRUE if writable for entire length
330  *
331  * DESCRIPTION: Verify that a pointer is valid for writing
332  *
333  *****************************************************************************/
334
335 BOOLEAN
336 AcpiOsWritable (
337     void                    *Pointer,
338     ACPI_SIZE               Length)
339 {
340
341     return (TRUE);
342 }
343
344
345 /******************************************************************************
346  *
347  * FUNCTION:    AcpiOslDoFormat
348  *
349  * PARAMETERS:  fmt, ...            Standard printf format
350  *
351  * RETURN:      None
352  *
353  * DESCRIPTION: Replace %X with %lX everywhere.
354  *
355  *****************************************************************************/
356
357 static char                 NewFmt[256];
358
359 void
360 AcpiOslDoFormat (
361     const char              *Fmt)
362 {
363     char                    *New = NewFmt;
364     const char              *Old = Fmt;
365
366     while (*Fmt)
367     {
368         if (*Fmt != '%')
369         {
370             *New++ = *Fmt++;
371             continue;
372         }
373
374         *New++ = *Fmt++;
375
376         if (*Fmt == 'x' || *Fmt == 'X')
377         {
378             memcpy (New, "lX", 2);
379             New += 2;
380             Fmt += 1;
381             continue;
382         }
383
384         if (*Fmt == 'd')
385         {
386             memcpy (New, "ld", 2);
387             New += 2;
388             Fmt += 1;
389             continue;
390         }
391
392         if (*Fmt == 'u')
393         {
394             memcpy (New, "lu", 2);
395             New += 2;
396             Fmt += 1;
397             continue;
398         }
399
400         if (!ACPI_STRNCMP (Fmt, "2.2d", 4))
401         {
402             memcpy (New, "2.2ld", 5);
403             New += 5;
404             Fmt += 4;
405             continue;
406         }
407
408         if (!ACPI_STRNCMP (Fmt, "2d", 2))
409         {
410             memcpy (New, "2ld", 3);
411             New += 3;
412             Fmt += 2;
413             continue;
414         }
415
416         if (!ACPI_STRNCMP (Fmt, "8.8X", 4))
417         {
418             memcpy (New, "8.8lX", 5);
419             New += 5;
420             Fmt += 4;
421             continue;
422         }
423
424         if (!ACPI_STRNCMP (Fmt, "5.5X", 4))
425         {
426             memcpy (New, "5.5lX", 5);
427             New += 5;
428             Fmt += 4;
429             continue;
430         }
431
432         if (!ACPI_STRNCMP (Fmt, "4.4X", 4))
433         {
434             memcpy (New, "4.4lX", 5);
435             New += 5;
436             Fmt += 4;
437             continue;
438         }
439
440         if (!ACPI_STRNCMP (Fmt, "2.2X", 4))
441         {
442             memcpy (New, "2.2lX", 5);
443             New += 5;
444             Fmt += 4;
445             continue;
446         }
447
448         if (!ACPI_STRNCMP (Fmt, ".8X", 3))
449         {
450             memcpy (New, ".8lX", 4);
451             New += 4;
452             Fmt += 3;
453             continue;
454         }
455
456         if (!ACPI_STRNCMP (Fmt, ".4X", 3))
457         {
458             memcpy (New, ".4lX", 4);
459             New += 4;
460             Fmt += 3;
461             continue;
462         }
463
464         if (!ACPI_STRNCMP (Fmt, ".2X", 3))
465         {
466             memcpy (New, ".2lX", 4);
467             New += 4;
468             Fmt += 3;
469             continue;
470         }
471
472         if (!ACPI_STRNCMP (Fmt, "2X", 2))
473         {
474             memcpy (New, "2lX", 3);
475             New += 3;
476             Fmt += 2;
477             continue;
478         }
479
480         if (!ACPI_STRNCMP (Fmt, "02X", 2))
481         {
482             memcpy (New, "02lX", 4);
483             New += 4;
484             Fmt += 3;
485             continue;
486         }
487        *New++ = *Fmt++;
488     }
489
490     *New = 0;
491 }
492
493
494 /******************************************************************************
495  *
496  * FUNCTION:    AcpiOsRedirectOutput
497  *
498  * PARAMETERS:  Destination         - An open file handle/pointer
499  *
500  * RETURN:      None
501  *
502  * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
503  *
504  *****************************************************************************/
505
506 void
507 AcpiOsRedirectOutput (
508     void                    *Destination)
509 {
510
511     AcpiGbl_OutputFile = Destination;
512 }
513
514
515 /******************************************************************************
516  *
517  * FUNCTION:    AcpiOsPrintf
518  *
519  * PARAMETERS:  fmt, ...            Standard printf format
520  *
521  * RETURN:      None
522  *
523  * DESCRIPTION: Formatted output
524  *
525  *****************************************************************************/
526
527 void ACPI_INTERNAL_VAR_XFACE
528 AcpiOsPrintf (
529     const char              *Fmt,
530     ...)
531 {
532     va_list                 Args;
533
534
535     va_start (Args, Fmt);
536
537     AcpiOsVprintf (Fmt, Args);
538
539     va_end (Args);
540     return;
541 }
542
543
544 /******************************************************************************
545  *
546  * FUNCTION:    AcpiOsVprintf
547  *
548  * PARAMETERS:  fmt                 Standard printf format
549  *              args                Argument list
550  *
551  * RETURN:      None
552  *
553  * DESCRIPTION: Formatted output with argument list pointer
554  *
555  *****************************************************************************/
556
557 void
558 AcpiOsVprintf (
559     const char              *Fmt,
560     va_list                 Args)
561 {
562     INT32                   Count = 0;
563     UINT8                   Flags;
564
565
566     AcpiOslDoFormat (Fmt);
567
568     Flags = AcpiGbl_DbOutputFlags;
569     if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
570     {
571         /* Output is directable to either a file (if open) or the console */
572
573         if (AcpiGbl_DebugFile)
574         {
575             /* Output file is open, send the output there */
576
577             Count = vfprintf (AcpiGbl_DebugFile, NewFmt, Args);
578         }
579         else
580         {
581             /* No redirection, send output to console (once only!) */
582
583             Flags |= ACPI_DB_CONSOLE_OUTPUT;
584         }
585     }
586
587     if (Flags & ACPI_DB_CONSOLE_OUTPUT)
588     {
589         Count = vfprintf (AcpiGbl_OutputFile, NewFmt, Args);
590     }
591
592     return;
593 }
594
595
596 /******************************************************************************
597  *
598  * FUNCTION:    AcpiOsGetLine
599  *
600  * PARAMETERS:  fmt                 Standard printf format
601  *              args                Argument list
602  *
603  * RETURN:      Actual bytes read
604  *
605  * DESCRIPTION: Formatted input with argument list pointer
606  *
607  *****************************************************************************/
608
609 UINT32
610 AcpiOsGetLine (
611     char                    *Buffer)
612 {
613     UINT8                   Temp;
614     UINT32                  i;
615
616
617     for (i = 0; ; i++)
618     {
619         scanf ("%1c", &Temp);
620         if (!Temp || Temp == '\n')
621         {
622             break;
623         }
624
625         Buffer [i] = Temp;
626     }
627
628     /* Null terminate the buffer */
629
630     Buffer [i] = 0;
631
632     /* Return the number of bytes in the string */
633
634     return (i);
635 }
636
637 /******************************************************************************
638  *
639  * FUNCTION:    AcpiOsMapMemory
640  *
641  * PARAMETERS:  where               Physical address of memory to be mapped
642  *              length              How much memory to map
643  *              there               Logical address of mapped memory
644  *
645  * RETURN:      Pointer to mapped memory.  Null on error.
646  *
647  * DESCRIPTION: Map physical memory into caller's address space
648  *
649  *****************************************************************************/
650
651 ACPI_STATUS
652 AcpiOsMapMemory (
653     ACPI_PHYSICAL_ADDRESS   where,
654     ACPI_SIZE               length,
655     void                    **there)
656 {
657     *there = where;
658
659     return AE_OK;
660 }
661
662
663 /******************************************************************************
664  *
665  * FUNCTION:    AcpiOsUnmapMemory
666  *
667  * PARAMETERS:  where               Logical address of memory to be unmapped
668  *              length              How much memory to unmap
669  *
670  * RETURN:      None.
671  *
672  * DESCRIPTION: Delete a previously created mapping.  Where and Length must
673  *              correspond to a previous mapping exactly.
674  *
675  *****************************************************************************/
676
677 void
678 AcpiOsUnmapMemory (
679     void                    *where,
680     ACPI_SIZE               length)
681 {
682
683     return;
684 }
685
686
687 /******************************************************************************
688  *
689  * FUNCTION:    AcpiOsAllocate
690  *
691  * PARAMETERS:  Size                Amount to allocate, in bytes
692  *
693  * RETURN:      Pointer to the new allocation.  Null on error.
694  *
695  * DESCRIPTION: Allocate memory.  Algorithm is dependent on the OS.
696  *
697  *****************************************************************************/
698
699 UINT32 TotalAllocations;
700 UINT32 TotalSize;
701
702 void *
703 AcpiOsAllocate (
704     ACPI_SIZE               size)
705 {
706     void                    *Mem;
707
708
709     Mem = (void *) malloc ((size_t) size);
710     if (!Mem)
711     {
712         ACPI_ERROR ((AE_INFO,
713             "Could not allocate memory of size %X\n (total allocations/size, %X/%X)",
714             (UINT32) size, TotalAllocations, TotalSize));
715     }
716
717     TotalAllocations++;
718     TotalSize += size;
719     return Mem;
720 }
721
722
723 /******************************************************************************
724  *
725  * FUNCTION:    AcpiOsFree
726  *
727  * PARAMETERS:  mem                 Pointer to previously allocated memory
728  *
729  * RETURN:      None.
730  *
731  * DESCRIPTION: Free memory allocated via AcpiOsAllocate
732  *
733  *****************************************************************************/
734
735 void
736 AcpiOsFree (
737     char                    *mem)
738 {
739
740
741     free ((void *) mem);
742 }
743
744
745 /******************************************************************************
746  *
747  * FUNCTION:    AcpiOsCreateSemaphore
748  *
749  * PARAMETERS:  InitialUnits        - Units to be assigned to the new semaphore
750  *              OutHandle           - Where a handle will be returned
751  *
752  * RETURN:      Status
753  *
754  * DESCRIPTION: Create an OS semaphore
755  *
756  *****************************************************************************/
757
758 ACPI_STATUS
759 AcpiOsCreateSemaphore (
760     UINT32              MaxUnits,
761     UINT32              InitialUnits,
762     ACPI_HANDLE         *OutHandle)
763 {
764     DOS_SEMAPHORE       *Sem;
765
766
767     Sem = AcpiOsAllocate (sizeof (DOS_SEMAPHORE));
768     if (!Sem)
769     {
770         return (AE_NO_MEMORY);
771     }
772
773     Sem->Units = InitialUnits;
774     *OutHandle = Sem;
775     return AE_OK;
776 }
777
778 /******************************************************************************
779  *
780  * FUNCTION:    AcpiOsDeleteSemaphore
781  *
782  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
783  *
784  * RETURN:      Status
785  *
786  * DESCRIPTION: Delete an OS semaphore
787  *
788  *****************************************************************************/
789
790 ACPI_STATUS
791 AcpiOsDeleteSemaphore (
792     ACPI_HANDLE         Handle)
793 {
794
795     if (!Handle)
796     {
797         return AE_BAD_PARAMETER;
798     }
799
800     AcpiOsFree (Handle);
801     return AE_OK;
802 }
803
804
805 /******************************************************************************
806  *
807  * FUNCTION:    AcpiOsWaitSemaphore
808  *
809  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
810  *              Units               - How many units to wait for
811  *              Timeout             - How long to wait
812  *
813  * RETURN:      Status
814  *
815  * DESCRIPTION: Wait for units
816  *
817  *****************************************************************************/
818
819 ACPI_STATUS
820 AcpiOsWaitSemaphore (
821     ACPI_HANDLE         Handle,
822     UINT32              Units,
823     UINT16              Timeout)
824 {
825     DOS_SEMAPHORE       *Sem;
826
827     if (!Handle)
828     {
829         return AE_BAD_PARAMETER;
830     }
831
832     Sem = Handle;
833     if (Sem->Units)
834     {
835         Sem->Units--;
836         return AE_OK;
837     }
838
839
840     return AE_TIME;
841 }
842
843
844 /******************************************************************************
845  *
846  * FUNCTION:    AcpiOsSignalSemaphore
847  *
848  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
849  *              Units               - Number of units to send
850  *
851  * RETURN:      Status
852  *
853  * DESCRIPTION: Send units
854  *
855  *****************************************************************************/
856
857 ACPI_STATUS
858 AcpiOsSignalSemaphore (
859     ACPI_HANDLE         Handle,
860     UINT32              Units)
861 {
862     DOS_SEMAPHORE       *Sem;
863
864     if (!Handle)
865     {
866         return AE_BAD_PARAMETER;
867     }
868
869     Sem = Handle;
870     Sem->Units++;
871     return AE_OK;
872 }
873
874
875 ACPI_STATUS
876 AcpiOsCreateLock (
877     ACPI_SPINLOCK           *OutHandle);
878 {
879
880     return (AcpiOsCreateSemaphore (1, 1, OutHandle));
881 }
882
883 void
884 AcpiOsDeleteLock (
885     ACPI_SPINLOCK           Handle)
886 {
887     AcpiOsDeleteSemaphore (Handle);
888 }
889
890
891 ACPI_CPU_FLAGS
892 AcpiOsAcquireLock (
893     ACPI_SPINLOCK           Handle)
894 {
895     AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
896     return (0);
897 }
898
899
900 void
901 AcpiOsReleaseLock (
902     ACPI_SPINLOCK           Handle,
903     ACPI_CPU_FLAGS          Flags)
904 {
905     AcpiOsSignalSemaphore (Handle, 1);
906 }
907
908
909 /******************************************************************************
910  *
911  * FUNCTION:    AcpiOsInstallInterruptHandler
912  *
913  * PARAMETERS:  InterruptNumber     Level handler should respond to.
914  *              Isr                 Address of the ACPI interrupt handler
915  *              ExceptPtr           Where status is returned
916  *
917  * RETURN:      Handle to the newly installed handler.
918  *
919  * DESCRIPTION: Install an interrupt handler.  Used to install the ACPI
920  *              OS-independent handler.
921  *
922  *****************************************************************************/
923
924 UINT32
925 AcpiOsInstallInterruptHandler (
926     UINT32                  InterruptNumber,
927     ACPI_OSD_HANDLER        ServiceRoutine,
928     void                    *Context)
929 {
930
931
932     return AE_OK;
933 }
934
935
936 /******************************************************************************
937  *
938  * FUNCTION:    AcpiOsRemoveInterruptHandler
939  *
940  * PARAMETERS:  Handle              Returned when handler was installed
941  *
942  * RETURN:      Status
943  *
944  * DESCRIPTION: Uninstalls an interrupt handler.
945  *
946  *****************************************************************************/
947
948 ACPI_STATUS
949 AcpiOsRemoveInterruptHandler (
950     UINT32                  InterruptNumber,
951     ACPI_OSD_HANDLER        ServiceRoutine)
952 {
953
954     return AE_OK;
955 }
956
957
958 /******************************************************************************
959  *
960  * FUNCTION:    AcpiOsGetThreadId
961  *
962  * PARAMETERS:  None
963  *
964  * RETURN:      Id of the running thread
965  *
966  * DESCRIPTION: Get the Id of the current (running) thread
967  *
968  *****************************************************************************/
969
970 ACPI_THREAD_ID
971 AcpiOsGetThreadId (
972     void)
973 {
974
975     /* Only one thread! */
976
977     return (1);
978
979 }
980
981
982 /******************************************************************************
983  *
984  * FUNCTION:    AcpiOsExecute
985  *
986  * PARAMETERS:  Type            - Type of execution
987  *              Function        - Address of the function to execute
988  *              Context         - Passed as a parameter to the function
989  *
990  * RETURN:      Status.
991  *
992  * DESCRIPTION: Execute a new thread
993  *
994  *****************************************************************************/
995
996 ACPI_STATUS
997 AcpiOsExecute (
998     ACPI_EXECUTE_TYPE       Type,
999     ACPI_OSD_EXEC_CALLBACK  Function,
1000     void                    *Context)
1001 {
1002
1003     return 0;
1004 }
1005
1006
1007 /******************************************************************************
1008  *
1009  * FUNCTION:    AcpiOsBreakpoint
1010  *
1011  * PARAMETERS:  Msg                 Message to print
1012  *
1013  * RETURN:      Status
1014  *
1015  * DESCRIPTION: Print a message and break to the debugger.
1016  *
1017  *****************************************************************************/
1018
1019 ACPI_STATUS
1020 AcpiOsBreakpoint (
1021     char                    *Msg)
1022 {
1023
1024     /* Print the message and do an INT 3 */
1025
1026     if (Msg)
1027     {
1028         AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Msg);
1029     }
1030     else
1031     {
1032         AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
1033     }
1034
1035
1036     return AE_OK;
1037 }
1038
1039
1040 /******************************************************************************
1041  *
1042  * FUNCTION:    AcpiOsStall
1043  *
1044  * PARAMETERS:  microseconds        To sleep
1045  *
1046  * RETURN:      Blocks until sleep is completed.
1047  *
1048  * DESCRIPTION: Sleep at microsecond granularity
1049  *
1050  *****************************************************************************/
1051
1052 void
1053 AcpiOsStall (
1054     UINT32                  microseconds)
1055 {
1056
1057     return;
1058 }
1059
1060
1061 /******************************************************************************
1062  *
1063  * FUNCTION:    AcpiOsSleep
1064  *
1065  * PARAMETERS:  milliseconds        To sleep
1066  *
1067  * RETURN:      Blocks until sleep is completed.
1068  *
1069  * DESCRIPTION: Sleep at millisecond granularity
1070  *
1071  *****************************************************************************/
1072
1073 void
1074 AcpiOsSleep (
1075     ACPI_INTEGER            milliseconds)
1076 {
1077
1078     return;
1079 }
1080
1081
1082 /******************************************************************************
1083  *
1084  * FUNCTION:    AcpiOsGetTimer
1085  *
1086  * PARAMETERS:  None
1087  *
1088  * RETURN:      Current time in 100 nanosecond units
1089  *
1090  * DESCRIPTION: Get the current system time
1091  *
1092  *****************************************************************************/
1093
1094 UINT64
1095 AcpiOsGetTimer (void)
1096 {
1097     UINT64                  Time;
1098
1099     Time.Lo = 0;
1100     Time.Hi = 0;
1101     return (Time);
1102 }
1103
1104
1105 /******************************************************************************
1106  *
1107  * FUNCTION:    AcpiOsValidateInterface
1108  *
1109  * PARAMETERS:  Interface           - Requested interface to be validated
1110  *
1111  * RETURN:      AE_OK if interface is supported, AE_SUPPORT otherwise
1112  *
1113  * DESCRIPTION: Match an interface string to the interfaces supported by the
1114  *              host. Strings originate from an AML call to the _OSI method.
1115  *
1116  *****************************************************************************/
1117
1118 ACPI_STATUS
1119 AcpiOsValidateInterface (
1120     char                    *Interface)
1121 {
1122
1123     return (AE_SUPPORT);
1124 }
1125
1126
1127 /******************************************************************************
1128  *
1129  * FUNCTION:    AcpiOsValidateAddress
1130  *
1131  * PARAMETERS:  SpaceId             - ACPI space ID
1132  *              Address             - Physical address
1133  *              Length              - Address length
1134  *
1135  * RETURN:      AE_OK if Address/Length is valid for the SpaceId. Otherwise,
1136  *              should return AE_AML_ILLEGAL_ADDRESS.
1137  *
1138  * DESCRIPTION: Validate a system address via the host OS. Used to validate
1139  *              the addresses accessed by AML operation regions.
1140  *
1141  *****************************************************************************/
1142
1143 ACPI_STATUS
1144 AcpiOsValidateAddress (
1145     UINT8                   SpaceId,
1146     ACPI_PHYSICAL_ADDRESS   Address,
1147     ACPI_SIZE               Length)
1148 {
1149
1150     return (AE_OK);
1151 }
1152
1153
1154 /******************************************************************************
1155  *
1156  * FUNCTION:    AcpiOsReadPciConfiguration
1157  *
1158  * PARAMETERS:  PciId               Seg/Bus/Dev
1159  *              Register            Device Register
1160  *              Value               Buffer where value is placed
1161  *              Width               Number of bits
1162  *
1163  * RETURN:      Status
1164  *
1165  * DESCRIPTION: Read data from PCI configuration space
1166  *
1167  *****************************************************************************/
1168
1169 ACPI_STATUS
1170 AcpiOsReadPciConfiguration (
1171     ACPI_PCI_ID             *PciId,
1172     UINT32                  Register,
1173     void                    *Value,
1174     UINT32                  Width)
1175 {
1176
1177     return (AE_OK);
1178 }
1179
1180
1181 /******************************************************************************
1182  *
1183  * FUNCTION:    AcpiOsWritePciConfiguration
1184  *
1185  * PARAMETERS:  PciId               Seg/Bus/Dev
1186  *              Register            Device Register
1187  *              Value               Value to be written
1188  *              Width               Number of bits
1189  *
1190  * RETURN:      Status.
1191  *
1192  * DESCRIPTION: Write data to PCI configuration space
1193  *
1194  *****************************************************************************/
1195
1196 ACPI_STATUS
1197 AcpiOsWritePciConfiguration (
1198     ACPI_PCI_ID             *PciId,
1199     UINT32                  Register,
1200     ACPI_INTEGER            Value,
1201     UINT32                  Width)
1202 {
1203
1204     return (AE_OK);
1205 }
1206
1207 /* TEMPORARY STUB FUNCTION */
1208 void
1209 AcpiOsDerivePciId(
1210     ACPI_HANDLE             rhandle,
1211     ACPI_HANDLE             chandle,
1212     ACPI_PCI_ID             **PciId)
1213 {
1214
1215 }
1216
1217
1218 /******************************************************************************
1219  *
1220  * FUNCTION:    AcpiOsReadPort
1221  *
1222  * PARAMETERS:  Address             Address of I/O port/register to read
1223  *              Value               Where value is placed
1224  *              Width               Number of bits
1225  *
1226  * RETURN:      Value read from port
1227  *
1228  * DESCRIPTION: Read data from an I/O port or register
1229  *
1230  *****************************************************************************/
1231
1232 ACPI_STATUS
1233 AcpiOsReadPort (
1234     ACPI_IO_ADDRESS         Address,
1235     UINT32                  *Value,
1236     UINT32                  Width)
1237 {
1238
1239     switch (Width)
1240     {
1241     case 8:
1242         *Value = 0xFF;
1243         break;
1244
1245     case 16:
1246         *Value = 0xFFFF;
1247         break;
1248
1249     case 32:
1250         *Value = 0xFFFFFFFF;
1251         break;
1252     }
1253
1254     return (AE_OK);
1255 }
1256
1257
1258 /******************************************************************************
1259  *
1260  * FUNCTION:    AcpiOsWritePort
1261  *
1262  * PARAMETERS:  Address             Address of I/O port/register to write
1263  *              Value               Value to write
1264  *              Width               Number of bits
1265  *
1266  * RETURN:      None
1267  *
1268  * DESCRIPTION: Write data to an I/O port or register
1269  *
1270  *****************************************************************************/
1271
1272 ACPI_STATUS
1273 AcpiOsWritePort (
1274     ACPI_IO_ADDRESS         Address,
1275     UINT32                  Value,
1276     UINT32                  Width)
1277 {
1278
1279     return (AE_OK);
1280 }
1281
1282
1283 /******************************************************************************
1284  *
1285  * FUNCTION:    AcpiOsReadMemory
1286  *
1287  * PARAMETERS:  Address             Physical Memory Address to read
1288  *              Value               Where value is placed
1289  *              Width               Number of bits
1290  *
1291  * RETURN:      Value read from physical memory address
1292  *
1293  * DESCRIPTION: Read data from a physical memory address
1294  *
1295  *****************************************************************************/
1296
1297 ACPI_STATUS
1298 AcpiOsReadMemory (
1299     ACPI_PHYSICAL_ADDRESS   Address,
1300     UINT32                  *Value,
1301     UINT32                  Width)
1302 {
1303
1304     switch (Width)
1305     {
1306     case 8:
1307     case 16:
1308     case 32:
1309         *Value = 0;
1310         break;
1311
1312     default:
1313         return (AE_BAD_PARAMETER);
1314         break;
1315     }
1316
1317     return (AE_OK);
1318 }
1319
1320
1321 /******************************************************************************
1322  *
1323  * FUNCTION:    AcpiOsWriteMemory
1324  *
1325  * PARAMETERS:  Address             Physical Memory Address to write
1326  *              Value               Value to write
1327  *              Width               Number of bits
1328  *
1329  * RETURN:      None
1330  *
1331  * DESCRIPTION: Write data to a physical memory address
1332  *
1333  *****************************************************************************/
1334
1335 ACPI_STATUS
1336 AcpiOsWriteMemory (
1337     ACPI_PHYSICAL_ADDRESS   Address,
1338     UINT32                  Value,
1339     UINT32                  Width)
1340 {
1341
1342     return (AE_OK);
1343 }
1344
1345
1346 /******************************************************************************
1347  *
1348  * FUNCTION:    AcpiOsSignal
1349  *
1350  * PARAMETERS:  Function            ACPI CA signal function code
1351  *              Info                Pointer to function-dependent structure
1352  *
1353  * RETURN:      Status
1354  *
1355  * DESCRIPTION: Miscellaneous functions
1356  *
1357  *****************************************************************************/
1358
1359 ACPI_STATUS
1360 AcpiOsSignal (
1361     UINT32                  Function,
1362     void                    *Info)
1363 {
1364
1365     return (AE_OK);
1366 }
1367
1368