Skip to contentSkip to conversation

hw/arm/virt_acpi_build: Generate DBG2 table

PATCH Superseded Eric Auger 3 participants 9 messages Sep 6, 2021 – Sep 9, 2021

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

v2 cover hw/arm/virt_acpi_build: Generate DBG2 table

This series generates the ACPI DBG2 table along with machvirt. It applies on top of Igor's
[PATCH v2 00/35] acpi: refactor error prone build_header() and packed structures usage in ACPI tables

The DBG2 specification can be found at
https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/acpi-debug-port-table.

DBG2 is mandated by ARM SBBR since its v1.0 release (the rationale behind is Windows requires it on all systems).

The DBG2 is used to describe a debug port, used by the kernel debugger.

This series and its dependency can be found at
https://github.com/eauger/qemu.git
branch: dbg2-v2-igor-v2-fix

History:
v1 -> v2:
- rebase on top of Igor's series and use acpi_init_table/acpi_table_composed and build_append_int_noprefix()

Eric Auger (3):
tests/acpi: Add void table for virt/DBG2 bios-tables-test
bios-tables-test: Generate reference table for virt/DBG2 hw/arm/virt_acpi_build: Generate DBG2 table

 hw/arm/virt-acpi-build.c  |  64 +++++++++++++++++++++++++++++++++++++-
 tests/data/acpi/virt/DBG2 | Bin 0 -> 87 bytes
 2 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 tests/data/acpi/virt/DBG2
Signature · 1 line
2.26.3
author
#1 lore raw

PATCH v2 1/3 tests/acpi: Add void table for virt/DBG2 bios-tables-test

Add placeholders for DBG2 reference table for virt tests and ignore this later for the time being.

---
 tests/data/acpi/virt/DBG2                   | 0
 tests/qtest/bios-tables-test-allowed-diff.h | 1 +
 2 files changed, 1 insertion(+)
 create mode 100644 tests/data/acpi/virt/DBG2
tests/data/acpi/virt/DBG2 new file +0 -0
new file mode 100644
index 00000000000..e69de29bb2d
tests/qtest/bios-tables-test-allowed-diff.h +1 -0
index dfb8523c8bf..1910d154c27 100644
@@ -1 +1,2 @@
 /* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/virt/DBG2",
Signature · 1 line
2.26.3
Acked-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] tests/acpi: Add void table for virt/DBG2 bios-tables-test

Quoted 2 lines · On Mon, 6 Sep 2021 14:31:37 +0200 Eric Auger <[email protected]> wrote:

Add placeholders for DBG2 reference table for virt tests and ignore this later for the time being.

s/ignore.*/ignore till reference blob is added /

Quoted 2 lines
Quoted 16 lines
---
 tests/data/acpi/virt/DBG2                   | 0
 tests/qtest/bios-tables-test-allowed-diff.h | 1 +
 2 files changed, 1 insertion(+)
 create mode 100644 tests/data/acpi/virt/DBG2
tests/data/acpi/virt/DBG2 new file +0 -0
new file mode 100644
index 00000000000..e69de29bb2d
tests/qtest/bios-tables-test-allowed-diff.h +1 -0
index dfb8523c8bf..1910d154c27 100644
@@ -1 +1,2 @@
 /* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/virt/DBG2",
author
#3 lore raw

PATCH v2 2/3 bios-tables-test: Generate reference table for virt/DBG2

In reply to Eric Auger

Add the DBG2 table generated with
tests/data/acpi/rebuild-expected-aml.sh

---

Tested by comparing the content with the table generated by EDK2 along with the SBSA-REF machine (code generated by DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c).

I reused the Generic Address Structure filled by QEMU in the SPCR, ie. bit_width = 8 and byte access. While EDK2 sets bit_width = 32 and dword access. Also the name exposed by acpica tools is different:
'COM0' in my case where '\_SB.COM0' in SBSA-REF case?

Here is the human readable content:

[000h 0000   4]                    Signature : "DBG2"    [Debug Port table type 2]
[004h 0004   4]                 Table Length : 00000057
[008h 0008   1]                     Revision : 03
[009h 0009   1]                     Checksum : C8
[00Ah 0010   6]                       Oem ID : "BOCHS "
[010h 0016   8]                 Oem Table ID : "BXPC    "
[018h 0024   4]                 Oem Revision : 00000001
[01Ch 0028   4]              Asl Compiler ID : "BXPC"
[020h 0032   4]        Asl Compiler Revision : 00000001

[024h 0036 4] Info Offset : 0000002C
[028h 0040 4] Info Count : 00000001

[02Ch 0044   1]                     Revision : 00
[02Dh 0045   2]                       Length : 002F
[02Fh 0047   1]               Register Count : 01
[030h 0048   2]              Namepath Length : 0005
[032h 0050   2]              Namepath Offset : 0026
[034h 0052   2]              OEM Data Length : 0000 [Optional field not present]
[036h 0054   2]              OEM Data Offset : 0000 [Optional field not present]
[038h 0056   2]                    Port Type : 8000
[03Ah 0058   2]                 Port Subtype : 0003
[03Ch 0060   2]                     Reserved : 0000
[03Eh 0062   2]          Base Address Offset : 0016
[040h 0064   2]          Address Size Offset : 0022

[042h 0066 12] Base Address Register : [Generic Address Structure]

[042h 0066   1]                     Space ID : 00 [SystemMemory]
[043h 0067   1]                    Bit Width : 08
[044h 0068   1]                   Bit Offset : 00
[045h 0069   1]         Encoded Access Width : 01 [Byte Access:8]
[046h 0070   8]                      Address : 0000000009000000

[04Eh 0078 4] Address Size : 00001000

[052h 0082 5] Namepath : "COM0"

---
 tests/data/acpi/virt/DBG2                   | Bin 0 -> 87 bytes
 tests/qtest/bios-tables-test-allowed-diff.h |   1 -
 2 files changed, 1 deletion(-)
tests/data/acpi/virt/DBG2 binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..895679cec0732f4109322b59b532e904885e1cca 100644
GIT binary patch
tests/qtest/bios-tables-test-allowed-diff.h +0 -1
index 1910d154c27..dfb8523c8bf 100644
@@ -1,2 +1 @@
 /* List of comma-separated changed AML files to ignore */
-"tests/data/acpi/virt/DBG2",
Signature · 1 line
2.26.3
author
#4 lore raw

PATCH v2 3/3 hw/arm/virt_acpi_build: Generate DBG2 table

In reply to Eric Auger

ARM SBBR specification mandates DBG2 table (Debug Port Table 2). this latter allows to describe one or more debug ports.

Generate an DBG2 table featuring a single debug port, the PL011.

The DBG2 specification can be found at:
https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/acpi-debug-port-table?redirectedfrom=MSDN

---
v1 -> v2:
- rebased on Igor's refactoring

---
 hw/arm/virt-acpi-build.c | 64 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)
hw/arm/virt-acpi-build.c +63 -1
index 488ea04eed7..de604e79779 100644
@@ -512,6 +512,65 @@ build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     acpi_table_composed(linker, &table);
 }
 
+/* Debug Port Table 2 (DBG2) */
+static void
+build_dbg2(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
+{
+    AcpiTable table = { .sig = "DBG2", .rev = 3, .oem_id = vms->oem_id,
+                        .oem_table_id = vms->oem_table_id };
+    int dbg2devicelength, baseaddroffset = 22, namespace_length;
+    char name[] = "COM0";
+
+    acpi_init_table(&table, table_data);
+
+    namespace_length = sizeof name;
+    dbg2devicelength = baseaddroffset +
+                       sizeof(struct AcpiGenericAddress) + 4 + namespace_length;
+
+    /* offset to the first debug struct */
+    build_append_int_noprefix(table_data, 44, 4);
+    /* number of debug device info struct entries */
+    build_append_int_noprefix(table_data, 1, 4);
+
+    /* debug device info structure */
+    /* revision */
+    build_append_int_noprefix(table_data, 0, 1);
+    /* length */
+    build_append_int_noprefix(table_data, dbg2devicelength, 2);
+    /* register count */
+    build_append_int_noprefix(table_data, 1, 1);
+    /* name path length */
+    build_append_int_noprefix(table_data, namespace_length, 2);
+    /* name path offset */
+    build_append_int_noprefix(table_data, 38, 2);
+    /* oem data length */
+    build_append_int_noprefix(table_data, 0, 2);
+    /* oem data offset (0 means no OEM data) */
+    build_append_int_noprefix(table_data, 0, 2);
+    /* port type (serial port) */
+    build_append_int_noprefix(table_data, 0x8000, 2);
+    /* port subtype (ARM PL011)*/
+    build_append_int_noprefix(table_data, 0x3, 2);
+    /* reserved */
+    build_append_int_noprefix(table_data, 0, 2);
+    /* base address offset */
+    build_append_int_noprefix(table_data, 22, 2);
+    /* address size offset */
+    build_append_int_noprefix(table_data, 34, 2);
+
+    /* BaseAddressRegister */
+    build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 8, 0, 1,
+                     vms->memmap[VIRT_UART].base);
+
+    /* AddressSize (PL011 UART length) */
+    build_append_int_noprefix(table_data, 0x1000, 4);
+
+    /* NamespaceString */
+    g_array_append_vals(table_data, name, namespace_length);
+
+    acpi_table_composed(linker, &table);
+};
+
 /*
  * ACPI spec, Revision 5.1 Errata A
  * 5.2.12 Multiple APIC Description Table (MADT)
@@ -770,7 +829,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
     dsdt = tables_blob->len;
     build_dsdt(tables_blob, tables->linker, vms);
 
-    /* FADT MADT GTDT MCFG SPCR pointed to by RSDT */
+    /* FADT MADT GTDT MCFG SPCR DBG2 pointed to by RSDT */
     acpi_add_table(table_offsets, tables_blob);
     build_fadt_rev5(tables_blob, tables->linker, vms, dsdt);
 
@@ -793,6 +852,9 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
     acpi_add_table(table_offsets, tables_blob);
     build_spcr(tables_blob, tables->linker, vms);
 
+    acpi_add_table(table_offsets, tables_blob);
+    build_dbg2(tables_blob, tables->linker, vms);
+
     if (vms->ras) {
         build_ghes_error_table(tables->hardware_errors, tables->linker);
         acpi_add_table(table_offsets, tables_blob);
Signature · 1 line
2.26.3
#5 lore raw
Quoted 1 line · On Mon, 6 Sep 2021 14:31:39 +0200 Eric Auger <[email protected]> wrote:

ARM SBBR specification mandates DBG2 table (Debug Port Table 2).

^^ revision here, and possibly a pointer [chapter]
to concrete place in spec where it's said.

Quoted 6 lines

this latter allows to describe one or more debug ports.

Generate an DBG2 table featuring a single debug port, the PL011.

The DBG2 specification can be found at:
https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/acpi-debug-port-table?redirectedfrom=MSDN

links tend to go stale, I'd use a combo of name and optionally link here:
"Microsoft Debug Port Table 2 (DBG2)"
link

Quoted 1 line

table looks correct,
so only style related thing to fix to match the common ACPI code style.

Quoted 14 lines

---
v1 -> v2:
- rebased on Igor's refactoring

---
 hw/arm/virt-acpi-build.c | 64 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)
hw/arm/virt-acpi-build.c +0 -0
index 488ea04eed7..de604e79779 100644
@@ -512,6 +512,65 @@ build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     acpi_table_composed(linker, &table);

hw/arm/virt-acpi-build.c build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 522

Quoted 10 lines
hw/arm/virt-acpi-build.c +8 -0
 }
 
+/* Debug Port Table 2 (DBG2) */
+static void
+build_dbg2(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
+{
+    AcpiTable table = { .sig = "DBG2", .rev = 3, .oem_id = vms->oem_id,
+                        .oem_table_id = vms->oem_table_id };
+    int dbg2devicelength, baseaddroffset = 22, namespace_length;
+    char name[] = "COM0";

const?

Also I'd move here:

       const int namespace_length = sizeof(name);

hw/arm/virt-acpi-build.c build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 528

Quoted 6 lines
hw/arm/virt-acpi-build.c +6 -0
+
+    acpi_init_table(&table, table_data);
+
+    namespace_length = sizeof name;
+    dbg2devicelength = baseaddroffset +
+                       sizeof(struct AcpiGenericAddress) + 4 + namespace_length;

^^^^, fragile as it's subject to alignment which depends on target

I suggest following style:

       dbg2devicelength = 22 /* BaseAddressRegister[] offset, fixed size table header */ +
                          12 /* BaseAddressRegister[] */ +
                          4 /* AddressSize[] */
                          namespace_length /* NamespaceString[] */;

       and drop 'baseaddroffset' and 'sizeof(struct AcpiGenericAddress)'
       to be more consistent with other ACPI code to annotate where lengths come from

hw/arm/virt-acpi-build.c build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 530

Quoted 1 line
hw/arm/virt-acpi-build.c +1 -0
+    /* offset to the first debug struct */

comment should be verbatim field name from spec table, i.e. in this case
/* OffsetDbgDeviceInfo */
ditto for the rest of field comments

hw/arm/virt-acpi-build.c build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 535

Quoted 5 lines
hw/arm/virt-acpi-build.c +5 -0
+    build_append_int_noprefix(table_data, 44, 4);
+    /* number of debug device info struct entries */
+    build_append_int_noprefix(table_data, 1, 4);
+
+    /* debug device info structure */

copy from spec, for ease to find it using just copy/past,

/* Table 2. Debug Device Information structure format */

Quoted 6 lines
hw/arm/virt-acpi-build.c +6 -0
+    /* revision */
+    build_append_int_noprefix(table_data, 0, 1);
+    /* length */
+    build_append_int_noprefix(table_data, dbg2devicelength, 2);
+    /* register count */
+    build_append_int_noprefix(table_data, 1, 1);

hw/arm/virt-acpi-build.c build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 551

Quoted 10 lines
hw/arm/virt-acpi-build.c +10 -0
+    /* name path length */
+    build_append_int_noprefix(table_data, namespace_length, 2);
+    /* name path offset */
+    build_append_int_noprefix(table_data, 38, 2);
+    /* oem data length */
+    build_append_int_noprefix(table_data, 0, 2);
+    /* oem data offset (0 means no OEM data) */
+    build_append_int_noprefix(table_data, 0, 2);
+    /* port type (serial port) */
+    build_append_int_noprefix(table_data, 0x8000, 2);

values could be annotated like following, using description from spec:

          build_append_int_noprefix(table_data, 0x8000 /* Serial */, 2);

hw/arm/virt-acpi-build.c build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 553

Quoted 2 lines
hw/arm/virt-acpi-build.c +2 -0
+    /* port subtype (ARM PL011)*/
+    build_append_int_noprefix(table_data, 0x3, 2);
                                             0x3 /* ARM PL011 UART */

it gives checkpatch warning but all APCI code uses this style, so it's fine

hw/arm/virt-acpi-build.c build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 566

Quoted 13 lines
hw/arm/virt-acpi-build.c +13 -0
+    /* reserved */
+    build_append_int_noprefix(table_data, 0, 2);
+    /* base address offset */
+    build_append_int_noprefix(table_data, 22, 2);
+    /* address size offset */
+    build_append_int_noprefix(table_data, 34, 2);
+
+    /* BaseAddressRegister */
+    build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 8, 0, 1,
+                     vms->memmap[VIRT_UART].base);
+
+    /* AddressSize (PL011 UART length) */
+    build_append_int_noprefix(table_data, 0x1000, 4);
                                             ^^^^

at least point out where it comes from or use macro to define value and use it here and in pl011_init()

Quoted 29 lines
hw/arm/virt-acpi-build.c +11 -1
+
+    /* NamespaceString */
+    g_array_append_vals(table_data, name, namespace_length);
+
+    acpi_table_composed(linker, &table);
+};
+
 /*
  * ACPI spec, Revision 5.1 Errata A
  * 5.2.12 Multiple APIC Description Table (MADT)
@@ -770,7 +829,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
     dsdt = tables_blob->len;
     build_dsdt(tables_blob, tables->linker, vms);
 
-    /* FADT MADT GTDT MCFG SPCR pointed to by RSDT */
+    /* FADT MADT GTDT MCFG SPCR DBG2 pointed to by RSDT */
     acpi_add_table(table_offsets, tables_blob);
     build_fadt_rev5(tables_blob, tables->linker, vms, dsdt);
 
@@ -793,6 +852,9 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
     acpi_add_table(table_offsets, tables_blob);
     build_spcr(tables_blob, tables->linker, vms);
 
+    acpi_add_table(table_offsets, tables_blob);
+    build_dbg2(tables_blob, tables->linker, vms);
+
     if (vms->ras) {
         build_ghes_error_table(tables->hardware_errors, tables->linker);
         acpi_add_table(table_offsets, tables_blob);
#6 lore raw
In reply to Eric Auger
Quoted 4 lines · On Mon, 6 Sep 2021 14:31:36 +0200 Eric Auger <[email protected]> wrote:

This series generates the ACPI DBG2 table along with machvirt. It applies on top of Igor's
[PATCH v2 00/35] acpi: refactor error prone build_header() and packed structures usage in ACPI tables

FYI: I'm preparing to post v3 today, with so far received feedback addressed. Change that will affect 3/3 is
s/acpi_init_table|acpi_table_composed/acpi_table_begin|acpi_table_end/

Quoted 17 lines

The DBG2 specification can be found at
https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/acpi-debug-port-table.

DBG2 is mandated by ARM SBBR since its v1.0 release (the rationale behind is Windows requires it on all systems).

The DBG2 is used to describe a debug port, used by the kernel debugger.

This series and its dependency can be found at
https://github.com/eauger/qemu.git
branch: dbg2-v2-igor-v2-fix

History:
v1 -> v2:
- rebase on top of Igor's series and use acpi_init_table/acpi_table_composed and build_append_int_noprefix()

Quoted 5 lines

Eric Auger (3):
tests/acpi: Add void table for virt/DBG2 bios-tables-test

bios-tables-test: Generate reference table for virt/DBG2 hw/arm/virt_acpi_build: Generate DBG2 table

I'd swap 2/3 and 3/3, so it would be obvious where DBG2 comes from.

Quoted 6 lines
 hw/arm/virt-acpi-build.c  |  64 +++++++++++++++++++++++++++++++++++++-
 tests/data/acpi/virt/DBG2 | Bin 0 -> 87 bytes
 2 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 tests/data/acpi/virt/DBG2
#7 lore raw
In reply to Eric Auger
Quoted 5 lines · Eric Auger

This series generates the ACPI DBG2 table along with machvirt. It applies on top of Igor's
[PATCH v2 00/35] acpi: refactor error prone build_header() and packed structures usage in ACPI tables

Quoted 7 lines

The DBG2 specification can be found at
https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/acpi-debug-port-table.

DBG2 is mandated by ARM SBBR since its v1.0 release (the rationale behind is Windows requires it on all systems).

The DBG2 is used to describe a debug port, used by the kernel debugger.

Hi Eric,

Did you test this in some way with a Linux guest?

Thanks,
drew

Quoted 23 lines

This series and its dependency can be found at
https://github.com/eauger/qemu.git
branch: dbg2-v2-igor-v2-fix

History:
v1 -> v2:
- rebase on top of Igor's series and use acpi_init_table/acpi_table_composed and build_append_int_noprefix()

Eric Auger (3):
tests/acpi: Add void table for virt/DBG2 bios-tables-test
bios-tables-test: Generate reference table for virt/DBG2 hw/arm/virt_acpi_build: Generate DBG2 table

 hw/arm/virt-acpi-build.c  |  64 +++++++++++++++++++++++++++++++++++++-
 tests/data/acpi/virt/DBG2 | Bin 0 -> 87 bytes
 2 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 tests/data/acpi/virt/DBG2
Signature · 1 line
2.26.3
author
#8 lore raw

Hi Drew,

Quoted 9 lines · Andrew Jones
Quoted 8 lines · Eric Auger

This series generates the ACPI DBG2 table along with machvirt. It applies on top of Igor's
[PATCH v2 00/35] acpi: refactor error prone build_header() and packed structures usage in ACPI tables

The DBG2 specification can be found at
https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/acpi-debug-port-table.

Quoted 7 lines
Quoted 4 lines

DBG2 is mandated by ARM SBBR since its v1.0 release (the rationale behind is Windows requires it on all systems).

The DBG2 is used to describe a debug port, used by the kernel debugger.

Hi Eric,

Did you test this in some way with a Linux guest?

no, I don't know how to test it functionaly. As I diff'ed against sbsa-ref generated table maybe guys using the sbsa-ref have some proper testing use case of it? Adding Hongbo and Leif in CC.

Thanks

Eric

Quoted 26 lines

Thanks,
drew

Quoted 22 lines

This series and its dependency can be found at
https://github.com/eauger/qemu.git
branch: dbg2-v2-igor-v2-fix

History:
v1 -> v2:
- rebase on top of Igor's series and use acpi_init_table/acpi_table_composed and build_append_int_noprefix()

Eric Auger (3):
tests/acpi: Add void table for virt/DBG2 bios-tables-test
bios-tables-test: Generate reference table for virt/DBG2 hw/arm/virt_acpi_build: Generate DBG2 table

 hw/arm/virt-acpi-build.c  |  64 +++++++++++++++++++++++++++++++++++++-
 tests/data/acpi/virt/DBG2 | Bin 0 -> 87 bytes
 2 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 tests/data/acpi/virt/DBG2
Signature · 1 line
2.26.3