Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / os_specific / service_layers / osunixxf.c
blob74c4c242395a219ccefa572b898a6951e3dce38f
1 /******************************************************************************
3 * Module Name: osunixxf - UNIX OSL interfaces
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
46 * These interfaces are required in order to compile the ASL compiler and the
47 * various ACPICA tools under Linux or other Unix-like system.
49 #include "acpi.h"
50 #include "accommon.h"
51 #include "amlcode.h"
52 #include "acparser.h"
53 #include "acdebug.h"
55 #include <stdio.h>
56 #include <stdlib.h>
57 #include <stdarg.h>
58 #include <unistd.h>
59 #include <sys/time.h>
60 #include <semaphore.h>
61 #include <pthread.h>
62 #include <errno.h>
64 #define _COMPONENT ACPI_OS_SERVICES
65 ACPI_MODULE_NAME ("osunixxf")
68 extern FILE *AcpiGbl_DebugFile;
69 FILE *AcpiGbl_OutputFile;
70 BOOLEAN AcpiGbl_DebugTimeout = FALSE;
73 /* Upcalls to AcpiExec */
75 ACPI_PHYSICAL_ADDRESS
76 AeLocalGetRootPointer (
77 void);
79 void
80 AeTableOverride (
81 ACPI_TABLE_HEADER *ExistingTable,
82 ACPI_TABLE_HEADER **NewTable);
84 typedef void* (*PTHREAD_CALLBACK) (void *);
86 /* Buffer used by AcpiOsVprintf */
88 #define ACPI_VPRINTF_BUFFER_SIZE 512
89 #define _ASCII_NEWLINE '\n'
91 /* Terminal support for AcpiExec only */
93 #ifdef ACPI_EXEC_APP
94 #include <termios.h>
96 struct termios OriginalTermAttributes;
98 ACPI_STATUS
99 AcpiUtReadLine (
100 char *Buffer,
101 UINT32 BufferLength,
102 UINT32 *BytesRead);
104 static void
105 OsEnterLineEditMode (
106 void);
108 static void
109 OsExitLineEditMode (
110 void);
113 /******************************************************************************
115 * FUNCTION: OsEnterLineEditMode, OsExitLineEditMode
117 * PARAMETERS: None
119 * RETURN: None
121 * DESCRIPTION: Enter/Exit the raw character input mode for the terminal.
123 * Interactive line-editing support for the AML debugger. Used with the
124 * common/acgetline module.
126 * readline() is not used because of non-portability. It is not available
127 * on all systems, and if it is, often the package must be manually installed.
129 * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line
130 * editing that we need in AcpiOsGetLine.
132 * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these
133 * calls will also work:
134 * For OsEnterLineEditMode: system ("stty cbreak -echo")
135 * For OsExitLineEditMode: system ("stty cooked echo")
137 *****************************************************************************/
139 static void
140 OsEnterLineEditMode (
141 void)
143 struct termios LocalTermAttributes;
146 /* Get and keep the original attributes */
148 if (tcgetattr (STDIN_FILENO, &OriginalTermAttributes))
150 fprintf (stderr, "Could not get/set terminal attributes!\n");
151 return;
154 /* Set the new attributes to enable raw character input */
156 memcpy (&LocalTermAttributes, &OriginalTermAttributes,
157 sizeof (struct termios));
159 LocalTermAttributes.c_lflag &= ~(ICANON | ECHO);
160 LocalTermAttributes.c_cc[VMIN] = 1;
161 LocalTermAttributes.c_cc[VTIME] = 0;
163 tcsetattr (STDIN_FILENO, TCSANOW, &LocalTermAttributes);
166 static void
167 OsExitLineEditMode (
168 void)
170 /* Set terminal attributes back to the original values */
172 tcsetattr (STDIN_FILENO, TCSANOW, &OriginalTermAttributes);
176 #else
178 /* These functions are not needed for other ACPICA utilities */
180 #define OsEnterLineEditMode()
181 #define OsExitLineEditMode()
182 #endif
185 /******************************************************************************
187 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate
189 * PARAMETERS: None
191 * RETURN: Status
193 * DESCRIPTION: Initialize and terminate this module.
195 *****************************************************************************/
197 ACPI_STATUS
198 AcpiOsInitialize (
199 void)
202 AcpiGbl_OutputFile = stdout;
204 OsEnterLineEditMode ();
205 return (AE_OK);
208 ACPI_STATUS
209 AcpiOsTerminate (
210 void)
213 OsExitLineEditMode ();
214 return (AE_OK);
218 /******************************************************************************
220 * FUNCTION: AcpiOsGetRootPointer
222 * PARAMETERS: None
224 * RETURN: RSDP physical address
226 * DESCRIPTION: Gets the ACPI root pointer (RSDP)
228 *****************************************************************************/
230 ACPI_PHYSICAL_ADDRESS
231 AcpiOsGetRootPointer (
232 void)
235 return (AeLocalGetRootPointer ());
239 /******************************************************************************
241 * FUNCTION: AcpiOsPredefinedOverride
243 * PARAMETERS: InitVal - Initial value of the predefined object
244 * NewVal - The new value for the object
246 * RETURN: Status, pointer to value. Null pointer returned if not
247 * overriding.
249 * DESCRIPTION: Allow the OS to override predefined names
251 *****************************************************************************/
253 ACPI_STATUS
254 AcpiOsPredefinedOverride (
255 const ACPI_PREDEFINED_NAMES *InitVal,
256 ACPI_STRING *NewVal)
259 if (!InitVal || !NewVal)
261 return (AE_BAD_PARAMETER);
264 *NewVal = NULL;
265 return (AE_OK);
269 /******************************************************************************
271 * FUNCTION: AcpiOsTableOverride
273 * PARAMETERS: ExistingTable - Header of current table (probably
274 * firmware)
275 * NewTable - Where an entire new table is returned.
277 * RETURN: Status, pointer to new table. Null pointer returned if no
278 * table is available to override
280 * DESCRIPTION: Return a different version of a table if one is available
282 *****************************************************************************/
284 ACPI_STATUS
285 AcpiOsTableOverride (
286 ACPI_TABLE_HEADER *ExistingTable,
287 ACPI_TABLE_HEADER **NewTable)
290 if (!ExistingTable || !NewTable)
292 return (AE_BAD_PARAMETER);
295 *NewTable = NULL;
297 #ifdef ACPI_EXEC_APP
299 AeTableOverride (ExistingTable, NewTable);
300 return (AE_OK);
301 #else
303 return (AE_NO_ACPI_TABLES);
304 #endif
308 /******************************************************************************
310 * FUNCTION: AcpiOsPhysicalTableOverride
312 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
313 * NewAddress - Where new table address is returned
314 * (Physical address)
315 * NewTableLength - Where new table length is returned
317 * RETURN: Status, address/length of new table. Null pointer returned
318 * if no table is available to override.
320 * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
322 *****************************************************************************/
324 ACPI_STATUS
325 AcpiOsPhysicalTableOverride (
326 ACPI_TABLE_HEADER *ExistingTable,
327 ACPI_PHYSICAL_ADDRESS *NewAddress,
328 UINT32 *NewTableLength)
331 return (AE_SUPPORT);
335 /******************************************************************************
337 * FUNCTION: AcpiOsRedirectOutput
339 * PARAMETERS: Destination - An open file handle/pointer
341 * RETURN: None
343 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
345 *****************************************************************************/
347 void
348 AcpiOsRedirectOutput (
349 void *Destination)
352 AcpiGbl_OutputFile = Destination;
356 /******************************************************************************
358 * FUNCTION: AcpiOsPrintf
360 * PARAMETERS: fmt, ... - Standard printf format
362 * RETURN: None
364 * DESCRIPTION: Formatted output. Note: very similar to AcpiOsVprintf
365 * (performance), changes should be tracked in both functions.
367 *****************************************************************************/
369 void ACPI_INTERNAL_VAR_XFACE
370 AcpiOsPrintf (
371 const char *Fmt,
372 ...)
374 va_list Args;
375 UINT8 Flags;
378 Flags = AcpiGbl_DbOutputFlags;
379 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
381 /* Output is directable to either a file (if open) or the console */
383 if (AcpiGbl_DebugFile)
385 /* Output file is open, send the output there */
387 va_start (Args, Fmt);
388 vfprintf (AcpiGbl_DebugFile, Fmt, Args);
389 va_end (Args);
391 else
393 /* No redirection, send output to console (once only!) */
395 Flags |= ACPI_DB_CONSOLE_OUTPUT;
399 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
401 va_start (Args, Fmt);
402 vfprintf (AcpiGbl_OutputFile, Fmt, Args);
403 va_end (Args);
408 /******************************************************************************
410 * FUNCTION: AcpiOsVprintf
412 * PARAMETERS: fmt - Standard printf format
413 * args - Argument list
415 * RETURN: None
417 * DESCRIPTION: Formatted output with argument list pointer. Note: very
418 * similar to AcpiOsPrintf, changes should be tracked in both
419 * functions.
421 *****************************************************************************/
423 void
424 AcpiOsVprintf (
425 const char *Fmt,
426 va_list Args)
428 UINT8 Flags;
429 char Buffer[ACPI_VPRINTF_BUFFER_SIZE];
433 * We build the output string in a local buffer because we may be
434 * outputting the buffer twice. Using vfprintf is problematic because
435 * some implementations modify the args pointer/structure during
436 * execution. Thus, we use the local buffer for portability.
438 * Note: Since this module is intended for use by the various ACPICA
439 * utilities/applications, we can safely declare the buffer on the stack.
440 * Also, This function is used for relatively small error messages only.
442 vsnprintf (Buffer, ACPI_VPRINTF_BUFFER_SIZE, Fmt, Args);
444 Flags = AcpiGbl_DbOutputFlags;
445 if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
447 /* Output is directable to either a file (if open) or the console */
449 if (AcpiGbl_DebugFile)
451 /* Output file is open, send the output there */
453 fputs (Buffer, AcpiGbl_DebugFile);
455 else
457 /* No redirection, send output to console (once only!) */
459 Flags |= ACPI_DB_CONSOLE_OUTPUT;
463 if (Flags & ACPI_DB_CONSOLE_OUTPUT)
465 fputs (Buffer, AcpiGbl_OutputFile);
470 #ifndef ACPI_EXEC_APP
471 /******************************************************************************
473 * FUNCTION: AcpiOsGetLine
475 * PARAMETERS: Buffer - Where to return the command line
476 * BufferLength - Maximum length of Buffer
477 * BytesRead - Where the actual byte count is returned
479 * RETURN: Status and actual bytes read
481 * DESCRIPTION: Get the next input line from the terminal. NOTE: For the
482 * AcpiExec utility, we use the acgetline module instead to
483 * provide line-editing and history support.
485 *****************************************************************************/
487 ACPI_STATUS
488 AcpiOsGetLine (
489 char *Buffer,
490 UINT32 BufferLength,
491 UINT32 *BytesRead)
493 int InputChar;
494 UINT32 EndOfLine;
497 /* Standard AcpiOsGetLine for all utilities except AcpiExec */
499 for (EndOfLine = 0; ; EndOfLine++)
501 if (EndOfLine >= BufferLength)
503 return (AE_BUFFER_OVERFLOW);
506 if ((InputChar = getchar ()) == EOF)
508 return (AE_ERROR);
511 if (!InputChar || InputChar == _ASCII_NEWLINE)
513 break;
516 Buffer[EndOfLine] = (char) InputChar;
519 /* Null terminate the buffer */
521 Buffer[EndOfLine] = 0;
523 /* Return the number of bytes in the string */
525 if (BytesRead)
527 *BytesRead = EndOfLine;
530 return (AE_OK);
532 #endif
535 /******************************************************************************
537 * FUNCTION: AcpiOsMapMemory
539 * PARAMETERS: where - Physical address of memory to be mapped
540 * length - How much memory to map
542 * RETURN: Pointer to mapped memory. Null on error.
544 * DESCRIPTION: Map physical memory into caller's address space
546 *****************************************************************************/
548 void *
549 AcpiOsMapMemory (
550 ACPI_PHYSICAL_ADDRESS where,
551 ACPI_SIZE length)
554 return (ACPI_TO_POINTER ((ACPI_SIZE) where));
558 /******************************************************************************
560 * FUNCTION: AcpiOsUnmapMemory
562 * PARAMETERS: where - Logical address of memory to be unmapped
563 * length - How much memory to unmap
565 * RETURN: None.
567 * DESCRIPTION: Delete a previously created mapping. Where and Length must
568 * correspond to a previous mapping exactly.
570 *****************************************************************************/
572 void
573 AcpiOsUnmapMemory (
574 void *where,
575 ACPI_SIZE length)
578 return;
582 /******************************************************************************
584 * FUNCTION: AcpiOsAllocate
586 * PARAMETERS: Size - Amount to allocate, in bytes
588 * RETURN: Pointer to the new allocation. Null on error.
590 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
592 *****************************************************************************/
594 void *
595 AcpiOsAllocate (
596 ACPI_SIZE size)
598 void *Mem;
601 Mem = (void *) malloc ((size_t) size);
602 return (Mem);
606 /******************************************************************************
608 * FUNCTION: AcpiOsFree
610 * PARAMETERS: mem - Pointer to previously allocated memory
612 * RETURN: None.
614 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
616 *****************************************************************************/
618 void
619 AcpiOsFree (
620 void *mem)
623 free (mem);
627 #ifdef ACPI_SINGLE_THREADED
628 /******************************************************************************
630 * FUNCTION: Semaphore stub functions
632 * DESCRIPTION: Stub functions used for single-thread applications that do
633 * not require semaphore synchronization. Full implementations
634 * of these functions appear after the stubs.
636 *****************************************************************************/
638 ACPI_STATUS
639 AcpiOsCreateSemaphore (
640 UINT32 MaxUnits,
641 UINT32 InitialUnits,
642 ACPI_HANDLE *OutHandle)
644 *OutHandle = (ACPI_HANDLE) 1;
645 return (AE_OK);
648 ACPI_STATUS
649 AcpiOsDeleteSemaphore (
650 ACPI_HANDLE Handle)
652 return (AE_OK);
655 ACPI_STATUS
656 AcpiOsWaitSemaphore (
657 ACPI_HANDLE Handle,
658 UINT32 Units,
659 UINT16 Timeout)
661 return (AE_OK);
664 ACPI_STATUS
665 AcpiOsSignalSemaphore (
666 ACPI_HANDLE Handle,
667 UINT32 Units)
669 return (AE_OK);
672 #else
673 /******************************************************************************
675 * FUNCTION: AcpiOsCreateSemaphore
677 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore
678 * OutHandle - Where a handle will be returned
680 * RETURN: Status
682 * DESCRIPTION: Create an OS semaphore
684 *****************************************************************************/
686 ACPI_STATUS
687 AcpiOsCreateSemaphore (
688 UINT32 MaxUnits,
689 UINT32 InitialUnits,
690 ACPI_HANDLE *OutHandle)
692 sem_t *Sem;
695 if (!OutHandle)
697 return (AE_BAD_PARAMETER);
700 #ifdef __APPLE__
702 char *SemaphoreName = tmpnam (NULL);
704 Sem = sem_open (SemaphoreName, O_EXCL|O_CREAT, 0755, InitialUnits);
705 if (!Sem)
707 return (AE_NO_MEMORY);
709 sem_unlink (SemaphoreName); /* This just deletes the name */
712 #else
713 Sem = AcpiOsAllocate (sizeof (sem_t));
714 if (!Sem)
716 return (AE_NO_MEMORY);
719 if (sem_init (Sem, 0, InitialUnits) == -1)
721 AcpiOsFree (Sem);
722 return (AE_BAD_PARAMETER);
724 #endif
726 *OutHandle = (ACPI_HANDLE) Sem;
727 return (AE_OK);
731 /******************************************************************************
733 * FUNCTION: AcpiOsDeleteSemaphore
735 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
737 * RETURN: Status
739 * DESCRIPTION: Delete an OS semaphore
741 *****************************************************************************/
743 ACPI_STATUS
744 AcpiOsDeleteSemaphore (
745 ACPI_HANDLE Handle)
747 sem_t *Sem = (sem_t *) Handle;
750 if (!Sem)
752 return (AE_BAD_PARAMETER);
755 if (sem_destroy (Sem) == -1)
757 return (AE_BAD_PARAMETER);
760 return (AE_OK);
764 /******************************************************************************
766 * FUNCTION: AcpiOsWaitSemaphore
768 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
769 * Units - How many units to wait for
770 * MsecTimeout - How long to wait (milliseconds)
772 * RETURN: Status
774 * DESCRIPTION: Wait for units
776 *****************************************************************************/
778 ACPI_STATUS
779 AcpiOsWaitSemaphore (
780 ACPI_HANDLE Handle,
781 UINT32 Units,
782 UINT16 MsecTimeout)
784 ACPI_STATUS Status = AE_OK;
785 sem_t *Sem = (sem_t *) Handle;
786 #ifndef ACPI_USE_ALTERNATE_TIMEOUT
787 struct timespec Time;
788 int RetVal;
789 #endif
792 if (!Sem)
794 return (AE_BAD_PARAMETER);
797 switch (MsecTimeout)
800 * No Wait:
801 * --------
802 * A zero timeout value indicates that we shouldn't wait - just
803 * acquire the semaphore if available otherwise return AE_TIME
804 * (a.k.a. 'would block').
806 case 0:
808 if (sem_trywait(Sem) == -1)
810 Status = (AE_TIME);
812 break;
814 /* Wait Indefinitely */
816 case ACPI_WAIT_FOREVER:
818 if (sem_wait (Sem))
820 Status = (AE_TIME);
822 break;
824 /* Wait with MsecTimeout */
826 default:
828 #ifdef ACPI_USE_ALTERNATE_TIMEOUT
830 * Alternate timeout mechanism for environments where
831 * sem_timedwait is not available or does not work properly.
833 while (MsecTimeout)
835 if (sem_trywait (Sem) == 0)
837 /* Got the semaphore */
838 return (AE_OK);
841 if (MsecTimeout >= 10)
843 MsecTimeout -= 10;
844 usleep (10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */
846 else
848 MsecTimeout--;
849 usleep (ACPI_USEC_PER_MSEC); /* one millisecond */
852 Status = (AE_TIME);
853 #else
855 * The interface to sem_timedwait is an absolute time, so we need to
856 * get the current time, then add in the millisecond Timeout value.
858 if (clock_gettime (CLOCK_REALTIME, &Time) == -1)
860 perror ("clock_gettime");
861 return (AE_TIME);
864 Time.tv_sec += (MsecTimeout / ACPI_MSEC_PER_SEC);
865 Time.tv_nsec += ((MsecTimeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC);
867 /* Handle nanosecond overflow (field must be less than one second) */
869 if (Time.tv_nsec >= ACPI_NSEC_PER_SEC)
871 Time.tv_sec += (Time.tv_nsec / ACPI_NSEC_PER_SEC);
872 Time.tv_nsec = (Time.tv_nsec % ACPI_NSEC_PER_SEC);
875 while (((RetVal = sem_timedwait (Sem, &Time)) == -1) && (errno == EINTR))
877 continue;
880 if (RetVal != 0)
882 if (errno != ETIMEDOUT)
884 perror ("sem_timedwait");
886 Status = (AE_TIME);
888 #endif
889 break;
892 return (Status);
896 /******************************************************************************
898 * FUNCTION: AcpiOsSignalSemaphore
900 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
901 * Units - Number of units to send
903 * RETURN: Status
905 * DESCRIPTION: Send units
907 *****************************************************************************/
909 ACPI_STATUS
910 AcpiOsSignalSemaphore (
911 ACPI_HANDLE Handle,
912 UINT32 Units)
914 sem_t *Sem = (sem_t *)Handle;
917 if (!Sem)
919 return (AE_BAD_PARAMETER);
922 if (sem_post (Sem) == -1)
924 return (AE_LIMIT);
927 return (AE_OK);
930 #endif /* ACPI_SINGLE_THREADED */
933 /******************************************************************************
935 * FUNCTION: Spinlock interfaces
937 * DESCRIPTION: Map these interfaces to semaphore interfaces
939 *****************************************************************************/
941 ACPI_STATUS
942 AcpiOsCreateLock (
943 ACPI_SPINLOCK *OutHandle)
946 return (AcpiOsCreateSemaphore (1, 1, OutHandle));
950 void
951 AcpiOsDeleteLock (
952 ACPI_SPINLOCK Handle)
954 AcpiOsDeleteSemaphore (Handle);
958 ACPI_CPU_FLAGS
959 AcpiOsAcquireLock (
960 ACPI_HANDLE Handle)
962 AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
963 return (0);
967 void
968 AcpiOsReleaseLock (
969 ACPI_SPINLOCK Handle,
970 ACPI_CPU_FLAGS Flags)
972 AcpiOsSignalSemaphore (Handle, 1);
976 /******************************************************************************
978 * FUNCTION: AcpiOsInstallInterruptHandler
980 * PARAMETERS: InterruptNumber - Level handler should respond to.
981 * Isr - Address of the ACPI interrupt handler
982 * ExceptPtr - Where status is returned
984 * RETURN: Handle to the newly installed handler.
986 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
987 * OS-independent handler.
989 *****************************************************************************/
991 UINT32
992 AcpiOsInstallInterruptHandler (
993 UINT32 InterruptNumber,
994 ACPI_OSD_HANDLER ServiceRoutine,
995 void *Context)
998 return (AE_OK);
1002 /******************************************************************************
1004 * FUNCTION: AcpiOsRemoveInterruptHandler
1006 * PARAMETERS: Handle - Returned when handler was installed
1008 * RETURN: Status
1010 * DESCRIPTION: Uninstalls an interrupt handler.
1012 *****************************************************************************/
1014 ACPI_STATUS
1015 AcpiOsRemoveInterruptHandler (
1016 UINT32 InterruptNumber,
1017 ACPI_OSD_HANDLER ServiceRoutine)
1020 return (AE_OK);
1024 /******************************************************************************
1026 * FUNCTION: AcpiOsStall
1028 * PARAMETERS: microseconds - Time to sleep
1030 * RETURN: Blocks until sleep is completed.
1032 * DESCRIPTION: Sleep at microsecond granularity
1034 *****************************************************************************/
1036 void
1037 AcpiOsStall (
1038 UINT32 microseconds)
1041 if (microseconds)
1043 usleep (microseconds);
1048 /******************************************************************************
1050 * FUNCTION: AcpiOsSleep
1052 * PARAMETERS: milliseconds - Time to sleep
1054 * RETURN: Blocks until sleep is completed.
1056 * DESCRIPTION: Sleep at millisecond granularity
1058 *****************************************************************************/
1060 void
1061 AcpiOsSleep (
1062 UINT64 milliseconds)
1065 /* Sleep for whole seconds */
1067 sleep (milliseconds / ACPI_MSEC_PER_SEC);
1070 * Sleep for remaining microseconds.
1071 * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second).
1073 usleep ((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC);
1077 /******************************************************************************
1079 * FUNCTION: AcpiOsGetTimer
1081 * PARAMETERS: None
1083 * RETURN: Current time in 100 nanosecond units
1085 * DESCRIPTION: Get the current system time
1087 *****************************************************************************/
1089 UINT64
1090 AcpiOsGetTimer (
1091 void)
1093 struct timeval time;
1096 /* This timer has sufficient resolution for user-space application code */
1098 gettimeofday (&time, NULL);
1100 /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */
1102 return (((UINT64) time.tv_sec * ACPI_100NSEC_PER_SEC) +
1103 ((UINT64) time.tv_usec * ACPI_100NSEC_PER_USEC));
1107 /******************************************************************************
1109 * FUNCTION: AcpiOsReadPciConfiguration
1111 * PARAMETERS: PciId - Seg/Bus/Dev
1112 * Register - Device Register
1113 * Value - Buffer where value is placed
1114 * Width - Number of bits
1116 * RETURN: Status
1118 * DESCRIPTION: Read data from PCI configuration space
1120 *****************************************************************************/
1122 ACPI_STATUS
1123 AcpiOsReadPciConfiguration (
1124 ACPI_PCI_ID *PciId,
1125 UINT32 Register,
1126 UINT64 *Value,
1127 UINT32 Width)
1130 *Value = 0;
1131 return (AE_OK);
1135 /******************************************************************************
1137 * FUNCTION: AcpiOsWritePciConfiguration
1139 * PARAMETERS: PciId - Seg/Bus/Dev
1140 * Register - Device Register
1141 * Value - Value to be written
1142 * Width - Number of bits
1144 * RETURN: Status.
1146 * DESCRIPTION: Write data to PCI configuration space
1148 *****************************************************************************/
1150 ACPI_STATUS
1151 AcpiOsWritePciConfiguration (
1152 ACPI_PCI_ID *PciId,
1153 UINT32 Register,
1154 UINT64 Value,
1155 UINT32 Width)
1158 return (AE_OK);
1162 /******************************************************************************
1164 * FUNCTION: AcpiOsReadPort
1166 * PARAMETERS: Address - Address of I/O port/register to read
1167 * Value - Where value is placed
1168 * Width - Number of bits
1170 * RETURN: Value read from port
1172 * DESCRIPTION: Read data from an I/O port or register
1174 *****************************************************************************/
1176 ACPI_STATUS
1177 AcpiOsReadPort (
1178 ACPI_IO_ADDRESS Address,
1179 UINT32 *Value,
1180 UINT32 Width)
1183 switch (Width)
1185 case 8:
1187 *Value = 0xFF;
1188 break;
1190 case 16:
1192 *Value = 0xFFFF;
1193 break;
1195 case 32:
1197 *Value = 0xFFFFFFFF;
1198 break;
1200 default:
1202 return (AE_BAD_PARAMETER);
1205 return (AE_OK);
1209 /******************************************************************************
1211 * FUNCTION: AcpiOsWritePort
1213 * PARAMETERS: Address - Address of I/O port/register to write
1214 * Value - Value to write
1215 * Width - Number of bits
1217 * RETURN: None
1219 * DESCRIPTION: Write data to an I/O port or register
1221 *****************************************************************************/
1223 ACPI_STATUS
1224 AcpiOsWritePort (
1225 ACPI_IO_ADDRESS Address,
1226 UINT32 Value,
1227 UINT32 Width)
1230 return (AE_OK);
1234 /******************************************************************************
1236 * FUNCTION: AcpiOsReadMemory
1238 * PARAMETERS: Address - Physical Memory Address to read
1239 * Value - Where value is placed
1240 * Width - Number of bits (8,16,32, or 64)
1242 * RETURN: Value read from physical memory address. Always returned
1243 * as a 64-bit integer, regardless of the read width.
1245 * DESCRIPTION: Read data from a physical memory address
1247 *****************************************************************************/
1249 ACPI_STATUS
1250 AcpiOsReadMemory (
1251 ACPI_PHYSICAL_ADDRESS Address,
1252 UINT64 *Value,
1253 UINT32 Width)
1256 switch (Width)
1258 case 8:
1259 case 16:
1260 case 32:
1261 case 64:
1263 *Value = 0;
1264 break;
1266 default:
1268 return (AE_BAD_PARAMETER);
1270 return (AE_OK);
1274 /******************************************************************************
1276 * FUNCTION: AcpiOsWriteMemory
1278 * PARAMETERS: Address - Physical Memory Address to write
1279 * Value - Value to write
1280 * Width - Number of bits (8,16,32, or 64)
1282 * RETURN: None
1284 * DESCRIPTION: Write data to a physical memory address
1286 *****************************************************************************/
1288 ACPI_STATUS
1289 AcpiOsWriteMemory (
1290 ACPI_PHYSICAL_ADDRESS Address,
1291 UINT64 Value,
1292 UINT32 Width)
1295 return (AE_OK);
1299 /******************************************************************************
1301 * FUNCTION: AcpiOsReadable
1303 * PARAMETERS: Pointer - Area to be verified
1304 * Length - Size of area
1306 * RETURN: TRUE if readable for entire length
1308 * DESCRIPTION: Verify that a pointer is valid for reading
1310 *****************************************************************************/
1312 BOOLEAN
1313 AcpiOsReadable (
1314 void *Pointer,
1315 ACPI_SIZE Length)
1318 return (TRUE);
1322 /******************************************************************************
1324 * FUNCTION: AcpiOsWritable
1326 * PARAMETERS: Pointer - Area to be verified
1327 * Length - Size of area
1329 * RETURN: TRUE if writable for entire length
1331 * DESCRIPTION: Verify that a pointer is valid for writing
1333 *****************************************************************************/
1335 BOOLEAN
1336 AcpiOsWritable (
1337 void *Pointer,
1338 ACPI_SIZE Length)
1341 return (TRUE);
1345 /******************************************************************************
1347 * FUNCTION: AcpiOsSignal
1349 * PARAMETERS: Function - ACPI CA signal function code
1350 * Info - Pointer to function-dependent structure
1352 * RETURN: Status
1354 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1356 *****************************************************************************/
1358 ACPI_STATUS
1359 AcpiOsSignal (
1360 UINT32 Function,
1361 void *Info)
1364 switch (Function)
1366 case ACPI_SIGNAL_FATAL:
1368 break;
1370 case ACPI_SIGNAL_BREAKPOINT:
1372 break;
1374 default:
1376 break;
1379 return (AE_OK);
1382 /* Optional multi-thread support */
1384 #ifndef ACPI_SINGLE_THREADED
1385 /******************************************************************************
1387 * FUNCTION: AcpiOsGetThreadId
1389 * PARAMETERS: None
1391 * RETURN: Id of the running thread
1393 * DESCRIPTION: Get the ID of the current (running) thread
1395 *****************************************************************************/
1397 ACPI_THREAD_ID
1398 AcpiOsGetThreadId (
1399 void)
1401 pthread_t thread;
1404 thread = pthread_self();
1405 return (ACPI_CAST_PTHREAD_T (thread));
1409 /******************************************************************************
1411 * FUNCTION: AcpiOsExecute
1413 * PARAMETERS: Type - Type of execution
1414 * Function - Address of the function to execute
1415 * Context - Passed as a parameter to the function
1417 * RETURN: Status.
1419 * DESCRIPTION: Execute a new thread
1421 *****************************************************************************/
1423 ACPI_STATUS
1424 AcpiOsExecute (
1425 ACPI_EXECUTE_TYPE Type,
1426 ACPI_OSD_EXEC_CALLBACK Function,
1427 void *Context)
1429 pthread_t thread;
1430 int ret;
1433 ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context);
1434 if (ret)
1436 AcpiOsPrintf("Create thread failed");
1438 return (0);
1441 #endif /* ACPI_SINGLE_THREADED */
1444 /******************************************************************************
1446 * FUNCTION: AcpiOsWaitEventsComplete
1448 * PARAMETERS: None
1450 * RETURN: None
1452 * DESCRIPTION: Wait for all asynchronous events to complete. This
1453 * implementation does nothing.
1455 *****************************************************************************/
1457 void
1458 AcpiOsWaitEventsComplete (
1459 void)
1461 return;