Path: blob/master/tools/power/acpi/os_specific/service_layers/osunixxf.c
26292 views
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.01/******************************************************************************2*3* Module Name: osunixxf - UNIX OSL interfaces4*5* Copyright (C) 2000 - 2025, Intel Corp.6*7*****************************************************************************/89/*10* These interfaces are required in order to compile the ASL compiler and the11* various ACPICA tools under Linux or other Unix-like system.12*/13#include <acpi/acpi.h>14#include "accommon.h"15#include "amlcode.h"16#include "acparser.h"17#include "acdebug.h"1819#include <stdio.h>20#include <stdlib.h>21#include <stdarg.h>22#include <unistd.h>23#include <sys/time.h>24#include <semaphore.h>25#include <pthread.h>26#include <errno.h>2728#define _COMPONENT ACPI_OS_SERVICES29ACPI_MODULE_NAME("osunixxf")3031/* Upcalls to acpi_exec */32void33ae_table_override(struct acpi_table_header *existing_table,34struct acpi_table_header **new_table);3536typedef void *(*PTHREAD_CALLBACK) (void *);3738/* Buffer used by acpi_os_vprintf */3940#define ACPI_VPRINTF_BUFFER_SIZE 51241#define _ASCII_NEWLINE '\n'4243/* Terminal support for acpi_exec only */4445#ifdef ACPI_EXEC_APP46#include <termios.h>4748struct termios original_term_attributes;49int term_attributes_were_set = 0;5051acpi_status acpi_ut_read_line(char *buffer, u32 buffer_length, u32 *bytes_read);5253static void os_enter_line_edit_mode(void);5455static void os_exit_line_edit_mode(void);5657/******************************************************************************58*59* FUNCTION: os_enter_line_edit_mode, os_exit_line_edit_mode60*61* PARAMETERS: None62*63* RETURN: None64*65* DESCRIPTION: Enter/Exit the raw character input mode for the terminal.66*67* Interactive line-editing support for the AML debugger. Used with the68* common/acgetline module.69*70* readline() is not used because of non-portability. It is not available71* on all systems, and if it is, often the package must be manually installed.72*73* Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line74* editing that we need in acpi_os_get_line.75*76* If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these77* calls will also work:78* For os_enter_line_edit_mode: system ("stty cbreak -echo")79* For os_exit_line_edit_mode: system ("stty cooked echo")80*81*****************************************************************************/8283static void os_enter_line_edit_mode(void)84{85struct termios local_term_attributes;8687term_attributes_were_set = 0;8889/* STDIN must be a terminal */9091if (!isatty(STDIN_FILENO)) {92return;93}9495/* Get and keep the original attributes */9697if (tcgetattr(STDIN_FILENO, &original_term_attributes)) {98fprintf(stderr, "Could not get terminal attributes!\n");99return;100}101102/* Set the new attributes to enable raw character input */103104memcpy(&local_term_attributes, &original_term_attributes,105sizeof(struct termios));106107local_term_attributes.c_lflag &= ~(ICANON | ECHO);108local_term_attributes.c_cc[VMIN] = 1;109local_term_attributes.c_cc[VTIME] = 0;110111if (tcsetattr(STDIN_FILENO, TCSANOW, &local_term_attributes)) {112fprintf(stderr, "Could not set terminal attributes!\n");113return;114}115116term_attributes_were_set = 1;117}118119static void os_exit_line_edit_mode(void)120{121122if (!term_attributes_were_set) {123return;124}125126/* Set terminal attributes back to the original values */127128if (tcsetattr(STDIN_FILENO, TCSANOW, &original_term_attributes)) {129fprintf(stderr, "Could not restore terminal attributes!\n");130}131}132133#else134135/* These functions are not needed for other ACPICA utilities */136137#define os_enter_line_edit_mode()138#define os_exit_line_edit_mode()139#endif140141/******************************************************************************142*143* FUNCTION: acpi_os_initialize, acpi_os_terminate144*145* PARAMETERS: None146*147* RETURN: Status148*149* DESCRIPTION: Initialize and terminate this module.150*151*****************************************************************************/152153acpi_status acpi_os_initialize(void)154{155acpi_status status;156157acpi_gbl_output_file = stdout;158159os_enter_line_edit_mode();160161status = acpi_os_create_lock(&acpi_gbl_print_lock);162if (ACPI_FAILURE(status)) {163return (status);164}165166return (AE_OK);167}168169acpi_status acpi_os_terminate(void)170{171172os_exit_line_edit_mode();173return (AE_OK);174}175176#ifndef ACPI_USE_NATIVE_RSDP_POINTER177/******************************************************************************178*179* FUNCTION: acpi_os_get_root_pointer180*181* PARAMETERS: None182*183* RETURN: RSDP physical address184*185* DESCRIPTION: Gets the ACPI root pointer (RSDP)186*187*****************************************************************************/188189acpi_physical_address acpi_os_get_root_pointer(void)190{191192return (0);193}194#endif195196/******************************************************************************197*198* FUNCTION: acpi_os_predefined_override199*200* PARAMETERS: init_val - Initial value of the predefined object201* new_val - The new value for the object202*203* RETURN: Status, pointer to value. Null pointer returned if not204* overriding.205*206* DESCRIPTION: Allow the OS to override predefined names207*208*****************************************************************************/209210acpi_status211acpi_os_predefined_override(const struct acpi_predefined_names *init_val,212acpi_string *new_val)213{214215if (!init_val || !new_val) {216return (AE_BAD_PARAMETER);217}218219*new_val = NULL;220return (AE_OK);221}222223/******************************************************************************224*225* FUNCTION: acpi_os_table_override226*227* PARAMETERS: existing_table - Header of current table (probably228* firmware)229* new_table - Where an entire new table is returned.230*231* RETURN: Status, pointer to new table. Null pointer returned if no232* table is available to override233*234* DESCRIPTION: Return a different version of a table if one is available235*236*****************************************************************************/237238acpi_status239acpi_os_table_override(struct acpi_table_header *existing_table,240struct acpi_table_header **new_table)241{242243if (!existing_table || !new_table) {244return (AE_BAD_PARAMETER);245}246247*new_table = NULL;248249#ifdef ACPI_EXEC_APP250251ae_table_override(existing_table, new_table);252return (AE_OK);253#else254255return (AE_NO_ACPI_TABLES);256#endif257}258259/******************************************************************************260*261* FUNCTION: acpi_os_physical_table_override262*263* PARAMETERS: existing_table - Header of current table (probably firmware)264* new_address - Where new table address is returned265* (Physical address)266* new_table_length - Where new table length is returned267*268* RETURN: Status, address/length of new table. Null pointer returned269* if no table is available to override.270*271* DESCRIPTION: Returns AE_SUPPORT, function not used in user space.272*273*****************************************************************************/274275acpi_status276acpi_os_physical_table_override(struct acpi_table_header *existing_table,277acpi_physical_address *new_address,278u32 *new_table_length)279{280281return (AE_SUPPORT);282}283284/******************************************************************************285*286* FUNCTION: acpi_os_enter_sleep287*288* PARAMETERS: sleep_state - Which sleep state to enter289* rega_value - Register A value290* regb_value - Register B value291*292* RETURN: Status293*294* DESCRIPTION: A hook before writing sleep registers to enter the sleep295* state. Return AE_CTRL_TERMINATE to skip further sleep register296* writes.297*298*****************************************************************************/299300acpi_status acpi_os_enter_sleep(u8 sleep_state, u32 rega_value, u32 regb_value)301{302303return (AE_OK);304}305306/******************************************************************************307*308* FUNCTION: acpi_os_redirect_output309*310* PARAMETERS: destination - An open file handle/pointer311*312* RETURN: None313*314* DESCRIPTION: Causes redirect of acpi_os_printf and acpi_os_vprintf315*316*****************************************************************************/317318void acpi_os_redirect_output(void *destination)319{320321acpi_gbl_output_file = destination;322}323324/******************************************************************************325*326* FUNCTION: acpi_os_printf327*328* PARAMETERS: fmt, ... - Standard printf format329*330* RETURN: None331*332* DESCRIPTION: Formatted output. Note: very similar to acpi_os_vprintf333* (performance), changes should be tracked in both functions.334*335*****************************************************************************/336337void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...)338{339va_list args;340u8 flags;341342flags = acpi_gbl_db_output_flags;343if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {344345/* Output is directable to either a file (if open) or the console */346347if (acpi_gbl_debug_file) {348349/* Output file is open, send the output there */350351va_start(args, fmt);352vfprintf(acpi_gbl_debug_file, fmt, args);353va_end(args);354} else {355/* No redirection, send output to console (once only!) */356357flags |= ACPI_DB_CONSOLE_OUTPUT;358}359}360361if (flags & ACPI_DB_CONSOLE_OUTPUT) {362va_start(args, fmt);363vfprintf(acpi_gbl_output_file, fmt, args);364va_end(args);365}366}367368/******************************************************************************369*370* FUNCTION: acpi_os_vprintf371*372* PARAMETERS: fmt - Standard printf format373* args - Argument list374*375* RETURN: None376*377* DESCRIPTION: Formatted output with argument list pointer. Note: very378* similar to acpi_os_printf, changes should be tracked in both379* functions.380*381*****************************************************************************/382383void acpi_os_vprintf(const char *fmt, va_list args)384{385u8 flags;386char buffer[ACPI_VPRINTF_BUFFER_SIZE];387388/*389* We build the output string in a local buffer because we may be390* outputting the buffer twice. Using vfprintf is problematic because391* some implementations modify the args pointer/structure during392* execution. Thus, we use the local buffer for portability.393*394* Note: Since this module is intended for use by the various ACPICA395* utilities/applications, we can safely declare the buffer on the stack.396* Also, This function is used for relatively small error messages only.397*/398vsnprintf(buffer, ACPI_VPRINTF_BUFFER_SIZE, fmt, args);399400flags = acpi_gbl_db_output_flags;401if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {402403/* Output is directable to either a file (if open) or the console */404405if (acpi_gbl_debug_file) {406407/* Output file is open, send the output there */408409fputs(buffer, acpi_gbl_debug_file);410} else {411/* No redirection, send output to console (once only!) */412413flags |= ACPI_DB_CONSOLE_OUTPUT;414}415}416417if (flags & ACPI_DB_CONSOLE_OUTPUT) {418fputs(buffer, acpi_gbl_output_file);419}420}421422#ifndef ACPI_EXEC_APP423/******************************************************************************424*425* FUNCTION: acpi_os_get_line426*427* PARAMETERS: buffer - Where to return the command line428* buffer_length - Maximum length of Buffer429* bytes_read - Where the actual byte count is returned430*431* RETURN: Status and actual bytes read432*433* DESCRIPTION: Get the next input line from the terminal. NOTE: For the434* acpi_exec utility, we use the acgetline module instead to435* provide line-editing and history support.436*437*****************************************************************************/438439acpi_status acpi_os_get_line(char *buffer, u32 buffer_length, u32 *bytes_read)440{441int input_char;442u32 end_of_line;443444/* Standard acpi_os_get_line for all utilities except acpi_exec */445446for (end_of_line = 0;; end_of_line++) {447if (end_of_line >= buffer_length) {448return (AE_BUFFER_OVERFLOW);449}450451if ((input_char = getchar()) == EOF) {452return (AE_ERROR);453}454455if (!input_char || input_char == _ASCII_NEWLINE) {456break;457}458459buffer[end_of_line] = (char)input_char;460}461462/* Null terminate the buffer */463464buffer[end_of_line] = 0;465466/* Return the number of bytes in the string */467468if (bytes_read) {469*bytes_read = end_of_line;470}471472return (AE_OK);473}474#endif475476#ifndef ACPI_USE_NATIVE_MEMORY_MAPPING477/******************************************************************************478*479* FUNCTION: acpi_os_map_memory480*481* PARAMETERS: where - Physical address of memory to be mapped482* length - How much memory to map483*484* RETURN: Pointer to mapped memory. Null on error.485*486* DESCRIPTION: Map physical memory into caller's address space487*488*****************************************************************************/489490void *acpi_os_map_memory(acpi_physical_address where, acpi_size length)491{492493return (ACPI_TO_POINTER((acpi_size)where));494}495496/******************************************************************************497*498* FUNCTION: acpi_os_unmap_memory499*500* PARAMETERS: where - Logical address of memory to be unmapped501* length - How much memory to unmap502*503* RETURN: None.504*505* DESCRIPTION: Delete a previously created mapping. Where and Length must506* correspond to a previous mapping exactly.507*508*****************************************************************************/509510void acpi_os_unmap_memory(void *where, acpi_size length)511{512513return;514}515#endif516517/******************************************************************************518*519* FUNCTION: acpi_os_allocate520*521* PARAMETERS: size - Amount to allocate, in bytes522*523* RETURN: Pointer to the new allocation. Null on error.524*525* DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.526*527*****************************************************************************/528529void *acpi_os_allocate(acpi_size size)530{531void *mem;532533mem = (void *)malloc((size_t) size);534return (mem);535}536537#ifdef USE_NATIVE_ALLOCATE_ZEROED538/******************************************************************************539*540* FUNCTION: acpi_os_allocate_zeroed541*542* PARAMETERS: size - Amount to allocate, in bytes543*544* RETURN: Pointer to the new allocation. Null on error.545*546* DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.547*548*****************************************************************************/549550void *acpi_os_allocate_zeroed(acpi_size size)551{552void *mem;553554mem = (void *)calloc(1, (size_t) size);555return (mem);556}557#endif558559/******************************************************************************560*561* FUNCTION: acpi_os_free562*563* PARAMETERS: mem - Pointer to previously allocated memory564*565* RETURN: None.566*567* DESCRIPTION: Free memory allocated via acpi_os_allocate568*569*****************************************************************************/570571void acpi_os_free(void *mem)572{573574free(mem);575}576577#ifdef ACPI_SINGLE_THREADED578/******************************************************************************579*580* FUNCTION: Semaphore stub functions581*582* DESCRIPTION: Stub functions used for single-thread applications that do583* not require semaphore synchronization. Full implementations584* of these functions appear after the stubs.585*586*****************************************************************************/587588acpi_status589acpi_os_create_semaphore(u32 max_units,590u32 initial_units, acpi_handle *out_handle)591{592*out_handle = (acpi_handle)1;593return (AE_OK);594}595596acpi_status acpi_os_delete_semaphore(acpi_handle handle)597{598return (AE_OK);599}600601acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)602{603return (AE_OK);604}605606acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)607{608return (AE_OK);609}610611#else612/******************************************************************************613*614* FUNCTION: acpi_os_create_semaphore615*616* PARAMETERS: initial_units - Units to be assigned to the new semaphore617* out_handle - Where a handle will be returned618*619* RETURN: Status620*621* DESCRIPTION: Create an OS semaphore622*623*****************************************************************************/624625acpi_status626acpi_os_create_semaphore(u32 max_units,627u32 initial_units, acpi_handle *out_handle)628{629sem_t *sem;630631if (!out_handle) {632return (AE_BAD_PARAMETER);633}634#ifdef __APPLE__635{636static int semaphore_count = 0;637char semaphore_name[32];638639snprintf(semaphore_name, sizeof(semaphore_name), "acpi_sem_%d",640semaphore_count++);641printf("%s\n", semaphore_name);642sem =643sem_open(semaphore_name, O_EXCL | O_CREAT, 0755,644initial_units);645if (!sem) {646return (AE_NO_MEMORY);647}648sem_unlink(semaphore_name); /* This just deletes the name */649}650651#else652sem = acpi_os_allocate(sizeof(sem_t));653if (!sem) {654return (AE_NO_MEMORY);655}656657if (sem_init(sem, 0, initial_units) == -1) {658acpi_os_free(sem);659return (AE_BAD_PARAMETER);660}661#endif662663*out_handle = (acpi_handle)sem;664return (AE_OK);665}666667/******************************************************************************668*669* FUNCTION: acpi_os_delete_semaphore670*671* PARAMETERS: handle - Handle returned by acpi_os_create_semaphore672*673* RETURN: Status674*675* DESCRIPTION: Delete an OS semaphore676*677*****************************************************************************/678679acpi_status acpi_os_delete_semaphore(acpi_handle handle)680{681sem_t *sem = (sem_t *) handle;682683if (!sem) {684return (AE_BAD_PARAMETER);685}686#ifdef __APPLE__687if (sem_close(sem) == -1) {688return (AE_BAD_PARAMETER);689}690#else691if (sem_destroy(sem) == -1) {692return (AE_BAD_PARAMETER);693}694#endif695696return (AE_OK);697}698699/******************************************************************************700*701* FUNCTION: acpi_os_wait_semaphore702*703* PARAMETERS: handle - Handle returned by acpi_os_create_semaphore704* units - How many units to wait for705* msec_timeout - How long to wait (milliseconds)706*707* RETURN: Status708*709* DESCRIPTION: Wait for units710*711*****************************************************************************/712713acpi_status714acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 msec_timeout)715{716acpi_status status = AE_OK;717sem_t *sem = (sem_t *) handle;718int ret_val;719#ifndef ACPI_USE_ALTERNATE_TIMEOUT720struct timespec time;721#endif722723if (!sem) {724return (AE_BAD_PARAMETER);725}726727switch (msec_timeout) {728/*729* No Wait:730* --------731* A zero timeout value indicates that we shouldn't wait - just732* acquire the semaphore if available otherwise return AE_TIME733* (a.k.a. 'would block').734*/735case 0:736737if (sem_trywait(sem) == -1) {738status = (AE_TIME);739}740break;741742/* Wait Indefinitely */743744case ACPI_WAIT_FOREVER:745746while (((ret_val = sem_wait(sem)) == -1) && (errno == EINTR)) {747continue; /* Restart if interrupted */748}749if (ret_val != 0) {750status = (AE_TIME);751}752break;753754/* Wait with msec_timeout */755756default:757758#ifdef ACPI_USE_ALTERNATE_TIMEOUT759/*760* Alternate timeout mechanism for environments where761* sem_timedwait is not available or does not work properly.762*/763while (msec_timeout) {764if (sem_trywait(sem) == 0) {765766/* Got the semaphore */767return (AE_OK);768}769770if (msec_timeout >= 10) {771msec_timeout -= 10;772usleep(10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */773} else {774msec_timeout--;775usleep(ACPI_USEC_PER_MSEC); /* one millisecond */776}777}778status = (AE_TIME);779#else780/*781* The interface to sem_timedwait is an absolute time, so we need to782* get the current time, then add in the millisecond Timeout value.783*/784if (clock_gettime(CLOCK_REALTIME, &time) == -1) {785perror("clock_gettime");786return (AE_TIME);787}788789time.tv_sec += (msec_timeout / ACPI_MSEC_PER_SEC);790time.tv_nsec +=791((msec_timeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC);792793/* Handle nanosecond overflow (field must be less than one second) */794795if (time.tv_nsec >= ACPI_NSEC_PER_SEC) {796time.tv_sec += (time.tv_nsec / ACPI_NSEC_PER_SEC);797time.tv_nsec = (time.tv_nsec % ACPI_NSEC_PER_SEC);798}799800while (((ret_val = sem_timedwait(sem, &time)) == -1)801&& (errno == EINTR)) {802continue; /* Restart if interrupted */803804}805806if (ret_val != 0) {807if (errno != ETIMEDOUT) {808perror("sem_timedwait");809}810status = (AE_TIME);811}812#endif813break;814}815816return (status);817}818819/******************************************************************************820*821* FUNCTION: acpi_os_signal_semaphore822*823* PARAMETERS: handle - Handle returned by acpi_os_create_semaphore824* units - Number of units to send825*826* RETURN: Status827*828* DESCRIPTION: Send units829*830*****************************************************************************/831832acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)833{834sem_t *sem = (sem_t *) handle;835836if (!sem) {837return (AE_BAD_PARAMETER);838}839840if (sem_post(sem) == -1) {841return (AE_LIMIT);842}843844return (AE_OK);845}846847#endif /* ACPI_SINGLE_THREADED */848849/******************************************************************************850*851* FUNCTION: Spinlock interfaces852*853* DESCRIPTION: Map these interfaces to semaphore interfaces854*855*****************************************************************************/856857acpi_status acpi_os_create_lock(acpi_spinlock * out_handle)858{859860return (acpi_os_create_semaphore(1, 1, out_handle));861}862863void acpi_os_delete_lock(acpi_spinlock handle)864{865acpi_os_delete_semaphore(handle);866}867868acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle)869{870acpi_os_wait_semaphore(handle, 1, 0xFFFF);871return (0);872}873874void acpi_os_release_lock(acpi_spinlock handle, acpi_cpu_flags flags)875{876acpi_os_signal_semaphore(handle, 1);877}878879/******************************************************************************880*881* FUNCTION: acpi_os_install_interrupt_handler882*883* PARAMETERS: interrupt_number - Level handler should respond to.884* isr - Address of the ACPI interrupt handler885* except_ptr - Where status is returned886*887* RETURN: Handle to the newly installed handler.888*889* DESCRIPTION: Install an interrupt handler. Used to install the ACPI890* OS-independent handler.891*892*****************************************************************************/893894u32895acpi_os_install_interrupt_handler(u32 interrupt_number,896acpi_osd_handler service_routine,897void *context)898{899900return (AE_OK);901}902903/******************************************************************************904*905* FUNCTION: acpi_os_remove_interrupt_handler906*907* PARAMETERS: handle - Returned when handler was installed908*909* RETURN: Status910*911* DESCRIPTION: Uninstalls an interrupt handler.912*913*****************************************************************************/914915acpi_status916acpi_os_remove_interrupt_handler(u32 interrupt_number,917acpi_osd_handler service_routine)918{919920return (AE_OK);921}922923/******************************************************************************924*925* FUNCTION: acpi_os_stall926*927* PARAMETERS: microseconds - Time to sleep928*929* RETURN: Blocks until sleep is completed.930*931* DESCRIPTION: Sleep at microsecond granularity932*933*****************************************************************************/934935void acpi_os_stall(u32 microseconds)936{937938if (microseconds) {939usleep(microseconds);940}941}942943/******************************************************************************944*945* FUNCTION: acpi_os_sleep946*947* PARAMETERS: milliseconds - Time to sleep948*949* RETURN: Blocks until sleep is completed.950*951* DESCRIPTION: Sleep at millisecond granularity952*953*****************************************************************************/954955void acpi_os_sleep(u64 milliseconds)956{957958/* Sleep for whole seconds */959960sleep(milliseconds / ACPI_MSEC_PER_SEC);961962/*963* Sleep for remaining microseconds.964* Arg to usleep() is in usecs and must be less than 1,000,000 (1 second).965*/966usleep((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC);967}968969/******************************************************************************970*971* FUNCTION: acpi_os_get_timer972*973* PARAMETERS: None974*975* RETURN: Current time in 100 nanosecond units976*977* DESCRIPTION: Get the current system time978*979*****************************************************************************/980981u64 acpi_os_get_timer(void)982{983struct timeval time;984985/* This timer has sufficient resolution for user-space application code */986987gettimeofday(&time, NULL);988989/* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */990991return (((u64)time.tv_sec * ACPI_100NSEC_PER_SEC) +992((u64)time.tv_usec * ACPI_100NSEC_PER_USEC));993}994995/******************************************************************************996*997* FUNCTION: acpi_os_read_pci_configuration998*999* PARAMETERS: pci_id - Seg/Bus/Dev1000* pci_register - Device Register1001* value - Buffer where value is placed1002* width - Number of bits1003*1004* RETURN: Status1005*1006* DESCRIPTION: Read data from PCI configuration space1007*1008*****************************************************************************/10091010acpi_status1011acpi_os_read_pci_configuration(struct acpi_pci_id *pci_id,1012u32 pci_register, u64 *value, u32 width)1013{10141015*value = 0;1016return (AE_OK);1017}10181019/******************************************************************************1020*1021* FUNCTION: acpi_os_write_pci_configuration1022*1023* PARAMETERS: pci_id - Seg/Bus/Dev1024* pci_register - Device Register1025* value - Value to be written1026* width - Number of bits1027*1028* RETURN: Status.1029*1030* DESCRIPTION: Write data to PCI configuration space1031*1032*****************************************************************************/10331034acpi_status1035acpi_os_write_pci_configuration(struct acpi_pci_id *pci_id,1036u32 pci_register, u64 value, u32 width)1037{10381039return (AE_OK);1040}10411042/******************************************************************************1043*1044* FUNCTION: acpi_os_read_port1045*1046* PARAMETERS: address - Address of I/O port/register to read1047* value - Where value is placed1048* width - Number of bits1049*1050* RETURN: Value read from port1051*1052* DESCRIPTION: Read data from an I/O port or register1053*1054*****************************************************************************/10551056acpi_status acpi_os_read_port(acpi_io_address address, u32 *value, u32 width)1057{10581059switch (width) {1060case 8:10611062*value = 0xFF;1063break;10641065case 16:10661067*value = 0xFFFF;1068break;10691070case 32:10711072*value = 0xFFFFFFFF;1073break;10741075default:10761077return (AE_BAD_PARAMETER);1078}10791080return (AE_OK);1081}10821083/******************************************************************************1084*1085* FUNCTION: acpi_os_write_port1086*1087* PARAMETERS: address - Address of I/O port/register to write1088* value - Value to write1089* width - Number of bits1090*1091* RETURN: None1092*1093* DESCRIPTION: Write data to an I/O port or register1094*1095*****************************************************************************/10961097acpi_status acpi_os_write_port(acpi_io_address address, u32 value, u32 width)1098{10991100return (AE_OK);1101}11021103/******************************************************************************1104*1105* FUNCTION: acpi_os_read_memory1106*1107* PARAMETERS: address - Physical Memory Address to read1108* value - Where value is placed1109* width - Number of bits (8,16,32, or 64)1110*1111* RETURN: Value read from physical memory address. Always returned1112* as a 64-bit integer, regardless of the read width.1113*1114* DESCRIPTION: Read data from a physical memory address1115*1116*****************************************************************************/11171118acpi_status1119acpi_os_read_memory(acpi_physical_address address, u64 *value, u32 width)1120{11211122switch (width) {1123case 8:1124case 16:1125case 32:1126case 64:11271128*value = 0;1129break;11301131default:11321133return (AE_BAD_PARAMETER);1134}1135return (AE_OK);1136}11371138/******************************************************************************1139*1140* FUNCTION: acpi_os_write_memory1141*1142* PARAMETERS: address - Physical Memory Address to write1143* value - Value to write1144* width - Number of bits (8,16,32, or 64)1145*1146* RETURN: None1147*1148* DESCRIPTION: Write data to a physical memory address1149*1150*****************************************************************************/11511152acpi_status1153acpi_os_write_memory(acpi_physical_address address, u64 value, u32 width)1154{11551156return (AE_OK);1157}11581159/******************************************************************************1160*1161* FUNCTION: acpi_os_readable1162*1163* PARAMETERS: pointer - Area to be verified1164* length - Size of area1165*1166* RETURN: TRUE if readable for entire length1167*1168* DESCRIPTION: Verify that a pointer is valid for reading1169*1170*****************************************************************************/11711172u8 acpi_os_readable(void *pointer, acpi_size length)1173{11741175return (TRUE);1176}11771178/******************************************************************************1179*1180* FUNCTION: acpi_os_writable1181*1182* PARAMETERS: pointer - Area to be verified1183* length - Size of area1184*1185* RETURN: TRUE if writable for entire length1186*1187* DESCRIPTION: Verify that a pointer is valid for writing1188*1189*****************************************************************************/11901191u8 acpi_os_writable(void *pointer, acpi_size length)1192{11931194return (TRUE);1195}11961197/******************************************************************************1198*1199* FUNCTION: acpi_os_signal1200*1201* PARAMETERS: function - ACPI A signal function code1202* info - Pointer to function-dependent structure1203*1204* RETURN: Status1205*1206* DESCRIPTION: Miscellaneous functions. Example implementation only.1207*1208*****************************************************************************/12091210acpi_status acpi_os_signal(u32 function, void *info)1211{12121213switch (function) {1214case ACPI_SIGNAL_FATAL:12151216break;12171218case ACPI_SIGNAL_BREAKPOINT:12191220break;12211222default:12231224break;1225}12261227return (AE_OK);1228}12291230/* Optional multi-thread support */12311232#ifndef ACPI_SINGLE_THREADED1233/******************************************************************************1234*1235* FUNCTION: acpi_os_get_thread_id1236*1237* PARAMETERS: None1238*1239* RETURN: Id of the running thread1240*1241* DESCRIPTION: Get the ID of the current (running) thread1242*1243*****************************************************************************/12441245acpi_thread_id acpi_os_get_thread_id(void)1246{1247pthread_t thread;12481249thread = pthread_self();1250return (ACPI_CAST_PTHREAD_T(thread));1251}12521253/******************************************************************************1254*1255* FUNCTION: acpi_os_execute1256*1257* PARAMETERS: type - Type of execution1258* function - Address of the function to execute1259* context - Passed as a parameter to the function1260*1261* RETURN: Status.1262*1263* DESCRIPTION: Execute a new thread1264*1265*****************************************************************************/12661267acpi_status1268acpi_os_execute(acpi_execute_type type,1269acpi_osd_exec_callback function, void *context)1270{1271pthread_t thread;1272int ret;12731274ret =1275pthread_create(&thread, NULL, (PTHREAD_CALLBACK) function, context);1276if (ret) {1277acpi_os_printf("Create thread failed");1278}1279return (0);1280}12811282#else /* ACPI_SINGLE_THREADED */1283acpi_thread_id acpi_os_get_thread_id(void)1284{1285return (1);1286}12871288acpi_status1289acpi_os_execute(acpi_execute_type type,1290acpi_osd_exec_callback function, void *context)1291{12921293function(context);12941295return (AE_OK);1296}12971298#endif /* ACPI_SINGLE_THREADED */12991300/******************************************************************************1301*1302* FUNCTION: acpi_os_wait_events_complete1303*1304* PARAMETERS: None1305*1306* RETURN: None1307*1308* DESCRIPTION: Wait for all asynchronous events to complete. This1309* implementation does nothing.1310*1311*****************************************************************************/13121313void acpi_os_wait_events_complete(void)1314{1315return;1316}131713181319