diff options
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 = \ | |||
| 108 | apmain.o\ | 108 | apmain.o\ |
| 109 | osunixdir.o\ | 109 | osunixdir.o\ |
| 110 | osunixmap.o\ | 110 | osunixmap.o\ |
| 111 | osunixxf.o\ | ||
| 111 | tbprint.o\ | 112 | tbprint.o\ |
| 112 | tbxfroot.o\ | 113 | tbxfroot.o\ |
| 113 | utbuffer.o\ | 114 | utbuffer.o\ |
| 115 | utdebug.o\ | ||
| 114 | utexcep.o\ | 116 | utexcep.o\ |
| 117 | utglobal.o\ | ||
| 115 | utmath.o\ | 118 | utmath.o\ |
| 119 | utprint.o\ | ||
| 116 | utstring.o\ | 120 | utstring.o\ |
| 117 | utxferror.o\ | 121 | utxferror.o\ |
| 122 | oslibcfs.o\ | ||
| 118 | oslinuxtbl.o\ | 123 | oslinuxtbl.o\ |
| 119 | cmfsize.o\ | 124 | cmfsize.o\ |
| 120 | getopt.o | 125 | 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") | |||
| 58 | * RETURN: File Size. On error, -1 (ACPI_UINT32_MAX) | 58 | * RETURN: File Size. On error, -1 (ACPI_UINT32_MAX) |
| 59 | * | 59 | * |
| 60 | * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open. | 60 | * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open. |
| 61 | * Does not disturb the current file pointer. Uses perror for | 61 | * Does not disturb the current file pointer. |
| 62 | * error messages. | ||
| 63 | * | 62 | * |
| 64 | ******************************************************************************/ | 63 | ******************************************************************************/ |
| 65 | u32 cm_get_file_size(FILE * file) | 64 | u32 cm_get_file_size(ACPI_FILE file) |
| 66 | { | 65 | { |
| 67 | long file_size; | 66 | long file_size; |
| 68 | long current_offset; | 67 | long current_offset; |
| 68 | acpi_status status; | ||
| 69 | 69 | ||
| 70 | /* Save the current file pointer, seek to EOF to obtain file size */ | 70 | /* Save the current file pointer, seek to EOF to obtain file size */ |
| 71 | 71 | ||
| 72 | current_offset = ftell(file); | 72 | current_offset = acpi_os_get_file_offset(file); |
| 73 | if (current_offset < 0) { | 73 | if (current_offset < 0) { |
| 74 | goto offset_error; | 74 | goto offset_error; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | if (fseek(file, 0, SEEK_END)) { | 77 | status = acpi_os_set_file_offset(file, 0, ACPI_FILE_END); |
| 78 | if (ACPI_FAILURE(status)) { | ||
| 78 | goto seek_error; | 79 | goto seek_error; |
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | file_size = ftell(file); | 82 | file_size = acpi_os_get_file_offset(file); |
| 82 | if (file_size < 0) { | 83 | if (file_size < 0) { |
| 83 | goto offset_error; | 84 | goto offset_error; |
| 84 | } | 85 | } |
| 85 | 86 | ||
| 86 | /* Restore original file pointer */ | 87 | /* Restore original file pointer */ |
| 87 | 88 | ||
| 88 | if (fseek(file, current_offset, SEEK_SET)) { | 89 | status = acpi_os_set_file_offset(file, current_offset, ACPI_FILE_BEGIN); |
| 90 | if (ACPI_FAILURE(status)) { | ||
| 89 | goto seek_error; | 91 | goto seek_error; |
| 90 | } | 92 | } |
| 91 | 93 | ||
| 92 | return ((u32)file_size); | 94 | return ((u32)file_size); |
| 93 | 95 | ||
| 94 | offset_error: | 96 | offset_error: |
| 95 | perror("Could not get file offset"); | 97 | acpi_log_error("Could not get file offset"); |
| 96 | return (ACPI_UINT32_MAX); | 98 | return (ACPI_UINT32_MAX); |
| 97 | 99 | ||
| 98 | seek_error: | 100 | seek_error: |
| 99 | perror("Could not seek file"); | 101 | acpi_log_error("Could not set file offset"); |
| 100 | return (ACPI_UINT32_MAX); | 102 | return (ACPI_UINT32_MAX); |
| 101 | } | 103 | } |
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 @@ | |||
| 51 | * "f|" - Option has required single-char sub-options | 51 | * "f|" - Option has required single-char sub-options |
| 52 | */ | 52 | */ |
| 53 | 53 | ||
| 54 | #include <stdio.h> | ||
| 55 | #include <string.h> | ||
| 56 | #include <acpi/acpi.h> | 54 | #include <acpi/acpi.h> |
| 57 | #include "accommon.h" | 55 | #include "accommon.h" |
| 58 | #include "acapps.h" | 56 | #include "acapps.h" |
| 59 | 57 | ||
| 60 | #define ACPI_OPTION_ERROR(msg, badchar) \ | 58 | #define ACPI_OPTION_ERROR(msg, badchar) \ |
| 61 | if (acpi_gbl_opterr) {fprintf (stderr, "%s%c\n", msg, badchar);} | 59 | if (acpi_gbl_opterr) {acpi_log_error ("%s%c\n", msg, badchar);} |
| 62 | 60 | ||
| 63 | int acpi_gbl_opterr = 1; | 61 | int acpi_gbl_opterr = 1; |
| 64 | int acpi_gbl_optind = 1; | 62 | int acpi_gbl_optind = 1; |
| @@ -113,7 +111,7 @@ int acpi_getopt_argument(int argc, char **argv) | |||
| 113 | * PARAMETERS: argc, argv - from main | 111 | * PARAMETERS: argc, argv - from main |
| 114 | * opts - options info list | 112 | * opts - options info list |
| 115 | * | 113 | * |
| 116 | * RETURN: Option character or EOF | 114 | * RETURN: Option character or ACPI_OPT_END |
| 117 | * | 115 | * |
| 118 | * DESCRIPTION: Get the next option | 116 | * DESCRIPTION: Get the next option |
| 119 | * | 117 | * |
| @@ -128,10 +126,10 @@ int acpi_getopt(int argc, char **argv, char *opts) | |||
| 128 | if (acpi_gbl_optind >= argc || | 126 | if (acpi_gbl_optind >= argc || |
| 129 | argv[acpi_gbl_optind][0] != '-' || | 127 | argv[acpi_gbl_optind][0] != '-' || |
| 130 | argv[acpi_gbl_optind][1] == '\0') { | 128 | argv[acpi_gbl_optind][1] == '\0') { |
| 131 | return (EOF); | 129 | return (ACPI_OPT_END); |
| 132 | } else if (strcmp(argv[acpi_gbl_optind], "--") == 0) { | 130 | } else if (ACPI_STRCMP(argv[acpi_gbl_optind], "--") == 0) { |
| 133 | acpi_gbl_optind++; | 131 | acpi_gbl_optind++; |
| 134 | return (EOF); | 132 | return (ACPI_OPT_END); |
| 135 | } | 133 | } |
| 136 | } | 134 | } |
| 137 | 135 | ||
| @@ -142,7 +140,7 @@ int acpi_getopt(int argc, char **argv, char *opts) | |||
| 142 | /* Make sure that the option is legal */ | 140 | /* Make sure that the option is legal */ |
| 143 | 141 | ||
| 144 | if (current_char == ':' || | 142 | if (current_char == ':' || |
| 145 | (opts_ptr = strchr(opts, current_char)) == NULL) { | 143 | (opts_ptr = ACPI_STRCHR(opts, current_char)) == NULL) { |
| 146 | ACPI_OPTION_ERROR("Illegal option: -", current_char); | 144 | ACPI_OPTION_ERROR("Illegal option: -", current_char); |
| 147 | 145 | ||
| 148 | if (argv[acpi_gbl_optind][++current_char_ptr] == '\0') { | 146 | 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 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | * | ||
| 3 | * Module Name: oslibcfs - C library OSL for file I/O | ||
| 4 | * | ||
| 5 | *****************************************************************************/ | ||
| 6 | |||
| 7 | /* | ||
| 8 | * Copyright (C) 2000 - 2014, Intel Corp. | ||
| 9 | * All rights reserved. | ||
| 10 | * | ||
| 11 | * Redistribution and use in source and binary forms, with or without | ||
| 12 | * modification, are permitted provided that the following conditions | ||
| 13 | * are met: | ||
| 14 | * 1. Redistributions of source code must retain the above copyright | ||
| 15 | * notice, this list of conditions, and the following disclaimer, | ||
| 16 | * without modification. | ||
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
| 20 | * including a substantially similar Disclaimer requirement for further | ||
| 21 | * binary redistribution. | ||
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
| 23 | * of any contributors may be used to endorse or promote products derived | ||
| 24 | * from this software without specific prior written permission. | ||
| 25 | * | ||
| 26 | * Alternatively, this software may be distributed under the terms of the | ||
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
| 28 | * Software Foundation. | ||
| 29 | * | ||
| 30 | * NO WARRANTY | ||
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 41 | * POSSIBILITY OF SUCH DAMAGES. | ||
| 42 | */ | ||
| 43 | |||
| 44 | #include <acpi/acpi.h> | ||
| 45 | #include <stdio.h> | ||
| 46 | #include <stdarg.h> | ||
| 47 | |||
| 48 | #define _COMPONENT ACPI_OS_SERVICES | ||
| 49 | ACPI_MODULE_NAME("oslibcfs") | ||
| 50 | |||
| 51 | /******************************************************************************* | ||
| 52 | * | ||
| 53 | * FUNCTION: acpi_os_open_file | ||
| 54 | * | ||
| 55 | * PARAMETERS: path - File path | ||
| 56 | * modes - File operation type | ||
| 57 | * | ||
| 58 | * RETURN: File descriptor. | ||
| 59 | * | ||
| 60 | * DESCRIPTION: Open a file for reading (ACPI_FILE_READING) or/and writing | ||
| 61 | * (ACPI_FILE_WRITING). | ||
| 62 | * | ||
| 63 | ******************************************************************************/ | ||
| 64 | ACPI_FILE acpi_os_open_file(const char *path, u8 modes) | ||
| 65 | { | ||
| 66 | ACPI_FILE file; | ||
| 67 | u32 i = 0; | ||
| 68 | char modes_str[4]; | ||
| 69 | |||
| 70 | if (modes & ACPI_FILE_READING) { | ||
| 71 | modes_str[i++] = 'r'; | ||
| 72 | } | ||
| 73 | if (modes & ACPI_FILE_WRITING) { | ||
| 74 | modes_str[i++] = 'w'; | ||
| 75 | } | ||
| 76 | if (modes & ACPI_FILE_BINARY) { | ||
| 77 | modes_str[i++] = 'b'; | ||
| 78 | } | ||
| 79 | |||
| 80 | modes_str[i++] = '\0'; | ||
| 81 | |||
| 82 | file = fopen(path, modes_str); | ||
| 83 | if (!file) { | ||
| 84 | perror("Could not open file"); | ||
| 85 | } | ||
| 86 | |||
| 87 | return (file); | ||
| 88 | } | ||
| 89 | |||
| 90 | /******************************************************************************* | ||
| 91 | * | ||
| 92 | * FUNCTION: acpi_os_close_file | ||
| 93 | * | ||
| 94 | * PARAMETERS: file - An open file descriptor | ||
| 95 | * | ||
| 96 | * RETURN: None. | ||
| 97 | * | ||
| 98 | * DESCRIPTION: Close a file opened via acpi_os_open_file. | ||
| 99 | * | ||
| 100 | ******************************************************************************/ | ||
| 101 | |||
| 102 | void acpi_os_close_file(ACPI_FILE file) | ||
| 103 | { | ||
| 104 | fclose(file); | ||
| 105 | } | ||
| 106 | |||
| 107 | /******************************************************************************* | ||
| 108 | * | ||
| 109 | * FUNCTION: acpi_os_read_file | ||
| 110 | * | ||
| 111 | * PARAMETERS: file - An open file descriptor | ||
| 112 | * buffer - Data buffer | ||
| 113 | * size - Data block size | ||
| 114 | * count - Number of data blocks | ||
| 115 | * | ||
| 116 | * RETURN: Number of bytes actually read. | ||
| 117 | * | ||
| 118 | * DESCRIPTION: Read from a file. | ||
| 119 | * | ||
| 120 | ******************************************************************************/ | ||
| 121 | |||
| 122 | int | ||
| 123 | acpi_os_read_file(ACPI_FILE file, void *buffer, acpi_size size, acpi_size count) | ||
| 124 | { | ||
| 125 | int length; | ||
| 126 | |||
| 127 | length = fread(buffer, size, count, file); | ||
| 128 | if (length < 0) { | ||
| 129 | perror("Error reading file"); | ||
| 130 | } | ||
| 131 | |||
| 132 | return (length); | ||
| 133 | } | ||
| 134 | |||
| 135 | /******************************************************************************* | ||
| 136 | * | ||
| 137 | * FUNCTION: acpi_os_write_file | ||
| 138 | * | ||
| 139 | * PARAMETERS: file - An open file descriptor | ||
| 140 | * buffer - Data buffer | ||
| 141 | * size - Data block size | ||
| 142 | * count - Number of data blocks | ||
| 143 | * | ||
| 144 | * RETURN: Number of bytes actually written. | ||
| 145 | * | ||
| 146 | * DESCRIPTION: Write to a file. | ||
| 147 | * | ||
| 148 | ******************************************************************************/ | ||
| 149 | |||
| 150 | int | ||
| 151 | acpi_os_write_file(ACPI_FILE file, | ||
| 152 | void *buffer, acpi_size size, acpi_size count) | ||
| 153 | { | ||
| 154 | int length; | ||
| 155 | |||
| 156 | length = fwrite(buffer, size, count, file); | ||
| 157 | if (length < 0) { | ||
| 158 | perror("Error writing file"); | ||
| 159 | } | ||
| 160 | |||
| 161 | return (length); | ||
| 162 | } | ||
| 163 | |||
| 164 | /******************************************************************************* | ||
| 165 | * | ||
| 166 | * FUNCTION: acpi_os_get_file_offset | ||
| 167 | * | ||
| 168 | * PARAMETERS: file - An open file descriptor | ||
| 169 | * | ||
| 170 | * RETURN: Current file pointer position. | ||
| 171 | * | ||
| 172 | * DESCRIPTION: Get current file offset. | ||
| 173 | * | ||
| 174 | ******************************************************************************/ | ||
| 175 | |||
| 176 | long acpi_os_get_file_offset(ACPI_FILE file) | ||
| 177 | { | ||
| 178 | long offset; | ||
| 179 | |||
| 180 | offset = ftell(file); | ||
| 181 | return (offset); | ||
| 182 | } | ||
| 183 | |||
| 184 | /******************************************************************************* | ||
| 185 | * | ||
| 186 | * FUNCTION: acpi_os_set_file_offset | ||
| 187 | * | ||
| 188 | * PARAMETERS: file - An open file descriptor | ||
| 189 | * offset - New file offset | ||
| 190 | * from - From begin/end of file | ||
| 191 | * | ||
| 192 | * RETURN: Status | ||
| 193 | * | ||
| 194 | * DESCRIPTION: Set current file offset. | ||
| 195 | * | ||
| 196 | ******************************************************************************/ | ||
| 197 | |||
| 198 | acpi_status acpi_os_set_file_offset(ACPI_FILE file, long offset, u8 from) | ||
| 199 | { | ||
| 200 | int ret = 0; | ||
| 201 | |||
| 202 | if (from == ACPI_FILE_BEGIN) { | ||
| 203 | ret = fseek(file, offset, SEEK_SET); | ||
| 204 | } | ||
| 205 | if (from == ACPI_FILE_END) { | ||
| 206 | ret = fseek(file, offset, SEEK_END); | ||
| 207 | } | ||
| 208 | |||
| 209 | if (ret < 0) { | ||
| 210 | return (AE_ERROR); | ||
| 211 | } else { | ||
| 212 | return (AE_OK); | ||
| 213 | } | ||
| 214 | } | ||
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, | |||
| 77 | 77 | ||
| 78 | static void osl_unmap_table(struct acpi_table_header *table); | 78 | static void osl_unmap_table(struct acpi_table_header *table); |
| 79 | 79 | ||
| 80 | static acpi_physical_address | ||
| 81 | osl_find_rsdp_via_efi_by_keyword(FILE * file, const char *keyword); | ||
| 82 | |||
| 80 | static acpi_physical_address osl_find_rsdp_via_efi(void); | 83 | static acpi_physical_address osl_find_rsdp_via_efi(void); |
| 81 | 84 | ||
| 82 | static acpi_status osl_load_rsdp(void); | 85 | static acpi_status osl_load_rsdp(void); |
| @@ -417,6 +420,38 @@ acpi_os_get_table_by_index(u32 index, | |||
| 417 | 420 | ||
| 418 | /****************************************************************************** | 421 | /****************************************************************************** |
| 419 | * | 422 | * |
| 423 | * FUNCTION: osl_find_rsdp_via_efi_by_keyword | ||
| 424 | * | ||
| 425 | * PARAMETERS: keyword - Character string indicating ACPI GUID version | ||
| 426 | * in the EFI table | ||
| 427 | * | ||
| 428 | * RETURN: RSDP address if found | ||
| 429 | * | ||
| 430 | * DESCRIPTION: Find RSDP address via EFI using keyword indicating the ACPI | ||
| 431 | * GUID version. | ||
| 432 | * | ||
| 433 | *****************************************************************************/ | ||
| 434 | |||
| 435 | static acpi_physical_address | ||
| 436 | osl_find_rsdp_via_efi_by_keyword(FILE * file, const char *keyword) | ||
| 437 | { | ||
| 438 | char buffer[80]; | ||
| 439 | unsigned long long address = 0; | ||
| 440 | char format[32]; | ||
| 441 | |||
| 442 | snprintf(format, 32, "%s=%s", keyword, "%llx"); | ||
| 443 | fseek(file, 0, SEEK_SET); | ||
| 444 | while (fgets(buffer, 80, file)) { | ||
| 445 | if (sscanf(buffer, format, &address) == 1) { | ||
| 446 | break; | ||
| 447 | } | ||
| 448 | } | ||
| 449 | |||
| 450 | return ((acpi_physical_address) (address)); | ||
| 451 | } | ||
| 452 | |||
| 453 | /****************************************************************************** | ||
| 454 | * | ||
| 420 | * FUNCTION: osl_find_rsdp_via_efi | 455 | * FUNCTION: osl_find_rsdp_via_efi |
| 421 | * | 456 | * |
| 422 | * PARAMETERS: None | 457 | * PARAMETERS: None |
| @@ -430,20 +465,19 @@ acpi_os_get_table_by_index(u32 index, | |||
| 430 | static acpi_physical_address osl_find_rsdp_via_efi(void) | 465 | static acpi_physical_address osl_find_rsdp_via_efi(void) |
| 431 | { | 466 | { |
| 432 | FILE *file; | 467 | FILE *file; |
| 433 | char buffer[80]; | 468 | acpi_physical_address address = 0; |
| 434 | unsigned long address = 0; | ||
| 435 | 469 | ||
| 436 | file = fopen(EFI_SYSTAB, "r"); | 470 | file = fopen(EFI_SYSTAB, "r"); |
| 437 | if (file) { | 471 | if (file) { |
| 438 | while (fgets(buffer, 80, file)) { | 472 | address = osl_find_rsdp_via_efi_by_keyword(file, "ACPI20"); |
| 439 | if (sscanf(buffer, "ACPI20=0x%lx", &address) == 1) { | 473 | if (!address) { |
| 440 | break; | 474 | address = |
| 441 | } | 475 | osl_find_rsdp_via_efi_by_keyword(file, "ACPI"); |
| 442 | } | 476 | } |
| 443 | fclose(file); | 477 | fclose(file); |
| 444 | } | 478 | } |
| 445 | 479 | ||
| 446 | return ((acpi_physical_address) (address)); | 480 | return (address); |
| 447 | } | 481 | } |
| 448 | 482 | ||
| 449 | /****************************************************************************** | 483 | /****************************************************************************** |
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 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | * | ||
| 3 | * Module Name: osunixxf - UNIX OSL interfaces | ||
| 4 | * | ||
| 5 | *****************************************************************************/ | ||
| 6 | |||
| 7 | /* | ||
| 8 | * Copyright (C) 2000 - 2014, Intel Corp. | ||
| 9 | * All rights reserved. | ||
| 10 | * | ||
| 11 | * Redistribution and use in source and binary forms, with or without | ||
| 12 | * modification, are permitted provided that the following conditions | ||
| 13 | * are met: | ||
| 14 | * 1. Redistributions of source code must retain the above copyright | ||
| 15 | * notice, this list of conditions, and the following disclaimer, | ||
| 16 | * without modification. | ||
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below | ||
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon | ||
| 20 | * including a substantially similar Disclaimer requirement for further | ||
| 21 | * binary redistribution. | ||
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names | ||
| 23 | * of any contributors may be used to endorse or promote products derived | ||
| 24 | * from this software without specific prior written permission. | ||
| 25 | * | ||
| 26 | * Alternatively, this software may be distributed under the terms of the | ||
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
| 28 | * Software Foundation. | ||
| 29 | * | ||
| 30 | * NO WARRANTY | ||
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | ||
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 41 | * POSSIBILITY OF SUCH DAMAGES. | ||
| 42 | */ | ||
| 43 | |||
| 44 | /* | ||
| 45 | * These interfaces are required in order to compile the ASL compiler and the | ||
| 46 | * various ACPICA tools under Linux or other Unix-like system. | ||
| 47 | */ | ||
| 48 | #include <acpi/acpi.h> | ||
| 49 | #include "accommon.h" | ||
| 50 | #include "amlcode.h" | ||
| 51 | #include "acparser.h" | ||
| 52 | #include "acdebug.h" | ||
| 53 | |||
| 54 | #include <stdio.h> | ||
| 55 | #include <stdlib.h> | ||
| 56 | #include <stdarg.h> | ||
| 57 | #include <unistd.h> | ||
| 58 | #include <sys/time.h> | ||
| 59 | #include <semaphore.h> | ||
| 60 | #include <pthread.h> | ||
| 61 | #include <errno.h> | ||
| 62 | |||
| 63 | #define _COMPONENT ACPI_OS_SERVICES | ||
| 64 | ACPI_MODULE_NAME("osunixxf") | ||
| 65 | |||
| 66 | u8 acpi_gbl_debug_timeout = FALSE; | ||
| 67 | |||
| 68 | /* Upcalls to acpi_exec */ | ||
| 69 | |||
| 70 | void | ||
| 71 | ae_table_override(struct acpi_table_header *existing_table, | ||
| 72 | struct acpi_table_header **new_table); | ||
| 73 | |||
| 74 | typedef void *(*PTHREAD_CALLBACK) (void *); | ||
| 75 | |||
| 76 | /* Buffer used by acpi_os_vprintf */ | ||
| 77 | |||
| 78 | #define ACPI_VPRINTF_BUFFER_SIZE 512 | ||
| 79 | #define _ASCII_NEWLINE '\n' | ||
| 80 | |||
| 81 | /* Terminal support for acpi_exec only */ | ||
| 82 | |||
| 83 | #ifdef ACPI_EXEC_APP | ||
| 84 | #include <termios.h> | ||
| 85 | |||
| 86 | struct termios original_term_attributes; | ||
| 87 | int term_attributes_were_set = 0; | ||
| 88 | |||
| 89 | acpi_status acpi_ut_read_line(char *buffer, u32 buffer_length, u32 *bytes_read); | ||
| 90 | |||
| 91 | static void os_enter_line_edit_mode(void); | ||
| 92 | |||
| 93 | static void os_exit_line_edit_mode(void); | ||
| 94 | |||
| 95 | /****************************************************************************** | ||
| 96 | * | ||
| 97 | * FUNCTION: os_enter_line_edit_mode, os_exit_line_edit_mode | ||
| 98 | * | ||
| 99 | * PARAMETERS: None | ||
| 100 | * | ||
| 101 | * RETURN: None | ||
| 102 | * | ||
| 103 | * DESCRIPTION: Enter/Exit the raw character input mode for the terminal. | ||
| 104 | * | ||
| 105 | * Interactive line-editing support for the AML debugger. Used with the | ||
| 106 | * common/acgetline module. | ||
| 107 | * | ||
| 108 | * readline() is not used because of non-portability. It is not available | ||
| 109 | * on all systems, and if it is, often the package must be manually installed. | ||
| 110 | * | ||
| 111 | * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line | ||
| 112 | * editing that we need in acpi_os_get_line. | ||
| 113 | * | ||
| 114 | * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these | ||
| 115 | * calls will also work: | ||
| 116 | * For os_enter_line_edit_mode: system ("stty cbreak -echo") | ||
| 117 | * For os_exit_line_edit_mode: system ("stty cooked echo") | ||
| 118 | * | ||
| 119 | *****************************************************************************/ | ||
| 120 | |||
| 121 | static void os_enter_line_edit_mode(void) | ||
| 122 | { | ||
| 123 | struct termios local_term_attributes; | ||
| 124 | |||
| 125 | /* Get and keep the original attributes */ | ||
| 126 | |||
| 127 | if (tcgetattr(STDIN_FILENO, &original_term_attributes)) { | ||
| 128 | fprintf(stderr, "Could not get terminal attributes!\n"); | ||
| 129 | return; | ||
| 130 | } | ||
| 131 | |||
| 132 | /* Set the new attributes to enable raw character input */ | ||
| 133 | |||
| 134 | memcpy(&local_term_attributes, &original_term_attributes, | ||
| 135 | sizeof(struct termios)); | ||
| 136 | |||
| 137 | local_term_attributes.c_lflag &= ~(ICANON | ECHO); | ||
| 138 | local_term_attributes.c_cc[VMIN] = 1; | ||
| 139 | local_term_attributes.c_cc[VTIME] = 0; | ||
| 140 | |||
| 141 | if (tcsetattr(STDIN_FILENO, TCSANOW, &local_term_attributes)) { | ||
| 142 | fprintf(stderr, "Could not set terminal attributes!\n"); | ||
| 143 | return; | ||
| 144 | } | ||
| 145 | |||
| 146 | term_attributes_were_set = 1; | ||
| 147 | } | ||
| 148 | |||
| 149 | static void os_exit_line_edit_mode(void) | ||
| 150 | { | ||
| 151 | |||
| 152 | if (!term_attributes_were_set) { | ||
| 153 | return; | ||
| 154 | } | ||
| 155 | |||
| 156 | /* Set terminal attributes back to the original values */ | ||
| 157 | |||
| 158 | if (tcsetattr(STDIN_FILENO, TCSANOW, &original_term_attributes)) { | ||
| 159 | fprintf(stderr, "Could not restore terminal attributes!\n"); | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | #else | ||
| 164 | |||
| 165 | /* These functions are not needed for other ACPICA utilities */ | ||
| 166 | |||
| 167 | #define os_enter_line_edit_mode() | ||
| 168 | #define os_exit_line_edit_mode() | ||
| 169 | #endif | ||
| 170 | |||
| 171 | /****************************************************************************** | ||
| 172 | * | ||
| 173 | * FUNCTION: acpi_os_initialize, acpi_os_terminate | ||
| 174 | * | ||
| 175 | * PARAMETERS: None | ||
| 176 | * | ||
| 177 | * RETURN: Status | ||
| 178 | * | ||
| 179 | * DESCRIPTION: Initialize and terminate this module. | ||
| 180 | * | ||
| 181 | *****************************************************************************/ | ||
| 182 | |||
| 183 | acpi_status acpi_os_initialize(void) | ||
| 184 | { | ||
| 185 | acpi_status status; | ||
| 186 | |||
| 187 | acpi_gbl_output_file = stdout; | ||
| 188 | |||
| 189 | os_enter_line_edit_mode(); | ||
| 190 | |||
| 191 | status = acpi_os_create_lock(&acpi_gbl_print_lock); | ||
| 192 | if (ACPI_FAILURE(status)) { | ||
| 193 | return (status); | ||
| 194 | } | ||
| 195 | |||
| 196 | return (AE_OK); | ||
| 197 | } | ||
| 198 | |||
| 199 | acpi_status acpi_os_terminate(void) | ||
| 200 | { | ||
| 201 | |||
| 202 | os_exit_line_edit_mode(); | ||
| 203 | return (AE_OK); | ||
| 204 | } | ||
| 205 | |||
| 206 | #ifndef ACPI_USE_NATIVE_RSDP_POINTER | ||
| 207 | /****************************************************************************** | ||
| 208 | * | ||
| 209 | * FUNCTION: acpi_os_get_root_pointer | ||
| 210 | * | ||
| 211 | * PARAMETERS: None | ||
| 212 | * | ||
| 213 | * RETURN: RSDP physical address | ||
| 214 | * | ||
| 215 | * DESCRIPTION: Gets the ACPI root pointer (RSDP) | ||
| 216 | * | ||
| 217 | *****************************************************************************/ | ||
| 218 | |||
| 219 | acpi_physical_address acpi_os_get_root_pointer(void) | ||
| 220 | { | ||
| 221 | |||
| 222 | return (0); | ||
| 223 | } | ||
| 224 | #endif | ||
| 225 | |||
| 226 | /****************************************************************************** | ||
| 227 | * | ||
| 228 | * FUNCTION: acpi_os_predefined_override | ||
| 229 | * | ||
| 230 | * PARAMETERS: init_val - Initial value of the predefined object | ||
| 231 | * new_val - The new value for the object | ||
| 232 | * | ||
| 233 | * RETURN: Status, pointer to value. Null pointer returned if not | ||
| 234 | * overriding. | ||
| 235 | * | ||
| 236 | * DESCRIPTION: Allow the OS to override predefined names | ||
| 237 | * | ||
| 238 | *****************************************************************************/ | ||
| 239 | |||
| 240 | acpi_status | ||
| 241 | acpi_os_predefined_override(const struct acpi_predefined_names * init_val, | ||
| 242 | acpi_string * new_val) | ||
| 243 | { | ||
| 244 | |||
| 245 | if (!init_val || !new_val) { | ||
| 246 | return (AE_BAD_PARAMETER); | ||
| 247 | } | ||
| 248 | |||
| 249 | *new_val = NULL; | ||
| 250 | return (AE_OK); | ||
| 251 | } | ||
| 252 | |||
| 253 | /****************************************************************************** | ||
| 254 | * | ||
| 255 | * FUNCTION: acpi_os_table_override | ||
| 256 | * | ||
| 257 | * PARAMETERS: existing_table - Header of current table (probably | ||
| 258 | * firmware) | ||
| 259 | * new_table - Where an entire new table is returned. | ||
| 260 | * | ||
| 261 | * RETURN: Status, pointer to new table. Null pointer returned if no | ||
| 262 | * table is available to override | ||
| 263 | * | ||
| 264 | * DESCRIPTION: Return a different version of a table if one is available | ||
| 265 | * | ||
| 266 | *****************************************************************************/ | ||
| 267 | |||
| 268 | acpi_status | ||
| 269 | acpi_os_table_override(struct acpi_table_header * existing_table, | ||
| 270 | struct acpi_table_header ** new_table) | ||
| 271 | { | ||
| 272 | |||
| 273 | if (!existing_table || !new_table) { | ||
| 274 | return (AE_BAD_PARAMETER); | ||
| 275 | } | ||
| 276 | |||
| 277 | *new_table = NULL; | ||
| 278 | |||
| 279 | #ifdef ACPI_EXEC_APP | ||
| 280 | |||
| 281 | ae_table_override(existing_table, new_table); | ||
| 282 | return (AE_OK); | ||
| 283 | #else | ||
| 284 | |||
| 285 | return (AE_NO_ACPI_TABLES); | ||
| 286 | #endif | ||
| 287 | } | ||
| 288 | |||
| 289 | /****************************************************************************** | ||
| 290 | * | ||
| 291 | * FUNCTION: acpi_os_physical_table_override | ||
| 292 | * | ||
| 293 | * PARAMETERS: existing_table - Header of current table (probably firmware) | ||
| 294 | * new_address - Where new table address is returned | ||
| 295 | * (Physical address) | ||
| 296 | * new_table_length - Where new table length is returned | ||
| 297 | * | ||
| 298 | * RETURN: Status, address/length of new table. Null pointer returned | ||
| 299 | * if no table is available to override. | ||
| 300 | * | ||
| 301 | * DESCRIPTION: Returns AE_SUPPORT, function not used in user space. | ||
| 302 | * | ||
| 303 | *****************************************************************************/ | ||
| 304 | |||
| 305 | acpi_status | ||
| 306 | acpi_os_physical_table_override(struct acpi_table_header * existing_table, | ||
| 307 | acpi_physical_address * new_address, | ||
| 308 | u32 *new_table_length) | ||
| 309 | { | ||
| 310 | |||
| 311 | return (AE_SUPPORT); | ||
| 312 | } | ||
| 313 | |||
| 314 | /****************************************************************************** | ||
| 315 | * | ||
| 316 | * FUNCTION: acpi_os_redirect_output | ||
| 317 | * | ||
| 318 | * PARAMETERS: destination - An open file handle/pointer | ||
| 319 | * | ||
| 320 | * RETURN: None | ||
| 321 | * | ||
| 322 | * DESCRIPTION: Causes redirect of acpi_os_printf and acpi_os_vprintf | ||
| 323 | * | ||
| 324 | *****************************************************************************/ | ||
| 325 | |||
| 326 | void acpi_os_redirect_output(void *destination) | ||
| 327 | { | ||
| 328 | |||
| 329 | acpi_gbl_output_file = destination; | ||
| 330 | } | ||
| 331 | |||
| 332 | /****************************************************************************** | ||
| 333 | * | ||
| 334 | * FUNCTION: acpi_os_printf | ||
| 335 | * | ||
| 336 | * PARAMETERS: fmt, ... - Standard printf format | ||
| 337 | * | ||
| 338 | * RETURN: None | ||
| 339 | * | ||
| 340 | * DESCRIPTION: Formatted output. Note: very similar to acpi_os_vprintf | ||
| 341 | * (performance), changes should be tracked in both functions. | ||
| 342 | * | ||
| 343 | *****************************************************************************/ | ||
| 344 | |||
| 345 | void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...) | ||
| 346 | { | ||
| 347 | va_list args; | ||
| 348 | u8 flags; | ||
| 349 | |||
| 350 | flags = acpi_gbl_db_output_flags; | ||
| 351 | if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) { | ||
| 352 | |||
| 353 | /* Output is directable to either a file (if open) or the console */ | ||
| 354 | |||
| 355 | if (acpi_gbl_debug_file) { | ||
| 356 | |||
| 357 | /* Output file is open, send the output there */ | ||
| 358 | |||
| 359 | va_start(args, fmt); | ||
| 360 | vfprintf(acpi_gbl_debug_file, fmt, args); | ||
| 361 | va_end(args); | ||
| 362 | } else { | ||
| 363 | /* No redirection, send output to console (once only!) */ | ||
| 364 | |||
| 365 | flags |= ACPI_DB_CONSOLE_OUTPUT; | ||
| 366 | } | ||
| 367 | } | ||
| 368 | |||
| 369 | if (flags & ACPI_DB_CONSOLE_OUTPUT) { | ||
| 370 | va_start(args, fmt); | ||
| 371 | vfprintf(acpi_gbl_output_file, fmt, args); | ||
| 372 | va_end(args); | ||
| 373 | } | ||
| 374 | } | ||
| 375 | |||
| 376 | /****************************************************************************** | ||
| 377 | * | ||
| 378 | * FUNCTION: acpi_os_vprintf | ||
| 379 | * | ||
| 380 | * PARAMETERS: fmt - Standard printf format | ||
| 381 | * args - Argument list | ||
| 382 | * | ||
| 383 | * RETURN: None | ||
| 384 | * | ||
| 385 | * DESCRIPTION: Formatted output with argument list pointer. Note: very | ||
| 386 | * similar to acpi_os_printf, changes should be tracked in both | ||
| 387 | * functions. | ||
| 388 | * | ||
| 389 | *****************************************************************************/ | ||
| 390 | |||
| 391 | void acpi_os_vprintf(const char *fmt, va_list args) | ||
| 392 | { | ||
| 393 | u8 flags; | ||
| 394 | char buffer[ACPI_VPRINTF_BUFFER_SIZE]; | ||
| 395 | |||
| 396 | /* | ||
| 397 | * We build the output string in a local buffer because we may be | ||
| 398 | * outputting the buffer twice. Using vfprintf is problematic because | ||
| 399 | * some implementations modify the args pointer/structure during | ||
| 400 | * execution. Thus, we use the local buffer for portability. | ||
| 401 | * | ||
| 402 | * Note: Since this module is intended for use by the various ACPICA | ||
| 403 | * utilities/applications, we can safely declare the buffer on the stack. | ||
| 404 | * Also, This function is used for relatively small error messages only. | ||
| 405 | */ | ||
| 406 | vsnprintf(buffer, ACPI_VPRINTF_BUFFER_SIZE, fmt, args); | ||
| 407 | |||
| 408 | flags = acpi_gbl_db_output_flags; | ||
| 409 | if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) { | ||
| 410 | |||
| 411 | /* Output is directable to either a file (if open) or the console */ | ||
| 412 | |||
| 413 | if (acpi_gbl_debug_file) { | ||
| 414 | |||
| 415 | /* Output file is open, send the output there */ | ||
| 416 | |||
| 417 | fputs(buffer, acpi_gbl_debug_file); | ||
| 418 | } else { | ||
| 419 | /* No redirection, send output to console (once only!) */ | ||
| 420 | |||
| 421 | flags |= ACPI_DB_CONSOLE_OUTPUT; | ||
| 422 | } | ||
| 423 | } | ||
| 424 | |||
| 425 | if (flags & ACPI_DB_CONSOLE_OUTPUT) { | ||
| 426 | fputs(buffer, acpi_gbl_output_file); | ||
| 427 | } | ||
| 428 | } | ||
| 429 | |||
| 430 | #ifndef ACPI_EXEC_APP | ||
| 431 | /****************************************************************************** | ||
| 432 | * | ||
| 433 | * FUNCTION: acpi_os_get_line | ||
| 434 | * | ||
| 435 | * PARAMETERS: buffer - Where to return the command line | ||
| 436 | * buffer_length - Maximum length of Buffer | ||
| 437 | * bytes_read - Where the actual byte count is returned | ||
| 438 | * | ||
| 439 | * RETURN: Status and actual bytes read | ||
| 440 | * | ||
| 441 | * DESCRIPTION: Get the next input line from the terminal. NOTE: For the | ||
| 442 | * acpi_exec utility, we use the acgetline module instead to | ||
| 443 | * provide line-editing and history support. | ||
| 444 | * | ||
| 445 | *****************************************************************************/ | ||
| 446 | |||
| 447 | acpi_status acpi_os_get_line(char *buffer, u32 buffer_length, u32 *bytes_read) | ||
| 448 | { | ||
| 449 | int input_char; | ||
| 450 | u32 end_of_line; | ||
| 451 | |||
| 452 | /* Standard acpi_os_get_line for all utilities except acpi_exec */ | ||
| 453 | |||
| 454 | for (end_of_line = 0;; end_of_line++) { | ||
| 455 | if (end_of_line >= buffer_length) { | ||
| 456 | return (AE_BUFFER_OVERFLOW); | ||
| 457 | } | ||
| 458 | |||
| 459 | if ((input_char = getchar()) == EOF) { | ||
| 460 | return (AE_ERROR); | ||
| 461 | } | ||
| 462 | |||
| 463 | if (!input_char || input_char == _ASCII_NEWLINE) { | ||
| 464 | break; | ||
| 465 | } | ||
| 466 | |||
| 467 | buffer[end_of_line] = (char)input_char; | ||
| 468 | } | ||
| 469 | |||
| 470 | /* Null terminate the buffer */ | ||
| 471 | |||
| 472 | buffer[end_of_line] = 0; | ||
| 473 | |||
| 474 | /* Return the number of bytes in the string */ | ||
| 475 | |||
| 476 | if (bytes_read) { | ||
| 477 | *bytes_read = end_of_line; | ||
| 478 | } | ||
| 479 | |||
| 480 | return (AE_OK); | ||
| 481 | } | ||
| 482 | #endif | ||
| 483 | |||
| 484 | #ifndef ACPI_USE_NATIVE_MEMORY_MAPPING | ||
| 485 | /****************************************************************************** | ||
| 486 | * | ||
| 487 | * FUNCTION: acpi_os_map_memory | ||
| 488 | * | ||
| 489 | * PARAMETERS: where - Physical address of memory to be mapped | ||
| 490 | * length - How much memory to map | ||
| 491 | * | ||
| 492 | * RETURN: Pointer to mapped memory. Null on error. | ||
| 493 | * | ||
| 494 | * DESCRIPTION: Map physical memory into caller's address space | ||
| 495 | * | ||
| 496 | *****************************************************************************/ | ||
| 497 | |||
| 498 | void *acpi_os_map_memory(acpi_physical_address where, acpi_size length) | ||
| 499 | { | ||
| 500 | |||
| 501 | return (ACPI_TO_POINTER((acpi_size) where)); | ||
| 502 | } | ||
| 503 | |||
| 504 | /****************************************************************************** | ||
| 505 | * | ||
| 506 | * FUNCTION: acpi_os_unmap_memory | ||
| 507 | * | ||
| 508 | * PARAMETERS: where - Logical address of memory to be unmapped | ||
| 509 | * length - How much memory to unmap | ||
| 510 | * | ||
| 511 | * RETURN: None. | ||
| 512 | * | ||
| 513 | * DESCRIPTION: Delete a previously created mapping. Where and Length must | ||
| 514 | * correspond to a previous mapping exactly. | ||
| 515 | * | ||
| 516 | *****************************************************************************/ | ||
| 517 | |||
| 518 | void acpi_os_unmap_memory(void *where, acpi_size length) | ||
| 519 | { | ||
| 520 | |||
| 521 | return; | ||
| 522 | } | ||
| 523 | #endif | ||
| 524 | |||
| 525 | /****************************************************************************** | ||
| 526 | * | ||
| 527 | * FUNCTION: acpi_os_allocate | ||
| 528 | * | ||
| 529 | * PARAMETERS: size - Amount to allocate, in bytes | ||
| 530 | * | ||
| 531 | * RETURN: Pointer to the new allocation. Null on error. | ||
| 532 | * | ||
| 533 | * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS. | ||
| 534 | * | ||
| 535 | *****************************************************************************/ | ||
| 536 | |||
| 537 | void *acpi_os_allocate(acpi_size size) | ||
| 538 | { | ||
| 539 | void *mem; | ||
| 540 | |||
| 541 | mem = (void *)malloc((size_t) size); | ||
| 542 | return (mem); | ||
| 543 | } | ||
| 544 | |||
| 545 | #ifdef USE_NATIVE_ALLOCATE_ZEROED | ||
| 546 | /****************************************************************************** | ||
| 547 | * | ||
| 548 | * FUNCTION: acpi_os_allocate_zeroed | ||
| 549 | * | ||
| 550 | * PARAMETERS: size - Amount to allocate, in bytes | ||
| 551 | * | ||
| 552 | * RETURN: Pointer to the new allocation. Null on error. | ||
| 553 | * | ||
| 554 | * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS. | ||
| 555 | * | ||
| 556 | *****************************************************************************/ | ||
| 557 | |||
| 558 | void *acpi_os_allocate_zeroed(acpi_size size) | ||
| 559 | { | ||
| 560 | void *mem; | ||
| 561 | |||
| 562 | mem = (void *)calloc(1, (size_t) size); | ||
| 563 | return (mem); | ||
| 564 | } | ||
| 565 | #endif | ||
| 566 | |||
| 567 | /****************************************************************************** | ||
| 568 | * | ||
| 569 | * FUNCTION: acpi_os_free | ||
| 570 | * | ||
| 571 | * PARAMETERS: mem - Pointer to previously allocated memory | ||
| 572 | * | ||
| 573 | * RETURN: None. | ||
| 574 | * | ||
| 575 | * DESCRIPTION: Free memory allocated via acpi_os_allocate | ||
| 576 | * | ||
| 577 | *****************************************************************************/ | ||
| 578 | |||
| 579 | void acpi_os_free(void *mem) | ||
| 580 | { | ||
| 581 | |||
| 582 | free(mem); | ||
| 583 | } | ||
| 584 | |||
| 585 | #ifdef ACPI_SINGLE_THREADED | ||
| 586 | /****************************************************************************** | ||
| 587 | * | ||
| 588 | * FUNCTION: Semaphore stub functions | ||
| 589 | * | ||
| 590 | * DESCRIPTION: Stub functions used for single-thread applications that do | ||
| 591 | * not require semaphore synchronization. Full implementations | ||
| 592 | * of these functions appear after the stubs. | ||
| 593 | * | ||
| 594 | *****************************************************************************/ | ||
| 595 | |||
| 596 | acpi_status | ||
| 597 | acpi_os_create_semaphore(u32 max_units, | ||
| 598 | u32 initial_units, acpi_handle * out_handle) | ||
| 599 | { | ||
| 600 | *out_handle = (acpi_handle) 1; | ||
| 601 | return (AE_OK); | ||
| 602 | } | ||
| 603 | |||
| 604 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) | ||
| 605 | { | ||
| 606 | return (AE_OK); | ||
| 607 | } | ||
| 608 | |||
| 609 | acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) | ||
| 610 | { | ||
| 611 | return (AE_OK); | ||
| 612 | } | ||
| 613 | |||
| 614 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) | ||
| 615 | { | ||
| 616 | return (AE_OK); | ||
| 617 | } | ||
| 618 | |||
| 619 | #else | ||
| 620 | /****************************************************************************** | ||
| 621 | * | ||
| 622 | * FUNCTION: acpi_os_create_semaphore | ||
| 623 | * | ||
| 624 | * PARAMETERS: initial_units - Units to be assigned to the new semaphore | ||
| 625 | * out_handle - Where a handle will be returned | ||
| 626 | * | ||
| 627 | * RETURN: Status | ||
| 628 | * | ||
| 629 | * DESCRIPTION: Create an OS semaphore | ||
| 630 | * | ||
| 631 | *****************************************************************************/ | ||
| 632 | |||
| 633 | acpi_status | ||
| 634 | acpi_os_create_semaphore(u32 max_units, | ||
| 635 | u32 initial_units, acpi_handle * out_handle) | ||
| 636 | { | ||
| 637 | sem_t *sem; | ||
| 638 | |||
| 639 | if (!out_handle) { | ||
| 640 | return (AE_BAD_PARAMETER); | ||
| 641 | } | ||
| 642 | #ifdef __APPLE__ | ||
| 643 | { | ||
| 644 | char *semaphore_name = tmpnam(NULL); | ||
| 645 | |||
| 646 | sem = | ||
| 647 | sem_open(semaphore_name, O_EXCL | O_CREAT, 0755, | ||
| 648 | initial_units); | ||
| 649 | if (!sem) { | ||
| 650 | return (AE_NO_MEMORY); | ||
| 651 | } | ||
| 652 | sem_unlink(semaphore_name); /* This just deletes the name */ | ||
| 653 | } | ||
| 654 | |||
| 655 | #else | ||
| 656 | sem = acpi_os_allocate(sizeof(sem_t)); | ||
| 657 | if (!sem) { | ||
| 658 | return (AE_NO_MEMORY); | ||
| 659 | } | ||
| 660 | |||
| 661 | if (sem_init(sem, 0, initial_units) == -1) { | ||
| 662 | acpi_os_free(sem); | ||
| 663 | return (AE_BAD_PARAMETER); | ||
| 664 | } | ||
| 665 | #endif | ||
| 666 | |||
| 667 | *out_handle = (acpi_handle) sem; | ||
| 668 | return (AE_OK); | ||
| 669 | } | ||
| 670 | |||
| 671 | /****************************************************************************** | ||
| 672 | * | ||
| 673 | * FUNCTION: acpi_os_delete_semaphore | ||
| 674 | * | ||
| 675 | * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore | ||
| 676 | * | ||
| 677 | * RETURN: Status | ||
| 678 | * | ||
| 679 | * DESCRIPTION: Delete an OS semaphore | ||
| 680 | * | ||
| 681 | *****************************************************************************/ | ||
| 682 | |||
| 683 | acpi_status acpi_os_delete_semaphore(acpi_handle handle) | ||
| 684 | { | ||
| 685 | sem_t *sem = (sem_t *) handle; | ||
| 686 | |||
| 687 | if (!sem) { | ||
| 688 | return (AE_BAD_PARAMETER); | ||
| 689 | } | ||
| 690 | |||
| 691 | if (sem_destroy(sem) == -1) { | ||
| 692 | return (AE_BAD_PARAMETER); | ||
| 693 | } | ||
| 694 | |||
| 695 | return (AE_OK); | ||
| 696 | } | ||
| 697 | |||
| 698 | /****************************************************************************** | ||
| 699 | * | ||
| 700 | * FUNCTION: acpi_os_wait_semaphore | ||
| 701 | * | ||
| 702 | * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore | ||
| 703 | * units - How many units to wait for | ||
| 704 | * msec_timeout - How long to wait (milliseconds) | ||
| 705 | * | ||
| 706 | * RETURN: Status | ||
| 707 | * | ||
| 708 | * DESCRIPTION: Wait for units | ||
| 709 | * | ||
| 710 | *****************************************************************************/ | ||
| 711 | |||
| 712 | acpi_status | ||
| 713 | acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 msec_timeout) | ||
| 714 | { | ||
| 715 | acpi_status status = AE_OK; | ||
| 716 | sem_t *sem = (sem_t *) handle; | ||
| 717 | #ifndef ACPI_USE_ALTERNATE_TIMEOUT | ||
| 718 | struct timespec time; | ||
| 719 | int ret_val; | ||
| 720 | #endif | ||
| 721 | |||
| 722 | if (!sem) { | ||
| 723 | return (AE_BAD_PARAMETER); | ||
| 724 | } | ||
| 725 | |||
| 726 | switch (msec_timeout) { | ||
| 727 | /* | ||
| 728 | * No Wait: | ||
| 729 | * -------- | ||
| 730 | * A zero timeout value indicates that we shouldn't wait - just | ||
| 731 | * acquire the semaphore if available otherwise return AE_TIME | ||
| 732 | * (a.k.a. 'would block'). | ||
| 733 | */ | ||
| 734 | case 0: | ||
| 735 | |||
| 736 | if (sem_trywait(sem) == -1) { | ||
| 737 | status = (AE_TIME); | ||
| 738 | } | ||
| 739 | break; | ||
| 740 | |||
| 741 | /* Wait Indefinitely */ | ||
| 742 | |||
| 743 | case ACPI_WAIT_FOREVER: | ||
| 744 | |||
| 745 | if (sem_wait(sem)) { | ||
| 746 | status = (AE_TIME); | ||
| 747 | } | ||
| 748 | break; | ||
| 749 | |||
| 750 | /* Wait with msec_timeout */ | ||
| 751 | |||
| 752 | default: | ||
| 753 | |||
| 754 | #ifdef ACPI_USE_ALTERNATE_TIMEOUT | ||
| 755 | /* | ||
| 756 | * Alternate timeout mechanism for environments where | ||
| 757 | * sem_timedwait is not available or does not work properly. | ||
| 758 | */ | ||
| 759 | while (msec_timeout) { | ||
| 760 | if (sem_trywait(sem) == 0) { | ||
| 761 | |||
| 762 | /* Got the semaphore */ | ||
| 763 | return (AE_OK); | ||
| 764 | } | ||
| 765 | |||
| 766 | if (msec_timeout >= 10) { | ||
| 767 | msec_timeout -= 10; | ||
| 768 | usleep(10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */ | ||
| 769 | } else { | ||
| 770 | msec_timeout--; | ||
| 771 | usleep(ACPI_USEC_PER_MSEC); /* one millisecond */ | ||
| 772 | } | ||
| 773 | } | ||
| 774 | status = (AE_TIME); | ||
| 775 | #else | ||
| 776 | /* | ||
| 777 | * The interface to sem_timedwait is an absolute time, so we need to | ||
| 778 | * get the current time, then add in the millisecond Timeout value. | ||
| 779 | */ | ||
| 780 | if (clock_gettime(CLOCK_REALTIME, &time) == -1) { | ||
| 781 | perror("clock_gettime"); | ||
| 782 | return (AE_TIME); | ||
| 783 | } | ||
| 784 | |||
| 785 | time.tv_sec += (msec_timeout / ACPI_MSEC_PER_SEC); | ||
| 786 | time.tv_nsec += | ||
| 787 | ((msec_timeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC); | ||
| 788 | |||
| 789 | /* Handle nanosecond overflow (field must be less than one second) */ | ||
| 790 | |||
| 791 | if (time.tv_nsec >= ACPI_NSEC_PER_SEC) { | ||
| 792 | time.tv_sec += (time.tv_nsec / ACPI_NSEC_PER_SEC); | ||
| 793 | time.tv_nsec = (time.tv_nsec % ACPI_NSEC_PER_SEC); | ||
| 794 | } | ||
| 795 | |||
| 796 | while (((ret_val = sem_timedwait(sem, &time)) == -1) | ||
| 797 | && (errno == EINTR)) { | ||
| 798 | continue; | ||
| 799 | } | ||
| 800 | |||
| 801 | if (ret_val != 0) { | ||
| 802 | if (errno != ETIMEDOUT) { | ||
| 803 | perror("sem_timedwait"); | ||
| 804 | } | ||
| 805 | status = (AE_TIME); | ||
| 806 | } | ||
| 807 | #endif | ||
| 808 | break; | ||
| 809 | } | ||
| 810 | |||
| 811 | return (status); | ||
| 812 | } | ||
| 813 | |||
| 814 | /****************************************************************************** | ||
| 815 | * | ||
| 816 | * FUNCTION: acpi_os_signal_semaphore | ||
| 817 | * | ||
| 818 | * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore | ||
| 819 | * units - Number of units to send | ||
| 820 | * | ||
| 821 | * RETURN: Status | ||
| 822 | * | ||
| 823 | * DESCRIPTION: Send units | ||
| 824 | * | ||
| 825 | *****************************************************************************/ | ||
| 826 | |||
| 827 | acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) | ||
| 828 | { | ||
| 829 | sem_t *sem = (sem_t *) handle; | ||
| 830 | |||
| 831 | if (!sem) { | ||
| 832 | return (AE_BAD_PARAMETER); | ||
| 833 | } | ||
| 834 | |||
| 835 | if (sem_post(sem) == -1) { | ||
| 836 | return (AE_LIMIT); | ||
| 837 | } | ||
| 838 | |||
| 839 | return (AE_OK); | ||
| 840 | } | ||
| 841 | |||
| 842 | #endif /* ACPI_SINGLE_THREADED */ | ||
| 843 | |||
| 844 | /****************************************************************************** | ||
| 845 | * | ||
| 846 | * FUNCTION: Spinlock interfaces | ||
| 847 | * | ||
| 848 | * DESCRIPTION: Map these interfaces to semaphore interfaces | ||
| 849 | * | ||
| 850 | *****************************************************************************/ | ||
| 851 | |||
| 852 | acpi_status acpi_os_create_lock(acpi_spinlock * out_handle) | ||
| 853 | { | ||
| 854 | |||
| 855 | return (acpi_os_create_semaphore(1, 1, out_handle)); | ||
| 856 | } | ||
| 857 | |||
| 858 | void acpi_os_delete_lock(acpi_spinlock handle) | ||
| 859 | { | ||
| 860 | acpi_os_delete_semaphore(handle); | ||
| 861 | } | ||
| 862 | |||
| 863 | acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle) | ||
| 864 | { | ||
| 865 | acpi_os_wait_semaphore(handle, 1, 0xFFFF); | ||
| 866 | return (0); | ||
| 867 | } | ||
| 868 | |||
| 869 | void acpi_os_release_lock(acpi_spinlock handle, acpi_cpu_flags flags) | ||
| 870 | { | ||
| 871 | acpi_os_signal_semaphore(handle, 1); | ||
| 872 | } | ||
| 873 | |||
| 874 | /****************************************************************************** | ||
| 875 | * | ||
| 876 | * FUNCTION: acpi_os_install_interrupt_handler | ||
| 877 | * | ||
| 878 | * PARAMETERS: interrupt_number - Level handler should respond to. | ||
| 879 | * isr - Address of the ACPI interrupt handler | ||
| 880 | * except_ptr - Where status is returned | ||
| 881 | * | ||
| 882 | * RETURN: Handle to the newly installed handler. | ||
| 883 | * | ||
| 884 | * DESCRIPTION: Install an interrupt handler. Used to install the ACPI | ||
| 885 | * OS-independent handler. | ||
| 886 | * | ||
| 887 | *****************************************************************************/ | ||
| 888 | |||
| 889 | u32 | ||
| 890 | acpi_os_install_interrupt_handler(u32 interrupt_number, | ||
| 891 | acpi_osd_handler service_routine, | ||
| 892 | void *context) | ||
| 893 | { | ||
| 894 | |||
| 895 | return (AE_OK); | ||
| 896 | } | ||
| 897 | |||
| 898 | /****************************************************************************** | ||
| 899 | * | ||
| 900 | * FUNCTION: acpi_os_remove_interrupt_handler | ||
| 901 | * | ||
| 902 | * PARAMETERS: handle - Returned when handler was installed | ||
| 903 | * | ||
| 904 | * RETURN: Status | ||
| 905 | * | ||
| 906 | * DESCRIPTION: Uninstalls an interrupt handler. | ||
| 907 | * | ||
| 908 | *****************************************************************************/ | ||
| 909 | |||
| 910 | acpi_status | ||
| 911 | acpi_os_remove_interrupt_handler(u32 interrupt_number, | ||
| 912 | acpi_osd_handler service_routine) | ||
| 913 | { | ||
| 914 | |||
| 915 | return (AE_OK); | ||
| 916 | } | ||
| 917 | |||
| 918 | /****************************************************************************** | ||
| 919 | * | ||
| 920 | * FUNCTION: acpi_os_stall | ||
| 921 | * | ||
| 922 | * PARAMETERS: microseconds - Time to sleep | ||
| 923 | * | ||
| 924 | * RETURN: Blocks until sleep is completed. | ||
| 925 | * | ||
| 926 | * DESCRIPTION: Sleep at microsecond granularity | ||
| 927 | * | ||
| 928 | *****************************************************************************/ | ||
| 929 | |||
| 930 | void acpi_os_stall(u32 microseconds) | ||
| 931 | { | ||
| 932 | |||
| 933 | if (microseconds) { | ||
| 934 | usleep(microseconds); | ||
| 935 | } | ||
| 936 | } | ||
| 937 | |||
| 938 | /****************************************************************************** | ||
| 939 | * | ||
| 940 | * FUNCTION: acpi_os_sleep | ||
| 941 | * | ||
| 942 | * PARAMETERS: milliseconds - Time to sleep | ||
| 943 | * | ||
| 944 | * RETURN: Blocks until sleep is completed. | ||
| 945 | * | ||
| 946 | * DESCRIPTION: Sleep at millisecond granularity | ||
| 947 | * | ||
| 948 | *****************************************************************************/ | ||
| 949 | |||
| 950 | void acpi_os_sleep(u64 milliseconds) | ||
| 951 | { | ||
| 952 | |||
| 953 | /* Sleep for whole seconds */ | ||
| 954 | |||
| 955 | sleep(milliseconds / ACPI_MSEC_PER_SEC); | ||
| 956 | |||
| 957 | /* | ||
| 958 | * Sleep for remaining microseconds. | ||
| 959 | * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second). | ||
| 960 | */ | ||
| 961 | usleep((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC); | ||
| 962 | } | ||
| 963 | |||
| 964 | /****************************************************************************** | ||
| 965 | * | ||
| 966 | * FUNCTION: acpi_os_get_timer | ||
| 967 | * | ||
| 968 | * PARAMETERS: None | ||
| 969 | * | ||
| 970 | * RETURN: Current time in 100 nanosecond units | ||
| 971 | * | ||
| 972 | * DESCRIPTION: Get the current system time | ||
| 973 | * | ||
| 974 | *****************************************************************************/ | ||
| 975 | |||
| 976 | u64 acpi_os_get_timer(void) | ||
| 977 | { | ||
| 978 | struct timeval time; | ||
| 979 | |||
| 980 | /* This timer has sufficient resolution for user-space application code */ | ||
| 981 | |||
| 982 | gettimeofday(&time, NULL); | ||
| 983 | |||
| 984 | /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */ | ||
| 985 | |||
| 986 | return (((u64)time.tv_sec * ACPI_100NSEC_PER_SEC) + | ||
| 987 | ((u64)time.tv_usec * ACPI_100NSEC_PER_USEC)); | ||
| 988 | } | ||
| 989 | |||
| 990 | /****************************************************************************** | ||
| 991 | * | ||
| 992 | * FUNCTION: acpi_os_read_pci_configuration | ||
| 993 | * | ||
| 994 | * PARAMETERS: pci_id - Seg/Bus/Dev | ||
| 995 | * pci_register - Device Register | ||
| 996 | * value - Buffer where value is placed | ||
| 997 | * width - Number of bits | ||
| 998 | * | ||
| 999 | * RETURN: Status | ||
| 1000 | * | ||
| 1001 | * DESCRIPTION: Read data from PCI configuration space | ||
| 1002 | * | ||
| 1003 | *****************************************************************************/ | ||
| 1004 | |||
| 1005 | acpi_status | ||
| 1006 | acpi_os_read_pci_configuration(struct acpi_pci_id *pci_id, | ||
| 1007 | u32 pci_register, u64 *value, u32 width) | ||
| 1008 | { | ||
| 1009 | |||
| 1010 | *value = 0; | ||
| 1011 | return (AE_OK); | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | /****************************************************************************** | ||
| 1015 | * | ||
| 1016 | * FUNCTION: acpi_os_write_pci_configuration | ||
| 1017 | * | ||
| 1018 | * PARAMETERS: pci_id - Seg/Bus/Dev | ||
| 1019 | * pci_register - Device Register | ||
| 1020 | * value - Value to be written | ||
| 1021 | * width - Number of bits | ||
| 1022 | * | ||
| 1023 | * RETURN: Status. | ||
| 1024 | * | ||
| 1025 | * DESCRIPTION: Write data to PCI configuration space | ||
| 1026 | * | ||
| 1027 | *****************************************************************************/ | ||
| 1028 | |||
| 1029 | acpi_status | ||
| 1030 | acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, | ||
| 1031 | u32 pci_register, u64 value, u32 width) | ||
| 1032 | { | ||
| 1033 | |||
| 1034 | return (AE_OK); | ||
| 1035 | } | ||
| 1036 | |||
| 1037 | /****************************************************************************** | ||
| 1038 | * | ||
| 1039 | * FUNCTION: acpi_os_read_port | ||
| 1040 | * | ||
| 1041 | * PARAMETERS: address - Address of I/O port/register to read | ||
| 1042 | * value - Where value is placed | ||
| 1043 | * width - Number of bits | ||
| 1044 | * | ||
| 1045 | * RETURN: Value read from port | ||
| 1046 | * | ||
| 1047 | * DESCRIPTION: Read data from an I/O port or register | ||
| 1048 | * | ||
| 1049 | *****************************************************************************/ | ||
| 1050 | |||
| 1051 | acpi_status acpi_os_read_port(acpi_io_address address, u32 *value, u32 width) | ||
| 1052 | { | ||
| 1053 | |||
| 1054 | switch (width) { | ||
| 1055 | case 8: | ||
| 1056 | |||
| 1057 | *value = 0xFF; | ||
| 1058 | break; | ||
| 1059 | |||
| 1060 | case 16: | ||
| 1061 | |||
| 1062 | *value = 0xFFFF; | ||
| 1063 | break; | ||
| 1064 | |||
| 1065 | case 32: | ||
| 1066 | |||
| 1067 | *value = 0xFFFFFFFF; | ||
| 1068 | break; | ||
| 1069 | |||
| 1070 | default: | ||
| 1071 | |||
| 1072 | return (AE_BAD_PARAMETER); | ||
| 1073 | } | ||
| 1074 | |||
| 1075 | return (AE_OK); | ||
| 1076 | } | ||
| 1077 | |||
| 1078 | /****************************************************************************** | ||
| 1079 | * | ||
| 1080 | * FUNCTION: acpi_os_write_port | ||
| 1081 | * | ||
| 1082 | * PARAMETERS: address - Address of I/O port/register to write | ||
| 1083 | * value - Value to write | ||
| 1084 | * width - Number of bits | ||
| 1085 | * | ||
| 1086 | * RETURN: None | ||
| 1087 | * | ||
| 1088 | * DESCRIPTION: Write data to an I/O port or register | ||
| 1089 | * | ||
| 1090 | *****************************************************************************/ | ||
| 1091 | |||
| 1092 | acpi_status acpi_os_write_port(acpi_io_address address, u32 value, u32 width) | ||
| 1093 | { | ||
| 1094 | |||
| 1095 | return (AE_OK); | ||
| 1096 | } | ||
| 1097 | |||
| 1098 | /****************************************************************************** | ||
| 1099 | * | ||
| 1100 | * FUNCTION: acpi_os_read_memory | ||
| 1101 | * | ||
| 1102 | * PARAMETERS: address - Physical Memory Address to read | ||
| 1103 | * value - Where value is placed | ||
| 1104 | * width - Number of bits (8,16,32, or 64) | ||
| 1105 | * | ||
| 1106 | * RETURN: Value read from physical memory address. Always returned | ||
| 1107 | * as a 64-bit integer, regardless of the read width. | ||
| 1108 | * | ||
| 1109 | * DESCRIPTION: Read data from a physical memory address | ||
| 1110 | * | ||
| 1111 | *****************************************************************************/ | ||
| 1112 | |||
| 1113 | acpi_status | ||
| 1114 | acpi_os_read_memory(acpi_physical_address address, u64 *value, u32 width) | ||
| 1115 | { | ||
| 1116 | |||
| 1117 | switch (width) { | ||
| 1118 | case 8: | ||
| 1119 | case 16: | ||
| 1120 | case 32: | ||
| 1121 | case 64: | ||
| 1122 | |||
| 1123 | *value = 0; | ||
| 1124 | break; | ||
| 1125 | |||
| 1126 | default: | ||
| 1127 | |||
| 1128 | return (AE_BAD_PARAMETER); | ||
| 1129 | } | ||
| 1130 | return (AE_OK); | ||
| 1131 | } | ||
| 1132 | |||
| 1133 | /****************************************************************************** | ||
| 1134 | * | ||
| 1135 | * FUNCTION: acpi_os_write_memory | ||
| 1136 | * | ||
| 1137 | * PARAMETERS: address - Physical Memory Address to write | ||
| 1138 | * value - Value to write | ||
| 1139 | * width - Number of bits (8,16,32, or 64) | ||
| 1140 | * | ||
| 1141 | * RETURN: None | ||
| 1142 | * | ||
| 1143 | * DESCRIPTION: Write data to a physical memory address | ||
| 1144 | * | ||
| 1145 | *****************************************************************************/ | ||
| 1146 | |||
| 1147 | acpi_status | ||
| 1148 | acpi_os_write_memory(acpi_physical_address address, u64 value, u32 width) | ||
| 1149 | { | ||
| 1150 | |||
| 1151 | return (AE_OK); | ||
| 1152 | } | ||
| 1153 | |||
| 1154 | /****************************************************************************** | ||
| 1155 | * | ||
| 1156 | * FUNCTION: acpi_os_readable | ||
| 1157 | * | ||
| 1158 | * PARAMETERS: pointer - Area to be verified | ||
| 1159 | * length - Size of area | ||
| 1160 | * | ||
| 1161 | * RETURN: TRUE if readable for entire length | ||
| 1162 | * | ||
| 1163 | * DESCRIPTION: Verify that a pointer is valid for reading | ||
| 1164 | * | ||
| 1165 | *****************************************************************************/ | ||
| 1166 | |||
| 1167 | u8 acpi_os_readable(void *pointer, acpi_size length) | ||
| 1168 | { | ||
| 1169 | |||
| 1170 | return (TRUE); | ||
| 1171 | } | ||
| 1172 | |||
| 1173 | /****************************************************************************** | ||
| 1174 | * | ||
| 1175 | * FUNCTION: acpi_os_writable | ||
| 1176 | * | ||
| 1177 | * PARAMETERS: pointer - Area to be verified | ||
| 1178 | * length - Size of area | ||
| 1179 | * | ||
| 1180 | * RETURN: TRUE if writable for entire length | ||
| 1181 | * | ||
| 1182 | * DESCRIPTION: Verify that a pointer is valid for writing | ||
| 1183 | * | ||
| 1184 | *****************************************************************************/ | ||
| 1185 | |||
| 1186 | u8 acpi_os_writable(void *pointer, acpi_size length) | ||
| 1187 | { | ||
| 1188 | |||
| 1189 | return (TRUE); | ||
| 1190 | } | ||
| 1191 | |||
| 1192 | /****************************************************************************** | ||
| 1193 | * | ||
| 1194 | * FUNCTION: acpi_os_signal | ||
| 1195 | * | ||
| 1196 | * PARAMETERS: function - ACPI A signal function code | ||
| 1197 | * info - Pointer to function-dependent structure | ||
| 1198 | * | ||
| 1199 | * RETURN: Status | ||
| 1200 | * | ||
| 1201 | * DESCRIPTION: Miscellaneous functions. Example implementation only. | ||
| 1202 | * | ||
| 1203 | *****************************************************************************/ | ||
| 1204 | |||
| 1205 | acpi_status acpi_os_signal(u32 function, void *info) | ||
| 1206 | { | ||
| 1207 | |||
| 1208 | switch (function) { | ||
| 1209 | case ACPI_SIGNAL_FATAL: | ||
| 1210 | |||
| 1211 | break; | ||
| 1212 | |||
| 1213 | case ACPI_SIGNAL_BREAKPOINT: | ||
| 1214 | |||
| 1215 | break; | ||
| 1216 | |||
| 1217 | default: | ||
| 1218 | |||
| 1219 | break; | ||
| 1220 | } | ||
| 1221 | |||
| 1222 | return (AE_OK); | ||
| 1223 | } | ||
| 1224 | |||
| 1225 | /* Optional multi-thread support */ | ||
| 1226 | |||
| 1227 | #ifndef ACPI_SINGLE_THREADED | ||
| 1228 | /****************************************************************************** | ||
| 1229 | * | ||
| 1230 | * FUNCTION: acpi_os_get_thread_id | ||
| 1231 | * | ||
| 1232 | * PARAMETERS: None | ||
| 1233 | * | ||
| 1234 | * RETURN: Id of the running thread | ||
| 1235 | * | ||
| 1236 | * DESCRIPTION: Get the ID of the current (running) thread | ||
| 1237 | * | ||
| 1238 | *****************************************************************************/ | ||
| 1239 | |||
| 1240 | acpi_thread_id acpi_os_get_thread_id(void) | ||
| 1241 | { | ||
| 1242 | pthread_t thread; | ||
| 1243 | |||
| 1244 | thread = pthread_self(); | ||
| 1245 | return (ACPI_CAST_PTHREAD_T(thread)); | ||
| 1246 | } | ||
| 1247 | |||
| 1248 | /****************************************************************************** | ||
| 1249 | * | ||
| 1250 | * FUNCTION: acpi_os_execute | ||
| 1251 | * | ||
| 1252 | * PARAMETERS: type - Type of execution | ||
| 1253 | * function - Address of the function to execute | ||
| 1254 | * context - Passed as a parameter to the function | ||
| 1255 | * | ||
| 1256 | * RETURN: Status. | ||
| 1257 | * | ||
| 1258 | * DESCRIPTION: Execute a new thread | ||
| 1259 | * | ||
| 1260 | *****************************************************************************/ | ||
| 1261 | |||
| 1262 | acpi_status | ||
| 1263 | acpi_os_execute(acpi_execute_type type, | ||
| 1264 | acpi_osd_exec_callback function, void *context) | ||
| 1265 | { | ||
| 1266 | pthread_t thread; | ||
| 1267 | int ret; | ||
| 1268 | |||
| 1269 | ret = | ||
| 1270 | pthread_create(&thread, NULL, (PTHREAD_CALLBACK) function, context); | ||
| 1271 | if (ret) { | ||
| 1272 | acpi_os_printf("Create thread failed"); | ||
| 1273 | } | ||
| 1274 | return (0); | ||
| 1275 | } | ||
| 1276 | |||
| 1277 | #else /* ACPI_SINGLE_THREADED */ | ||
| 1278 | acpi_thread_id acpi_os_get_thread_id(void) | ||
| 1279 | { | ||
| 1280 | return (1); | ||
| 1281 | } | ||
| 1282 | |||
| 1283 | acpi_status | ||
| 1284 | acpi_os_execute(acpi_execute_type type, | ||
| 1285 | acpi_osd_exec_callback function, void *context) | ||
| 1286 | { | ||
| 1287 | |||
| 1288 | function(context); | ||
| 1289 | |||
| 1290 | return (AE_OK); | ||
| 1291 | } | ||
| 1292 | |||
| 1293 | #endif /* ACPI_SINGLE_THREADED */ | ||
| 1294 | |||
| 1295 | /****************************************************************************** | ||
| 1296 | * | ||
| 1297 | * FUNCTION: acpi_os_wait_events_complete | ||
| 1298 | * | ||
| 1299 | * PARAMETERS: None | ||
| 1300 | * | ||
| 1301 | * RETURN: None | ||
| 1302 | * | ||
| 1303 | * DESCRIPTION: Wait for all asynchronous events to complete. This | ||
| 1304 | * implementation does nothing. | ||
| 1305 | * | ||
| 1306 | *****************************************************************************/ | ||
| 1307 | |||
| 1308 | void acpi_os_wait_events_complete(void) | ||
| 1309 | { | ||
| 1310 | return; | ||
| 1311 | } | ||
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 @@ | |||
| 47 | #ifdef _DECLARE_GLOBALS | 47 | #ifdef _DECLARE_GLOBALS |
| 48 | #define EXTERN | 48 | #define EXTERN |
| 49 | #define INIT_GLOBAL(a,b) a=b | 49 | #define INIT_GLOBAL(a,b) a=b |
| 50 | #define DEFINE_ACPI_GLOBALS 1 | ||
| 51 | #else | 50 | #else |
| 52 | #define EXTERN extern | 51 | #define EXTERN extern |
| 53 | #define INIT_GLOBAL(a,b) a | 52 | #define INIT_GLOBAL(a,b) a |
| @@ -69,7 +68,7 @@ EXTERN u8 INIT_GLOBAL(gbl_verbose_mode, FALSE); | |||
| 69 | EXTERN u8 INIT_GLOBAL(gbl_binary_mode, FALSE); | 68 | EXTERN u8 INIT_GLOBAL(gbl_binary_mode, FALSE); |
| 70 | EXTERN u8 INIT_GLOBAL(gbl_dump_customized_tables, FALSE); | 69 | EXTERN u8 INIT_GLOBAL(gbl_dump_customized_tables, FALSE); |
| 71 | EXTERN u8 INIT_GLOBAL(gbl_do_not_dump_xsdt, FALSE); | 70 | EXTERN u8 INIT_GLOBAL(gbl_do_not_dump_xsdt, FALSE); |
| 72 | EXTERN FILE INIT_GLOBAL(*gbl_output_file, NULL); | 71 | EXTERN ACPI_FILE INIT_GLOBAL(gbl_output_file, NULL); |
| 73 | EXTERN char INIT_GLOBAL(*gbl_output_filename, NULL); | 72 | EXTERN char INIT_GLOBAL(*gbl_output_filename, NULL); |
| 74 | EXTERN u64 INIT_GLOBAL(gbl_rsdp_base, 0); | 73 | EXTERN u64 INIT_GLOBAL(gbl_rsdp_base, 0); |
| 75 | 74 | ||
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) | |||
| 69 | /* Make sure signature is all ASCII and a valid ACPI name */ | 69 | /* Make sure signature is all ASCII and a valid ACPI name */ |
| 70 | 70 | ||
| 71 | if (!acpi_ut_valid_acpi_name(table->signature)) { | 71 | if (!acpi_ut_valid_acpi_name(table->signature)) { |
| 72 | fprintf(stderr, | 72 | acpi_log_error("Table signature (0x%8.8X) is invalid\n", |
| 73 | "Table signature (0x%8.8X) is invalid\n", | 73 | *(u32 *)table->signature); |
| 74 | *(u32 *)table->signature); | ||
| 75 | return (FALSE); | 74 | return (FALSE); |
| 76 | } | 75 | } |
| 77 | 76 | ||
| 78 | /* Check for minimum table length */ | 77 | /* Check for minimum table length */ |
| 79 | 78 | ||
| 80 | if (table->length < sizeof(struct acpi_table_header)) { | 79 | if (table->length < sizeof(struct acpi_table_header)) { |
| 81 | fprintf(stderr, "Table length (0x%8.8X) is invalid\n", | 80 | acpi_log_error("Table length (0x%8.8X) is invalid\n", |
| 82 | table->length); | 81 | table->length); |
| 83 | return (FALSE); | 82 | return (FALSE); |
| 84 | } | 83 | } |
| 85 | } | 84 | } |
| @@ -116,8 +115,8 @@ u8 ap_is_valid_checksum(struct acpi_table_header *table) | |||
| 116 | } | 115 | } |
| 117 | 116 | ||
| 118 | if (ACPI_FAILURE(status)) { | 117 | if (ACPI_FAILURE(status)) { |
| 119 | fprintf(stderr, "%4.4s: Warning: wrong checksum in table\n", | 118 | acpi_log_error("%4.4s: Warning: wrong checksum in table\n", |
| 120 | table->signature); | 119 | table->signature); |
| 121 | } | 120 | } |
| 122 | 121 | ||
| 123 | return (AE_OK); | 122 | return (AE_OK); |
| @@ -196,12 +195,13 @@ ap_dump_table_buffer(struct acpi_table_header *table, | |||
| 196 | * Note: simplest to just always emit a 64-bit address. acpi_xtract | 195 | * Note: simplest to just always emit a 64-bit address. acpi_xtract |
| 197 | * utility can handle this. | 196 | * utility can handle this. |
| 198 | */ | 197 | */ |
| 199 | printf("%4.4s @ 0x%8.8X%8.8X\n", table->signature, | 198 | acpi_ut_file_printf(gbl_output_file, "%4.4s @ 0x%8.8X%8.8X\n", |
| 200 | ACPI_FORMAT_UINT64(address)); | 199 | table->signature, ACPI_FORMAT_UINT64(address)); |
| 201 | 200 | ||
| 202 | acpi_ut_dump_buffer(ACPI_CAST_PTR(u8, table), table_length, | 201 | acpi_ut_dump_buffer_to_file(gbl_output_file, |
| 203 | DB_BYTE_DISPLAY, 0); | 202 | ACPI_CAST_PTR(u8, table), table_length, |
| 204 | printf("\n"); | 203 | DB_BYTE_DISPLAY, 0); |
| 204 | acpi_ut_file_printf(gbl_output_file, "\n"); | ||
| 205 | return (0); | 205 | return (0); |
| 206 | } | 206 | } |
| 207 | 207 | ||
| @@ -239,20 +239,20 @@ int ap_dump_all_tables(void) | |||
| 239 | if (status == AE_LIMIT) { | 239 | if (status == AE_LIMIT) { |
| 240 | return (0); | 240 | return (0); |
| 241 | } else if (i == 0) { | 241 | } else if (i == 0) { |
| 242 | fprintf(stderr, | 242 | acpi_log_error |
| 243 | "Could not get ACPI tables, %s\n", | 243 | ("Could not get ACPI tables, %s\n", |
| 244 | acpi_format_exception(status)); | 244 | acpi_format_exception(status)); |
| 245 | return (-1); | 245 | return (-1); |
| 246 | } else { | 246 | } else { |
| 247 | fprintf(stderr, | 247 | acpi_log_error |
| 248 | "Could not get ACPI table at index %u, %s\n", | 248 | ("Could not get ACPI table at index %u, %s\n", |
| 249 | i, acpi_format_exception(status)); | 249 | i, acpi_format_exception(status)); |
| 250 | continue; | 250 | continue; |
| 251 | } | 251 | } |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | table_status = ap_dump_table_buffer(table, instance, address); | 254 | table_status = ap_dump_table_buffer(table, instance, address); |
| 255 | free(table); | 255 | ACPI_FREE(table); |
| 256 | 256 | ||
| 257 | if (table_status) { | 257 | if (table_status) { |
| 258 | break; | 258 | break; |
| @@ -288,22 +288,22 @@ int ap_dump_table_by_address(char *ascii_address) | |||
| 288 | 288 | ||
| 289 | status = acpi_ut_strtoul64(ascii_address, 0, &long_address); | 289 | status = acpi_ut_strtoul64(ascii_address, 0, &long_address); |
| 290 | if (ACPI_FAILURE(status)) { | 290 | if (ACPI_FAILURE(status)) { |
| 291 | fprintf(stderr, "%s: Could not convert to a physical address\n", | 291 | acpi_log_error("%s: Could not convert to a physical address\n", |
| 292 | ascii_address); | 292 | ascii_address); |
| 293 | return (-1); | 293 | return (-1); |
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | address = (acpi_physical_address) long_address; | 296 | address = (acpi_physical_address) long_address; |
| 297 | status = acpi_os_get_table_by_address(address, &table); | 297 | status = acpi_os_get_table_by_address(address, &table); |
| 298 | if (ACPI_FAILURE(status)) { | 298 | if (ACPI_FAILURE(status)) { |
| 299 | fprintf(stderr, "Could not get table at 0x%8.8X%8.8X, %s\n", | 299 | acpi_log_error("Could not get table at 0x%8.8X%8.8X, %s\n", |
| 300 | ACPI_FORMAT_UINT64(address), | 300 | ACPI_FORMAT_UINT64(address), |
| 301 | acpi_format_exception(status)); | 301 | acpi_format_exception(status)); |
| 302 | return (-1); | 302 | return (-1); |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | table_status = ap_dump_table_buffer(table, 0, address); | 305 | table_status = ap_dump_table_buffer(table, 0, address); |
| 306 | free(table); | 306 | ACPI_FREE(table); |
| 307 | return (table_status); | 307 | return (table_status); |
| 308 | } | 308 | } |
| 309 | 309 | ||
| @@ -329,24 +329,24 @@ int ap_dump_table_by_name(char *signature) | |||
| 329 | acpi_status status; | 329 | acpi_status status; |
| 330 | int table_status; | 330 | int table_status; |
| 331 | 331 | ||
| 332 | if (strlen(signature) != ACPI_NAME_SIZE) { | 332 | if (ACPI_STRLEN(signature) != ACPI_NAME_SIZE) { |
| 333 | fprintf(stderr, | 333 | acpi_log_error |
| 334 | "Invalid table signature [%s]: must be exactly 4 characters\n", | 334 | ("Invalid table signature [%s]: must be exactly 4 characters\n", |
| 335 | signature); | 335 | signature); |
| 336 | return (-1); | 336 | return (-1); |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | /* Table signatures are expected to be uppercase */ | 339 | /* Table signatures are expected to be uppercase */ |
| 340 | 340 | ||
| 341 | strcpy(local_signature, signature); | 341 | ACPI_STRCPY(local_signature, signature); |
| 342 | acpi_ut_strupr(local_signature); | 342 | acpi_ut_strupr(local_signature); |
| 343 | 343 | ||
| 344 | /* To be friendly, handle tables whose signatures do not match the name */ | 344 | /* To be friendly, handle tables whose signatures do not match the name */ |
| 345 | 345 | ||
| 346 | if (ACPI_COMPARE_NAME(local_signature, "FADT")) { | 346 | if (ACPI_COMPARE_NAME(local_signature, "FADT")) { |
| 347 | strcpy(local_signature, ACPI_SIG_FADT); | 347 | ACPI_STRCPY(local_signature, ACPI_SIG_FADT); |
| 348 | } else if (ACPI_COMPARE_NAME(local_signature, "MADT")) { | 348 | } else if (ACPI_COMPARE_NAME(local_signature, "MADT")) { |
| 349 | strcpy(local_signature, ACPI_SIG_MADT); | 349 | ACPI_STRCPY(local_signature, ACPI_SIG_MADT); |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | /* Dump all instances of this signature (to handle multiple SSDTs) */ | 352 | /* Dump all instances of this signature (to handle multiple SSDTs) */ |
| @@ -362,14 +362,14 @@ int ap_dump_table_by_name(char *signature) | |||
| 362 | return (0); | 362 | return (0); |
| 363 | } | 363 | } |
| 364 | 364 | ||
| 365 | fprintf(stderr, | 365 | acpi_log_error |
| 366 | "Could not get ACPI table with signature [%s], %s\n", | 366 | ("Could not get ACPI table with signature [%s], %s\n", |
| 367 | local_signature, acpi_format_exception(status)); | 367 | local_signature, acpi_format_exception(status)); |
| 368 | return (-1); | 368 | return (-1); |
| 369 | } | 369 | } |
| 370 | 370 | ||
| 371 | table_status = ap_dump_table_buffer(table, instance, address); | 371 | table_status = ap_dump_table_buffer(table, instance, address); |
| 372 | free(table); | 372 | ACPI_FREE(table); |
| 373 | 373 | ||
| 374 | if (table_status) { | 374 | if (table_status) { |
| 375 | break; | 375 | break; |
| @@ -409,43 +409,21 @@ int ap_dump_table_from_file(char *pathname) | |||
| 409 | /* File must be at least as long as the table length */ | 409 | /* File must be at least as long as the table length */ |
| 410 | 410 | ||
| 411 | if (table->length > file_size) { | 411 | if (table->length > file_size) { |
| 412 | fprintf(stderr, | 412 | acpi_log_error |
| 413 | "Table length (0x%X) is too large for input file (0x%X) %s\n", | 413 | ("Table length (0x%X) is too large for input file (0x%X) %s\n", |
| 414 | table->length, file_size, pathname); | 414 | table->length, file_size, pathname); |
| 415 | goto exit; | 415 | goto exit; |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | if (gbl_verbose_mode) { | 418 | if (gbl_verbose_mode) { |
| 419 | fprintf(stderr, | 419 | acpi_log_error |
| 420 | "Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n", | 420 | ("Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n", |
| 421 | pathname, table->signature, file_size, file_size); | 421 | pathname, table->signature, file_size, file_size); |
| 422 | } | 422 | } |
| 423 | 423 | ||
| 424 | table_status = ap_dump_table_buffer(table, 0, 0); | 424 | table_status = ap_dump_table_buffer(table, 0, 0); |
| 425 | 425 | ||
| 426 | exit: | 426 | exit: |
| 427 | free(table); | 427 | ACPI_FREE(table); |
| 428 | return (table_status); | 428 | return (table_status); |
| 429 | } | 429 | } |
| 430 | |||
| 431 | /****************************************************************************** | ||
| 432 | * | ||
| 433 | * FUNCTION: acpi_os* print functions | ||
| 434 | * | ||
| 435 | * DESCRIPTION: Used for linkage with ACPICA modules | ||
| 436 | * | ||
| 437 | ******************************************************************************/ | ||
| 438 | |||
| 439 | void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...) | ||
| 440 | { | ||
| 441 | va_list args; | ||
| 442 | |||
| 443 | va_start(args, fmt); | ||
| 444 | vfprintf(stdout, fmt, args); | ||
| 445 | va_end(args); | ||
| 446 | } | ||
| 447 | |||
| 448 | void acpi_os_vprintf(const char *fmt, va_list args) | ||
| 449 | { | ||
| 450 | vfprintf(stdout, fmt, args); | ||
| 451 | } | ||
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 @@ | |||
| 44 | #include "acpidump.h" | 44 | #include "acpidump.h" |
| 45 | #include "acapps.h" | 45 | #include "acapps.h" |
| 46 | 46 | ||
| 47 | /* Local prototypes */ | ||
| 48 | |||
| 49 | static int ap_is_existing_file(char *pathname); | ||
| 50 | |||
| 51 | static int ap_is_existing_file(char *pathname) | ||
| 52 | { | ||
| 53 | #ifndef _GNU_EFI | ||
| 54 | struct stat stat_info; | ||
| 55 | |||
| 56 | if (!stat(pathname, &stat_info)) { | ||
| 57 | acpi_log_error("Target path already exists, overwrite? [y|n] "); | ||
| 58 | |||
| 59 | if (getchar() != 'y') { | ||
| 60 | return (-1); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | #endif | ||
| 64 | |||
| 65 | return 0; | ||
| 66 | } | ||
| 67 | |||
| 47 | /****************************************************************************** | 68 | /****************************************************************************** |
| 48 | * | 69 | * |
| 49 | * FUNCTION: ap_open_output_file | 70 | * FUNCTION: ap_open_output_file |
| @@ -59,25 +80,19 @@ | |||
| 59 | 80 | ||
| 60 | int ap_open_output_file(char *pathname) | 81 | int ap_open_output_file(char *pathname) |
| 61 | { | 82 | { |
| 62 | struct stat stat_info; | 83 | ACPI_FILE file; |
| 63 | FILE *file; | ||
| 64 | 84 | ||
| 65 | /* If file exists, prompt for overwrite */ | 85 | /* If file exists, prompt for overwrite */ |
| 66 | 86 | ||
| 67 | if (!stat(pathname, &stat_info)) { | 87 | if (ap_is_existing_file(pathname) != 0) { |
| 68 | fprintf(stderr, | 88 | return (-1); |
| 69 | "Target path already exists, overwrite? [y|n] "); | ||
| 70 | |||
| 71 | if (getchar() != 'y') { | ||
| 72 | return (-1); | ||
| 73 | } | ||
| 74 | } | 89 | } |
| 75 | 90 | ||
| 76 | /* Point stdout to the file */ | 91 | /* Point stdout to the file */ |
| 77 | 92 | ||
| 78 | file = freopen(pathname, "w", stdout); | 93 | file = acpi_os_open_file(pathname, ACPI_FILE_WRITING); |
| 79 | if (!file) { | 94 | if (!file) { |
| 80 | perror("Could not open output file"); | 95 | acpi_log_error("Could not open output file: %s\n", pathname); |
| 81 | return (-1); | 96 | return (-1); |
| 82 | } | 97 | } |
| 83 | 98 | ||
| @@ -106,7 +121,7 @@ int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance) | |||
| 106 | { | 121 | { |
| 107 | char filename[ACPI_NAME_SIZE + 16]; | 122 | char filename[ACPI_NAME_SIZE + 16]; |
| 108 | char instance_str[16]; | 123 | char instance_str[16]; |
| 109 | FILE *file; | 124 | ACPI_FILE file; |
| 110 | size_t actual; | 125 | size_t actual; |
| 111 | u32 table_length; | 126 | u32 table_length; |
| 112 | 127 | ||
| @@ -130,35 +145,37 @@ int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance) | |||
| 130 | /* Handle multiple SSDts - create different filenames for each */ | 145 | /* Handle multiple SSDts - create different filenames for each */ |
| 131 | 146 | ||
| 132 | if (instance > 0) { | 147 | if (instance > 0) { |
| 133 | sprintf(instance_str, "%u", instance); | 148 | acpi_ut_snprintf(instance_str, sizeof(instance_str), "%u", |
| 134 | strcat(filename, instance_str); | 149 | instance); |
| 150 | ACPI_STRCAT(filename, instance_str); | ||
| 135 | } | 151 | } |
| 136 | 152 | ||
| 137 | strcat(filename, ACPI_TABLE_FILE_SUFFIX); | 153 | ACPI_STRCAT(filename, ACPI_TABLE_FILE_SUFFIX); |
| 138 | 154 | ||
| 139 | if (gbl_verbose_mode) { | 155 | if (gbl_verbose_mode) { |
| 140 | fprintf(stderr, | 156 | acpi_log_error |
| 141 | "Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n", | 157 | ("Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n", |
| 142 | table->signature, filename, table->length, | 158 | table->signature, filename, table->length, table->length); |
| 143 | table->length); | ||
| 144 | } | 159 | } |
| 145 | 160 | ||
| 146 | /* Open the file and dump the entire table in binary mode */ | 161 | /* Open the file and dump the entire table in binary mode */ |
| 147 | 162 | ||
| 148 | file = fopen(filename, "wb"); | 163 | file = acpi_os_open_file(filename, |
| 164 | ACPI_FILE_WRITING | ACPI_FILE_BINARY); | ||
| 149 | if (!file) { | 165 | if (!file) { |
| 150 | perror("Could not open output file"); | 166 | acpi_log_error("Could not open output file: %s\n", filename); |
| 151 | return (-1); | 167 | return (-1); |
| 152 | } | 168 | } |
| 153 | 169 | ||
| 154 | actual = fwrite(table, 1, table_length, file); | 170 | actual = acpi_os_write_file(file, table, 1, table_length); |
| 155 | if (actual != table_length) { | 171 | if (actual != table_length) { |
| 156 | perror("Error writing binary output file"); | 172 | acpi_log_error("Error writing binary output file: %s\n", |
| 157 | fclose(file); | 173 | filename); |
| 174 | acpi_os_close_file(file); | ||
| 158 | return (-1); | 175 | return (-1); |
| 159 | } | 176 | } |
| 160 | 177 | ||
| 161 | fclose(file); | 178 | acpi_os_close_file(file); |
| 162 | return (0); | 179 | return (0); |
| 163 | } | 180 | } |
| 164 | 181 | ||
| @@ -179,15 +196,16 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname, | |||
| 179 | u32 *out_file_size) | 196 | u32 *out_file_size) |
| 180 | { | 197 | { |
| 181 | struct acpi_table_header *buffer = NULL; | 198 | struct acpi_table_header *buffer = NULL; |
| 182 | FILE *file; | 199 | ACPI_FILE file; |
| 183 | u32 file_size; | 200 | u32 file_size; |
| 184 | size_t actual; | 201 | size_t actual; |
| 185 | 202 | ||
| 186 | /* Must use binary mode */ | 203 | /* Must use binary mode */ |
| 187 | 204 | ||
| 188 | file = fopen(pathname, "rb"); | 205 | file = |
| 206 | acpi_os_open_file(pathname, ACPI_FILE_READING | ACPI_FILE_BINARY); | ||
| 189 | if (!file) { | 207 | if (!file) { |
| 190 | perror("Could not open input file"); | 208 | acpi_log_error("Could not open input file: %s\n", pathname); |
| 191 | return (NULL); | 209 | return (NULL); |
| 192 | } | 210 | } |
| 193 | 211 | ||
| @@ -195,27 +213,25 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname, | |||
| 195 | 213 | ||
| 196 | file_size = cm_get_file_size(file); | 214 | file_size = cm_get_file_size(file); |
| 197 | if (file_size == ACPI_UINT32_MAX) { | 215 | if (file_size == ACPI_UINT32_MAX) { |
| 198 | fprintf(stderr, | 216 | acpi_log_error("Could not get input file size: %s\n", pathname); |
| 199 | "Could not get input file size: %s\n", pathname); | ||
| 200 | goto cleanup; | 217 | goto cleanup; |
| 201 | } | 218 | } |
| 202 | 219 | ||
| 203 | /* Allocate a buffer for the entire file */ | 220 | /* Allocate a buffer for the entire file */ |
| 204 | 221 | ||
| 205 | buffer = calloc(1, file_size); | 222 | buffer = ACPI_ALLOCATE_ZEROED(file_size); |
| 206 | if (!buffer) { | 223 | if (!buffer) { |
| 207 | fprintf(stderr, | 224 | acpi_log_error("Could not allocate file buffer of size: %u\n", |
| 208 | "Could not allocate file buffer of size: %u\n", | 225 | file_size); |
| 209 | file_size); | ||
| 210 | goto cleanup; | 226 | goto cleanup; |
| 211 | } | 227 | } |
| 212 | 228 | ||
| 213 | /* Read the entire file */ | 229 | /* Read the entire file */ |
| 214 | 230 | ||
| 215 | actual = fread(buffer, 1, file_size, file); | 231 | actual = acpi_os_read_file(file, buffer, 1, file_size); |
| 216 | if (actual != file_size) { | 232 | if (actual != file_size) { |
| 217 | fprintf(stderr, "Could not read input file: %s\n", pathname); | 233 | acpi_log_error("Could not read input file: %s\n", pathname); |
| 218 | free(buffer); | 234 | ACPI_FREE(buffer); |
| 219 | buffer = NULL; | 235 | buffer = NULL; |
| 220 | goto cleanup; | 236 | goto cleanup; |
| 221 | } | 237 | } |
| @@ -223,6 +239,6 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname, | |||
| 223 | *out_file_size = file_size; | 239 | *out_file_size = file_size; |
| 224 | 240 | ||
| 225 | cleanup: | 241 | cleanup: |
| 226 | fclose(file); | 242 | acpi_os_close_file(file); |
| 227 | return (buffer); | 243 | return (buffer); |
| 228 | } | 244 | } |
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); | |||
| 72 | 72 | ||
| 73 | static int ap_do_options(int argc, char **argv); | 73 | static int ap_do_options(int argc, char **argv); |
| 74 | 74 | ||
| 75 | static void ap_insert_action(char *argument, u32 to_be_done); | 75 | static int ap_insert_action(char *argument, u32 to_be_done); |
| 76 | 76 | ||
| 77 | /* Table for deferred actions from command line options */ | 77 | /* Table for deferred actions from command line options */ |
| 78 | 78 | ||
| @@ -104,7 +104,7 @@ static void ap_display_usage(void) | |||
| 104 | ACPI_OPTION("-v", "Display version information"); | 104 | ACPI_OPTION("-v", "Display version information"); |
| 105 | ACPI_OPTION("-z", "Verbose mode"); | 105 | ACPI_OPTION("-z", "Verbose mode"); |
| 106 | 106 | ||
| 107 | printf("\nTable Options:\n"); | 107 | ACPI_USAGE_TEXT("\nTable Options:\n"); |
| 108 | 108 | ||
| 109 | ACPI_OPTION("-a <Address>", "Get table via a physical address"); | 109 | ACPI_OPTION("-a <Address>", "Get table via a physical address"); |
| 110 | ACPI_OPTION("-f <BinaryFile>", "Get table via a binary file"); | 110 | ACPI_OPTION("-f <BinaryFile>", "Get table via a binary file"); |
| @@ -112,9 +112,9 @@ static void ap_display_usage(void) | |||
| 112 | ACPI_OPTION("-x", "Do not use but dump XSDT"); | 112 | ACPI_OPTION("-x", "Do not use but dump XSDT"); |
| 113 | ACPI_OPTION("-x -x", "Do not use or dump XSDT"); | 113 | ACPI_OPTION("-x -x", "Do not use or dump XSDT"); |
| 114 | 114 | ||
| 115 | printf("\n" | 115 | ACPI_USAGE_TEXT("\n" |
| 116 | "Invocation without parameters dumps all available tables\n" | 116 | "Invocation without parameters dumps all available tables\n" |
| 117 | "Multiple mixed instances of -a, -f, and -n are supported\n\n"); | 117 | "Multiple mixed instances of -a, -f, and -n are supported\n\n"); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | /****************************************************************************** | 120 | /****************************************************************************** |
| @@ -124,13 +124,13 @@ static void ap_display_usage(void) | |||
| 124 | * PARAMETERS: argument - Pointer to the argument for this action | 124 | * PARAMETERS: argument - Pointer to the argument for this action |
| 125 | * to_be_done - What to do to process this action | 125 | * to_be_done - What to do to process this action |
| 126 | * | 126 | * |
| 127 | * RETURN: None. Exits program if action table becomes full. | 127 | * RETURN: Status |
| 128 | * | 128 | * |
| 129 | * DESCRIPTION: Add an action item to the action table | 129 | * DESCRIPTION: Add an action item to the action table |
| 130 | * | 130 | * |
| 131 | ******************************************************************************/ | 131 | ******************************************************************************/ |
| 132 | 132 | ||
| 133 | static void ap_insert_action(char *argument, u32 to_be_done) | 133 | static int ap_insert_action(char *argument, u32 to_be_done) |
| 134 | { | 134 | { |
| 135 | 135 | ||
| 136 | /* Insert action and check for table overflow */ | 136 | /* Insert action and check for table overflow */ |
| @@ -140,10 +140,12 @@ static void ap_insert_action(char *argument, u32 to_be_done) | |||
| 140 | 140 | ||
| 141 | current_action++; | 141 | current_action++; |
| 142 | if (current_action > AP_MAX_ACTIONS) { | 142 | if (current_action > AP_MAX_ACTIONS) { |
| 143 | fprintf(stderr, "Too many table options (max %u)\n", | 143 | acpi_log_error("Too many table options (max %u)\n", |
| 144 | AP_MAX_ACTIONS); | 144 | AP_MAX_ACTIONS); |
| 145 | exit(-1); | 145 | return (-1); |
| 146 | } | 146 | } |
| 147 | |||
| 148 | return (0); | ||
| 147 | } | 149 | } |
| 148 | 150 | ||
| 149 | /****************************************************************************** | 151 | /****************************************************************************** |
| @@ -166,7 +168,8 @@ static int ap_do_options(int argc, char **argv) | |||
| 166 | 168 | ||
| 167 | /* Command line options */ | 169 | /* Command line options */ |
| 168 | 170 | ||
| 169 | while ((j = acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != EOF) | 171 | while ((j = |
| 172 | acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END) | ||
| 170 | switch (j) { | 173 | switch (j) { |
| 171 | /* | 174 | /* |
| 172 | * Global options | 175 | * Global options |
| @@ -185,12 +188,12 @@ static int ap_do_options(int argc, char **argv) | |||
| 185 | case '?': | 188 | case '?': |
| 186 | 189 | ||
| 187 | ap_display_usage(); | 190 | ap_display_usage(); |
| 188 | exit(0); | 191 | return (1); |
| 189 | 192 | ||
| 190 | case 'o': /* Redirect output to a single file */ | 193 | case 'o': /* Redirect output to a single file */ |
| 191 | 194 | ||
| 192 | if (ap_open_output_file(acpi_gbl_optarg)) { | 195 | if (ap_open_output_file(acpi_gbl_optarg)) { |
| 193 | exit(-1); | 196 | return (-1); |
| 194 | } | 197 | } |
| 195 | continue; | 198 | continue; |
| 196 | 199 | ||
| @@ -200,10 +203,10 @@ static int ap_do_options(int argc, char **argv) | |||
| 200 | acpi_ut_strtoul64(acpi_gbl_optarg, 0, | 203 | acpi_ut_strtoul64(acpi_gbl_optarg, 0, |
| 201 | &gbl_rsdp_base); | 204 | &gbl_rsdp_base); |
| 202 | if (ACPI_FAILURE(status)) { | 205 | if (ACPI_FAILURE(status)) { |
| 203 | fprintf(stderr, | 206 | acpi_log_error |
| 204 | "%s: Could not convert to a physical address\n", | 207 | ("%s: Could not convert to a physical address\n", |
| 205 | acpi_gbl_optarg); | 208 | acpi_gbl_optarg); |
| 206 | exit(-1); | 209 | return (-1); |
| 207 | } | 210 | } |
| 208 | continue; | 211 | continue; |
| 209 | 212 | ||
| @@ -223,13 +226,13 @@ static int ap_do_options(int argc, char **argv) | |||
| 223 | 226 | ||
| 224 | case 'v': /* Revision/version */ | 227 | case 'v': /* Revision/version */ |
| 225 | 228 | ||
| 226 | printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); | 229 | acpi_os_printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); |
| 227 | exit(0); | 230 | return (1); |
| 228 | 231 | ||
| 229 | case 'z': /* Verbose mode */ | 232 | case 'z': /* Verbose mode */ |
| 230 | 233 | ||
| 231 | gbl_verbose_mode = TRUE; | 234 | gbl_verbose_mode = TRUE; |
| 232 | fprintf(stderr, ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); | 235 | acpi_log_error(ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); |
| 233 | continue; | 236 | continue; |
| 234 | 237 | ||
| 235 | /* | 238 | /* |
| @@ -237,32 +240,40 @@ static int ap_do_options(int argc, char **argv) | |||
| 237 | */ | 240 | */ |
| 238 | case 'a': /* Get table by physical address */ | 241 | case 'a': /* Get table by physical address */ |
| 239 | 242 | ||
| 240 | ap_insert_action(acpi_gbl_optarg, | 243 | if (ap_insert_action |
| 241 | AP_DUMP_TABLE_BY_ADDRESS); | 244 | (acpi_gbl_optarg, AP_DUMP_TABLE_BY_ADDRESS)) { |
| 245 | return (-1); | ||
| 246 | } | ||
| 242 | break; | 247 | break; |
| 243 | 248 | ||
| 244 | case 'f': /* Get table from a file */ | 249 | case 'f': /* Get table from a file */ |
| 245 | 250 | ||
| 246 | ap_insert_action(acpi_gbl_optarg, | 251 | if (ap_insert_action |
| 247 | AP_DUMP_TABLE_BY_FILE); | 252 | (acpi_gbl_optarg, AP_DUMP_TABLE_BY_FILE)) { |
| 253 | return (-1); | ||
| 254 | } | ||
| 248 | break; | 255 | break; |
| 249 | 256 | ||
| 250 | case 'n': /* Get table by input name (signature) */ | 257 | case 'n': /* Get table by input name (signature) */ |
| 251 | 258 | ||
| 252 | ap_insert_action(acpi_gbl_optarg, | 259 | if (ap_insert_action |
| 253 | AP_DUMP_TABLE_BY_NAME); | 260 | (acpi_gbl_optarg, AP_DUMP_TABLE_BY_NAME)) { |
| 261 | return (-1); | ||
| 262 | } | ||
| 254 | break; | 263 | break; |
| 255 | 264 | ||
| 256 | default: | 265 | default: |
| 257 | 266 | ||
| 258 | ap_display_usage(); | 267 | ap_display_usage(); |
| 259 | exit(-1); | 268 | return (-1); |
| 260 | } | 269 | } |
| 261 | 270 | ||
| 262 | /* If there are no actions, this means "get/dump all tables" */ | 271 | /* If there are no actions, this means "get/dump all tables" */ |
| 263 | 272 | ||
| 264 | if (current_action == 0) { | 273 | if (current_action == 0) { |
| 265 | ap_insert_action(NULL, AP_DUMP_ALL_TABLES); | 274 | if (ap_insert_action(NULL, AP_DUMP_ALL_TABLES)) { |
| 275 | return (-1); | ||
| 276 | } | ||
| 266 | } | 277 | } |
| 267 | 278 | ||
| 268 | return (0); | 279 | return (0); |
| @@ -280,7 +291,11 @@ static int ap_do_options(int argc, char **argv) | |||
| 280 | * | 291 | * |
| 281 | ******************************************************************************/ | 292 | ******************************************************************************/ |
| 282 | 293 | ||
| 294 | #ifndef _GNU_EFI | ||
| 283 | int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) | 295 | int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) |
| 296 | #else | ||
| 297 | int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[]) | ||
| 298 | #endif | ||
| 284 | { | 299 | { |
| 285 | int status = 0; | 300 | int status = 0; |
| 286 | struct ap_dump_action *action; | 301 | struct ap_dump_action *action; |
| @@ -288,11 +303,17 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) | |||
| 288 | u32 i; | 303 | u32 i; |
| 289 | 304 | ||
| 290 | ACPI_DEBUG_INITIALIZE(); /* For debug version only */ | 305 | ACPI_DEBUG_INITIALIZE(); /* For debug version only */ |
| 306 | acpi_os_initialize(); | ||
| 307 | gbl_output_file = ACPI_FILE_OUT; | ||
| 291 | 308 | ||
| 292 | /* Process command line options */ | 309 | /* Process command line options */ |
| 293 | 310 | ||
| 294 | if (ap_do_options(argc, argv)) { | 311 | status = ap_do_options(argc, argv); |
| 295 | return (-1); | 312 | if (status > 0) { |
| 313 | return (0); | ||
| 314 | } | ||
| 315 | if (status < 0) { | ||
| 316 | return (status); | ||
| 296 | } | 317 | } |
| 297 | 318 | ||
| 298 | /* Get/dump ACPI table(s) as requested */ | 319 | /* Get/dump ACPI table(s) as requested */ |
| @@ -322,9 +343,8 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) | |||
| 322 | 343 | ||
| 323 | default: | 344 | default: |
| 324 | 345 | ||
| 325 | fprintf(stderr, | 346 | acpi_log_error("Internal error, invalid action: 0x%X\n", |
| 326 | "Internal error, invalid action: 0x%X\n", | 347 | action->to_be_done); |
| 327 | action->to_be_done); | ||
| 328 | return (-1); | 348 | return (-1); |
| 329 | } | 349 | } |
| 330 | 350 | ||
| @@ -333,18 +353,18 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[]) | |||
| 333 | } | 353 | } |
| 334 | } | 354 | } |
| 335 | 355 | ||
| 336 | if (gbl_output_file) { | 356 | if (gbl_output_filename) { |
| 337 | if (gbl_verbose_mode) { | 357 | if (gbl_verbose_mode) { |
| 338 | 358 | ||
| 339 | /* Summary for the output file */ | 359 | /* Summary for the output file */ |
| 340 | 360 | ||
| 341 | file_size = cm_get_file_size(gbl_output_file); | 361 | file_size = cm_get_file_size(gbl_output_file); |
| 342 | fprintf(stderr, | 362 | acpi_log_error |
| 343 | "Output file %s contains 0x%X (%u) bytes\n\n", | 363 | ("Output file %s contains 0x%X (%u) bytes\n\n", |
| 344 | gbl_output_filename, file_size, file_size); | 364 | gbl_output_filename, file_size, file_size); |
| 345 | } | 365 | } |
| 346 | 366 | ||
| 347 | fclose(gbl_output_file); | 367 | acpi_os_close_file(gbl_output_file); |
| 348 | } | 368 | } |
| 349 | 369 | ||
| 350 | return (status); | 370 | 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() | |||
| 158 | int prepare_config(const char *path, struct config *config) | 158 | int prepare_config(const char *path, struct config *config) |
| 159 | { | 159 | { |
| 160 | size_t len = 0; | 160 | size_t len = 0; |
| 161 | char *opt, *val, *line = NULL; | 161 | char opt[16], val[32], *line = NULL; |
| 162 | FILE *configfile = fopen(path, "r"); | 162 | FILE *configfile; |
| 163 | 163 | ||
| 164 | if (config == NULL) { | 164 | if (config == NULL) { |
| 165 | fprintf(stderr, "error: config is NULL\n"); | 165 | fprintf(stderr, "error: config is NULL\n"); |
| 166 | return 1; | 166 | return 1; |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | configfile = fopen(path, "r"); | ||
| 169 | if (configfile == NULL) { | 170 | if (configfile == NULL) { |
| 170 | perror("fopen"); | 171 | perror("fopen"); |
| 171 | fprintf(stderr, "error: unable to read configfile\n"); | 172 | fprintf(stderr, "error: unable to read configfile\n"); |
| @@ -174,52 +175,54 @@ int prepare_config(const char *path, struct config *config) | |||
| 174 | } | 175 | } |
| 175 | 176 | ||
| 176 | while (getline(&line, &len, configfile) != -1) { | 177 | while (getline(&line, &len, configfile) != -1) { |
| 177 | if (line[0] == '#' || line[0] == ' ') | 178 | if (line[0] == '#' || line[0] == ' ' || line[0] == '\n') |
| 178 | continue; | 179 | continue; |
| 179 | 180 | ||
| 180 | sscanf(line, "%as = %as", &opt, &val); | 181 | if (sscanf(line, "%14s = %30s", opt, val) < 2) |
| 182 | continue; | ||
| 181 | 183 | ||
| 182 | dprintf("parsing: %s -> %s\n", opt, val); | 184 | dprintf("parsing: %s -> %s\n", opt, val); |
| 183 | 185 | ||
| 184 | if (strncmp("sleep", opt, strlen(opt)) == 0) | 186 | if (strcmp("sleep", opt) == 0) |
| 185 | sscanf(val, "%li", &config->sleep); | 187 | sscanf(val, "%li", &config->sleep); |
| 186 | 188 | ||
| 187 | else if (strncmp("load", opt, strlen(opt)) == 0) | 189 | else if (strcmp("load", opt) == 0) |
| 188 | sscanf(val, "%li", &config->load); | 190 | sscanf(val, "%li", &config->load); |
| 189 | 191 | ||
| 190 | else if (strncmp("load_step", opt, strlen(opt)) == 0) | 192 | else if (strcmp("load_step", opt) == 0) |
| 191 | sscanf(val, "%li", &config->load_step); | 193 | sscanf(val, "%li", &config->load_step); |
| 192 | 194 | ||
| 193 | else if (strncmp("sleep_step", opt, strlen(opt)) == 0) | 195 | else if (strcmp("sleep_step", opt) == 0) |
| 194 | sscanf(val, "%li", &config->sleep_step); | 196 | sscanf(val, "%li", &config->sleep_step); |
| 195 | 197 | ||
| 196 | else if (strncmp("cycles", opt, strlen(opt)) == 0) | 198 | else if (strcmp("cycles", opt) == 0) |
| 197 | sscanf(val, "%u", &config->cycles); | 199 | sscanf(val, "%u", &config->cycles); |
| 198 | 200 | ||
| 199 | else if (strncmp("rounds", opt, strlen(opt)) == 0) | 201 | else if (strcmp("rounds", opt) == 0) |
| 200 | sscanf(val, "%u", &config->rounds); | 202 | sscanf(val, "%u", &config->rounds); |
| 201 | 203 | ||
| 202 | else if (strncmp("verbose", opt, strlen(opt)) == 0) | 204 | else if (strcmp("verbose", opt) == 0) |
| 203 | sscanf(val, "%u", &config->verbose); | 205 | sscanf(val, "%u", &config->verbose); |
| 204 | 206 | ||
| 205 | else if (strncmp("output", opt, strlen(opt)) == 0) | 207 | else if (strcmp("output", opt) == 0) |
| 206 | config->output = prepare_output(val); | 208 | config->output = prepare_output(val); |
| 207 | 209 | ||
| 208 | else if (strncmp("cpu", opt, strlen(opt)) == 0) | 210 | else if (strcmp("cpu", opt) == 0) |
| 209 | sscanf(val, "%u", &config->cpu); | 211 | sscanf(val, "%u", &config->cpu); |
| 210 | 212 | ||
| 211 | else if (strncmp("governor", opt, 14) == 0) | 213 | else if (strcmp("governor", opt) == 0) { |
| 212 | strncpy(config->governor, val, 14); | 214 | strncpy(config->governor, val, |
| 215 | sizeof(config->governor)); | ||
| 216 | config->governor[sizeof(config->governor) - 1] = '\0'; | ||
| 217 | } | ||
| 213 | 218 | ||
| 214 | else if (strncmp("priority", opt, strlen(opt)) == 0) { | 219 | else if (strcmp("priority", opt) == 0) { |
| 215 | if (string_to_prio(val) != SCHED_ERR) | 220 | if (string_to_prio(val) != SCHED_ERR) |
| 216 | config->prio = string_to_prio(val); | 221 | config->prio = string_to_prio(val); |
| 217 | } | 222 | } |
| 218 | } | 223 | } |
| 219 | 224 | ||
| 220 | free(line); | 225 | free(line); |
| 221 | free(opt); | ||
| 222 | free(val); | ||
| 223 | 226 | ||
| 224 | return 0; | 227 | return 0; |
| 225 | } | 228 | } |
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) | |||
| 320 | 320 | ||
| 321 | printf(_("Setting cpu: %d\n"), cpu); | 321 | printf(_("Setting cpu: %d\n"), cpu); |
| 322 | ret = do_one_cpu(cpu, &new_pol, freq, policychange); | 322 | ret = do_one_cpu(cpu, &new_pol, freq, policychange); |
| 323 | if (ret) | 323 | if (ret) { |
| 324 | break; | 324 | print_error(); |
| 325 | return ret; | ||
| 326 | } | ||
| 325 | } | 327 | } |
| 326 | 328 | ||
| 327 | if (ret) | 329 | return 0; |
| 328 | print_error(); | ||
| 329 | |||
| 330 | return ret; | ||
| 331 | } | 330 | } |
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) | |||
| 81 | close(fd); | 81 | close(fd); |
| 82 | 82 | ||
| 83 | value = strtoull(linebuf, &endp, 0); | 83 | value = strtoull(linebuf, &endp, 0); |
| 84 | if (value > 1 || value < 0) | 84 | if (value > 1) |
| 85 | return -EINVAL; | 85 | return -EINVAL; |
| 86 | 86 | ||
| 87 | return value; | 87 | 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) | |||
| 237 | unsigned long long hwcr; | 237 | unsigned long long hwcr; |
| 238 | unsigned long min; | 238 | unsigned long min; |
| 239 | 239 | ||
| 240 | if (!cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC) | 240 | if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC)) |
| 241 | goto use_sysfs; | 241 | goto use_sysfs; |
| 242 | 242 | ||
| 243 | if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) { | 243 | if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) { |
