WIP FPC-III support
[linux/fpc-iii.git] / tools / power / acpi / os_specific / service_layers / osunixxf.c
blob5b2fd968535fd6b28a71f04ac2d39dd19df21797
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: osunixxf - UNIX OSL interfaces
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
11 * These interfaces are required in order to compile the ASL compiler and the
12 * various ACPICA tools under Linux or other Unix-like system.
14 #include <acpi/acpi.h>
15 #include "accommon.h"
16 #include "amlcode.h"
17 #include "acparser.h"
18 #include "acdebug.h"
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stdarg.h>
23 #include <unistd.h>
24 #include <sys/time.h>
25 #include <semaphore.h>
26 #include <pthread.h>
27 #include <errno.h>
29 #define _COMPONENT ACPI_OS_SERVICES
30 ACPI_MODULE_NAME("osunixxf")
32 /* Upcalls to acpi_exec */
33 void
34 ae_table_override(struct acpi_table_header *existing_table,
35 struct acpi_table_header **new_table);
37 typedef void *(*PTHREAD_CALLBACK) (void *);
39 /* Buffer used by acpi_os_vprintf */
41 #define ACPI_VPRINTF_BUFFER_SIZE 512
42 #define _ASCII_NEWLINE '\n'
44 /* Terminal support for acpi_exec only */
46 #ifdef ACPI_EXEC_APP
47 #include <termios.h>
49 struct termios original_term_attributes;
50 int term_attributes_were_set = 0;
52 acpi_status acpi_ut_read_line(char *buffer, u32 buffer_length, u32 *bytes_read);
54 static void os_enter_line_edit_mode(void);
56 static void os_exit_line_edit_mode(void);
58 /******************************************************************************
60 * FUNCTION: os_enter_line_edit_mode, os_exit_line_edit_mode
62 * PARAMETERS: None
64 * RETURN: None
66 * DESCRIPTION: Enter/Exit the raw character input mode for the terminal.
68 * Interactive line-editing support for the AML debugger. Used with the
69 * common/acgetline module.
71 * readline() is not used because of non-portability. It is not available
72 * on all systems, and if it is, often the package must be manually installed.
74 * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line
75 * editing that we need in acpi_os_get_line.
77 * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these
78 * calls will also work:
79 * For os_enter_line_edit_mode: system ("stty cbreak -echo")
80 * For os_exit_line_edit_mode: system ("stty cooked echo")
82 *****************************************************************************/
84 static void os_enter_line_edit_mode(void)
86 struct termios local_term_attributes;
88 term_attributes_were_set = 0;
90 /* STDIN must be a terminal */
92 if (!isatty(STDIN_FILENO)) {
93 return;
96 /* Get and keep the original attributes */
98 if (tcgetattr(STDIN_FILENO, &original_term_attributes)) {
99 fprintf(stderr, "Could not get terminal attributes!\n");
100 return;
103 /* Set the new attributes to enable raw character input */
105 memcpy(&local_term_attributes, &original_term_attributes,
106 sizeof(struct termios));
108 local_term_attributes.c_lflag &= ~(ICANON | ECHO);
109 local_term_attributes.c_cc[VMIN] = 1;
110 local_term_attributes.c_cc[VTIME] = 0;
112 if (tcsetattr(STDIN_FILENO, TCSANOW, &local_term_attributes)) {
113 fprintf(stderr, "Could not set terminal attributes!\n");
114 return;
117 term_attributes_were_set = 1;
120 static void os_exit_line_edit_mode(void)
123 if (!term_attributes_were_set) {
124 return;
127 /* Set terminal attributes back to the original values */
129 if (tcsetattr(STDIN_FILENO, TCSANOW, &original_term_attributes)) {
130 fprintf(stderr, "Could not restore terminal attributes!\n");
134 #else
136 /* These functions are not needed for other ACPICA utilities */
138 #define os_enter_line_edit_mode()
139 #define os_exit_line_edit_mode()
140 #endif
142 /******************************************************************************
144 * FUNCTION: acpi_os_initialize, acpi_os_terminate
146 * PARAMETERS: None
148 * RETURN: Status
150 * DESCRIPTION: Initialize and terminate this module.
152 *****************************************************************************/
154 acpi_status acpi_os_initialize(void)
156 acpi_status status;
158 acpi_gbl_output_file = stdout;
160 os_enter_line_edit_mode();
162 status = acpi_os_create_lock(&acpi_gbl_print_lock);
163 if (ACPI_FAILURE(status)) {
164 return (status);
167 return (AE_OK);
170 acpi_status acpi_os_terminate(void)
173 os_exit_line_edit_mode();
174 return (AE_OK);
177 #ifndef ACPI_USE_NATIVE_RSDP_POINTER
178 /******************************************************************************
180 * FUNCTION: acpi_os_get_root_pointer
182 * PARAMETERS: None
184 * RETURN: RSDP physical address
186 * DESCRIPTION: Gets the ACPI root pointer (RSDP)
188 *****************************************************************************/
190 acpi_physical_address acpi_os_get_root_pointer(void)
193 return (0);
195 #endif
197 /******************************************************************************
199 * FUNCTION: acpi_os_predefined_override
201 * PARAMETERS: init_val - Initial value of the predefined object
202 * new_val - The new value for the object
204 * RETURN: Status, pointer to value. Null pointer returned if not
205 * overriding.
207 * DESCRIPTION: Allow the OS to override predefined names
209 *****************************************************************************/
211 acpi_status
212 acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
213 acpi_string *new_val)
216 if (!init_val || !new_val) {
217 return (AE_BAD_PARAMETER);
220 *new_val = NULL;
221 return (AE_OK);
224 /******************************************************************************
226 * FUNCTION: acpi_os_table_override
228 * PARAMETERS: existing_table - Header of current table (probably
229 * firmware)
230 * new_table - Where an entire new table is returned.
232 * RETURN: Status, pointer to new table. Null pointer returned if no
233 * table is available to override
235 * DESCRIPTION: Return a different version of a table if one is available
237 *****************************************************************************/
239 acpi_status
240 acpi_os_table_override(struct acpi_table_header *existing_table,
241 struct acpi_table_header **new_table)
244 if (!existing_table || !new_table) {
245 return (AE_BAD_PARAMETER);
248 *new_table = NULL;
250 #ifdef ACPI_EXEC_APP
252 ae_table_override(existing_table, new_table);
253 return (AE_OK);
254 #else
256 return (AE_NO_ACPI_TABLES);
257 #endif
260 /******************************************************************************
262 * FUNCTION: acpi_os_physical_table_override
264 * PARAMETERS: existing_table - Header of current table (probably firmware)
265 * new_address - Where new table address is returned
266 * (Physical address)
267 * new_table_length - Where new table length is returned
269 * RETURN: Status, address/length of new table. Null pointer returned
270 * if no table is available to override.
272 * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
274 *****************************************************************************/
276 acpi_status
277 acpi_os_physical_table_override(struct acpi_table_header *existing_table,
278 acpi_physical_address *new_address,
279 u32 *new_table_length)
282 return (AE_SUPPORT);
285 /******************************************************************************
287 * FUNCTION: acpi_os_enter_sleep
289 * PARAMETERS: sleep_state - Which sleep state to enter
290 * rega_value - Register A value
291 * regb_value - Register B value
293 * RETURN: Status
295 * DESCRIPTION: A hook before writing sleep registers to enter the sleep
296 * state. Return AE_CTRL_TERMINATE to skip further sleep register
297 * writes.
299 *****************************************************************************/
301 acpi_status acpi_os_enter_sleep(u8 sleep_state, u32 rega_value, u32 regb_value)
304 return (AE_OK);
307 /******************************************************************************
309 * FUNCTION: acpi_os_redirect_output
311 * PARAMETERS: destination - An open file handle/pointer
313 * RETURN: None
315 * DESCRIPTION: Causes redirect of acpi_os_printf and acpi_os_vprintf
317 *****************************************************************************/
319 void acpi_os_redirect_output(void *destination)
322 acpi_gbl_output_file = destination;
325 /******************************************************************************
327 * FUNCTION: acpi_os_printf
329 * PARAMETERS: fmt, ... - Standard printf format
331 * RETURN: None
333 * DESCRIPTION: Formatted output. Note: very similar to acpi_os_vprintf
334 * (performance), changes should be tracked in both functions.
336 *****************************************************************************/
338 void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...)
340 va_list args;
341 u8 flags;
343 flags = acpi_gbl_db_output_flags;
344 if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
346 /* Output is directable to either a file (if open) or the console */
348 if (acpi_gbl_debug_file) {
350 /* Output file is open, send the output there */
352 va_start(args, fmt);
353 vfprintf(acpi_gbl_debug_file, fmt, args);
354 va_end(args);
355 } else {
356 /* No redirection, send output to console (once only!) */
358 flags |= ACPI_DB_CONSOLE_OUTPUT;
362 if (flags & ACPI_DB_CONSOLE_OUTPUT) {
363 va_start(args, fmt);
364 vfprintf(acpi_gbl_output_file, fmt, args);
365 va_end(args);
369 /******************************************************************************
371 * FUNCTION: acpi_os_vprintf
373 * PARAMETERS: fmt - Standard printf format
374 * args - Argument list
376 * RETURN: None
378 * DESCRIPTION: Formatted output with argument list pointer. Note: very
379 * similar to acpi_os_printf, changes should be tracked in both
380 * functions.
382 *****************************************************************************/
384 void acpi_os_vprintf(const char *fmt, va_list args)
386 u8 flags;
387 char buffer[ACPI_VPRINTF_BUFFER_SIZE];
390 * We build the output string in a local buffer because we may be
391 * outputting the buffer twice. Using vfprintf is problematic because
392 * some implementations modify the args pointer/structure during
393 * execution. Thus, we use the local buffer for portability.
395 * Note: Since this module is intended for use by the various ACPICA
396 * utilities/applications, we can safely declare the buffer on the stack.
397 * Also, This function is used for relatively small error messages only.
399 vsnprintf(buffer, ACPI_VPRINTF_BUFFER_SIZE, fmt, args);
401 flags = acpi_gbl_db_output_flags;
402 if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
404 /* Output is directable to either a file (if open) or the console */
406 if (acpi_gbl_debug_file) {
408 /* Output file is open, send the output there */
410 fputs(buffer, acpi_gbl_debug_file);
411 } else {
412 /* No redirection, send output to console (once only!) */
414 flags |= ACPI_DB_CONSOLE_OUTPUT;
418 if (flags & ACPI_DB_CONSOLE_OUTPUT) {
419 fputs(buffer, acpi_gbl_output_file);
423 #ifndef ACPI_EXEC_APP
424 /******************************************************************************
426 * FUNCTION: acpi_os_get_line
428 * PARAMETERS: buffer - Where to return the command line
429 * buffer_length - Maximum length of Buffer
430 * bytes_read - Where the actual byte count is returned
432 * RETURN: Status and actual bytes read
434 * DESCRIPTION: Get the next input line from the terminal. NOTE: For the
435 * acpi_exec utility, we use the acgetline module instead to
436 * provide line-editing and history support.
438 *****************************************************************************/
440 acpi_status acpi_os_get_line(char *buffer, u32 buffer_length, u32 *bytes_read)
442 int input_char;
443 u32 end_of_line;
445 /* Standard acpi_os_get_line for all utilities except acpi_exec */
447 for (end_of_line = 0;; end_of_line++) {
448 if (end_of_line >= buffer_length) {
449 return (AE_BUFFER_OVERFLOW);
452 if ((input_char = getchar()) == EOF) {
453 return (AE_ERROR);
456 if (!input_char || input_char == _ASCII_NEWLINE) {
457 break;
460 buffer[end_of_line] = (char)input_char;
463 /* Null terminate the buffer */
465 buffer[end_of_line] = 0;
467 /* Return the number of bytes in the string */
469 if (bytes_read) {
470 *bytes_read = end_of_line;
473 return (AE_OK);
475 #endif
477 #ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
478 /******************************************************************************
480 * FUNCTION: acpi_os_map_memory
482 * PARAMETERS: where - Physical address of memory to be mapped
483 * length - How much memory to map
485 * RETURN: Pointer to mapped memory. Null on error.
487 * DESCRIPTION: Map physical memory into caller's address space
489 *****************************************************************************/
491 void *acpi_os_map_memory(acpi_physical_address where, acpi_size length)
494 return (ACPI_TO_POINTER((acpi_size)where));
497 /******************************************************************************
499 * FUNCTION: acpi_os_unmap_memory
501 * PARAMETERS: where - Logical address of memory to be unmapped
502 * length - How much memory to unmap
504 * RETURN: None.
506 * DESCRIPTION: Delete a previously created mapping. Where and Length must
507 * correspond to a previous mapping exactly.
509 *****************************************************************************/
511 void acpi_os_unmap_memory(void *where, acpi_size length)
514 return;
516 #endif
518 /******************************************************************************
520 * FUNCTION: acpi_os_allocate
522 * PARAMETERS: size - Amount to allocate, in bytes
524 * RETURN: Pointer to the new allocation. Null on error.
526 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
528 *****************************************************************************/
530 void *acpi_os_allocate(acpi_size size)
532 void *mem;
534 mem = (void *)malloc((size_t) size);
535 return (mem);
538 #ifdef USE_NATIVE_ALLOCATE_ZEROED
539 /******************************************************************************
541 * FUNCTION: acpi_os_allocate_zeroed
543 * PARAMETERS: size - Amount to allocate, in bytes
545 * RETURN: Pointer to the new allocation. Null on error.
547 * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
549 *****************************************************************************/
551 void *acpi_os_allocate_zeroed(acpi_size size)
553 void *mem;
555 mem = (void *)calloc(1, (size_t) size);
556 return (mem);
558 #endif
560 /******************************************************************************
562 * FUNCTION: acpi_os_free
564 * PARAMETERS: mem - Pointer to previously allocated memory
566 * RETURN: None.
568 * DESCRIPTION: Free memory allocated via acpi_os_allocate
570 *****************************************************************************/
572 void acpi_os_free(void *mem)
575 free(mem);
578 #ifdef ACPI_SINGLE_THREADED
579 /******************************************************************************
581 * FUNCTION: Semaphore stub functions
583 * DESCRIPTION: Stub functions used for single-thread applications that do
584 * not require semaphore synchronization. Full implementations
585 * of these functions appear after the stubs.
587 *****************************************************************************/
589 acpi_status
590 acpi_os_create_semaphore(u32 max_units,
591 u32 initial_units, acpi_handle *out_handle)
593 *out_handle = (acpi_handle)1;
594 return (AE_OK);
597 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
599 return (AE_OK);
602 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
604 return (AE_OK);
607 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
609 return (AE_OK);
612 #else
613 /******************************************************************************
615 * FUNCTION: acpi_os_create_semaphore
617 * PARAMETERS: initial_units - Units to be assigned to the new semaphore
618 * out_handle - Where a handle will be returned
620 * RETURN: Status
622 * DESCRIPTION: Create an OS semaphore
624 *****************************************************************************/
626 acpi_status
627 acpi_os_create_semaphore(u32 max_units,
628 u32 initial_units, acpi_handle *out_handle)
630 sem_t *sem;
632 if (!out_handle) {
633 return (AE_BAD_PARAMETER);
635 #ifdef __APPLE__
637 static int semaphore_count = 0;
638 char semaphore_name[32];
640 snprintf(semaphore_name, sizeof(semaphore_name), "acpi_sem_%d",
641 semaphore_count++);
642 printf("%s\n", semaphore_name);
643 sem =
644 sem_open(semaphore_name, O_EXCL | O_CREAT, 0755,
645 initial_units);
646 if (!sem) {
647 return (AE_NO_MEMORY);
649 sem_unlink(semaphore_name); /* This just deletes the name */
652 #else
653 sem = acpi_os_allocate(sizeof(sem_t));
654 if (!sem) {
655 return (AE_NO_MEMORY);
658 if (sem_init(sem, 0, initial_units) == -1) {
659 acpi_os_free(sem);
660 return (AE_BAD_PARAMETER);
662 #endif
664 *out_handle = (acpi_handle)sem;
665 return (AE_OK);
668 /******************************************************************************
670 * FUNCTION: acpi_os_delete_semaphore
672 * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore
674 * RETURN: Status
676 * DESCRIPTION: Delete an OS semaphore
678 *****************************************************************************/
680 acpi_status acpi_os_delete_semaphore(acpi_handle handle)
682 sem_t *sem = (sem_t *) handle;
684 if (!sem) {
685 return (AE_BAD_PARAMETER);
687 #ifdef __APPLE__
688 if (sem_close(sem) == -1) {
689 return (AE_BAD_PARAMETER);
691 #else
692 if (sem_destroy(sem) == -1) {
693 return (AE_BAD_PARAMETER);
695 #endif
697 return (AE_OK);
700 /******************************************************************************
702 * FUNCTION: acpi_os_wait_semaphore
704 * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore
705 * units - How many units to wait for
706 * msec_timeout - How long to wait (milliseconds)
708 * RETURN: Status
710 * DESCRIPTION: Wait for units
712 *****************************************************************************/
714 acpi_status
715 acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 msec_timeout)
717 acpi_status status = AE_OK;
718 sem_t *sem = (sem_t *) handle;
719 int ret_val;
720 #ifndef ACPI_USE_ALTERNATE_TIMEOUT
721 struct timespec time;
722 #endif
724 if (!sem) {
725 return (AE_BAD_PARAMETER);
728 switch (msec_timeout) {
730 * No Wait:
731 * --------
732 * A zero timeout value indicates that we shouldn't wait - just
733 * acquire the semaphore if available otherwise return AE_TIME
734 * (a.k.a. 'would block').
736 case 0:
738 if (sem_trywait(sem) == -1) {
739 status = (AE_TIME);
741 break;
743 /* Wait Indefinitely */
745 case ACPI_WAIT_FOREVER:
747 while (((ret_val = sem_wait(sem)) == -1) && (errno == EINTR)) {
748 continue; /* Restart if interrupted */
750 if (ret_val != 0) {
751 status = (AE_TIME);
753 break;
755 /* Wait with msec_timeout */
757 default:
759 #ifdef ACPI_USE_ALTERNATE_TIMEOUT
761 * Alternate timeout mechanism for environments where
762 * sem_timedwait is not available or does not work properly.
764 while (msec_timeout) {
765 if (sem_trywait(sem) == 0) {
767 /* Got the semaphore */
768 return (AE_OK);
771 if (msec_timeout >= 10) {
772 msec_timeout -= 10;
773 usleep(10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */
774 } else {
775 msec_timeout--;
776 usleep(ACPI_USEC_PER_MSEC); /* one millisecond */
779 status = (AE_TIME);
780 #else
782 * The interface to sem_timedwait is an absolute time, so we need to
783 * get the current time, then add in the millisecond Timeout value.
785 if (clock_gettime(CLOCK_REALTIME, &time) == -1) {
786 perror("clock_gettime");
787 return (AE_TIME);
790 time.tv_sec += (msec_timeout / ACPI_MSEC_PER_SEC);
791 time.tv_nsec +=
792 ((msec_timeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC);
794 /* Handle nanosecond overflow (field must be less than one second) */
796 if (time.tv_nsec >= ACPI_NSEC_PER_SEC) {
797 time.tv_sec += (time.tv_nsec / ACPI_NSEC_PER_SEC);
798 time.tv_nsec = (time.tv_nsec % ACPI_NSEC_PER_SEC);
801 while (((ret_val = sem_timedwait(sem, &time)) == -1)
802 && (errno == EINTR)) {
803 continue; /* Restart if interrupted */
807 if (ret_val != 0) {
808 if (errno != ETIMEDOUT) {
809 perror("sem_timedwait");
811 status = (AE_TIME);
813 #endif
814 break;
817 return (status);
820 /******************************************************************************
822 * FUNCTION: acpi_os_signal_semaphore
824 * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore
825 * units - Number of units to send
827 * RETURN: Status
829 * DESCRIPTION: Send units
831 *****************************************************************************/
833 acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
835 sem_t *sem = (sem_t *) handle;
837 if (!sem) {
838 return (AE_BAD_PARAMETER);
841 if (sem_post(sem) == -1) {
842 return (AE_LIMIT);
845 return (AE_OK);
848 #endif /* ACPI_SINGLE_THREADED */
850 /******************************************************************************
852 * FUNCTION: Spinlock interfaces
854 * DESCRIPTION: Map these interfaces to semaphore interfaces
856 *****************************************************************************/
858 acpi_status acpi_os_create_lock(acpi_spinlock * out_handle)
861 return (acpi_os_create_semaphore(1, 1, out_handle));
864 void acpi_os_delete_lock(acpi_spinlock handle)
866 acpi_os_delete_semaphore(handle);
869 acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle)
871 acpi_os_wait_semaphore(handle, 1, 0xFFFF);
872 return (0);
875 void acpi_os_release_lock(acpi_spinlock handle, acpi_cpu_flags flags)
877 acpi_os_signal_semaphore(handle, 1);
880 /******************************************************************************
882 * FUNCTION: acpi_os_install_interrupt_handler
884 * PARAMETERS: interrupt_number - Level handler should respond to.
885 * isr - Address of the ACPI interrupt handler
886 * except_ptr - Where status is returned
888 * RETURN: Handle to the newly installed handler.
890 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
891 * OS-independent handler.
893 *****************************************************************************/
896 acpi_os_install_interrupt_handler(u32 interrupt_number,
897 acpi_osd_handler service_routine,
898 void *context)
901 return (AE_OK);
904 /******************************************************************************
906 * FUNCTION: acpi_os_remove_interrupt_handler
908 * PARAMETERS: handle - Returned when handler was installed
910 * RETURN: Status
912 * DESCRIPTION: Uninstalls an interrupt handler.
914 *****************************************************************************/
916 acpi_status
917 acpi_os_remove_interrupt_handler(u32 interrupt_number,
918 acpi_osd_handler service_routine)
921 return (AE_OK);
924 /******************************************************************************
926 * FUNCTION: acpi_os_stall
928 * PARAMETERS: microseconds - Time to sleep
930 * RETURN: Blocks until sleep is completed.
932 * DESCRIPTION: Sleep at microsecond granularity
934 *****************************************************************************/
936 void acpi_os_stall(u32 microseconds)
939 if (microseconds) {
940 usleep(microseconds);
944 /******************************************************************************
946 * FUNCTION: acpi_os_sleep
948 * PARAMETERS: milliseconds - Time to sleep
950 * RETURN: Blocks until sleep is completed.
952 * DESCRIPTION: Sleep at millisecond granularity
954 *****************************************************************************/
956 void acpi_os_sleep(u64 milliseconds)
959 /* Sleep for whole seconds */
961 sleep(milliseconds / ACPI_MSEC_PER_SEC);
964 * Sleep for remaining microseconds.
965 * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second).
967 usleep((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC);
970 /******************************************************************************
972 * FUNCTION: acpi_os_get_timer
974 * PARAMETERS: None
976 * RETURN: Current time in 100 nanosecond units
978 * DESCRIPTION: Get the current system time
980 *****************************************************************************/
982 u64 acpi_os_get_timer(void)
984 struct timeval time;
986 /* This timer has sufficient resolution for user-space application code */
988 gettimeofday(&time, NULL);
990 /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */
992 return (((u64)time.tv_sec * ACPI_100NSEC_PER_SEC) +
993 ((u64)time.tv_usec * ACPI_100NSEC_PER_USEC));
996 /******************************************************************************
998 * FUNCTION: acpi_os_read_pci_configuration
1000 * PARAMETERS: pci_id - Seg/Bus/Dev
1001 * pci_register - Device Register
1002 * value - Buffer where value is placed
1003 * width - Number of bits
1005 * RETURN: Status
1007 * DESCRIPTION: Read data from PCI configuration space
1009 *****************************************************************************/
1011 acpi_status
1012 acpi_os_read_pci_configuration(struct acpi_pci_id *pci_id,
1013 u32 pci_register, u64 *value, u32 width)
1016 *value = 0;
1017 return (AE_OK);
1020 /******************************************************************************
1022 * FUNCTION: acpi_os_write_pci_configuration
1024 * PARAMETERS: pci_id - Seg/Bus/Dev
1025 * pci_register - Device Register
1026 * value - Value to be written
1027 * width - Number of bits
1029 * RETURN: Status.
1031 * DESCRIPTION: Write data to PCI configuration space
1033 *****************************************************************************/
1035 acpi_status
1036 acpi_os_write_pci_configuration(struct acpi_pci_id *pci_id,
1037 u32 pci_register, u64 value, u32 width)
1040 return (AE_OK);
1043 /******************************************************************************
1045 * FUNCTION: acpi_os_read_port
1047 * PARAMETERS: address - Address of I/O port/register to read
1048 * value - Where value is placed
1049 * width - Number of bits
1051 * RETURN: Value read from port
1053 * DESCRIPTION: Read data from an I/O port or register
1055 *****************************************************************************/
1057 acpi_status acpi_os_read_port(acpi_io_address address, u32 *value, u32 width)
1060 switch (width) {
1061 case 8:
1063 *value = 0xFF;
1064 break;
1066 case 16:
1068 *value = 0xFFFF;
1069 break;
1071 case 32:
1073 *value = 0xFFFFFFFF;
1074 break;
1076 default:
1078 return (AE_BAD_PARAMETER);
1081 return (AE_OK);
1084 /******************************************************************************
1086 * FUNCTION: acpi_os_write_port
1088 * PARAMETERS: address - Address of I/O port/register to write
1089 * value - Value to write
1090 * width - Number of bits
1092 * RETURN: None
1094 * DESCRIPTION: Write data to an I/O port or register
1096 *****************************************************************************/
1098 acpi_status acpi_os_write_port(acpi_io_address address, u32 value, u32 width)
1101 return (AE_OK);
1104 /******************************************************************************
1106 * FUNCTION: acpi_os_read_memory
1108 * PARAMETERS: address - Physical Memory Address to read
1109 * value - Where value is placed
1110 * width - Number of bits (8,16,32, or 64)
1112 * RETURN: Value read from physical memory address. Always returned
1113 * as a 64-bit integer, regardless of the read width.
1115 * DESCRIPTION: Read data from a physical memory address
1117 *****************************************************************************/
1119 acpi_status
1120 acpi_os_read_memory(acpi_physical_address address, u64 *value, u32 width)
1123 switch (width) {
1124 case 8:
1125 case 16:
1126 case 32:
1127 case 64:
1129 *value = 0;
1130 break;
1132 default:
1134 return (AE_BAD_PARAMETER);
1136 return (AE_OK);
1139 /******************************************************************************
1141 * FUNCTION: acpi_os_write_memory
1143 * PARAMETERS: address - Physical Memory Address to write
1144 * value - Value to write
1145 * width - Number of bits (8,16,32, or 64)
1147 * RETURN: None
1149 * DESCRIPTION: Write data to a physical memory address
1151 *****************************************************************************/
1153 acpi_status
1154 acpi_os_write_memory(acpi_physical_address address, u64 value, u32 width)
1157 return (AE_OK);
1160 /******************************************************************************
1162 * FUNCTION: acpi_os_readable
1164 * PARAMETERS: pointer - Area to be verified
1165 * length - Size of area
1167 * RETURN: TRUE if readable for entire length
1169 * DESCRIPTION: Verify that a pointer is valid for reading
1171 *****************************************************************************/
1173 u8 acpi_os_readable(void *pointer, acpi_size length)
1176 return (TRUE);
1179 /******************************************************************************
1181 * FUNCTION: acpi_os_writable
1183 * PARAMETERS: pointer - Area to be verified
1184 * length - Size of area
1186 * RETURN: TRUE if writable for entire length
1188 * DESCRIPTION: Verify that a pointer is valid for writing
1190 *****************************************************************************/
1192 u8 acpi_os_writable(void *pointer, acpi_size length)
1195 return (TRUE);
1198 /******************************************************************************
1200 * FUNCTION: acpi_os_signal
1202 * PARAMETERS: function - ACPI A signal function code
1203 * info - Pointer to function-dependent structure
1205 * RETURN: Status
1207 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1209 *****************************************************************************/
1211 acpi_status acpi_os_signal(u32 function, void *info)
1214 switch (function) {
1215 case ACPI_SIGNAL_FATAL:
1217 break;
1219 case ACPI_SIGNAL_BREAKPOINT:
1221 break;
1223 default:
1225 break;
1228 return (AE_OK);
1231 /* Optional multi-thread support */
1233 #ifndef ACPI_SINGLE_THREADED
1234 /******************************************************************************
1236 * FUNCTION: acpi_os_get_thread_id
1238 * PARAMETERS: None
1240 * RETURN: Id of the running thread
1242 * DESCRIPTION: Get the ID of the current (running) thread
1244 *****************************************************************************/
1246 acpi_thread_id acpi_os_get_thread_id(void)
1248 pthread_t thread;
1250 thread = pthread_self();
1251 return (ACPI_CAST_PTHREAD_T(thread));
1254 /******************************************************************************
1256 * FUNCTION: acpi_os_execute
1258 * PARAMETERS: type - Type of execution
1259 * function - Address of the function to execute
1260 * context - Passed as a parameter to the function
1262 * RETURN: Status.
1264 * DESCRIPTION: Execute a new thread
1266 *****************************************************************************/
1268 acpi_status
1269 acpi_os_execute(acpi_execute_type type,
1270 acpi_osd_exec_callback function, void *context)
1272 pthread_t thread;
1273 int ret;
1275 ret =
1276 pthread_create(&thread, NULL, (PTHREAD_CALLBACK) function, context);
1277 if (ret) {
1278 acpi_os_printf("Create thread failed");
1280 return (0);
1283 #else /* ACPI_SINGLE_THREADED */
1284 acpi_thread_id acpi_os_get_thread_id(void)
1286 return (1);
1289 acpi_status
1290 acpi_os_execute(acpi_execute_type type,
1291 acpi_osd_exec_callback function, void *context)
1294 function(context);
1296 return (AE_OK);
1299 #endif /* ACPI_SINGLE_THREADED */
1301 /******************************************************************************
1303 * FUNCTION: acpi_os_wait_events_complete
1305 * PARAMETERS: None
1307 * RETURN: None
1309 * DESCRIPTION: Wait for all asynchronous events to complete. This
1310 * implementation does nothing.
1312 *****************************************************************************/
1314 void acpi_os_wait_events_complete(void)
1316 return;