acpi: Error Record Serialization Table, ERST, support for QEMU
PATCH v13 6/10 ACPI ERST: build the ACPI ERST table
In reply to Eric DeVolderThis builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.
--- hw/acpi/erst.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+)
hw/acpi/erst.c +188 -0
@@ -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,173 @@ typedef struct {/*******************************************************************/ /*******************************************************************/ + +/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */ +static void build_serialization_instruction_entry (GArray *table_data, +uint8_t serialization_action, +uint8_t instruction, +uint8_t flags, +uint8_t register_bit_width, +uint64_t register_address, +uint64_t value) +{ +/* ACPI 4.0: Table 17-18 Serialization Instruction Entry */ +struct AcpiGenericAddress gas; +uint64_t mask; + +/* Serialization Action */ +build_append_int_noprefix (table_data, serialization_action,1 ); +/* Instruction */ +build_append_int_noprefix (table_data, instruction ,1 ); +/* Flags */ +build_append_int_noprefix (table_data, flags ,1 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Register Region */ + gas.space_id =AML_SYSTEM_MEMORY ; + gas.bit_width = register_bit_width; + gas.bit_offset =0 ; + gas.access_width =ctz32 (register_bit_width) -2 ; + gas.address = register_address; +build_append_gas_from_struct (table_data, &gas); +/* Value */ +build_append_int_noprefix (table_data, value ,8 ); +/* Mask */ + mask = (1ULL << (register_bit_width -1 ) <<1 ) -1 ; +build_append_int_noprefix (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) +{ +GArray *table_instruction_data; +unsigned action; +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 }; + +trace_acpi_erst_pci_bar_0 (bar0); + +/* +* 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. +*/ + table_instruction_data =g_array_new (FALSE, FALSE,sizeof (char )); + +/* +* Macros for use with construction of the action instructions +*/ +#define BUILD_READ_REGISTER (width_in_bits, reg) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER, 0, width_in_bits, \ + bar0 + reg, 0) + +#define BUILD_READ_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +/* Serialization Instruction Entries */ + action =ACTION_BEGIN_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_READ_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_CLEAR_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_END_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_SET_RECORD_OFFSET ; +BUILD_WRITE_REGISTER (32 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_EXECUTE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET , +ERST_EXECUTE_OPERATION_MAGIC ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_CHECK_BUSY_STATUS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET ,0x01 ); + + action =ACTION_GET_COMMAND_STATUS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_SET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER (64 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_GET_RECORD_COUNT ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_BEGIN_DUMMY_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_LENGTH ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_EXECUTE_OPERATION_TIMINGS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + +/* 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
v13 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.
---
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 | 1032 +++++++++++++++++++++++++++++++++++++ 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, 1537 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
PATCH v13 2/10 ACPI ERST: specification for ERST support
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
@@ -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
PATCH v13 3/10 ACPI ERST: PCI device_id for ERST
In reply to Eric DeVolderThis 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
@@ -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
PATCH v13 10/10 ACPI ERST: step 6 of bios-tables-test.c
In reply to Eric DeVolderFollowing 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
tests/data/acpi/pc/DSDT.acpierst binary +0 -0
tests/data/acpi/pc/ERST.acpierst binary +0 -0
tests/data/acpi/q35/DSDT.acpierst binary +0 -0
tests/data/acpi/q35/ERST.acpierst binary +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +0 -5
@@ -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
PATCH v13 4/10 ACPI ERST: header file for ERST
In reply to Eric DeVolderThis 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
@@ -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
PATCH v13 1/10 ACPI ERST: bios-tables-test.c steps 1 and 2
In reply to Eric DeVolderFollowing 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
tests/data/acpi/pc/DSDT.acpierst new file +0 -0
tests/data/acpi/pc/ERST.acpierst new file +0 -0
tests/data/acpi/q35/DSDT.acpierst new file +0 -0
tests/data/acpi/q35/ERST.acpierst new file +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +5 -0
@@ -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
PATCH v13 7/10 ACPI ERST: create ACPI ERST table for pc/x86 machines
In reply to Eric DeVolderThis 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
@@ -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
@@ -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
@@ -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
PATCH v13 8/10 ACPI ERST: qtest for ERST
In reply to Eric DeVolderThis 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
@@ -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
@@ -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
PATCH v13 9/10 ACPI ERST: bios-tables-test testcase
In reply to Eric DeVolderThis 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
@@ -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
PATCH v13 5/10 ACPI ERST: support for ACPI ERST feature
In reply to Eric DeVolderThis 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
@@ -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
@@ -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
@@ -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
Re: [PATCH v13 06/10] ACPI ERST: build the ACPI ERST table
In reply to Eric DeVolderQuoted 133 lines · Eric DeVolder
This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.
Signed-off-by Eric DeVolder <[email protected]>--- hw/acpi/erst.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+)hw/acpi/erst.c +110
-0@@ -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,173 @@ typedef struct {/*******************************************************************/ /*******************************************************************/ + +/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */ +static void build_serialization_instruction_entry (GArray *table_data, +uint8_t serialization_action, +uint8_t instruction, +uint8_t flags, +uint8_t register_bit_width, +uint64_t register_address, +uint64_t value) +{ +/* ACPI 4.0: Table 17-18 Serialization Instruction Entry */ +struct AcpiGenericAddress gas; +uint64_t mask; + +/* Serialization Action */ +build_append_int_noprefix (table_data, serialization_action,1 ); +/* Instruction */ +build_append_int_noprefix (table_data, instruction ,1 ); +/* Flags */ +build_append_int_noprefix (table_data, flags ,1 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Register Region */ + gas.space_id =AML_SYSTEM_MEMORY ; + gas.bit_width = register_bit_width; + gas.bit_offset =0 ; + gas.access_width =ctz32 (register_bit_width) -2 ; + gas.address = register_address; +build_append_gas_from_struct (table_data, &gas); +/* Value */ +build_append_int_noprefix (table_data, value ,8 ); +/* Mask */ + mask = (1ULL << (register_bit_width -1 ) <<1 ) -1 ; +build_append_int_noprefix (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) +{ +GArray *table_instruction_data; +unsigned action; +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 }; + +trace_acpi_erst_pci_bar_0 (bar0); + +/* +* 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. +*/ + table_instruction_data =g_array_new (FALSE, FALSE,sizeof (char )); + +/* +* Macros for use with construction of the action instructions +*/ +#define BUILD_READ_REGISTER (width_in_bits, reg) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER, 0, width_in_bits, \ + bar0 + reg, 0) + +#define BUILD_READ_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +/* Serialization Instruction Entries */ + action =ACTION_BEGIN_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_READ_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_CLEAR_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +
hw/acpi/erst.c typedef struct { · line 294
Quoted 10 lines
hw/acpi/erst.c +10
-0+ action =ACTION_END_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_SET_RECORD_OFFSET ; +BUILD_WRITE_REGISTER (32 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_EXECUTE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET , +ERST_EXECUTE_OPERATION_MAGIC );
except here, on all cases we have BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);
We should treat the above as special case and simplify the rest of the calls (eliminate repeated common arguments).
Quoted 7 lines
hw/acpi/erst.c +7
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_CHECK_BUSY_STATUS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET ,0x01 ); + + action =ACTION_GET_COMMAND_STATUS ;
hw/acpi/erst.c typedef struct { · line 311
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_SET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER (64 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);
This one seems reverted. Should this be BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action); BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0);
like others?
Quoted 14 lines
hw/acpi/erst.c +14
-0+ + action =ACTION_GET_RECORD_COUNT ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_BEGIN_DUMMY_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_LENGTH ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);
hw/acpi/erst.c typedef struct { · line 335
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_EXECUTE_OPERATION_TIMINGS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); +
BUILD_READ_REGISTER() is always called with ERST_VALUE_OFFSET as second argument. WE should eliminate this repeated passing of same argument.
Quoted 34 lines
hw/acpi/erst.c +27
-1+/* 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
Re: [PATCH v13 06/10] ACPI ERST: build the ACPI ERST table
Quoted 118 lines · Ani Sinha
Quoted 114 lines · Eric DeVolder
This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.
Signed-off-by Eric DeVolder <[email protected]>--- hw/acpi/erst.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+)hw/acpi/erst.c +91
-0@@ -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,173 @@ typedef struct {/*******************************************************************/ /*******************************************************************/ + +/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */ +static void build_serialization_instruction_entry (GArray *table_data, +uint8_t serialization_action, +uint8_t instruction, +uint8_t flags, +uint8_t register_bit_width, +uint64_t register_address, +uint64_t value) +{ +/* ACPI 4.0: Table 17-18 Serialization Instruction Entry */ +struct AcpiGenericAddress gas; +uint64_t mask; + +/* Serialization Action */ +build_append_int_noprefix (table_data, serialization_action,1 ); +/* Instruction */ +build_append_int_noprefix (table_data, instruction ,1 ); +/* Flags */ +build_append_int_noprefix (table_data, flags ,1 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Register Region */ + gas.space_id =AML_SYSTEM_MEMORY ; + gas.bit_width = register_bit_width; + gas.bit_offset =0 ; + gas.access_width =ctz32 (register_bit_width) -2 ; + gas.address = register_address; +build_append_gas_from_struct (table_data, &gas); +/* Value */ +build_append_int_noprefix (table_data, value ,8 ); +/* Mask */ + mask = (1ULL << (register_bit_width -1 ) <<1 ) -1 ; +build_append_int_noprefix (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) +{ +GArray *table_instruction_data; +unsigned action; +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 }; + +trace_acpi_erst_pci_bar_0 (bar0); + +/* +* 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. +*/ + table_instruction_data =g_array_new (FALSE, FALSE,sizeof (char )); + +/* +* Macros for use with construction of the action instructions +*/ +#define BUILD_READ_REGISTER (width_in_bits, reg) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER, 0, width_in_bits, \ + bar0 + reg, 0) + +#define BUILD_READ_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER (width_in_bits, reg, value) \
Quoted 8 lines
hw/acpi/erst.c typedef struct { · line 273
Quoted 8 lines
hw/acpi/erst.c +8
-0+build_serialization_instruction_entry (table_instruction_data, \ + action,INST_WRITE_REGISTER ,0 , width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value)
I think these macros which in a hidden way use the bar0 variable really should be replaced with inline functions, improving type safety.
Quoted 115 lines
Quoted 11 lines
hw/acpi/erst.c +11
-0+ +/* Serialization Instruction Entries */ + action =ACTION_BEGIN_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_READ_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_CLEAR_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +hw/acpi/erst.c typedef struct { · line 294
Quoted 10 lines
hw/acpi/erst.c +10
-0+ action =ACTION_END_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_SET_RECORD_OFFSET ; +BUILD_WRITE_REGISTER (32 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_EXECUTE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET , +ERST_EXECUTE_OPERATION_MAGIC );except here, on all cases we have
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);We should treat the above as special case and simplify the rest of the calls (eliminate repeated common arguments).
Quoted 7 lines
hw/acpi/erst.c +7
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_CHECK_BUSY_STATUS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET ,0x01 ); + + action =ACTION_GET_COMMAND_STATUS ;hw/acpi/erst.c typedef struct { · line 311
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_SET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER (64 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);This one seems reverted. Should this be
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0);like others?
Quoted 14 lines
hw/acpi/erst.c +14
-0+ + action =ACTION_GET_RECORD_COUNT ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_BEGIN_DUMMY_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_LENGTH ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);hw/acpi/erst.c typedef struct { · line 335
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_EXECUTE_OPERATION_TIMINGS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); +
BUILD_READ_REGISTER()is always called withERST_VALUE_OFFSETas second argument. WE should eliminate this repeated passing of same argument.Quoted 34 lines
hw/acpi/erst.c +27
-1+/* 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
Re: [PATCH v13 06/10] ACPI ERST: build the ACPI ERST table
Quoted 4 lines
I think these macros which in a hidden way use the bar0 variable really should be replaced with inline functions, improving type safety.
I second that.
Re: [PATCH v13 06/10] ACPI ERST: build the ACPI ERST table
In reply to Ani SinhaAni,
Thanks for the feedback! Inline responses below.
eric
Quoted 151 lines · Ani Sinha
Quoted 133 lines · Eric DeVolder
This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.
Signed-off-by Eric DeVolder <[email protected]>--- hw/acpi/erst.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+)hw/acpi/erst.c +110
-0@@ -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,173 @@ typedef struct {/*******************************************************************/ /*******************************************************************/ + +/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */ +static void build_serialization_instruction_entry (GArray *table_data, +uint8_t serialization_action, +uint8_t instruction, +uint8_t flags, +uint8_t register_bit_width, +uint64_t register_address, +uint64_t value) +{ +/* ACPI 4.0: Table 17-18 Serialization Instruction Entry */ +struct AcpiGenericAddress gas; +uint64_t mask; + +/* Serialization Action */ +build_append_int_noprefix (table_data, serialization_action,1 ); +/* Instruction */ +build_append_int_noprefix (table_data, instruction ,1 ); +/* Flags */ +build_append_int_noprefix (table_data, flags ,1 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Register Region */ + gas.space_id =AML_SYSTEM_MEMORY ; + gas.bit_width = register_bit_width; + gas.bit_offset =0 ; + gas.access_width =ctz32 (register_bit_width) -2 ; + gas.address = register_address; +build_append_gas_from_struct (table_data, &gas); +/* Value */ +build_append_int_noprefix (table_data, value ,8 ); +/* Mask */ + mask = (1ULL << (register_bit_width -1 ) <<1 ) -1 ; +build_append_int_noprefix (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) +{ +GArray *table_instruction_data; +unsigned action; +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 }; + +trace_acpi_erst_pci_bar_0 (bar0); + +/* +* 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. +*/ + table_instruction_data =g_array_new (FALSE, FALSE,sizeof (char )); + +/* +* Macros for use with construction of the action instructions +*/ +#define BUILD_READ_REGISTER (width_in_bits, reg) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER, 0, width_in_bits, \ + bar0 + reg, 0) + +#define BUILD_READ_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +/* Serialization Instruction Entries */ + action =ACTION_BEGIN_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_READ_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_CLEAR_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +hw/acpi/erst.c typedef struct { · line 294
Quoted 10 lines
hw/acpi/erst.c +10
-0+ action =ACTION_END_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_SET_RECORD_OFFSET ; +BUILD_WRITE_REGISTER (32 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_EXECUTE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET , +ERST_EXECUTE_OPERATION_MAGIC );except here, on all cases we have
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);
Quoted 2 lines
We should treat the above as special case and simplify the rest of the calls (eliminate repeated common arguments).
OK, I created BUILD_WRITE_ACTION() to replace this occurrence. I've provided what this section of code looks like with this and the other below change at the end.
I have seen the comment from Michael and you about using inline functions, I will respond to that in the other message.
Quoted 23 lines
Quoted 8 lines
hw/acpi/erst.c +7
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_CHECK_BUSY_STATUS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET ,0x01 ); + + action =ACTION_GET_COMMAND_STATUS ;hw/acpi/erst.c typedef struct { · line 311
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_SET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER (64 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);This one seems reverted. Should this be
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0);
Quoted 1 line
like others?
This is a SET operation, so the data is provided in VALUE register, then the ACTION is written to perform the command, ie record the value.
Quoted 20 lines
Quoted 20 lines
hw/acpi/erst.c +19
-0+ + action =ACTION_GET_RECORD_COUNT ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_BEGIN_DUMMY_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_LENGTH ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET );
Quoted 8 lines
hw/acpi/erst.c typedef struct { · line 335
Quoted 5 lines
hw/acpi/erst.c +5
-0+ + action =ACTION_GET_EXECUTE_OPERATION_TIMINGS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); +
BUILD_READ_REGISTER()is always called withERST_VALUE_OFFSETas second argument. WE should eliminate this repeated passing of same argument.
The BUILD_READ_REGISTER is always against the VALUE register, as you point out, so I've s/BUILD_READ_REGISTER/BUILD_READ_VALUE/ and embedded the offset in the macro now. You can see this below.
Quoted 28 lines
Quoted 28 lines
hw/acpi/erst.c +26
-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); +} + +/*******************************************************************/
Quoted 8 lines
Quoted 8 lines
hw/acpi/erst.c +1
-1+/*******************************************************************/ static uint8_t *get_nvram_ptr_by_index (ERSTDeviceState *s,unsigned index) {uint8_t *rc =NULL ; --1.8.3.1
And here is what the main snippet looks like with the above changes (a diff is quite messy):
/*
* Macros for use with construction of the action instructions
*/
#define BUILD_READ_VALUE(width_in_bits) \
build_serialization_instruction_entry(table_instruction_data, \
action, INST_READ_REGISTER, 0, width_in_bits, \
bar0 + ERST_VALUE_OFFSET, 0)#define BUILD_READ_VALUE_VALUE(width_in_bits, value) \
build_serialization_instruction_entry(table_instruction_data, \
action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \
bar0 + ERST_VALUE_OFFSET, value)#define BUILD_WRITE_REGISTER(width_in_bits, reg, value) \
build_serialization_instruction_entry(table_instruction_data, \
action, INST_WRITE_REGISTER, 0, width_in_bits, \
bar0 + reg, value)#define BUILD_WRITE_REGISTER_VALUE(width_in_bits, reg, value) \
build_serialization_instruction_entry(table_instruction_data, \
action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \
bar0 + reg, value)#define BUILD_WRITE_ACTION() \
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action)
/* Serialization Instruction Entries */
action = ACTION_BEGIN_WRITE_OPERATION;
BUILD_WRITE_ACTION();
action = ACTION_BEGIN_READ_OPERATION;
BUILD_WRITE_ACTION();
action = ACTION_BEGIN_CLEAR_OPERATION;
BUILD_WRITE_ACTION();
action = ACTION_END_OPERATION;
BUILD_WRITE_ACTION();
action = ACTION_SET_RECORD_OFFSET;
BUILD_WRITE_REGISTER(32, ERST_VALUE_OFFSET, 0);
BUILD_WRITE_ACTION();
action = ACTION_EXECUTE_OPERATION;
BUILD_WRITE_REGISTER_VALUE(32, ERST_VALUE_OFFSET,
ERST_EXECUTE_OPERATION_MAGIC);
BUILD_WRITE_ACTION();
action = ACTION_CHECK_BUSY_STATUS;
BUILD_WRITE_ACTION();
BUILD_READ_VALUE_VALUE(32, 0x01);
action = ACTION_GET_COMMAND_STATUS;
BUILD_WRITE_ACTION();
BUILD_READ_VALUE(32);
action = ACTION_GET_RECORD_IDENTIFIER;
BUILD_WRITE_ACTION();
BUILD_READ_VALUE(64);
action = ACTION_SET_RECORD_IDENTIFIER;
BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0);
BUILD_WRITE_ACTION();
action = ACTION_GET_RECORD_COUNT;
BUILD_WRITE_ACTION();
BUILD_READ_VALUE(32);
action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
BUILD_WRITE_ACTION();
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);
action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
BUILD_WRITE_ACTION();
BUILD_READ_VALUE(64);
action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
BUILD_WRITE_ACTION();
BUILD_READ_VALUE(64);
action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
BUILD_WRITE_ACTION();
BUILD_READ_VALUE(32);
action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
BUILD_WRITE_ACTION();
BUILD_READ_VALUE(64);
/* Serialization Header */Re: [PATCH v13 06/10] ACPI ERST: build the ACPI ERST table
In reply to Michael S. TsirkinHi Michael,
Thanks for examining this! Inline response below.
eric
Quoted 123 lines · Michael S. Tsirkin
Quoted 122 lines · Ani Sinha
Quoted 118 lines · Eric DeVolder
This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.
Signed-off-by Eric DeVolder <[email protected]>--- hw/acpi/erst.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+)hw/acpi/erst.c +95
-0@@ -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,173 @@ typedef struct {/*******************************************************************/ /*******************************************************************/ + +/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */ +static void build_serialization_instruction_entry (GArray *table_data, +uint8_t serialization_action, +uint8_t instruction, +uint8_t flags, +uint8_t register_bit_width, +uint64_t register_address, +uint64_t value) +{ +/* ACPI 4.0: Table 17-18 Serialization Instruction Entry */ +struct AcpiGenericAddress gas; +uint64_t mask; + +/* Serialization Action */ +build_append_int_noprefix (table_data, serialization_action,1 ); +/* Instruction */ +build_append_int_noprefix (table_data, instruction ,1 ); +/* Flags */ +build_append_int_noprefix (table_data, flags ,1 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Register Region */ + gas.space_id =AML_SYSTEM_MEMORY ; + gas.bit_width = register_bit_width; + gas.bit_offset =0 ; + gas.access_width =ctz32 (register_bit_width) -2 ; + gas.address = register_address; +build_append_gas_from_struct (table_data, &gas); +/* Value */ +build_append_int_noprefix (table_data, value ,8 ); +/* Mask */ + mask = (1ULL << (register_bit_width -1 ) <<1 ) -1 ; +build_append_int_noprefix (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) +{ +GArray *table_instruction_data; +unsigned action; +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 }; + +trace_acpi_erst_pci_bar_0 (bar0); + +/* +* 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. +*/ + table_instruction_data =g_array_new (FALSE, FALSE,sizeof (char )); + +/* +* Macros for use with construction of the action instructions +*/ +#define BUILD_READ_REGISTER (width_in_bits, reg) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER, 0, width_in_bits, \ + bar0 + reg, 0) + +#define BUILD_READ_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER, 0, width_in_bits, \ + bar0 + reg, value) +
Quoted 8 lines
Quoted 4 lines
hw/acpi/erst.c typedef struct { · line 273
Quoted 4 lines
hw/acpi/erst.c +4
-0+#define BUILD_WRITE_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value)I think these macros which in a hidden way use the bar0 variable really should be replaced with inline functions, improving type safety.
I had not stated this previously, but my choice for using macros over functions was the use three local variables: table_instruction_data, bar0, and action.
Any function would then automatically require these three as parameters, or I'm stuffing these temporary items into local globals (to avoid passing as parameters).
As for the type safety of bar0, I don't quite understand what I should do differently (regardless of macro vs function). Ultimately these call build_serialization_instruction_entry() with the 'uint64_t register address' accepting the bar0+offset value. Bar0 is pcibar_t and the compiler happily implicitly typecasts to uint64_t.
What would an acceptable function prototype look like?
Quoted 120 lines
Quoted 119 lines
Quoted 15 lines
hw/acpi/erst.c +11
-0+ +/* Serialization Instruction Entries */ + action =ACTION_BEGIN_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_READ_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_CLEAR_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +hw/acpi/erst.c typedef struct { · line 294
Quoted 10 lines
hw/acpi/erst.c +10
-0+ action =ACTION_END_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_SET_RECORD_OFFSET ; +BUILD_WRITE_REGISTER (32 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_EXECUTE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET , +ERST_EXECUTE_OPERATION_MAGIC );except here, on all cases we have
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);We should treat the above as special case and simplify the rest of the calls (eliminate repeated common arguments).
Quoted 7 lines
hw/acpi/erst.c +7
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_CHECK_BUSY_STATUS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET ,0x01 ); + + action =ACTION_GET_COMMAND_STATUS ;hw/acpi/erst.c typedef struct { · line 311
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_SET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER (64 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);This one seems reverted. Should this be
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0);like others?
Quoted 14 lines
hw/acpi/erst.c +14
-0+ + action =ACTION_GET_RECORD_COUNT ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_BEGIN_DUMMY_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_LENGTH ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);hw/acpi/erst.c typedef struct { · line 335
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_EXECUTE_OPERATION_TIMINGS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); +
BUILD_READ_REGISTER()is always called withERST_VALUE_OFFSETas second argument. WE should eliminate this repeated passing of same argument.Quoted 34 lines
hw/acpi/erst.c +27
-1+/* 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
Re: [PATCH v13 06/10] ACPI ERST: build the ACPI ERST table
Quoted 137 lines · Eric DeVolder
Hi Michael,
Thanks for examining this! Inline response below.
ericQuoted 123 lines · Michael S. Tsirkin
Quoted 122 lines · Ani Sinha
Quoted 118 lines · Eric DeVolder
This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.
Signed-off-by Eric DeVolder <[email protected]>--- hw/acpi/erst.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+)hw/acpi/erst.c +95
-0@@ -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,173 @@ typedef struct {/*******************************************************************/ /*******************************************************************/ + +/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */ +static void build_serialization_instruction_entry (GArray *table_data, +uint8_t serialization_action, +uint8_t instruction, +uint8_t flags, +uint8_t register_bit_width, +uint64_t register_address, +uint64_t value) +{ +/* ACPI 4.0: Table 17-18 Serialization Instruction Entry */ +struct AcpiGenericAddress gas; +uint64_t mask; + +/* Serialization Action */ +build_append_int_noprefix (table_data, serialization_action,1 ); +/* Instruction */ +build_append_int_noprefix (table_data, instruction ,1 ); +/* Flags */ +build_append_int_noprefix (table_data, flags ,1 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Register Region */ + gas.space_id =AML_SYSTEM_MEMORY ; + gas.bit_width = register_bit_width; + gas.bit_offset =0 ; + gas.access_width =ctz32 (register_bit_width) -2 ; + gas.address = register_address; +build_append_gas_from_struct (table_data, &gas); +/* Value */ +build_append_int_noprefix (table_data, value ,8 ); +/* Mask */ + mask = (1ULL << (register_bit_width -1 ) <<1 ) -1 ; +build_append_int_noprefix (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) +{ +GArray *table_instruction_data; +unsigned action; +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 }; + +trace_acpi_erst_pci_bar_0 (bar0); + +/* +* 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. +*/ + table_instruction_data =g_array_new (FALSE, FALSE,sizeof (char )); + +/* +* Macros for use with construction of the action instructions +*/ +#define BUILD_READ_REGISTER (width_in_bits, reg) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER, 0, width_in_bits, \ + bar0 + reg, 0) + +#define BUILD_READ_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER, 0, width_in_bits, \ + bar0 + reg, value) +Quoted 8 lines
Quoted 4 lines
hw/acpi/erst.c typedef struct { · line 273
Quoted 4 lines
hw/acpi/erst.c +4
-0+#define BUILD_WRITE_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value)I think these macros which in a hidden way use the bar0 variable really should be replaced with inline functions, improving type safety.
Quoted 2 lines
I had not stated this previously, but my choice for using macros over functions was the use three local variables:
table_instruction_data, bar0, and action.
Oh, didn't notice the others too.
Quoted 2 lines
Any function would then automatically require these three as parameters, or I'm stuffing these temporary items into local globals (to avoid passing as parameters).
Please, no globals.
Quoted 4 lines
As for the type safety of bar0, I don't quite understand what I should do differently (regardless of macro vs function). Ultimately these call
build_serialization_instruction_entry()with the 'uint64_tregister address' accepting the bar0+offset value. Bar0 ispcibar_tand the compiler happily implicitly typecasts touint64_t.
The other way could warn though - maybe we should build with -Wconversion. That's going to require quite a bit of work though.
Quoted 1 line
What would an acceptable function prototype look like?
Well, that's a limitation of C. We can pass a
structure if you really need to save some code lines but that's really all we can do.
Quoted 121 lines
Quoted 121 lines
Quoted 120 lines
Quoted 16 lines
hw/acpi/erst.c +11
-0+ +/* Serialization Instruction Entries */ + action =ACTION_BEGIN_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_READ_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_CLEAR_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +hw/acpi/erst.c typedef struct { · line 294
Quoted 10 lines
hw/acpi/erst.c +10
-0+ action =ACTION_END_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_SET_RECORD_OFFSET ; +BUILD_WRITE_REGISTER (32 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_EXECUTE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET , +ERST_EXECUTE_OPERATION_MAGIC );except here, on all cases we have
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);We should treat the above as special case and simplify the rest of the calls (eliminate repeated common arguments).
Quoted 7 lines
hw/acpi/erst.c +7
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_CHECK_BUSY_STATUS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET ,0x01 ); + + action =ACTION_GET_COMMAND_STATUS ;hw/acpi/erst.c typedef struct { · line 311
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_SET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER (64 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);This one seems reverted. Should this be
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0);like others?
Quoted 14 lines
hw/acpi/erst.c +14
-0+ + action =ACTION_GET_RECORD_COUNT ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_BEGIN_DUMMY_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_LENGTH ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);hw/acpi/erst.c typedef struct { · line 335
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_EXECUTE_OPERATION_TIMINGS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); +
BUILD_READ_REGISTER()is always called withERST_VALUE_OFFSETas second argument. WE should eliminate this repeated passing of same argument.Quoted 34 lines
hw/acpi/erst.c +27
-1+/* 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
Re: [PATCH v13 06/10] ACPI ERST: build the ACPI ERST table
In reply to Eric DeVolderQuoted 144 lines · Eric DeVolder
Ani,
Thanks for the feedback! Inline responses below.
ericQuoted 139 lines · Ani Sinha
Quoted 135 lines · Eric DeVolder
This builds the ACPI ERST table to inform OSPM how to communicate with the acpi-erst device.
Signed-off-by Eric DeVolder <[email protected]>--- hw/acpi/erst.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+)hw/acpi/erst.c +112
-0@@ -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,173 @@ typedef struct {/*******************************************************************/ /*******************************************************************/ + +/* ACPI 4.0: 17.4.1.2 Serialization Instruction Entries */ +static void build_serialization_instruction_entry (GArray *table_data, +uint8_t serialization_action, +uint8_t instruction, +uint8_t flags, +uint8_t register_bit_width, +uint64_t register_address, +uint64_t value) +{ +/* ACPI 4.0: Table 17-18 Serialization Instruction Entry */ +struct AcpiGenericAddress gas; +uint64_t mask; + +/* Serialization Action */ +build_append_int_noprefix (table_data, serialization_action,1 ); +/* Instruction */ +build_append_int_noprefix (table_data, instruction ,1 ); +/* Flags */ +build_append_int_noprefix (table_data, flags ,1 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Register Region */ + gas.space_id =AML_SYSTEM_MEMORY ; + gas.bit_width = register_bit_width; + gas.bit_offset =0 ; + gas.access_width =ctz32 (register_bit_width) -2 ; + gas.address = register_address; +build_append_gas_from_struct (table_data, &gas); +/* Value */ +build_append_int_noprefix (table_data, value ,8 ); +/* Mask */ + mask = (1ULL << (register_bit_width -1 ) <<1 ) -1 ; +build_append_int_noprefix (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) +{ +GArray *table_instruction_data; +unsigned action; +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 }; + +trace_acpi_erst_pci_bar_0 (bar0); + +/* +* 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. +*/ + table_instruction_data =g_array_new (FALSE, FALSE,sizeof (char )); + +/* +* Macros for use with construction of the action instructions +*/ +#define BUILD_READ_REGISTER (width_in_bits, reg) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER, 0, width_in_bits, \ + bar0 + reg, 0) + +#define BUILD_READ_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER, 0, width_in_bits, \ + bar0 + reg, value) + +#define BUILD_WRITE_REGISTER_VALUE (width_in_bits, reg, value) \ + build_serialization_instruction_entry(table_instruction_data, \ + action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \ + bar0 + reg, value) + +/* Serialization Instruction Entries */ + action =ACTION_BEGIN_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_READ_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_BEGIN_CLEAR_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_END_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);
Quoted 8 lines
Quoted 8 lines
hw/acpi/erst.c typedef struct { · line 294
Quoted 8 lines
hw/acpi/erst.c +8
-0+ + action =ACTION_SET_RECORD_OFFSET ; +BUILD_WRITE_REGISTER (32 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_EXECUTE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET , +ERST_EXECUTE_OPERATION_MAGIC );
So e.g.
typedef struct {
GArray *table_data;
uint8_t register_bit_width;
pcibus_t bar;
unsigned register;
} BuildSerializationInstructionEntry;void build_serialization_instruction_entry(BuildSerializationInstructionEntry *)
and now
BuildSerializationInstructionEntry entry = {
.table_data = table_instruction_data,
bar = bar0,
};BuildSerializationInstructionEntry write32 = {
.table_data = entry.table_data,
.bar = entry.bar,
.register_bit_width = 32,
.register = ERST_ACTION_OFFSET
};
etc.
you can move common fields into structure, uncommon ones out of it.
Quoted 204 lines
Quoted 6 lines
except here, on all cases we have
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);We should treat the above as special case and simplify the rest of the calls (eliminate repeated common arguments).
OK, I created
BUILD_WRITE_ACTION()to replace this occurrence. I've provided what this section of code looks like with this and the other below change at the end.I have seen the comment from Michael and you about using inline functions, I will respond to that in the other message.
Quoted 23 lines
Quoted 8 lines
hw/acpi/erst.c +7
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_CHECK_BUSY_STATUS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET ,0x01 ); + + action =ACTION_GET_COMMAND_STATUS ;hw/acpi/erst.c typedef struct { · line 311
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_SET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER (64 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);This one seems reverted. Should this be
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0);Quoted 1 line
like others?
This is a SET operation, so the data is provided in VALUE register, then the ACTION is written to perform the command, ie record the value.
Quoted 20 lines
Quoted 20 lines
hw/acpi/erst.c +19
-0+ + action =ACTION_GET_RECORD_COUNT ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_BEGIN_DUMMY_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_LENGTH ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET );Quoted 8 lines
hw/acpi/erst.c typedef struct { · line 335
Quoted 5 lines
hw/acpi/erst.c +5
-0+ + action =ACTION_GET_EXECUTE_OPERATION_TIMINGS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); +
BUILD_READ_REGISTER()is always called withERST_VALUE_OFFSETas second argument. WE should eliminate this repeated passing of same argument.The
BUILD_READ_REGISTERis always against the VALUE register, as you point out, so I've s/BUILD_READ_REGISTER/BUILD_READ_VALUE/ and embedded the offset in the macro now. You can see this below.Quoted 28 lines
Quoted 28 lines
hw/acpi/erst.c +26
-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); +} + +/*******************************************************************/ Quoted 8 lines
Quoted 8 lines
hw/acpi/erst.c +1
-1+/*******************************************************************/ static uint8_t *get_nvram_ptr_by_index (ERSTDeviceState *s,unsigned index) {uint8_t *rc =NULL ; --1.8.3.1
And here is what the main snippet looks like with the above changes (a diff is quite messy):
/* * Macros for use with construction of the action instructions */ #define BUILD_READ_VALUE(width_in_bits) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_READ_REGISTER, 0, width_in_bits, \ bar0 + ERST_VALUE_OFFSET, 0)#define BUILD_READ_VALUE_VALUE(width_in_bits, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ bar0 + ERST_VALUE_OFFSET, value)#define BUILD_WRITE_REGISTER(width_in_bits, reg, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_WRITE_REGISTER, 0, width_in_bits, \ bar0 + reg, value)#define BUILD_WRITE_REGISTER_VALUE(width_in_bits, reg, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \ bar0 + reg, value)#define BUILD_WRITE_ACTION() \ BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action) /* Serialization Instruction Entries */ action = ACTION_BEGIN_WRITE_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_BEGIN_READ_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_BEGIN_CLEAR_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_END_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_SET_RECORD_OFFSET; BUILD_WRITE_REGISTER(32, ERST_VALUE_OFFSET, 0); BUILD_WRITE_ACTION(); action = ACTION_EXECUTE_OPERATION; BUILD_WRITE_REGISTER_VALUE(32, ERST_VALUE_OFFSET, ERST_EXECUTE_OPERATION_MAGIC); BUILD_WRITE_ACTION(); action = ACTION_CHECK_BUSY_STATUS; BUILD_WRITE_ACTION(); BUILD_READ_VALUE_VALUE(32, 0x01); action = ACTION_GET_COMMAND_STATUS; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(32); action = ACTION_GET_RECORD_IDENTIFIER; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64); action = ACTION_SET_RECORD_IDENTIFIER; BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0); BUILD_WRITE_ACTION(); action = ACTION_GET_RECORD_COUNT; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(32); action = ACTION_BEGIN_DUMMY_WRITE_OPERATION; BUILD_WRITE_ACTION(); BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action); action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64); action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64); action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(32); action = ACTION_GET_EXECUTE_OPERATION_TIMINGS; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64); /* Serialization Header */
Re: [PATCH v13 06/10] ACPI ERST: build the ACPI ERST table
In reply to Eric DeVolderQuoted 58 lines · Eric DeVolder
Ani,
Thanks for the feedback! Inline responses below.
ericQuoted 20 lines · Ani Sinha
Quoted 6 lines
hw/acpi/erst.c +4
-0+ + action =ACTION_BEGIN_CLEAR_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +hw/acpi/erst.c typedef struct { · line 294
Quoted 10 lines
hw/acpi/erst.c +10
-0+ action =ACTION_END_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_SET_RECORD_OFFSET ; +BUILD_WRITE_REGISTER (32 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_EXECUTE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET , +ERST_EXECUTE_OPERATION_MAGIC );except here, on all cases we have
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);Quoted 2 lines
We should treat the above as special case and simplify the rest of the calls (eliminate repeated common arguments).
OK, I created
BUILD_WRITE_ACTION()to replace this occurrence. I've provided what this section of code looks like with this and the other below change at the end.I have seen the comment from Michael and you about using inline functions, I will respond to that in the other message.
Quoted 23 lines
Quoted 8 lines
hw/acpi/erst.c +7
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_CHECK_BUSY_STATUS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET ,0x01 ); + + action =ACTION_GET_COMMAND_STATUS ;hw/acpi/erst.c typedef struct { · line 311
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_SET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER (64 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);This one seems reverted. Should this be
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0);
Quoted 5 lines
Quoted 1 line
like others?
This is a SET operation, so the data is provided in VALUE register, then the ACTION is written to perform the command, ie record the value.
Ok I see. makes sense.
Quoted 119 lines
Quoted 20 lines
Quoted 20 lines
hw/acpi/erst.c +19
-0+ + action =ACTION_GET_RECORD_COUNT ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_BEGIN_DUMMY_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_LENGTH ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET );Quoted 8 lines
hw/acpi/erst.c typedef struct { · line 335
Quoted 5 lines
hw/acpi/erst.c +5
-0+ + action =ACTION_GET_EXECUTE_OPERATION_TIMINGS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); +
BUILD_READ_REGISTER()is always called withERST_VALUE_OFFSETas second argument. WE should eliminate this repeated passing of same argument.The
BUILD_READ_REGISTERis always against the VALUE register, as you point out,
so I've s/BUILD_READ_REGISTER/BUILD_READ_VALUE/ and embedded the offset in the macro now. You can see this below.And here is what the main snippet looks like with the above changes (a diff is quite messy):
/* * Macros for use with construction of the action instructions */ #define BUILD_READ_VALUE(width_in_bits) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_READ_REGISTER, 0, width_in_bits, \ bar0 + ERST_VALUE_OFFSET, 0)#define BUILD_READ_VALUE_VALUE(width_in_bits, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ bar0 + ERST_VALUE_OFFSET, value)#define BUILD_WRITE_REGISTER(width_in_bits, reg, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_WRITE_REGISTER, 0, width_in_bits, \ bar0 + reg, value)#define BUILD_WRITE_REGISTER_VALUE(width_in_bits, reg, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \ bar0 + reg, value)#define BUILD_WRITE_ACTION() \ BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action) /* Serialization Instruction Entries */ action = ACTION_BEGIN_WRITE_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_BEGIN_READ_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_BEGIN_CLEAR_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_END_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_SET_RECORD_OFFSET; BUILD_WRITE_REGISTER(32, ERST_VALUE_OFFSET, 0); BUILD_WRITE_ACTION(); action = ACTION_EXECUTE_OPERATION; BUILD_WRITE_REGISTER_VALUE(32, ERST_VALUE_OFFSET, ERST_EXECUTE_OPERATION_MAGIC); BUILD_WRITE_ACTION(); action = ACTION_CHECK_BUSY_STATUS; BUILD_WRITE_ACTION(); BUILD_READ_VALUE_VALUE(32, 0x01); action = ACTION_GET_COMMAND_STATUS; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(32); action = ACTION_GET_RECORD_IDENTIFIER; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64); action = ACTION_SET_RECORD_IDENTIFIER; BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0); BUILD_WRITE_ACTION(); action = ACTION_GET_RECORD_COUNT; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(32); action = ACTION_BEGIN_DUMMY_WRITE_OPERATION; BUILD_WRITE_ACTION(); BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action); action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64); action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64); action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
Quoted 8 lines
BUILD_WRITE_ACTION();
BUILD_READ_VALUE(32);
action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
BUILD_WRITE_ACTION();
BUILD_READ_VALUE(64);
/* Serialization Header */Yes this looks a lot cleaner. Now as Michael suggested, we can convert them to inline functions and pass a struct with the common params. Maybe we can use a macro also to make things even more cleaner. Like calling the inline function from the macro with the common struct. I am trying to avoid repeated copy-paste code.
Re: [PATCH v13 06/10] ACPI ERST: build the ACPI ERST table
In reply to Eric DeVolderQuoted 21 lines · Eric DeVolder
And here is what the main snippet looks like with the above changes (a diff is quite messy):
/* * Macros for use with construction of the action instructions */ #define BUILD_READ_VALUE(width_in_bits) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_READ_REGISTER, 0, width_in_bits, \ bar0 + ERST_VALUE_OFFSET, 0)#define BUILD_READ_VALUE_VALUE(width_in_bits, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ bar0 + ERST_VALUE_OFFSET, value)#define BUILD_WRITE_REGISTER(width_in_bits, reg, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_WRITE_REGISTER, 0, width_in_bits, \ bar0 + reg, value)
Quoted 4 lines
#define BUILD_WRITE_REGISTER_VALUE(width_in_bits, reg, value) \
build_serialization_instruction_entry(table_instruction_data, \
action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \
bar0 + reg, value)Please, don't hide variable accesses in macros like that. whatever is accessed should be part of a parameter.
Signature · 1 line
MST
Re: [PATCH v13 06/10] ACPI ERST: build the ACPI ERST table
In reply to Ani SinhaAni, Michael,
An inline response at the bottom.
Thanks!
eric
Quoted 196 lines · Ani Sinha
Quoted 58 lines · Eric DeVolder
Ani,
Thanks for the feedback! Inline responses below.
ericQuoted 20 lines · Ani Sinha
Quoted 6 lines
hw/acpi/erst.c +4
-0+ + action =ACTION_BEGIN_CLEAR_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +hw/acpi/erst.c typedef struct { · line 294
Quoted 10 lines
hw/acpi/erst.c +10
-0+ action =ACTION_END_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_SET_RECORD_OFFSET ; +BUILD_WRITE_REGISTER (32 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_EXECUTE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET , +ERST_EXECUTE_OPERATION_MAGIC );except here, on all cases we have
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);Quoted 2 lines
We should treat the above as special case and simplify the rest of the calls (eliminate repeated common arguments).
OK, I created
BUILD_WRITE_ACTION()to replace this occurrence. I've provided what this section of code looks like with this and the other below change at the end.I have seen the comment from Michael and you about using inline functions, I will respond to that in the other message.
Quoted 23 lines
Quoted 8 lines
hw/acpi/erst.c +7
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_CHECK_BUSY_STATUS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER_VALUE (32 ,ERST_VALUE_OFFSET ,0x01 ); + + action =ACTION_GET_COMMAND_STATUS ;hw/acpi/erst.c typedef struct { · line 311
Quoted 10 lines
hw/acpi/erst.c +10
-0+BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_SET_RECORD_IDENTIFIER ; +BUILD_WRITE_REGISTER (64 ,ERST_VALUE_OFFSET ,0 ); +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action);This one seems reverted. Should this be
BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action);BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0);Quoted 5 lines
Quoted 1 line
like others?
This is a SET operation, so the data is provided in VALUE register, then the ACTION is written to perform the command, ie record the value.
Ok I see. makes sense.
Quoted 126 lines
Quoted 20 lines
Quoted 20 lines
hw/acpi/erst.c +19
-0+ + action =ACTION_GET_RECORD_COUNT ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET ); + + action =ACTION_BEGIN_DUMMY_WRITE_OPERATION ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_LENGTH ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); + + action =ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (32 ,ERST_VALUE_OFFSET );Quoted 8 lines
hw/acpi/erst.c typedef struct { · line 335
Quoted 5 lines
hw/acpi/erst.c +5
-0+ + action =ACTION_GET_EXECUTE_OPERATION_TIMINGS ; +BUILD_WRITE_REGISTER_VALUE (32 ,ERST_ACTION_OFFSET , action); +BUILD_READ_REGISTER (64 ,ERST_VALUE_OFFSET ); +
BUILD_READ_REGISTER()is always called withERST_VALUE_OFFSETas second argument. WE should eliminate this repeated passing of same argument.The
BUILD_READ_REGISTERis always against the VALUE register, as you point out,
so I've s/BUILD_READ_REGISTER/BUILD_READ_VALUE/ and embedded the offset in the macro now. You can see this below.And here is what the main snippet looks like with the above changes (a diff is quite messy):
/* * Macros for use with construction of the action instructions */ #define BUILD_READ_VALUE(width_in_bits) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_READ_REGISTER, 0, width_in_bits, \ bar0 + ERST_VALUE_OFFSET, 0)#define BUILD_READ_VALUE_VALUE(width_in_bits, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_READ_REGISTER_VALUE, 0, width_in_bits, \ bar0 + ERST_VALUE_OFFSET, value)#define BUILD_WRITE_REGISTER(width_in_bits, reg, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_WRITE_REGISTER, 0, width_in_bits, \ bar0 + reg, value)#define BUILD_WRITE_REGISTER_VALUE(width_in_bits, reg, value) \ build_serialization_instruction_entry(table_instruction_data, \ action, INST_WRITE_REGISTER_VALUE, 0, width_in_bits, \ bar0 + reg, value)#define BUILD_WRITE_ACTION() \ BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action) /* Serialization Instruction Entries */ action = ACTION_BEGIN_WRITE_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_BEGIN_READ_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_BEGIN_CLEAR_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_END_OPERATION; BUILD_WRITE_ACTION(); action = ACTION_SET_RECORD_OFFSET; BUILD_WRITE_REGISTER(32, ERST_VALUE_OFFSET, 0); BUILD_WRITE_ACTION(); action = ACTION_EXECUTE_OPERATION; BUILD_WRITE_REGISTER_VALUE(32, ERST_VALUE_OFFSET, ERST_EXECUTE_OPERATION_MAGIC); BUILD_WRITE_ACTION(); action = ACTION_CHECK_BUSY_STATUS; BUILD_WRITE_ACTION(); BUILD_READ_VALUE_VALUE(32, 0x01); action = ACTION_GET_COMMAND_STATUS; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(32); action = ACTION_GET_RECORD_IDENTIFIER; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64); action = ACTION_SET_RECORD_IDENTIFIER; BUILD_WRITE_REGISTER(64, ERST_VALUE_OFFSET, 0); BUILD_WRITE_ACTION(); action = ACTION_GET_RECORD_COUNT; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(32); action = ACTION_BEGIN_DUMMY_WRITE_OPERATION; BUILD_WRITE_ACTION(); BUILD_WRITE_REGISTER_VALUE(32, ERST_ACTION_OFFSET, action); action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64); action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64); action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(32); action = ACTION_GET_EXECUTE_OPERATION_TIMINGS; BUILD_WRITE_ACTION(); BUILD_READ_VALUE(64);
Quoted 8 lines
Quoted 1 line
/* Serialization Header */Yes this looks a lot cleaner. Now as Michael suggested, we can convert them to inline functions and pass a struct with the common params. Maybe we can use a macro also to make things even more cleaner. Like calling the inline function from the macro with the common struct. I am trying to avoid repeated copy-paste code.
OK, I've converted the above to utilize a context structure that Michael outlined, and a function call, rather than macro (as above), to generate the table content.
Without using macros, I think this code is about as simplified as can be.
As this has significant changes, I'll post as v14. Note that the code grew by about 35 lines, not too bad.
eric