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