Merge branch 'acpica'

* acpica: (30 commits)
  ACPICA: Add new GPE public interface - acpi_mark_gpe_for_wake.
  ACPICA: GPEs: Do not allow enable for GPEs that have no handler(s).
  ACPICA: Fix a regression for deletion of Alias() objects.
  ACPICA: Update version to 20140627
  ACPICA: Tables: Merge DMAR table structure updates
  ACPICA: Hardware: back port of a recursive locking fix
  ACPICA: utprint/oslibcfs: cleanup - no functional change
  ACPICA: Executer: Fix trivial issues in acpi_get_serial_access_bytes()
  ACPICA: OSL: Update acpidump to reduce source code differences
  ACPICA: acpidump: Reduce freopen() invocations to improve portability
  ACPICA: acpidump: Replace file IOs with new APIs to improve portability
  ACPICA: acpidump: Remove exit() from generic layer to improve portability
  ACPICA: acpidump: Add memory/string OSL usage to improve portability
  ACPICA: Common: Enhance acpi_getopt() to improve portability
  ACPICA: Common: Enhance cm_get_file_size() to improve portability
  ACPICA: Application: Enhance ACPI_USAGE_xxx/ACPI_OPTION with acpi_os_printf() to improve portability
  ACPICA: Utilities: Introduce acpi_log_error() to improve portability
  ACPICA: Utilities: Add formatted printing APIs
  ACPICA: OSL: Add portable file IO to improve portability
  ACPICA: OSL: Clean up acpi_os_printf()/acpi_os_vprintf() stubs
  ...
This commit is contained in:
Rafael J. Wysocki 2014-07-27 23:51:45 +02:00
commit 92a18409ba
38 changed files with 3340 additions and 404 deletions

View file

@ -108,13 +108,18 @@ DUMP_OBJS = \
apmain.o\
osunixdir.o\
osunixmap.o\
osunixxf.o\
tbprint.o\
tbxfroot.o\
utbuffer.o\
utdebug.o\
utexcep.o\
utglobal.o\
utmath.o\
utprint.o\
utstring.o\
utxferror.o\
oslibcfs.o\
oslinuxtbl.o\
cmfsize.o\
getopt.o

View file

@ -58,44 +58,46 @@ ACPI_MODULE_NAME("cmfsize")
* RETURN: File Size. On error, -1 (ACPI_UINT32_MAX)
*
* DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open.
* Does not disturb the current file pointer. Uses perror for
* error messages.
* Does not disturb the current file pointer.
*
******************************************************************************/
u32 cm_get_file_size(FILE * file)
u32 cm_get_file_size(ACPI_FILE file)
{
long file_size;
long current_offset;
acpi_status status;
/* Save the current file pointer, seek to EOF to obtain file size */
current_offset = ftell(file);
current_offset = acpi_os_get_file_offset(file);
if (current_offset < 0) {
goto offset_error;
}
if (fseek(file, 0, SEEK_END)) {
status = acpi_os_set_file_offset(file, 0, ACPI_FILE_END);
if (ACPI_FAILURE(status)) {
goto seek_error;
}
file_size = ftell(file);
file_size = acpi_os_get_file_offset(file);
if (file_size < 0) {
goto offset_error;
}
/* Restore original file pointer */
if (fseek(file, current_offset, SEEK_SET)) {
status = acpi_os_set_file_offset(file, current_offset, ACPI_FILE_BEGIN);
if (ACPI_FAILURE(status)) {
goto seek_error;
}
return ((u32)file_size);
offset_error:
perror("Could not get file offset");
acpi_log_error("Could not get file offset");
return (ACPI_UINT32_MAX);
seek_error:
perror("Could not seek file");
acpi_log_error("Could not set file offset");
return (ACPI_UINT32_MAX);
}

View file

@ -51,14 +51,12 @@
* "f|" - Option has required single-char sub-options
*/
#include <stdio.h>
#include <string.h>
#include <acpi/acpi.h>
#include "accommon.h"
#include "acapps.h"
#define ACPI_OPTION_ERROR(msg, badchar) \
if (acpi_gbl_opterr) {fprintf (stderr, "%s%c\n", msg, badchar);}
if (acpi_gbl_opterr) {acpi_log_error ("%s%c\n", msg, badchar);}
int acpi_gbl_opterr = 1;
int acpi_gbl_optind = 1;
@ -113,7 +111,7 @@ int acpi_getopt_argument(int argc, char **argv)
* PARAMETERS: argc, argv - from main
* opts - options info list
*
* RETURN: Option character or EOF
* RETURN: Option character or ACPI_OPT_END
*
* DESCRIPTION: Get the next option
*
@ -128,10 +126,10 @@ int acpi_getopt(int argc, char **argv, char *opts)
if (acpi_gbl_optind >= argc ||
argv[acpi_gbl_optind][0] != '-' ||
argv[acpi_gbl_optind][1] == '\0') {
return (EOF);
} else if (strcmp(argv[acpi_gbl_optind], "--") == 0) {
return (ACPI_OPT_END);
} else if (ACPI_STRCMP(argv[acpi_gbl_optind], "--") == 0) {
acpi_gbl_optind++;
return (EOF);
return (ACPI_OPT_END);
}
}
@ -142,7 +140,7 @@ int acpi_getopt(int argc, char **argv, char *opts)
/* Make sure that the option is legal */
if (current_char == ':' ||
(opts_ptr = strchr(opts, current_char)) == NULL) {
(opts_ptr = ACPI_STRCHR(opts, current_char)) == NULL) {
ACPI_OPTION_ERROR("Illegal option: -", current_char);
if (argv[acpi_gbl_optind][++current_char_ptr] == '\0') {

View file

@ -0,0 +1,214 @@
/******************************************************************************
*
* Module Name: oslibcfs - C library OSL for file I/O
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2014, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#include <acpi/acpi.h>
#include <stdio.h>
#include <stdarg.h>
#define _COMPONENT ACPI_OS_SERVICES
ACPI_MODULE_NAME("oslibcfs")
/*******************************************************************************
*
* FUNCTION: acpi_os_open_file
*
* PARAMETERS: path - File path
* modes - File operation type
*
* RETURN: File descriptor.
*
* DESCRIPTION: Open a file for reading (ACPI_FILE_READING) or/and writing
* (ACPI_FILE_WRITING).
*
******************************************************************************/
ACPI_FILE acpi_os_open_file(const char *path, u8 modes)
{
ACPI_FILE file;
u32 i = 0;
char modes_str[4];
if (modes & ACPI_FILE_READING) {
modes_str[i++] = 'r';
}
if (modes & ACPI_FILE_WRITING) {
modes_str[i++] = 'w';
}
if (modes & ACPI_FILE_BINARY) {
modes_str[i++] = 'b';
}
modes_str[i++] = '\0';
file = fopen(path, modes_str);
if (!file) {
perror("Could not open file");
}
return (file);
}
/*******************************************************************************
*
* FUNCTION: acpi_os_close_file
*
* PARAMETERS: file - An open file descriptor
*
* RETURN: None.
*
* DESCRIPTION: Close a file opened via acpi_os_open_file.
*
******************************************************************************/
void acpi_os_close_file(ACPI_FILE file)
{
fclose(file);
}
/*******************************************************************************
*
* FUNCTION: acpi_os_read_file
*
* PARAMETERS: file - An open file descriptor
* buffer - Data buffer
* size - Data block size
* count - Number of data blocks
*
* RETURN: Number of bytes actually read.
*
* DESCRIPTION: Read from a file.
*
******************************************************************************/
int
acpi_os_read_file(ACPI_FILE file, void *buffer, acpi_size size, acpi_size count)
{
int length;
length = fread(buffer, size, count, file);
if (length < 0) {
perror("Error reading file");
}
return (length);
}
/*******************************************************************************
*
* FUNCTION: acpi_os_write_file
*
* PARAMETERS: file - An open file descriptor
* buffer - Data buffer
* size - Data block size
* count - Number of data blocks
*
* RETURN: Number of bytes actually written.
*
* DESCRIPTION: Write to a file.
*
******************************************************************************/
int
acpi_os_write_file(ACPI_FILE file,
void *buffer, acpi_size size, acpi_size count)
{
int length;
length = fwrite(buffer, size, count, file);
if (length < 0) {
perror("Error writing file");
}
return (length);
}
/*******************************************************************************
*
* FUNCTION: acpi_os_get_file_offset
*
* PARAMETERS: file - An open file descriptor
*
* RETURN: Current file pointer position.
*
* DESCRIPTION: Get current file offset.
*
******************************************************************************/
long acpi_os_get_file_offset(ACPI_FILE file)
{
long offset;
offset = ftell(file);
return (offset);
}
/*******************************************************************************
*
* FUNCTION: acpi_os_set_file_offset
*
* PARAMETERS: file - An open file descriptor
* offset - New file offset
* from - From begin/end of file
*
* RETURN: Status
*
* DESCRIPTION: Set current file offset.
*
******************************************************************************/
acpi_status acpi_os_set_file_offset(ACPI_FILE file, long offset, u8 from)
{
int ret = 0;
if (from == ACPI_FILE_BEGIN) {
ret = fseek(file, offset, SEEK_SET);
}
if (from == ACPI_FILE_END) {
ret = fseek(file, offset, SEEK_END);
}
if (ret < 0) {
return (AE_ERROR);
} else {
return (AE_OK);
}
}

View file

@ -77,6 +77,9 @@ osl_map_table(acpi_size address,
static void osl_unmap_table(struct acpi_table_header *table);
static acpi_physical_address
osl_find_rsdp_via_efi_by_keyword(FILE * file, const char *keyword);
static acpi_physical_address osl_find_rsdp_via_efi(void);
static acpi_status osl_load_rsdp(void);
@ -415,6 +418,38 @@ acpi_os_get_table_by_index(u32 index,
return (status);
}
/******************************************************************************
*
* FUNCTION: osl_find_rsdp_via_efi_by_keyword
*
* PARAMETERS: keyword - Character string indicating ACPI GUID version
* in the EFI table
*
* RETURN: RSDP address if found
*
* DESCRIPTION: Find RSDP address via EFI using keyword indicating the ACPI
* GUID version.
*
*****************************************************************************/
static acpi_physical_address
osl_find_rsdp_via_efi_by_keyword(FILE * file, const char *keyword)
{
char buffer[80];
unsigned long long address = 0;
char format[32];
snprintf(format, 32, "%s=%s", keyword, "%llx");
fseek(file, 0, SEEK_SET);
while (fgets(buffer, 80, file)) {
if (sscanf(buffer, format, &address) == 1) {
break;
}
}
return ((acpi_physical_address) (address));
}
/******************************************************************************
*
* FUNCTION: osl_find_rsdp_via_efi
@ -430,20 +465,19 @@ acpi_os_get_table_by_index(u32 index,
static acpi_physical_address osl_find_rsdp_via_efi(void)
{
FILE *file;
char buffer[80];
unsigned long address = 0;
acpi_physical_address address = 0;
file = fopen(EFI_SYSTAB, "r");
if (file) {
while (fgets(buffer, 80, file)) {
if (sscanf(buffer, "ACPI20=0x%lx", &address) == 1) {
break;
}
address = osl_find_rsdp_via_efi_by_keyword(file, "ACPI20");
if (!address) {
address =
osl_find_rsdp_via_efi_by_keyword(file, "ACPI");
}
fclose(file);
}
return ((acpi_physical_address) (address));
return (address);
}
/******************************************************************************

File diff suppressed because it is too large Load diff

View file

@ -47,7 +47,6 @@
#ifdef _DECLARE_GLOBALS
#define EXTERN
#define INIT_GLOBAL(a,b) a=b
#define DEFINE_ACPI_GLOBALS 1
#else
#define EXTERN extern
#define INIT_GLOBAL(a,b) a
@ -69,7 +68,7 @@ EXTERN u8 INIT_GLOBAL(gbl_verbose_mode, FALSE);
EXTERN u8 INIT_GLOBAL(gbl_binary_mode, FALSE);
EXTERN u8 INIT_GLOBAL(gbl_dump_customized_tables, FALSE);
EXTERN u8 INIT_GLOBAL(gbl_do_not_dump_xsdt, FALSE);
EXTERN FILE INIT_GLOBAL(*gbl_output_file, NULL);
EXTERN ACPI_FILE INIT_GLOBAL(gbl_output_file, NULL);
EXTERN char INIT_GLOBAL(*gbl_output_filename, NULL);
EXTERN u64 INIT_GLOBAL(gbl_rsdp_base, 0);

View file

@ -69,17 +69,16 @@ u8 ap_is_valid_header(struct acpi_table_header *table)
/* Make sure signature is all ASCII and a valid ACPI name */
if (!acpi_ut_valid_acpi_name(table->signature)) {
fprintf(stderr,
"Table signature (0x%8.8X) is invalid\n",
*(u32 *)table->signature);
acpi_log_error("Table signature (0x%8.8X) is invalid\n",
*(u32 *)table->signature);
return (FALSE);
}
/* Check for minimum table length */
if (table->length < sizeof(struct acpi_table_header)) {
fprintf(stderr, "Table length (0x%8.8X) is invalid\n",
table->length);
acpi_log_error("Table length (0x%8.8X) is invalid\n",
table->length);
return (FALSE);
}
}
@ -116,8 +115,8 @@ u8 ap_is_valid_checksum(struct acpi_table_header *table)
}
if (ACPI_FAILURE(status)) {
fprintf(stderr, "%4.4s: Warning: wrong checksum in table\n",
table->signature);
acpi_log_error("%4.4s: Warning: wrong checksum in table\n",
table->signature);
}
return (AE_OK);
@ -196,12 +195,13 @@ ap_dump_table_buffer(struct acpi_table_header *table,
* Note: simplest to just always emit a 64-bit address. acpi_xtract
* utility can handle this.
*/
printf("%4.4s @ 0x%8.8X%8.8X\n", table->signature,
ACPI_FORMAT_UINT64(address));
acpi_ut_file_printf(gbl_output_file, "%4.4s @ 0x%8.8X%8.8X\n",
table->signature, ACPI_FORMAT_UINT64(address));
acpi_ut_dump_buffer(ACPI_CAST_PTR(u8, table), table_length,
DB_BYTE_DISPLAY, 0);
printf("\n");
acpi_ut_dump_buffer_to_file(gbl_output_file,
ACPI_CAST_PTR(u8, table), table_length,
DB_BYTE_DISPLAY, 0);
acpi_ut_file_printf(gbl_output_file, "\n");
return (0);
}
@ -239,20 +239,20 @@ int ap_dump_all_tables(void)
if (status == AE_LIMIT) {
return (0);
} else if (i == 0) {
fprintf(stderr,
"Could not get ACPI tables, %s\n",
acpi_format_exception(status));
acpi_log_error
("Could not get ACPI tables, %s\n",
acpi_format_exception(status));
return (-1);
} else {
fprintf(stderr,
"Could not get ACPI table at index %u, %s\n",
i, acpi_format_exception(status));
acpi_log_error
("Could not get ACPI table at index %u, %s\n",
i, acpi_format_exception(status));
continue;
}
}
table_status = ap_dump_table_buffer(table, instance, address);
free(table);
ACPI_FREE(table);
if (table_status) {
break;
@ -288,22 +288,22 @@ int ap_dump_table_by_address(char *ascii_address)
status = acpi_ut_strtoul64(ascii_address, 0, &long_address);
if (ACPI_FAILURE(status)) {
fprintf(stderr, "%s: Could not convert to a physical address\n",
ascii_address);
acpi_log_error("%s: Could not convert to a physical address\n",
ascii_address);
return (-1);
}
address = (acpi_physical_address) long_address;
status = acpi_os_get_table_by_address(address, &table);
if (ACPI_FAILURE(status)) {
fprintf(stderr, "Could not get table at 0x%8.8X%8.8X, %s\n",
ACPI_FORMAT_UINT64(address),
acpi_format_exception(status));
acpi_log_error("Could not get table at 0x%8.8X%8.8X, %s\n",
ACPI_FORMAT_UINT64(address),
acpi_format_exception(status));
return (-1);
}
table_status = ap_dump_table_buffer(table, 0, address);
free(table);
ACPI_FREE(table);
return (table_status);
}
@ -329,24 +329,24 @@ int ap_dump_table_by_name(char *signature)
acpi_status status;
int table_status;
if (strlen(signature) != ACPI_NAME_SIZE) {
fprintf(stderr,
"Invalid table signature [%s]: must be exactly 4 characters\n",
signature);
if (ACPI_STRLEN(signature) != ACPI_NAME_SIZE) {
acpi_log_error
("Invalid table signature [%s]: must be exactly 4 characters\n",
signature);
return (-1);
}
/* Table signatures are expected to be uppercase */
strcpy(local_signature, signature);
ACPI_STRCPY(local_signature, signature);
acpi_ut_strupr(local_signature);
/* To be friendly, handle tables whose signatures do not match the name */
if (ACPI_COMPARE_NAME(local_signature, "FADT")) {
strcpy(local_signature, ACPI_SIG_FADT);
ACPI_STRCPY(local_signature, ACPI_SIG_FADT);
} else if (ACPI_COMPARE_NAME(local_signature, "MADT")) {
strcpy(local_signature, ACPI_SIG_MADT);
ACPI_STRCPY(local_signature, ACPI_SIG_MADT);
}
/* Dump all instances of this signature (to handle multiple SSDTs) */
@ -362,14 +362,14 @@ int ap_dump_table_by_name(char *signature)
return (0);
}
fprintf(stderr,
"Could not get ACPI table with signature [%s], %s\n",
local_signature, acpi_format_exception(status));
acpi_log_error
("Could not get ACPI table with signature [%s], %s\n",
local_signature, acpi_format_exception(status));
return (-1);
}
table_status = ap_dump_table_buffer(table, instance, address);
free(table);
ACPI_FREE(table);
if (table_status) {
break;
@ -409,43 +409,21 @@ int ap_dump_table_from_file(char *pathname)
/* File must be at least as long as the table length */
if (table->length > file_size) {
fprintf(stderr,
"Table length (0x%X) is too large for input file (0x%X) %s\n",
table->length, file_size, pathname);
acpi_log_error
("Table length (0x%X) is too large for input file (0x%X) %s\n",
table->length, file_size, pathname);
goto exit;
}
if (gbl_verbose_mode) {
fprintf(stderr,
"Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n",
pathname, table->signature, file_size, file_size);
acpi_log_error
("Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n",
pathname, table->signature, file_size, file_size);
}
table_status = ap_dump_table_buffer(table, 0, 0);
exit:
free(table);
ACPI_FREE(table);
return (table_status);
}
/******************************************************************************
*
* FUNCTION: acpi_os* print functions
*
* DESCRIPTION: Used for linkage with ACPICA modules
*
******************************************************************************/
void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vfprintf(stdout, fmt, args);
va_end(args);
}
void acpi_os_vprintf(const char *fmt, va_list args)
{
vfprintf(stdout, fmt, args);
}

View file

@ -44,6 +44,27 @@
#include "acpidump.h"
#include "acapps.h"
/* Local prototypes */
static int ap_is_existing_file(char *pathname);
static int ap_is_existing_file(char *pathname)
{
#ifndef _GNU_EFI
struct stat stat_info;
if (!stat(pathname, &stat_info)) {
acpi_log_error("Target path already exists, overwrite? [y|n] ");
if (getchar() != 'y') {
return (-1);
}
}
#endif
return 0;
}
/******************************************************************************
*
* FUNCTION: ap_open_output_file
@ -59,25 +80,19 @@
int ap_open_output_file(char *pathname)
{
struct stat stat_info;
FILE *file;
ACPI_FILE file;
/* If file exists, prompt for overwrite */
if (!stat(pathname, &stat_info)) {
fprintf(stderr,
"Target path already exists, overwrite? [y|n] ");
if (getchar() != 'y') {
return (-1);
}
if (ap_is_existing_file(pathname) != 0) {
return (-1);
}
/* Point stdout to the file */
file = freopen(pathname, "w", stdout);
file = acpi_os_open_file(pathname, ACPI_FILE_WRITING);
if (!file) {
perror("Could not open output file");
acpi_log_error("Could not open output file: %s\n", pathname);
return (-1);
}
@ -106,7 +121,7 @@ int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance)
{
char filename[ACPI_NAME_SIZE + 16];
char instance_str[16];
FILE *file;
ACPI_FILE file;
size_t actual;
u32 table_length;
@ -130,35 +145,37 @@ int ap_write_to_binary_file(struct acpi_table_header *table, u32 instance)
/* Handle multiple SSDts - create different filenames for each */
if (instance > 0) {
sprintf(instance_str, "%u", instance);
strcat(filename, instance_str);
acpi_ut_snprintf(instance_str, sizeof(instance_str), "%u",
instance);
ACPI_STRCAT(filename, instance_str);
}
strcat(filename, ACPI_TABLE_FILE_SUFFIX);
ACPI_STRCAT(filename, ACPI_TABLE_FILE_SUFFIX);
if (gbl_verbose_mode) {
fprintf(stderr,
"Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n",
table->signature, filename, table->length,
table->length);
acpi_log_error
("Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n",
table->signature, filename, table->length, table->length);
}
/* Open the file and dump the entire table in binary mode */
file = fopen(filename, "wb");
file = acpi_os_open_file(filename,
ACPI_FILE_WRITING | ACPI_FILE_BINARY);
if (!file) {
perror("Could not open output file");
acpi_log_error("Could not open output file: %s\n", filename);
return (-1);
}
actual = fwrite(table, 1, table_length, file);
actual = acpi_os_write_file(file, table, 1, table_length);
if (actual != table_length) {
perror("Error writing binary output file");
fclose(file);
acpi_log_error("Error writing binary output file: %s\n",
filename);
acpi_os_close_file(file);
return (-1);
}
fclose(file);
acpi_os_close_file(file);
return (0);
}
@ -179,15 +196,16 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname,
u32 *out_file_size)
{
struct acpi_table_header *buffer = NULL;
FILE *file;
ACPI_FILE file;
u32 file_size;
size_t actual;
/* Must use binary mode */
file = fopen(pathname, "rb");
file =
acpi_os_open_file(pathname, ACPI_FILE_READING | ACPI_FILE_BINARY);
if (!file) {
perror("Could not open input file");
acpi_log_error("Could not open input file: %s\n", pathname);
return (NULL);
}
@ -195,27 +213,25 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname,
file_size = cm_get_file_size(file);
if (file_size == ACPI_UINT32_MAX) {
fprintf(stderr,
"Could not get input file size: %s\n", pathname);
acpi_log_error("Could not get input file size: %s\n", pathname);
goto cleanup;
}
/* Allocate a buffer for the entire file */
buffer = calloc(1, file_size);
buffer = ACPI_ALLOCATE_ZEROED(file_size);
if (!buffer) {
fprintf(stderr,
"Could not allocate file buffer of size: %u\n",
file_size);
acpi_log_error("Could not allocate file buffer of size: %u\n",
file_size);
goto cleanup;
}
/* Read the entire file */
actual = fread(buffer, 1, file_size, file);
actual = acpi_os_read_file(file, buffer, 1, file_size);
if (actual != file_size) {
fprintf(stderr, "Could not read input file: %s\n", pathname);
free(buffer);
acpi_log_error("Could not read input file: %s\n", pathname);
ACPI_FREE(buffer);
buffer = NULL;
goto cleanup;
}
@ -223,6 +239,6 @@ struct acpi_table_header *ap_get_table_from_file(char *pathname,
*out_file_size = file_size;
cleanup:
fclose(file);
acpi_os_close_file(file);
return (buffer);
}

View file

@ -72,7 +72,7 @@ static void ap_display_usage(void);
static int ap_do_options(int argc, char **argv);
static void ap_insert_action(char *argument, u32 to_be_done);
static int ap_insert_action(char *argument, u32 to_be_done);
/* Table for deferred actions from command line options */
@ -104,7 +104,7 @@ static void ap_display_usage(void)
ACPI_OPTION("-v", "Display version information");
ACPI_OPTION("-z", "Verbose mode");
printf("\nTable Options:\n");
ACPI_USAGE_TEXT("\nTable Options:\n");
ACPI_OPTION("-a <Address>", "Get table via a physical address");
ACPI_OPTION("-f <BinaryFile>", "Get table via a binary file");
@ -112,9 +112,9 @@ static void ap_display_usage(void)
ACPI_OPTION("-x", "Do not use but dump XSDT");
ACPI_OPTION("-x -x", "Do not use or dump XSDT");
printf("\n"
"Invocation without parameters dumps all available tables\n"
"Multiple mixed instances of -a, -f, and -n are supported\n\n");
ACPI_USAGE_TEXT("\n"
"Invocation without parameters dumps all available tables\n"
"Multiple mixed instances of -a, -f, and -n are supported\n\n");
}
/******************************************************************************
@ -124,13 +124,13 @@ static void ap_display_usage(void)
* PARAMETERS: argument - Pointer to the argument for this action
* to_be_done - What to do to process this action
*
* RETURN: None. Exits program if action table becomes full.
* RETURN: Status
*
* DESCRIPTION: Add an action item to the action table
*
******************************************************************************/
static void ap_insert_action(char *argument, u32 to_be_done)
static int ap_insert_action(char *argument, u32 to_be_done)
{
/* Insert action and check for table overflow */
@ -140,10 +140,12 @@ static void ap_insert_action(char *argument, u32 to_be_done)
current_action++;
if (current_action > AP_MAX_ACTIONS) {
fprintf(stderr, "Too many table options (max %u)\n",
AP_MAX_ACTIONS);
exit(-1);
acpi_log_error("Too many table options (max %u)\n",
AP_MAX_ACTIONS);
return (-1);
}
return (0);
}
/******************************************************************************
@ -166,7 +168,8 @@ static int ap_do_options(int argc, char **argv)
/* Command line options */
while ((j = acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != EOF)
while ((j =
acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END)
switch (j) {
/*
* Global options
@ -185,12 +188,12 @@ static int ap_do_options(int argc, char **argv)
case '?':
ap_display_usage();
exit(0);
return (1);
case 'o': /* Redirect output to a single file */
if (ap_open_output_file(acpi_gbl_optarg)) {
exit(-1);
return (-1);
}
continue;
@ -200,10 +203,10 @@ static int ap_do_options(int argc, char **argv)
acpi_ut_strtoul64(acpi_gbl_optarg, 0,
&gbl_rsdp_base);
if (ACPI_FAILURE(status)) {
fprintf(stderr,
"%s: Could not convert to a physical address\n",
acpi_gbl_optarg);
exit(-1);
acpi_log_error
("%s: Could not convert to a physical address\n",
acpi_gbl_optarg);
return (-1);
}
continue;
@ -223,13 +226,13 @@ static int ap_do_options(int argc, char **argv)
case 'v': /* Revision/version */
printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
exit(0);
acpi_os_printf(ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
return (1);
case 'z': /* Verbose mode */
gbl_verbose_mode = TRUE;
fprintf(stderr, ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
acpi_log_error(ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
continue;
/*
@ -237,32 +240,40 @@ static int ap_do_options(int argc, char **argv)
*/
case 'a': /* Get table by physical address */
ap_insert_action(acpi_gbl_optarg,
AP_DUMP_TABLE_BY_ADDRESS);
if (ap_insert_action
(acpi_gbl_optarg, AP_DUMP_TABLE_BY_ADDRESS)) {
return (-1);
}
break;
case 'f': /* Get table from a file */
ap_insert_action(acpi_gbl_optarg,
AP_DUMP_TABLE_BY_FILE);
if (ap_insert_action
(acpi_gbl_optarg, AP_DUMP_TABLE_BY_FILE)) {
return (-1);
}
break;
case 'n': /* Get table by input name (signature) */
ap_insert_action(acpi_gbl_optarg,
AP_DUMP_TABLE_BY_NAME);
if (ap_insert_action
(acpi_gbl_optarg, AP_DUMP_TABLE_BY_NAME)) {
return (-1);
}
break;
default:
ap_display_usage();
exit(-1);
return (-1);
}
/* If there are no actions, this means "get/dump all tables" */
if (current_action == 0) {
ap_insert_action(NULL, AP_DUMP_ALL_TABLES);
if (ap_insert_action(NULL, AP_DUMP_ALL_TABLES)) {
return (-1);
}
}
return (0);
@ -280,7 +291,11 @@ static int ap_do_options(int argc, char **argv)
*
******************************************************************************/
#ifndef _GNU_EFI
int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
#else
int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[])
#endif
{
int status = 0;
struct ap_dump_action *action;
@ -288,11 +303,17 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
u32 i;
ACPI_DEBUG_INITIALIZE(); /* For debug version only */
acpi_os_initialize();
gbl_output_file = ACPI_FILE_OUT;
/* Process command line options */
if (ap_do_options(argc, argv)) {
return (-1);
status = ap_do_options(argc, argv);
if (status > 0) {
return (0);
}
if (status < 0) {
return (status);
}
/* Get/dump ACPI table(s) as requested */
@ -322,9 +343,8 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
default:
fprintf(stderr,
"Internal error, invalid action: 0x%X\n",
action->to_be_done);
acpi_log_error("Internal error, invalid action: 0x%X\n",
action->to_be_done);
return (-1);
}
@ -333,18 +353,18 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
}
}
if (gbl_output_file) {
if (gbl_output_filename) {
if (gbl_verbose_mode) {
/* Summary for the output file */
file_size = cm_get_file_size(gbl_output_file);
fprintf(stderr,
"Output file %s contains 0x%X (%u) bytes\n\n",
gbl_output_filename, file_size, file_size);
acpi_log_error
("Output file %s contains 0x%X (%u) bytes\n\n",
gbl_output_filename, file_size, file_size);
}
fclose(gbl_output_file);
acpi_os_close_file(gbl_output_file);
}
return (status);