Import acpica-unix-20061109 from Intel.
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / osunixxf.c
1 /******************************************************************************
2  *
3  * Module Name: osunixxf - UNIX OSL interfaces
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 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 compile the ASL compiler under
119  * Linux.
120  */
121
122 #include <stdio.h>
123 #include <stdlib.h>
124 #include <stdarg.h>
125 #include <unistd.h>
126 #include <sys/time.h>
127
128 #include "acpi.h"
129 #include "amlcode.h"
130 #include "acparser.h"
131 #include "acdebug.h"
132
133 #define _COMPONENT          ACPI_OS_SERVICES
134         ACPI_MODULE_NAME    ("osunixxf")
135
136
137 extern FILE                    *AcpiGbl_DebugFile;
138 FILE                           *AcpiGbl_OutputFile;
139
140 ACPI_PHYSICAL_ADDRESS
141 AeLocalGetRootPointer (
142     void);
143
144
145 /******************************************************************************
146  *
147  * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
148  *
149  * PARAMETERS:  None
150  *
151  * RETURN:      Status
152  *
153  * DESCRIPTION: Init and terminate.  Nothing to do.
154  *
155  *****************************************************************************/
156
157 ACPI_STATUS
158 AcpiOsInitialize (void)
159 {
160     AcpiGbl_OutputFile = stdout;
161
162     return AE_OK;
163 }
164
165
166 ACPI_STATUS
167 AcpiOsTerminate (void)
168 {
169     return AE_OK;
170 }
171
172
173 /******************************************************************************
174  *
175  * FUNCTION:    AcpiOsGetRootPointer
176  *
177  * PARAMETERS:  None
178  *
179  * RETURN:      RSDP physical address
180  *
181  * DESCRIPTION: Gets the root pointer (RSDP)
182  *
183  *****************************************************************************/
184
185 ACPI_PHYSICAL_ADDRESS
186 AcpiOsGetRootPointer (
187     void)
188 {
189
190     return (AeLocalGetRootPointer ());
191 }
192
193
194 /******************************************************************************
195  *
196  * FUNCTION:    AcpiOsPredefinedOverride
197  *
198  * PARAMETERS:  InitVal     - Initial value of the predefined object
199  *              NewVal      - The new value for the object
200  *
201  * RETURN:      Status, pointer to value.  Null pointer returned if not
202  *              overriding.
203  *
204  * DESCRIPTION: Allow the OS to override predefined names
205  *
206  *****************************************************************************/
207
208 ACPI_STATUS
209 AcpiOsPredefinedOverride (
210     const ACPI_PREDEFINED_NAMES *InitVal,
211     ACPI_STRING                 *NewVal)
212 {
213
214     if (!InitVal || !NewVal)
215     {
216         return (AE_BAD_PARAMETER);
217     }
218
219     *NewVal = NULL;
220     return (AE_OK);
221 }
222
223
224 /******************************************************************************
225  *
226  * FUNCTION:    AcpiOsTableOverride
227  *
228  * PARAMETERS:  ExistingTable   - Header of current table (probably firmware)
229  *              NewTable        - Where an entire new table is returned.
230  *
231  * RETURN:      Status, pointer to new table.  Null pointer returned if no
232  *              table is available to override
233  *
234  * DESCRIPTION: Return a different version of a table if one is available
235  *
236  *****************************************************************************/
237
238 ACPI_STATUS
239 AcpiOsTableOverride (
240     ACPI_TABLE_HEADER       *ExistingTable,
241     ACPI_TABLE_HEADER       **NewTable)
242 {
243
244     if (!ExistingTable || !NewTable)
245     {
246         return (AE_BAD_PARAMETER);
247     }
248
249     *NewTable = NULL;
250
251 #ifdef ACPI_EXEC_APP
252
253     /* This code exercises the table override mechanism in the core */
254
255     if (ACPI_COMPARE_NAME (ExistingTable->Signature, ACPI_SIG_DSDT))
256     {
257         /* override DSDT with itself */
258
259         *NewTable = AcpiGbl_DbTablePtr;
260     }
261     return (AE_OK);
262 #else
263     return AE_NO_ACPI_TABLES;
264 #endif
265 }
266
267
268 /******************************************************************************
269  *
270  * FUNCTION:    AcpiOsReadable
271  *
272  * PARAMETERS:  Pointer             - Area to be verified
273  *              Length              - Size of area
274  *
275  * RETURN:      TRUE if readable for entire length
276  *
277  * DESCRIPTION: Verify that a pointer is valid for reading
278  *
279  *****************************************************************************/
280
281 BOOLEAN
282 AcpiOsReadable (
283     void                    *Pointer,
284     ACPI_SIZE               Length)
285 {
286
287     return (TRUE);
288 }
289
290
291 /******************************************************************************
292  *
293  * FUNCTION:    AcpiOsWritable
294  *
295  * PARAMETERS:  Pointer             - Area to be verified
296  *              Length              - Size of area
297  *
298  * RETURN:      TRUE if writable for entire length
299  *
300  * DESCRIPTION: Verify that a pointer is valid for writing
301  *
302  *****************************************************************************/
303
304 BOOLEAN
305 AcpiOsWritable (
306     void                    *Pointer,
307     ACPI_SIZE               Length)
308 {
309
310     return (TRUE);
311 }
312
313
314 /******************************************************************************
315  *
316  * FUNCTION:    AcpiOsRedirectOutput
317  *
318  * PARAMETERS:  Destination         - An open file handle/pointer
319  *
320  * RETURN:      None
321  *
322  * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
323  *
324  *****************************************************************************/
325
326 void
327 AcpiOsRedirectOutput (
328     void                    *Destination)
329 {
330
331     AcpiGbl_OutputFile = Destination;
332 }
333
334
335 /******************************************************************************
336  *
337  * FUNCTION:    AcpiOsPrintf
338  *
339  * PARAMETERS:  fmt, ...            Standard printf format
340  *
341  * RETURN:      None
342  *
343  * DESCRIPTION: Formatted output
344  *
345  *****************************************************************************/
346
347 void ACPI_INTERNAL_VAR_XFACE
348 AcpiOsPrintf (
349     const char              *Fmt,
350     ...)
351 {
352     va_list                 Args;
353
354
355     va_start (Args, Fmt);
356
357     AcpiOsVprintf (Fmt, Args);
358
359     va_end (Args);
360     return;
361 }
362
363
364 /******************************************************************************
365  *
366  * FUNCTION:    AcpiOsVprintf
367  *
368  * PARAMETERS:  fmt                 Standard printf format
369  *              args                Argument list
370  *
371  * RETURN:      None
372  *
373  * DESCRIPTION: Formatted output with argument list pointer
374  *
375  *****************************************************************************/
376
377 void
378 AcpiOsVprintf (
379     const char              *Fmt,
380     va_list                 Args)
381 {
382     INT32                   Count = 0;
383     UINT8                   Flags;
384
385
386     Flags = AcpiGbl_DbOutputFlags;
387     if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
388     {
389         /* Output is directable to either a file (if open) or the console */
390
391         if (AcpiGbl_DebugFile)
392         {
393             /* Output file is open, send the output there */
394
395             Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
396         }
397         else
398         {
399             /* No redirection, send output to console (once only!) */
400
401             Flags |= ACPI_DB_CONSOLE_OUTPUT;
402         }
403     }
404
405     if (Flags & ACPI_DB_CONSOLE_OUTPUT)
406     {
407         Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
408     }
409
410     return;
411 }
412
413
414 /******************************************************************************
415  *
416  * FUNCTION:    AcpiOsGetLine
417  *
418  * PARAMETERS:  fmt                 Standard printf format
419  *              args                Argument list
420  *
421  * RETURN:      Actual bytes read
422  *
423  * DESCRIPTION: Formatted input with argument list pointer
424  *
425  *****************************************************************************/
426
427 UINT32
428 AcpiOsGetLine (
429     char                    *Buffer)
430 {
431     UINT8                   Temp;
432     UINT32                  i;
433
434
435     for (i = 0; ; i++)
436     {
437         scanf ("%1c", &Temp);
438         if (!Temp || Temp == '\n')
439         {
440             break;
441         }
442
443         Buffer [i] = Temp;
444     }
445
446     /* Null terminate the buffer */
447
448     Buffer [i] = 0;
449
450     /* Return the number of bytes in the string */
451
452     return (i);
453 }
454
455 /******************************************************************************
456  *
457  * FUNCTION:    AcpiOsMapMemory
458  *
459  * PARAMETERS:  where               Physical address of memory to be mapped
460  *              length              How much memory to map
461  *
462  * RETURN:      Pointer to mapped memory.  Null on error.
463  *
464  * DESCRIPTION: Map physical memory into caller's address space
465  *
466  *****************************************************************************/
467
468 void *
469 AcpiOsMapMemory (
470     ACPI_PHYSICAL_ADDRESS   where,
471     ACPI_SIZE               length)
472 {
473
474     return (ACPI_TO_POINTER ((ACPI_NATIVE_UINT) where));
475 }
476
477
478 /******************************************************************************
479  *
480  * FUNCTION:    AcpiOsUnmapMemory
481  *
482  * PARAMETERS:  where               Logical address of memory to be unmapped
483  *              length              How much memory to unmap
484  *
485  * RETURN:      None.
486  *
487  * DESCRIPTION: Delete a previously created mapping.  Where and Length must
488  *              correspond to a previous mapping exactly.
489  *
490  *****************************************************************************/
491
492 void
493 AcpiOsUnmapMemory (
494     void                    *where,
495     ACPI_SIZE               length)
496 {
497
498     return;
499 }
500
501
502 /******************************************************************************
503  *
504  * FUNCTION:    AcpiOsAllocate
505  *
506  * PARAMETERS:  Size                Amount to allocate, in bytes
507  *
508  * RETURN:      Pointer to the new allocation.  Null on error.
509  *
510  * DESCRIPTION: Allocate memory.  Algorithm is dependent on the OS.
511  *
512  *****************************************************************************/
513
514 void *
515 AcpiOsAllocate (
516     ACPI_SIZE               size)
517 {
518     void                    *Mem;
519
520
521     Mem = (void *) malloc ((size_t) size);
522
523     return Mem;
524 }
525
526
527 /******************************************************************************
528  *
529  * FUNCTION:    AcpiOsFree
530  *
531  * PARAMETERS:  mem                 Pointer to previously allocated memory
532  *
533  * RETURN:      None.
534  *
535  * DESCRIPTION: Free memory allocated via AcpiOsAllocate
536  *
537  *****************************************************************************/
538
539 void
540 AcpiOsFree (
541     void                    *mem)
542 {
543
544
545     free (mem);
546 }
547
548
549 /******************************************************************************
550  *
551  * FUNCTION:    AcpiOsCreateSemaphore
552  *
553  * PARAMETERS:  InitialUnits        - Units to be assigned to the new semaphore
554  *              OutHandle           - Where a handle will be returned
555  *
556  * RETURN:      Status
557  *
558  * DESCRIPTION: Create an OS semaphore
559  *
560  *****************************************************************************/
561
562 ACPI_STATUS
563 AcpiOsCreateSemaphore (
564     UINT32              MaxUnits,
565     UINT32              InitialUnits,
566     ACPI_HANDLE         *OutHandle)
567 {
568
569
570     *OutHandle = (ACPI_HANDLE) 1;
571     return AE_OK;
572 }
573
574 /******************************************************************************
575  *
576  * FUNCTION:    AcpiOsDeleteSemaphore
577  *
578  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
579  *
580  * RETURN:      Status
581  *
582  * DESCRIPTION: Delete an OS semaphore
583  *
584  *****************************************************************************/
585
586 ACPI_STATUS
587 AcpiOsDeleteSemaphore (
588     ACPI_HANDLE         Handle)
589 {
590
591     if (!Handle)
592     {
593         return AE_BAD_PARAMETER;
594     }
595
596     return AE_OK;
597 }
598
599
600 /******************************************************************************
601  *
602  * FUNCTION:    AcpiOsWaitSemaphore
603  *
604  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
605  *              Units               - How many units to wait for
606  *              Timeout             - How long to wait
607  *
608  * RETURN:      Status
609  *
610  * DESCRIPTION: Wait for units
611  *
612  *****************************************************************************/
613
614 ACPI_STATUS
615 AcpiOsWaitSemaphore (
616     ACPI_HANDLE         Handle,
617     UINT32              Units,
618     UINT16              Timeout)
619 {
620
621
622     return AE_OK;
623 }
624
625
626 /******************************************************************************
627  *
628  * FUNCTION:    AcpiOsSignalSemaphore
629  *
630  * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
631  *              Units               - Number of units to send
632  *
633  * RETURN:      Status
634  *
635  * DESCRIPTION: Send units
636  *
637  *****************************************************************************/
638
639 ACPI_STATUS
640 AcpiOsSignalSemaphore (
641     ACPI_HANDLE         Handle,
642     UINT32              Units)
643 {
644
645
646     return AE_OK;
647 }
648
649
650 ACPI_STATUS
651 AcpiOsCreateLock (
652     ACPI_SPINLOCK           *OutHandle)
653 {
654
655     return (AcpiOsCreateSemaphore (1, 1, OutHandle));
656 }
657
658 void
659 AcpiOsDeleteLock (
660     ACPI_SPINLOCK           Handle)
661 {
662     AcpiOsDeleteSemaphore (Handle);
663 }
664
665
666 ACPI_CPU_FLAGS
667 AcpiOsAcquireLock (
668     ACPI_HANDLE             Handle)
669 {
670     AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
671     return (0);
672 }
673
674
675 void
676 AcpiOsReleaseLock (
677     ACPI_SPINLOCK           Handle,
678     ACPI_CPU_FLAGS          Flags)
679 {
680     AcpiOsSignalSemaphore (Handle, 1);
681 }
682
683
684 /******************************************************************************
685  *
686  * FUNCTION:    AcpiOsInstallInterruptHandler
687  *
688  * PARAMETERS:  InterruptNumber     Level handler should respond to.
689  *              Isr                 Address of the ACPI interrupt handler
690  *              ExceptPtr           Where status is returned
691  *
692  * RETURN:      Handle to the newly installed handler.
693  *
694  * DESCRIPTION: Install an interrupt handler.  Used to install the ACPI
695  *              OS-independent handler.
696  *
697  *****************************************************************************/
698
699 UINT32
700 AcpiOsInstallInterruptHandler (
701     UINT32                  InterruptNumber,
702     ACPI_OSD_HANDLER        ServiceRoutine,
703     void                    *Context)
704 {
705
706
707     return AE_OK;
708 }
709
710
711 /******************************************************************************
712  *
713  * FUNCTION:    AcpiOsRemoveInterruptHandler
714  *
715  * PARAMETERS:  Handle              Returned when handler was installed
716  *
717  * RETURN:      Status
718  *
719  * DESCRIPTION: Uninstalls an interrupt handler.
720  *
721  *****************************************************************************/
722
723 ACPI_STATUS
724 AcpiOsRemoveInterruptHandler (
725     UINT32                  InterruptNumber,
726     ACPI_OSD_HANDLER        ServiceRoutine)
727 {
728
729     return AE_OK;
730 }
731
732
733 /******************************************************************************
734  *
735  * FUNCTION:    AcpiOsExecute
736  *
737  * PARAMETERS:  Type            - Type of execution
738  *              Function        - Address of the function to execute
739  *              Context         - Passed as a parameter to the function
740  *
741  * RETURN:      Status.
742  *
743  * DESCRIPTION: Execute a new thread
744  *
745  *****************************************************************************/
746
747 ACPI_STATUS
748 AcpiOsExecute (
749     ACPI_EXECUTE_TYPE       Type,
750     ACPI_OSD_EXEC_CALLBACK  Function,
751     void                    *Context)
752 {
753
754 //    _beginthread (Function, (unsigned) 0, Context);
755     return 0;
756 }
757
758
759 /******************************************************************************
760  *
761  * FUNCTION:    AcpiOsBreakpoint
762  *
763  * PARAMETERS:  Msg                 Message to print
764  *
765  * RETURN:      Status
766  *
767  * DESCRIPTION: Print a message and break to the debugger.
768  *
769  *****************************************************************************/
770
771 ACPI_STATUS
772 AcpiOsBreakpoint (
773     char                    *Msg)
774 {
775
776     if (Msg)
777     {
778         AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Msg);
779     }
780     else
781     {
782         AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
783     }
784
785     return AE_OK;
786 }
787
788
789 /******************************************************************************
790  *
791  * FUNCTION:    AcpiOsStall
792  *
793  * PARAMETERS:  microseconds        To sleep
794  *
795  * RETURN:      Blocks until sleep is completed.
796  *
797  * DESCRIPTION: Sleep at microsecond granularity
798  *
799  *****************************************************************************/
800
801 void
802 AcpiOsStall (
803     UINT32                  microseconds)
804 {
805
806     if (microseconds)
807     {
808         usleep (microseconds);
809     }
810     return;
811 }
812
813
814 /******************************************************************************
815  *
816  * FUNCTION:    AcpiOsSleep
817  *
818  * PARAMETERS:  milliseconds        To sleep
819  *
820  * RETURN:      Blocks until sleep is completed.
821  *
822  * DESCRIPTION: Sleep at millisecond granularity
823  *
824  *****************************************************************************/
825
826 void
827 AcpiOsSleep (
828     ACPI_INTEGER            milliseconds)
829 {
830
831     sleep (milliseconds / 1000);    /* Sleep for whole seconds */
832
833     /*
834      * Arg to usleep() must be less than 1,000,000 (1 second)
835      */
836     usleep ((milliseconds % 1000) * 1000);      /* Sleep for remaining usecs */
837
838     return;
839 }
840
841 /******************************************************************************
842  *
843  * FUNCTION:    AcpiOsGetTimer
844  *
845  * PARAMETERS:  None
846  *
847  * RETURN:      Current time in 100 nanosecond units
848  *
849  * DESCRIPTION: Get the current system time
850  *
851  *****************************************************************************/
852
853 UINT64
854 AcpiOsGetTimer (void)
855 {
856     struct timeval  time;
857
858     gettimeofday(&time, NULL);
859
860     /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
861
862     return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10));
863 }
864
865
866 /******************************************************************************
867  *
868  * FUNCTION:    AcpiOsValidateInterface
869  *
870  * PARAMETERS:  Interface           - Requested interface to be validated
871  *
872  * RETURN:      AE_OK if interface is supported, AE_SUPPORT otherwise
873  *
874  * DESCRIPTION: Match an interface string to the interfaces supported by the
875  *              host. Strings originate from an AML call to the _OSI method.
876  *
877  *****************************************************************************/
878
879 ACPI_STATUS
880 AcpiOsValidateInterface (
881     char                    *Interface)
882 {
883
884     return (AE_SUPPORT);
885 }
886
887
888 /******************************************************************************
889  *
890  * FUNCTION:    AcpiOsValidateAddress
891  *
892  * PARAMETERS:  SpaceId             - ACPI space ID
893  *              Address             - Physical address
894  *              Length              - Address length
895  *
896  * RETURN:      AE_OK if Address/Length is valid for the SpaceId. Otherwise,
897  *              should return AE_AML_ILLEGAL_ADDRESS.
898  *
899  * DESCRIPTION: Validate a system address via the host OS. Used to validate
900  *              the addresses accessed by AML operation regions.
901  *
902  *****************************************************************************/
903
904 ACPI_STATUS
905 AcpiOsValidateAddress (
906     UINT8                   SpaceId,
907     ACPI_PHYSICAL_ADDRESS   Address,
908     ACPI_SIZE               Length)
909 {
910
911     return (AE_OK);
912 }
913
914
915 /******************************************************************************
916  *
917  * FUNCTION:    AcpiOsReadPciConfiguration
918  *
919  * PARAMETERS:  PciId               Seg/Bus/Dev
920  *              Register            Device Register
921  *              Value               Buffer where value is placed
922  *              Width               Number of bits
923  *
924  * RETURN:      Status
925  *
926  * DESCRIPTION: Read data from PCI configuration space
927  *
928  *****************************************************************************/
929
930 ACPI_STATUS
931 AcpiOsReadPciConfiguration (
932     ACPI_PCI_ID             *PciId,
933     UINT32                  Register,
934     void                    *Value,
935     UINT32                  Width)
936 {
937
938     return (AE_OK);
939 }
940
941
942 /******************************************************************************
943  *
944  * FUNCTION:    AcpiOsWritePciConfiguration
945  *
946  * PARAMETERS:  PciId               Seg/Bus/Dev
947  *              Register            Device Register
948  *              Value               Value to be written
949  *              Width               Number of bits
950  *
951  * RETURN:      Status.
952  *
953  * DESCRIPTION: Write data to PCI configuration space
954  *
955  *****************************************************************************/
956
957 ACPI_STATUS
958 AcpiOsWritePciConfiguration (
959     ACPI_PCI_ID             *PciId,
960     UINT32                  Register,
961     ACPI_INTEGER            Value,
962     UINT32                  Width)
963 {
964
965     return (AE_OK);
966 }
967
968 /* TEMPORARY STUB FUNCTION */
969 void
970 AcpiOsDerivePciId(
971     ACPI_HANDLE             rhandle,
972     ACPI_HANDLE             chandle,
973     ACPI_PCI_ID             **PciId)
974 {
975
976 }
977
978
979 /******************************************************************************
980  *
981  * FUNCTION:    AcpiOsReadPort
982  *
983  * PARAMETERS:  Address             Address of I/O port/register to read
984  *              Value               Where value is placed
985  *              Width               Number of bits
986  *
987  * RETURN:      Value read from port
988  *
989  * DESCRIPTION: Read data from an I/O port or register
990  *
991  *****************************************************************************/
992
993 ACPI_STATUS
994 AcpiOsReadPort (
995     ACPI_IO_ADDRESS         Address,
996     UINT32                  *Value,
997     UINT32                  Width)
998 {
999
1000     switch (Width)
1001     {
1002     case 8:
1003         *Value = 0xFF;
1004         break;
1005
1006     case 16:
1007         *Value = 0xFFFF;
1008         break;
1009
1010     case 32:
1011         *Value = 0xFFFFFFFF;
1012         break;
1013     }
1014
1015     return (AE_OK);
1016 }
1017
1018
1019 /******************************************************************************
1020  *
1021  * FUNCTION:    AcpiOsWritePort
1022  *
1023  * PARAMETERS:  Address             Address of I/O port/register to write
1024  *              Value               Value to write
1025  *              Width               Number of bits
1026  *
1027  * RETURN:      None
1028  *
1029  * DESCRIPTION: Write data to an I/O port or register
1030  *
1031  *****************************************************************************/
1032
1033 ACPI_STATUS
1034 AcpiOsWritePort (
1035     ACPI_IO_ADDRESS         Address,
1036     UINT32                  Value,
1037     UINT32                  Width)
1038 {
1039
1040     return (AE_OK);
1041 }
1042
1043
1044 /******************************************************************************
1045  *
1046  * FUNCTION:    AcpiOsReadMemory
1047  *
1048  * PARAMETERS:  Address             Physical Memory Address to read
1049  *              Value               Where value is placed
1050  *              Width               Number of bits
1051  *
1052  * RETURN:      Value read from physical memory address
1053  *
1054  * DESCRIPTION: Read data from a physical memory address
1055  *
1056  *****************************************************************************/
1057
1058 ACPI_STATUS
1059 AcpiOsReadMemory (
1060     ACPI_PHYSICAL_ADDRESS   Address,
1061     UINT32                  *Value,
1062     UINT32                  Width)
1063 {
1064
1065     switch (Width)
1066     {
1067     case 8:
1068     case 16:
1069     case 32:
1070         *Value = 0;
1071         break;
1072
1073     default:
1074         return (AE_BAD_PARAMETER);
1075         break;
1076     }
1077     return (AE_OK);
1078 }
1079
1080
1081 /******************************************************************************
1082  *
1083  * FUNCTION:    AcpiOsWriteMemory
1084  *
1085  * PARAMETERS:  Address             Physical Memory Address to write
1086  *              Value               Value to write
1087  *              Width               Number of bits
1088  *
1089  * RETURN:      None
1090  *
1091  * DESCRIPTION: Write data to a physical memory address
1092  *
1093  *****************************************************************************/
1094
1095 ACPI_STATUS
1096 AcpiOsWriteMemory (
1097     ACPI_PHYSICAL_ADDRESS   Address,
1098     UINT32                  Value,
1099     UINT32                  Width)
1100 {
1101
1102     return (AE_OK);
1103 }
1104
1105
1106 ACPI_THREAD_ID
1107 AcpiOsGetThreadId(void)
1108 {
1109     return getpid();
1110 }
1111
1112
1113 /******************************************************************************
1114  *
1115  * FUNCTION:    AcpiOsSignal
1116  *
1117  * PARAMETERS:  Function            ACPI CA signal function code
1118  *              Info                Pointer to function-dependent structure
1119  *
1120  * RETURN:      Status
1121  *
1122  * DESCRIPTION: Miscellaneous functions
1123  *
1124  *****************************************************************************/
1125
1126 ACPI_STATUS
1127 AcpiOsSignal (
1128     UINT32                  Function,
1129     void                    *Info)
1130 {
1131
1132     switch (Function)
1133     {
1134     case ACPI_SIGNAL_FATAL:
1135         break;
1136
1137     case ACPI_SIGNAL_BREAKPOINT:
1138
1139         if (Info)
1140         {
1141             AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Info);
1142         }
1143         else
1144         {
1145             AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
1146         }
1147
1148         break;
1149     }
1150
1151
1152     return (AE_OK);
1153 }
1154
1155