diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-06 20:34:19 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-06 20:34:19 -0700 |
commit | 7725131982477bffff8ffdea143434dcc69f5d90 (patch) | |
tree | 099440f6a8b11c8221ea99effec4c22818b3b577 /tools | |
parent | 6b22df74f7af62137772c280791c932855f7635b (diff) | |
parent | 7ef97e0e3a0f4b02601dde384127cc85d27e46e2 (diff) | |
download | linux-7725131982477bffff8ffdea143434dcc69f5d90.tar.bz2 |
Merge tag 'pm+acpi-3.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull ACPI and power management updates from Rafael Wysocki:
"Again, ACPICA leads the pack (47 commits), followed by cpufreq (18
commits) and system suspend/hibernation (9 commits).
From the new code perspective, the ACPICA update brings ACPI 5.1 to
the table, including a new device configuration object called _DSD
(Device Specific Data) that will hopefully help us to operate device
properties like Device Trees do (at least to some extent) and changes
related to supporting ACPI on ARM.
Apart from that we have hibernation changes making it use radix trees
to store memory bitmaps which should speed up some operations carried
out by it quite significantly. We also have some power management
changes related to suspend-to-idle (the "freeze" sleep state) support
and more preliminary changes needed to support ACPI on ARM (outside of
ACPICA).
The rest is fixes and cleanups pretty much everywhere.
Specifics:
- ACPICA update to upstream version 20140724. That includes ACPI 5.1
material (support for the _CCA and _DSD predefined names, changes
related to the DMAR and PCCT tables and ARM support among other
things) and cleanups related to using ACPICA's header files. A
major part of it is related to acpidump and the core code used by
that utility. Changes from Bob Moore, David E Box, Lv Zheng,
Sascha Wildner, Tomasz Nowicki, Hanjun Guo.
- Radix trees for memory bitmaps used by the hibernation core from
Joerg Roedel.
- Support for waking up the system from suspend-to-idle (also known
as the "freeze" sleep state) using ACPI-based PCI wakeup signaling
(Rafael J Wysocki).
- Fixes for issues related to ACPI button events (Rafael J Wysocki).
- New device ID for an ACPI-enumerated device included into the
Wildcat Point PCH from Jie Yang.
- ACPI video updates related to backlight handling from Hans de Goede
and Linus Torvalds.
- Preliminary changes needed to support ACPI on ARM from Hanjun Guo
and Graeme Gregory.
- ACPI PNP core cleanups from Arjun Sreedharan and Zhang Rui.
- Cleanups related to ACPI_COMPANION() and ACPI_HANDLE() macros
(Rafael J Wysocki).
- ACPI-based device hotplug cleanups from Wei Yongjun and Rafael J
Wysocki.
- Cleanups and improvements related to system suspend from Lan
Tianyu, Randy Dunlap and Rafael J Wysocki.
- ACPI battery cleanup from Wei Yongjun.
- cpufreq core fixes from Viresh Kumar.
- Elimination of a deadband effect from the cpufreq ondemand governor
and intel_pstate driver cleanups from Stratos Karafotis.
- 350MHz CPU support for the powernow-k6 cpufreq driver from Mikulas
Patocka.
- Fix for the imx6 cpufreq driver from Anson Huang.
- cpuidle core and governor cleanups from Daniel Lezcano, Sandeep
Tripathy and Mohammad Merajul Islam Molla.
- Build fix for the big_little cpuidle driver from Sachin Kamat.
- Configuration fix for the Operation Performance Points (OPP)
framework from Mark Brown.
- APM cleanup from Jean Delvare.
- cpupower utility fixes and cleanups from Peter Senna Tschudin,
Andrey Utkin, Himangi Saraogi, Rickard Strandqvist, Thomas
Renninger"
* tag 'pm+acpi-3.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (118 commits)
ACPI / LPSS: add LPSS device for Wildcat Point PCH
ACPI / PNP: Replace faulty is_hex_digit() by isxdigit()
ACPICA: Update version to 20140724.
ACPICA: ACPI 5.1: Update for PCCT table changes.
ACPICA/ARM: ACPI 5.1: Update for GTDT table changes.
ACPICA/ARM: ACPI 5.1: Update for MADT changes.
ACPICA/ARM: ACPI 5.1: Update for FADT changes.
ACPICA: ACPI 5.1: Support for the _CCA predifined name.
ACPICA: ACPI 5.1: New notify value for System Affinity Update.
ACPICA: ACPI 5.1: Support for the _DSD predefined name.
ACPICA: Debug object: Add current value of Timer() to debug line prefix.
ACPICA: acpihelp: Add UUID support, restructure some existing files.
ACPICA: Utilities: Fix local printf issue.
ACPICA: Tables: Update for DMAR table changes.
ACPICA: Remove some extraneous printf arguments.
ACPICA: Update for comments/formatting. No functional changes.
ACPICA: Disassembler: Add support for the ToUUID opererator (macro).
ACPICA: Remove a redundant cast to acpi_size for ACPI_OFFSET() macro.
ACPICA: Work around an ancient GCC bug.
ACPI / processor: Make it possible to get local x2apic id via _MAT
...
Diffstat (limited to 'tools')
-rw-r--r-- | tools/power/acpi/Makefile | 5 | ||||
-rw-r--r-- | tools/power/acpi/common/cmfsize.c | 20 | ||||
-rw-r--r-- | tools/power/acpi/common/getopt.c | 14 | ||||
-rw-r--r-- | tools/power/acpi/os_specific/service_layers/oslibcfs.c | 214 | ||||
-rw-r--r-- | tools/power/acpi/os_specific/service_layers/oslinuxtbl.c | 48 | ||||
-rw-r--r-- | tools/power/acpi/os_specific/service_layers/osunixxf.c | 1311 | ||||
-rw-r--r-- | tools/power/acpi/tools/acpidump/acpidump.h | 3 | ||||
-rw-r--r-- | tools/power/acpi/tools/acpidump/apdump.c | 108 | ||||
-rw-r--r-- | tools/power/acpi/tools/acpidump/apfiles.c | 92 | ||||
-rw-r--r-- | tools/power/acpi/tools/acpidump/apmain.c | 96 | ||||
-rw-r--r-- | tools/power/cpupower/bench/parse.c | 39 | ||||
-rw-r--r-- | tools/power/cpupower/utils/cpufreq-set.c | 11 | ||||
-rw-r--r-- | tools/power/cpupower/utils/helpers/sysfs.c | 2 | ||||
-rw-r--r-- | tools/power/cpupower/utils/idle_monitor/mperf_monitor.c | 2 |
14 files changed, 1772 insertions, 193 deletions
diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile index e5a3c4be2a10..3d1537b93c64 100644 --- a/tools/power/acpi/Makefile +++ b/tools/power/acpi/Makefile @@ -108,13 +108,18 @@ DUMP_OBJS = \ apmain.o\ osunixdir.o\ osunixmap.o\ + osunixxf.o\ tbprint.o\ tbxfroot.o\ utbuffer.o\ + utdebug.o\ utexcep.o\ + utglobal.o\ utmath.o\ + utprint.o\ utstring.o\ utxferror.o\ + oslibcfs.o\ oslinuxtbl.o\ cmfsize.o\ getopt.o diff --git a/tools/power/acpi/common/cmfsize.c b/tools/power/acpi/common/cmfsize.c index 5140e5edae1f..f4b953354ff7 100644 --- a/tools/power/acpi/common/cmfsize.c +++ b/tools/power/acpi/common/cmfsize.c @@ -58,44 +58,46 @@ ACPI_MODULE_NAME("cmfsize") * RETURN: File Size. On error, -1 (ACPI_UINT32_MAX) * * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open. - * Does not disturb the current file pointer. Uses perror for - * error messages. + * Does not disturb the current file pointer. * ******************************************************************************/ -u32 cm_get_file_size(FILE * file) +u32 cm_get_file_size(ACPI_FILE file) { long file_size; long current_offset; + acpi_status status; /* Save the current file pointer, seek to EOF to obtain file size */ - current_offset = ftell(file); + current_offset = acpi_os_get_file_offset(file); if (current_offset < 0) { goto offset_error; } - if (fseek(file, 0, SEEK_END)) { + status = acpi_os_set_file_offset(file, 0, ACPI_FILE_END); + if (ACPI_FAILURE(status)) { goto seek_error; } - file_size = ftell(file); + file_size = acpi_os_get_file_offset(file); if (file_size < 0) { goto offset_error; } /* Restore original file pointer */ - if (fseek(file, current_offset, SEEK_SET)) { + status = acpi_os_set_file_offset(file, current_offset, ACPI_FILE_BEGIN); + if (ACPI_FAILURE(status)) { goto seek_error; } return ((u32)file_size); offset_error: - perror("Could not get file offset"); + acpi_log_error("Could not get file offset"); return (ACPI_UINT32_MAX); seek_error: - perror("Could not seek file"); + acpi_log_error("Could not set file offset"); return (ACPI_UINT32_MAX); } diff --git a/tools/power/acpi/common/getopt.c b/tools/power/acpi/common/getopt.c index a302f52e4fd3..2f0f34a36db4 100644 --- a/tools/power/acpi/common/getopt.c +++ b/tools/power/acpi/common/getopt.c @@ -51,14 +51,12 @@ * "f|" - Option has required single-char sub-options */ -#include <stdio.h> -#include <string.h> #include <acpi/acpi.h> #include "accommon.h" #include "acapps.h" #define ACPI_OPTION_ERROR(msg, badchar) \ - if (acpi_gbl_opterr) {fprintf (stderr, "%s%c\n", msg, badchar);} + if (acpi_gbl_opterr) {acpi_log_error ("%s%c\n", msg, badchar);} int acpi_gbl_opterr = 1; int acpi_gbl_optind = 1; @@ -113,7 +111,7 @@ int acpi_getopt_argument(int argc, char **argv) * PARAMETERS: argc, argv - from main * opts - options info list * - * RETURN: Option character or EOF + * RETURN: Option character or ACPI_OPT_END * * DESCRIPTION: Get the next option * @@ -128,10 +126,10 @@ int acpi_getopt(int argc, char **argv, char *opts) if (acpi_gbl_optind >= argc || argv[acpi_gbl_optind][0] != '-' || argv[acpi_gbl_optind][1] == '\0') { - return (EOF); - } else if (strcmp(argv[acpi_gbl_optind], "--") == 0) { + return (ACPI_OPT_END); + } else if (ACPI_STRCMP(argv[acpi_gbl_optind], "--") == 0) { acpi_gbl_optind++; - return (EOF); + return (ACPI_OPT_END); } } @@ -142,7 +140,7 @@ int acpi_getopt(int argc, char **argv, char *opts) /* Make sure that the option is legal */ if (current_char == ':' || - (opts_ptr = strchr(opts, current_char)) == NULL) { + (opts_ptr = ACPI_STRCHR(opts, current_char)) == NULL) { ACPI_OPTION_ERROR("Illegal option: -", current_char); if (argv[acpi_gbl_optind][++current_char_ptr] == '\0') { diff --git a/tools/power/acpi/os_specific/service_layers/oslibcfs.c b/tools/power/acpi/os_specific/service_layers/oslibcfs.c new file mode 100644 index 000000000000..c13ff9c51d74 --- /dev/null +++ b/tools/power/acpi/os_specific/service_layers/oslibcfs.c @@ -0,0 +1,214 @@ +/****************************************************************************** + * + * Module Name: oslibcfs - C library OSL for file I/O + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2014, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <acpi/acpi.h> +#include <stdio.h> +#include <stdarg.h> + +#define _COMPONENT ACPI_OS_SERVICES +ACPI_MODULE_NAME("oslibcfs") + +/******************************************************************************* + * + * FUNCTION: acpi_os_open_file + * + * PARAMETERS: path - File path + * modes - File operation type + * + * RETURN: File descriptor. + * + * DESCRIPTION: Open a file for reading (ACPI_FILE_READING) or/and writing + * (ACPI_FILE_WRITING). + * + ******************************************************************************/ +ACPI_FILE acpi_os_open_file(const char *path, u8 modes) +{ + ACPI_FILE file; + u32 i = 0; + char modes_str[4]; + + if (modes & ACPI_FILE_READING) { + modes_str[i++] = 'r'; + } + if (modes & ACPI_FILE_WRITING) { + modes_str[i++] = 'w'; + } + if (modes & ACPI_FILE_BINARY) { + modes_str[i++] = 'b'; + } + + modes_str[i++] = '\0'; + + file = fopen(path, modes_str); + if (!file) { + perror("Could not open file"); + } + + return (file); +} + +/******************************************************************************* + * + * FUNCTION: acpi_os_close_file + * + * PARAMETERS: file - An open file descriptor + * + * RETURN: None. + * + * DESCRIPTION: Close a file opened via acpi_os_open_file. + * + ******************************************************************************/ + +void acpi_os_close_file(ACPI_FILE file) +{ + fclose(file); +} + +/******************************************************************************* + * + * FUNCTION: acpi_os_read_file + * + * PARAMETERS: file - An open file descriptor + * buffer - Data buffer + * size - Data block size + * count - Number of data blocks + * + * RETURN: Number of bytes actually read. + * + * DESCRIPTION: Read from a file. + * + ******************************************************************************/ + +int +acpi_os_read_file(ACPI_FILE file, void *buffer, acpi_size size, acpi_size count) +{ + int length; + + length = fread(buffer, size, count, file); + if (length < 0) { + perror("Error reading file"); + } + + return (length); +} + +/******************************************************************************* + * + * FUNCTION: acpi_os_write_file + * + * PARAMETERS: file - An open file descriptor + * buffer - Data buffer + * size - Data block size + * count - Number of data blocks + * + * RETURN: Number of bytes actually written. + * + * DESCRIPTION: Write to a file. + * + ******************************************************************************/ + +int +acpi_os_write_file(ACPI_FILE file, + void *buffer, acpi_size size, acpi_size count) +{ + int length; + + length = fwrite(buffer, size, count, file); + if (length < 0) { + perror("Error writing file"); + } + + return (length); +} + +/******************************************************************************* + * + * FUNCTION: acpi_os_get_file_offset + * + * PARAMETERS: file - An open file descriptor + * + * RETURN: Current file pointer position. + * + * DESCRIPTION: Get current file offset. + * + ******************************************************************************/ + +long acpi_os_get_file_offset(ACPI_FILE file) +{ + long offset; + + offset = ftell(file); + return (offset); +} + +/******************************************************************************* + * + * FUNCTION: acpi_os_set_file_offset + * + * PARAMETERS: file - An open file descriptor + * offset - New file offset + * from - From begin/end of file + * + * RETURN: Status + * + * DESCRIPTION: Set current file offset. + * + ******************************************************************************/ + +acpi_status acpi_os_set_file_offset(ACPI_FILE file, long offset, u8 from) +{ + int ret = 0; + + if (from == ACPI_FILE_BEGIN) { + ret = fseek(file, offset, SEEK_SET); + } + if (from == ACPI_FILE_END) { + ret = fseek(file, offset, SEEK_END); + } + + if (ret < 0) { + return (AE_ERROR); + } else { + return (AE_OK); + } +} diff --git a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c index 28c52008e854..0dc2485dedf5 100644 --- a/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c +++ b/tools/power/acpi/os_specific/service_layers/oslinuxtbl.c @@ -77,6 +77,9 @@ osl_map_table(acpi_size address, static void osl_unmap_table(struct acpi_table_header *table); +static acpi_physical_address +osl_find_rsdp_via_efi_by_keyword(FILE * file, const char *keyword); + static acpi_physical_address osl_find_rsdp_via_efi(void); static acpi_status osl_load_rsdp(void); @@ -417,6 +420,38 @@ acpi_os_get_table_by_index(u32 index, /****************************************************************************** * + * FUNCTION: osl_find_rsdp_via_efi_by_keyword + * + * PARAMETERS: keyword - Character string indicating ACPI GUID version + * in the EFI table + * + * RETURN: RSDP address if found + * + * DESCRIPTION: Find RSDP address via EFI using keyword indicating the ACPI + * GUID version. + * + *****************************************************************************/ + +static acpi_physical_address +osl_find_rsdp_via_efi_by_keyword(FILE * file, const char *keyword) +{ + char buffer[80]; + unsigned long long address = 0; + char format[32]; + + snprintf(format, 32, "%s=%s", keyword, "%llx"); + fseek(file, 0, SEEK_SET); + while (fgets(buffer, 80, file)) { + if (sscanf(buffer, format, &address) == 1) { + break; + } + } + + return ((acpi_physical_address) (address)); +} + +/****************************************************************************** + * * FUNCTION: osl_find_rsdp_via_efi * * PARAMETERS: None @@ -430,20 +465,19 @@ acpi_os_get_table_by_index(u32 index, static acpi_physical_address osl_find_rsdp_via_efi(void) { FILE *file; - char buffer[80]; - unsigned long address = 0; + acpi_physical_address address = 0; file = fopen(EFI_SYSTAB, "r"); if (file) { - while (fgets(buffer, 80, file)) { - if (sscanf(buffer, "ACPI20=0x%lx", &address) == 1) { - break; - } + address = osl_find_rsdp_via_efi_by_keyword(file, "ACPI20"); + if (!address) { + address = + osl_find_rsdp_via_efi_by_keyword(file, "ACPI"); } fclose(file); } - return ((acpi_physical_address) (address)); + return (address); } /****************************************************************************** diff --git a/tools/power/acpi/os_specific/service_layers/osunixxf.c b/tools/power/acpi/os_specific/service_layers/osunixxf.c new file mode 100644 index 000000000000..60b58cd18410 --- /dev/null +++ b/tools/power/acpi/os_specific/service_layers/osunixxf.c @@ -0,0 +1,1311 @@ +/****************************************************************************** + * + * Module Name: osunixxf - UNIX OSL interfaces + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2014, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +/* + * These interfaces are required in order to compile the ASL compiler and the + * various ACPICA tools under Linux or other Unix-like system. + */ +#include <acpi/acpi.h> +#include "accommon.h" +#include "amlcode.h" +#include "acparser.h" +#include "acdebug.h" + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <unistd.h> +#include <sys/time.h> +#include <semaphore.h> +#include <pthread.h> +#include <errno.h> + +#define _COMPONENT ACPI_OS_SERVICES +ACPI_MODULE_NAME("osunixxf") + +u8 acpi_gbl_debug_timeout = FALSE; + +/* Upcalls to acpi_exec */ + +void +ae_table_override(struct acpi_table_header *existing_table, + struct acpi_table_header **new_table); + +typedef void *(*PTHREAD_CALLBACK) (void *); + +/* Buffer used by acpi_os_vprintf */ + +#define ACPI_VPRINTF_BUFFER_SIZE 512 +#define _ASCII_NEWLINE '\n' + +/* Terminal support for acpi_exec only */ + +#ifdef ACPI_EXEC_APP +#include <termios.h> + +struct termios original_term_attributes; +int term_attributes_were_set = 0; + +acpi_status acpi_ut_read_line(char *buffer, u32 buffer_length, u32 *bytes_read); + +static void os_enter_line_edit_mode(void); + +static void os_exit_line_edit_mode(void); + +/****************************************************************************** + * + * FUNCTION: os_enter_line_edit_mode, os_exit_line_edit_mode + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Enter/Exit the raw character input mode for the terminal. + * + * Interactive line-editing support for the AML debugger. Used with the + * common/acgetline module. + * + * readline() is not used because of non-portability. It is not available + * on all systems, and if it is, often the package must be manually installed. + * + * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line + * editing that we need in acpi_os_get_line. + * + * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these + * calls will also work: + * For os_enter_line_edit_mode: system ("stty cbreak -echo") + * For os_exit_line_edit_mode: system ("stty cooked echo") + * + *****************************************************************************/ + +static void os_enter_line_edit_mode(void) +{ + struct termios local_term_attributes; + + /* Get and keep the original attributes */ + + if (tcgetattr(STDIN_FILENO, &original_term_attributes)) { + fprintf(stderr, "Could not get terminal attributes!\n"); + return; + } + + /* Set the new attributes to enable raw character input */ + + memcpy(&local_term_attributes, &original_term_attributes, + sizeof(struct termios)); + + local_term_attributes.c_lflag &= ~(ICANON | ECHO); + local_term_attributes.c_cc[VMIN] = 1; + local_term_attributes.c_cc[VTIME] = 0; + + if (tcsetattr(STDIN_FILENO, TCSANOW, &local_term_attributes)) { + fprintf(stderr, "Could not set terminal attributes!\n"); + return; + } + + term_attributes_were_set = 1; +} + +static void os_exit_line_edit_mode(void) +{ + + if (!term_attributes_were_set) { + return; + } + + /* Set terminal attributes back to the original values */ + + if (tcsetattr(STDIN_FILENO, TCSANOW, &original_term_attributes)) { + fprintf(stderr, "Could not restore terminal attributes!\n"); + } +} + +#else + +/* These functions are not needed for other ACPICA utilities */ + +#define os_enter_line_edit_mode() +#define os_exit_line_edit_mode() +#endif + +/****************************************************************************** + * + * FUNCTION: acpi_os_initialize, acpi_os_terminate + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Initialize and terminate this module. + * + *****************************************************************************/ + +acpi_status acpi_os_initialize(void) +{ + acpi_status status; + + acpi_gbl_output_file = stdout; + + os_enter_line_edit_mode(); + + status = acpi_os_create_lock(&acpi_gbl_print_lock); + if (ACPI_FAILURE(status)) { + return (status); + } + + return (AE_OK); +} + +acpi_status acpi_os_terminate(void) +{ + + os_exit_line_edit_mode(); + return (AE_OK); +} + +#ifndef ACPI_USE_NATIVE_RSDP_POINTER +/****************************************************************************** + * + * FUNCTION: acpi_os_get_root_pointer + * + * PARAMETERS: None + * + * RETURN: RSDP physical address + * + * DESCRIPTION: Gets the ACPI root pointer (RSDP) + * + *****************************************************************************/ + +acpi_physical_address acpi_os_get_root_pointer(void) +{ + + return (0); +} +#endif + +/****************************************************************************** + * + * FUNCTION: acpi_os_predefined_override + * + * PARAMETERS: init_val - Initial value of the predefined object + * new_val - The new value for the object + * + * RETURN: Status, pointer to value. Null pointer returned if not + * overriding. + * + * DESCRIPTION: Allow the OS to override predefined names + * + *****************************************************************************/ + +acpi_status +acpi_os_predefined_override(const struct acpi_predefined_names * init_val, + acpi_string * new_val) +{ + + if (!init_val || !new_val) { + return (AE_BAD_PARAMETER); + } + + *new_val = NULL; + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_table_override + * + * PARAMETERS: existing_table - Header of current table (probably + * firmware) + * new_table - Where an entire new table is returned. + * + * RETURN: Status, pointer to new table. Null pointer returned if no + * table is available to override + * + * DESCRIPTION: Return a different version of a table if one is available + * + *****************************************************************************/ + +acpi_status +acpi_os_table_override(struct acpi_table_header * existing_table, + struct acpi_table_header ** new_table) +{ + + if (!existing_table || !new_table) { + return (AE_BAD_PARAMETER); + } + + *new_table = NULL; + +#ifdef ACPI_EXEC_APP + + ae_table_override(existing_table, new_table); + return (AE_OK); +#else + + return (AE_NO_ACPI_TABLES); +#endif +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_physical_table_override + * + * PARAMETERS: existing_table - Header of current table (probably firmware) + * new_address - Where new table address is returned + * (Physical address) + * new_table_length - Where new table length is returned + * + * RETURN: Status, address/length of new table. Null pointer returned + * if no table is available to override. + * + * DESCRIPTION: Returns AE_SUPPORT, function not used in user space. + * + *****************************************************************************/ + +acpi_status +acpi_os_physical_table_override(struct acpi_table_header * existing_table, + acpi_physical_address * new_address, + u32 *new_table_length) +{ + + return (AE_SUPPORT); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_redirect_output + * + * PARAMETERS: destination - An open file handle/pointer + * + * RETURN: None + * + * DESCRIPTION: Causes redirect of acpi_os_printf and acpi_os_vprintf + * + *****************************************************************************/ + +void acpi_os_redirect_output(void *destination) +{ + + acpi_gbl_output_file = destination; +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_printf + * + * PARAMETERS: fmt, ... - Standard printf format + * + * RETURN: None + * + * DESCRIPTION: Formatted output. Note: very similar to acpi_os_vprintf + * (performance), changes should be tracked in both functions. + * + *****************************************************************************/ + +void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...) +{ + va_list args; + u8 flags; + + flags = acpi_gbl_db_output_flags; + if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) { + + /* Output is directable to either a file (if open) or the console */ + + if (acpi_gbl_debug_file) { + + /* Output file is open, send the output there */ + + va_start(args, fmt); + vfprintf(acpi_gbl_debug_file, fmt, args); + va_end(args); + } else { + /* No redirection, send output to console (once only!) */ + + flags |= ACPI_DB_CONSOLE_OUTPUT; + } + } + + if (flags & ACPI_DB_CONSOLE_OUTPUT) { + va_start(args, fmt); + vfprintf(acpi_gbl_output_file, fmt, args); + va_end(args); + } +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_vprintf + * + * PARAMETERS: fmt - Standard printf format + * args - Argument list + * + * RETURN: None + * + * DESCRIPTION: Formatted output with argument list pointer. Note: very + * similar to acpi_os_printf, changes should be tracked in both + * functions. + * + *****************************************************************************/ + +void acpi_os_vprintf(const char *fmt, va_list args) +{ + u8 flags; + char buffer[ACPI_VPRINTF_BUFFER_SIZE]; + + /* + * We build the output string in a local buffer because we may be + * outputting the buffer twice. Using vfprintf is problematic because + * some implementations modify the args pointer/structure during + * execution. Thus, we use the local buffer for portability. + * + * Note: Since this module is intended for use by the various ACPICA + * utilities/applications, we can safely declare the buffer on the stack. + * Also, This function is used for relatively small error messages only. + */ + vsnprintf(buffer, ACPI_VPRINTF_BUFFER_SIZE, fmt, args); + + flags = acpi_gbl_db_output_flags; + if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) { + + /* Output is directable to either a file (if open) or the console */ + + if (acpi_gbl_debug_file) { + + /* Output file is open, send the output there */ + + fputs(buffer, acpi_gbl_debug_file); + } else { + /* No redirection, send output to console (once only!) */ + + flags |= ACPI_DB_CONSOLE_OUTPUT; + } + } + + if (flags & ACPI_DB_CONSOLE_OUTPUT) { + fputs(buffer, acpi_gbl_output_file); + } +} + +#ifndef ACPI_EXEC_APP +/****************************************************************************** + * + * FUNCTION: acpi_os_get_line + * + * PARAMETERS: buffer - Where to return the command line + * buffer_length - Maximum length of Buffer + * bytes_read - Where the actual byte count is returned + * + * RETURN: Status and actual bytes read + * + * DESCRIPTION: Get the next input line from the terminal. NOTE: For the + * acpi_exec utility, we use the acgetline module instead to + * provide line-editing and history support. + * + *****************************************************************************/ + +acpi_status acpi_os_get_line(char *buffer, u32 buffer_length, u32 *bytes_read) +{ + int input_char; + u32 end_of_line; + + /* Standard acpi_os_get_line for all utilities except acpi_exec */ + + for (end_of_line = 0;; end_of_line++) { + if (end_of_line >= buffer_length) { + return (AE_BUFFER_OVERFLOW); + } + + if ((input_char = getchar()) == EOF) { + return (AE_ERROR); + } + + if (!input_char || input_char == _ASCII_NEWLINE) { + break; + } + + buffer[end_of_line] = (char)input_char; + } + + /* Null terminate the buffer */ + + buffer[end_of_line] = 0; + + /* Return the number of bytes in the string */ + + if (bytes_read) { + *bytes_read = end_of_line; + } + + return (AE_OK); +} +#endif + +#ifndef ACPI_USE_NATIVE_MEMORY_MAPPING +/****************************************************************************** + * + * FUNCTION: acpi_os_map_memory + * + * PARAMETERS: where - Physical address of memory to be mapped + * length - How much memory to map + * + * RETURN: Pointer to mapped memory. Null on error. + * + * DESCRIPTION: Map physical memory into caller's address space + * + *****************************************************************************/ + +void *acpi_os_map_memory(acpi_physical_address where, acpi_size length) +{ + + return (ACPI_TO_POINTER((acpi_size) where)); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_unmap_memory + * + * PARAMETERS: where - Logical address of memory to be unmapped + * length - How much memory to unmap + * + * RETURN: None. + * + * DESCRIPTION: Delete a previously created mapping. Where and Length must + * correspond to a previous mapping exactly. + * + *****************************************************************************/ + +void acpi_os_unmap_memory(void *where, acpi_size length) +{ + + return; +} +#endif + +/****************************************************************************** + * + * FUNCTION: acpi_os_allocate + * + * PARAMETERS: size - Amount to allocate, in bytes + * + * RETURN: Pointer to the new allocation. Null on error. + * + * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS. + * + *****************************************************************************/ + +void *acpi_os_allocate(acpi_size size) +{ + void *mem; + + mem = (void *)malloc((size_t) size); + return (mem); +} + +#ifdef USE_NATIVE_ALLOCATE_ZEROED +/****************************************************************************** + * + * FUNCTION: acpi_os_allocate_zeroed + * + * PARAMETERS: size - Amount to allocate, in bytes + * + * RETURN: Pointer to the new allocation. Null on error. + * + * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS. + * + *****************************************************************************/ + +void *acpi_os_allocate_zeroed(acpi_size size) +{ + void *mem; + + mem = (void *)calloc(1, (size_t) size); + return (mem); +} +#endif + +/****************************************************************************** + * + * FUNCTION: acpi_os_free + * + * PARAMETERS: mem - Pointer to previously allocated memory + * + * RETURN: None. + * + * DESCRIPTION: Free memory allocated via acpi_os_allocate + * + *****************************************************************************/ + +void acpi_os_free(void *mem) +{ + + free(mem); +} + +#ifdef ACPI_SINGLE_THREADED +/****************************************************************************** + * + * FUNCTION: Semaphore stub functions + * + * DESCRIPTION: Stub functions used for single-thread applications that do + * not require semaphore synchronization. Full implementations + * of these functions appear after the stubs. + * + *****************************************************************************/ + +acpi_status +acpi_os_create_semaphore(u32 max_units, + u32 initial_units, acpi_handle * out_handle) +{ + *out_handle = (acpi_handle) 1; + return (AE_OK); +} + +acpi_status acpi_os_delete_semaphore(acpi_handle handle) +{ + return (AE_OK); +} + +acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) +{ + return (AE_OK); +} + +acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) +{ + return (AE_OK); +} + +#else +/****************************************************************************** + * + * FUNCTION: acpi_os_create_semaphore + * + * PARAMETERS: initial_units - Units to be assigned to the new semaphore + * out_handle - Where a handle will be returned + * + * RETURN: Status + * + * DESCRIPTION: Create an OS semaphore + * + *****************************************************************************/ + +acpi_status +acpi_os_create_semaphore(u32 max_units, + u32 initial_units, acpi_handle * out_handle) +{ + sem_t *sem; + + if (!out_handle) { + return (AE_BAD_PARAMETER); + } +#ifdef __APPLE__ + { + char *semaphore_name = tmpnam(NULL); + + sem = + sem_open(semaphore_name, O_EXCL | O_CREAT, 0755, + initial_units); + if (!sem) { + return (AE_NO_MEMORY); + } + sem_unlink(semaphore_name); /* This just deletes the name */ + } + +#else + sem = acpi_os_allocate(sizeof(sem_t)); + if (!sem) { + return (AE_NO_MEMORY); + } + + if (sem_init(sem, 0, initial_units) == -1) { + acpi_os_free(sem); + return (AE_BAD_PARAMETER); + } +#endif + + *out_handle = (acpi_handle) sem; + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_delete_semaphore + * + * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore + * + * RETURN: Status + * + * DESCRIPTION: Delete an OS semaphore + * + *****************************************************************************/ + +acpi_status acpi_os_delete_semaphore(acpi_handle handle) +{ + sem_t *sem = (sem_t *) handle; + + if (!sem) { + return (AE_BAD_PARAMETER); + } + + if (sem_destroy(sem) == -1) { + return (AE_BAD_PARAMETER); + } + + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_wait_semaphore + * + * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore + * units - How many units to wait for + * msec_timeout - How long to wait (milliseconds) + * + * RETURN: Status + * + * DESCRIPTION: Wait for units + * + *****************************************************************************/ + +acpi_status +acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 msec_timeout) +{ + acpi_status status = AE_OK; + sem_t *sem = (sem_t *) handle; +#ifndef ACPI_USE_ALTERNATE_TIMEOUT + struct timespec time; + int ret_val; +#endif + + if (!sem) { + return (AE_BAD_PARAMETER); + } + + switch (msec_timeout) { + /* + * No Wait: + * -------- + * A zero timeout value indicates that we shouldn't wait - just + * acquire the semaphore if available otherwise return AE_TIME + * (a.k.a. 'would block'). + */ + case 0: + + if (sem_trywait(sem) == -1) { + status = (AE_TIME); + } + break; + + /* Wait Indefinitely */ + + case ACPI_WAIT_FOREVER: + + if (sem_wait(sem)) { + status = (AE_TIME); + } + break; + + /* Wait with msec_timeout */ + + default: + +#ifdef ACPI_USE_ALTERNATE_TIMEOUT + /* + * Alternate timeout mechanism for environments where + * sem_timedwait is not available or does not work properly. + */ + while (msec_timeout) { + if (sem_trywait(sem) == 0) { + + /* Got the semaphore */ + return (AE_OK); + } + + if (msec_timeout >= 10) { + msec_timeout -= 10; + usleep(10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */ + } else { + msec_timeout--; + usleep(ACPI_USEC_PER_MSEC); /* one millisecond */ + } + } + status = (AE_TIME); +#else + /* + * The interface to sem_timedwait is an absolute time, so we need to + * get the current time, then add in the millisecond Timeout value. + */ + if (clock_gettime(CLOCK_REALTIME, &time) == -1) { + perror("clock_gettime"); + return (AE_TIME); + } + + time.tv_sec += (msec_timeout / ACPI_MSEC_PER_SEC); + time.tv_nsec += + ((msec_timeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC); + + /* Handle nanosecond overflow (field must be less than one second) */ + + if (time.tv_nsec >= ACPI_NSEC_PER_SEC) { + time.tv_sec += (time.tv_nsec / ACPI_NSEC_PER_SEC); + time.tv_nsec = (time.tv_nsec % ACPI_NSEC_PER_SEC); + } + + while (((ret_val = sem_timedwait(sem, &time)) == -1) + && (errno == EINTR)) { + continue; + } + + if (ret_val != 0) { + if (errno != ETIMEDOUT) { + perror("sem_timedwait"); + } + status = (AE_TIME); + } +#endif + break; + } + + return (status); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_signal_semaphore + * + * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore + * units - Number of units to send + * + * RETURN: Status + * + * DESCRIPTION: Send units + * + *****************************************************************************/ + +acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) +{ + sem_t *sem = (sem_t *) handle; + + if (!sem) { + return (AE_BAD_PARAMETER); + } + + if (sem_post(sem) == -1) { + return (AE_LIMIT); + } + + return (AE_OK); +} + +#endif /* ACPI_SINGLE_THREADED */ + +/****************************************************************************** + * + * FUNCTION: Spinlock interfaces + * + * DESCRIPTION: Map these interfaces to semaphore interfaces + * + *****************************************************************************/ + +acpi_status acpi_os_create_lock(acpi_spinlock * out_handle) +{ + + return (acpi_os_create_semaphore(1, 1, out_handle)); +} + +void acpi_os_delete_lock(acpi_spinlock handle) +{ + acpi_os_delete_semaphore(handle); +} + +acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle) +{ + acpi_os_wait_semaphore(handle, 1, 0xFFFF); + return (0); +} + +void acpi_os_release_lock(acpi_spinlock handle, acpi_cpu_flags flags) +{ + acpi_os_signal_semaphore(handle, 1); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_install_interrupt_handler + * + * PARAMETERS: interrupt_number - Level handler should respond to. + * isr - Address of the ACPI interrupt handler + * except_ptr - Where status is returned + * + * RETURN: Handle to the newly installed handler. + * + * DESCRIPTION: Install an interrupt handler. Used to install the ACPI + * OS-independent handler. + * + *****************************************************************************/ + +u32 +acpi_os_install_interrupt_handler(u32 interrupt_number, + acpi_osd_handler service_routine, + void *context) +{ + + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_remove_interrupt_handler + * + * PARAMETERS: handle - Returned when handler was installed + * + * RETURN: Status + * + * DESCRIPTION: Uninstalls an interrupt handler. + * + *****************************************************************************/ + +acpi_status +acpi_os_remove_interrupt_handler(u32 interrupt_number, + acpi_osd_handler service_routine) +{ + + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_stall + * + * PARAMETERS: microseconds - Time to sleep + * + * RETURN: Blocks until sleep is completed. + * + * DESCRIPTION: Sleep at microsecond granularity + * + *****************************************************************************/ + +void acpi_os_stall(u32 microseconds) +{ + + if (microseconds) { + usleep(microseconds); + } +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_sleep + * + * PARAMETERS: milliseconds - Time to sleep + * + * RETURN: Blocks until sleep is completed. + * + * DESCRIPTION: Sleep at millisecond granularity + * + *****************************************************************************/ + +void acpi_os_sleep(u64 milliseconds) +{ + + /* Sleep for whole seconds */ + + sleep(milliseconds / ACPI_MSEC_PER_SEC); + + /* + * Sleep for remaining microseconds. + * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second). + */ + usleep((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_get_timer + * + * PARAMETERS: None + * + * RETURN: Current time in 100 nanosecond units + * + * DESCRIPTION: Get the current system time + * + *****************************************************************************/ + +u64 acpi_os_get_timer(void) +{ + struct timeval time; + + /* This timer has sufficient resolution for user-space application code */ + + gettimeofday(&time, NULL); + + /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */ + + return (((u64)time.tv_sec * ACPI_100NSEC_PER_SEC) + + ((u64)time.tv_usec * ACPI_100NSEC_PER_USEC)); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_read_pci_configuration + * + * PARAMETERS: pci_id - Seg/Bus/Dev + * pci_register - Device Register + * value - Buffer where value is placed + * width - Number of bits + * + * RETURN: Status + * + * DESCRIPTION: Read data from PCI configuration space + * + *****************************************************************************/ + +acpi_status +acpi_os_read_pci_configuration(struct acpi_pci_id *pci_id, + u32 pci_register, u64 *value, u32 width) +{ + + *value = 0; + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_write_pci_configuration + * + * PARAMETERS: pci_id - Seg/Bus/Dev + * pci_register - Device Register + * value - Value to be written + * width - Number of bits + * + * RETURN: Status. + * + * DESCRIPTION: Write data to PCI configuration space + * + *****************************************************************************/ + +acpi_status +acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, + u32 pci_register, u64 value, u32 width) +{ + + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_read_port + * + * PARAMETERS: address - Address of I/O port/register to read + * value - Where value is placed + * width - Number of bits + * + * RETURN: Value read from port + * + * DESCRIPTION: Read data from an I/O port or register + * + *****************************************************************************/ + +acpi_status acpi_os_read_port(acpi_io_address address, u32 *value, u32 width) +{ + + switch (width) { + case 8: + + *value = 0xFF; + break; + + case 16: + + *value = 0xFFFF; + break; + + case 32: + + *value = 0xFFFFFFFF; + break; + + default: + + return (AE_BAD_PARAMETER); + } + + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_write_port + * + * PARAMETERS: address - Address of I/O port/register to write + * value - Value to write + * width - Number of bits + * + * RETURN: None + * + * DESCRIPTION: Write data to an I/O port or register + * + *****************************************************************************/ + +acpi_status acpi_os_write_port(acpi_io_address address, u32 value, u32 width) +{ + + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_read_memory + * + * PARAMETERS: address - Physical Memory Address to read + * value - Where value is placed + * width - Number of bits (8,16,32, or 64) + * + * RETURN: Value read from physical memory address. Always returned + * as a 64-bit integer, regardless of the read width. + * + * DESCRIPTION: Read data from a physical memory address + * + *****************************************************************************/ + +acpi_status +acpi_os_read_memory(acpi_physical_address address, u64 *value, u32 width) +{ + + switch (width) { + case 8: + case 16: + case 32: + case 64: + + *value = 0; + break; + + default: + + return (AE_BAD_PARAMETER); + } + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_write_memory + * + * PARAMETERS: address - Physical Memory Address to write + * value - Value to write + * width - Number of bits (8,16,32, or 64) + * + * RETURN: None + * + * DESCRIPTION: Write data to a physical memory address + * + *****************************************************************************/ + +acpi_status +acpi_os_write_memory(acpi_physical_address address, u64 value, u32 width) +{ + + return (AE_OK); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_readable + * + * PARAMETERS: pointer - Area to be verified + * length - Size of area + * + * RETURN: TRUE if readable for entire length + * + * DESCRIPTION: Verify that a pointer is valid for reading + * + *****************************************************************************/ + +u8 acpi_os_readable(void *pointer, acpi_size length) +{ + + return (TRUE); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_writable + * + * PARAMETERS: pointer - Area to be verified + * length - Size of area + * + * RETURN: TRUE if writable for entire length + * + * DESCRIPTION: Verify that a pointer is valid for writing + * + *****************************************************************************/ + +u8 acpi_os_writable(void *pointer, acpi_size length) +{ + + return (TRUE); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_signal + * + * PARAMETERS: function - ACPI A signal function code + * info - Pointer to function-dependent structure + * + * RETURN: Status + * + * DESCRIPTION: Miscellaneous functions. Example implementation only. + * + *****************************************************************************/ + +acpi_status acpi_os_signal(u32 function, void *info) +{ + + switch (function) { + case ACPI_SIGNAL_FATAL: + + break; + + case ACPI_SIGNAL_BREAKPOINT: + + break; + + default: + + break; + } + + return (AE_OK); +} + +/* Optional multi-thread support */ + +#ifndef ACPI_SINGLE_THREADED +/****************************************************************************** + * + * FUNCTION: acpi_os_get_thread_id + * + * PARAMETERS: None + * + * RETURN: Id of the running thread + * + * DESCRIPTION: Get the ID of the current (running) thread + * + *****************************************************************************/ + +acpi_thread_id acpi_os_get_thread_id(void) +{ + pthread_t thread; + + thread = pthread_self(); + return (ACPI_CAST_PTHREAD_T(thread)); +} + +/****************************************************************************** + * + * FUNCTION: acpi_os_execute + * + * PARAMETERS: type - Type of execution + * function - Address of the function to execute + * context - Passed as a parameter to the function + * + * RETURN: Status. + * + * DESCRIPTION: Execute a new thread + * + *****************************************************************************/ + +acpi_status +acpi_os_execute(acpi_execute_type type, + acpi_osd_exec_callback function, void *context) +{ + pthread_t thread; + int ret; + + ret = + pthread_create(&thread, NULL, (PTHREAD_CALLBACK) function, context); + if (ret) { + acpi_os_printf("Create thread failed"); + } + return (0); +} + +#else /* ACPI_SINGLE_THREADED */ +acpi_thread_id acpi_os_get_thread_id(void) +{ + return (1); +} + +acpi_status +acpi_os_execute(acpi_execute_type type, + acpi_osd_exec_callback function, void *context) +{ + + function(context); + + return (AE_OK); +} + +#endif /* ACPI_SINGLE_THREADED */ + +/****************************************************************************** + * + * FUNCTION: acpi_os_wait_events_complete + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Wait for all asynchronous events to complete. This + * implementation does nothing. + * + *****************************************************************************/ + +void acpi_os_wait_events_complete(void) +{ + return; +} diff --git a/tools/power/acpi/tools/acpidump/acpidump.h b/tools/power/acpi/tools/acpidump/acpidump.h index 46f519597fe5..a2d37d610639 100644 --- a/tools/power/acpi/tools/acpidump/acpidump.h +++ b/tools/power/acpi/tools/acpidump/acpidump.h @@ -47,7 +47,6 @@ #ifdef _DECLARE_GLOBALS #define EXTERN #define INIT_GLOBAL(a,b) a=b -#define DEFINE_ACPI_GLOBALS 1 #else #define EXTERN extern #define INIT_GLOBAL(a,b) a @@ -69,7 +68,7 @@ EXTERN u8 INIT_GLOBAL(gbl_verbose_mode, FALSE); EXTERN u8 INIT_GLOBAL(gbl_binary_mode, FALSE); EXTERN u8 INIT_GLOBAL(gbl_dump_customized_tables, FALSE); EXTERN u8 INIT_GLOBAL(gbl_do_not_dump_xsdt, FALSE); -EXTERN FILE INIT_GLOBAL(*gbl_output_file, NULL); +EXTERN ACPI_FILE INIT_GLOBAL(gbl_output_file, NULL); EXTERN char INIT_GLOBAL(*gbl_output_filename, NULL); EXTERN u64 INIT_GLOBAL(gbl_rsdp_base, 0); diff --git a/tools/power/acpi/tools/acpidump/apdump.c b/tools/power/acpi/tools/acpidump/apdump.c index 3cac12378366..53cee781e24e 100644 --- a/tools/power/acpi/tools/acpidump/apdump.c +++ b/tools/power/acpi/tools/acpidump/apdump.c @@ -69,17 +69,16 @@ u8 ap_is_valid_header(struct acpi_table_header *table) /* Make sure signature is all ASCII and a valid ACPI name */ if (!acpi_ut_valid_acpi_name(table->signature)) { - fprintf(stderr, - "Table signature (0x%8.8X) is invalid\n", - *(u32 *)table->signature); + acpi_log_error("Table signature (0x%8.8X) is invalid\n", + *(u32 *)table->signature); return (FALSE); } /* Check for minimum table length */ if (table->length < sizeof(struct acpi_table_header)) { - fprintf(stderr, "Table length (0x%8.8X) is invalid\n", - table->length); + acpi_log_error("Table length (0x%8.8X) is invalid\n", + table->length); return (FALSE); } } @@ -116,8 +115,8 @@ u8 ap_is_valid_checksum(struct acpi_table_header *table) } if (ACPI_FAILURE(status)) { - fprintf(stderr, "%4.4s: Warning: wrong checksum in table\n", - table->signature); + acpi_log_error("%4.4s: Warning: wrong checksum in table\n", + table->signature); } return (AE_OK); @@ -196,12 +195,13 @@ ap_dump_table_buffer(struct acpi_table_header *table, * Note: simplest to just always emit a 64-bit address. acpi_xtract * utility can handle this. */ - printf("%4.4s @ 0x%8.8X%8.8X\n", table->signature, - ACPI_FORMAT_UINT64(address)); + acpi_ut_file_printf(gbl_output_file, "%4.4s @ 0x%8.8X%8.8X\n", + table->signature, ACPI_FORMAT_UINT64(address)); - acpi_ut_dump_buffer(ACPI_CAST_PTR(u8, table), table_length, - DB_BYTE_DISPLAY, 0); - printf("\n"); + acpi_ut_dump_buffer_to_file(gbl_output_file, + ACPI_CAST_PTR(u8, table), table_length, + DB_BYTE_DISPLAY, 0); + acpi_ut_file_printf(gbl_output_file, "\n"); return (0); } @@ -239,20 +239,20 @@ int ap_dump_all_tables(void) if (status == AE_LIMIT) { return (0); } else if (i == 0) { - fprintf(stderr, - "Could not get ACPI tables, %s\n", - acpi_format_exception(status)); + acpi_log_error + ("Could not get ACPI tables, %s\n", + acpi_format_exception(status)); return (-1); } else { - fprintf(stderr, - "Could not get ACPI table at index %u, %s\n", - i, acpi_format_exception(status)); + acpi_log_error + ("Could not get ACPI table at index %u, %s\n", + i, acpi_format_exception(status)); continue; } } table_status = ap_dump_table_buffer(table, instance, address); - free(table); + ACPI_FREE(table); if (table_status) { break; @@ -288,22 +288,22 @@ int ap_dump_table_by_address(char *ascii_address) status = acpi_ut_strtoul64(ascii_address, 0, &long_address); if (ACPI_FAILURE(status)) { - fprintf(stderr, "%s: Could not convert to a physical address\n", - ascii_address); + acpi_log_error("%s: Could not convert to a physical address\n", + ascii_address); return (-1); } address = (acpi_physical_address) long_address; status = acpi_os_get_table_by_address(address, &table); if (ACPI_FAILURE(status)) { - fprintf(stderr, "Could not get table at 0x%8.8X%8.8X, %s\n", - ACPI_FORMAT_UINT64(address), - acpi_format_exception(status)); + acpi_log_error("Could not get table at 0x%8.8X%8.8X, %s\n", + ACPI_FORMAT_UINT64(address), + acpi_format_exception(status)); return (-1); } table_status = ap_dump_table_buffer(table, 0, address); - free(table); + ACPI_FREE(table); return (table_status); } @@ -329,24 +329,24 @@ int ap_dump_table_by_name(char *signature) acpi_status status; int table_status; - if (strlen(signature) != ACPI_NAME_SIZE) { - fprintf(stderr, - "Invalid table signature [%s]: must be exactly 4 characters\n", - signature); + if (ACPI_STRLEN(signature) != ACPI_NAME_SIZE) { + acpi_log_error + ("Invalid table signature [%s]: must be exactly 4 characters\n", + signature); return (-1); } /* Table signatures are expected to be uppercase */ - strcpy(local_signature, signature); + ACPI_STRCPY(local_signature, signature); acpi_ut_strupr(local_signature); /* To be friendly, handle tables whose signatures do not match the name */ if (ACPI_COMPARE_NAME(local_signature, "FADT")) { - strcpy(local_signature, ACPI_SIG_FADT); + ACPI_STRCPY(local_signature, ACPI_SIG_FADT); } else if (ACPI_COMPARE_NAME(local_signature, "MADT")) { - strcpy(local_signature, ACPI_SIG_MADT); + ACPI_STRCPY(local_signature, ACPI_SIG_MADT); } /* Dump all instances of this signature (to handle multiple SSDTs) */ @@ -362,14 +362,14 @@ int ap_dump_table_by_name(char *signature) return (0); } - fprintf(stderr, - "Could not get ACPI table with signature [%s], %s\n", - local_signature, acpi_format_exception(status)); + acpi_log_error + ("Could not get ACPI table with signature [%s], %s\n", + local_signature, acpi_format_exception(status)); return (-1); } table_status = ap_dump_table_buffer(table, instance, address); - free(table); + ACPI_FREE(table); if (table_status) { break; @@ -409,43 +409,21 @@ int ap_dump_table_from_file(char *pathname) /* File must be at least as long as the table length */ if (table->length > file_size) { - fprintf(stderr, - "Table length (0x%X) is too large for input file (0x%X) %s\n", - table->length, file_size, pathname); + acpi_log_error + ("Table length (0x%X) is too large for input file (0x%X) %s\n", + table->length, file_size, pathname); goto exit; } if (gbl_verbose_mode) { - fprintf(stderr, - "Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n", - pathname, table->signature, file_size, file_size); + acpi_log_error + ("Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n", + pathname, table->signature, file_size, file_size); } table_status = ap_dump_table_buffer(table, 0, 0); exit: - free(table); + ACPI_FREE(table); return (table_status); } - -/****************************************************************************** - * - * FUNCTION: acpi_os* print functions - * - * DESCRIPTION: Used for linkage with ACPICA modules - * - ******************************************************************************/ - -void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - vfprintf(stdout, fmt, args); - va_end(args); -} - -void acpi_os_vprintf(const char *fmt, va_list args) -{ - vfprintf(stdout, fmt, args); -} diff --git a/tools/power/acpi/tools/acpidump/apfiles.c b/tools/power/acpi/tools/acpidump/apfiles.c index 4488accc010b..d470046a6d81 100644 --- a/tools/power/acpi/tools/acpidump/apfiles.c +++ b/tools/power/acpi/tools/acpidump/apfiles.c @@ -44,6 +44,27 @@ #include "acpidump.h" #include "acapps.h" +/* Local prototypes */ + +static int ap_is_existing_file(char *pathname); + +static int ap_is_existing_file(char *pathname) +{ +#ifndef _GNU_EFI + struct stat stat_info; + + if (!stat(pathname, &stat_info)) { + acpi_log_error("Target path already exists, overwrite? [y|n] "); + + if (getchar() != 'y') { + return (-1); + } + } +#endif + + return 0; +} + /****************************************************************************** * * FUNCTION: ap_open_output_file @@ -59,25 +80,19 @@ int ap_open_output_file(char *pathname) { - struct stat stat_info; - FILE *file; + ACPI_FILE file; /* If file exists, prompt for overwrite */ - if (!stat(pathname, &stat_info)) { - fprintf(stderr, - "Target path already exists, overwrite? [y|n] "); - - if (getchar() != 'y') { - return (-1); - } + if (ap_is_existing_file(pathname) != 0) { + return (-1); } /* Point stdout to the file */ - file = freopen(pathname, "w", stdout); + file = acpi_os_open_file(pathname, ACPI_FILE_WRITING); if (!file) { - perror("Could not open output file"); + acpi_log_error("Could not open output file: %s\n", pathname); return (-1); } @@ -106,7 +121,7 @@ int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance) { char filename[ACPI_NAME_SIZE + 16]; char instance_str[16]; - FILE *file; + ACPI_FILE file; size_t actual; u32 table_length; @@ -130,35 +145,37 @@ int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance) /* Handle multiple SSDts - create different filenames for each */ if (instance > 0) { - sprintf(instance_str, "%u", instance); - strcat(filename, instance_str); + acpi_ut_snprintf(instance_str, sizeof(instance_str), "%u", + instance); + ACPI_STRCAT(filename, instance_str); } - strcat(filename, ACPI_TABLE_FILE_SUFFIX); + ACPI_STRCAT(filename, ACPI_TABLE_FILE_SUFFIX); if (gbl_verbose_mode) { - fprintf(stderr, - "Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n", - table->signature, filename, table->length, - table->length); + acpi_log_error + ("Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n", + table->signature, filename, table->length, table->length); } /* Open the file and dump the entire table in binary mode */ - file = fopen(filename, "wb"); + file = acpi_os_open_file(filename, + ACPI_FILE_WRITING | ACPI_FILE_BINARY); if (!file) { - perror("Could not open output file"); + acpi_log_error("Could not open output file: %s\n", filename); return (-1); } - actual = fwrite(table, 1, table_length, file); + actual = acpi_os_write_file(file, table, 1, table_length); if (actual != table_length) { - perror("Error writing binary output file"); - fclose(file); + acpi_log_error("Error writing binary output file: %s\n", + filename); + acpi_os_close_file(file); return (-1); } - fclose(file); + acpi_os_close_file(file); return (0); } @@ -179,15 +196,16 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname, u32 *out_file_size) { struct acpi_table_header *buffer = NULL; - FILE *file; + ACPI_FILE file; u32 file_size; size_t actual; /* Must use binary mode */ - file = fopen(pathname, "rb"); + file = + acpi_os_open_file(pathname, ACPI_FILE_READING | ACPI_FILE_BINARY); if (!file) { - perror("Could not open input file"); + acpi_log_error("Could not open input file: %s\n", pathname); return (NULL); } @@ -195,27 +213,25 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname, file_size = cm_get_file_size(file); if (file_size == ACPI_UINT32_MAX) { - fprintf(stderr, - "Could not get input file size: %s\n", pathname); + acpi_log_error("Could not get input file size: %s\n", pathname); goto cleanup; } /* Allocate a buffer for the entire file */ - buffer = calloc(1, file_size); + buffer = ACPI_ALLOCATE_ZEROED(file_size); if (!buffer) { - fprintf(stderr, - "Could not allocate file buffer of size: %u\n", - file_size); + acpi_log_error("Could not allocate file buffer of size: %u\n", + file_size); goto cleanup; } /* Read the entire file */ - actual = fread(buffer, 1, file_size, file); + actual = acpi_os_read_file(file, buffer, 1, file_size); if (actual != file_size) { - fprintf(stderr, "Could not read input file: %s\n", pathname); - free(buffer); + acpi_log_error("Could not read input file: %s\n", pathname); + ACPI_FREE(buffer); buffer = NULL; goto cleanup; } @@ -223,6 +239,6 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname, *out_file_size = file_size; cleanup: - fclose(file); + acpi_os_close_file(file); return (buffer); } diff --git a/tools/power/acpi/tools/acpidump/apmain.c b/tools/power/acpi/tools/acpidump/apmain.c index 51e8d638db18..853b4da22c3e 100644 --- a/tools/power/acpi/tools/acpidump/apmain.c +++ b/tools/power/acpi/tools/acpidump/apmain.c @@ -72,7 +72,7 @@ static void ap_display_usage(void); static int ap_do_options(int argc, char **argv); -static void ap_insert_action(char *argument, u32 to_be_done); +static int ap_insert_action(char *argument, u32 to_be_done); /* Table for deferred actions from command line options */ @@ -104,7 +104,7 @@ static void ap_display_usage(void) ACPI_OPTION("-v", "Display version information"); ACPI_OPTION("-z", "Verbose mode"); - printf("\nTable Options:\n"); + ACPI_USAGE_TEXT("\nTable Options:\n"); ACPI_OPTION("-a <Address>", "Get table via a physical address"); ACPI_OPTION("-f <BinaryFile>", "Get table via a binary file"); @@ -112,9 +112,9 @@ static void ap_display_usage(void) ACPI_OPTION("-x", "Do not use but dump XSDT"); ACPI_OPTION("-x -x", "Do not use or dump XSDT"); - printf("\n" - "Invocation without parameters dumps all available tables\n" - "Multiple mixed instances of -a, -f, and -n are supported\n\n"); + ACPI_USAGE_TEXT("\n" + "Invocation without parameters dumps all available tables\n" + "Multiple mixed instances of -a, -f, and -n are supported\n\n"); } /****************************************************************************** @@ -124,13 +124,13 @@ static void ap_display_usage(void) * PARAMETERS: argument - Pointer to the argument for this action * to_be_done - What to do to process this action * - * RETURN: None. Exits program if action table becomes full. + * RETURN: Status * * DESCRIPTION: Add an action item to the action table * ******************************************************************************/ -static void ap_insert_action(char *argument, u32 to_be_done) +static int ap_insert_action(char *argument, u32 to_be_done) { /* Insert action and check for table overflow */ @@ -140,10 +140,12 @@ static void ap_insert_action(char *argument, u32 to_be_done) current_action++; if (current_action > AP_MAX_ACTIONS) { - fprintf(stderr, "Too many table options (max %u)\n", - AP_MAX_ACTIONS); - exit(-1); + acpi_log_error("Too many table options (max %u)\n", + AP_MAX_ACTIONS); + return (-1); } + + return (0); } /****************************************************************************** @@ -166,7 +168,8 @@ static int ap_do_options(int argc, char **argv) /* Command line options */ - while ((j = acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != EOF) + while ((j = + acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j) { /* * Global options @@ -185,12 +188,12 @@ static int ap_do_options(int argc, char **argv) case '?': ap_display_usage(); - exit(0); + return (1); case 'o': /* Redirect output to a single file */ if (ap_open_output_file(acpi_gbl_optarg)) { - exit(-1); + return (-1); } continue; @@ -200,10 +203,10 @@ static int ap_do_options(int argc, char **argv) acpi_ut_strtoul64(acpi_gbl_optarg, 0, &gbl_rsdp_base); if (ACPI_FAILURE(status)) { - fprintf(stderr, - "%s: Could not convert to a physical address\n", - acpi_gbl_optarg); - exit(-1); + acpi_log_error + ("%s: Could not convert to a physical address\n", + acpi_gbl_optarg); + return (-1); } continue; @@ -223,13 +226,13 @@ static int ap_do_options(int argc, char **argv) case 'v': /* Revision/version */ - printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); - exit(0); + acpi_os_printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); + return (1); case 'z': /* Verbose mode */ gbl_verbose_mode = TRUE; - fprintf(stderr, ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); + acpi_log_error(ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); continue; /* @@ -237,32 +240,40 @@ static int ap_do_options(int argc, char **argv) */ case 'a': /* Get table by physical address */ - ap_insert_action(acpi_gbl_optarg, - AP_DUMP_TABLE_BY_ADDRESS); + if (ap_insert_action + (acpi_gbl_optarg, AP_DUMP_TABLE_BY_ADDRESS)) { + return (-1); + } break; case 'f': /* Get table from a file */ - ap_insert_action(acpi_gbl_optarg, - AP_DUMP_TABLE_BY_FILE); + if (ap_insert_action + (acpi_gbl_optarg, AP_DUMP_TABLE_BY_FILE)) { + return (-1); + } break; case 'n': /* Get table by input name (signature) */ - ap_insert_action(acpi_gbl_optarg, - AP_DUMP_TABLE_BY_NAME); + if (ap_insert_action + (acpi_gbl_optarg, AP_DUMP_TABLE_BY_NAME)) { + return (-1); + } break; default: ap_display_usage(); - exit(-1); + return (-1); } /* If there are no actions, this means "get/dump all tables" */ if (current_action == 0) { - ap_insert_action(NULL, AP_DUMP_ALL_TABLES); + if (ap_insert_action(NULL, AP_DUMP_ALL_TABLES)) { + return (-1); + } } return (0); @@ -280,7 +291,11 @@ static int ap_do_options(int argc, char **argv) * ******************************************************************************/ +#ifndef _GNU_EFI int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) +#else +int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[]) +#endif { int status = 0; struct ap_dump_action *action; @@ -288,11 +303,17 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) u32 i; ACPI_DEBUG_INITIALIZE(); /* For debug version only */ + acpi_os_initialize(); + gbl_output_file = ACPI_FILE_OUT; /* Process command line options */ - if (ap_do_options(argc, argv)) { - return (-1); + status = ap_do_options(argc, argv); + if (status > 0) { + return (0); + } + if (status < 0) { + return (status); } /* Get/dump ACPI table(s) as requested */ @@ -322,9 +343,8 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) default: - fprintf(stderr, - "Internal error, invalid action: 0x%X\n", - action->to_be_done); + acpi_log_error("Internal error, invalid action: 0x%X\n", + action->to_be_done); return (-1); } @@ -333,18 +353,18 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) } } - if (gbl_output_file) { + if (gbl_output_filename) { if (gbl_verbose_mode) { /* Summary for the output file */ file_size = cm_get_file_size(gbl_output_file); - fprintf(stderr, - "Output file %s contains 0x%X (%u) bytes\n\n", - gbl_output_filename, file_size, file_size); + acpi_log_error + ("Output file %s contains 0x%X (%u) bytes\n\n", + gbl_output_filename, file_size, file_size); } - fclose(gbl_output_file); + acpi_os_close_file(gbl_output_file); } return (status); diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c index 543bba14ae2c..f503fb53824e 100644 --- a/tools/power/cpupower/bench/parse.c +++ b/tools/power/cpupower/bench/parse.c @@ -158,14 +158,15 @@ struct config *prepare_default_config() int prepare_config(const char *path, struct config *config) { size_t len = 0; - char *opt, *val, *line = NULL; - FILE *configfile = fopen(path, "r"); + char opt[16], val[32], *line = NULL; + FILE *configfile; if (config == NULL) { fprintf(stderr, "error: config is NULL\n"); return 1; } + configfile = fopen(path, "r"); if (configfile == NULL) { perror("fopen"); fprintf(stderr, "error: unable to read configfile\n"); @@ -174,52 +175,54 @@ int prepare_config(const char *path, struct config *config) } while (getline(&line, &len, configfile) != -1) { - if (line[0] == '#' || line[0] == ' ') + if (line[0] == '#' || line[0] == ' ' || line[0] == '\n') continue; - sscanf(line, "%as = %as", &opt, &val); + if (sscanf(line, "%14s = %30s", opt, val) < 2) + continue; dprintf("parsing: %s -> %s\n", opt, val); - if (strncmp("sleep", opt, strlen(opt)) == 0) + if (strcmp("sleep", opt) == 0) sscanf(val, "%li", &config->sleep); - else if (strncmp("load", opt, strlen(opt)) == 0) + else if (strcmp("load", opt) == 0) sscanf(val, "%li", &config->load); - else if (strncmp("load_step", opt, strlen(opt)) == 0) + else if (strcmp("load_step", opt) == 0) sscanf(val, "%li", &config->load_step); - else if (strncmp("sleep_step", opt, strlen(opt)) == 0) + else if (strcmp("sleep_step", opt) == 0) sscanf(val, "%li", &config->sleep_step); - else if (strncmp("cycles", opt, strlen(opt)) == 0) + else if (strcmp("cycles", opt) == 0) sscanf(val, "%u", &config->cycles); - else if (strncmp("rounds", opt, strlen(opt)) == 0) + else if (strcmp("rounds", opt) == 0) sscanf(val, "%u", &config->rounds); - else if (strncmp("verbose", opt, strlen(opt)) == 0) + else if (strcmp("verbose", opt) == 0) sscanf(val, "%u", &config->verbose); - else if (strncmp("output", opt, strlen(opt)) == 0) + else if (strcmp("output", opt) == 0) config->output = prepare_output(val); - else if (strncmp("cpu", opt, strlen(opt)) == 0) + else if (strcmp("cpu", opt) == 0) sscanf(val, "%u", &config->cpu); - else if (strncmp("governor", opt, 14) == 0) - strncpy(config->governor, val, 14); + else if (strcmp("governor", opt) == 0) { + strncpy(config->governor, val, + sizeof(config->governor)); + config->governor[sizeof(config->governor) - 1] = '\0'; + } - else if (strncmp("priority", opt, strlen(opt)) == 0) { + else if (strcmp("priority", opt) == 0) { if (string_to_prio(val) != SCHED_ERR) config->prio = string_to_prio(val); } } free(line); - free(opt); - free(val); return 0; } diff --git a/tools/power/cpupower/utils/cpufreq-set.c b/tools/power/cpupower/utils/cpufreq-set.c index a416de80c55e..f656e585ed45 100644 --- a/tools/power/cpupower/utils/cpufreq-set.c +++ b/tools/power/cpupower/utils/cpufreq-set.c @@ -320,12 +320,11 @@ int cmd_freq_set(int argc, char **argv) printf(_("Setting cpu: %d\n"), cpu); ret = do_one_cpu(cpu, &new_pol, freq, policychange); - if (ret) - break; + if (ret) { + print_error(); + return ret; + } } - if (ret) - print_error(); - - return ret; + return 0; } diff --git a/tools/power/cpupower/utils/helpers/sysfs.c b/tools/power/cpupower/utils/helpers/sysfs.c index 851c7a16ca49..09afe5d87f2b 100644 --- a/tools/power/cpupower/utils/helpers/sysfs.c +++ b/tools/power/cpupower/utils/helpers/sysfs.c @@ -81,7 +81,7 @@ int sysfs_is_cpu_online(unsigned int cpu) close(fd); value = strtoull(linebuf, &endp, 0); - if (value > 1 || value < 0) + if (value > 1) return -EINVAL; return value; diff --git a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c index 5650ab5a2c20..90a8c4f071e7 100644 --- a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c @@ -237,7 +237,7 @@ static int init_maxfreq_mode(void) unsigned long long hwcr; unsigned long min; - if (!cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC) + if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC)) goto use_sysfs; if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) { |