aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2014-07-07 22:07:46 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-07-08 08:22:27 -0400
commitdcaff16df2750a400db1983754542f2cc6bf4e93 (patch)
tree3f2f141e7f9dfa89ac4577933357db10bd34f8d6 /tools
parent135610f792addb71af7be0e00aa7486429bf7a37 (diff)
ACPICA: acpidump: Replace file IOs with new APIs to improve portability
The new APIs are enabled to offer a portable layer to access files: 1. acpi_os_XXX_file_XXX: Wrapper of fopen/fclose/fread/fwrite 2. acpi_os_printf: Wrapper of printf 3. acpi_log_error: Wrapper of fprintf(stderr) This patch deploys such mechanisms to acpidump to improve the portability of this tool. Lv Zheng. Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/power/acpi/tools/acpidump/acpidump.h2
-rw-r--r--tools/power/acpi/tools/acpidump/apdump.c65
-rw-r--r--tools/power/acpi/tools/acpidump/apfiles.c47
-rw-r--r--tools/power/acpi/tools/acpidump/apmain.c27
4 files changed, 69 insertions, 72 deletions
diff --git a/tools/power/acpi/tools/acpidump/acpidump.h b/tools/power/acpi/tools/acpidump/acpidump.h
index 8efc84824308..a2d37d610639 100644
--- a/tools/power/acpi/tools/acpidump/acpidump.h
+++ b/tools/power/acpi/tools/acpidump/acpidump.h
@@ -68,7 +68,7 @@ EXTERN u8 INIT_GLOBAL(gbl_verbose_mode, FALSE);
68EXTERN u8 INIT_GLOBAL(gbl_binary_mode, FALSE); 68EXTERN u8 INIT_GLOBAL(gbl_binary_mode, FALSE);
69EXTERN u8 INIT_GLOBAL(gbl_dump_customized_tables, FALSE); 69EXTERN u8 INIT_GLOBAL(gbl_dump_customized_tables, FALSE);
70EXTERN u8 INIT_GLOBAL(gbl_do_not_dump_xsdt, FALSE); 70EXTERN u8 INIT_GLOBAL(gbl_do_not_dump_xsdt, FALSE);
71EXTERN FILE INIT_GLOBAL(*gbl_output_file, NULL); 71EXTERN ACPI_FILE INIT_GLOBAL(gbl_output_file, NULL);
72EXTERN char INIT_GLOBAL(*gbl_output_filename, NULL); 72EXTERN char INIT_GLOBAL(*gbl_output_filename, NULL);
73EXTERN u64 INIT_GLOBAL(gbl_rsdp_base, 0); 73EXTERN u64 INIT_GLOBAL(gbl_rsdp_base, 0);
74 74
diff --git a/tools/power/acpi/tools/acpidump/apdump.c b/tools/power/acpi/tools/acpidump/apdump.c
index ccb6262829d6..34fa5f25be39 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,12 @@ 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_os_printf("%4.4s @ 0x%8.8X%8.8X\n", table->signature,
200 ACPI_FORMAT_UINT64(address)); 199 ACPI_FORMAT_UINT64(address));
201 200
202 acpi_ut_dump_buffer(ACPI_CAST_PTR(u8, table), table_length, 201 acpi_ut_dump_buffer(ACPI_CAST_PTR(u8, table), table_length,
203 DB_BYTE_DISPLAY, 0); 202 DB_BYTE_DISPLAY, 0);
204 printf("\n"); 203 acpi_os_printf("\n");
205 return (0); 204 return (0);
206} 205}
207 206
@@ -239,14 +238,14 @@ int ap_dump_all_tables(void)
239 if (status == AE_LIMIT) { 238 if (status == AE_LIMIT) {
240 return (0); 239 return (0);
241 } else if (i == 0) { 240 } else if (i == 0) {
242 fprintf(stderr, 241 acpi_log_error
243 "Could not get ACPI tables, %s\n", 242 ("Could not get ACPI tables, %s\n",
244 acpi_format_exception(status)); 243 acpi_format_exception(status));
245 return (-1); 244 return (-1);
246 } else { 245 } else {
247 fprintf(stderr, 246 acpi_log_error
248 "Could not get ACPI table at index %u, %s\n", 247 ("Could not get ACPI table at index %u, %s\n",
249 i, acpi_format_exception(status)); 248 i, acpi_format_exception(status));
250 continue; 249 continue;
251 } 250 }
252 } 251 }
@@ -288,17 +287,17 @@ int ap_dump_table_by_address(char *ascii_address)
288 287
289 status = acpi_ut_strtoul64(ascii_address, 0, &long_address); 288 status = acpi_ut_strtoul64(ascii_address, 0, &long_address);
290 if (ACPI_FAILURE(status)) { 289 if (ACPI_FAILURE(status)) {
291 fprintf(stderr, "%s: Could not convert to a physical address\n", 290 acpi_log_error("%s: Could not convert to a physical address\n",
292 ascii_address); 291 ascii_address);
293 return (-1); 292 return (-1);
294 } 293 }
295 294
296 address = (acpi_physical_address) long_address; 295 address = (acpi_physical_address) long_address;
297 status = acpi_os_get_table_by_address(address, &table); 296 status = acpi_os_get_table_by_address(address, &table);
298 if (ACPI_FAILURE(status)) { 297 if (ACPI_FAILURE(status)) {
299 fprintf(stderr, "Could not get table at 0x%8.8X%8.8X, %s\n", 298 acpi_log_error("Could not get table at 0x%8.8X%8.8X, %s\n",
300 ACPI_FORMAT_UINT64(address), 299 ACPI_FORMAT_UINT64(address),
301 acpi_format_exception(status)); 300 acpi_format_exception(status));
302 return (-1); 301 return (-1);
303 } 302 }
304 303
@@ -330,9 +329,9 @@ int ap_dump_table_by_name(char *signature)
330 int table_status; 329 int table_status;
331 330
332 if (ACPI_STRLEN(signature) != ACPI_NAME_SIZE) { 331 if (ACPI_STRLEN(signature) != ACPI_NAME_SIZE) {
333 fprintf(stderr, 332 acpi_log_error
334 "Invalid table signature [%s]: must be exactly 4 characters\n", 333 ("Invalid table signature [%s]: must be exactly 4 characters\n",
335 signature); 334 signature);
336 return (-1); 335 return (-1);
337 } 336 }
338 337
@@ -362,9 +361,9 @@ int ap_dump_table_by_name(char *signature)
362 return (0); 361 return (0);
363 } 362 }
364 363
365 fprintf(stderr, 364 acpi_log_error
366 "Could not get ACPI table with signature [%s], %s\n", 365 ("Could not get ACPI table with signature [%s], %s\n",
367 local_signature, acpi_format_exception(status)); 366 local_signature, acpi_format_exception(status));
368 return (-1); 367 return (-1);
369 } 368 }
370 369
@@ -409,16 +408,16 @@ int ap_dump_table_from_file(char *pathname)
409 /* File must be at least as long as the table length */ 408 /* File must be at least as long as the table length */
410 409
411 if (table->length > file_size) { 410 if (table->length > file_size) {
412 fprintf(stderr, 411 acpi_log_error
413 "Table length (0x%X) is too large for input file (0x%X) %s\n", 412 ("Table length (0x%X) is too large for input file (0x%X) %s\n",
414 table->length, file_size, pathname); 413 table->length, file_size, pathname);
415 goto exit; 414 goto exit;
416 } 415 }
417 416
418 if (gbl_verbose_mode) { 417 if (gbl_verbose_mode) {
419 fprintf(stderr, 418 acpi_log_error
420 "Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n", 419 ("Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n",
421 pathname, table->signature, file_size, file_size); 420 pathname, table->signature, file_size, file_size);
422 } 421 }
423 422
424 table_status = ap_dump_table_buffer(table, 0, 0); 423 table_status = ap_dump_table_buffer(table, 0, 0);
diff --git a/tools/power/acpi/tools/acpidump/apfiles.c b/tools/power/acpi/tools/acpidump/apfiles.c
index 1d12b9d3d44e..5699ca1d0922 100644
--- a/tools/power/acpi/tools/acpidump/apfiles.c
+++ b/tools/power/acpi/tools/acpidump/apfiles.c
@@ -65,8 +65,7 @@ int ap_open_output_file(char *pathname)
65 /* If file exists, prompt for overwrite */ 65 /* If file exists, prompt for overwrite */
66 66
67 if (!stat(pathname, &stat_info)) { 67 if (!stat(pathname, &stat_info)) {
68 fprintf(stderr, 68 acpi_log_error("Target path already exists, overwrite? [y|n] ");
69 "Target path already exists, overwrite? [y|n] ");
70 69
71 if (getchar() != 'y') { 70 if (getchar() != 'y') {
72 return (-1); 71 return (-1);
@@ -106,7 +105,7 @@ int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance)
106{ 105{
107 char filename[ACPI_NAME_SIZE + 16]; 106 char filename[ACPI_NAME_SIZE + 16];
108 char instance_str[16]; 107 char instance_str[16];
109 FILE *file; 108 ACPI_FILE file;
110 size_t actual; 109 size_t actual;
111 u32 table_length; 110 u32 table_length;
112 111
@@ -138,28 +137,29 @@ int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance)
138 ACPI_STRCAT(filename, ACPI_TABLE_FILE_SUFFIX); 137 ACPI_STRCAT(filename, ACPI_TABLE_FILE_SUFFIX);
139 138
140 if (gbl_verbose_mode) { 139 if (gbl_verbose_mode) {
141 fprintf(stderr, 140 acpi_log_error
142 "Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n", 141 ("Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n",
143 table->signature, filename, table->length, 142 table->signature, filename, table->length, table->length);
144 table->length);
145 } 143 }
146 144
147 /* Open the file and dump the entire table in binary mode */ 145 /* Open the file and dump the entire table in binary mode */
148 146
149 file = fopen(filename, "wb"); 147 file = acpi_os_open_file(filename,
148 ACPI_FILE_WRITING | ACPI_FILE_BINARY);
150 if (!file) { 149 if (!file) {
151 perror("Could not open output file"); 150 acpi_log_error("Could not open output file: %s\n", filename);
152 return (-1); 151 return (-1);
153 } 152 }
154 153
155 actual = fwrite(table, 1, table_length, file); 154 actual = acpi_os_write_file(file, table, 1, table_length);
156 if (actual != table_length) { 155 if (actual != table_length) {
157 perror("Error writing binary output file"); 156 acpi_log_error("Error writing binary output file: %s\n",
158 fclose(file); 157 filename);
158 acpi_os_close_file(file);
159 return (-1); 159 return (-1);
160 } 160 }
161 161
162 fclose(file); 162 acpi_os_close_file(file);
163 return (0); 163 return (0);
164} 164}
165 165
@@ -180,15 +180,16 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname,
180 u32 *out_file_size) 180 u32 *out_file_size)
181{ 181{
182 struct acpi_table_header *buffer = NULL; 182 struct acpi_table_header *buffer = NULL;
183 FILE *file; 183 ACPI_FILE file;
184 u32 file_size; 184 u32 file_size;
185 size_t actual; 185 size_t actual;
186 186
187 /* Must use binary mode */ 187 /* Must use binary mode */
188 188
189 file = fopen(pathname, "rb"); 189 file =
190 acpi_os_open_file(pathname, ACPI_FILE_READING | ACPI_FILE_BINARY);
190 if (!file) { 191 if (!file) {
191 perror("Could not open input file"); 192 acpi_log_error("Could not open input file: %s\n", pathname);
192 return (NULL); 193 return (NULL);
193 } 194 }
194 195
@@ -196,8 +197,7 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname,
196 197
197 file_size = cm_get_file_size(file); 198 file_size = cm_get_file_size(file);
198 if (file_size == ACPI_UINT32_MAX) { 199 if (file_size == ACPI_UINT32_MAX) {
199 fprintf(stderr, 200 acpi_log_error("Could not get input file size: %s\n", pathname);
200 "Could not get input file size: %s\n", pathname);
201 goto cleanup; 201 goto cleanup;
202 } 202 }
203 203
@@ -205,17 +205,16 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname,
205 205
206 buffer = ACPI_ALLOCATE_ZEROED(file_size); 206 buffer = ACPI_ALLOCATE_ZEROED(file_size);
207 if (!buffer) { 207 if (!buffer) {
208 fprintf(stderr, 208 acpi_log_error("Could not allocate file buffer of size: %u\n",
209 "Could not allocate file buffer of size: %u\n", 209 file_size);
210 file_size);
211 goto cleanup; 210 goto cleanup;
212 } 211 }
213 212
214 /* Read the entire file */ 213 /* Read the entire file */
215 214
216 actual = fread(buffer, 1, file_size, file); 215 actual = acpi_os_read_file(file, buffer, 1, file_size);
217 if (actual != file_size) { 216 if (actual != file_size) {
218 fprintf(stderr, "Could not read input file: %s\n", pathname); 217 acpi_log_error("Could not read input file: %s\n", pathname);
219 ACPI_FREE(buffer); 218 ACPI_FREE(buffer);
220 buffer = NULL; 219 buffer = NULL;
221 goto cleanup; 220 goto cleanup;
@@ -224,6 +223,6 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname,
224 *out_file_size = file_size; 223 *out_file_size = file_size;
225 224
226cleanup: 225cleanup:
227 fclose(file); 226 acpi_os_close_file(file);
228 return (buffer); 227 return (buffer);
229} 228}
diff --git a/tools/power/acpi/tools/acpidump/apmain.c b/tools/power/acpi/tools/acpidump/apmain.c
index 55fd44d5f2e8..63f7bc9fdf29 100644
--- a/tools/power/acpi/tools/acpidump/apmain.c
+++ b/tools/power/acpi/tools/acpidump/apmain.c
@@ -140,8 +140,8 @@ static int 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 return (-1); 145 return (-1);
146 } 146 }
147 147
@@ -203,9 +203,9 @@ static int ap_do_options(int argc, char **argv)
203 acpi_ut_strtoul64(acpi_gbl_optarg, 0, 203 acpi_ut_strtoul64(acpi_gbl_optarg, 0,
204 &gbl_rsdp_base); 204 &gbl_rsdp_base);
205 if (ACPI_FAILURE(status)) { 205 if (ACPI_FAILURE(status)) {
206 fprintf(stderr, 206 acpi_log_error
207 "%s: Could not convert to a physical address\n", 207 ("%s: Could not convert to a physical address\n",
208 acpi_gbl_optarg); 208 acpi_gbl_optarg);
209 return (-1); 209 return (-1);
210 } 210 }
211 continue; 211 continue;
@@ -226,13 +226,13 @@ static int ap_do_options(int argc, char **argv)
226 226
227 case 'v': /* Revision/version */ 227 case 'v': /* Revision/version */
228 228
229 printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); 229 acpi_os_printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
230 return (1); 230 return (1);
231 231
232 case 'z': /* Verbose mode */ 232 case 'z': /* Verbose mode */
233 233
234 gbl_verbose_mode = TRUE; 234 gbl_verbose_mode = TRUE;
235 fprintf(stderr, ACPI_COMMON_SIGNON(AP_UTILITY_NAME)); 235 acpi_log_error(ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
236 continue; 236 continue;
237 237
238 /* 238 /*
@@ -338,9 +338,8 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
338 338
339 default: 339 default:
340 340
341 fprintf(stderr, 341 acpi_log_error("Internal error, invalid action: 0x%X\n",
342 "Internal error, invalid action: 0x%X\n", 342 action->to_be_done);
343 action->to_be_done);
344 return (-1); 343 return (-1);
345 } 344 }
346 345
@@ -355,12 +354,12 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
355 /* Summary for the output file */ 354 /* Summary for the output file */
356 355
357 file_size = cm_get_file_size(gbl_output_file); 356 file_size = cm_get_file_size(gbl_output_file);
358 fprintf(stderr, 357 acpi_log_error
359 "Output file %s contains 0x%X (%u) bytes\n\n", 358 ("Output file %s contains 0x%X (%u) bytes\n\n",
360 gbl_output_filename, file_size, file_size); 359 gbl_output_filename, file_size, file_size);
361 } 360 }
362 361
363 fclose(gbl_output_file); 362 acpi_os_close_file(gbl_output_file);
364 } 363 }
365 364
366 return (status); 365 return (status);