ACK: [PATCH] lib: iasl: rework IASL interface to ACPICA

ivanhu ivan.hu at canonical.com
Tue Dec 8 06:23:17 UTC 2015



On 2015年11月28日 02:47, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> This set of changes re-works the iasl interface in fwts in preperation
> for a re-working of acpidump to use IASL rather than hand-write our
> own table dumping code.
>
> The main objective of this change was to remove the awful original
> design of referencing the tables to be disassembled by a table index
> and instead allow fwts tests to reference the acpi table via the
> info descriptor.  This allows more context to be passed around to
> help simplify the next set of changes when we want to disassemble
> not only DSTD and SSDT but any table type.
>
> Unfortunately this change requires touching a few places from the
> core ACPICA <--> fwts lib layer and the fwts lib <---> fwts test
> layer.
>
> One final change was to add a boolean flag to inform IASL to either
> to use tables containing AML for exernal referencing or not. Only
> disassembly of DSDT and SSDT should require this to be enabled.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>   src/acpi/hpet/hpet.c                             |  19 ++-
>   src/acpi/osilinux/osilinux.c                     |  22 ++-
>   src/acpi/syntaxcheck/syntaxcheck.c               |  27 ++--
>   src/acpica/source/compiler/fwts_iasl_interface.c |  63 +++++---
>   src/acpica/source/compiler/fwts_iasl_interface.h |   9 +-
>   src/lib/include/fwts_acpi_tables.h               |   4 +
>   src/lib/include/fwts_iasl.h                      |   8 +-
>   src/lib/src/fwts_acpi_tables.c                   |   8 +-
>   src/lib/src/fwts_iasl.c                          | 196 ++++++++++-------------
>   9 files changed, 187 insertions(+), 169 deletions(-)
>
> diff --git a/src/acpi/hpet/hpet.c b/src/acpi/hpet/hpet.c
> index b8f82cf..d3380a3 100644
> --- a/src/acpi/hpet/hpet.c
> +++ b/src/acpi/hpet/hpet.c
> @@ -101,13 +101,14 @@ static void hpet_parse_device_hpet(fwts_framework *fw,
>    *  check_hpet_base_dsdt()
>    *	used to parse the DSDT for HPET base info
>    */
> -static void hpet_check_base_acpi_table(fwts_framework *fw,
> -	const char *table, const int which)
> +static void hpet_check_base_acpi_table(
> +	fwts_framework *fw,
> +	fwts_acpi_table_info *info)
>   {
>   	fwts_list *output;
>   	fwts_list_link *item;
>   
> -	if (fwts_iasl_disassemble(fw, table, which, &output) != FWTS_OK) {
> +	if (fwts_iasl_disassemble(fw, info, true, &output) != FWTS_OK) {
>   		fwts_iasl_deinit();
>   		return;
>   	}
> @@ -116,7 +117,7 @@ static void hpet_check_base_acpi_table(fwts_framework *fw,
>   
>   	fwts_list_foreach(item, output)
>   		if (strstr(fwts_text_list_text(item), "Device (HPET)") != NULL)
> -			hpet_parse_device_hpet(fw, table, item);
> +			hpet_parse_device_hpet(fw, info->name, item);
>   
>   	fwts_text_list_free(output);
>   }
> @@ -384,10 +385,14 @@ static int hpet_check_test3(fwts_framework *fw)
>   		return FWTS_ERROR;
>   	}
>   
> -	hpet_check_base_acpi_table(fw, "DSDT", 0);
> +	for (i = 0; i < ACPI_MAX_TABLES; i++) {
> +		fwts_acpi_table_info *info;
>   
> -	for (i = 0; i < 11; i++)
> -		hpet_check_base_acpi_table(fw, "SSDT", i);
> +		if (fwts_acpi_get_table(fw, i, &info) != FWTS_OK)
> +			break;
> +		if (info && info->has_aml)
> +			hpet_check_base_acpi_table(fw, info);
> +	}
>   
>   	fwts_iasl_deinit();
>   
> diff --git a/src/acpi/osilinux/osilinux.c b/src/acpi/osilinux/osilinux.c
> index 556d4bc..e94547a 100644
> --- a/src/acpi/osilinux/osilinux.c
> +++ b/src/acpi/osilinux/osilinux.c
> @@ -22,6 +22,7 @@
>   
>   #include <stdlib.h>
>   #include <stdio.h>
> +#include <stdbool.h>
>   #include <sys/types.h>
>   #include <sys/stat.h>
>   #include <unistd.h>
> @@ -29,22 +30,29 @@
>   
>   static int osilinux_test1(fwts_framework *fw)
>   {
> +	fwts_acpi_table_info *info;
>   	fwts_list_link *item;
>   	fwts_list_link *dumpitem = NULL;
> -	fwts_list* disassembly;
> +	fwts_list* disassembly = NULL;
>   	int depth = 0;
>   	int dumpdepth = 0;
> -	int found = 0;
> +	bool found = false;
>   
>   	if (fwts_iasl_init(fw) != FWTS_OK) {
>   		fwts_aborted(fw, "Failure to initialise iasl, aborting.");
>   		fwts_iasl_deinit();
>   		return FWTS_ERROR;
>   	}
> -	if (fwts_iasl_disassemble(fw, "DSDT", 0, &disassembly) != FWTS_OK) {
> -		fwts_aborted(fw, "Cannot disassemble DSDT with iasl.");
> -		fwts_iasl_deinit();
> -		return FWTS_ERROR;
> +	if (fwts_acpi_find_table(fw, "DSDT", 0, &info) != FWTS_OK) {
> +		fwts_log_error(fw, "Cannot located DSDT.");
> +                return FWTS_ERROR;
> +        }
> +        if (info) {
> +		if (fwts_iasl_disassemble(fw, info, true, &disassembly) != FWTS_OK) {
> +			fwts_aborted(fw, "Cannot disassemble DSDT with iasl.");
> +			fwts_iasl_deinit();
> +			return FWTS_ERROR;
> +		}
>   	}
>   	fwts_iasl_deinit();
>   
> @@ -73,7 +81,7 @@ static int osilinux_test1(fwts_framework *fw)
>   		if (strstr(line, "}")) {
>   			depth--;
>   			if (dumpdepth != 0 && dumpdepth != depth) {
> -				found++;
> +				found = true;
>   				while (dumpitem != NULL &&
>   				       dumpitem != item->next) {
>   					fwts_log_warning_verbatum(fw, "%s", fwts_text_list_text(dumpitem));
> diff --git a/src/acpi/syntaxcheck/syntaxcheck.c b/src/acpi/syntaxcheck/syntaxcheck.c
> index c189e87..c5b0d27 100644
> --- a/src/acpi/syntaxcheck/syntaxcheck.c
> +++ b/src/acpi/syntaxcheck/syntaxcheck.c
> @@ -462,16 +462,18 @@ static void syntaxcheck_give_advice(fwts_framework *fw, uint32_t error_code)
>    *	disassemble and reassemble a table, check for errors. which indicates the Nth
>    *	table
>    */
> -static int syntaxcheck_table(fwts_framework *fw, int which)
> +static int syntaxcheck_table(
> +	fwts_framework *fw,
> +	const fwts_acpi_table_info *info,
> +	const int n)
>   {
>   	fwts_list_link *item;
>   	int errors = 0;
>   	int warnings = 0;
>   	int remarks = 0;
> -	char *tablename = fwts_iasl_aml_name(which);
>   	fwts_list *iasl_stdout, *iasl_stderr, *iasl_disassembly;
>   
> -	if (fwts_iasl_reassemble(fw, which,
> +	if (fwts_iasl_reassemble(fw, info,
>   		&iasl_disassembly, &iasl_stdout, &iasl_stderr) != FWTS_OK) {
>   		fwts_text_list_free(iasl_disassembly);
>   		fwts_text_list_free(iasl_stderr);
> @@ -481,7 +483,7 @@ static int syntaxcheck_table(fwts_framework *fw, int which)
>   	}
>   
>   	fwts_log_nl(fw);
> -	fwts_log_info(fw, "Checking ACPI table %s (#%d)", tablename, which);
> +	fwts_log_info(fw, "Checking ACPI table %s (#%d)", info->name, n);
>   	fwts_log_nl(fw);
>   
>   	if (iasl_stdout) {
> @@ -601,9 +603,9 @@ static int syntaxcheck_table(fwts_framework *fw, int which)
>   
>   	if (errors + warnings + remarks > 0)
>   		fwts_log_info(fw, "Table %s (%d) reassembly: Found %d errors, %d warnings, %d remarks.",
> -			tablename, which, errors, warnings, remarks);
> +			info->name, n, errors, warnings, remarks);
>   	else
> -		fwts_passed(fw, "%s (%d) reassembly, Found 0 errors, 0 warnings, 0 remarks.", tablename, which);
> +		fwts_passed(fw, "%s (%d) reassembly, Found 0 errors, 0 warnings, 0 remarks.", info->name, n);
>   
>   	fwts_log_nl(fw);
>   
> @@ -612,11 +614,16 @@ static int syntaxcheck_table(fwts_framework *fw, int which)
>   
>   static int syntaxcheck_tables(fwts_framework *fw)
>   {
> -	int i;
> -	const int n = fwts_iasl_aml_file_count();
> +	int i, n;
> +
> +	for (i = 0, n = 0; i < ACPI_MAX_TABLES; i++) {
> +		fwts_acpi_table_info *info;
>   
> -	for (i = 0; i < n; i++)
> -		syntaxcheck_table(fw, i);
> +		if (fwts_acpi_get_table(fw, i, &info) != FWTS_OK)
> +			break;
> +		if (info && info->has_aml)
> +			syntaxcheck_table(fw, info, n++);
> +	}
>   
>   	return FWTS_OK;
>   }
> diff --git a/src/acpica/source/compiler/fwts_iasl_interface.c b/src/acpica/source/compiler/fwts_iasl_interface.c
> index ee2970d..83fb926 100644
> --- a/src/acpica/source/compiler/fwts_iasl_interface.c
> +++ b/src/acpica/source/compiler/fwts_iasl_interface.c
> @@ -65,13 +65,18 @@ static void init_asl_core(void)
>    */
>   int fwts_iasl_disassemble_aml(
>   	char *tables[],
> +	char *names[],
>   	const int table_entries,
>   	const int which,
> +	const bool use_externals,
>   	const char *outputfile)
>   {
>   	pid_t	pid;
>   	int	status, i;
> -	FILE *fp;
> +	FILE	*fpout, *fperr;
> +
> +	fflush(stdout);
> +	fflush(stderr);
>   
>   	pid = fork();
>   	switch (pid) {
> @@ -92,30 +97,45 @@ int fwts_iasl_disassemble_aml(
>   		AcpiGbl_DmOpt_Verbose = FALSE;
>   		UtConvertBackslashes (Gbl_OutputFilenamePrefix);
>   
> -		/*
> -		 * Add in external files and NOT the one we want
> -		 * disassemble
> -		 */
> -		for (i = 0; i < table_entries; i++) {
> -			if (i != which) {
> -				ACPI_STATUS	acpi_status;
> -				/*
> -				 *  Add in external tables that are NOT the table
> -				 *  we intent to disassemble
> -				 */
> -				acpi_status = AcpiDmAddToExternalFileList(tables[i]);
> -				if (ACPI_FAILURE(acpi_status)) {
> -					(void)unlink(outputfile);
> -					_exit(1);
> +		/* Do we need to include external tables in? */
> +		if (use_externals) {
> +			/*
> +			 * Add in external SSDT files and NOT the one we want
> +			 * disassemble
> +			 */
> +			for (i = 0; i < table_entries; i++) {
> +				if ((i != which) &&
> +				    (names[i] != NULL) &&
> +				    (tables[i] != NULL) &&
> +				    (!strcmp(names[i], "SSDT") ||
> +				     !strcmp(names[i], "DSDT"))) {
> +					ACPI_STATUS	acpi_status;
> +					/*
> +					 *  Add in external tables that are NOT the table
> +					 *  we intent to disassemble
> +					 */
> +					acpi_status = AcpiDmAddToExternalFileList(tables[i]);
> +					if (ACPI_FAILURE(acpi_status)) {
> +						(void)unlink(outputfile);
> +						_exit(1);
> +					}
>   				}
>   			}
>   		}
> -
>   		/* Throw away noisy errors */
> -		if ((fp = freopen("/dev/null", "w", stderr)) != NULL) {
> -			AslDoOneFile((char *)tables[which]);
> -			fclose(fp);
> +		if ((fpout = freopen("/dev/null", "w", stdout)) == NULL) {
> +			_exit(1);
>   		}
> +		if ((fperr = freopen("/dev/null", "w", stderr)) == NULL) {
> +			fclose(fpout);
> +			_exit(1);
> +		}
> +
> +		/* ...and do the ACPICA disassambly... */
> +		AslDoOneFile((char *)tables[which]);
> +
> +		fclose(fperr);
> +		fclose(fpout);
>   		_exit(0);
>   		break;
>   	default:
> @@ -163,6 +183,9 @@ int fwts_iasl_assemble_aml(const char *source, char **stdout_output, char **stde
>   	pid_t	pid;
>   	bool	stdout_eof = false, stderr_eof = false;
>   
> +	fflush(stdout);
> +	fflush(stderr);
> +
>   	if (pipe(stdout_fds) < 0)
>   		return -1;
>   	if (pipe(stderr_fds) < 0)
> diff --git a/src/acpica/source/compiler/fwts_iasl_interface.h b/src/acpica/source/compiler/fwts_iasl_interface.h
> index a64bce8..62dcb9f 100644
> --- a/src/acpica/source/compiler/fwts_iasl_interface.h
> +++ b/src/acpica/source/compiler/fwts_iasl_interface.h
> @@ -22,8 +22,13 @@
>   
>   #include <stdint.h>
>   
> -int fwts_iasl_disassemble_aml(char *tables[], const int table_entries, const int which, const char *outputfile);
> -int fwts_iasl_assemble_aml(const char *source, char **stdout_output, char **stderr_output);
> +int fwts_iasl_disassemble_aml(
> +	char *tables[], char *names[], const int table_entries,
> +	const int which, const bool use_externals,
> +	const char *outputfile);
> +int fwts_iasl_assemble_aml(
> +	const char *source, char **stdout_output,
> +	char **stderr_output);
>   const char *fwts_iasl_exception_level__(uint8_t level);
>   
>   #endif
> diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
> index df72e76..6b433d9 100644
> --- a/src/lib/include/fwts_acpi_tables.h
> +++ b/src/lib/include/fwts_acpi_tables.h
> @@ -22,6 +22,8 @@
>   
>   #include "fwts.h"
>   
> +#define ACPI_MAX_TABLES		(128)
> +
>   typedef enum {
>   	FWTS_ACPI_TABLE_FROM_FIRMWARE,	/* directly from firmware */
>   	FWTS_ACPI_TABLE_FROM_FILE,	/* loaded from file, e.g. from acpidump */
> @@ -33,6 +35,8 @@ typedef struct {
>   	const void *data;
>   	size_t	length;
>   	int 	which;
> +	int	index;
> +	bool	has_aml;
>   	uint64_t addr;
>   	fwts_acpi_table_provenance provenance;
>   } fwts_acpi_table_info;
> diff --git a/src/lib/include/fwts_iasl.h b/src/lib/include/fwts_iasl.h
> index 425298e..3acd5bb 100644
> --- a/src/lib/include/fwts_iasl.h
> +++ b/src/lib/include/fwts_iasl.h
> @@ -23,8 +23,6 @@
>   #include "fwts.h"
>   #include <stdint.h>
>   
> -int fwts_iasl_aml_file_count(void);
> -char *fwts_iasl_aml_name(const int nth);
>   int fwts_iasl_init(fwts_framework *fw);
>   void fwts_iasl_deinit(void);
>   
> @@ -32,12 +30,12 @@ int fwts_iasl_disassemble_all_to_file(fwts_framework *fw,
>   	const char *path);
>   
>   int fwts_iasl_disassemble(fwts_framework *fw,
> -	const char *table,
> -	const int which,
> +	const fwts_acpi_table_info *info,
> +	const bool use_externals,
>   	fwts_list **ias_output);
>   
>   int fwts_iasl_reassemble(fwts_framework *fw,
> -	const int which,
> +	const fwts_acpi_table_info *info,
>   	fwts_list **iasl_disassembly,
>   	fwts_list **iasl_stdout,
>   	fwts_list **iasl_stderr);
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 6dcf7f8..56f4c6b 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -40,8 +40,6 @@
>   #define BIOS_LENGTH	(BIOS_END - BIOS_START)	/* Length of BIOS memory */
>   #define PAGE_SIZE	(4096)
>   
> -#define ACPI_MAX_TABLES	(64)			/* Max number of ACPI tables */
> -
>   static fwts_acpi_table_info	tables[ACPI_MAX_TABLES];
>   
>   typedef enum {
> @@ -236,7 +234,7 @@ static void fwts_acpi_add_table(
>   	int i;
>   	int which = 0;
>   
> -	for (i=0;i<ACPI_MAX_TABLES;i++) {
> +	for (i = 0; i < ACPI_MAX_TABLES; i++) {
>   		if (addr && tables[i].addr == addr) {
>   			/* We don't need it, it's a duplicate, so free and return */
>   			fwts_low_free(table);
> @@ -251,7 +249,11 @@ static void fwts_acpi_add_table(
>   			tables[i].addr = addr;
>   			tables[i].length = length;
>   			tables[i].which = which;
> +			tables[i].index = i;
>   			tables[i].provenance = provenance;
> +			tables[i].has_aml =
> +				((!strcmp(tables[i].name, "DSDT")) ||
> +				 (!strcmp(tables[i].name, "SSDT")));
>   			return;
>   		}
>   	}
> diff --git a/src/lib/src/fwts_iasl.c b/src/lib/src/fwts_iasl.c
> index 81eecd2..be6d13c 100644
> --- a/src/lib/src/fwts_iasl.c
> +++ b/src/lib/src/fwts_iasl.c
> @@ -31,36 +31,12 @@
>   #include "fwts_iasl_interface.h"
>   #include "fwts_acpica.h"
>   
> -#define MAX_TABLES		(128)
> +/* For ACPICA interface */
> +static char *iasl_cached_table_filename[ACPI_MAX_TABLES];
> +static char *iasl_cached_table_name[ACPI_MAX_TABLES];
>   
> -static fwts_acpi_table_info *iasl_cached_table_info[MAX_TABLES];
> -static char *iasl_cached_table_files[MAX_TABLES];
> -static int iasl_cached_table_file_max = 0;
>   static bool iasl_init = false;
> -
> -/*
> - *  fwts_iasl_aml_file_count()
> - *	return number of cached dumped amlfiles
> - */
> -int fwts_iasl_aml_file_count(void)
> -{
> -	if (iasl_init)
> -		return iasl_cached_table_file_max;
> -	else
> -		return 0;
> -}
> -
> -/*
> - *  fwts_iasl_aml_name()
> - *	return back nth iASL cached table name
> - */
> -char *fwts_iasl_aml_name(const int nth)
> -{
> -	if (iasl_init && nth < iasl_cached_table_file_max)
> -		return iasl_cached_table_info[nth]->name;
> -	else
> -		return "<unknown>";
> -}
> +static int cached_max = 0;
>   
>   /*
>    *  fwts_iasl_dump_aml_to_file()
> @@ -92,46 +68,41 @@ static int fwts_iasl_dump_aml_to_file(
>   }
>   
>   /*
> - *  fwts_iasl_cache_table_to_file()
> + *  fwts_iasl_cache_tables_to_file()
>    *	to disassemble an APCPI table we need to dump it
>    *	to file. To save effort in saving these to file
> - *	multiple times, we dump out all the DSDT and
> - *	SSDTs and cache the references to these.
> + *	multiple times, we dump out all the tables and
> + *	cache the references to these.
>    */
> -static int fwts_iasl_cache_table_to_file(fwts_framework *fw, char *tablename, int which)
> +static int fwts_iasl_cache_tables_to_file(fwts_framework *fw)
>   {
> -	static pid_t pid = 0;
> +	pid_t pid = getpid();
>   	char tmpname[PATH_MAX];
>   	fwts_acpi_table_info *table;
>   	int ret;
>   
> -	if (iasl_cached_table_file_max >= MAX_TABLES) {
> -		fwts_log_error(fw, "Temporary ACPI table lookup table full.");
> -		return FWTS_ERROR;
> -	}
> -	ret = fwts_acpi_find_table(fw, tablename, which, &table);
> -	if (ret != FWTS_OK) {
> -		fwts_log_error(fw, "Cannot load ACPI table %s.", tablename);
> -		return ret;
> -	}
> -	if (table == NULL)
> -		return FWTS_NO_TABLE;	/* Table does not exist */
> -	if (!pid)
> -		pid = getpid();
> -
> -	snprintf(tmpname, sizeof(tmpname), "/tmp/fwts_tmp_table_%d_%s_%d.dsl", pid, tablename, which);
> -	iasl_cached_table_files[iasl_cached_table_file_max] = strdup(tmpname);
> -	if (iasl_cached_table_files[iasl_cached_table_file_max] == NULL) {
> -		fwts_log_error(fw, "Cannot allocate cached table file name.");
> -		return FWTS_ERROR;
> -	}
> -	if (fwts_iasl_dump_aml_to_file(fw, table->data, table->length, tmpname) != FWTS_OK) {
> -		free(iasl_cached_table_files[iasl_cached_table_file_max]);
> -		iasl_cached_table_files[iasl_cached_table_file_max] = NULL;
> -		return FWTS_ERROR;
> +	for (cached_max = 0; cached_max < ACPI_MAX_TABLES; cached_max++) {
> +		ret = fwts_acpi_get_table(fw, cached_max, &table);
> +		if (ret != FWTS_OK)
> +			return ret;
> +		if (table == NULL)
> +			continue;
> +
> +		snprintf(tmpname, sizeof(tmpname),
> +			"/tmp/fwts_tmp_table_%d_%s_%d.dsl",
> +			pid, table->name, cached_max);
> +		iasl_cached_table_filename[cached_max] = strdup(tmpname);
> +		iasl_cached_table_name[cached_max] = table->name;
> +		if (iasl_cached_table_filename[cached_max] == NULL) {
> +			fwts_log_error(fw, "Cannot allocate cached table file name.");
> +			return FWTS_ERROR;
> +		}
> +		if (fwts_iasl_dump_aml_to_file(fw, table->data, table->length, tmpname) != FWTS_OK) {
> +			free(iasl_cached_table_filename[cached_max]);
> +			iasl_cached_table_filename[cached_max] = NULL;
> +			iasl_cached_table_name[cached_max] = NULL;
> +		}
>   	}
> -	iasl_cached_table_info[iasl_cached_table_file_max] = table;
> -	iasl_cached_table_file_max++;
>   	return FWTS_OK;
>   }
>   
> @@ -143,13 +114,16 @@ void fwts_iasl_deinit(void)
>   {
>   	int i;
>   
> -	for (i = 0; i < iasl_cached_table_file_max; i++) {
> -		if (iasl_cached_table_files[i])
> -			(void)unlink(iasl_cached_table_files[i]);
> -		iasl_cached_table_files[i] = NULL;
> -		iasl_cached_table_info[i] = NULL;
> +	for (i = 0; i < cached_max; i++) {
> +		if (iasl_cached_table_filename[i]) {
> +			(void)unlink(iasl_cached_table_filename[i]);
> +			free(iasl_cached_table_filename[i]);
> +		}
> +		iasl_cached_table_filename[i] = NULL;
> +		iasl_cached_table_name[i] = NULL;
>   	}
> -	iasl_cached_table_file_max = 0;
> +	memset(iasl_cached_table_filename, 0, sizeof(iasl_cached_table_filename));
> +	cached_max = 0;
>   }
>   
>   /*
> @@ -158,20 +132,17 @@ void fwts_iasl_deinit(void)
>    */
>   int fwts_iasl_init(fwts_framework *fw)
>   {
> -	int i;
>   	int ret;
>   
> +	cached_max = 0;
>   	fwts_iasl_deinit();	/* Ensure it is clean */
>   
> -	ret = fwts_iasl_cache_table_to_file(fw, "DSDT", 0);
> +	memset(iasl_cached_table_filename, 0, sizeof(iasl_cached_table_filename));
> +
> +	ret = fwts_iasl_cache_tables_to_file(fw);
>   	if (ret != FWTS_OK)
>   		return ret;
>   
> -	for (i = 0; i < MAX_TABLES; i++) {
> -		if (fwts_iasl_cache_table_to_file(fw, "SSDT", i) != FWTS_OK)
> -			break;
> -	}
> -
>   	iasl_init = true;
>   
>   	return FWTS_OK;
> @@ -180,34 +151,21 @@ int fwts_iasl_init(fwts_framework *fw)
>   /*
>    *  fwts_iasl_disassemble_to_file()
>    *	Disassemble a given table and dump disassembly to a file.
> - *	For tables where there are multiple matches, e.g. SSDT, we
> - *	specify the Nth table with 'which'.
>    */
>   static int fwts_iasl_disassemble_to_file(fwts_framework *fw,
> -	const char *tablename,
> -	const int which,
> +	const fwts_acpi_table_info *info,
> +	const bool use_externals,
>   	const char *filename)
>   {
> -	int i, count, n = 0;
> -
>   	if (!iasl_init)
>   		return FWTS_ERROR;
>   
> -	/* Find Nth table of a given name */
> -	count = fwts_iasl_aml_file_count();
> -	for (i = 0; i < count; i++) {
> -		if (!strcmp(tablename, iasl_cached_table_info[i]->name)) {
> -			if (n == which)
> -				break;
> -			n++;
> -		}
> -	}
> -	if (i >= count)
> -		return FWTS_NO_TABLE;
> -
>   	fwts_acpcia_set_fwts_framework(fw);
>   
> -	if (fwts_iasl_disassemble_aml(iasl_cached_table_files, iasl_cached_table_file_max, i, filename) < 0)
> +	if (fwts_iasl_disassemble_aml(
> +		iasl_cached_table_filename,
> +		iasl_cached_table_name,
> +		cached_max, info->index, use_externals, filename) < 0)
>   		return FWTS_ERROR;
>   
>   	return FWTS_OK;
> @@ -216,13 +174,11 @@ static int fwts_iasl_disassemble_to_file(fwts_framework *fw,
>   /*
>    *  fwts_iasl_disassemble()
>    *	Disassemble a given table and dump disassembly list of strings.
> - *	For tables where there are multiple matches, e.g. SSDT, we
> - *	specify the Nth table with 'which'.
>    *
>    */
>   int fwts_iasl_disassemble(fwts_framework *fw,
> -	const char *tablename,
> -	const int which,
> +	const fwts_acpi_table_info *info,
> +	const bool use_externals,
>   	fwts_list **iasl_output)
>   {
>   	char tmpfile[PATH_MAX];
> @@ -236,9 +192,11 @@ int fwts_iasl_disassemble(fwts_framework *fw,
>   
>   	*iasl_output = NULL;
>   
> -	snprintf(tmpfile, sizeof(tmpfile), "/tmp/fwts_iasl_disassemble_%d_%s.dsl", pid, tablename);
> +	snprintf(tmpfile, sizeof(tmpfile),
> +		"/tmp/fwts_iasl_disassemble_%d_%s_%d.dsl",
> +		pid, info->name, info->index);
>   
> -	if ((ret = fwts_iasl_disassemble_to_file(fw, tablename, which, tmpfile)) != FWTS_OK)
> +	if ((ret = fwts_iasl_disassemble_to_file(fw, info, use_externals, tmpfile)) != FWTS_OK)
>   		return ret;
>   
>   	*iasl_output = fwts_file_open_and_read(tmpfile);
> @@ -252,11 +210,11 @@ int fwts_iasl_disassemble(fwts_framework *fw,
>    *  fwts_iasl_disassemble_all_to_file()
>    * 	Disassemble DSDT and SSDT tables to separate files.
>    */
> -int fwts_iasl_disassemble_all_to_file(fwts_framework *fw,
> +int fwts_iasl_disassemble_all_to_file(
> +	fwts_framework *fw,
>   	const char *path)
>   {
> -	int i, n;
> -	int ret;
> +	int i, j, ret;
>   	char filename[PATH_MAX];
>   	char pathname[PATH_MAX];
>   
> @@ -270,19 +228,26 @@ int fwts_iasl_disassemble_all_to_file(fwts_framework *fw,
>   		return FWTS_ERROR;
>   	}
>   
> -	n = fwts_iasl_aml_file_count();
>   	if (path == NULL)
> -		strncpy(pathname, "", sizeof(pathname));
> +		*pathname = '\0';
>   	else
>   		snprintf(pathname, sizeof(pathname), "%s/", path);
>   
> -	for (i = 0; i < n; i++) {
> -		snprintf(filename, sizeof(filename), "%s%s%d.dsl", pathname, iasl_cached_table_info[i]->name, i);
> -		fwts_iasl_disassemble_to_file(fw, "DSDT", 0, filename);
> -		if (fwts_iasl_disassemble_aml(iasl_cached_table_files, iasl_cached_table_file_max, i, filename) < 0)
> -			fprintf(stderr, "Could not disassemble %s\n", iasl_cached_table_info[i]->name);
> -		else
> -			printf("Disassembled %s to %s\n", iasl_cached_table_info[i]->name, filename);
> +	for (i = 0, j = 0; i < cached_max; i++) {
> +		fwts_acpi_table_info *info;
> +
> +		ret = fwts_acpi_get_table(fw, i, &info);
> +		if (ret != FWTS_OK)
> +			break;
> +		if (info && info->has_aml) {
> +			snprintf(filename, sizeof(filename), "%s%s%d.dsl",
> +				pathname, info->name, j);
> +			if (fwts_iasl_disassemble_to_file(fw, info, true, filename) != FWTS_OK)
> +				fprintf(stderr, "Could not disassemble %s\n", info->name);
> +			else
> +				printf("Disassembled %s to %s\n", info->name, filename);
> +			j++;
> +		}
>   	}
>   	fwts_iasl_deinit();
>   
> @@ -291,12 +256,12 @@ int fwts_iasl_disassemble_all_to_file(fwts_framework *fw,
>   
>   /*
>    *  fwts_iasl_reassemble()
> - *	given a ACPI table in 'data', lenth 'len, go and disassemble it
> + *	given a ACPI table go and disassemble it
>    *	and re-assemble it.  Dump the disassembly into list iasl_disassembly and
>    * 	any re-assembly errors into list iasl_errors.
>    */
>   int fwts_iasl_reassemble(fwts_framework *fw,
> -	const int which,
> +	const fwts_acpi_table_info *info,
>   	fwts_list **iasl_disassembly,
>   	fwts_list **iasl_stdout,
>   	fwts_list **iasl_stderr)
> @@ -309,16 +274,17 @@ int fwts_iasl_reassemble(fwts_framework *fw,
>   	    (iasl_disassembly  == NULL) ||
>   	    (iasl_stdout == NULL) ||
>   	    (iasl_stderr == NULL) ||
> -	    (which > iasl_cached_table_file_max))
> +	    (info == NULL))
>   		return FWTS_ERROR;
>   
>   	fwts_acpcia_set_fwts_framework(fw);
> -
>   	*iasl_disassembly = NULL;
> -
>   	snprintf(tmpfile, sizeof(tmpfile), "/tmp/fwts_iasl_reassemble_%d.dsl", pid);
>   
> -	if (fwts_iasl_disassemble_aml(iasl_cached_table_files, iasl_cached_table_file_max, which, tmpfile) < 0) {
> +	if (fwts_iasl_disassemble_aml(
> +		iasl_cached_table_filename,
> +		iasl_cached_table_name,
> +		cached_max, info->index, true, tmpfile) < 0) {
>   		(void)unlink(tmpfile);
>   		return FWTS_ERROR;
>   	}

Acked-by: Colin Ian King<colin.king at canonical.com>





More information about the fwts-devel mailing list