git: f5a04b16b189 - main - acpidump: add 's' option to parse dsdt and ssdt's separately. In some machine, they may not be parsed if they are concatinated into one image.

From: Takanori Watanabe <takawata_at_FreeBSD.org>
Date: Wed, 02 Oct 2024 06:37:05 UTC
The branch main has been updated by takawata:

URL: https://cgit.FreeBSD.org/src/commit/?id=f5a04b16b1895b331d6b54534321a8395fc2d5de

commit f5a04b16b1895b331d6b54534321a8395fc2d5de
Author:     Takanori Watanabe <takawata@FreeBSD.org>
AuthorDate: 2023-06-22 10:08:21 +0000
Commit:     Takanori Watanabe <takawata@FreeBSD.org>
CommitDate: 2024-10-02 06:36:41 +0000

    acpidump: add 's' option to parse dsdt and ssdt's separately. In some machine, they may not be parsed if they are concatinated into one image.
    
    Reviewed by:           kib
    MFC after:              1 week
    Differential Revision:  https://reviews.freebsd.org/D46796
---
 usr.sbin/acpi/acpidump/acpi.c     | 16 ++++++++++++++++
 usr.sbin/acpi/acpidump/acpidump.8 | 14 +++++++++++++-
 usr.sbin/acpi/acpidump/acpidump.c | 11 +++++++++--
 usr.sbin/acpi/acpidump/acpidump.h |  1 +
 4 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/acpi/acpidump/acpi.c b/usr.sbin/acpi/acpidump/acpi.c
index af0068649fbb..fe68b5062351 100644
--- a/usr.sbin/acpi/acpidump/acpi.c
+++ b/usr.sbin/acpi/acpidump/acpi.c
@@ -2643,6 +2643,22 @@ aml_disassemble(ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp)
 		perror("rmdir");
 }
 
+void
+aml_disassemble_separate(ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp)
+{
+	ACPI_TABLE_HEADER *ssdt = NULL;
+
+	aml_disassemble(NULL, dsdp);
+	if (rsdt != NULL) {
+		for (;;) {
+			ssdt = sdt_from_rsdt(rsdt, "SSDT", ssdt);
+			if (ssdt == NULL)
+				break;
+			aml_disassemble(NULL, ssdt);
+		}
+	}
+}
+
 void
 sdt_print_all(ACPI_TABLE_HEADER *rsdp)
 {
diff --git a/usr.sbin/acpi/acpidump/acpidump.8 b/usr.sbin/acpi/acpidump/acpidump.8
index dc8f724ea738..f193b9a3511a 100644
--- a/usr.sbin/acpi/acpidump/acpidump.8
+++ b/usr.sbin/acpi/acpidump/acpidump.8
@@ -133,13 +133,25 @@ The following options are supported by
 .Nm :
 .Bl -tag -width indent
 .It Fl d
-Disassemble the DSDT into ASL using
+Concatenate the DSDT and the SSDT's into single image and disassemble the image into ASL using
 .Xr iasl 8
 and print the results to stdout.
 .It Fl t
 Dump the contents of the various fixed tables listed above.
 .It Fl h
 Displays usage and exit.
+.It Fl s
+Disassemble each of the DSDT and the SSDT's into ASL using
+.Xr iasl 8
+and print the results to stdout.
+This will avoid
+.Xr iasl 8
+error on disassembling concatenated image.
+If both
+.Fl d
+and
+.Fl s
+are specified, the last option is effective.
 .It Fl v
 Enable verbose messages.
 .It Fl f Ar dsdt_input
diff --git a/usr.sbin/acpi/acpidump/acpidump.c b/usr.sbin/acpi/acpidump/acpidump.c
index 23978aca010b..0fad7e68ef47 100644
--- a/usr.sbin/acpi/acpidump/acpidump.c
+++ b/usr.sbin/acpi/acpidump/acpidump.c
@@ -65,7 +65,7 @@ main(int argc, char *argv[])
 	if (argc < 2)
 		usage(progname);
 
-	while ((c = getopt(argc, argv, "dhtvf:o:")) != -1) {
+	while ((c = getopt(argc, argv, "dhtvsf:o:")) != -1) {
 		switch (c) {
 		case 'd':
 			dflag = 1;
@@ -82,6 +82,9 @@ main(int argc, char *argv[])
 		case 'o':
 			dsdt_output_file = optarg;
 			break;
+		case 's':
+			dflag = 2;
+			break;
 		case 'h':
 		default:
 			usage(progname);
@@ -136,7 +139,11 @@ main(int argc, char *argv[])
 	if (dflag) {
 		if (vflag)
 			warnx("disassembling DSDT, iasl messages follow");
-		aml_disassemble(rsdt, sdt);
+		if (dflag == 1) {
+			aml_disassemble(rsdt, sdt);
+		} else {
+			aml_disassemble_separate(rsdt, sdt);
+		}
 		if (vflag)
 			warnx("iasl processing complete");
 	}
diff --git a/usr.sbin/acpi/acpidump/acpidump.h b/usr.sbin/acpi/acpidump/acpidump.h
index 80f86a748d76..872facbad59d 100644
--- a/usr.sbin/acpi/acpidump/acpidump.h
+++ b/usr.sbin/acpi/acpidump/acpidump.h
@@ -144,6 +144,7 @@ void	 sdt_print_all(ACPI_TABLE_HEADER *);
 
 /* Disassemble the AML in the DSDT */
 void	 aml_disassemble(ACPI_TABLE_HEADER *, ACPI_TABLE_HEADER *);
+void	 aml_disassemble_separate(ACPI_TABLE_HEADER *, ACPI_TABLE_HEADER *);
 
 /* Routines for accessing tables in physical memory */
 ACPI_TABLE_RSDP *acpi_find_rsd_ptr(void);