From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, drjones@redhat.com,
shannon.zhaosl@gmail.com, mst@redhat.com,
Eric Auger <eric.auger@redhat.com>,
qemu-arm@nongnu.org
Subject: [PATCH v3 31/35] acpi: arm/virt: build_spcr: use acpi_table_begin()/acpi_table_end() instead of build_header()
Date: Tue, 7 Sep 2021 10:48:10 -0400 [thread overview]
Message-ID: <20210907144814.741785-32-imammedo@redhat.com> (raw)
In-Reply-To: <20210907144814.741785-1-imammedo@redhat.com>
it replaces error-prone pointer arithmetic for build_header() API,
with 2 calls to start and finish table creation,
which hides offsets magic from API user.
while at it, replace packed structure with endian agnostic
build_append_FOO() API.
PS:
Spec is Microsoft hosted, however 1.02 is no where to be found
(MS lists only the current revision) and the current revision is 1.07,
so bring comments in line with 1.07 as this is the only available spec.
There is no content change between originally implemented 1.02
(using QEMU code as reference) and 1.07. The only change is renaming
'Reserved2' field to 'Language', with the same 0 value.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
---
v3:
* s/acpi_init_table|acpi_table_composed/acpi_table_begin|acpi_table_end/
PS:
perhaps we should cache MS hosted specs in QEMU tree, given they do not
maintain old revisions.
CC: drjones@redhat.com
CC: peter.maydell@linaro.org
CC: shannon.zhaosl@gmail.com
CC: qemu-arm@nongnu.org
---
include/hw/acpi/acpi-defs.h | 32 -----------------
hw/arm/virt-acpi-build.c | 68 ++++++++++++++++++++++---------------
2 files changed, 41 insertions(+), 59 deletions(-)
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index 6f2f08a9de..012c4ffb3a 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -117,38 +117,6 @@ typedef struct AcpiFadtData {
#define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0)
#define ACPI_FADT_ARM_PSCI_USE_HVC (1 << 1)
-/*
- * Serial Port Console Redirection Table (SPCR), Rev. 1.02
- *
- * For .interface_type see Debug Port Table 2 (DBG2) serial port
- * subtypes in Table 3, Rev. May 22, 2012
- */
-struct AcpiSerialPortConsoleRedirection {
- ACPI_TABLE_HEADER_DEF
- uint8_t interface_type;
- uint8_t reserved1[3];
- struct AcpiGenericAddress base_address;
- uint8_t interrupt_types;
- uint8_t irq;
- uint32_t gsi;
- uint8_t baud;
- uint8_t parity;
- uint8_t stopbits;
- uint8_t flowctrl;
- uint8_t term_type;
- uint8_t reserved2;
- uint16_t pci_device_id;
- uint16_t pci_vendor_id;
- uint8_t pci_bus;
- uint8_t pci_slot;
- uint8_t pci_func;
- uint32_t pci_flags;
- uint8_t pci_seg;
- uint32_t reserved3;
-} QEMU_PACKED;
-typedef struct AcpiSerialPortConsoleRedirection
- AcpiSerialPortConsoleRedirection;
-
/*
* ACPI 1.0 Firmware ACPI Control Structure (FACS)
*/
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 50ed73b9d0..ea783128a9 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -447,39 +447,53 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
g_array_free(its_idmaps, true);
}
+/*
+ * Serial Port Console Redirection Table (SPCR)
+ * Rev: 1.07
+ */
static void
build_spcr(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
{
- AcpiSerialPortConsoleRedirection *spcr;
- const MemMapEntry *uart_memmap = &vms->memmap[VIRT_UART];
- int irq = vms->irqmap[VIRT_UART] + ARM_SPI_BASE;
- int spcr_start = table_data->len;
-
- spcr = acpi_data_push(table_data, sizeof(*spcr));
-
- spcr->interface_type = 0x3; /* ARM PL011 UART */
-
- spcr->base_address.space_id = AML_AS_SYSTEM_MEMORY;
- spcr->base_address.bit_width = 8;
- spcr->base_address.bit_offset = 0;
- spcr->base_address.access_width = 1;
- spcr->base_address.address = cpu_to_le64(uart_memmap->base);
-
- spcr->interrupt_types = (1 << 3); /* Bit[3] ARMH GIC interrupt */
- spcr->gsi = cpu_to_le32(irq); /* Global System Interrupt */
+ AcpiTable table = { .sig = "SPCR", .rev = 2, .oem_id = vms->oem_id,
+ .oem_table_id = vms->oem_table_id };
- spcr->baud = 3; /* Baud Rate: 3 = 9600 */
- spcr->parity = 0; /* No Parity */
- spcr->stopbits = 1; /* 1 Stop bit */
- spcr->flowctrl = (1 << 1); /* Bit[1] = RTS/CTS hardware flow control */
- spcr->term_type = 0; /* Terminal Type: 0 = VT100 */
+ acpi_table_begin(&table, table_data);
- spcr->pci_device_id = 0xffff; /* PCI Device ID: not a PCI device */
- spcr->pci_vendor_id = 0xffff; /* PCI Vendor ID: not a PCI device */
+ /* Interface Type */
+ build_append_int_noprefix(table_data, 3, 1); /* ARM PL011 UART */
+ build_append_int_noprefix(table_data, 0, 3); /* Reserved */
+ /* Base Address */
+ build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 8, 0, 1,
+ vms->memmap[VIRT_UART].base);
+ /* Interrupt Type */
+ build_append_int_noprefix(table_data,
+ (1 << 3) /* Bit[3] ARMH GIC interrupt */, 1);
+ build_append_int_noprefix(table_data, 0, 1); /* IRQ */
+ /* Global System Interrupt */
+ build_append_int_noprefix(table_data,
+ vms->irqmap[VIRT_UART] + ARM_SPI_BASE, 4);
+ build_append_int_noprefix(table_data, 3 /* 9600 */, 1); /* Baud Rate */
+ build_append_int_noprefix(table_data, 0 /* No Parity */, 1); /* Parity */
+ /* Stop Bits */
+ build_append_int_noprefix(table_data, 1 /* 1 Stop bit */, 1);
+ /* Flow Control */
+ build_append_int_noprefix(table_data,
+ (1 << 1) /* RTS/CTS hardware flow control */, 1);
+ /* Terminal Type */
+ build_append_int_noprefix(table_data, 0 /* VT100 */, 1);
+ build_append_int_noprefix(table_data, 0, 1); /* Language */
+ /* PCI Device ID */
+ build_append_int_noprefix(table_data, 0xffff /* not a PCI device*/, 2);
+ /* PCI Vendor ID */
+ build_append_int_noprefix(table_data, 0xffff /* not a PCI device*/, 2);
+ build_append_int_noprefix(table_data, 0, 1); /* PCI Bus Number */
+ build_append_int_noprefix(table_data, 0, 1); /* PCI Device Number */
+ build_append_int_noprefix(table_data, 0, 1); /* PCI Function Number */
+ build_append_int_noprefix(table_data, 0, 4); /* PCI Flags */
+ build_append_int_noprefix(table_data, 0, 1); /* PCI Segment */
+ build_append_int_noprefix(table_data, 0, 4); /* Reserved */
- build_header(linker, table_data, (void *)(table_data->data + spcr_start),
- "SPCR", table_data->len - spcr_start, 2, vms->oem_id,
- vms->oem_table_id);
+ acpi_table_end(linker, &table);
}
/*
--
2.27.0
next prev parent reply other threads:[~2021-09-07 15:14 UTC|newest]
Thread overview: 79+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-07 14:47 [PATCH v3 00/35] acpi: refactor error prone build_header() and packed structures usage in ACPI tables Igor Mammedov
2021-09-07 14:47 ` [PATCH v3 01/35] acpi: add helper routines to initialize " Igor Mammedov
2021-09-20 16:21 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 02/35] acpi: build_rsdt: use acpi_table_begin()/acpi_table_end() instead of build_header() Igor Mammedov
2021-09-20 16:21 ` Eric Auger
2021-09-21 9:13 ` Igor Mammedov
2021-09-07 14:47 ` [PATCH v3 03/35] acpi: build_xsdt: " Igor Mammedov
2021-09-20 16:21 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 04/35] acpi: build_slit: " Igor Mammedov
2021-09-20 16:24 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 05/35] acpi: build_fadt: " Igor Mammedov
2021-09-20 16:25 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 06/35] acpi: build_tpm2: " Igor Mammedov
2021-09-07 14:47 ` [PATCH v3 07/35] acpi: acpi_build_hest: " Igor Mammedov
2021-09-20 16:27 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 08/35] acpi: build_mcfg: " Igor Mammedov
2021-09-20 16:28 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 09/35] acpi: build_hmat: " Igor Mammedov
2021-09-20 16:33 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 10/35] acpi: nvdimm_build_nfit: " Igor Mammedov
2021-09-20 16:36 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 11/35] acpi: nvdimm_build_ssdt: " Igor Mammedov
2021-09-20 16:41 ` Eric Auger
2021-09-22 14:38 ` Igor Mammedov
2021-09-07 14:47 ` [PATCH v3 12/35] acpi: vmgenid_build_acpi: " Igor Mammedov
2021-09-22 7:23 ` Eric Auger
2021-09-22 14:46 ` Igor Mammedov
2021-09-07 14:47 ` [PATCH v3 13/35] acpi: x86: build_dsdt: " Igor Mammedov
2021-09-07 14:47 ` [PATCH v3 14/35] acpi: build_hpet: " Igor Mammedov
2021-09-07 14:47 ` [PATCH v3 15/35] acpi: build_tpm_tcpa: " Igor Mammedov
2021-09-22 7:23 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 16/35] acpi: arm/x86: build_srat: " Igor Mammedov
2021-09-22 7:38 ` Eric Auger
2021-09-22 15:02 ` Igor Mammedov
2021-09-07 14:47 ` [PATCH v3 17/35] acpi: use build_append_int_noprefix() API to compose SRAT table Igor Mammedov
2021-09-22 8:55 ` Eric Auger
2021-09-22 10:02 ` Igor Mammedov
2021-09-22 15:32 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 18/35] acpi: build_dmar_q35: use acpi_table_begin()/acpi_table_end() instead of build_header() Igor Mammedov
2021-09-22 9:19 ` Eric Auger
2021-09-22 10:06 ` Igor Mammedov
2021-09-07 14:47 ` [PATCH v3 19/35] acpi: build_waet: " Igor Mammedov
2021-09-22 9:20 ` Eric Auger
2021-09-07 14:47 ` [PATCH v3 20/35] acpi: build_amd_iommu: " Igor Mammedov
2021-09-22 9:22 ` Eric Auger
2021-09-07 14:48 ` [PATCH v3 21/35] acpi: madt: arm/x86: " Igor Mammedov
2021-09-22 9:36 ` Eric Auger
2021-09-07 14:48 ` [PATCH v3 22/35] acpi: x86: remove dead code Igor Mammedov
2021-09-22 9:38 ` Eric Auger
2021-09-07 14:48 ` [PATCH v3 23/35] acpi: x86: set enabled when composing _MAT entries Igor Mammedov
2021-09-22 9:50 ` Eric Auger
2021-09-07 14:48 ` [PATCH v3 24/35] acpi: x86: madt: use build_append_int_noprefix() API to compose MADT table Igor Mammedov
2021-09-22 10:20 ` Eric Auger
2021-09-22 15:30 ` Igor Mammedov
2021-09-22 15:37 ` Eric Auger
2021-09-23 6:34 ` Igor Mammedov
2021-09-07 14:48 ` [PATCH v3 25/35] acpi: arm/virt: " Igor Mammedov
2021-09-07 14:48 ` [PATCH v3 26/35] acpi: build_dsdt_microvm: use acpi_table_begin()/acpi_table_end() instead of build_header() Igor Mammedov
2021-09-22 10:01 ` Eric Auger
2021-09-07 14:48 ` [PATCH v3 27/35] acpi: arm: virt: build_dsdt: " Igor Mammedov
2021-09-07 14:48 ` [PATCH v3 28/35] acpi: arm: virt: build_iort: " Igor Mammedov
2021-09-22 12:31 ` Eric Auger
2021-09-22 12:32 ` Eric Auger
2021-09-07 14:48 ` [PATCH v3 29/35] acpi: arm/virt: convert build_iort() to endian agnostic build_append_FOO() API Igor Mammedov
2021-09-22 13:26 ` Eric Auger
2021-09-22 13:54 ` Igor Mammedov
2021-09-22 15:31 ` Eric Auger
2021-09-23 7:47 ` [PATCH v4 " Igor Mammedov
2021-09-07 14:48 ` [PATCH v3 30/35] acpi: arm/virt: build_spcr: fix invalid cast Igor Mammedov
2021-09-07 14:48 ` Igor Mammedov [this message]
2021-09-07 14:48 ` [PATCH v3 32/35] acpi: arm/virt: build_gtdt: use acpi_table_begin()/acpi_table_end() instead of build_header() Igor Mammedov
2021-09-07 14:48 ` [PATCH v3 33/35] acpi: build_facs: use build_append_int_noprefix() API to compose table Igor Mammedov
2021-09-22 13:33 ` Eric Auger
2021-09-22 13:58 ` Igor Mammedov
2021-09-07 14:48 ` [PATCH v3 34/35] acpi: remove no longer used build_header() Igor Mammedov
2021-09-22 13:34 ` Eric Auger
2021-09-07 14:48 ` [PATCH v3 35/35] acpi: AcpiGenericAddress no longer used to map/access fields of MMIO, drop packed attribute Igor Mammedov
2021-09-22 13:34 ` Eric Auger
2021-09-22 14:03 ` [PATCH v3 00/35] acpi: refactor error prone build_header() and packed structures usage in ACPI tables Igor Mammedov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210907144814.741785-32-imammedo@redhat.com \
--to=imammedo@redhat.com \
--cc=drjones@redhat.com \
--cc=eric.auger@redhat.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=shannon.zhaosl@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).