xref: /linux/tools/power/acpi/os_specific/service_layers/osunixxf.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
283b80bacSLv Zheng /******************************************************************************
383b80bacSLv Zheng  *
483b80bacSLv Zheng  * Module Name: osunixxf - UNIX OSL interfaces
583b80bacSLv Zheng  *
6*612c2932SBob Moore  * Copyright (C) 2000 - 2023, Intel Corp.
783b80bacSLv Zheng  *
895857638SErik Schmauss  *****************************************************************************/
983b80bacSLv Zheng 
1083b80bacSLv Zheng /*
1183b80bacSLv Zheng  * These interfaces are required in order to compile the ASL compiler and the
1283b80bacSLv Zheng  * various ACPICA tools under Linux or other Unix-like system.
1383b80bacSLv Zheng  */
1483b80bacSLv Zheng #include <acpi/acpi.h>
1583b80bacSLv Zheng #include "accommon.h"
1683b80bacSLv Zheng #include "amlcode.h"
1783b80bacSLv Zheng #include "acparser.h"
1883b80bacSLv Zheng #include "acdebug.h"
1983b80bacSLv Zheng 
2083b80bacSLv Zheng #include <stdio.h>
2183b80bacSLv Zheng #include <stdlib.h>
2283b80bacSLv Zheng #include <stdarg.h>
2383b80bacSLv Zheng #include <unistd.h>
2483b80bacSLv Zheng #include <sys/time.h>
2583b80bacSLv Zheng #include <semaphore.h>
2683b80bacSLv Zheng #include <pthread.h>
2783b80bacSLv Zheng #include <errno.h>
2883b80bacSLv Zheng 
2983b80bacSLv Zheng #define _COMPONENT          ACPI_OS_SERVICES
3083b80bacSLv Zheng ACPI_MODULE_NAME("osunixxf")
3183b80bacSLv Zheng 
3283b80bacSLv Zheng /* Upcalls to acpi_exec */
3383b80bacSLv Zheng void
3483b80bacSLv Zheng ae_table_override(struct acpi_table_header *existing_table,
3583b80bacSLv Zheng 		  struct acpi_table_header **new_table);
3683b80bacSLv Zheng 
3783b80bacSLv Zheng typedef void *(*PTHREAD_CALLBACK) (void *);
3883b80bacSLv Zheng 
3983b80bacSLv Zheng /* Buffer used by acpi_os_vprintf */
4083b80bacSLv Zheng 
4183b80bacSLv Zheng #define ACPI_VPRINTF_BUFFER_SIZE    512
4283b80bacSLv Zheng #define _ASCII_NEWLINE              '\n'
4383b80bacSLv Zheng 
4483b80bacSLv Zheng /* Terminal support for acpi_exec only */
4583b80bacSLv Zheng 
4683b80bacSLv Zheng #ifdef ACPI_EXEC_APP
4783b80bacSLv Zheng #include <termios.h>
4883b80bacSLv Zheng 
4983b80bacSLv Zheng struct termios original_term_attributes;
5083b80bacSLv Zheng int term_attributes_were_set = 0;
5183b80bacSLv Zheng 
5283b80bacSLv Zheng acpi_status acpi_ut_read_line(char *buffer, u32 buffer_length, u32 *bytes_read);
5383b80bacSLv Zheng 
5483b80bacSLv Zheng static void os_enter_line_edit_mode(void);
5583b80bacSLv Zheng 
5683b80bacSLv Zheng static void os_exit_line_edit_mode(void);
5783b80bacSLv Zheng 
5883b80bacSLv Zheng /******************************************************************************
5983b80bacSLv Zheng  *
6083b80bacSLv Zheng  * FUNCTION:    os_enter_line_edit_mode, os_exit_line_edit_mode
6183b80bacSLv Zheng  *
6283b80bacSLv Zheng  * PARAMETERS:  None
6383b80bacSLv Zheng  *
6483b80bacSLv Zheng  * RETURN:      None
6583b80bacSLv Zheng  *
6683b80bacSLv Zheng  * DESCRIPTION: Enter/Exit the raw character input mode for the terminal.
6783b80bacSLv Zheng  *
6883b80bacSLv Zheng  * Interactive line-editing support for the AML debugger. Used with the
6983b80bacSLv Zheng  * common/acgetline module.
7083b80bacSLv Zheng  *
7183b80bacSLv Zheng  * readline() is not used because of non-portability. It is not available
7283b80bacSLv Zheng  * on all systems, and if it is, often the package must be manually installed.
7383b80bacSLv Zheng  *
7483b80bacSLv Zheng  * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line
7583b80bacSLv Zheng  * editing that we need in acpi_os_get_line.
7683b80bacSLv Zheng  *
7783b80bacSLv Zheng  * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these
7883b80bacSLv Zheng  * calls will also work:
7983b80bacSLv Zheng  *     For os_enter_line_edit_mode: system ("stty cbreak -echo")
8083b80bacSLv Zheng  *     For os_exit_line_edit_mode: system ("stty cooked echo")
8183b80bacSLv Zheng  *
8283b80bacSLv Zheng  *****************************************************************************/
8383b80bacSLv Zheng 
os_enter_line_edit_mode(void)8483b80bacSLv Zheng static void os_enter_line_edit_mode(void)
8583b80bacSLv Zheng {
8683b80bacSLv Zheng 	struct termios local_term_attributes;
8783b80bacSLv Zheng 
8863c9043bSBob Moore 	term_attributes_were_set = 0;
8963c9043bSBob Moore 
9063c9043bSBob Moore 	/* STDIN must be a terminal */
9163c9043bSBob Moore 
9263c9043bSBob Moore 	if (!isatty(STDIN_FILENO)) {
9363c9043bSBob Moore 		return;
9463c9043bSBob Moore 	}
9563c9043bSBob Moore 
9683b80bacSLv Zheng 	/* Get and keep the original attributes */
9783b80bacSLv Zheng 
9883b80bacSLv Zheng 	if (tcgetattr(STDIN_FILENO, &original_term_attributes)) {
9983b80bacSLv Zheng 		fprintf(stderr, "Could not get terminal attributes!\n");
10083b80bacSLv Zheng 		return;
10183b80bacSLv Zheng 	}
10283b80bacSLv Zheng 
10383b80bacSLv Zheng 	/* Set the new attributes to enable raw character input */
10483b80bacSLv Zheng 
10583b80bacSLv Zheng 	memcpy(&local_term_attributes, &original_term_attributes,
10683b80bacSLv Zheng 	       sizeof(struct termios));
10783b80bacSLv Zheng 
10883b80bacSLv Zheng 	local_term_attributes.c_lflag &= ~(ICANON | ECHO);
10983b80bacSLv Zheng 	local_term_attributes.c_cc[VMIN] = 1;
11083b80bacSLv Zheng 	local_term_attributes.c_cc[VTIME] = 0;
11183b80bacSLv Zheng 
11283b80bacSLv Zheng 	if (tcsetattr(STDIN_FILENO, TCSANOW, &local_term_attributes)) {
11383b80bacSLv Zheng 		fprintf(stderr, "Could not set terminal attributes!\n");
11483b80bacSLv Zheng 		return;
11583b80bacSLv Zheng 	}
11683b80bacSLv Zheng 
11783b80bacSLv Zheng 	term_attributes_were_set = 1;
11883b80bacSLv Zheng }
11983b80bacSLv Zheng 
os_exit_line_edit_mode(void)12083b80bacSLv Zheng static void os_exit_line_edit_mode(void)
12183b80bacSLv Zheng {
12283b80bacSLv Zheng 
12383b80bacSLv Zheng 	if (!term_attributes_were_set) {
12483b80bacSLv Zheng 		return;
12583b80bacSLv Zheng 	}
12683b80bacSLv Zheng 
12783b80bacSLv Zheng 	/* Set terminal attributes back to the original values */
12883b80bacSLv Zheng 
12983b80bacSLv Zheng 	if (tcsetattr(STDIN_FILENO, TCSANOW, &original_term_attributes)) {
13083b80bacSLv Zheng 		fprintf(stderr, "Could not restore terminal attributes!\n");
13183b80bacSLv Zheng 	}
13283b80bacSLv Zheng }
13383b80bacSLv Zheng 
13483b80bacSLv Zheng #else
13583b80bacSLv Zheng 
13683b80bacSLv Zheng /* These functions are not needed for other ACPICA utilities */
13783b80bacSLv Zheng 
13883b80bacSLv Zheng #define os_enter_line_edit_mode()
13983b80bacSLv Zheng #define os_exit_line_edit_mode()
14083b80bacSLv Zheng #endif
14183b80bacSLv Zheng 
14283b80bacSLv Zheng /******************************************************************************
14383b80bacSLv Zheng  *
14483b80bacSLv Zheng  * FUNCTION:    acpi_os_initialize, acpi_os_terminate
14583b80bacSLv Zheng  *
14683b80bacSLv Zheng  * PARAMETERS:  None
14783b80bacSLv Zheng  *
14883b80bacSLv Zheng  * RETURN:      Status
14983b80bacSLv Zheng  *
15083b80bacSLv Zheng  * DESCRIPTION: Initialize and terminate this module.
15183b80bacSLv Zheng  *
15283b80bacSLv Zheng  *****************************************************************************/
15383b80bacSLv Zheng 
acpi_os_initialize(void)15483b80bacSLv Zheng acpi_status acpi_os_initialize(void)
15583b80bacSLv Zheng {
15680a648c1SLv Zheng 	acpi_status status;
15783b80bacSLv Zheng 
15883b80bacSLv Zheng 	acpi_gbl_output_file = stdout;
15983b80bacSLv Zheng 
16083b80bacSLv Zheng 	os_enter_line_edit_mode();
16180a648c1SLv Zheng 
16280a648c1SLv Zheng 	status = acpi_os_create_lock(&acpi_gbl_print_lock);
16380a648c1SLv Zheng 	if (ACPI_FAILURE(status)) {
16480a648c1SLv Zheng 		return (status);
16580a648c1SLv Zheng 	}
16680a648c1SLv Zheng 
16783b80bacSLv Zheng 	return (AE_OK);
16883b80bacSLv Zheng }
16983b80bacSLv Zheng 
acpi_os_terminate(void)17083b80bacSLv Zheng acpi_status acpi_os_terminate(void)
17183b80bacSLv Zheng {
17283b80bacSLv Zheng 
17383b80bacSLv Zheng 	os_exit_line_edit_mode();
17483b80bacSLv Zheng 	return (AE_OK);
17583b80bacSLv Zheng }
17683b80bacSLv Zheng 
17783b80bacSLv Zheng #ifndef ACPI_USE_NATIVE_RSDP_POINTER
17883b80bacSLv Zheng /******************************************************************************
17983b80bacSLv Zheng  *
18083b80bacSLv Zheng  * FUNCTION:    acpi_os_get_root_pointer
18183b80bacSLv Zheng  *
18283b80bacSLv Zheng  * PARAMETERS:  None
18383b80bacSLv Zheng  *
18483b80bacSLv Zheng  * RETURN:      RSDP physical address
18583b80bacSLv Zheng  *
18683b80bacSLv Zheng  * DESCRIPTION: Gets the ACPI root pointer (RSDP)
18783b80bacSLv Zheng  *
18883b80bacSLv Zheng  *****************************************************************************/
18983b80bacSLv Zheng 
acpi_os_get_root_pointer(void)19083b80bacSLv Zheng acpi_physical_address acpi_os_get_root_pointer(void)
19183b80bacSLv Zheng {
19283b80bacSLv Zheng 
19383b80bacSLv Zheng 	return (0);
19483b80bacSLv Zheng }
19583b80bacSLv Zheng #endif
19683b80bacSLv Zheng 
19783b80bacSLv Zheng /******************************************************************************
19883b80bacSLv Zheng  *
19983b80bacSLv Zheng  * FUNCTION:    acpi_os_predefined_override
20083b80bacSLv Zheng  *
20183b80bacSLv Zheng  * PARAMETERS:  init_val            - Initial value of the predefined object
20283b80bacSLv Zheng  *              new_val             - The new value for the object
20383b80bacSLv Zheng  *
20483b80bacSLv Zheng  * RETURN:      Status, pointer to value. Null pointer returned if not
20583b80bacSLv Zheng  *              overriding.
20683b80bacSLv Zheng  *
20783b80bacSLv Zheng  * DESCRIPTION: Allow the OS to override predefined names
20883b80bacSLv Zheng  *
20983b80bacSLv Zheng  *****************************************************************************/
21083b80bacSLv Zheng 
21183b80bacSLv Zheng acpi_status
acpi_os_predefined_override(const struct acpi_predefined_names * init_val,acpi_string * new_val)21283b80bacSLv Zheng acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
21383b80bacSLv Zheng 			    acpi_string *new_val)
21483b80bacSLv Zheng {
21583b80bacSLv Zheng 
21683b80bacSLv Zheng 	if (!init_val || !new_val) {
21783b80bacSLv Zheng 		return (AE_BAD_PARAMETER);
21883b80bacSLv Zheng 	}
21983b80bacSLv Zheng 
22083b80bacSLv Zheng 	*new_val = NULL;
22183b80bacSLv Zheng 	return (AE_OK);
22283b80bacSLv Zheng }
22383b80bacSLv Zheng 
22483b80bacSLv Zheng /******************************************************************************
22583b80bacSLv Zheng  *
22683b80bacSLv Zheng  * FUNCTION:    acpi_os_table_override
22783b80bacSLv Zheng  *
22883b80bacSLv Zheng  * PARAMETERS:  existing_table      - Header of current table (probably
22983b80bacSLv Zheng  *                                    firmware)
23083b80bacSLv Zheng  *              new_table           - Where an entire new table is returned.
23183b80bacSLv Zheng  *
23283b80bacSLv Zheng  * RETURN:      Status, pointer to new table. Null pointer returned if no
23383b80bacSLv Zheng  *              table is available to override
23483b80bacSLv Zheng  *
23583b80bacSLv Zheng  * DESCRIPTION: Return a different version of a table if one is available
23683b80bacSLv Zheng  *
23783b80bacSLv Zheng  *****************************************************************************/
23883b80bacSLv Zheng 
23983b80bacSLv Zheng acpi_status
acpi_os_table_override(struct acpi_table_header * existing_table,struct acpi_table_header ** new_table)24083b80bacSLv Zheng acpi_os_table_override(struct acpi_table_header *existing_table,
24183b80bacSLv Zheng 		       struct acpi_table_header **new_table)
24283b80bacSLv Zheng {
24383b80bacSLv Zheng 
24483b80bacSLv Zheng 	if (!existing_table || !new_table) {
24583b80bacSLv Zheng 		return (AE_BAD_PARAMETER);
24683b80bacSLv Zheng 	}
24783b80bacSLv Zheng 
24883b80bacSLv Zheng 	*new_table = NULL;
24983b80bacSLv Zheng 
25083b80bacSLv Zheng #ifdef ACPI_EXEC_APP
25183b80bacSLv Zheng 
25283b80bacSLv Zheng 	ae_table_override(existing_table, new_table);
25383b80bacSLv Zheng 	return (AE_OK);
25483b80bacSLv Zheng #else
25583b80bacSLv Zheng 
25683b80bacSLv Zheng 	return (AE_NO_ACPI_TABLES);
25783b80bacSLv Zheng #endif
25883b80bacSLv Zheng }
25983b80bacSLv Zheng 
26083b80bacSLv Zheng /******************************************************************************
26183b80bacSLv Zheng  *
26283b80bacSLv Zheng  * FUNCTION:    acpi_os_physical_table_override
26383b80bacSLv Zheng  *
26483b80bacSLv Zheng  * PARAMETERS:  existing_table      - Header of current table (probably firmware)
26583b80bacSLv Zheng  *              new_address         - Where new table address is returned
26683b80bacSLv Zheng  *                                    (Physical address)
26783b80bacSLv Zheng  *              new_table_length    - Where new table length is returned
26883b80bacSLv Zheng  *
26983b80bacSLv Zheng  * RETURN:      Status, address/length of new table. Null pointer returned
27083b80bacSLv Zheng  *              if no table is available to override.
27183b80bacSLv Zheng  *
27283b80bacSLv Zheng  * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
27383b80bacSLv Zheng  *
27483b80bacSLv Zheng  *****************************************************************************/
27583b80bacSLv Zheng 
27683b80bacSLv Zheng acpi_status
acpi_os_physical_table_override(struct acpi_table_header * existing_table,acpi_physical_address * new_address,u32 * new_table_length)27783b80bacSLv Zheng acpi_os_physical_table_override(struct acpi_table_header *existing_table,
27883b80bacSLv Zheng 				acpi_physical_address *new_address,
27983b80bacSLv Zheng 				u32 *new_table_length)
28083b80bacSLv Zheng {
28183b80bacSLv Zheng 
28283b80bacSLv Zheng 	return (AE_SUPPORT);
28383b80bacSLv Zheng }
28483b80bacSLv Zheng 
28583b80bacSLv Zheng /******************************************************************************
28683b80bacSLv Zheng  *
2870fc5e8f4SLv Zheng  * FUNCTION:    acpi_os_enter_sleep
2880fc5e8f4SLv Zheng  *
2890fc5e8f4SLv Zheng  * PARAMETERS:  sleep_state         - Which sleep state to enter
2900fc5e8f4SLv Zheng  *              rega_value          - Register A value
2910fc5e8f4SLv Zheng  *              regb_value          - Register B value
2920fc5e8f4SLv Zheng  *
2930fc5e8f4SLv Zheng  * RETURN:      Status
2940fc5e8f4SLv Zheng  *
2950fc5e8f4SLv Zheng  * DESCRIPTION: A hook before writing sleep registers to enter the sleep
2960fc5e8f4SLv Zheng  *              state. Return AE_CTRL_TERMINATE to skip further sleep register
2970fc5e8f4SLv Zheng  *              writes.
2980fc5e8f4SLv Zheng  *
2990fc5e8f4SLv Zheng  *****************************************************************************/
3000fc5e8f4SLv Zheng 
acpi_os_enter_sleep(u8 sleep_state,u32 rega_value,u32 regb_value)3010fc5e8f4SLv Zheng acpi_status acpi_os_enter_sleep(u8 sleep_state, u32 rega_value, u32 regb_value)
3020fc5e8f4SLv Zheng {
3030fc5e8f4SLv Zheng 
3040fc5e8f4SLv Zheng 	return (AE_OK);
3050fc5e8f4SLv Zheng }
3060fc5e8f4SLv Zheng 
3070fc5e8f4SLv Zheng /******************************************************************************
3080fc5e8f4SLv Zheng  *
30983b80bacSLv Zheng  * FUNCTION:    acpi_os_redirect_output
31083b80bacSLv Zheng  *
31183b80bacSLv Zheng  * PARAMETERS:  destination         - An open file handle/pointer
31283b80bacSLv Zheng  *
31383b80bacSLv Zheng  * RETURN:      None
31483b80bacSLv Zheng  *
31583b80bacSLv Zheng  * DESCRIPTION: Causes redirect of acpi_os_printf and acpi_os_vprintf
31683b80bacSLv Zheng  *
31783b80bacSLv Zheng  *****************************************************************************/
31883b80bacSLv Zheng 
acpi_os_redirect_output(void * destination)31983b80bacSLv Zheng void acpi_os_redirect_output(void *destination)
32083b80bacSLv Zheng {
32183b80bacSLv Zheng 
32283b80bacSLv Zheng 	acpi_gbl_output_file = destination;
32383b80bacSLv Zheng }
32483b80bacSLv Zheng 
32583b80bacSLv Zheng /******************************************************************************
32683b80bacSLv Zheng  *
32783b80bacSLv Zheng  * FUNCTION:    acpi_os_printf
32883b80bacSLv Zheng  *
32983b80bacSLv Zheng  * PARAMETERS:  fmt, ...            - Standard printf format
33083b80bacSLv Zheng  *
33183b80bacSLv Zheng  * RETURN:      None
33283b80bacSLv Zheng  *
33383b80bacSLv Zheng  * DESCRIPTION: Formatted output. Note: very similar to acpi_os_vprintf
33483b80bacSLv Zheng  *              (performance), changes should be tracked in both functions.
33583b80bacSLv Zheng  *
33683b80bacSLv Zheng  *****************************************************************************/
33783b80bacSLv Zheng 
acpi_os_printf(const char * fmt,...)33883b80bacSLv Zheng void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...)
33983b80bacSLv Zheng {
34083b80bacSLv Zheng 	va_list args;
34183b80bacSLv Zheng 	u8 flags;
34283b80bacSLv Zheng 
34383b80bacSLv Zheng 	flags = acpi_gbl_db_output_flags;
34483b80bacSLv Zheng 	if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
34583b80bacSLv Zheng 
34683b80bacSLv Zheng 		/* Output is directable to either a file (if open) or the console */
34783b80bacSLv Zheng 
34883b80bacSLv Zheng 		if (acpi_gbl_debug_file) {
34983b80bacSLv Zheng 
35083b80bacSLv Zheng 			/* Output file is open, send the output there */
35183b80bacSLv Zheng 
35283b80bacSLv Zheng 			va_start(args, fmt);
35383b80bacSLv Zheng 			vfprintf(acpi_gbl_debug_file, fmt, args);
35483b80bacSLv Zheng 			va_end(args);
35583b80bacSLv Zheng 		} else {
35683b80bacSLv Zheng 			/* No redirection, send output to console (once only!) */
35783b80bacSLv Zheng 
35883b80bacSLv Zheng 			flags |= ACPI_DB_CONSOLE_OUTPUT;
35983b80bacSLv Zheng 		}
36083b80bacSLv Zheng 	}
36183b80bacSLv Zheng 
36283b80bacSLv Zheng 	if (flags & ACPI_DB_CONSOLE_OUTPUT) {
36383b80bacSLv Zheng 		va_start(args, fmt);
36483b80bacSLv Zheng 		vfprintf(acpi_gbl_output_file, fmt, args);
36583b80bacSLv Zheng 		va_end(args);
36683b80bacSLv Zheng 	}
36783b80bacSLv Zheng }
36883b80bacSLv Zheng 
36983b80bacSLv Zheng /******************************************************************************
37083b80bacSLv Zheng  *
37183b80bacSLv Zheng  * FUNCTION:    acpi_os_vprintf
37283b80bacSLv Zheng  *
37383b80bacSLv Zheng  * PARAMETERS:  fmt                 - Standard printf format
37483b80bacSLv Zheng  *              args                - Argument list
37583b80bacSLv Zheng  *
37683b80bacSLv Zheng  * RETURN:      None
37783b80bacSLv Zheng  *
37883b80bacSLv Zheng  * DESCRIPTION: Formatted output with argument list pointer. Note: very
37983b80bacSLv Zheng  *              similar to acpi_os_printf, changes should be tracked in both
38083b80bacSLv Zheng  *              functions.
38183b80bacSLv Zheng  *
38283b80bacSLv Zheng  *****************************************************************************/
38383b80bacSLv Zheng 
acpi_os_vprintf(const char * fmt,va_list args)38483b80bacSLv Zheng void acpi_os_vprintf(const char *fmt, va_list args)
38583b80bacSLv Zheng {
38683b80bacSLv Zheng 	u8 flags;
38783b80bacSLv Zheng 	char buffer[ACPI_VPRINTF_BUFFER_SIZE];
38883b80bacSLv Zheng 
38983b80bacSLv Zheng 	/*
39083b80bacSLv Zheng 	 * We build the output string in a local buffer because we may be
39183b80bacSLv Zheng 	 * outputting the buffer twice. Using vfprintf is problematic because
39283b80bacSLv Zheng 	 * some implementations modify the args pointer/structure during
39383b80bacSLv Zheng 	 * execution. Thus, we use the local buffer for portability.
39483b80bacSLv Zheng 	 *
39583b80bacSLv Zheng 	 * Note: Since this module is intended for use by the various ACPICA
39683b80bacSLv Zheng 	 * utilities/applications, we can safely declare the buffer on the stack.
39783b80bacSLv Zheng 	 * Also, This function is used for relatively small error messages only.
39883b80bacSLv Zheng 	 */
39983b80bacSLv Zheng 	vsnprintf(buffer, ACPI_VPRINTF_BUFFER_SIZE, fmt, args);
40083b80bacSLv Zheng 
40183b80bacSLv Zheng 	flags = acpi_gbl_db_output_flags;
40283b80bacSLv Zheng 	if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
40383b80bacSLv Zheng 
40483b80bacSLv Zheng 		/* Output is directable to either a file (if open) or the console */
40583b80bacSLv Zheng 
40683b80bacSLv Zheng 		if (acpi_gbl_debug_file) {
40783b80bacSLv Zheng 
40883b80bacSLv Zheng 			/* Output file is open, send the output there */
40983b80bacSLv Zheng 
41083b80bacSLv Zheng 			fputs(buffer, acpi_gbl_debug_file);
41183b80bacSLv Zheng 		} else {
41283b80bacSLv Zheng 			/* No redirection, send output to console (once only!) */
41383b80bacSLv Zheng 
41483b80bacSLv Zheng 			flags |= ACPI_DB_CONSOLE_OUTPUT;
41583b80bacSLv Zheng 		}
41683b80bacSLv Zheng 	}
41783b80bacSLv Zheng 
41883b80bacSLv Zheng 	if (flags & ACPI_DB_CONSOLE_OUTPUT) {
41983b80bacSLv Zheng 		fputs(buffer, acpi_gbl_output_file);
42083b80bacSLv Zheng 	}
42183b80bacSLv Zheng }
42283b80bacSLv Zheng 
42383b80bacSLv Zheng #ifndef ACPI_EXEC_APP
42483b80bacSLv Zheng /******************************************************************************
42583b80bacSLv Zheng  *
42683b80bacSLv Zheng  * FUNCTION:    acpi_os_get_line
42783b80bacSLv Zheng  *
42883b80bacSLv Zheng  * PARAMETERS:  buffer              - Where to return the command line
42983b80bacSLv Zheng  *              buffer_length       - Maximum length of Buffer
43083b80bacSLv Zheng  *              bytes_read          - Where the actual byte count is returned
43183b80bacSLv Zheng  *
43283b80bacSLv Zheng  * RETURN:      Status and actual bytes read
43383b80bacSLv Zheng  *
43483b80bacSLv Zheng  * DESCRIPTION: Get the next input line from the terminal. NOTE: For the
43583b80bacSLv Zheng  *              acpi_exec utility, we use the acgetline module instead to
43683b80bacSLv Zheng  *              provide line-editing and history support.
43783b80bacSLv Zheng  *
43883b80bacSLv Zheng  *****************************************************************************/
43983b80bacSLv Zheng 
acpi_os_get_line(char * buffer,u32 buffer_length,u32 * bytes_read)44083b80bacSLv Zheng acpi_status acpi_os_get_line(char *buffer, u32 buffer_length, u32 *bytes_read)
44183b80bacSLv Zheng {
44283b80bacSLv Zheng 	int input_char;
44383b80bacSLv Zheng 	u32 end_of_line;
44483b80bacSLv Zheng 
44583b80bacSLv Zheng 	/* Standard acpi_os_get_line for all utilities except acpi_exec */
44683b80bacSLv Zheng 
44783b80bacSLv Zheng 	for (end_of_line = 0;; end_of_line++) {
44883b80bacSLv Zheng 		if (end_of_line >= buffer_length) {
44983b80bacSLv Zheng 			return (AE_BUFFER_OVERFLOW);
45083b80bacSLv Zheng 		}
45183b80bacSLv Zheng 
45283b80bacSLv Zheng 		if ((input_char = getchar()) == EOF) {
45383b80bacSLv Zheng 			return (AE_ERROR);
45483b80bacSLv Zheng 		}
45583b80bacSLv Zheng 
45683b80bacSLv Zheng 		if (!input_char || input_char == _ASCII_NEWLINE) {
45783b80bacSLv Zheng 			break;
45883b80bacSLv Zheng 		}
45983b80bacSLv Zheng 
46083b80bacSLv Zheng 		buffer[end_of_line] = (char)input_char;
46183b80bacSLv Zheng 	}
46283b80bacSLv Zheng 
46383b80bacSLv Zheng 	/* Null terminate the buffer */
46483b80bacSLv Zheng 
46583b80bacSLv Zheng 	buffer[end_of_line] = 0;
46683b80bacSLv Zheng 
46783b80bacSLv Zheng 	/* Return the number of bytes in the string */
46883b80bacSLv Zheng 
46983b80bacSLv Zheng 	if (bytes_read) {
47083b80bacSLv Zheng 		*bytes_read = end_of_line;
47183b80bacSLv Zheng 	}
47283b80bacSLv Zheng 
47383b80bacSLv Zheng 	return (AE_OK);
47483b80bacSLv Zheng }
47583b80bacSLv Zheng #endif
47683b80bacSLv Zheng 
47783b80bacSLv Zheng #ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
47883b80bacSLv Zheng /******************************************************************************
47983b80bacSLv Zheng  *
48083b80bacSLv Zheng  * FUNCTION:    acpi_os_map_memory
48183b80bacSLv Zheng  *
48283b80bacSLv Zheng  * PARAMETERS:  where               - Physical address of memory to be mapped
48383b80bacSLv Zheng  *              length              - How much memory to map
48483b80bacSLv Zheng  *
48583b80bacSLv Zheng  * RETURN:      Pointer to mapped memory. Null on error.
48683b80bacSLv Zheng  *
48783b80bacSLv Zheng  * DESCRIPTION: Map physical memory into caller's address space
48883b80bacSLv Zheng  *
48983b80bacSLv Zheng  *****************************************************************************/
49083b80bacSLv Zheng 
acpi_os_map_memory(acpi_physical_address where,acpi_size length)49183b80bacSLv Zheng void *acpi_os_map_memory(acpi_physical_address where, acpi_size length)
49283b80bacSLv Zheng {
49383b80bacSLv Zheng 
49483b80bacSLv Zheng 	return (ACPI_TO_POINTER((acpi_size)where));
49583b80bacSLv Zheng }
49683b80bacSLv Zheng 
49783b80bacSLv Zheng /******************************************************************************
49883b80bacSLv Zheng  *
49983b80bacSLv Zheng  * FUNCTION:    acpi_os_unmap_memory
50083b80bacSLv Zheng  *
50183b80bacSLv Zheng  * PARAMETERS:  where               - Logical address of memory to be unmapped
50283b80bacSLv Zheng  *              length              - How much memory to unmap
50383b80bacSLv Zheng  *
50483b80bacSLv Zheng  * RETURN:      None.
50583b80bacSLv Zheng  *
50683b80bacSLv Zheng  * DESCRIPTION: Delete a previously created mapping. Where and Length must
50783b80bacSLv Zheng  *              correspond to a previous mapping exactly.
50883b80bacSLv Zheng  *
50983b80bacSLv Zheng  *****************************************************************************/
51083b80bacSLv Zheng 
acpi_os_unmap_memory(void * where,acpi_size length)51183b80bacSLv Zheng void acpi_os_unmap_memory(void *where, acpi_size length)
51283b80bacSLv Zheng {
51383b80bacSLv Zheng 
51483b80bacSLv Zheng 	return;
51583b80bacSLv Zheng }
51683b80bacSLv Zheng #endif
51783b80bacSLv Zheng 
51883b80bacSLv Zheng /******************************************************************************
51983b80bacSLv Zheng  *
52083b80bacSLv Zheng  * FUNCTION:    acpi_os_allocate
52183b80bacSLv Zheng  *
52283b80bacSLv Zheng  * PARAMETERS:  size                - Amount to allocate, in bytes
52383b80bacSLv Zheng  *
52483b80bacSLv Zheng  * RETURN:      Pointer to the new allocation. Null on error.
52583b80bacSLv Zheng  *
52683b80bacSLv Zheng  * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
52783b80bacSLv Zheng  *
52883b80bacSLv Zheng  *****************************************************************************/
52983b80bacSLv Zheng 
acpi_os_allocate(acpi_size size)53083b80bacSLv Zheng void *acpi_os_allocate(acpi_size size)
53183b80bacSLv Zheng {
53283b80bacSLv Zheng 	void *mem;
53383b80bacSLv Zheng 
53483b80bacSLv Zheng 	mem = (void *)malloc((size_t) size);
53583b80bacSLv Zheng 	return (mem);
53683b80bacSLv Zheng }
53783b80bacSLv Zheng 
53883b80bacSLv Zheng #ifdef USE_NATIVE_ALLOCATE_ZEROED
53983b80bacSLv Zheng /******************************************************************************
54083b80bacSLv Zheng  *
54183b80bacSLv Zheng  * FUNCTION:    acpi_os_allocate_zeroed
54283b80bacSLv Zheng  *
54383b80bacSLv Zheng  * PARAMETERS:  size                - Amount to allocate, in bytes
54483b80bacSLv Zheng  *
54583b80bacSLv Zheng  * RETURN:      Pointer to the new allocation. Null on error.
54683b80bacSLv Zheng  *
54783b80bacSLv Zheng  * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
54883b80bacSLv Zheng  *
54983b80bacSLv Zheng  *****************************************************************************/
55083b80bacSLv Zheng 
acpi_os_allocate_zeroed(acpi_size size)55183b80bacSLv Zheng void *acpi_os_allocate_zeroed(acpi_size size)
55283b80bacSLv Zheng {
55383b80bacSLv Zheng 	void *mem;
55483b80bacSLv Zheng 
55583b80bacSLv Zheng 	mem = (void *)calloc(1, (size_t) size);
55683b80bacSLv Zheng 	return (mem);
55783b80bacSLv Zheng }
55883b80bacSLv Zheng #endif
55983b80bacSLv Zheng 
56083b80bacSLv Zheng /******************************************************************************
56183b80bacSLv Zheng  *
56283b80bacSLv Zheng  * FUNCTION:    acpi_os_free
56383b80bacSLv Zheng  *
56483b80bacSLv Zheng  * PARAMETERS:  mem                 - Pointer to previously allocated memory
56583b80bacSLv Zheng  *
56683b80bacSLv Zheng  * RETURN:      None.
56783b80bacSLv Zheng  *
56883b80bacSLv Zheng  * DESCRIPTION: Free memory allocated via acpi_os_allocate
56983b80bacSLv Zheng  *
57083b80bacSLv Zheng  *****************************************************************************/
57183b80bacSLv Zheng 
acpi_os_free(void * mem)57283b80bacSLv Zheng void acpi_os_free(void *mem)
57383b80bacSLv Zheng {
57483b80bacSLv Zheng 
57583b80bacSLv Zheng 	free(mem);
57683b80bacSLv Zheng }
57783b80bacSLv Zheng 
57883b80bacSLv Zheng #ifdef ACPI_SINGLE_THREADED
57983b80bacSLv Zheng /******************************************************************************
58083b80bacSLv Zheng  *
58183b80bacSLv Zheng  * FUNCTION:    Semaphore stub functions
58283b80bacSLv Zheng  *
58383b80bacSLv Zheng  * DESCRIPTION: Stub functions used for single-thread applications that do
58483b80bacSLv Zheng  *              not require semaphore synchronization. Full implementations
58583b80bacSLv Zheng  *              of these functions appear after the stubs.
58683b80bacSLv Zheng  *
58783b80bacSLv Zheng  *****************************************************************************/
58883b80bacSLv Zheng 
58983b80bacSLv Zheng acpi_status
acpi_os_create_semaphore(u32 max_units,u32 initial_units,acpi_handle * out_handle)59083b80bacSLv Zheng acpi_os_create_semaphore(u32 max_units,
59183b80bacSLv Zheng 			 u32 initial_units, acpi_handle *out_handle)
59283b80bacSLv Zheng {
59383b80bacSLv Zheng 	*out_handle = (acpi_handle)1;
59483b80bacSLv Zheng 	return (AE_OK);
59583b80bacSLv Zheng }
59683b80bacSLv Zheng 
acpi_os_delete_semaphore(acpi_handle handle)59783b80bacSLv Zheng acpi_status acpi_os_delete_semaphore(acpi_handle handle)
59883b80bacSLv Zheng {
59983b80bacSLv Zheng 	return (AE_OK);
60083b80bacSLv Zheng }
60183b80bacSLv Zheng 
acpi_os_wait_semaphore(acpi_handle handle,u32 units,u16 timeout)60283b80bacSLv Zheng acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
60383b80bacSLv Zheng {
60483b80bacSLv Zheng 	return (AE_OK);
60583b80bacSLv Zheng }
60683b80bacSLv Zheng 
acpi_os_signal_semaphore(acpi_handle handle,u32 units)60783b80bacSLv Zheng acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
60883b80bacSLv Zheng {
60983b80bacSLv Zheng 	return (AE_OK);
61083b80bacSLv Zheng }
61183b80bacSLv Zheng 
61283b80bacSLv Zheng #else
61383b80bacSLv Zheng /******************************************************************************
61483b80bacSLv Zheng  *
61583b80bacSLv Zheng  * FUNCTION:    acpi_os_create_semaphore
61683b80bacSLv Zheng  *
61783b80bacSLv Zheng  * PARAMETERS:  initial_units       - Units to be assigned to the new semaphore
61883b80bacSLv Zheng  *              out_handle          - Where a handle will be returned
61983b80bacSLv Zheng  *
62083b80bacSLv Zheng  * RETURN:      Status
62183b80bacSLv Zheng  *
62283b80bacSLv Zheng  * DESCRIPTION: Create an OS semaphore
62383b80bacSLv Zheng  *
62483b80bacSLv Zheng  *****************************************************************************/
62583b80bacSLv Zheng 
62683b80bacSLv Zheng acpi_status
acpi_os_create_semaphore(u32 max_units,u32 initial_units,acpi_handle * out_handle)62783b80bacSLv Zheng acpi_os_create_semaphore(u32 max_units,
62883b80bacSLv Zheng 			 u32 initial_units, acpi_handle *out_handle)
62983b80bacSLv Zheng {
63083b80bacSLv Zheng 	sem_t *sem;
63183b80bacSLv Zheng 
63283b80bacSLv Zheng 	if (!out_handle) {
63383b80bacSLv Zheng 		return (AE_BAD_PARAMETER);
63483b80bacSLv Zheng 	}
63583b80bacSLv Zheng #ifdef __APPLE__
63683b80bacSLv Zheng 	{
6376c9fd7edSLv Zheng 		static int semaphore_count = 0;
6386c9fd7edSLv Zheng 		char semaphore_name[32];
63983b80bacSLv Zheng 
6406c9fd7edSLv Zheng 		snprintf(semaphore_name, sizeof(semaphore_name), "acpi_sem_%d",
6416c9fd7edSLv Zheng 			 semaphore_count++);
6426c9fd7edSLv Zheng 		printf("%s\n", semaphore_name);
64383b80bacSLv Zheng 		sem =
64483b80bacSLv Zheng 		    sem_open(semaphore_name, O_EXCL | O_CREAT, 0755,
64583b80bacSLv Zheng 			     initial_units);
64683b80bacSLv Zheng 		if (!sem) {
64783b80bacSLv Zheng 			return (AE_NO_MEMORY);
64883b80bacSLv Zheng 		}
64983b80bacSLv Zheng 		sem_unlink(semaphore_name);	/* This just deletes the name */
65083b80bacSLv Zheng 	}
65183b80bacSLv Zheng 
65283b80bacSLv Zheng #else
65383b80bacSLv Zheng 	sem = acpi_os_allocate(sizeof(sem_t));
65483b80bacSLv Zheng 	if (!sem) {
65583b80bacSLv Zheng 		return (AE_NO_MEMORY);
65683b80bacSLv Zheng 	}
65783b80bacSLv Zheng 
65883b80bacSLv Zheng 	if (sem_init(sem, 0, initial_units) == -1) {
65983b80bacSLv Zheng 		acpi_os_free(sem);
66083b80bacSLv Zheng 		return (AE_BAD_PARAMETER);
66183b80bacSLv Zheng 	}
66283b80bacSLv Zheng #endif
66383b80bacSLv Zheng 
66483b80bacSLv Zheng 	*out_handle = (acpi_handle)sem;
66583b80bacSLv Zheng 	return (AE_OK);
66683b80bacSLv Zheng }
66783b80bacSLv Zheng 
66883b80bacSLv Zheng /******************************************************************************
66983b80bacSLv Zheng  *
67083b80bacSLv Zheng  * FUNCTION:    acpi_os_delete_semaphore
67183b80bacSLv Zheng  *
67283b80bacSLv Zheng  * PARAMETERS:  handle              - Handle returned by acpi_os_create_semaphore
67383b80bacSLv Zheng  *
67483b80bacSLv Zheng  * RETURN:      Status
67583b80bacSLv Zheng  *
67683b80bacSLv Zheng  * DESCRIPTION: Delete an OS semaphore
67783b80bacSLv Zheng  *
67883b80bacSLv Zheng  *****************************************************************************/
67983b80bacSLv Zheng 
acpi_os_delete_semaphore(acpi_handle handle)68083b80bacSLv Zheng acpi_status acpi_os_delete_semaphore(acpi_handle handle)
68183b80bacSLv Zheng {
68283b80bacSLv Zheng 	sem_t *sem = (sem_t *) handle;
68383b80bacSLv Zheng 
68483b80bacSLv Zheng 	if (!sem) {
68583b80bacSLv Zheng 		return (AE_BAD_PARAMETER);
68683b80bacSLv Zheng 	}
687b97acdf1SLv Zheng #ifdef __APPLE__
688b97acdf1SLv Zheng 	if (sem_close(sem) == -1) {
689b97acdf1SLv Zheng 		return (AE_BAD_PARAMETER);
690b97acdf1SLv Zheng 	}
691b97acdf1SLv Zheng #else
69283b80bacSLv Zheng 	if (sem_destroy(sem) == -1) {
69383b80bacSLv Zheng 		return (AE_BAD_PARAMETER);
69483b80bacSLv Zheng 	}
695b97acdf1SLv Zheng #endif
69683b80bacSLv Zheng 
69783b80bacSLv Zheng 	return (AE_OK);
69883b80bacSLv Zheng }
69983b80bacSLv Zheng 
70083b80bacSLv Zheng /******************************************************************************
70183b80bacSLv Zheng  *
70283b80bacSLv Zheng  * FUNCTION:    acpi_os_wait_semaphore
70383b80bacSLv Zheng  *
70483b80bacSLv Zheng  * PARAMETERS:  handle              - Handle returned by acpi_os_create_semaphore
70583b80bacSLv Zheng  *              units               - How many units to wait for
70683b80bacSLv Zheng  *              msec_timeout        - How long to wait (milliseconds)
70783b80bacSLv Zheng  *
70883b80bacSLv Zheng  * RETURN:      Status
70983b80bacSLv Zheng  *
71083b80bacSLv Zheng  * DESCRIPTION: Wait for units
71183b80bacSLv Zheng  *
71283b80bacSLv Zheng  *****************************************************************************/
71383b80bacSLv Zheng 
71483b80bacSLv Zheng acpi_status
acpi_os_wait_semaphore(acpi_handle handle,u32 units,u16 msec_timeout)71583b80bacSLv Zheng acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 msec_timeout)
71683b80bacSLv Zheng {
71783b80bacSLv Zheng 	acpi_status status = AE_OK;
71883b80bacSLv Zheng 	sem_t *sem = (sem_t *) handle;
719fdf8707bSBob Moore 	int ret_val;
72083b80bacSLv Zheng #ifndef ACPI_USE_ALTERNATE_TIMEOUT
72183b80bacSLv Zheng 	struct timespec time;
72283b80bacSLv Zheng #endif
72383b80bacSLv Zheng 
72483b80bacSLv Zheng 	if (!sem) {
72583b80bacSLv Zheng 		return (AE_BAD_PARAMETER);
72683b80bacSLv Zheng 	}
72783b80bacSLv Zheng 
72883b80bacSLv Zheng 	switch (msec_timeout) {
72983b80bacSLv Zheng 		/*
73083b80bacSLv Zheng 		 * No Wait:
73183b80bacSLv Zheng 		 * --------
73283b80bacSLv Zheng 		 * A zero timeout value indicates that we shouldn't wait - just
73383b80bacSLv Zheng 		 * acquire the semaphore if available otherwise return AE_TIME
73483b80bacSLv Zheng 		 * (a.k.a. 'would block').
73583b80bacSLv Zheng 		 */
73683b80bacSLv Zheng 	case 0:
73783b80bacSLv Zheng 
73883b80bacSLv Zheng 		if (sem_trywait(sem) == -1) {
73983b80bacSLv Zheng 			status = (AE_TIME);
74083b80bacSLv Zheng 		}
74183b80bacSLv Zheng 		break;
74283b80bacSLv Zheng 
74383b80bacSLv Zheng 		/* Wait Indefinitely */
74483b80bacSLv Zheng 
74583b80bacSLv Zheng 	case ACPI_WAIT_FOREVER:
74683b80bacSLv Zheng 
747fdf8707bSBob Moore 		while (((ret_val = sem_wait(sem)) == -1) && (errno == EINTR)) {
748fdf8707bSBob Moore 			continue;	/* Restart if interrupted */
749fdf8707bSBob Moore 		}
750fdf8707bSBob Moore 		if (ret_val != 0) {
75183b80bacSLv Zheng 			status = (AE_TIME);
75283b80bacSLv Zheng 		}
75383b80bacSLv Zheng 		break;
75483b80bacSLv Zheng 
75583b80bacSLv Zheng 		/* Wait with msec_timeout */
75683b80bacSLv Zheng 
75783b80bacSLv Zheng 	default:
75883b80bacSLv Zheng 
75983b80bacSLv Zheng #ifdef ACPI_USE_ALTERNATE_TIMEOUT
76083b80bacSLv Zheng 		/*
76183b80bacSLv Zheng 		 * Alternate timeout mechanism for environments where
76283b80bacSLv Zheng 		 * sem_timedwait is not available or does not work properly.
76383b80bacSLv Zheng 		 */
76483b80bacSLv Zheng 		while (msec_timeout) {
76583b80bacSLv Zheng 			if (sem_trywait(sem) == 0) {
76683b80bacSLv Zheng 
76783b80bacSLv Zheng 				/* Got the semaphore */
76883b80bacSLv Zheng 				return (AE_OK);
76983b80bacSLv Zheng 			}
77083b80bacSLv Zheng 
77183b80bacSLv Zheng 			if (msec_timeout >= 10) {
77283b80bacSLv Zheng 				msec_timeout -= 10;
77383b80bacSLv Zheng 				usleep(10 * ACPI_USEC_PER_MSEC);	/* ten milliseconds */
77483b80bacSLv Zheng 			} else {
77583b80bacSLv Zheng 				msec_timeout--;
77683b80bacSLv Zheng 				usleep(ACPI_USEC_PER_MSEC);	/* one millisecond */
77783b80bacSLv Zheng 			}
77883b80bacSLv Zheng 		}
77983b80bacSLv Zheng 		status = (AE_TIME);
78083b80bacSLv Zheng #else
78183b80bacSLv Zheng 		/*
78283b80bacSLv Zheng 		 * The interface to sem_timedwait is an absolute time, so we need to
78383b80bacSLv Zheng 		 * get the current time, then add in the millisecond Timeout value.
78483b80bacSLv Zheng 		 */
78583b80bacSLv Zheng 		if (clock_gettime(CLOCK_REALTIME, &time) == -1) {
78683b80bacSLv Zheng 			perror("clock_gettime");
78783b80bacSLv Zheng 			return (AE_TIME);
78883b80bacSLv Zheng 		}
78983b80bacSLv Zheng 
79083b80bacSLv Zheng 		time.tv_sec += (msec_timeout / ACPI_MSEC_PER_SEC);
79183b80bacSLv Zheng 		time.tv_nsec +=
79283b80bacSLv Zheng 		    ((msec_timeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC);
79383b80bacSLv Zheng 
79483b80bacSLv Zheng 		/* Handle nanosecond overflow (field must be less than one second) */
79583b80bacSLv Zheng 
79683b80bacSLv Zheng 		if (time.tv_nsec >= ACPI_NSEC_PER_SEC) {
79783b80bacSLv Zheng 			time.tv_sec += (time.tv_nsec / ACPI_NSEC_PER_SEC);
79883b80bacSLv Zheng 			time.tv_nsec = (time.tv_nsec % ACPI_NSEC_PER_SEC);
79983b80bacSLv Zheng 		}
80083b80bacSLv Zheng 
80183b80bacSLv Zheng 		while (((ret_val = sem_timedwait(sem, &time)) == -1)
80283b80bacSLv Zheng 		       && (errno == EINTR)) {
803fdf8707bSBob Moore 			continue;	/* Restart if interrupted */
804fdf8707bSBob Moore 
80583b80bacSLv Zheng 		}
80683b80bacSLv Zheng 
80783b80bacSLv Zheng 		if (ret_val != 0) {
80883b80bacSLv Zheng 			if (errno != ETIMEDOUT) {
80983b80bacSLv Zheng 				perror("sem_timedwait");
81083b80bacSLv Zheng 			}
81183b80bacSLv Zheng 			status = (AE_TIME);
81283b80bacSLv Zheng 		}
81383b80bacSLv Zheng #endif
81483b80bacSLv Zheng 		break;
81583b80bacSLv Zheng 	}
81683b80bacSLv Zheng 
81783b80bacSLv Zheng 	return (status);
81883b80bacSLv Zheng }
81983b80bacSLv Zheng 
82083b80bacSLv Zheng /******************************************************************************
82183b80bacSLv Zheng  *
82283b80bacSLv Zheng  * FUNCTION:    acpi_os_signal_semaphore
82383b80bacSLv Zheng  *
82483b80bacSLv Zheng  * PARAMETERS:  handle              - Handle returned by acpi_os_create_semaphore
82583b80bacSLv Zheng  *              units               - Number of units to send
82683b80bacSLv Zheng  *
82783b80bacSLv Zheng  * RETURN:      Status
82883b80bacSLv Zheng  *
82983b80bacSLv Zheng  * DESCRIPTION: Send units
83083b80bacSLv Zheng  *
83183b80bacSLv Zheng  *****************************************************************************/
83283b80bacSLv Zheng 
acpi_os_signal_semaphore(acpi_handle handle,u32 units)83383b80bacSLv Zheng acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
83483b80bacSLv Zheng {
83583b80bacSLv Zheng 	sem_t *sem = (sem_t *) handle;
83683b80bacSLv Zheng 
83783b80bacSLv Zheng 	if (!sem) {
83883b80bacSLv Zheng 		return (AE_BAD_PARAMETER);
83983b80bacSLv Zheng 	}
84083b80bacSLv Zheng 
84183b80bacSLv Zheng 	if (sem_post(sem) == -1) {
84283b80bacSLv Zheng 		return (AE_LIMIT);
84383b80bacSLv Zheng 	}
84483b80bacSLv Zheng 
84583b80bacSLv Zheng 	return (AE_OK);
84683b80bacSLv Zheng }
84783b80bacSLv Zheng 
84883b80bacSLv Zheng #endif				/* ACPI_SINGLE_THREADED */
84983b80bacSLv Zheng 
85083b80bacSLv Zheng /******************************************************************************
85183b80bacSLv Zheng  *
85283b80bacSLv Zheng  * FUNCTION:    Spinlock interfaces
85383b80bacSLv Zheng  *
85483b80bacSLv Zheng  * DESCRIPTION: Map these interfaces to semaphore interfaces
85583b80bacSLv Zheng  *
85683b80bacSLv Zheng  *****************************************************************************/
85783b80bacSLv Zheng 
acpi_os_create_lock(acpi_spinlock * out_handle)85883b80bacSLv Zheng acpi_status acpi_os_create_lock(acpi_spinlock * out_handle)
85983b80bacSLv Zheng {
86083b80bacSLv Zheng 
86183b80bacSLv Zheng 	return (acpi_os_create_semaphore(1, 1, out_handle));
86283b80bacSLv Zheng }
86383b80bacSLv Zheng 
acpi_os_delete_lock(acpi_spinlock handle)86483b80bacSLv Zheng void acpi_os_delete_lock(acpi_spinlock handle)
86583b80bacSLv Zheng {
86683b80bacSLv Zheng 	acpi_os_delete_semaphore(handle);
86783b80bacSLv Zheng }
86883b80bacSLv Zheng 
acpi_os_acquire_lock(acpi_handle handle)86983b80bacSLv Zheng acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle)
87083b80bacSLv Zheng {
87183b80bacSLv Zheng 	acpi_os_wait_semaphore(handle, 1, 0xFFFF);
87283b80bacSLv Zheng 	return (0);
87383b80bacSLv Zheng }
87483b80bacSLv Zheng 
acpi_os_release_lock(acpi_spinlock handle,acpi_cpu_flags flags)87583b80bacSLv Zheng void acpi_os_release_lock(acpi_spinlock handle, acpi_cpu_flags flags)
87683b80bacSLv Zheng {
87783b80bacSLv Zheng 	acpi_os_signal_semaphore(handle, 1);
87883b80bacSLv Zheng }
87983b80bacSLv Zheng 
88083b80bacSLv Zheng /******************************************************************************
88183b80bacSLv Zheng  *
88283b80bacSLv Zheng  * FUNCTION:    acpi_os_install_interrupt_handler
88383b80bacSLv Zheng  *
88483b80bacSLv Zheng  * PARAMETERS:  interrupt_number    - Level handler should respond to.
88583b80bacSLv Zheng  *              isr                 - Address of the ACPI interrupt handler
88683b80bacSLv Zheng  *              except_ptr          - Where status is returned
88783b80bacSLv Zheng  *
88883b80bacSLv Zheng  * RETURN:      Handle to the newly installed handler.
88983b80bacSLv Zheng  *
89083b80bacSLv Zheng  * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
89183b80bacSLv Zheng  *              OS-independent handler.
89283b80bacSLv Zheng  *
89383b80bacSLv Zheng  *****************************************************************************/
89483b80bacSLv Zheng 
89583b80bacSLv Zheng u32
acpi_os_install_interrupt_handler(u32 interrupt_number,acpi_osd_handler service_routine,void * context)89683b80bacSLv Zheng acpi_os_install_interrupt_handler(u32 interrupt_number,
89783b80bacSLv Zheng 				  acpi_osd_handler service_routine,
89883b80bacSLv Zheng 				  void *context)
89983b80bacSLv Zheng {
90083b80bacSLv Zheng 
90183b80bacSLv Zheng 	return (AE_OK);
90283b80bacSLv Zheng }
90383b80bacSLv Zheng 
90483b80bacSLv Zheng /******************************************************************************
90583b80bacSLv Zheng  *
90683b80bacSLv Zheng  * FUNCTION:    acpi_os_remove_interrupt_handler
90783b80bacSLv Zheng  *
90883b80bacSLv Zheng  * PARAMETERS:  handle              - Returned when handler was installed
90983b80bacSLv Zheng  *
91083b80bacSLv Zheng  * RETURN:      Status
91183b80bacSLv Zheng  *
91283b80bacSLv Zheng  * DESCRIPTION: Uninstalls an interrupt handler.
91383b80bacSLv Zheng  *
91483b80bacSLv Zheng  *****************************************************************************/
91583b80bacSLv Zheng 
91683b80bacSLv Zheng acpi_status
acpi_os_remove_interrupt_handler(u32 interrupt_number,acpi_osd_handler service_routine)91783b80bacSLv Zheng acpi_os_remove_interrupt_handler(u32 interrupt_number,
91883b80bacSLv Zheng 				 acpi_osd_handler service_routine)
91983b80bacSLv Zheng {
92083b80bacSLv Zheng 
92183b80bacSLv Zheng 	return (AE_OK);
92283b80bacSLv Zheng }
92383b80bacSLv Zheng 
92483b80bacSLv Zheng /******************************************************************************
92583b80bacSLv Zheng  *
92683b80bacSLv Zheng  * FUNCTION:    acpi_os_stall
92783b80bacSLv Zheng  *
92883b80bacSLv Zheng  * PARAMETERS:  microseconds        - Time to sleep
92983b80bacSLv Zheng  *
93083b80bacSLv Zheng  * RETURN:      Blocks until sleep is completed.
93183b80bacSLv Zheng  *
93283b80bacSLv Zheng  * DESCRIPTION: Sleep at microsecond granularity
93383b80bacSLv Zheng  *
93483b80bacSLv Zheng  *****************************************************************************/
93583b80bacSLv Zheng 
acpi_os_stall(u32 microseconds)93683b80bacSLv Zheng void acpi_os_stall(u32 microseconds)
93783b80bacSLv Zheng {
93883b80bacSLv Zheng 
93983b80bacSLv Zheng 	if (microseconds) {
94083b80bacSLv Zheng 		usleep(microseconds);
94183b80bacSLv Zheng 	}
94283b80bacSLv Zheng }
94383b80bacSLv Zheng 
94483b80bacSLv Zheng /******************************************************************************
94583b80bacSLv Zheng  *
94683b80bacSLv Zheng  * FUNCTION:    acpi_os_sleep
94783b80bacSLv Zheng  *
94883b80bacSLv Zheng  * PARAMETERS:  milliseconds        - Time to sleep
94983b80bacSLv Zheng  *
95083b80bacSLv Zheng  * RETURN:      Blocks until sleep is completed.
95183b80bacSLv Zheng  *
95283b80bacSLv Zheng  * DESCRIPTION: Sleep at millisecond granularity
95383b80bacSLv Zheng  *
95483b80bacSLv Zheng  *****************************************************************************/
95583b80bacSLv Zheng 
acpi_os_sleep(u64 milliseconds)95683b80bacSLv Zheng void acpi_os_sleep(u64 milliseconds)
95783b80bacSLv Zheng {
95883b80bacSLv Zheng 
95983b80bacSLv Zheng 	/* Sleep for whole seconds */
96083b80bacSLv Zheng 
96183b80bacSLv Zheng 	sleep(milliseconds / ACPI_MSEC_PER_SEC);
96283b80bacSLv Zheng 
96383b80bacSLv Zheng 	/*
96483b80bacSLv Zheng 	 * Sleep for remaining microseconds.
96583b80bacSLv Zheng 	 * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second).
96683b80bacSLv Zheng 	 */
96783b80bacSLv Zheng 	usleep((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC);
96883b80bacSLv Zheng }
96983b80bacSLv Zheng 
97083b80bacSLv Zheng /******************************************************************************
97183b80bacSLv Zheng  *
97283b80bacSLv Zheng  * FUNCTION:    acpi_os_get_timer
97383b80bacSLv Zheng  *
97483b80bacSLv Zheng  * PARAMETERS:  None
97583b80bacSLv Zheng  *
97683b80bacSLv Zheng  * RETURN:      Current time in 100 nanosecond units
97783b80bacSLv Zheng  *
97883b80bacSLv Zheng  * DESCRIPTION: Get the current system time
97983b80bacSLv Zheng  *
98083b80bacSLv Zheng  *****************************************************************************/
98183b80bacSLv Zheng 
acpi_os_get_timer(void)98283b80bacSLv Zheng u64 acpi_os_get_timer(void)
98383b80bacSLv Zheng {
98483b80bacSLv Zheng 	struct timeval time;
98583b80bacSLv Zheng 
98683b80bacSLv Zheng 	/* This timer has sufficient resolution for user-space application code */
98783b80bacSLv Zheng 
98883b80bacSLv Zheng 	gettimeofday(&time, NULL);
98983b80bacSLv Zheng 
99083b80bacSLv Zheng 	/* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */
99183b80bacSLv Zheng 
99283b80bacSLv Zheng 	return (((u64)time.tv_sec * ACPI_100NSEC_PER_SEC) +
99383b80bacSLv Zheng 		((u64)time.tv_usec * ACPI_100NSEC_PER_USEC));
99483b80bacSLv Zheng }
99583b80bacSLv Zheng 
99683b80bacSLv Zheng /******************************************************************************
99783b80bacSLv Zheng  *
99883b80bacSLv Zheng  * FUNCTION:    acpi_os_read_pci_configuration
99983b80bacSLv Zheng  *
100083b80bacSLv Zheng  * PARAMETERS:  pci_id              - Seg/Bus/Dev
100183b80bacSLv Zheng  *              pci_register        - Device Register
100283b80bacSLv Zheng  *              value               - Buffer where value is placed
100383b80bacSLv Zheng  *              width               - Number of bits
100483b80bacSLv Zheng  *
100583b80bacSLv Zheng  * RETURN:      Status
100683b80bacSLv Zheng  *
100783b80bacSLv Zheng  * DESCRIPTION: Read data from PCI configuration space
100883b80bacSLv Zheng  *
100983b80bacSLv Zheng  *****************************************************************************/
101083b80bacSLv Zheng 
101183b80bacSLv Zheng acpi_status
acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id,u32 pci_register,u64 * value,u32 width)101283b80bacSLv Zheng acpi_os_read_pci_configuration(struct acpi_pci_id *pci_id,
101383b80bacSLv Zheng 			       u32 pci_register, u64 *value, u32 width)
101483b80bacSLv Zheng {
101583b80bacSLv Zheng 
101683b80bacSLv Zheng 	*value = 0;
101783b80bacSLv Zheng 	return (AE_OK);
101883b80bacSLv Zheng }
101983b80bacSLv Zheng 
102083b80bacSLv Zheng /******************************************************************************
102183b80bacSLv Zheng  *
102283b80bacSLv Zheng  * FUNCTION:    acpi_os_write_pci_configuration
102383b80bacSLv Zheng  *
102483b80bacSLv Zheng  * PARAMETERS:  pci_id              - Seg/Bus/Dev
102583b80bacSLv Zheng  *              pci_register        - Device Register
102683b80bacSLv Zheng  *              value               - Value to be written
102783b80bacSLv Zheng  *              width               - Number of bits
102883b80bacSLv Zheng  *
102983b80bacSLv Zheng  * RETURN:      Status.
103083b80bacSLv Zheng  *
103183b80bacSLv Zheng  * DESCRIPTION: Write data to PCI configuration space
103283b80bacSLv Zheng  *
103383b80bacSLv Zheng  *****************************************************************************/
103483b80bacSLv Zheng 
103583b80bacSLv Zheng acpi_status
acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id,u32 pci_register,u64 value,u32 width)103683b80bacSLv Zheng acpi_os_write_pci_configuration(struct acpi_pci_id *pci_id,
103783b80bacSLv Zheng 				u32 pci_register, u64 value, u32 width)
103883b80bacSLv Zheng {
103983b80bacSLv Zheng 
104083b80bacSLv Zheng 	return (AE_OK);
104183b80bacSLv Zheng }
104283b80bacSLv Zheng 
104383b80bacSLv Zheng /******************************************************************************
104483b80bacSLv Zheng  *
104583b80bacSLv Zheng  * FUNCTION:    acpi_os_read_port
104683b80bacSLv Zheng  *
104783b80bacSLv Zheng  * PARAMETERS:  address             - Address of I/O port/register to read
104883b80bacSLv Zheng  *              value               - Where value is placed
104983b80bacSLv Zheng  *              width               - Number of bits
105083b80bacSLv Zheng  *
105183b80bacSLv Zheng  * RETURN:      Value read from port
105283b80bacSLv Zheng  *
105383b80bacSLv Zheng  * DESCRIPTION: Read data from an I/O port or register
105483b80bacSLv Zheng  *
105583b80bacSLv Zheng  *****************************************************************************/
105683b80bacSLv Zheng 
acpi_os_read_port(acpi_io_address address,u32 * value,u32 width)105783b80bacSLv Zheng acpi_status acpi_os_read_port(acpi_io_address address, u32 *value, u32 width)
105883b80bacSLv Zheng {
105983b80bacSLv Zheng 
106083b80bacSLv Zheng 	switch (width) {
106183b80bacSLv Zheng 	case 8:
106283b80bacSLv Zheng 
106383b80bacSLv Zheng 		*value = 0xFF;
106483b80bacSLv Zheng 		break;
106583b80bacSLv Zheng 
106683b80bacSLv Zheng 	case 16:
106783b80bacSLv Zheng 
106883b80bacSLv Zheng 		*value = 0xFFFF;
106983b80bacSLv Zheng 		break;
107083b80bacSLv Zheng 
107183b80bacSLv Zheng 	case 32:
107283b80bacSLv Zheng 
107383b80bacSLv Zheng 		*value = 0xFFFFFFFF;
107483b80bacSLv Zheng 		break;
107583b80bacSLv Zheng 
107683b80bacSLv Zheng 	default:
107783b80bacSLv Zheng 
107883b80bacSLv Zheng 		return (AE_BAD_PARAMETER);
107983b80bacSLv Zheng 	}
108083b80bacSLv Zheng 
108183b80bacSLv Zheng 	return (AE_OK);
108283b80bacSLv Zheng }
108383b80bacSLv Zheng 
108483b80bacSLv Zheng /******************************************************************************
108583b80bacSLv Zheng  *
108683b80bacSLv Zheng  * FUNCTION:    acpi_os_write_port
108783b80bacSLv Zheng  *
108883b80bacSLv Zheng  * PARAMETERS:  address             - Address of I/O port/register to write
108983b80bacSLv Zheng  *              value               - Value to write
109083b80bacSLv Zheng  *              width               - Number of bits
109183b80bacSLv Zheng  *
109283b80bacSLv Zheng  * RETURN:      None
109383b80bacSLv Zheng  *
109483b80bacSLv Zheng  * DESCRIPTION: Write data to an I/O port or register
109583b80bacSLv Zheng  *
109683b80bacSLv Zheng  *****************************************************************************/
109783b80bacSLv Zheng 
acpi_os_write_port(acpi_io_address address,u32 value,u32 width)109883b80bacSLv Zheng acpi_status acpi_os_write_port(acpi_io_address address, u32 value, u32 width)
109983b80bacSLv Zheng {
110083b80bacSLv Zheng 
110183b80bacSLv Zheng 	return (AE_OK);
110283b80bacSLv Zheng }
110383b80bacSLv Zheng 
110483b80bacSLv Zheng /******************************************************************************
110583b80bacSLv Zheng  *
110683b80bacSLv Zheng  * FUNCTION:    acpi_os_read_memory
110783b80bacSLv Zheng  *
110883b80bacSLv Zheng  * PARAMETERS:  address             - Physical Memory Address to read
110983b80bacSLv Zheng  *              value               - Where value is placed
111083b80bacSLv Zheng  *              width               - Number of bits (8,16,32, or 64)
111183b80bacSLv Zheng  *
111283b80bacSLv Zheng  * RETURN:      Value read from physical memory address. Always returned
111383b80bacSLv Zheng  *              as a 64-bit integer, regardless of the read width.
111483b80bacSLv Zheng  *
111583b80bacSLv Zheng  * DESCRIPTION: Read data from a physical memory address
111683b80bacSLv Zheng  *
111783b80bacSLv Zheng  *****************************************************************************/
111883b80bacSLv Zheng 
111983b80bacSLv Zheng acpi_status
acpi_os_read_memory(acpi_physical_address address,u64 * value,u32 width)112083b80bacSLv Zheng acpi_os_read_memory(acpi_physical_address address, u64 *value, u32 width)
112183b80bacSLv Zheng {
112283b80bacSLv Zheng 
112383b80bacSLv Zheng 	switch (width) {
112483b80bacSLv Zheng 	case 8:
112583b80bacSLv Zheng 	case 16:
112683b80bacSLv Zheng 	case 32:
112783b80bacSLv Zheng 	case 64:
112883b80bacSLv Zheng 
112983b80bacSLv Zheng 		*value = 0;
113083b80bacSLv Zheng 		break;
113183b80bacSLv Zheng 
113283b80bacSLv Zheng 	default:
113383b80bacSLv Zheng 
113483b80bacSLv Zheng 		return (AE_BAD_PARAMETER);
113583b80bacSLv Zheng 	}
113683b80bacSLv Zheng 	return (AE_OK);
113783b80bacSLv Zheng }
113883b80bacSLv Zheng 
113983b80bacSLv Zheng /******************************************************************************
114083b80bacSLv Zheng  *
114183b80bacSLv Zheng  * FUNCTION:    acpi_os_write_memory
114283b80bacSLv Zheng  *
114383b80bacSLv Zheng  * PARAMETERS:  address             - Physical Memory Address to write
114483b80bacSLv Zheng  *              value               - Value to write
114583b80bacSLv Zheng  *              width               - Number of bits (8,16,32, or 64)
114683b80bacSLv Zheng  *
114783b80bacSLv Zheng  * RETURN:      None
114883b80bacSLv Zheng  *
114983b80bacSLv Zheng  * DESCRIPTION: Write data to a physical memory address
115083b80bacSLv Zheng  *
115183b80bacSLv Zheng  *****************************************************************************/
115283b80bacSLv Zheng 
115383b80bacSLv Zheng acpi_status
acpi_os_write_memory(acpi_physical_address address,u64 value,u32 width)115483b80bacSLv Zheng acpi_os_write_memory(acpi_physical_address address, u64 value, u32 width)
115583b80bacSLv Zheng {
115683b80bacSLv Zheng 
115783b80bacSLv Zheng 	return (AE_OK);
115883b80bacSLv Zheng }
115983b80bacSLv Zheng 
116083b80bacSLv Zheng /******************************************************************************
116183b80bacSLv Zheng  *
116283b80bacSLv Zheng  * FUNCTION:    acpi_os_readable
116383b80bacSLv Zheng  *
116483b80bacSLv Zheng  * PARAMETERS:  pointer             - Area to be verified
116583b80bacSLv Zheng  *              length              - Size of area
116683b80bacSLv Zheng  *
116783b80bacSLv Zheng  * RETURN:      TRUE if readable for entire length
116883b80bacSLv Zheng  *
116983b80bacSLv Zheng  * DESCRIPTION: Verify that a pointer is valid for reading
117083b80bacSLv Zheng  *
117183b80bacSLv Zheng  *****************************************************************************/
117283b80bacSLv Zheng 
acpi_os_readable(void * pointer,acpi_size length)117383b80bacSLv Zheng u8 acpi_os_readable(void *pointer, acpi_size length)
117483b80bacSLv Zheng {
117583b80bacSLv Zheng 
117683b80bacSLv Zheng 	return (TRUE);
117783b80bacSLv Zheng }
117883b80bacSLv Zheng 
117983b80bacSLv Zheng /******************************************************************************
118083b80bacSLv Zheng  *
118183b80bacSLv Zheng  * FUNCTION:    acpi_os_writable
118283b80bacSLv Zheng  *
118383b80bacSLv Zheng  * PARAMETERS:  pointer             - Area to be verified
118483b80bacSLv Zheng  *              length              - Size of area
118583b80bacSLv Zheng  *
118683b80bacSLv Zheng  * RETURN:      TRUE if writable for entire length
118783b80bacSLv Zheng  *
118883b80bacSLv Zheng  * DESCRIPTION: Verify that a pointer is valid for writing
118983b80bacSLv Zheng  *
119083b80bacSLv Zheng  *****************************************************************************/
119183b80bacSLv Zheng 
acpi_os_writable(void * pointer,acpi_size length)119283b80bacSLv Zheng u8 acpi_os_writable(void *pointer, acpi_size length)
119383b80bacSLv Zheng {
119483b80bacSLv Zheng 
119583b80bacSLv Zheng 	return (TRUE);
119683b80bacSLv Zheng }
119783b80bacSLv Zheng 
119883b80bacSLv Zheng /******************************************************************************
119983b80bacSLv Zheng  *
120083b80bacSLv Zheng  * FUNCTION:    acpi_os_signal
120183b80bacSLv Zheng  *
120283b80bacSLv Zheng  * PARAMETERS:  function            - ACPI A signal function code
120383b80bacSLv Zheng  *              info                - Pointer to function-dependent structure
120483b80bacSLv Zheng  *
120583b80bacSLv Zheng  * RETURN:      Status
120683b80bacSLv Zheng  *
120783b80bacSLv Zheng  * DESCRIPTION: Miscellaneous functions. Example implementation only.
120883b80bacSLv Zheng  *
120983b80bacSLv Zheng  *****************************************************************************/
121083b80bacSLv Zheng 
acpi_os_signal(u32 function,void * info)121183b80bacSLv Zheng acpi_status acpi_os_signal(u32 function, void *info)
121283b80bacSLv Zheng {
121383b80bacSLv Zheng 
121483b80bacSLv Zheng 	switch (function) {
121583b80bacSLv Zheng 	case ACPI_SIGNAL_FATAL:
121683b80bacSLv Zheng 
121783b80bacSLv Zheng 		break;
121883b80bacSLv Zheng 
121983b80bacSLv Zheng 	case ACPI_SIGNAL_BREAKPOINT:
122083b80bacSLv Zheng 
122183b80bacSLv Zheng 		break;
122283b80bacSLv Zheng 
122383b80bacSLv Zheng 	default:
122483b80bacSLv Zheng 
122583b80bacSLv Zheng 		break;
122683b80bacSLv Zheng 	}
122783b80bacSLv Zheng 
122883b80bacSLv Zheng 	return (AE_OK);
122983b80bacSLv Zheng }
123083b80bacSLv Zheng 
123183b80bacSLv Zheng /* Optional multi-thread support */
123283b80bacSLv Zheng 
123383b80bacSLv Zheng #ifndef ACPI_SINGLE_THREADED
123483b80bacSLv Zheng /******************************************************************************
123583b80bacSLv Zheng  *
123683b80bacSLv Zheng  * FUNCTION:    acpi_os_get_thread_id
123783b80bacSLv Zheng  *
123883b80bacSLv Zheng  * PARAMETERS:  None
123983b80bacSLv Zheng  *
124083b80bacSLv Zheng  * RETURN:      Id of the running thread
124183b80bacSLv Zheng  *
124283b80bacSLv Zheng  * DESCRIPTION: Get the ID of the current (running) thread
124383b80bacSLv Zheng  *
124483b80bacSLv Zheng  *****************************************************************************/
124583b80bacSLv Zheng 
acpi_os_get_thread_id(void)124683b80bacSLv Zheng acpi_thread_id acpi_os_get_thread_id(void)
124783b80bacSLv Zheng {
124883b80bacSLv Zheng 	pthread_t thread;
124983b80bacSLv Zheng 
125083b80bacSLv Zheng 	thread = pthread_self();
125183b80bacSLv Zheng 	return (ACPI_CAST_PTHREAD_T(thread));
125283b80bacSLv Zheng }
125383b80bacSLv Zheng 
125483b80bacSLv Zheng /******************************************************************************
125583b80bacSLv Zheng  *
125683b80bacSLv Zheng  * FUNCTION:    acpi_os_execute
125783b80bacSLv Zheng  *
125883b80bacSLv Zheng  * PARAMETERS:  type                - Type of execution
125983b80bacSLv Zheng  *              function            - Address of the function to execute
126083b80bacSLv Zheng  *              context             - Passed as a parameter to the function
126183b80bacSLv Zheng  *
126283b80bacSLv Zheng  * RETURN:      Status.
126383b80bacSLv Zheng  *
126483b80bacSLv Zheng  * DESCRIPTION: Execute a new thread
126583b80bacSLv Zheng  *
126683b80bacSLv Zheng  *****************************************************************************/
126783b80bacSLv Zheng 
126883b80bacSLv Zheng acpi_status
acpi_os_execute(acpi_execute_type type,acpi_osd_exec_callback function,void * context)126983b80bacSLv Zheng acpi_os_execute(acpi_execute_type type,
127083b80bacSLv Zheng 		acpi_osd_exec_callback function, void *context)
127183b80bacSLv Zheng {
127283b80bacSLv Zheng 	pthread_t thread;
127383b80bacSLv Zheng 	int ret;
127483b80bacSLv Zheng 
127583b80bacSLv Zheng 	ret =
127683b80bacSLv Zheng 	    pthread_create(&thread, NULL, (PTHREAD_CALLBACK) function, context);
127783b80bacSLv Zheng 	if (ret) {
127883b80bacSLv Zheng 		acpi_os_printf("Create thread failed");
127983b80bacSLv Zheng 	}
128083b80bacSLv Zheng 	return (0);
128183b80bacSLv Zheng }
128283b80bacSLv Zheng 
128383b80bacSLv Zheng #else				/* ACPI_SINGLE_THREADED */
acpi_os_get_thread_id(void)128483b80bacSLv Zheng acpi_thread_id acpi_os_get_thread_id(void)
128583b80bacSLv Zheng {
128683b80bacSLv Zheng 	return (1);
128783b80bacSLv Zheng }
128883b80bacSLv Zheng 
128983b80bacSLv Zheng acpi_status
acpi_os_execute(acpi_execute_type type,acpi_osd_exec_callback function,void * context)129083b80bacSLv Zheng acpi_os_execute(acpi_execute_type type,
129183b80bacSLv Zheng 		acpi_osd_exec_callback function, void *context)
129283b80bacSLv Zheng {
129383b80bacSLv Zheng 
129483b80bacSLv Zheng 	function(context);
129583b80bacSLv Zheng 
129683b80bacSLv Zheng 	return (AE_OK);
129783b80bacSLv Zheng }
129883b80bacSLv Zheng 
129983b80bacSLv Zheng #endif				/* ACPI_SINGLE_THREADED */
130083b80bacSLv Zheng 
130183b80bacSLv Zheng /******************************************************************************
130283b80bacSLv Zheng  *
130383b80bacSLv Zheng  * FUNCTION:    acpi_os_wait_events_complete
130483b80bacSLv Zheng  *
130583b80bacSLv Zheng  * PARAMETERS:  None
130683b80bacSLv Zheng  *
130783b80bacSLv Zheng  * RETURN:      None
130883b80bacSLv Zheng  *
130983b80bacSLv Zheng  * DESCRIPTION: Wait for all asynchronous events to complete. This
131083b80bacSLv Zheng  *              implementation does nothing.
131183b80bacSLv Zheng  *
131283b80bacSLv Zheng  *****************************************************************************/
131383b80bacSLv Zheng 
acpi_os_wait_events_complete(void)131483b80bacSLv Zheng void acpi_os_wait_events_complete(void)
131583b80bacSLv Zheng {
131683b80bacSLv Zheng 	return;
131783b80bacSLv Zheng }
1318