Skip to contentSkip to conversation

acpi: Error Record Serialization Table, ERST, support for QEMU

PATCH Superseded Eric DeVolder 3 participants 21 messages Jan 26, 2022 – Jan 28, 2022 Arm/Amlogic Meson SoC support

v14 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v14 cover acpi: Error Record Serialization Table, ERST, support for QEMU

This patchset introduces support for the ACPI Error Record Serialization Table, ERST.

For background and implementation information, please see docs/specs/acpi_erst.rst, which is patch 2/10.

---
v14: 26jan2022
- Changed build_erst() to utilize a context structure for generating accesses to ACTION and VALUE, per Michael Tsirkin.
- Other simplification per Ani Sinha.

v13: 24jan2022
- v12 erroneously omitted step 6 of bios-tables-test.c, this has step 6 included.
- No other changes to v12.

v12: 10jan2022
- Converted macros in build_erst() to uppert to follow coding style, as pointed out by Michael Tsirkin.
- And few items to help further simplify build_erst().

v11: 15dec2021
- Simplified build_erst() via feedback from Michael Tsirkin
- Addressed additional feedback from Ani Sinha

v10: 9dec2021
- Addressed additional feedback from Ani Sinha

v9: 2dec2021
- Addressed feedback from Ani Sinha

v8: 15oct2021
- Added Kconfig option for ERST, per Ani Sinha
- Fixed patch ordering, per Ani

v7: 7oct2021
- style improvements, per Igor
- use of endian accessors for storage header, per Igor
- a number of optimizations and improvements, per Igor
- updated spec for header, per Igor
- updated spec for rst format, per Michael Tsirkin
- updated spec for new record_size parameter Due to changes in the spec, I am not carrying the Acked-by from Ani Sinha.
- changes for and testing of migration to systems with differing ERST_RECORD_SIZE

v6: 5aug2021
- Fixed compile warning/error, per Michael Tsirkin
- Fixed mingw32 build error, per Michael
- Converted exchange buffer to MemoryBackend, per Igor
- Migrated test to PCI, per Igor
- Significantly reduced amount of copying, per Igor
- Corrections/enhancements to acpi_erst.txt, per Igor
- Many misc/other small items, per Igor

v5: 30jun2021
- Create docs/specs/acpi_erst.txt, per Igor
- Separate PCI BARs for registers and memory, per Igor
- Convert debugging to use trace infrastructure, per Igor
- Various other fixups, per Igor

v4: 11jun2021
- Converted to a PCI device, per Igor.
- Updated qtest.
- Rearranged patches, per Igor.

v3: 28may2021
- Converted to using a TYPE_MEMORY_BACKEND_FILE object rather than internal array with explicit file operations, per Igor.
- Changed the way the qdev and base address are handled, allowing ERST to be disabled at run-time. Also aligns better with other existing code.

v2: 8feb2021
- Added qtest/smoke test per Paolo Bonzini
- Split patch into smaller chunks, per Igor Mammedov
- Did away with use of ACPI packed structures, per Igor Mammedov

v1: 26oct2020
- initial post

---

Eric DeVolder (10):
ACPI ERST: bios-tables-test.c steps 1 and 2 ACPI ERST: specification for ERST support ACPI ERST: PCI device_id for ERST
ACPI ERST: header file for ERST
ACPI ERST: support for ACPI ERST feature ACPI ERST: build the ACPI ERST table
ACPI ERST: create ACPI ERST table for pc/x86 machines ACPI ERST: qtest for ERST
ACPI ERST: bios-tables-test testcase
ACPI ERST: step 6 of bios-tables-test.c

 docs/specs/acpi_erst.rst          |  200 +++++++
 hw/acpi/Kconfig                   |    6 +
 hw/acpi/erst.c                    | 1069 +++++++++++++++++++++++++++++++++++++
 hw/acpi/meson.build               |    1 +
 hw/acpi/trace-events              |   15 +
 hw/i386/acpi-build.c              |   15 +
 hw/i386/acpi-microvm.c            |   15 +
 include/hw/acpi/erst.h            |   24 +
 include/hw/pci/pci.h              |    1 +
 tests/data/acpi/microvm/ERST.pcie |  Bin 0 -> 912 bytes
 tests/data/acpi/pc/DSDT.acpierst  |  Bin 0 -> 5969 bytes
 tests/data/acpi/pc/ERST.acpierst  |  Bin 0 -> 912 bytes
 tests/data/acpi/q35/DSDT.acpierst |  Bin 0 -> 8306 bytes
 tests/data/acpi/q35/ERST.acpierst |  Bin 0 -> 912 bytes
 tests/qtest/bios-tables-test.c    |   54 ++
 tests/qtest/erst-test.c           |  172 ++++++
 tests/qtest/meson.build           |    2 +
 17 files changed, 1574 insertions(+)
 create mode 100644 docs/specs/acpi_erst.rst
 create mode 100644 hw/acpi/erst.c
 create mode 100644 include/hw/acpi/erst.h
 create mode 100644 tests/data/acpi/microvm/ERST.pcie
 create mode 100644 tests/data/acpi/pc/DSDT.acpierst
 create mode 100644 tests/data/acpi/pc/ERST.acpierst
 create mode 100644 tests/data/acpi/q35/DSDT.acpierst
 create mode 100644 tests/data/acpi/q35/ERST.acpierst
 create mode 100644 tests/qtest/erst-test.c
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v14 3/10 ACPI ERST: PCI device_id for ERST

This change reserves the PCI device_id for the new ACPI ERST device.

---
 include/hw/pci/pci.h | 1 +
 1 file changed, 1 insertion(+)
include/hw/pci/pci.h +1 -0
index 023abc0..c3f3c90 100644
@@ -108,6 +108,7 @@ extern bool pci_available;
 #define PCI_DEVICE_ID_REDHAT_MDPY        0x000f
 #define PCI_DEVICE_ID_REDHAT_NVME        0x0010
 #define PCI_DEVICE_ID_REDHAT_PVPANIC     0x0011
+#define PCI_DEVICE_ID_REDHAT_ACPI_ERST   0x0012
 #define PCI_DEVICE_ID_REDHAT_QXL         0x0100
 
 #define FMT_PCIBUS                      PRIx64
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v14 1/10 ACPI ERST: bios-tables-test.c steps 1 and 2

In reply to Eric DeVolder

Following the guidelines in tests/qtest/bios-tables-test.c, this change adds empty placeholder files per step 1 for the new ERST table, and excludes resulting changed files in bios-tables-test-allowed-diff.h per step 2.

---
 tests/data/acpi/microvm/ERST.pcie           | 0
 tests/data/acpi/pc/DSDT.acpierst            | 0
 tests/data/acpi/pc/ERST.acpierst            | 0
 tests/data/acpi/q35/DSDT.acpierst           | 0
 tests/data/acpi/q35/ERST.acpierst           | 0
 tests/qtest/bios-tables-test-allowed-diff.h | 5 +++++
 6 files changed, 5 insertions(+)
 create mode 100644 tests/data/acpi/microvm/ERST.pcie
 create mode 100644 tests/data/acpi/pc/DSDT.acpierst
 create mode 100644 tests/data/acpi/pc/ERST.acpierst
 create mode 100644 tests/data/acpi/q35/DSDT.acpierst
 create mode 100644 tests/data/acpi/q35/ERST.acpierst
tests/data/acpi/microvm/ERST.pcie new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/data/acpi/pc/DSDT.acpierst new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/data/acpi/pc/ERST.acpierst new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/data/acpi/q35/DSDT.acpierst new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/data/acpi/q35/ERST.acpierst new file +0 -0
new file mode 100644
index 0000000..e69de29
tests/qtest/bios-tables-test-allowed-diff.h +5 -0
index dfb8523..603db07 100644
@@ -1 +1,6 @@
 /* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/pc/DSDT.acpierst",
+"tests/data/acpi/pc/ERST.acpierst",
+"tests/data/acpi/q35/DSDT.acpierst",
+"tests/data/acpi/q35/ERST.acpierst",
+"tests/data/acpi/microvm/ERST.pcie",
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v14 2/10 ACPI ERST: specification for ERST support

In reply to Eric DeVolder

Information on the implementation of the ACPI ERST support.

---
 docs/specs/acpi_erst.rst | 200 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 200 insertions(+)
 create mode 100644 docs/specs/acpi_erst.rst
docs/specs/acpi_erst.rst new file +200 -0
new file mode 100644
index 0000000..a8a9d22
@@ -0,0 +1,200 @@
+ACPI ERST DEVICE
+================
+
+The ACPI ERST device is utilized to support the ACPI Error Record
+Serialization Table, ERST, functionality. This feature is designed for
+storing error records in persistent storage for future reference
+and/or debugging.
+
+The ACPI specification[1], in Chapter "ACPI Platform Error Interfaces
+(APEI)", and specifically subsection "Error Serialization", outlines a
+method for storing error records into persistent storage.
+
+The format of error records is described in the UEFI specification[2],
+in Appendix N "Common Platform Error Record".
+
+While the ACPI specification allows for an NVRAM "mode" (see
+GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES) where non-volatile RAM is
+directly exposed for direct access by the OS/guest, this device
+implements the non-NVRAM "mode". This non-NVRAM "mode" is what is
+implemented by most BIOS (since flash memory requires programming
+operations in order to update its contents). Furthermore, as of the
+time of this writing, Linux only supports the non-NVRAM "mode".
+
+
+Background/Motivation
+---------------------
+
+Linux uses the persistent storage filesystem, pstore, to record
+information (eg. dmesg tail) upon panics and shutdowns.  Pstore is
+independent of, and runs before, kdump.  In certain scenarios (ie.
+hosts/guests with root filesystems on NFS/iSCSI where networking
+software and/or hardware fails, and thus kdump fails), pstore may
+contain information available for post-mortem debugging.
+
+Two common storage backends for the pstore filesystem are ACPI ERST
+and UEFI. Most BIOS implement ACPI ERST. UEFI is not utilized in all
+guests. With QEMU supporting ACPI ERST, it becomes a viable pstore
+storage backend for virtual machines (as it is now for bare metal
+machines).
+
+Enabling support for ACPI ERST facilitates a consistent method to
+capture kernel panic information in a wide range of guests: from
+resource-constrained microvms to very large guests, and in particular,
+in direct-boot environments (which would lack UEFI run-time services).
+
+Note that Microsoft Windows also utilizes the ACPI ERST for certain
+crash information, if available[3].
+
+
+Configuration|Usage
+-------------------
+
+To use ACPI ERST, a memory-backend-file object and acpi-erst device
+can be created, for example:
+
+ qemu ...
+ -object memory-backend-file,id=erstnvram,mem-path=acpi-erst.backing,size=0x10000,share=on \
+ -device acpi-erst,memdev=erstnvram
+
+For proper operation, the ACPI ERST device needs a memory-backend-file
+object with the following parameters:
+
+ - id: The id of the memory-backend-file object is used to associate
+   this memory with the acpi-erst device.
+ - size: The size of the ACPI ERST backing storage. This parameter is
+   required.
+ - mem-path: The location of the ACPI ERST backing storage file. This
+   parameter is also required.
+ - share: The share=on parameter is required so that updates to the
+   ERST backing store are written to the file.
+
+and ERST device:
+
+ - memdev: Is the object id of the memory-backend-file.
+ - record_size: Specifies the size of the records (or slots) in the
+   backend storage. Must be a power of two value greater than or
+   equal to 4096 (PAGE_SIZE).
+
+
+PCI Interface
+-------------
+
+The ERST device is a PCI device with two BARs, one for accessing the
+programming registers, and the other for accessing the record exchange
+buffer.
+
+BAR0 contains the programming interface consisting of ACTION and VALUE
+64-bit registers.  All ERST actions/operations/side effects happen on
+the write to the ACTION, by design. Any data needed by the action must
+be placed into VALUE prior to writing ACTION.  Reading the VALUE
+simply returns the register contents, which can be updated by a
+previous ACTION.
+
+BAR1 contains the 8KiB record exchange buffer, which is the
+implemented maximum record size.
+
+
+Backend Storage Format
+----------------------
+
+The backend storage is divided into fixed size "slots", 8KiB in
+length, with each slot storing a single record.  Not all slots need to
+be occupied, and they need not be occupied in a contiguous fashion.
+The ability to clear/erase specific records allows for the formation
+of unoccupied slots.
+
+Slot 0 contains a backend storage header that identifies the contents
+as ERST and also facilitates efficient access to the records.
+Depending upon the size of the backend storage, additional slots will
+be designated to be a part of the slot 0 header. For example, at 8KiB,
+the slot 0 header can accomodate 1021 records. Thus a storage size
+of 8MiB (8KiB * 1024) requires an additional slot for use by the
+header. In this scenario, slot 0 and slot 1 form the backend storage
+header, and records can be stored starting at slot 2.
+
+Below is an example layout of the backend storage format (for storage
+size less than 8MiB). The size of the storage is a multiple of 8KiB,
+and contains N number of slots to store records. The example below
+shows two records (in CPER format) in the backend storage, while the
+remaining slots are empty/available.
+
+::
+
+ Slot   Record
+        <------------------ 8KiB -------------------->
+        +--------------------------------------------+
+    0   | storage header                             |
+        +--------------------------------------------+
+    1   | empty/available                            |
+        +--------------------------------------------+
+    2   | CPER                                       |
+        +--------------------------------------------+
+    3   | CPER                                       |
+        +--------------------------------------------+
+  ...   |                                            |
+        +--------------------------------------------+
+    N   | empty/available                            |
+        +--------------------------------------------+
+
+The storage header consists of some basic information and an array
+of CPER record_id's to efficiently access records in the backend
+storage.
+
+All fields in the header are stored in little endian format.
+
+::
+
+  +--------------------------------------------+
+  | magic                                      | 0x0000
+  +--------------------------------------------+
+  | record_offset        | record_size         | 0x0008
+  +--------------------------------------------+
+  | record_count         | reserved | version  | 0x0010
+  +--------------------------------------------+
+  | record_id[0]                               | 0x0018
+  +--------------------------------------------+
+  | record_id[1]                               | 0x0020
+  +--------------------------------------------+
+  | record_id[...]                             |
+  +--------------------------------------------+
+  | record_id[N]                               | 0x1FF8
+  +--------------------------------------------+
+
+The 'magic' field contains the value 0x524F545354535245.
+
+The 'record_size' field contains the value 0x2000, 8KiB.
+
+The 'record_offset' field points to the first record_id in the array,
+0x0018.
+
+The 'version' field contains 0x0100, the first version.
+
+The 'record_count' field contains the number of valid records in the
+backend storage.
+
+The 'record_id' array fields are the 64-bit record identifiers of the
+CPER record in the corresponding slot. Stated differently, the
+location of a CPER record_id in the record_id[] array provides the
+slot index for the corresponding record in the backend storage.
+
+Note that, for example, with a backend storage less than 8MiB, slot 0
+contains the header, so the record_id[0] will never contain a valid
+CPER record_id. Instead slot 1 is the first available slot and thus
+record_id_[1] may contain a CPER.
+
+A 'record_id' of all 0s or all 1s indicates an invalid record (ie. the
+slot is available).
+
+
+References
+----------
+
+[1] "Advanced Configuration and Power Interface Specification",
+    version 4.0, June 2009.
+
+[2] "Unified Extensible Firmware Interface Specification",
+    version 2.1, October 2008.
+
+[3] "Windows Hardware Error Architecture", specfically
+    "Error Record Persistence Mechanism".
Signature · 1 line
1.8.3.1
#17 lore raw

PATCH v14 7/10 ACPI ERST: create ACPI ERST table for pc/x86 machines

In reply to Eric DeVolder

This change exposes ACPI ERST support for x86 guests.

---
 hw/i386/acpi-build.c   | 15 +++++++++++++++
 hw/i386/acpi-microvm.c | 15 +++++++++++++++
 include/hw/acpi/erst.h |  5 +++++
 3 files changed, 35 insertions(+)
hw/i386/acpi-build.c +15 -0
index ce823e8..ebd47aa 100644
@@ -43,6 +43,7 @@
 #include "sysemu/tpm.h"
 #include "hw/acpi/tpm.h"
 #include "hw/acpi/vmgenid.h"
+#include "hw/acpi/erst.h"
 #include "sysemu/tpm_backend.h"
 #include "hw/rtc/mc146818rtc_regs.h"
 #include "migration/vmstate.h"
@@ -74,6 +75,8 @@
 #include "hw/acpi/hmat.h"
 #include "hw/acpi/viot.h"
 
+#include CONFIG_DEVICES
+
 /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and
  * -M pc-i440fx-2.0.  Even if the actual amount of AML generated grows
  * a little bit, there should be plenty of free space since the DSDT
@@ -2575,6 +2578,18 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
                     ACPI_DEVICE_IF(x86ms->acpi_dev), x86ms->oem_id,
                     x86ms->oem_table_id);
 
+#ifdef CONFIG_ACPI_ERST
+    {
+        Object *erst_dev;
+        erst_dev = find_erst_dev();
+        if (erst_dev) {
+            acpi_add_table(table_offsets, tables_blob);
+            build_erst(tables_blob, tables->linker, erst_dev,
+                       x86ms->oem_id, x86ms->oem_table_id);
+        }
+    }
+#endif
+
     vmgenid_dev = find_vmgenid_dev();
     if (vmgenid_dev) {
         acpi_add_table(table_offsets, tables_blob);
hw/i386/acpi-microvm.c +15 -0
index 196d318..68ca7e7 100644
@@ -30,6 +30,7 @@
 #include "hw/acpi/bios-linker-loader.h"
 #include "hw/acpi/generic_event_device.h"
 #include "hw/acpi/utils.h"
+#include "hw/acpi/erst.h"
 #include "hw/i386/fw_cfg.h"
 #include "hw/i386/microvm.h"
 #include "hw/pci/pci.h"
@@ -40,6 +41,8 @@
 #include "acpi-common.h"
 #include "acpi-microvm.h"
 
+#include CONFIG_DEVICES
+
 static void acpi_dsdt_add_virtio(Aml *scope,
                                  MicrovmMachineState *mms)
 {
@@ -207,6 +210,18 @@ static void acpi_build_microvm(AcpiBuildTables *tables,
                     ACPI_DEVICE_IF(x86ms->acpi_dev), x86ms->oem_id,
                     x86ms->oem_table_id);
 
+#ifdef CONFIG_ACPI_ERST
+    {
+        Object *erst_dev;
+        erst_dev = find_erst_dev();
+        if (erst_dev) {
+            acpi_add_table(table_offsets, tables_blob);
+            build_erst(tables_blob, tables->linker, erst_dev,
+                       x86ms->oem_id, x86ms->oem_table_id);
+        }
+    }
+#endif
+
     xsdt = tables_blob->len;
     build_xsdt(tables_blob, tables->linker, table_offsets, x86ms->oem_id,
                x86ms->oem_table_id);
include/hw/acpi/erst.h +5 -0
index 9d63717..b747fe7 100644
@@ -16,4 +16,9 @@ void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
 
 #define TYPE_ACPI_ERST "acpi-erst"
 
+/* returns NULL unless there is exactly one device */
+static inline Object *find_erst_dev(void)
+{
+    return object_resolve_path_type("", TYPE_ACPI_ERST, NULL);
+}
 #endif
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v14 4/10 ACPI ERST: header file for ERST

In reply to Eric DeVolder

This change introduces the public defintions for ACPI ERST.

---
 include/hw/acpi/erst.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 include/hw/acpi/erst.h
include/hw/acpi/erst.h new file +19 -0
new file mode 100644
index 0000000..9d63717
@@ -0,0 +1,19 @@
+/*
+ * ACPI Error Record Serialization Table, ERST, Implementation
+ *
+ * ACPI ERST introduced in ACPI 4.0, June 16, 2009.
+ * ACPI Platform Error Interfaces : Error Serialization
+ *
+ * Copyright (c) 2021 Oracle and/or its affiliates.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef HW_ACPI_ERST_H
+#define HW_ACPI_ERST_H
+
+void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
+                const char *oem_id, const char *oem_table_id);
+
+#define TYPE_ACPI_ERST "acpi-erst"
+
+#endif
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v14 6/10 ACPI ERST: build the ACPI ERST table

In reply to Eric DeVolder

This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.

---
 hw/acpi/erst.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 225 insertions(+)
hw/acpi/erst.c +225 -0
index fe9ba51..5d5a639 100644
@@ -59,6 +59,27 @@
 #define STATUS_RECORD_STORE_EMPTY     0x04
 #define STATUS_RECORD_NOT_FOUND       0x05
 
+/* ACPI 4.0: Table 17-19 Serialization Instructions */
+#define INST_READ_REGISTER                 0x00
+#define INST_READ_REGISTER_VALUE           0x01
+#define INST_WRITE_REGISTER                0x02
+#define INST_WRITE_REGISTER_VALUE          0x03
+#define INST_NOOP                          0x04
+#define INST_LOAD_VAR1                     0x05
+#define INST_LOAD_VAR2                     0x06
+#define INST_STORE_VAR1                    0x07
+#define INST_ADD                           0x08
+#define INST_SUBTRACT                      0x09
+#define INST_ADD_VALUE                     0x0A
+#define INST_SUBTRACT_VALUE                0x0B
+#define INST_STALL                         0x0C
+#define INST_STALL_WHILE_TRUE              0x0D
+#define INST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E
+#define INST_GOTO                          0x0F
+#define INST_SET_SRC_ADDRESS_BASE          0x10
+#define INST_SET_DST_ADDRESS_BASE          0x11
+#define INST_MOVE_DATA                     0x12
+
 /* UEFI 2.1: Appendix N Common Platform Error Record */
 #define UEFI_CPER_RECORD_MIN_SIZE 128U
 #define UEFI_CPER_RECORD_LENGTH_OFFSET 20U
@@ -172,6 +193,210 @@ typedef struct {
 
 /*******************************************************************/
 /*******************************************************************/
+typedef struct {
+    GArray *table_data;
+    pcibus_t bar;
+    uint8_t instruction;
+    uint8_t flags;
+    uint8_t register_bit_width;
+    pcibus_t register_offset;
+} BuildSerializationInstructionEntry;
+
+/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */
+static void build_serialization_instruction(
+    BuildSerializationInstructionEntry *e,
+    uint8_t serialization_action,
+    uint64_t value)
+{
+    /* ACPI 4.0: Table 17-18 Serialization Instruction Entry */
+    struct AcpiGenericAddress gas;
+    uint64_t mask;
+
+    /* Serialization Action */
+    build_append_int_noprefix(e->table_data, serialization_action, 1);
+    /* Instruction */
+    build_append_int_noprefix(e->table_data, e->instruction, 1);
+    /* Flags */
+    build_append_int_noprefix(e->table_data, e->flags, 1);
+    /* Reserved */
+    build_append_int_noprefix(e->table_data, 0, 1);
+    /* Register Region */
+    gas.space_id = AML_SYSTEM_MEMORY;
+    gas.bit_width = e->register_bit_width;
+    gas.bit_offset = 0;
+    gas.access_width = ctz32(e->register_bit_width) - 2;
+    gas.address = (uint64_t)(e->bar + e->register_offset);
+    build_append_gas_from_struct(e->table_data, &gas);
+    /* Value */
+    build_append_int_noprefix(e->table_data, value, 8);
+    /* Mask */
+    mask = (1ULL << (e->register_bit_width - 1) << 1) - 1;
+    build_append_int_noprefix(e->table_data, mask, 8);
+}
+
+/* ACPI 4.0: 17.4.1 Serialization Action Table */
+void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
+    const char *oem_id, const char *oem_table_id)
+{
+    /*
+     * Serialization Action Table
+     * The serialization action table must be generated first
+     * so that its size can be known in order to populate the
+     * Instruction Entry Count field.
+     */
+    GArray *table_instruction_data = g_array_new(FALSE, FALSE, sizeof(char));
+    pcibus_t bar0 = pci_get_bar_addr(PCI_DEVICE(erst_dev), 0);
+    AcpiTable table = { .sig = "ERST", .rev = 1, .oem_id = oem_id,
+                        .oem_table_id = oem_table_id };
+    /* Contexts for the different ways ACTION and VALUE are accessed */
+    BuildSerializationInstructionEntry rd_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_action = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_ACTION_OFFSET,
+    };
+    unsigned action;
+
+    trace_acpi_erst_pci_bar_0(bar0);
+
+    /* Serialization Instruction Entries */
+    action = ACTION_BEGIN_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_READ_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_CLEAR_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_END_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_SET_RECORD_OFFSET;
+    build_serialization_instruction(&wr_value_32, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_EXECUTE_OPERATION;
+    build_serialization_instruction(&wr_value_32_val, action,
+        ERST_EXECUTE_OPERATION_MAGIC);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_CHECK_BUSY_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32_val, action, 0x01);
+
+    action = ACTION_GET_COMMAND_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_SET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_value_64, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_RECORD_COUNT;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    /* Serialization Header */
+    acpi_table_begin(&table, table_data);
+
+    /* Serialization Header Size */
+    build_append_int_noprefix(table_data, 48, 4);
+
+    /* Reserved */
+    build_append_int_noprefix(table_data,  0, 4);
+
+    /*
+     * Instruction Entry Count
+     * Each instruction entry is 32 bytes
+     */
+    g_assert((table_instruction_data->len) % 32 == 0);
+    build_append_int_noprefix(table_data,
+        (table_instruction_data->len / 32), 4);
+
+    /* Serialization Instruction Entries */
+    g_array_append_vals(table_data, table_instruction_data->data,
+        table_instruction_data->len);
+    g_array_free(table_instruction_data, TRUE);
+
+    acpi_table_end(linker, &table);
+}
+
+/*******************************************************************/
+/*******************************************************************/
 static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index)
 {
     uint8_t *rc = NULL;
Signature · 1 line
1.8.3.1
#19 lore raw

PATCH v14 9/10 ACPI ERST: bios-tables-test testcase

In reply to Eric DeVolder

This change implements the test suite checks for the ERST table.

---
 tests/qtest/bios-tables-test.c | 54 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
tests/qtest/bios-tables-test.c +54 -0
index e6b72d9..266b215 100644
@@ -1446,6 +1446,57 @@ static void test_acpi_piix4_tcg_acpi_hmat(void)
     test_acpi_tcg_acpi_hmat(MACHINE_PC);
 }
 
+static void test_acpi_erst(const char *machine)
+{
+    gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL);
+    gchar *params;
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = machine;
+    data.variant = ".acpierst";
+    params = g_strdup_printf(
+        " -object memory-backend-file,id=erstnvram,"
+            "mem-path=%s,size=0x10000,share=on"
+        " -device acpi-erst,memdev=erstnvram", tmp_path);
+    test_acpi_one(params, &data);
+    free_test_data(&data);
+    g_free(params);
+    g_assert(g_rmdir(tmp_path) == 0);
+    g_free(tmp_path);
+}
+
+static void test_acpi_piix4_acpi_erst(void)
+{
+    test_acpi_erst(MACHINE_PC);
+}
+
+static void test_acpi_q35_acpi_erst(void)
+{
+    test_acpi_erst(MACHINE_Q35);
+}
+
+static void test_acpi_microvm_acpi_erst(void)
+{
+    gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL);
+    gchar *params;
+    test_data data;
+
+    test_acpi_microvm_prepare(&data);
+    data.variant = ".pcie";
+    data.tcg_only = true; /* need constant host-phys-bits */
+    params = g_strdup_printf(" -machine microvm,"
+        "acpi=on,ioapic2=off,rtc=off,pcie=on"
+        " -object memory-backend-file,id=erstnvram,"
+           "mem-path=%s,size=0x10000,share=on"
+        " -device acpi-erst,memdev=erstnvram", tmp_path);
+    test_acpi_one(params, &data);
+    g_free(params);
+    g_assert(g_rmdir(tmp_path) == 0);
+    g_free(tmp_path);
+    free_test_data(&data);
+}
+
 static void test_acpi_virt_tcg(void)
 {
     test_data data = {
@@ -1675,6 +1726,8 @@ int main(int argc, char *argv[])
         qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
         qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat);
         qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat);
+        qtest_add_func("acpi/piix4/acpierst", test_acpi_piix4_acpi_erst);
+        qtest_add_func("acpi/q35/acpierst", test_acpi_q35_acpi_erst);
         qtest_add_func("acpi/microvm", test_acpi_microvm_tcg);
         qtest_add_func("acpi/microvm/usb", test_acpi_microvm_usb_tcg);
         qtest_add_func("acpi/microvm/rtc", test_acpi_microvm_rtc_tcg);
@@ -1684,6 +1737,7 @@ int main(int argc, char *argv[])
             qtest_add_func("acpi/q35/ivrs", test_acpi_q35_tcg_ivrs);
             if (strcmp(arch, "x86_64") == 0) {
                 qtest_add_func("acpi/microvm/pcie", test_acpi_microvm_pcie_tcg);
+                qtest_add_func("acpi/microvm/acpierst", test_acpi_microvm_acpi_erst);
             }
         }
         if (has_kvm) {
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v14 5/10 ACPI ERST: support for ACPI ERST feature

In reply to Eric DeVolder

This implements a PCI device for ACPI ERST. This implements the non-NVRAM "mode" of operation for ERST as it is supported by Linux and Windows.

---
 hw/acpi/Kconfig      |   6 +
 hw/acpi/erst.c       | 844 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/acpi/meson.build  |   1 +
 hw/acpi/trace-events |  15 +
 4 files changed, 866 insertions(+)
 create mode 100644 hw/acpi/erst.c
hw/acpi/Kconfig +6 -0
index 622b0b5..19caebd 100644
@@ -10,6 +10,7 @@ config ACPI_X86
     select ACPI_HMAT
     select ACPI_PIIX4
     select ACPI_PCIHP
+    select ACPI_ERST
 
 config ACPI_X86_ICH
     bool
@@ -60,3 +61,8 @@ config ACPI_HW_REDUCED
     select ACPI
     select ACPI_MEMORY_HOTPLUG
     select ACPI_NVDIMM
+
+config ACPI_ERST
+    bool
+    default y
+    depends on ACPI && PCI
hw/acpi/erst.c new file +844 -0

844 lines not on this page · raw message

hw/acpi/meson.build +1 -0
index adf6347..f5b2298 100644
@@ -22,6 +22,7 @@ acpi_ss.add(when: 'CONFIG_ACPI_PCIHP', if_true: files('pcihp.c'))
 acpi_ss.add(when: 'CONFIG_ACPI_PCIHP', if_false: files('acpi-pci-hotplug-stub.c'))
 acpi_ss.add(when: 'CONFIG_ACPI_VIOT', if_true: files('viot.c'))
 acpi_ss.add(when: 'CONFIG_ACPI_X86_ICH', if_true: files('ich9.c', 'tco.c'))
+acpi_ss.add(when: 'CONFIG_ACPI_ERST', if_true: files('erst.c'))
 acpi_ss.add(when: 'CONFIG_IPMI', if_true: files('ipmi.c'), if_false: files('ipmi-stub.c'))
 acpi_ss.add(when: 'CONFIG_PC', if_false: files('acpi-x86-stub.c'))
 acpi_ss.add(when: 'CONFIG_TPM', if_true: files('tpm.c'))
hw/acpi/trace-events +15 -0
index 974d770..2250126 100644
@@ -55,3 +55,18 @@ piix4_gpe_writeb(uint64_t addr, unsigned width, uint64_t val) "addr: 0x%" PRIx64
 # tco.c
 tco_timer_reload(int ticks, int msec) "ticks=%d (%d ms)"
 tco_timer_expired(int timeouts_no, bool strap, bool no_reboot) "timeouts_no=%d no_reboot=%d/%d"
+
+# erst.c
+acpi_erst_reg_write(uint64_t addr, uint64_t val, unsigned size) "addr: 0x%04" PRIx64 " <== 0x%016" PRIx64 " (size: %u)"
+acpi_erst_reg_read(uint64_t addr, uint64_t val, unsigned size) " addr: 0x%04" PRIx64 " ==> 0x%016" PRIx64 " (size: %u)"
+acpi_erst_mem_write(uint64_t addr, uint64_t val, unsigned size) "addr: 0x%06" PRIx64 " <== 0x%016" PRIx64 " (size: %u)"
+acpi_erst_mem_read(uint64_t addr, uint64_t val, unsigned size) " addr: 0x%06" PRIx64 " ==> 0x%016" PRIx64 " (size: %u)"
+acpi_erst_pci_bar_0(uint64_t addr) "BAR0: 0x%016" PRIx64
+acpi_erst_pci_bar_1(uint64_t addr) "BAR1: 0x%016" PRIx64
+acpi_erst_realizefn_in(void)
+acpi_erst_realizefn_out(unsigned size) "total nvram size %u bytes"
+acpi_erst_reset_in(unsigned record_count) "record_count %u"
+acpi_erst_reset_out(unsigned record_count) "record_count %u"
+acpi_erst_post_load(void *header, unsigned slot_size) "header: 0x%p slot_size %u"
+acpi_erst_class_init_in(void)
+acpi_erst_class_init_out(void)
Signature · 1 line
1.8.3.1
#18 lore raw

PATCH v14 8/10 ACPI ERST: qtest for ERST

In reply to Eric DeVolder

This change provides a qtest that locates and then does a simple interrogation of the ERST feature within the guest.

---
 tests/qtest/erst-test.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++
 tests/qtest/meson.build |   2 +
 2 files changed, 174 insertions(+)
 create mode 100644 tests/qtest/erst-test.c
tests/qtest/erst-test.c new file +172 -0
new file mode 100644
index 0000000..f9ad3c9
@@ -0,0 +1,172 @@
+/*
+ * QTest testcase for acpi-erst
+ *
+ * Copyright (c) 2021 Oracle
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include <glib/gstdio.h>
+#include "libqos/libqos-pc.h"
+#include "libqos/libqtest.h"
+#include "qemu-common.h"
+
+#include "hw/pci/pci.h"
+
+static void save_fn(QPCIDevice *dev, int devfn, void *data)
+{
+    QPCIDevice **pdev = (QPCIDevice **) data;
+
+    *pdev = dev;
+}
+
+static QPCIDevice *get_erst_device(QPCIBus *pcibus)
+{
+    QPCIDevice *dev;
+
+    dev = NULL;
+    qpci_device_foreach(pcibus,
+        PCI_VENDOR_ID_REDHAT,
+        PCI_DEVICE_ID_REDHAT_ACPI_ERST,
+        save_fn, &dev);
+    g_assert(dev != NULL);
+
+    return dev;
+}
+
+typedef struct _ERSTState {
+    QOSState *qs;
+    QPCIBar reg_bar, mem_bar;
+    uint64_t reg_barsize, mem_barsize;
+    QPCIDevice *dev;
+} ERSTState;
+
+#define ACTION 0
+#define VALUE 8
+
+static const char *reg2str(unsigned reg)
+{
+    switch (reg) {
+    case 0:
+        return "ACTION";
+    case 8:
+        return "VALUE";
+    default:
+        return NULL;
+    }
+}
+
+static inline uint32_t in_reg32(ERSTState *s, unsigned reg)
+{
+    const char *name = reg2str(reg);
+    uint32_t res;
+
+    res = qpci_io_readl(s->dev, s->reg_bar, reg);
+    g_test_message("*%s -> %08x", name, res);
+
+    return res;
+}
+
+static inline uint64_t in_reg64(ERSTState *s, unsigned reg)
+{
+    const char *name = reg2str(reg);
+    uint64_t res;
+
+    res = qpci_io_readq(s->dev, s->reg_bar, reg);
+    g_test_message("*%s -> %016llx", name, (unsigned long long)res);
+
+    return res;
+}
+
+static inline void out_reg32(ERSTState *s, unsigned reg, uint32_t v)
+{
+    const char *name = reg2str(reg);
+
+    g_test_message("%08x -> *%s", v, name);
+    qpci_io_writel(s->dev, s->reg_bar, reg, v);
+}
+
+static inline void out_reg64(ERSTState *s, unsigned reg, uint64_t v)
+{
+    const char *name = reg2str(reg);
+
+    g_test_message("%016llx -> *%s", (unsigned long long)v, name);
+    qpci_io_writeq(s->dev, s->reg_bar, reg, v);
+}
+
+static void cleanup_vm(ERSTState *s)
+{
+    g_free(s->dev);
+    qtest_shutdown(s->qs);
+}
+
+static void setup_vm_cmd(ERSTState *s, const char *cmd)
+{
+    const char *arch = qtest_get_arch();
+
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        s->qs = qtest_pc_boot(cmd);
+    } else {
+        g_printerr("erst-test tests are only available on x86\n");
+        exit(EXIT_FAILURE);
+    }
+    s->dev = get_erst_device(s->qs->pcibus);
+
+    s->reg_bar = qpci_iomap(s->dev, 0, &s->reg_barsize);
+    g_assert_cmpuint(s->reg_barsize, ==, 16);
+
+    s->mem_bar = qpci_iomap(s->dev, 1, &s->mem_barsize);
+    g_assert_cmpuint(s->mem_barsize, ==, 0x2000);
+
+    qpci_device_enable(s->dev);
+}
+
+static void test_acpi_erst_basic(void)
+{
+    ERSTState state;
+    uint64_t log_address_range;
+    uint64_t log_address_length;
+    uint32_t log_address_attr;
+
+    setup_vm_cmd(&state,
+        "-object memory-backend-file,"
+            "mem-path=acpi-erst.XXXXXX,"
+            "size=64K,"
+            "share=on,"
+            "id=nvram "
+        "-device acpi-erst,"
+            "memdev=nvram");
+
+    out_reg32(&state, ACTION, 0xD);
+    log_address_range = in_reg64(&state, VALUE);
+    out_reg32(&state, ACTION, 0xE);
+    log_address_length = in_reg64(&state, VALUE);
+    out_reg32(&state, ACTION, 0xF);
+    log_address_attr = in_reg32(&state, VALUE);
+
+    /* Check log_address_range is not 0, ~0 or base */
+    g_assert_cmpuint(log_address_range, !=,  0ULL);
+    g_assert_cmpuint(log_address_range, !=, ~0ULL);
+    g_assert_cmpuint(log_address_range, !=, state.reg_bar.addr);
+    g_assert_cmpuint(log_address_range, ==, state.mem_bar.addr);
+
+    /* Check log_address_length is bar1_size */
+    g_assert_cmpuint(log_address_length, ==, state.mem_barsize);
+
+    /* Check log_address_attr is 0 */
+    g_assert_cmpuint(log_address_attr, ==, 0);
+
+    cleanup_vm(&state);
+}
+
+int main(int argc, char **argv)
+{
+    int ret;
+
+    g_test_init(&argc, &argv, NULL);
+    qtest_add_func("/acpi-erst/basic", test_acpi_erst_basic);
+    ret = g_test_run();
+    return ret;
+}
tests/qtest/meson.build +2 -0
index 26937de..581d217 100644
@@ -68,6 +68,7 @@ qtests_i386 = \
   (config_all_devices.has_key('CONFIG_RTL8139_PCI') ? ['rtl8139-test'] : []) +              \
   (config_all_devices.has_key('CONFIG_E1000E_PCI_EXPRESS') ? ['fuzz-e1000e-test'] : []) +   \
   (config_all_devices.has_key('CONFIG_ESP_PCI') ? ['am53c974-test'] : []) +                 \
+  (config_all_devices.has_key('CONFIG_ACPI_ERST') ? ['erst-test'] : []) +                        \
   (config_all_devices.has_key('CONFIG_VIRTIO_NET') and                                      \
    config_all_devices.has_key('CONFIG_Q35') and                                             \
    config_all_devices.has_key('CONFIG_VIRTIO_PCI') and                                      \
@@ -278,6 +279,7 @@ qtests = {
   'bios-tables-test': [io, 'boot-sector.c', 'acpi-utils.c', 'tpm-emu.c'],
   'cdrom-test': files('boot-sector.c'),
   'dbus-vmstate-test': files('migration-helpers.c') + dbus_vmstate1,
+  'erst-test': files('erst-test.c'),
   'ivshmem-test': [rt, '../../contrib/ivshmem-server/ivshmem-server.c'],
   'migration-test': files('migration-helpers.c'),
   'pxe-test': files('boot-sector.c'),
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH v14 10/10 ACPI ERST: step 6 of bios-tables-test.c

In reply to Eric DeVolder

Following the guidelines in tests/qtest/bios-tables-test.c, this is step 6.

Below is the disassembly of tests/data/acpi/pc/ERST.acpierst.

/*
* Intel ACPI Component Architecture
* AML/ASL+ Disassembler version 20180508 (64-bit version)
* Copyright (c) 2000 - 2018 Intel Corporation
*
* Disassembly of tests/data/acpi/pc/ERST.acpierst, Thu Dec 2 13:32:07 2021 *
* ACPI Data Table [ERST]
*
* Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue */

 [000h 0000   4]                    Signature : "ERST"    [Error Record Serialization Table]
 [004h 0004   4]                 Table Length : 00000390
 [008h 0008   1]                     Revision : 01
 [009h 0009   1]                     Checksum : D6
 [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]  Serialization Header Length : 00000030
 [028h 0040   4]                     Reserved : 00000000
 [02Ch 0044   4]      Instruction Entry Count : 0000001B
 [030h 0048   1]                       Action : 00 [Begin Write Operation]
 [031h 0049   1]                  Instruction : 03 [Write Register Value]
 [032h 0050   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[033h 0051 1] Reserved : 00

[034h 0052 12] Register Region : [Generic Address Structure]

 [034h 0052   1]                     Space ID : 00 [SystemMemory]
 [035h 0053   1]                    Bit Width : 20
 [036h 0054   1]                   Bit Offset : 00
 [037h 0055   1]         Encoded Access Width : 03 [DWord Access:32]
 [038h 0056   8]                      Address : 00000000FEBF3000

[040h 0064 8] Value : 0000000000000000
[048h 0072 8] Mask : 00000000000000FF

 [050h 0080   1]                       Action : 01 [Begin Read Operation]
 [051h 0081   1]                  Instruction : 03 [Write Register Value]
 [052h 0082   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[053h 0083 1] Reserved : 00

[054h 0084 12] Register Region : [Generic Address Structure]

 [054h 0084   1]                     Space ID : 00 [SystemMemory]
 [055h 0085   1]                    Bit Width : 20
 [056h 0086   1]                   Bit Offset : 00
 [057h 0087   1]         Encoded Access Width : 03 [DWord Access:32]
 [058h 0088   8]                      Address : 00000000FEBF3000

[060h 0096 8] Value : 0000000000000001
[068h 0104 8] Mask : 00000000000000FF

 [070h 0112   1]                       Action : 02 [Begin Clear Operation]
 [071h 0113   1]                  Instruction : 03 [Write Register Value]
 [072h 0114   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[073h 0115 1] Reserved : 00

[074h 0116 12] Register Region : [Generic Address Structure]

 [074h 0116   1]                     Space ID : 00 [SystemMemory]
 [075h 0117   1]                    Bit Width : 20
 [076h 0118   1]                   Bit Offset : 00
 [077h 0119   1]         Encoded Access Width : 03 [DWord Access:32]
 [078h 0120   8]                      Address : 00000000FEBF3000

[080h 0128 8] Value : 0000000000000002
[088h 0136 8] Mask : 00000000000000FF

 [090h 0144   1]                       Action : 03 [End Operation]
 [091h 0145   1]                  Instruction : 03 [Write Register Value]
 [092h 0146   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[093h 0147 1] Reserved : 00

[094h 0148 12] Register Region : [Generic Address Structure]

 [094h 0148   1]                     Space ID : 00 [SystemMemory]
 [095h 0149   1]                    Bit Width : 20
 [096h 0150   1]                   Bit Offset : 00
 [097h 0151   1]         Encoded Access Width : 03 [DWord Access:32]
 [098h 0152   8]                      Address : 00000000FEBF3000

[0A0h 0160 8] Value : 0000000000000003
[0A8h 0168 8] Mask : 00000000000000FF

 [0B0h 0176   1]                       Action : 04 [Set Record Offset]
 [0B1h 0177   1]                  Instruction : 02 [Write Register]
 [0B2h 0178   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[0B3h 0179 1] Reserved : 00

[0B4h 0180 12] Register Region : [Generic Address Structure]

 [0B4h 0180   1]                     Space ID : 00 [SystemMemory]
 [0B5h 0181   1]                    Bit Width : 20
 [0B6h 0182   1]                   Bit Offset : 00
 [0B7h 0183   1]         Encoded Access Width : 03 [DWord Access:32]
 [0B8h 0184   8]                      Address : 00000000FEBF3008

[0C0h 0192 8] Value : 0000000000000000
[0C8h 0200 8] Mask : 00000000FFFFFFFF

 [0D0h 0208   1]                       Action : 04 [Set Record Offset]
 [0D1h 0209   1]                  Instruction : 03 [Write Register Value]
 [0D2h 0210   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[0D3h 0211 1] Reserved : 00

[0D4h 0212 12] Register Region : [Generic Address Structure]

 [0D4h 0212   1]                     Space ID : 00 [SystemMemory]
 [0D5h 0213   1]                    Bit Width : 20
 [0D6h 0214   1]                   Bit Offset : 00
 [0D7h 0215   1]         Encoded Access Width : 03 [DWord Access:32]
 [0D8h 0216   8]                      Address : 00000000FEBF3000

[0E0h 0224 8] Value : 0000000000000004
[0E8h 0232 8] Mask : 00000000000000FF

 [0F0h 0240   1]                       Action : 05 [Execute Operation]
 [0F1h 0241   1]                  Instruction : 03 [Write Register Value]
 [0F2h 0242   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[0F3h 0243 1] Reserved : 00

[0F4h 0244 12] Register Region : [Generic Address Structure]

 [0F4h 0244   1]                     Space ID : 00 [SystemMemory]
 [0F5h 0245   1]                    Bit Width : 20
 [0F6h 0246   1]                   Bit Offset : 00
 [0F7h 0247   1]         Encoded Access Width : 03 [DWord Access:32]
 [0F8h 0248   8]                      Address : 00000000FEBF3008

[100h 0256 8] Value : 000000000000009C
[108h 0264 8] Mask : 00000000000000FF

 [110h 0272   1]                       Action : 05 [Execute Operation]
 [111h 0273   1]                  Instruction : 03 [Write Register Value]
 [112h 0274   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[113h 0275 1] Reserved : 00

[114h 0276 12] Register Region : [Generic Address Structure]

 [114h 0276   1]                     Space ID : 00 [SystemMemory]
 [115h 0277   1]                    Bit Width : 20
 [116h 0278   1]                   Bit Offset : 00
 [117h 0279   1]         Encoded Access Width : 03 [DWord Access:32]
 [118h 0280   8]                      Address : 00000000FEBF3000

[120h 0288 8] Value : 0000000000000005
[128h 0296 8] Mask : 00000000000000FF

 [130h 0304   1]                       Action : 06 [Check Busy Status]
 [131h 0305   1]                  Instruction : 03 [Write Register Value]
 [132h 0306   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[133h 0307 1] Reserved : 00

[134h 0308 12] Register Region : [Generic Address Structure]

 [134h 0308   1]                     Space ID : 00 [SystemMemory]
 [135h 0309   1]                    Bit Width : 20
 [136h 0310   1]                   Bit Offset : 00
 [137h 0311   1]         Encoded Access Width : 03 [DWord Access:32]
 [138h 0312   8]                      Address : 00000000FEBF3000

[140h 0320 8] Value : 0000000000000006
[148h 0328 8] Mask : 00000000000000FF

 [150h 0336   1]                       Action : 06 [Check Busy Status]
 [151h 0337   1]                  Instruction : 01 [Read Register Value]
 [152h 0338   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[153h 0339 1] Reserved : 00

[154h 0340 12] Register Region : [Generic Address Structure]

 [154h 0340   1]                     Space ID : 00 [SystemMemory]
 [155h 0341   1]                    Bit Width : 20
 [156h 0342   1]                   Bit Offset : 00
 [157h 0343   1]         Encoded Access Width : 03 [DWord Access:32]
 [158h 0344   8]                      Address : 00000000FEBF3008

[160h 0352 8] Value : 0000000000000001
[168h 0360 8] Mask : 00000000000000FF

 [170h 0368   1]                       Action : 07 [Get Command Status]
 [171h 0369   1]                  Instruction : 03 [Write Register Value]
 [172h 0370   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[173h 0371 1] Reserved : 00

[174h 0372 12] Register Region : [Generic Address Structure]

 [174h 0372   1]                     Space ID : 00 [SystemMemory]
 [175h 0373   1]                    Bit Width : 20
 [176h 0374   1]                   Bit Offset : 00
 [177h 0375   1]         Encoded Access Width : 03 [DWord Access:32]
 [178h 0376   8]                      Address : 00000000FEBF3000

[180h 0384 8] Value : 0000000000000007
[188h 0392 8] Mask : 00000000000000FF

 [190h 0400   1]                       Action : 07 [Get Command Status]
 [191h 0401   1]                  Instruction : 00 [Read Register]
 [192h 0402   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[193h 0403 1] Reserved : 00

[194h 0404 12] Register Region : [Generic Address Structure]

 [194h 0404   1]                     Space ID : 00 [SystemMemory]
 [195h 0405   1]                    Bit Width : 20
 [196h 0406   1]                   Bit Offset : 00
 [197h 0407   1]         Encoded Access Width : 03 [DWord Access:32]
 [198h 0408   8]                      Address : 00000000FEBF3008

[1A0h 0416 8] Value : 0000000000000000
[1A8h 0424 8] Mask : 00000000000000FF

 [1B0h 0432   1]                       Action : 08 [Get Record Identifier]
 [1B1h 0433   1]                  Instruction : 03 [Write Register Value]
 [1B2h 0434   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[1B3h 0435 1] Reserved : 00

[1B4h 0436 12] Register Region : [Generic Address Structure]

 [1B4h 0436   1]                     Space ID : 00 [SystemMemory]
 [1B5h 0437   1]                    Bit Width : 20
 [1B6h 0438   1]                   Bit Offset : 00
 [1B7h 0439   1]         Encoded Access Width : 03 [DWord Access:32]
 [1B8h 0440   8]                      Address : 00000000FEBF3000

[1C0h 0448 8] Value : 0000000000000008
[1C8h 0456 8] Mask : 00000000000000FF

 [1D0h 0464   1]                       Action : 08 [Get Record Identifier]
 [1D1h 0465   1]                  Instruction : 00 [Read Register]
 [1D2h 0466   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[1D3h 0467 1] Reserved : 00

[1D4h 0468 12] Register Region : [Generic Address Structure]

 [1D4h 0468   1]                     Space ID : 00 [SystemMemory]
 [1D5h 0469   1]                    Bit Width : 40
 [1D6h 0470   1]                   Bit Offset : 00
 [1D7h 0471   1]         Encoded Access Width : 04 [QWord Access:64]
 [1D8h 0472   8]                      Address : 00000000FEBF3008

[1E0h 0480 8] Value : 0000000000000000
[1E8h 0488 8] Mask : FFFFFFFFFFFFFFFF

 [1F0h 0496   1]                       Action : 09 [Set Record Identifier]
 [1F1h 0497   1]                  Instruction : 02 [Write Register]
 [1F2h 0498   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[1F3h 0499 1] Reserved : 00

[1F4h 0500 12] Register Region : [Generic Address Structure]

 [1F4h 0500   1]                     Space ID : 00 [SystemMemory]
 [1F5h 0501   1]                    Bit Width : 40
 [1F6h 0502   1]                   Bit Offset : 00
 [1F7h 0503   1]         Encoded Access Width : 04 [QWord Access:64]
 [1F8h 0504   8]                      Address : 00000000FEBF3008

[200h 0512 8] Value : 0000000000000000
[208h 0520 8] Mask : FFFFFFFFFFFFFFFF

 [210h 0528   1]                       Action : 09 [Set Record Identifier]
 [211h 0529   1]                  Instruction : 03 [Write Register Value]
 [212h 0530   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[213h 0531 1] Reserved : 00

[214h 0532 12] Register Region : [Generic Address Structure]

 [214h 0532   1]                     Space ID : 00 [SystemMemory]
 [215h 0533   1]                    Bit Width : 20
 [216h 0534   1]                   Bit Offset : 00
 [217h 0535   1]         Encoded Access Width : 03 [DWord Access:32]
 [218h 0536   8]                      Address : 00000000FEBF3000

[220h 0544 8] Value : 0000000000000009
[228h 0552 8] Mask : 00000000000000FF

 [230h 0560   1]                       Action : 0A [Get Record Count]
 [231h 0561   1]                  Instruction : 03 [Write Register Value]
 [232h 0562   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[233h 0563 1] Reserved : 00

[234h 0564 12] Register Region : [Generic Address Structure]

 [234h 0564   1]                     Space ID : 00 [SystemMemory]
 [235h 0565   1]                    Bit Width : 20
 [236h 0566   1]                   Bit Offset : 00
 [237h 0567   1]         Encoded Access Width : 03 [DWord Access:32]
 [238h 0568   8]                      Address : 00000000FEBF3000

[240h 0576 8] Value : 000000000000000A
[248h 0584 8] Mask : 00000000000000FF

 [250h 0592   1]                       Action : 0A [Get Record Count]
 [251h 0593   1]                  Instruction : 00 [Read Register]
 [252h 0594   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[253h 0595 1] Reserved : 00

[254h 0596 12] Register Region : [Generic Address Structure]

 [254h 0596   1]                     Space ID : 00 [SystemMemory]
 [255h 0597   1]                    Bit Width : 20
 [256h 0598   1]                   Bit Offset : 00
 [257h 0599   1]         Encoded Access Width : 03 [DWord Access:32]
 [258h 0600   8]                      Address : 00000000FEBF3008

[260h 0608 8] Value : 0000000000000000
[268h 0616 8] Mask : 00000000FFFFFFFF

 [270h 0624   1]                       Action : 0B [Begin Dummy Write]
 [271h 0625   1]                  Instruction : 03 [Write Register Value]
 [272h 0626   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[273h 0627 1] Reserved : 00

[274h 0628 12] Register Region : [Generic Address Structure]

 [274h 0628   1]                     Space ID : 00 [SystemMemory]
 [275h 0629   1]                    Bit Width : 20
 [276h 0630   1]                   Bit Offset : 00
 [277h 0631   1]         Encoded Access Width : 03 [DWord Access:32]
 [278h 0632   8]                      Address : 00000000FEBF3000

[280h 0640 8] Value : 000000000000000B
[288h 0648 8] Mask : 00000000000000FF

 [290h 0656   1]                       Action : 0D [Get Error Address Range]
 [291h 0657   1]                  Instruction : 03 [Write Register Value]
 [292h 0658   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[293h 0659 1] Reserved : 00

[294h 0660 12] Register Region : [Generic Address Structure]

 [294h 0660   1]                     Space ID : 00 [SystemMemory]
 [295h 0661   1]                    Bit Width : 20
 [296h 0662   1]                   Bit Offset : 00
 [297h 0663   1]         Encoded Access Width : 03 [DWord Access:32]
 [298h 0664   8]                      Address : 00000000FEBF3000

[2A0h 0672 8] Value : 000000000000000D
[2A8h 0680 8] Mask : 00000000000000FF

 [2B0h 0688   1]                       Action : 0D [Get Error Address Range]
 [2B1h 0689   1]                  Instruction : 00 [Read Register]
 [2B2h 0690   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[2B3h 0691 1] Reserved : 00

[2B4h 0692 12] Register Region : [Generic Address Structure]

 [2B4h 0692   1]                     Space ID : 00 [SystemMemory]
 [2B5h 0693   1]                    Bit Width : 40
 [2B6h 0694   1]                   Bit Offset : 00
 [2B7h 0695   1]         Encoded Access Width : 04 [QWord Access:64]
 [2B8h 0696   8]                      Address : 00000000FEBF3008

[2C0h 0704 8] Value : 0000000000000000
[2C8h 0712 8] Mask : FFFFFFFFFFFFFFFF

 [2D0h 0720   1]                       Action : 0E [Get Error Address Length]
 [2D1h 0721   1]                  Instruction : 03 [Write Register Value]
 [2D2h 0722   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[2D3h 0723 1] Reserved : 00

[2D4h 0724 12] Register Region : [Generic Address Structure]

 [2D4h 0724   1]                     Space ID : 00 [SystemMemory]
 [2D5h 0725   1]                    Bit Width : 20
 [2D6h 0726   1]                   Bit Offset : 00
 [2D7h 0727   1]         Encoded Access Width : 03 [DWord Access:32]
 [2D8h 0728   8]                      Address : 00000000FEBF3000

[2E0h 0736 8] Value : 000000000000000E
[2E8h 0744 8] Mask : 00000000000000FF

 [2F0h 0752   1]                       Action : 0E [Get Error Address Length]
 [2F1h 0753   1]                  Instruction : 00 [Read Register]
 [2F2h 0754   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[2F3h 0755 1] Reserved : 00

[2F4h 0756 12] Register Region : [Generic Address Structure]

 [2F4h 0756   1]                     Space ID : 00 [SystemMemory]
 [2F5h 0757   1]                    Bit Width : 40
 [2F6h 0758   1]                   Bit Offset : 00
 [2F7h 0759   1]         Encoded Access Width : 04 [QWord Access:64]
 [2F8h 0760   8]                      Address : 00000000FEBF3008

[300h 0768 8] Value : 0000000000000000
[308h 0776 8] Mask : 00000000FFFFFFFF

 [310h 0784   1]                       Action : 0F [Get Error Attributes]
 [311h 0785   1]                  Instruction : 03 [Write Register Value]
 [312h 0786   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[313h 0787 1] Reserved : 00

[314h 0788 12] Register Region : [Generic Address Structure]

 [314h 0788   1]                     Space ID : 00 [SystemMemory]
 [315h 0789   1]                    Bit Width : 20
 [316h 0790   1]                   Bit Offset : 00
 [317h 0791   1]         Encoded Access Width : 03 [DWord Access:32]
 [318h 0792   8]                      Address : 00000000FEBF3000

[320h 0800 8] Value : 000000000000000F
[328h 0808 8] Mask : 00000000000000FF

 [330h 0816   1]                       Action : 0F [Get Error Attributes]
 [331h 0817   1]                  Instruction : 00 [Read Register]
 [332h 0818   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[333h 0819 1] Reserved : 00

[334h 0820 12] Register Region : [Generic Address Structure]

 [334h 0820   1]                     Space ID : 00 [SystemMemory]
 [335h 0821   1]                    Bit Width : 20
 [336h 0822   1]                   Bit Offset : 00
 [337h 0823   1]         Encoded Access Width : 03 [DWord Access:32]
 [338h 0824   8]                      Address : 00000000FEBF3008

[340h 0832 8] Value : 0000000000000000
[348h 0840 8] Mask : 00000000FFFFFFFF

 [350h 0848   1]                       Action : 10 [Execute Timings]
 [351h 0849   1]                  Instruction : 03 [Write Register Value]
 [352h 0850   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[353h 0851 1] Reserved : 00

[354h 0852 12] Register Region : [Generic Address Structure]

 [354h 0852   1]                     Space ID : 00 [SystemMemory]
 [355h 0853   1]                    Bit Width : 20
 [356h 0854   1]                   Bit Offset : 00
 [357h 0855   1]         Encoded Access Width : 03 [DWord Access:32]
 [358h 0856   8]                      Address : 00000000FEBF3000

[360h 0864 8] Value : 0000000000000010
[368h 0872 8] Mask : 00000000000000FF

 [370h 0880   1]                       Action : 10 [Execute Timings]
 [371h 0881   1]                  Instruction : 00 [Read Register]
 [372h 0882   1]        Flags (decoded below) : 00

Preserve Register Bits : 0
[373h 0883 1] Reserved : 00

[374h 0884 12] Register Region : [Generic Address Structure]

 [374h 0884   1]                     Space ID : 00 [SystemMemory]
 [375h 0885   1]                    Bit Width : 40
 [376h 0886   1]                   Bit Offset : 00
 [377h 0887   1]         Encoded Access Width : 04 [QWord Access:64]
 [378h 0888   8]                      Address : 00000000FEBF3008

[380h 0896 8] Value : 0000000000000000
[388h 0904 8] Mask : FFFFFFFFFFFFFFFF

Raw Table Data: Length 912 (0x390)

Note that the contents of tests/data/q35/ERST.acpierst and tests/data/microvm/ERST.pcie are the same except for differences due to assigned base address.

Files tests/data/pc/DSDT.acpierst and tests/data/acpi/q35/DSDT.acpierst are new files (and are included as a result of 'make check' process). Rather than provide the entire content, I am providing the differences between pc/DSDT and pc/DSDT.acpierst, and the difference between q35/DSDT and q35/DSDT.acpierst, with an explanation to follow.

diff pc/DSDT pc/DSDT.acpierst:
@@ -5,13 +5,13 @@
*
* Disassembling to symbolic ASL+ operators
*
- * Disassembly of tests/data/acpi/pc/DSDT, Thu Dec 2 10:10:13 2021
+ * Disassembly of tests/data/acpi/pc/DSDT.acpierst, Thu Dec 2 12:59:36 2021 *
* Original Table Header:

   *     Signature        "DSDT"
 - *     Length           0x00001772 (6002)
 + *     Length           0x00001751 (5969)
   *     Revision         0x01 **** 32-bit table (V1), no 64-bit math support
 - *     Checksum         0x9E
 + *     Checksum         0x95
   *     OEM ID           "BOCHS "
   *     OEM Table ID     "BXPC    "
   *     OEM Revision     0x00000001 (1)

@@ -964,16 +964,11 @@ DefinitionBlock ("", "DSDT", 1, "BOCHS "

              Device (S18)
              {
 -                Name (_SUN, 0x03)  // _SUN: Slot User Number
                  Name (_ADR, 0x00030000)  // _ADR: Address
 -                Method (_EJ0, 1, NotSerialized)  // _EJx: Eject Device
 -                {
 -                    PCEJ (BSEL, _SUN)
 -                }
 -
 +                Name (ASUN, 0x03)
                  Method (_DSM, 4, Serialized)  // _DSM: Device-Specific Method
                  {
 -                    Return (PDSM (Arg0, Arg1, Arg2, Arg3, BSEL, _SUN))
 +                    Return (PDSM (Arg0, Arg1, Arg2, Arg3, BSEL, ASUN))
                  }
              }

@@ -1399,11 +1394,6 @@ DefinitionBlock ("", "DSDT", 1, "BOCHS "

Method (DVNT, 2, NotSerialized)
{
- If ((Arg0 & 0x08))
- {
- Notify (S18, Arg1)
- }
-

                  If ((Arg0 & 0x10))
                  {
                      Notify (S20, Arg1)

diff q35/DSDT and q35/DSDT.acpierst:
@@ -5,13 +5,13 @@
*
* Disassembling to symbolic ASL+ operators
*
- * Disassembly of tests/data/acpi/q35/DSDT, Thu Dec 2 10:10:13 2021
+ * Disassembly of tests/data/acpi/q35/DSDT.acpierst, Thu Dec 2 12:59:36 2021 *
* Original Table Header:

   *     Signature        "DSDT"
 - *     Length           0x00002061 (8289)
 + *     Length           0x00002072 (8306)
   *     Revision         0x01 **** 32-bit table (V1), no 64-bit math support
 - *     Checksum         0xFA
 + *     Checksum         0x9A
   *     OEM ID           "BOCHS "
   *     OEM Table ID     "BXPC    "
   *     OEM Revision     0x00000001 (1)
 @@ -3278,6 +3278,11 @@ DefinitionBlock ("", "DSDT", 1, "BOCHS "
                  }
              }

+ Device (S10)
+ {
+ Name (_ADR, 0x00020000) // _ADR: Address
+ }
+

              Method (PCNT, 0, NotSerialized)
              {
              }

For both pc and q35, there is but a small difference between this DSDT.acpierst and the corresponding DSDT. In both cases, the changes occur under the hiearchy:

    Scope (\_SB)
    {
        Scope (PCI0)
        {

which leads me to believe that the change to the DSDT was needed due to the introduction of the ERST PCI device.

And is explained in detail by Ani Sinha:
I have convinced myself of the changes we see in the DSDT tables. On i440fx side, we are adding a non-hotpluggable pci device on slot 3. So the changes we see are basically replacing an empty hotpluggable slot on the pci root port with a non-hotplugggable device. On q35, bsel on pcie root bus is not set (its not hotpluggable bus), so the change basically adds the address enumeration for the device.

---
 tests/data/acpi/microvm/ERST.pcie           | Bin 0 -> 912 bytes
 tests/data/acpi/pc/DSDT.acpierst            | Bin 0 -> 5969 bytes
 tests/data/acpi/pc/ERST.acpierst            | Bin 0 -> 912 bytes
 tests/data/acpi/q35/DSDT.acpierst           | Bin 0 -> 8306 bytes
 tests/data/acpi/q35/ERST.acpierst           | Bin 0 -> 912 bytes
 tests/qtest/bios-tables-test-allowed-diff.h |   5 -----
 6 files changed, 5 deletions(-)
tests/data/acpi/microvm/ERST.pcie binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a6d0cb783831ebc18972ec57bb6c624438ff150d 100644
GIT binary patch
tests/data/acpi/pc/DSDT.acpierst binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..bb0593eeb8730d51a6f0fe51a00a00df9c83c419 100644
GIT binary patch
tests/data/acpi/pc/ERST.acpierst binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..7965ac2562e7b23bf1dc2caaf00ef66453c4f47a 100644
GIT binary patch
tests/data/acpi/q35/DSDT.acpierst binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..cad26e3f0c27a40a33101155a5282ed9bcb1d441 100644
GIT binary patch
tests/data/acpi/q35/ERST.acpierst binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..7965ac2562e7b23bf1dc2caaf00ef66453c4f47a 100644
GIT binary patch
tests/qtest/bios-tables-test-allowed-diff.h +0 -5
index 603db07..dfb8523 100644
@@ -1,6 +1 @@
 /* List of comma-separated changed AML files to ignore */
-"tests/data/acpi/pc/DSDT.acpierst",
-"tests/data/acpi/pc/ERST.acpierst",
-"tests/data/acpi/q35/DSDT.acpierst",
-"tests/data/acpi/q35/ERST.acpierst",
-"tests/data/acpi/microvm/ERST.pcie",
Signature · 1 line
1.8.3.1
Reviewed-by on v14 6/10
#7 lore raw

Re: [PATCH v14 06/10] ACPI ERST: build the ACPI ERST table

In reply to Eric DeVolder
Quoted 2 lines · Eric DeVolder

This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.

There might be more optimizations possible but I think we have messaged this code enough. We can further rework the code if needed in subsequent patches once this is pushed.

Quoted 2 lines

with some minor comments,

Quoted 61 lines
 hw/acpi/erst.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 225 insertions(+)
hw/acpi/erst.c +43 -0
index fe9ba51..5d5a639 100644
@@ -59,6 +59,27 @@
 #define STATUS_RECORD_STORE_EMPTY     0x04
 #define STATUS_RECORD_NOT_FOUND       0x05
 
+/* ACPI 4.0: Table 17-19 Serialization Instructions */
+#define INST_READ_REGISTER                 0x00
+#define INST_READ_REGISTER_VALUE           0x01
+#define INST_WRITE_REGISTER                0x02
+#define INST_WRITE_REGISTER_VALUE          0x03
+#define INST_NOOP                          0x04
+#define INST_LOAD_VAR1                     0x05
+#define INST_LOAD_VAR2                     0x06
+#define INST_STORE_VAR1                    0x07
+#define INST_ADD                           0x08
+#define INST_SUBTRACT                      0x09
+#define INST_ADD_VALUE                     0x0A
+#define INST_SUBTRACT_VALUE                0x0B
+#define INST_STALL                         0x0C
+#define INST_STALL_WHILE_TRUE              0x0D
+#define INST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E
+#define INST_GOTO                          0x0F
+#define INST_SET_SRC_ADDRESS_BASE          0x10
+#define INST_SET_DST_ADDRESS_BASE          0x11
+#define INST_MOVE_DATA                     0x12
+
 /* UEFI 2.1: Appendix N Common Platform Error Record */
 #define UEFI_CPER_RECORD_MIN_SIZE 128U
 #define UEFI_CPER_RECORD_LENGTH_OFFSET 20U
@@ -172,6 +193,210 @@ typedef struct {
 
 /*******************************************************************/
 /*******************************************************************/
+typedef struct {
+    GArray *table_data;
+    pcibus_t bar;
+    uint8_t instruction;
+    uint8_t flags;
+    uint8_t register_bit_width;
+    pcibus_t register_offset;
+} BuildSerializationInstructionEntry;
+
+/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */
+static void build_serialization_instruction(
+    BuildSerializationInstructionEntry *e,
+    uint8_t serialization_action,
+    uint64_t value)
+{
+    /* ACPI 4.0: Table 17-18 Serialization Instruction Entry */
+    struct AcpiGenericAddress gas;
+    uint64_t mask;
+
+    /* Serialization Action */
+    build_append_int_noprefix(e->table_data, serialization_action, 1);
+    /* Instruction */

hw/acpi/erst.c typedef struct { · line 227

Quoted 10 lines
hw/acpi/erst.c +10 -0
+    build_append_int_noprefix(e->table_data, e->instruction, 1);
+    /* Flags */
+    build_append_int_noprefix(e->table_data, e->flags, 1);
+    /* Reserved */
+    build_append_int_noprefix(e->table_data, 0, 1);
+    /* Register Region */
+    gas.space_id = AML_SYSTEM_MEMORY;
+    gas.bit_width = e->register_bit_width;
+    gas.bit_offset = 0;
+    gas.access_width = ctz32(e->register_bit_width) - 2;

Should this be casted as unit8_t?

Quoted 70 lines
hw/acpi/erst.c +70 -0
+    gas.address = (uint64_t)(e->bar + e->register_offset);
+    build_append_gas_from_struct(e->table_data, &gas);
+    /* Value */
+    build_append_int_noprefix(e->table_data, value, 8);
+    /* Mask */
+    mask = (1ULL << (e->register_bit_width - 1) << 1) - 1;
+    build_append_int_noprefix(e->table_data, mask, 8);
+}
+
+/* ACPI 4.0: 17.4.1 Serialization Action Table */
+void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
+    const char *oem_id, const char *oem_table_id)
+{
+    /*
+     * Serialization Action Table
+     * The serialization action table must be generated first
+     * so that its size can be known in order to populate the
+     * Instruction Entry Count field.
+     */
+    GArray *table_instruction_data = g_array_new(FALSE, FALSE, sizeof(char));
+    pcibus_t bar0 = pci_get_bar_addr(PCI_DEVICE(erst_dev), 0);
+    AcpiTable table = { .sig = "ERST", .rev = 1, .oem_id = oem_id,
+                        .oem_table_id = oem_table_id };
+    /* Contexts for the different ways ACTION and VALUE are accessed */
+    BuildSerializationInstructionEntry rd_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,

hw/acpi/erst.c typedef struct { · line 307

Quoted 10 lines
hw/acpi/erst.c +10 -0
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_action = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_ACTION_OFFSET,
+    };

We can probably write a macro to simply generating these structs. I see .bar and .flags are the same in all structs. The .bit_width can be a param into the macro etc.

Quoted 99 lines
hw/acpi/erst.c +92 -1
+    unsigned action;
+
+    trace_acpi_erst_pci_bar_0(bar0);
+
+    /* Serialization Instruction Entries */
+    action = ACTION_BEGIN_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_READ_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_CLEAR_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_END_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_SET_RECORD_OFFSET;
+    build_serialization_instruction(&wr_value_32, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_EXECUTE_OPERATION;
+    build_serialization_instruction(&wr_value_32_val, action,
+        ERST_EXECUTE_OPERATION_MAGIC);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_CHECK_BUSY_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32_val, action, 0x01);
+
+    action = ACTION_GET_COMMAND_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_SET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_value_64, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_RECORD_COUNT;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    /* Serialization Header */
+    acpi_table_begin(&table, table_data);
+
+    /* Serialization Header Size */
+    build_append_int_noprefix(table_data, 48, 4);
+
+    /* Reserved */
+    build_append_int_noprefix(table_data,  0, 4);
+
+    /*
+     * Instruction Entry Count
+     * Each instruction entry is 32 bytes
+     */
+    g_assert((table_instruction_data->len) % 32 == 0);
+    build_append_int_noprefix(table_data,
+        (table_instruction_data->len / 32), 4);
+
+    /* Serialization Instruction Entries */
+    g_array_append_vals(table_data, table_instruction_data->data,
+        table_instruction_data->len);
+    g_array_free(table_instruction_data, TRUE);
+
+    acpi_table_end(linker, &table);
+}
+
+/*******************************************************************/
+/*******************************************************************/
 static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index)
 {
     uint8_t *rc = NULL;
--

1.8.3.1

#8 lore raw

Re: [PATCH v14 06/10] ACPI ERST: build the ACPI ERST table

Ani,
Thanks for the RB! Inline responses below.
eric

Quoted 83 lines · Ani Sinha
Quoted 2 lines · Eric DeVolder

This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.

There might be more optimizations possible but I think we have messaged this code enough. We can further rework the code if needed in subsequent patches once this is pushed.

Quoted 2 lines

with some minor comments,

Quoted 65 lines
  hw/acpi/erst.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 225 insertions(+)
hw/acpi/erst.c +47 -0
index fe9ba51..5d5a639 100644
@@ -59,6 +59,27 @@
  #define STATUS_RECORD_STORE_EMPTY     0x04
  #define STATUS_RECORD_NOT_FOUND       0x05
 
+/* ACPI 4.0: Table 17-19 Serialization Instructions */
+#define INST_READ_REGISTER                 0x00
+#define INST_READ_REGISTER_VALUE           0x01
+#define INST_WRITE_REGISTER                0x02
+#define INST_WRITE_REGISTER_VALUE          0x03
+#define INST_NOOP                          0x04
+#define INST_LOAD_VAR1                     0x05
+#define INST_LOAD_VAR2                     0x06
+#define INST_STORE_VAR1                    0x07
+#define INST_ADD                           0x08
+#define INST_SUBTRACT                      0x09
+#define INST_ADD_VALUE                     0x0A
+#define INST_SUBTRACT_VALUE                0x0B
+#define INST_STALL                         0x0C
+#define INST_STALL_WHILE_TRUE              0x0D
+#define INST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E
+#define INST_GOTO                          0x0F
+#define INST_SET_SRC_ADDRESS_BASE          0x10
+#define INST_SET_DST_ADDRESS_BASE          0x11
+#define INST_MOVE_DATA                     0x12
+
  /* UEFI 2.1: Appendix N Common Platform Error Record */
  #define UEFI_CPER_RECORD_MIN_SIZE 128U
  #define UEFI_CPER_RECORD_LENGTH_OFFSET 20U
@@ -172,6 +193,210 @@ typedef struct {
 
  /*******************************************************************/
  /*******************************************************************/
+typedef struct {
+    GArray *table_data;
+    pcibus_t bar;
+    uint8_t instruction;
+    uint8_t flags;
+    uint8_t register_bit_width;
+    pcibus_t register_offset;
+} BuildSerializationInstructionEntry;
+
+/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */
+static void build_serialization_instruction(
+    BuildSerializationInstructionEntry *e,
+    uint8_t serialization_action,
+    uint64_t value)
+{
+    /* ACPI 4.0: Table 17-18 Serialization Instruction Entry */
+    struct AcpiGenericAddress gas;
+    uint64_t mask;
+
+    /* Serialization Action */
+    build_append_int_noprefix(e->table_data, serialization_action, 1);
+    /* Instruction */
+    build_append_int_noprefix(e->table_data, e->instruction, 1);
+    /* Flags */
+    build_append_int_noprefix(e->table_data, e->flags, 1);
+    /* Reserved */
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 227

Quoted 6 lines
hw/acpi/erst.c +6 -0
+    build_append_int_noprefix(e->table_data, 0, 1);
+    /* Register Region */
+    gas.space_id = AML_SYSTEM_MEMORY;
+    gas.bit_width = e->register_bit_width;
+    gas.bit_offset = 0;
+    gas.access_width = ctz32(e->register_bit_width) - 2;

Should this be casted as unit8_t?

OK, done.

Quoted 77 lines
Quoted 77 lines
hw/acpi/erst.c +76 -0
+    gas.address = (uint64_t)(e->bar + e->register_offset);
+    build_append_gas_from_struct(e->table_data, &gas);
+    /* Value */
+    build_append_int_noprefix(e->table_data, value, 8);
+    /* Mask */
+    mask = (1ULL << (e->register_bit_width - 1) << 1) - 1;
+    build_append_int_noprefix(e->table_data, mask, 8);
+}
+
+/* ACPI 4.0: 17.4.1 Serialization Action Table */
+void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
+    const char *oem_id, const char *oem_table_id)
+{
+    /*
+     * Serialization Action Table
+     * The serialization action table must be generated first
+     * so that its size can be known in order to populate the
+     * Instruction Entry Count field.
+     */
+    GArray *table_instruction_data = g_array_new(FALSE, FALSE, sizeof(char));
+    pcibus_t bar0 = pci_get_bar_addr(PCI_DEVICE(erst_dev), 0);
+    AcpiTable table = { .sig = "ERST", .rev = 1, .oem_id = oem_id,
+                        .oem_table_id = oem_table_id };
+    /* Contexts for the different ways ACTION and VALUE are accessed */
+    BuildSerializationInstructionEntry rd_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_action = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 307

Quoted 4 lines
hw/acpi/erst.c +4 -0
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_ACTION_OFFSET,
+    };

We can probably write a macro to simply generating these structs. I see .bar and .flags are the same in all structs. The .bit_width can be a param into the macro etc.

Agree, however the request was to NOT hide the use of local variables in macros, so while .flags is always 0, .instruction, .register_bit_width and .register_offset would be parameters, that leaves .table_data and .bar which just need the local variables. Is the following acceptable (which hides the use of the local variables)?

#define SERIALIZATIONINSTRUCTIONCTX(name, \
    inst, bit_width, offset) \
    BuildSerializationInstructionEntry name = { \
        .table_data = table_instruction_data, \
        .bar = bar0, \
        .instruction = inst, \
        .flags = 0, \
        .register_bit_width = bit_width, \
        .register_offset = offset, \
    }
    SERIALIZATIONINSTRUCTIONCTX(rd_value_32_val,
        INST_READ_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(rd_value_32,
        INST_READ_REGISTER, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(rd_value_64,
        INST_READ_REGISTER, 64, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_value_32_val,
        INST_WRITE_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_value_32,
        INST_WRITE_REGISTER, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_value_64,
        INST_WRITE_REGISTER, 64, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_action,
        INST_WRITE_REGISTER_VALUE, 32, ERST_ACTION_OFFSET);

These are the 7 accessors needed.

Quoted 100 lines
Quoted 100 lines
hw/acpi/erst.c +92 -1
+    unsigned action;
+
+    trace_acpi_erst_pci_bar_0(bar0);
+
+    /* Serialization Instruction Entries */
+    action = ACTION_BEGIN_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_READ_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_CLEAR_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_END_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_SET_RECORD_OFFSET;
+    build_serialization_instruction(&wr_value_32, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_EXECUTE_OPERATION;
+    build_serialization_instruction(&wr_value_32_val, action,
+        ERST_EXECUTE_OPERATION_MAGIC);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_CHECK_BUSY_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32_val, action, 0x01);
+
+    action = ACTION_GET_COMMAND_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_SET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_value_64, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_RECORD_COUNT;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    /* Serialization Header */
+    acpi_table_begin(&table, table_data);
+
+    /* Serialization Header Size */
+    build_append_int_noprefix(table_data, 48, 4);
+
+    /* Reserved */
+    build_append_int_noprefix(table_data,  0, 4);
+
+    /*
+     * Instruction Entry Count
+     * Each instruction entry is 32 bytes
+     */
+    g_assert((table_instruction_data->len) % 32 == 0);
+    build_append_int_noprefix(table_data,
+        (table_instruction_data->len / 32), 4);
+
+    /* Serialization Instruction Entries */
+    g_array_append_vals(table_data, table_instruction_data->data,
+        table_instruction_data->len);
+    g_array_free(table_instruction_data, TRUE);
+
+    acpi_table_end(linker, &table);
+}
+
+/*******************************************************************/
+/*******************************************************************/
  static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index)
  {
      uint8_t *rc = NULL;
--

1.8.3.1

#9 lore raw

Re: [PATCH v14 06/10] ACPI ERST: build the ACPI ERST table

Quoted 183 lines · Eric DeVolder

Ani,
Thanks for the RB! Inline responses below.
eric

Quoted 83 lines · Ani Sinha
Quoted 2 lines · Eric DeVolder

This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.

There might be more optimizations possible but I think we have messaged this code enough. We can further rework the code if needed in subsequent patches once this is pushed.

Quoted 2 lines

with some minor comments,

Quoted 65 lines
  hw/acpi/erst.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 225 insertions(+)
hw/acpi/erst.c +47 -0
index fe9ba51..5d5a639 100644
@@ -59,6 +59,27 @@
  #define STATUS_RECORD_STORE_EMPTY     0x04
  #define STATUS_RECORD_NOT_FOUND       0x05
 
+/* ACPI 4.0: Table 17-19 Serialization Instructions */
+#define INST_READ_REGISTER                 0x00
+#define INST_READ_REGISTER_VALUE           0x01
+#define INST_WRITE_REGISTER                0x02
+#define INST_WRITE_REGISTER_VALUE          0x03
+#define INST_NOOP                          0x04
+#define INST_LOAD_VAR1                     0x05
+#define INST_LOAD_VAR2                     0x06
+#define INST_STORE_VAR1                    0x07
+#define INST_ADD                           0x08
+#define INST_SUBTRACT                      0x09
+#define INST_ADD_VALUE                     0x0A
+#define INST_SUBTRACT_VALUE                0x0B
+#define INST_STALL                         0x0C
+#define INST_STALL_WHILE_TRUE              0x0D
+#define INST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E
+#define INST_GOTO                          0x0F
+#define INST_SET_SRC_ADDRESS_BASE          0x10
+#define INST_SET_DST_ADDRESS_BASE          0x11
+#define INST_MOVE_DATA                     0x12
+
  /* UEFI 2.1: Appendix N Common Platform Error Record */
  #define UEFI_CPER_RECORD_MIN_SIZE 128U
  #define UEFI_CPER_RECORD_LENGTH_OFFSET 20U
@@ -172,6 +193,210 @@ typedef struct {
 
  /*******************************************************************/
  /*******************************************************************/
+typedef struct {
+    GArray *table_data;
+    pcibus_t bar;
+    uint8_t instruction;
+    uint8_t flags;
+    uint8_t register_bit_width;
+    pcibus_t register_offset;
+} BuildSerializationInstructionEntry;
+
+/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */
+static void build_serialization_instruction(
+    BuildSerializationInstructionEntry *e,
+    uint8_t serialization_action,
+    uint64_t value)
+{
+    /* ACPI 4.0: Table 17-18 Serialization Instruction Entry */
+    struct AcpiGenericAddress gas;
+    uint64_t mask;
+
+    /* Serialization Action */
+    build_append_int_noprefix(e->table_data, serialization_action, 1);
+    /* Instruction */
+    build_append_int_noprefix(e->table_data, e->instruction, 1);
+    /* Flags */
+    build_append_int_noprefix(e->table_data, e->flags, 1);
+    /* Reserved */
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 227

Quoted 6 lines
hw/acpi/erst.c +6 -0
+    build_append_int_noprefix(e->table_data, 0, 1);
+    /* Register Region */
+    gas.space_id = AML_SYSTEM_MEMORY;
+    gas.bit_width = e->register_bit_width;
+    gas.bit_offset = 0;
+    gas.access_width = ctz32(e->register_bit_width) - 2;

Should this be casted as unit8_t?

OK, done.

Quoted 77 lines
Quoted 77 lines
hw/acpi/erst.c +76 -0
+    gas.address = (uint64_t)(e->bar + e->register_offset);
+    build_append_gas_from_struct(e->table_data, &gas);
+    /* Value */
+    build_append_int_noprefix(e->table_data, value, 8);
+    /* Mask */
+    mask = (1ULL << (e->register_bit_width - 1) << 1) - 1;
+    build_append_int_noprefix(e->table_data, mask, 8);
+}
+
+/* ACPI 4.0: 17.4.1 Serialization Action Table */
+void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
+    const char *oem_id, const char *oem_table_id)
+{
+    /*
+     * Serialization Action Table
+     * The serialization action table must be generated first
+     * so that its size can be known in order to populate the
+     * Instruction Entry Count field.
+     */
+    GArray *table_instruction_data = g_array_new(FALSE, FALSE, sizeof(char));
+    pcibus_t bar0 = pci_get_bar_addr(PCI_DEVICE(erst_dev), 0);
+    AcpiTable table = { .sig = "ERST", .rev = 1, .oem_id = oem_id,
+                        .oem_table_id = oem_table_id };
+    /* Contexts for the different ways ACTION and VALUE are accessed */
+    BuildSerializationInstructionEntry rd_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_action = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 307

Quoted 4 lines
hw/acpi/erst.c +4 -0
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_ACTION_OFFSET,
+    };

We can probably write a macro to simply generating these structs. I see .bar and .flags are the same in all structs. The .bit_width can be a param into the macro etc.

Quoted 4 lines

Agree, however the request was to NOT hide the use of local variables in macros, so while .flags is always 0, .instruction, .register_bit_width and .register_offset would be parameters, that leaves .table_data and .bar which just need the local variables. Is the following acceptable (which hides the use of the local variables)?

You can just use assignment:

   BuildSerializationInstructionEntry entry = {
       .table_data = table_instruction_data,
       .bar = bar0,
       .flags = 0,
       .register_bit_width = 32,
   };
   BuildSerializationInstructionEntry rd_value_32_val = entry;
   rd_value_32_val.action = INST_READ_REGISTER_VALUE;
   rd_value_32_val.register_offset = ERST_ACTION_OFFSET;

and so on.
not sure it's worth it, it's just a couple of lines.

Quoted 25 lines
#define SERIALIZATIONINSTRUCTIONCTX(name, \
    inst, bit_width, offset) \
    BuildSerializationInstructionEntry name = { \
        .table_data = table_instruction_data, \
        .bar = bar0, \
        .instruction = inst, \
        .flags = 0, \
        .register_bit_width = bit_width, \
        .register_offset = offset, \
    }
    SERIALIZATIONINSTRUCTIONCTX(rd_value_32_val,
        INST_READ_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(rd_value_32,
        INST_READ_REGISTER, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(rd_value_64,
        INST_READ_REGISTER, 64, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_value_32_val,
        INST_WRITE_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_value_32,
        INST_WRITE_REGISTER, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_value_64,
        INST_WRITE_REGISTER, 64, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_action,
        INST_WRITE_REGISTER_VALUE, 32, ERST_ACTION_OFFSET);
Quoted 1 line

These are the 7 accessors needed.

not at all sure this one is worth the macro mess.

Quoted 100 lines
Quoted 100 lines
Quoted 100 lines
hw/acpi/erst.c +92 -1
+    unsigned action;
+
+    trace_acpi_erst_pci_bar_0(bar0);
+
+    /* Serialization Instruction Entries */
+    action = ACTION_BEGIN_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_READ_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_CLEAR_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_END_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_SET_RECORD_OFFSET;
+    build_serialization_instruction(&wr_value_32, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_EXECUTE_OPERATION;
+    build_serialization_instruction(&wr_value_32_val, action,
+        ERST_EXECUTE_OPERATION_MAGIC);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_CHECK_BUSY_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32_val, action, 0x01);
+
+    action = ACTION_GET_COMMAND_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_SET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_value_64, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_RECORD_COUNT;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    /* Serialization Header */
+    acpi_table_begin(&table, table_data);
+
+    /* Serialization Header Size */
+    build_append_int_noprefix(table_data, 48, 4);
+
+    /* Reserved */
+    build_append_int_noprefix(table_data,  0, 4);
+
+    /*
+     * Instruction Entry Count
+     * Each instruction entry is 32 bytes
+     */
+    g_assert((table_instruction_data->len) % 32 == 0);
+    build_append_int_noprefix(table_data,
+        (table_instruction_data->len / 32), 4);
+
+    /* Serialization Instruction Entries */
+    g_array_append_vals(table_data, table_instruction_data->data,
+        table_instruction_data->len);
+    g_array_free(table_instruction_data, TRUE);
+
+    acpi_table_end(linker, &table);
+}
+
+/*******************************************************************/
+/*******************************************************************/
  static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index)
  {
      uint8_t *rc = NULL;
--

1.8.3.1

#10 lore raw

Re: [PATCH v14 06/10] ACPI ERST: build the ACPI ERST table

Quoted 25 lines
Quoted 25 lines
#define SERIALIZATIONINSTRUCTIONCTX(name, \
    inst, bit_width, offset) \
    BuildSerializationInstructionEntry name = { \
        .table_data = table_instruction_data, \
        .bar = bar0, \
        .instruction = inst, \
        .flags = 0, \
        .register_bit_width = bit_width, \
        .register_offset = offset, \
    }
    SERIALIZATIONINSTRUCTIONCTX(rd_value_32_val,
        INST_READ_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(rd_value_32,
        INST_READ_REGISTER, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(rd_value_64,
        INST_READ_REGISTER, 64, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_value_32_val,
        INST_WRITE_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_value_32,
        INST_WRITE_REGISTER, 32, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_value_64,
        INST_WRITE_REGISTER, 64, ERST_VALUE_OFFSET);
    SERIALIZATIONINSTRUCTIONCTX(wr_action,
        INST_WRITE_REGISTER_VALUE, 32, ERST_ACTION_OFFSET);
Quoted 4 lines
Quoted 1 line

These are the 7 accessors needed.

not at all sure this one is worth the macro mess.

I did not quite have this in my mind when I said macro but it's fine. We can improve the code later.

#11 lore raw

Re: [PATCH v14 06/10] ACPI ERST: build the ACPI ERST table

In reply to Michael S. Tsirkin

Michael,
Thanks for examining this. Inline response below.
eric

Quoted 201 lines · Michael S. Tsirkin
Quoted 183 lines · Eric DeVolder

Ani,
Thanks for the RB! Inline responses below.
eric

Quoted 83 lines · Ani Sinha
Quoted 2 lines · Eric DeVolder

This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.

There might be more optimizations possible but I think we have messaged this code enough. We can further rework the code if needed in subsequent patches once this is pushed.

Quoted 2 lines

with some minor comments,

Quoted 65 lines
   hw/acpi/erst.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   1 file changed, 225 insertions(+)
hw/acpi/erst.c +47 -0
index fe9ba51..5d5a639 100644
@@ -59,6 +59,27 @@
   #define STATUS_RECORD_STORE_EMPTY     0x04
   #define STATUS_RECORD_NOT_FOUND       0x05
 
+/* ACPI 4.0: Table 17-19 Serialization Instructions */
+#define INST_READ_REGISTER                 0x00
+#define INST_READ_REGISTER_VALUE           0x01
+#define INST_WRITE_REGISTER                0x02
+#define INST_WRITE_REGISTER_VALUE          0x03
+#define INST_NOOP                          0x04
+#define INST_LOAD_VAR1                     0x05
+#define INST_LOAD_VAR2                     0x06
+#define INST_STORE_VAR1                    0x07
+#define INST_ADD                           0x08
+#define INST_SUBTRACT                      0x09
+#define INST_ADD_VALUE                     0x0A
+#define INST_SUBTRACT_VALUE                0x0B
+#define INST_STALL                         0x0C
+#define INST_STALL_WHILE_TRUE              0x0D
+#define INST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E
+#define INST_GOTO                          0x0F
+#define INST_SET_SRC_ADDRESS_BASE          0x10
+#define INST_SET_DST_ADDRESS_BASE          0x11
+#define INST_MOVE_DATA                     0x12
+
   /* UEFI 2.1: Appendix N Common Platform Error Record */
   #define UEFI_CPER_RECORD_MIN_SIZE 128U
   #define UEFI_CPER_RECORD_LENGTH_OFFSET 20U
@@ -172,6 +193,210 @@ typedef struct {
 
   /*******************************************************************/
   /*******************************************************************/
+typedef struct {
+    GArray *table_data;
+    pcibus_t bar;
+    uint8_t instruction;
+    uint8_t flags;
+    uint8_t register_bit_width;
+    pcibus_t register_offset;
+} BuildSerializationInstructionEntry;
+
+/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */
+static void build_serialization_instruction(
+    BuildSerializationInstructionEntry *e,
+    uint8_t serialization_action,
+    uint64_t value)
+{
+    /* ACPI 4.0: Table 17-18 Serialization Instruction Entry */
+    struct AcpiGenericAddress gas;
+    uint64_t mask;
+
+    /* Serialization Action */
+    build_append_int_noprefix(e->table_data, serialization_action, 1);
+    /* Instruction */
+    build_append_int_noprefix(e->table_data, e->instruction, 1);
+    /* Flags */
+    build_append_int_noprefix(e->table_data, e->flags, 1);
+    /* Reserved */
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 227

Quoted 6 lines
hw/acpi/erst.c +6 -0
+    build_append_int_noprefix(e->table_data, 0, 1);
+    /* Register Region */
+    gas.space_id = AML_SYSTEM_MEMORY;
+    gas.bit_width = e->register_bit_width;
+    gas.bit_offset = 0;
+    gas.access_width = ctz32(e->register_bit_width) - 2;

Should this be casted as unit8_t?

OK, done.

Quoted 77 lines
Quoted 77 lines
hw/acpi/erst.c +76 -0
+    gas.address = (uint64_t)(e->bar + e->register_offset);
+    build_append_gas_from_struct(e->table_data, &gas);
+    /* Value */
+    build_append_int_noprefix(e->table_data, value, 8);
+    /* Mask */
+    mask = (1ULL << (e->register_bit_width - 1) << 1) - 1;
+    build_append_int_noprefix(e->table_data, mask, 8);
+}
+
+/* ACPI 4.0: 17.4.1 Serialization Action Table */
+void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
+    const char *oem_id, const char *oem_table_id)
+{
+    /*
+     * Serialization Action Table
+     * The serialization action table must be generated first
+     * so that its size can be known in order to populate the
+     * Instruction Entry Count field.
+     */
+    GArray *table_instruction_data = g_array_new(FALSE, FALSE, sizeof(char));
+    pcibus_t bar0 = pci_get_bar_addr(PCI_DEVICE(erst_dev), 0);
+    AcpiTable table = { .sig = "ERST", .rev = 1, .oem_id = oem_id,
+                        .oem_table_id = oem_table_id };
+    /* Contexts for the different ways ACTION and VALUE are accessed */
+    BuildSerializationInstructionEntry rd_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_action = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 307

Quoted 4 lines
hw/acpi/erst.c +4 -0
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_ACTION_OFFSET,
+    };

We can probably write a macro to simply generating these structs. I see .bar and .flags are the same in all structs. The .bit_width can be a param into the macro etc.

Quoted 4 lines

Agree, however the request was to NOT hide the use of local variables in macros, so while .flags is always 0, .instruction, .register_bit_width and .register_offset would be parameters, that leaves .table_data and .bar which just need the local variables. Is the following acceptable (which hides the use of the local variables)?

You can just use assignment:

    BuildSerializationInstructionEntry entry = {
        .table_data = table_instruction_data,
        .bar = bar0,
        .flags = 0,
        .register_bit_width = 32,
    };
    BuildSerializationInstructionEntry rd_value_32_val = entry;
    rd_value_32_val.action = INST_READ_REGISTER_VALUE;
    rd_value_32_val.register_offset = ERST_ACTION_OFFSET;
Quoted 3 lines

and so on.
not sure it's worth it, it's just a couple of lines.

OK, here is the equivalent using struct assignment, is this what you were after?

    BuildSerializationInstructionEntry base = {
        .table_data = table_instruction_data,
        .bar = bar0,
        .instruction = INST_WRITE_REGISTER,
        .flags = 0,
        .register_bit_width = 32,
        .register_offset = ERST_VALUE_OFFSET,
    };
    BuildSerializationInstructionEntry rd_value_32_val = base;
    rd_value_32_val.instruction = INST_READ_REGISTER_VALUE;
    BuildSerializationInstructionEntry rd_value_32 = base;
    rd_value_32.instruction = INST_READ_REGISTER;
    BuildSerializationInstructionEntry rd_value_64 = base;
    rd_value_64.instruction = INST_READ_REGISTER;
    rd_value_64.register_bit_width = 64;
    BuildSerializationInstructionEntry wr_value_32_val = base;
    wr_value_32_val.instruction = INST_WRITE_REGISTER_VALUE;
    BuildSerializationInstructionEntry wr_value_32 = base;
    BuildSerializationInstructionEntry wr_value_64 = base;
    wr_value_64.register_bit_width = 64;
    BuildSerializationInstructionEntry wr_action = base;
    wr_action.instruction = INST_WRITE_REGISTER_VALUE;
    wr_action.register_offset = ERST_ACTION_OFFSET;
Quoted 27 lines
Quoted 27 lines

#define SERIALIZATIONINSTRUCTIONCTX(name, \
     inst, bit_width, offset) \
     BuildSerializationInstructionEntry name = { \
         .table_data = table_instruction_data, \
         .bar = bar0, \
         .instruction = inst, \
         .flags = 0, \
         .register_bit_width = bit_width, \
         .register_offset = offset, \
     }
     SERIALIZATIONINSTRUCTIONCTX(rd_value_32_val,
         INST_READ_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(rd_value_32,
         INST_READ_REGISTER, 32, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(rd_value_64,
         INST_READ_REGISTER, 64, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(wr_value_32_val,
         INST_WRITE_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(wr_value_32,
         INST_WRITE_REGISTER, 32, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(wr_value_64,
         INST_WRITE_REGISTER, 64, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(wr_action,
         INST_WRITE_REGISTER_VALUE, 32, ERST_ACTION_OFFSET);
Quoted 3 lines
Quoted 1 line

These are the 7 accessors needed.

not at all sure this one is worth the macro mess.

I'm hoping to produce a v15 with the style you want. eric

Quoted 102 lines
Quoted 101 lines
Quoted 101 lines
Quoted 101 lines
hw/acpi/erst.c +92 -1
+    unsigned action;
+
+    trace_acpi_erst_pci_bar_0(bar0);
+
+    /* Serialization Instruction Entries */
+    action = ACTION_BEGIN_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_READ_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_CLEAR_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_END_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_SET_RECORD_OFFSET;
+    build_serialization_instruction(&wr_value_32, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_EXECUTE_OPERATION;
+    build_serialization_instruction(&wr_value_32_val, action,
+        ERST_EXECUTE_OPERATION_MAGIC);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_CHECK_BUSY_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32_val, action, 0x01);
+
+    action = ACTION_GET_COMMAND_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_SET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_value_64, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_RECORD_COUNT;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    /* Serialization Header */
+    acpi_table_begin(&table, table_data);
+
+    /* Serialization Header Size */
+    build_append_int_noprefix(table_data, 48, 4);
+
+    /* Reserved */
+    build_append_int_noprefix(table_data,  0, 4);
+
+    /*
+     * Instruction Entry Count
+     * Each instruction entry is 32 bytes
+     */
+    g_assert((table_instruction_data->len) % 32 == 0);
+    build_append_int_noprefix(table_data,
+        (table_instruction_data->len / 32), 4);
+
+    /* Serialization Instruction Entries */
+    g_array_append_vals(table_data, table_instruction_data->data,
+        table_instruction_data->len);
+    g_array_free(table_instruction_data, TRUE);
+
+    acpi_table_end(linker, &table);
+}
+
+/*******************************************************************/
+/*******************************************************************/
   static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index)
   {
       uint8_t *rc = NULL;
--

1.8.3.1

#14 lore raw

Re: [PATCH v14 06/10] ACPI ERST: build the ACPI ERST table

In reply to Eric DeVolder
Quoted 242 lines · Eric DeVolder

Michael, thanks! See inline response below, please. eric

Quoted 238 lines · Michael S. Tsirkin
Quoted 236 lines · Eric DeVolder

Michael,
Thanks for examining this. Inline response below.
eric

Quoted 201 lines · Michael S. Tsirkin
Quoted 183 lines · Eric DeVolder

Ani,
Thanks for the RB! Inline responses below.
eric

Quoted 83 lines · Ani Sinha
Quoted 2 lines · Eric DeVolder

This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.

There might be more optimizations possible but I think we have messaged this code enough. We can further rework the code if needed in subsequent patches once this is pushed.

Quoted 2 lines

with some minor comments,

Quoted 65 lines
    hw/acpi/erst.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    1 file changed, 225 insertions(+)
hw/acpi/erst.c +47 -0
index fe9ba51..5d5a639 100644
@@ -59,6 +59,27 @@
    #define STATUS_RECORD_STORE_EMPTY     0x04
    #define STATUS_RECORD_NOT_FOUND       0x05
 
+/* ACPI 4.0: Table 17-19 Serialization Instructions */
+#define INST_READ_REGISTER                 0x00
+#define INST_READ_REGISTER_VALUE           0x01
+#define INST_WRITE_REGISTER                0x02
+#define INST_WRITE_REGISTER_VALUE          0x03
+#define INST_NOOP                          0x04
+#define INST_LOAD_VAR1                     0x05
+#define INST_LOAD_VAR2                     0x06
+#define INST_STORE_VAR1                    0x07
+#define INST_ADD                           0x08
+#define INST_SUBTRACT                      0x09
+#define INST_ADD_VALUE                     0x0A
+#define INST_SUBTRACT_VALUE                0x0B
+#define INST_STALL                         0x0C
+#define INST_STALL_WHILE_TRUE              0x0D
+#define INST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E
+#define INST_GOTO                          0x0F
+#define INST_SET_SRC_ADDRESS_BASE          0x10
+#define INST_SET_DST_ADDRESS_BASE          0x11
+#define INST_MOVE_DATA                     0x12
+
    /* UEFI 2.1: Appendix N Common Platform Error Record */
    #define UEFI_CPER_RECORD_MIN_SIZE 128U
    #define UEFI_CPER_RECORD_LENGTH_OFFSET 20U
@@ -172,6 +193,210 @@ typedef struct {
 
    /*******************************************************************/
    /*******************************************************************/
+typedef struct {
+    GArray *table_data;
+    pcibus_t bar;
+    uint8_t instruction;
+    uint8_t flags;
+    uint8_t register_bit_width;
+    pcibus_t register_offset;
+} BuildSerializationInstructionEntry;
+
+/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */
+static void build_serialization_instruction(
+    BuildSerializationInstructionEntry *e,
+    uint8_t serialization_action,
+    uint64_t value)
+{
+    /* ACPI 4.0: Table 17-18 Serialization Instruction Entry */
+    struct AcpiGenericAddress gas;
+    uint64_t mask;
+
+    /* Serialization Action */
+    build_append_int_noprefix(e->table_data, serialization_action, 1);
+    /* Instruction */
+    build_append_int_noprefix(e->table_data, e->instruction, 1);
+    /* Flags */
+    build_append_int_noprefix(e->table_data, e->flags, 1);
+    /* Reserved */
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 227

Quoted 6 lines
hw/acpi/erst.c +6 -0
+    build_append_int_noprefix(e->table_data, 0, 1);
+    /* Register Region */
+    gas.space_id = AML_SYSTEM_MEMORY;
+    gas.bit_width = e->register_bit_width;
+    gas.bit_offset = 0;
+    gas.access_width = ctz32(e->register_bit_width) - 2;

Should this be casted as unit8_t?

OK, done.

Quoted 77 lines
Quoted 77 lines
hw/acpi/erst.c +76 -0
+    gas.address = (uint64_t)(e->bar + e->register_offset);
+    build_append_gas_from_struct(e->table_data, &gas);
+    /* Value */
+    build_append_int_noprefix(e->table_data, value, 8);
+    /* Mask */
+    mask = (1ULL << (e->register_bit_width - 1) << 1) - 1;
+    build_append_int_noprefix(e->table_data, mask, 8);
+}
+
+/* ACPI 4.0: 17.4.1 Serialization Action Table */
+void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
+    const char *oem_id, const char *oem_table_id)
+{
+    /*
+     * Serialization Action Table
+     * The serialization action table must be generated first
+     * so that its size can be known in order to populate the
+     * Instruction Entry Count field.
+     */
+    GArray *table_instruction_data = g_array_new(FALSE, FALSE, sizeof(char));
+    pcibus_t bar0 = pci_get_bar_addr(PCI_DEVICE(erst_dev), 0);
+    AcpiTable table = { .sig = "ERST", .rev = 1, .oem_id = oem_id,
+                        .oem_table_id = oem_table_id };
+    /* Contexts for the different ways ACTION and VALUE are accessed */
+    BuildSerializationInstructionEntry rd_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_action = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 307

Quoted 4 lines
hw/acpi/erst.c +4 -0
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_ACTION_OFFSET,
+    };

We can probably write a macro to simply generating these structs. I see .bar and .flags are the same in all structs. The .bit_width can be a param into the macro etc.

Quoted 4 lines

Agree, however the request was to NOT hide the use of local variables in macros, so while .flags is always 0, .instruction, .register_bit_width and .register_offset would be parameters, that leaves .table_data and .bar which just need the local variables. Is the following acceptable (which hides the use of the local variables)?

You can just use assignment:

     BuildSerializationInstructionEntry entry = {
         .table_data = table_instruction_data,
         .bar = bar0,
         .flags = 0,
         .register_bit_width = 32,
     };
     BuildSerializationInstructionEntry rd_value_32_val = entry;
     rd_value_32_val.action = INST_READ_REGISTER_VALUE;
     rd_value_32_val.register_offset = ERST_ACTION_OFFSET;
Quoted 3 lines

and so on.
not sure it's worth it, it's just a couple of lines.

OK, here is the equivalent using struct assignment, is this what you were after?

     BuildSerializationInstructionEntry base = {
         .table_data = table_instruction_data,
         .bar = bar0,
         .instruction = INST_WRITE_REGISTER,
         .flags = 0,
         .register_bit_width = 32,
         .register_offset = ERST_VALUE_OFFSET,
     };
     BuildSerializationInstructionEntry rd_value_32_val = base;
     rd_value_32_val.instruction = INST_READ_REGISTER_VALUE;
     BuildSerializationInstructionEntry rd_value_32 = base;
     rd_value_32.instruction = INST_READ_REGISTER;
     BuildSerializationInstructionEntry rd_value_64 = base;
     rd_value_64.instruction = INST_READ_REGISTER;
     rd_value_64.register_bit_width = 64;
     BuildSerializationInstructionEntry wr_value_32_val = base;
     wr_value_32_val.instruction = INST_WRITE_REGISTER_VALUE;
     BuildSerializationInstructionEntry wr_value_32 = base;
     BuildSerializationInstructionEntry wr_value_64 = base;
     wr_value_64.register_bit_width = 64;
     BuildSerializationInstructionEntry wr_action = base;
     wr_action.instruction = INST_WRITE_REGISTER_VALUE;
     wr_action.register_offset = ERST_ACTION_OFFSET;
Quoted 7 lines
Quoted 3 lines

That's what I described, yes. We should have some empty lines here I guess. I'm ok with the original one too, there's not too much duplication.

Are the blank lines referring to spacing out the setup of each of the 7 accesors? If so, I could put a one line comment between each setup? Or is a blank line also needed?

A blank line between declarations and code is usually a good idea.

Quoted 5 lines

Is it OK to post v15 with the struct assignment approach? Or would you prefer the explicit structs (which is what I think you mean by 'the original one')?

Thanks!
eric

I don't care either way.

Quoted 140 lines
Quoted 140 lines
Quoted 139 lines
Quoted 30 lines
Quoted 30 lines




#define SERIALIZATIONINSTRUCTIONCTX(name, \
      inst, bit_width, offset) \
      BuildSerializationInstructionEntry name = { \
          .table_data = table_instruction_data, \
          .bar = bar0, \
          .instruction = inst, \
          .flags = 0, \
          .register_bit_width = bit_width, \
          .register_offset = offset, \
      }
      SERIALIZATIONINSTRUCTIONCTX(rd_value_32_val,
          INST_READ_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(rd_value_32,
          INST_READ_REGISTER, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(rd_value_64,
          INST_READ_REGISTER, 64, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_value_32_val,
          INST_WRITE_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_value_32,
          INST_WRITE_REGISTER, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_value_64,
          INST_WRITE_REGISTER, 64, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_action,
          INST_WRITE_REGISTER_VALUE, 32, ERST_ACTION_OFFSET);
Quoted 3 lines
Quoted 1 line

These are the 7 accessors needed.

not at all sure this one is worth the macro mess.

I'm hoping to produce a v15 with the style you want. eric

Quoted 102 lines
Quoted 101 lines
Quoted 101 lines
Quoted 101 lines
hw/acpi/erst.c +92 -1
+    unsigned action;
+
+    trace_acpi_erst_pci_bar_0(bar0);
+
+    /* Serialization Instruction Entries */
+    action = ACTION_BEGIN_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_READ_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_CLEAR_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_END_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_SET_RECORD_OFFSET;
+    build_serialization_instruction(&wr_value_32, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_EXECUTE_OPERATION;
+    build_serialization_instruction(&wr_value_32_val, action,
+        ERST_EXECUTE_OPERATION_MAGIC);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_CHECK_BUSY_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32_val, action, 0x01);
+
+    action = ACTION_GET_COMMAND_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_SET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_value_64, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_RECORD_COUNT;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    /* Serialization Header */
+    acpi_table_begin(&table, table_data);
+
+    /* Serialization Header Size */
+    build_append_int_noprefix(table_data, 48, 4);
+
+    /* Reserved */
+    build_append_int_noprefix(table_data,  0, 4);
+
+    /*
+     * Instruction Entry Count
+     * Each instruction entry is 32 bytes
+     */
+    g_assert((table_instruction_data->len) % 32 == 0);
+    build_append_int_noprefix(table_data,
+        (table_instruction_data->len / 32), 4);
+
+    /* Serialization Instruction Entries */
+    g_array_append_vals(table_data, table_instruction_data->data,
+        table_instruction_data->len);
+    g_array_free(table_instruction_data, TRUE);
+
+    acpi_table_end(linker, &table);
+}
+
+/*******************************************************************/
+/*******************************************************************/
    static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index)
    {
        uint8_t *rc = NULL;
--

1.8.3.1

#12 lore raw

Re: [PATCH v14 06/10] ACPI ERST: build the ACPI ERST table

In reply to Eric DeVolder
Quoted 227 lines · Eric DeVolder

Michael,
Thanks for examining this. Inline response below.
eric

Quoted 201 lines · Michael S. Tsirkin
Quoted 183 lines · Eric DeVolder

Ani,
Thanks for the RB! Inline responses below.
eric

Quoted 83 lines · Ani Sinha
Quoted 2 lines · Eric DeVolder

This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.

There might be more optimizations possible but I think we have messaged this code enough. We can further rework the code if needed in subsequent patches once this is pushed.

Quoted 2 lines

with some minor comments,

Quoted 65 lines
   hw/acpi/erst.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   1 file changed, 225 insertions(+)
hw/acpi/erst.c +47 -0
index fe9ba51..5d5a639 100644
@@ -59,6 +59,27 @@
   #define STATUS_RECORD_STORE_EMPTY     0x04
   #define STATUS_RECORD_NOT_FOUND       0x05
 
+/* ACPI 4.0: Table 17-19 Serialization Instructions */
+#define INST_READ_REGISTER                 0x00
+#define INST_READ_REGISTER_VALUE           0x01
+#define INST_WRITE_REGISTER                0x02
+#define INST_WRITE_REGISTER_VALUE          0x03
+#define INST_NOOP                          0x04
+#define INST_LOAD_VAR1                     0x05
+#define INST_LOAD_VAR2                     0x06
+#define INST_STORE_VAR1                    0x07
+#define INST_ADD                           0x08
+#define INST_SUBTRACT                      0x09
+#define INST_ADD_VALUE                     0x0A
+#define INST_SUBTRACT_VALUE                0x0B
+#define INST_STALL                         0x0C
+#define INST_STALL_WHILE_TRUE              0x0D
+#define INST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E
+#define INST_GOTO                          0x0F
+#define INST_SET_SRC_ADDRESS_BASE          0x10
+#define INST_SET_DST_ADDRESS_BASE          0x11
+#define INST_MOVE_DATA                     0x12
+
   /* UEFI 2.1: Appendix N Common Platform Error Record */
   #define UEFI_CPER_RECORD_MIN_SIZE 128U
   #define UEFI_CPER_RECORD_LENGTH_OFFSET 20U
@@ -172,6 +193,210 @@ typedef struct {
 
   /*******************************************************************/
   /*******************************************************************/
+typedef struct {
+    GArray *table_data;
+    pcibus_t bar;
+    uint8_t instruction;
+    uint8_t flags;
+    uint8_t register_bit_width;
+    pcibus_t register_offset;
+} BuildSerializationInstructionEntry;
+
+/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */
+static void build_serialization_instruction(
+    BuildSerializationInstructionEntry *e,
+    uint8_t serialization_action,
+    uint64_t value)
+{
+    /* ACPI 4.0: Table 17-18 Serialization Instruction Entry */
+    struct AcpiGenericAddress gas;
+    uint64_t mask;
+
+    /* Serialization Action */
+    build_append_int_noprefix(e->table_data, serialization_action, 1);
+    /* Instruction */
+    build_append_int_noprefix(e->table_data, e->instruction, 1);
+    /* Flags */
+    build_append_int_noprefix(e->table_data, e->flags, 1);
+    /* Reserved */
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 227

Quoted 6 lines
hw/acpi/erst.c +6 -0
+    build_append_int_noprefix(e->table_data, 0, 1);
+    /* Register Region */
+    gas.space_id = AML_SYSTEM_MEMORY;
+    gas.bit_width = e->register_bit_width;
+    gas.bit_offset = 0;
+    gas.access_width = ctz32(e->register_bit_width) - 2;

Should this be casted as unit8_t?

OK, done.

Quoted 77 lines
Quoted 77 lines
hw/acpi/erst.c +76 -0
+    gas.address = (uint64_t)(e->bar + e->register_offset);
+    build_append_gas_from_struct(e->table_data, &gas);
+    /* Value */
+    build_append_int_noprefix(e->table_data, value, 8);
+    /* Mask */
+    mask = (1ULL << (e->register_bit_width - 1) << 1) - 1;
+    build_append_int_noprefix(e->table_data, mask, 8);
+}
+
+/* ACPI 4.0: 17.4.1 Serialization Action Table */
+void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
+    const char *oem_id, const char *oem_table_id)
+{
+    /*
+     * Serialization Action Table
+     * The serialization action table must be generated first
+     * so that its size can be known in order to populate the
+     * Instruction Entry Count field.
+     */
+    GArray *table_instruction_data = g_array_new(FALSE, FALSE, sizeof(char));
+    pcibus_t bar0 = pci_get_bar_addr(PCI_DEVICE(erst_dev), 0);
+    AcpiTable table = { .sig = "ERST", .rev = 1, .oem_id = oem_id,
+                        .oem_table_id = oem_table_id };
+    /* Contexts for the different ways ACTION and VALUE are accessed */
+    BuildSerializationInstructionEntry rd_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_action = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 307

Quoted 4 lines
hw/acpi/erst.c +4 -0
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_ACTION_OFFSET,
+    };

We can probably write a macro to simply generating these structs. I see .bar and .flags are the same in all structs. The .bit_width can be a param into the macro etc.

Quoted 4 lines

Agree, however the request was to NOT hide the use of local variables in macros, so while .flags is always 0, .instruction, .register_bit_width and .register_offset would be parameters, that leaves .table_data and .bar which just need the local variables. Is the following acceptable (which hides the use of the local variables)?

You can just use assignment:

    BuildSerializationInstructionEntry entry = {
        .table_data = table_instruction_data,
        .bar = bar0,
        .flags = 0,
        .register_bit_width = 32,
    };
    BuildSerializationInstructionEntry rd_value_32_val = entry;
    rd_value_32_val.action = INST_READ_REGISTER_VALUE;
    rd_value_32_val.register_offset = ERST_ACTION_OFFSET;
Quoted 3 lines

and so on.
not sure it's worth it, it's just a couple of lines.

OK, here is the equivalent using struct assignment, is this what you were after?

    BuildSerializationInstructionEntry base = {
        .table_data = table_instruction_data,
        .bar = bar0,
        .instruction = INST_WRITE_REGISTER,
        .flags = 0,
        .register_bit_width = 32,
        .register_offset = ERST_VALUE_OFFSET,
    };
    BuildSerializationInstructionEntry rd_value_32_val = base;
    rd_value_32_val.instruction = INST_READ_REGISTER_VALUE;
    BuildSerializationInstructionEntry rd_value_32 = base;
    rd_value_32.instruction = INST_READ_REGISTER;
    BuildSerializationInstructionEntry rd_value_64 = base;
    rd_value_64.instruction = INST_READ_REGISTER;
    rd_value_64.register_bit_width = 64;
Quoted 9 lines
    BuildSerializationInstructionEntry wr_value_32_val = base;
    wr_value_32_val.instruction = INST_WRITE_REGISTER_VALUE;
    BuildSerializationInstructionEntry wr_value_32 = base;
    BuildSerializationInstructionEntry wr_value_64 = base;
    wr_value_64.register_bit_width = 64;
    BuildSerializationInstructionEntry wr_action = base;
    wr_action.instruction = INST_WRITE_REGISTER_VALUE;
    wr_action.register_offset = ERST_ACTION_OFFSET;

That's what I described, yes. We should have some empty lines here I guess. I'm ok with the original one too, there's not too much duplication.

Quoted 137 lines
Quoted 28 lines
Quoted 28 lines


#define SERIALIZATIONINSTRUCTIONCTX(name, \
     inst, bit_width, offset) \
     BuildSerializationInstructionEntry name = { \
         .table_data = table_instruction_data, \
         .bar = bar0, \
         .instruction = inst, \
         .flags = 0, \
         .register_bit_width = bit_width, \
         .register_offset = offset, \
     }
     SERIALIZATIONINSTRUCTIONCTX(rd_value_32_val,
         INST_READ_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(rd_value_32,
         INST_READ_REGISTER, 32, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(rd_value_64,
         INST_READ_REGISTER, 64, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(wr_value_32_val,
         INST_WRITE_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(wr_value_32,
         INST_WRITE_REGISTER, 32, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(wr_value_64,
         INST_WRITE_REGISTER, 64, ERST_VALUE_OFFSET);
     SERIALIZATIONINSTRUCTIONCTX(wr_action,
         INST_WRITE_REGISTER_VALUE, 32, ERST_ACTION_OFFSET);
Quoted 3 lines
Quoted 1 line

These are the 7 accessors needed.

not at all sure this one is worth the macro mess.

I'm hoping to produce a v15 with the style you want. eric

Quoted 102 lines
Quoted 101 lines
Quoted 101 lines
Quoted 101 lines
hw/acpi/erst.c +92 -1
+    unsigned action;
+
+    trace_acpi_erst_pci_bar_0(bar0);
+
+    /* Serialization Instruction Entries */
+    action = ACTION_BEGIN_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_READ_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_CLEAR_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_END_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_SET_RECORD_OFFSET;
+    build_serialization_instruction(&wr_value_32, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_EXECUTE_OPERATION;
+    build_serialization_instruction(&wr_value_32_val, action,
+        ERST_EXECUTE_OPERATION_MAGIC);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_CHECK_BUSY_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32_val, action, 0x01);
+
+    action = ACTION_GET_COMMAND_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_SET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_value_64, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_RECORD_COUNT;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    /* Serialization Header */
+    acpi_table_begin(&table, table_data);
+
+    /* Serialization Header Size */
+    build_append_int_noprefix(table_data, 48, 4);
+
+    /* Reserved */
+    build_append_int_noprefix(table_data,  0, 4);
+
+    /*
+     * Instruction Entry Count
+     * Each instruction entry is 32 bytes
+     */
+    g_assert((table_instruction_data->len) % 32 == 0);
+    build_append_int_noprefix(table_data,
+        (table_instruction_data->len / 32), 4);
+
+    /* Serialization Instruction Entries */
+    g_array_append_vals(table_data, table_instruction_data->data,
+        table_instruction_data->len);
+    g_array_free(table_instruction_data, TRUE);
+
+    acpi_table_end(linker, &table);
+}
+
+/*******************************************************************/
+/*******************************************************************/
   static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index)
   {
       uint8_t *rc = NULL;
--

1.8.3.1

#13 lore raw

Re: [PATCH v14 06/10] ACPI ERST: build the ACPI ERST table

Michael, thanks! See inline response below, please. eric

Quoted 238 lines · Michael S. Tsirkin
Quoted 227 lines · Eric DeVolder

Michael,
Thanks for examining this. Inline response below.
eric

Quoted 201 lines · Michael S. Tsirkin
Quoted 183 lines · Eric DeVolder

Ani,
Thanks for the RB! Inline responses below.
eric

Quoted 83 lines · Ani Sinha
Quoted 2 lines · Eric DeVolder

This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.

There might be more optimizations possible but I think we have messaged this code enough. We can further rework the code if needed in subsequent patches once this is pushed.

Quoted 2 lines

with some minor comments,

Quoted 65 lines
    hw/acpi/erst.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    1 file changed, 225 insertions(+)
hw/acpi/erst.c +47 -0
index fe9ba51..5d5a639 100644
@@ -59,6 +59,27 @@
    #define STATUS_RECORD_STORE_EMPTY     0x04
    #define STATUS_RECORD_NOT_FOUND       0x05
 
+/* ACPI 4.0: Table 17-19 Serialization Instructions */
+#define INST_READ_REGISTER                 0x00
+#define INST_READ_REGISTER_VALUE           0x01
+#define INST_WRITE_REGISTER                0x02
+#define INST_WRITE_REGISTER_VALUE          0x03
+#define INST_NOOP                          0x04
+#define INST_LOAD_VAR1                     0x05
+#define INST_LOAD_VAR2                     0x06
+#define INST_STORE_VAR1                    0x07
+#define INST_ADD                           0x08
+#define INST_SUBTRACT                      0x09
+#define INST_ADD_VALUE                     0x0A
+#define INST_SUBTRACT_VALUE                0x0B
+#define INST_STALL                         0x0C
+#define INST_STALL_WHILE_TRUE              0x0D
+#define INST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E
+#define INST_GOTO                          0x0F
+#define INST_SET_SRC_ADDRESS_BASE          0x10
+#define INST_SET_DST_ADDRESS_BASE          0x11
+#define INST_MOVE_DATA                     0x12
+
    /* UEFI 2.1: Appendix N Common Platform Error Record */
    #define UEFI_CPER_RECORD_MIN_SIZE 128U
    #define UEFI_CPER_RECORD_LENGTH_OFFSET 20U
@@ -172,6 +193,210 @@ typedef struct {
 
    /*******************************************************************/
    /*******************************************************************/
+typedef struct {
+    GArray *table_data;
+    pcibus_t bar;
+    uint8_t instruction;
+    uint8_t flags;
+    uint8_t register_bit_width;
+    pcibus_t register_offset;
+} BuildSerializationInstructionEntry;
+
+/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */
+static void build_serialization_instruction(
+    BuildSerializationInstructionEntry *e,
+    uint8_t serialization_action,
+    uint64_t value)
+{
+    /* ACPI 4.0: Table 17-18 Serialization Instruction Entry */
+    struct AcpiGenericAddress gas;
+    uint64_t mask;
+
+    /* Serialization Action */
+    build_append_int_noprefix(e->table_data, serialization_action, 1);
+    /* Instruction */
+    build_append_int_noprefix(e->table_data, e->instruction, 1);
+    /* Flags */
+    build_append_int_noprefix(e->table_data, e->flags, 1);
+    /* Reserved */
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 227

Quoted 6 lines
hw/acpi/erst.c +6 -0
+    build_append_int_noprefix(e->table_data, 0, 1);
+    /* Register Region */
+    gas.space_id = AML_SYSTEM_MEMORY;
+    gas.bit_width = e->register_bit_width;
+    gas.bit_offset = 0;
+    gas.access_width = ctz32(e->register_bit_width) - 2;

Should this be casted as unit8_t?

OK, done.

Quoted 77 lines
Quoted 77 lines
hw/acpi/erst.c +76 -0
+    gas.address = (uint64_t)(e->bar + e->register_offset);
+    build_append_gas_from_struct(e->table_data, &gas);
+    /* Value */
+    build_append_int_noprefix(e->table_data, value, 8);
+    /* Mask */
+    mask = (1ULL << (e->register_bit_width - 1) << 1) - 1;
+    build_append_int_noprefix(e->table_data, mask, 8);
+}
+
+/* ACPI 4.0: 17.4.1 Serialization Action Table */
+void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
+    const char *oem_id, const char *oem_table_id)
+{
+    /*
+     * Serialization Action Table
+     * The serialization action table must be generated first
+     * so that its size can be known in order to populate the
+     * Instruction Entry Count field.
+     */
+    GArray *table_instruction_data = g_array_new(FALSE, FALSE, sizeof(char));
+    pcibus_t bar0 = pci_get_bar_addr(PCI_DEVICE(erst_dev), 0);
+    AcpiTable table = { .sig = "ERST", .rev = 1, .oem_id = oem_id,
+                        .oem_table_id = oem_table_id };
+    /* Contexts for the different ways ACTION and VALUE are accessed */
+    BuildSerializationInstructionEntry rd_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_action = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 307

Quoted 4 lines
hw/acpi/erst.c +4 -0
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_ACTION_OFFSET,
+    };

We can probably write a macro to simply generating these structs. I see .bar and .flags are the same in all structs. The .bit_width can be a param into the macro etc.

Quoted 4 lines

Agree, however the request was to NOT hide the use of local variables in macros, so while .flags is always 0, .instruction, .register_bit_width and .register_offset would be parameters, that leaves .table_data and .bar which just need the local variables. Is the following acceptable (which hides the use of the local variables)?

You can just use assignment:

     BuildSerializationInstructionEntry entry = {
         .table_data = table_instruction_data,
         .bar = bar0,
         .flags = 0,
         .register_bit_width = 32,
     };
     BuildSerializationInstructionEntry rd_value_32_val = entry;
     rd_value_32_val.action = INST_READ_REGISTER_VALUE;
     rd_value_32_val.register_offset = ERST_ACTION_OFFSET;
Quoted 3 lines

and so on.
not sure it's worth it, it's just a couple of lines.

OK, here is the equivalent using struct assignment, is this what you were after?

     BuildSerializationInstructionEntry base = {
         .table_data = table_instruction_data,
         .bar = bar0,
         .instruction = INST_WRITE_REGISTER,
         .flags = 0,
         .register_bit_width = 32,
         .register_offset = ERST_VALUE_OFFSET,
     };
     BuildSerializationInstructionEntry rd_value_32_val = base;
     rd_value_32_val.instruction = INST_READ_REGISTER_VALUE;
     BuildSerializationInstructionEntry rd_value_32 = base;
     rd_value_32.instruction = INST_READ_REGISTER;
     BuildSerializationInstructionEntry rd_value_64 = base;
     rd_value_64.instruction = INST_READ_REGISTER;
     rd_value_64.register_bit_width = 64;
Quoted 9 lines
     BuildSerializationInstructionEntry wr_value_32_val = base;
     wr_value_32_val.instruction = INST_WRITE_REGISTER_VALUE;
     BuildSerializationInstructionEntry wr_value_32 = base;
     BuildSerializationInstructionEntry wr_value_64 = base;
     wr_value_64.register_bit_width = 64;
     BuildSerializationInstructionEntry wr_action = base;
     wr_action.instruction = INST_WRITE_REGISTER_VALUE;
     wr_action.register_offset = ERST_ACTION_OFFSET;
Quoted 3 lines

That's what I described, yes. We should have some empty lines here I guess. I'm ok with the original one too, there's not too much duplication.

Are the blank lines referring to spacing out the setup of each of the 7 accesors? If so, I could put a one line comment between each setup? Or is a blank line also needed?

Is it OK to post v15 with the struct assignment approach? Or would you prefer the explicit structs (which is what I think you mean by 'the original one')?

Thanks!
eric

Quoted 140 lines
Quoted 139 lines
Quoted 30 lines
Quoted 30 lines




#define SERIALIZATIONINSTRUCTIONCTX(name, \
      inst, bit_width, offset) \
      BuildSerializationInstructionEntry name = { \
          .table_data = table_instruction_data, \
          .bar = bar0, \
          .instruction = inst, \
          .flags = 0, \
          .register_bit_width = bit_width, \
          .register_offset = offset, \
      }
      SERIALIZATIONINSTRUCTIONCTX(rd_value_32_val,
          INST_READ_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(rd_value_32,
          INST_READ_REGISTER, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(rd_value_64,
          INST_READ_REGISTER, 64, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_value_32_val,
          INST_WRITE_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_value_32,
          INST_WRITE_REGISTER, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_value_64,
          INST_WRITE_REGISTER, 64, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_action,
          INST_WRITE_REGISTER_VALUE, 32, ERST_ACTION_OFFSET);
Quoted 3 lines
Quoted 1 line

These are the 7 accessors needed.

not at all sure this one is worth the macro mess.

I'm hoping to produce a v15 with the style you want. eric

Quoted 102 lines
Quoted 101 lines
Quoted 101 lines
Quoted 101 lines
hw/acpi/erst.c +92 -1
+    unsigned action;
+
+    trace_acpi_erst_pci_bar_0(bar0);
+
+    /* Serialization Instruction Entries */
+    action = ACTION_BEGIN_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_READ_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_BEGIN_CLEAR_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_END_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_SET_RECORD_OFFSET;
+    build_serialization_instruction(&wr_value_32, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_EXECUTE_OPERATION;
+    build_serialization_instruction(&wr_value_32_val, action,
+        ERST_EXECUTE_OPERATION_MAGIC);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_CHECK_BUSY_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32_val, action, 0x01);
+
+    action = ACTION_GET_COMMAND_STATUS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_SET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_value_64, action, 0);
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_RECORD_COUNT;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action, action);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_32, action, 0);
+
+    action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
+    build_serialization_instruction(&wr_action, action, action);
+    build_serialization_instruction(&rd_value_64, action, 0);
+
+    /* Serialization Header */
+    acpi_table_begin(&table, table_data);
+
+    /* Serialization Header Size */
+    build_append_int_noprefix(table_data, 48, 4);
+
+    /* Reserved */
+    build_append_int_noprefix(table_data,  0, 4);
+
+    /*
+     * Instruction Entry Count
+     * Each instruction entry is 32 bytes
+     */
+    g_assert((table_instruction_data->len) % 32 == 0);
+    build_append_int_noprefix(table_data,
+        (table_instruction_data->len / 32), 4);
+
+    /* Serialization Instruction Entries */
+    g_array_append_vals(table_data, table_instruction_data->data,
+        table_instruction_data->len);
+    g_array_free(table_instruction_data, TRUE);
+
+    acpi_table_end(linker, &table);
+}
+
+/*******************************************************************/
+/*******************************************************************/
    static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index)
    {
        uint8_t *rc = NULL;
--

1.8.3.1

#15 lore raw

Re: [PATCH v14 06/10] ACPI ERST: build the ACPI ERST table

In reply to Michael S. Tsirkin
Quoted 273 lines · Michael S. Tsirkin
Quoted 21 lines · Eric DeVolder

Michael, thanks! See inline response below, please. eric

Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Eric DeVolder

Michael,
Thanks for examining this. Inline response below.
eric

Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Eric DeVolder

Ani,
Thanks for the RB! Inline responses below.
eric

Quoted 5 lines · Ani Sinha
Quoted 1 line · Eric DeVolder

This builds the ACPI ERST table to inform OSPM how to

communicate

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

with the acpi-erst device.

There might be more optimizations possible but I think we have

messaged

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

this code enough. We can further rework the code if needed in

subsequent

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

patches once this is pushed.

Quoted 2 lines

with some minor comments,

Quoted 1 line
    hw/acpi/erst.c | 225

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
    1 file changed, 225 insertions(+)
hw/acpi/erst.c +19 -0
index fe9ba51..5d5a639 100644
@@ -59,6 +59,27 @@
    #define STATUS_RECORD_STORE_EMPTY     0x04
    #define STATUS_RECORD_NOT_FOUND       0x05
 
+/* ACPI 4.0: Table 17-19 Serialization Instructions */
+#define INST_READ_REGISTER                 0x00
+#define INST_READ_REGISTER_VALUE           0x01
+#define INST_WRITE_REGISTER                0x02
+#define INST_WRITE_REGISTER_VALUE          0x03
+#define INST_NOOP                          0x04
+#define INST_LOAD_VAR1                     0x05
+#define INST_LOAD_VAR2                     0x06
+#define INST_STORE_VAR1                    0x07
+#define INST_ADD                           0x08
+#define INST_SUBTRACT                      0x09
+#define INST_ADD_VALUE                     0x0A
+#define INST_SUBTRACT_VALUE                0x0B
+#define INST_STALL                         0x0C
+#define INST_STALL_WHILE_TRUE              0x0D
+#define INST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E
+#define INST_GOTO                          0x0F
+#define INST_SET_SRC_ADDRESS_BASE          0x10
+#define INST_SET_DST_ADDRESS_BASE          0x11
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

hw/acpi/erst.c typedef struct { · line 194

Quoted 8 lines
hw/acpi/erst.c +2 -0
+#define INST_MOVE_DATA                     0x12
+
    /* UEFI 2.1: Appendix N Common Platform Error Record */
    #define UEFI_CPER_RECORD_MIN_SIZE 128U
    #define UEFI_CPER_RECORD_LENGTH_OFFSET 20U
@@ -172,6 +193,210 @@ typedef struct {
 
 

/*******************************************************************/

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

/*******************************************************************/

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
hw/acpi/erst.c +8 -0
+typedef struct {
+    GArray *table_data;
+    pcibus_t bar;
+    uint8_t instruction;
+    uint8_t flags;
+    uint8_t register_bit_width;
+    pcibus_t register_offset;
+} BuildSerializationInstructionEntry;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

hw/acpi/erst.c

Quoted 8 lines
hw/acpi/erst.c +8 -0
+
+/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */
+static void build_serialization_instruction(
+    BuildSerializationInstructionEntry *e,
+    uint8_t serialization_action,
+    uint64_t value)
+{
+    /* ACPI 4.0: Table 17-18 Serialization Instruction

Entry */

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

hw/acpi/erst.c

Quoted 5 lines
hw/acpi/erst.c +5 -0
+    struct AcpiGenericAddress gas;
+    uint64_t mask;
+
+    /* Serialization Action */
+    build_append_int_noprefix(e->table_data,

serialization_action, 1);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

hw/acpi/erst.c

Quoted 2 lines
hw/acpi/erst.c +2 -0
+    /* Instruction */
+    build_append_int_noprefix(e->table_data,

e->instruction, 1);

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 11 lines

hw/acpi/erst.c

Quoted 9 lines
hw/acpi/erst.c +9 -0
+    /* Flags */
+    build_append_int_noprefix(e->table_data, e->flags, 1);
+    /* Reserved */
+    build_append_int_noprefix(e->table_data, 0, 1);
+    /* Register Region */
+    gas.space_id = AML_SYSTEM_MEMORY;
+    gas.bit_width = e->register_bit_width;
+    gas.bit_offset = 0;
+    gas.access_width = ctz32(e->register_bit_width) - 2;

Should this be casted as unit8_t?

OK, done.

Quoted 1 line
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

hw/acpi/erst.c

Quoted 11 lines
hw/acpi/erst.c +11 -0
+    gas.address = (uint64_t)(e->bar + e->register_offset);
+    build_append_gas_from_struct(e->table_data, &gas);
+    /* Value */
+    build_append_int_noprefix(e->table_data, value, 8);
+    /* Mask */
+    mask = (1ULL << (e->register_bit_width - 1) << 1) - 1;
+    build_append_int_noprefix(e->table_data, mask, 8);
+}
+
+/* ACPI 4.0: 17.4.1 Serialization Action Table */
+void build_erst(GArray *table_data, BIOSLinker *linker,

Object *erst_dev,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

hw/acpi/erst.c

Quoted 5 lines
hw/acpi/erst.c +5 -0
+    const char *oem_id, const char *oem_table_id)
+{
+    /*
+     * Serialization Action Table
+     * The serialization action table must be generated

first

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ * so that its size can be known in order to populate

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+     * Instruction Entry Count field.
+     */
+    GArray *table_instruction_data = g_array_new(FALSE,

FALSE, sizeof(char));

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ pcibus_t bar0 = pci_get_bar_addr(PCI_DEVICE(erst_dev),

0);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ AcpiTable table = { .sig = "ERST", .rev = 1, .oem_id =

oem_id,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

hw/acpi/erst.c

Quoted 2 lines
hw/acpi/erst.c +2 -0
+                        .oem_table_id = oem_table_id };
+    /* Contexts for the different ways ACTION and VALUE are

accessed */

Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Quoted 56 lines
hw/acpi/erst.c +56 -0
+    BuildSerializationInstructionEntry rd_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry rd_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_READ_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32_val = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_32 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_value_64 = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER,
+        .flags = 0,
+        .register_bit_width = 64,
+        .register_offset = ERST_VALUE_OFFSET,
+    };
+    BuildSerializationInstructionEntry wr_action = {
+        .table_data = table_instruction_data,
+        .bar = bar0,
+        .instruction = INST_WRITE_REGISTER_VALUE,
+        .flags = 0,
+        .register_bit_width = 32,
+        .register_offset = ERST_ACTION_OFFSET,
+    };
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

We can probably write a macro to simply generating these

structs. I see

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

.bar and .flags are the same in all structs. The .bit_width

can be a param

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

into the macro etc.

Agree, however the request was to NOT hide the use of local

variables in

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

macros, so while .flags is always 0, .instruction,

.register_bit_width and .register_offset

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

would be parameters, that leaves .table_data and .bar which just

need the local

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

variables. Is the following acceptable (which hides the use of

the local variables)?

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

You can just use assignment:

     BuildSerializationInstructionEntry entry = {
         .table_data = table_instruction_data,
         .bar = bar0,
         .flags = 0,
         .register_bit_width = 32,
     };
     BuildSerializationInstructionEntry rd_value_32_val = entry;
     rd_value_32_val.action = INST_READ_REGISTER_VALUE;
     rd_value_32_val.register_offset = ERST_ACTION_OFFSET;
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

and so on.
not sure it's worth it, it's just a couple of lines.

OK, here is the equivalent using struct assignment, is this what you

were after?

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
     BuildSerializationInstructionEntry base = {
         .table_data = table_instruction_data,
         .bar = bar0,
         .instruction = INST_WRITE_REGISTER,
         .flags = 0,
         .register_bit_width = 32,
         .register_offset = ERST_VALUE_OFFSET,
     };
     BuildSerializationInstructionEntry rd_value_32_val = base;
     rd_value_32_val.instruction = INST_READ_REGISTER_VALUE;
     BuildSerializationInstructionEntry rd_value_32 = base;
     rd_value_32.instruction = INST_READ_REGISTER;
     BuildSerializationInstructionEntry rd_value_64 = base;
     rd_value_64.instruction = INST_READ_REGISTER;
     rd_value_64.register_bit_width = 64;
     BuildSerializationInstructionEntry wr_value_32_val = base;
     wr_value_32_val.instruction = INST_WRITE_REGISTER_VALUE;
     BuildSerializationInstructionEntry wr_value_32 = base;
     BuildSerializationInstructionEntry wr_value_64 = base;
     wr_value_64.register_bit_width = 64;
     BuildSerializationInstructionEntry wr_action = base;
     wr_action.instruction = INST_WRITE_REGISTER_VALUE;
     wr_action.register_offset = ERST_ACTION_OFFSET;
Quoted 5 lines
Quoted 3 lines

That's what I described, yes. We should have some empty lines here I guess. I'm ok with the original one too, there's not too much duplication.

Are the blank lines referring to spacing out the setup of each of the 7

accesors?

Quoted 1 line

If so, I could put a one line comment between each setup? Or is a blank

Quoted 9 lines

line also

Quoted 1 line

needed?

A blank line between declarations and code is usually a good idea.

Quoted 1 line

Is it OK to post v15 with the struct assignment approach? Or would you

prefer the

Quoted 1 line

explicit structs (which is what I think you mean by 'the original one')?

I prefer the explicit structs as you had posted before.

Quoted 179 lines
Quoted 3 lines

Thanks!
eric

I don't care either way.

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 30 lines
Quoted 30 lines




#define SERIALIZATIONINSTRUCTIONCTX(name, \
      inst, bit_width, offset) \
      BuildSerializationInstructionEntry name = { \
          .table_data = table_instruction_data, \
          .bar = bar0, \
          .instruction = inst, \
          .flags = 0, \
          .register_bit_width = bit_width, \
          .register_offset = offset, \
      }
      SERIALIZATIONINSTRUCTIONCTX(rd_value_32_val,
          INST_READ_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(rd_value_32,
          INST_READ_REGISTER, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(rd_value_64,
          INST_READ_REGISTER, 64, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_value_32_val,
          INST_WRITE_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_value_32,
          INST_WRITE_REGISTER, 32, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_value_64,
          INST_WRITE_REGISTER, 64, ERST_VALUE_OFFSET);
      SERIALIZATIONINSTRUCTIONCTX(wr_action,
          INST_WRITE_REGISTER_VALUE, 32, ERST_ACTION_OFFSET);
Quoted 3 lines
Quoted 1 line

These are the 7 accessors needed.

not at all sure this one is worth the macro mess.

I'm hoping to produce a v15 with the style you want. eric

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

hw/acpi/erst.c

Quoted 7 lines
hw/acpi/erst.c +7 -0
+    unsigned action;
+
+    trace_acpi_erst_pci_bar_0(bar0);
+
+    /* Serialization Instruction Entries */
+    action = ACTION_BEGIN_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_BEGIN_READ_OPERATION;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_BEGIN_CLEAR_OPERATION;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_END_OPERATION;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_SET_RECORD_OFFSET;
+    build_serialization_instruction(&wr_value_32, action,

0);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ build_serialization_instruction(&wr_action, action,

action);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_EXECUTE_OPERATION;
+    build_serialization_instruction(&wr_value_32_val,

action,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

hw/acpi/erst.c

Quoted 2 lines
hw/acpi/erst.c +2 -0
+        ERST_EXECUTE_OPERATION_MAGIC);
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_CHECK_BUSY_STATUS;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ build_serialization_instruction(&rd_value_32_val,

action, 0x01);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_GET_COMMAND_STATUS;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ build_serialization_instruction(&rd_value_32, action,

0);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_GET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ build_serialization_instruction(&rd_value_64, action,

0);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_SET_RECORD_IDENTIFIER;
+    build_serialization_instruction(&wr_value_64, action,

0);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ build_serialization_instruction(&wr_action, action,

action);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_GET_RECORD_COUNT;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ build_serialization_instruction(&rd_value_32, action,

0);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ build_serialization_instruction(&rd_value_64, action,

0);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ build_serialization_instruction(&rd_value_64, action,

0);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ build_serialization_instruction(&rd_value_32, action,

0);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

hw/acpi/erst.c

Quoted 3 lines
hw/acpi/erst.c +3 -0
+
+    action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
+    build_serialization_instruction(&wr_action, action,

action);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ build_serialization_instruction(&rd_value_64, action,

0);

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
hw/acpi/erst.c +12 -0
+
+    /* Serialization Header */
+    acpi_table_begin(&table, table_data);
+
+    /* Serialization Header Size */
+    build_append_int_noprefix(table_data, 48, 4);
+
+    /* Reserved */
+    build_append_int_noprefix(table_data,  0, 4);
+
+    /*
+     * Instruction Entry Count
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

hw/acpi/erst.c

Quoted 8 lines
hw/acpi/erst.c +8 -0
+     * Each instruction entry is 32 bytes
+     */
+    g_assert((table_instruction_data->len) % 32 == 0);
+    build_append_int_noprefix(table_data,
+        (table_instruction_data->len / 32), 4);
+
+    /* Serialization Instruction Entries */
+    g_array_append_vals(table_data,

table_instruction_data->data,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

hw/acpi/erst.c

Quoted 7 lines
hw/acpi/erst.c +6 -0
+        table_instruction_data->len);
+    g_array_free(table_instruction_data, TRUE);
+
+    acpi_table_end(linker, &table);
+}
+

+/*******************************************************************/

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+/*******************************************************************/

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState

*s, unsigned index)

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
    {
        uint8_t *rc = NULL;

--
1.8.3.1

#16 lore raw

Re: [PATCH v14 06/10] ACPI ERST: build the ACPI ERST table

Quoted 47 lines · Ani Sinha

[snip]
On Fri, Jan 28, 2022 at 9:44 PM Michael S. Tsirkin <[email protected] <mailto:[email protected]>> wrote:

     > > > OK, here is the equivalent using struct assignment, is this what you were after?
     > > >
     > > >      BuildSerializationInstructionEntry base = {
     > > >          .table_data = table_instruction_data,
     > > >          .bar = bar0,
     > > >          .instruction = INST_WRITE_REGISTER,
     > > >          .flags = 0,
     > > >          .register_bit_width = 32,
     > > >          .register_offset = ERST_VALUE_OFFSET,
     > > >      };
     > > >      BuildSerializationInstructionEntry rd_value_32_val = base;
     > > >      rd_value_32_val.instruction = INST_READ_REGISTER_VALUE;
     > > >      BuildSerializationInstructionEntry rd_value_32 = base;
     > > >      rd_value_32.instruction = INST_READ_REGISTER;
     > > >      BuildSerializationInstructionEntry rd_value_64 = base;
     > > >      rd_value_64.instruction = INST_READ_REGISTER;
     > > >      rd_value_64.register_bit_width = 64;
     > > >      BuildSerializationInstructionEntry wr_value_32_val = base;
     > > >      wr_value_32_val.instruction = INST_WRITE_REGISTER_VALUE;
     > > >      BuildSerializationInstructionEntry wr_value_32 = base;
     > > >      BuildSerializationInstructionEntry wr_value_64 = base;
     > > >      wr_value_64.register_bit_width = 64;
     > > >      BuildSerializationInstructionEntry wr_action = base;
     > > >      wr_action.instruction = INST_WRITE_REGISTER_VALUE;
     > > >      wr_action.register_offset = ERST_ACTION_OFFSET;
     > > >
     > >
     > > That's what I described, yes. We should have some empty lines here I
     > > guess. I'm ok with the original one too, there's not too much
     > > duplication.
     >
     > Are the blank lines referring to spacing out the setup of each of the 7 accesors?
     > If so, I could put a one line comment between each setup? Or is a blank line also
     > needed?

    A blank line between declarations and code is usually a good idea.


     > Is it OK to post v15 with the struct assignment approach? Or would you prefer the
     > explicit structs (which is what I think you mean by 'the original one')?
Quoted 1 line

I prefer the explicit structs as you had posted before.

Ok, as Michael does not have a preference, so let's go with your preference of the explicit structs!
Thank you!
eric

Quoted 149 lines

     >
     > Thanks!
     > eric

    I don't care either way.

     > >
     > >
     > > >
     > > > >
     > > > >
     > > > > > #define SERIALIZATIONINSTRUCTIONCTX(name, \
     > > > > >       inst, bit_width, offset) \
     > > > > >       BuildSerializationInstructionEntry name = { \
     > > > > >           .table_data = table_instruction_data, \
     > > > > >           .bar = bar0, \
     > > > > >           .instruction = inst, \
     > > > > >           .flags = 0, \
     > > > > >           .register_bit_width = bit_width, \
     > > > > >           .register_offset = offset, \
     > > > > >       }
     > > > > >       SERIALIZATIONINSTRUCTIONCTX(rd_value_32_val,
     > > > > >           INST_READ_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
     > > > > >       SERIALIZATIONINSTRUCTIONCTX(rd_value_32,
     > > > > >           INST_READ_REGISTER, 32, ERST_VALUE_OFFSET);
     > > > > >       SERIALIZATIONINSTRUCTIONCTX(rd_value_64,
     > > > > >           INST_READ_REGISTER, 64, ERST_VALUE_OFFSET);
     > > > > >       SERIALIZATIONINSTRUCTIONCTX(wr_value_32_val,
     > > > > >           INST_WRITE_REGISTER_VALUE, 32, ERST_VALUE_OFFSET);
     > > > > >       SERIALIZATIONINSTRUCTIONCTX(wr_value_32,
     > > > > >           INST_WRITE_REGISTER, 32, ERST_VALUE_OFFSET);
     > > > > >       SERIALIZATIONINSTRUCTIONCTX(wr_value_64,
     > > > > >           INST_WRITE_REGISTER, 64, ERST_VALUE_OFFSET);
     > > > > >       SERIALIZATIONINSTRUCTIONCTX(wr_action,
     > > > > >           INST_WRITE_REGISTER_VALUE, 32, ERST_ACTION_OFFSET);
     > > > > >
     > > > > > These are the 7 accessors needed.
     > > > >
     > > > > not at all sure this one is worth the macro mess.
     > > >
     > > > I'm hoping to produce a v15 with the style you want.
     > > > eric
     > > >
     > > > >
     > > > > > >
     > > > > > > > +    unsigned action;
     > > > > > > > +
     > > > > > > > +    trace_acpi_erst_pci_bar_0(bar0);
     > > > > > > > +
     > > > > > > > +    /* Serialization Instruction Entries */
     > > > > > > > +    action = ACTION_BEGIN_WRITE_OPERATION;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +
     > > > > > > > +    action = ACTION_BEGIN_READ_OPERATION;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +
     > > > > > > > +    action = ACTION_BEGIN_CLEAR_OPERATION;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +
     > > > > > > > +    action = ACTION_END_OPERATION;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +
     > > > > > > > +    action = ACTION_SET_RECORD_OFFSET;
     > > > > > > > +    build_serialization_instruction(&wr_value_32, action, 0);
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +
     > > > > > > > +    action = ACTION_EXECUTE_OPERATION;
     > > > > > > > +    build_serialization_instruction(&wr_value_32_val, action,
     > > > > > > > +        ERST_EXECUTE_OPERATION_MAGIC);
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +
     > > > > > > > +    action = ACTION_CHECK_BUSY_STATUS;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +    build_serialization_instruction(&rd_value_32_val, action, 0x01);
     > > > > > > > +
     > > > > > > > +    action = ACTION_GET_COMMAND_STATUS;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +    build_serialization_instruction(&rd_value_32, action, 0);
     > > > > > > > +
     > > > > > > > +    action = ACTION_GET_RECORD_IDENTIFIER;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +    build_serialization_instruction(&rd_value_64, action, 0);
     > > > > > > > +
     > > > > > > > +    action = ACTION_SET_RECORD_IDENTIFIER;
     > > > > > > > +    build_serialization_instruction(&wr_value_64, action, 0);
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +
     > > > > > > > +    action = ACTION_GET_RECORD_COUNT;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +    build_serialization_instruction(&rd_value_32, action, 0);
     > > > > > > > +
     > > > > > > > +    action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +
     > > > > > > > +    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +    build_serialization_instruction(&rd_value_64, action, 0);
     > > > > > > > +
     > > > > > > > +    action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +    build_serialization_instruction(&rd_value_64, action, 0);
     > > > > > > > +
     > > > > > > > +    action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +    build_serialization_instruction(&rd_value_32, action, 0);
     > > > > > > > +
     > > > > > > > +    action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
     > > > > > > > +    build_serialization_instruction(&wr_action, action, action);
     > > > > > > > +    build_serialization_instruction(&rd_value_64, action, 0);
     > > > > > > > +
     > > > > > > > +    /* Serialization Header */
     > > > > > > > +    acpi_table_begin(&table, table_data);
     > > > > > > > +
     > > > > > > > +    /* Serialization Header Size */
     > > > > > > > +    build_append_int_noprefix(table_data, 48, 4);
     > > > > > > > +
     > > > > > > > +    /* Reserved */
     > > > > > > > +    build_append_int_noprefix(table_data,  0, 4);
     > > > > > > > +
     > > > > > > > +    /*
     > > > > > > > +     * Instruction Entry Count
     > > > > > > > +     * Each instruction entry is 32 bytes
     > > > > > > > +     */
     > > > > > > > +    g_assert((table_instruction_data->len) % 32 == 0);
     > > > > > > > +    build_append_int_noprefix(table_data,
     > > > > > > > +        (table_instruction_data->len / 32), 4);
     > > > > > > > +
     > > > > > > > +    /* Serialization Instruction Entries */
     > > > > > > > +    g_array_append_vals(table_data, table_instruction_data->data,
     > > > > > > > +        table_instruction_data->len);
     > > > > > > > +    g_array_free(table_instruction_data, TRUE);
     > > > > > > > +
     > > > > > > > +    acpi_table_end(linker, &table);
     > > > > > > > +}
     > > > > > > > +
     > > > > > > > +/*******************************************************************/
     > > > > > > > +/*******************************************************************/
     > > > > > > >     static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index)
     > > > > > > >     {
     > > > > > > >         uint8_t *rc = NULL;
     > > > > > > > --
     > > > > > > > 1.8.3.1
     > > > > > > >
     > > > > > > >
     > > > >
     > >