Add basic ACPI support for risc-v virt
Subsystems (2)
v4 cover Add basic ACPI support for risc-v virt
This series adds the basic ACPI support for the RISC-V virt machine. Currently only RINTC interrupt controller specification is approved by the UEFI forum. External interrupt controller support in ACPI is in progress.
The basic infrastructure changes are mostly leveraged from ARM.
This adds support for RINTC and RHCT tables as specified in below ECR links which are approved by UEFI forum.
RINTC - https://drive.google.com/file/d/1R6k4MshhN3WTT-hwqAquu5nX6xSEqK2l/view
RHCT - https://drive.google.com/file/d/1nP3nFiH4jkPMp6COOxP6123DCZKR-tia/view
These changes are also available @
https://github.com/vlsunil/qemu/tree/acpi_b1_us_review_V4
Changes since V3:
1) Added back acpi_align_size() wrapper as per Drew's feedback
2) Updated RB tags
Changes since V2:
1) Squashed commits and updated commit message as per feedback from Daniel.
2) Addressed comments from Drew.
3) Updated tags.
Changes since V1:
1) Addressed comments from Bin Meng.
2) Made acpi switch default AUTO similar to other architectures.
3) Re-based and added RB and ACKs.
The series is tested using SBI HVC console and initrd.
Test instructions:
1) Build Qemu with ACPI support (this series)
2) Build EDK2 as per instructions in
https://github.com/vlsunil/riscv-uefi-edk2-docs/wiki/RISC-V-Qemu-Virt-support
3) Build Linux with ACPI support using below branch
https://github.com/vlsunil/linux/commits/acpi_b1_us_review_ipi17_V2
after enabling SBI HVC and SBI earlycon options.
CONFIG_RISCV_SBI_V01=yCONFIG_SERIAL_EARLYCON_RISCV_SBI=yCONFIG_HVC_RISCV_SBI=y
4) Build buildroot.
Run with below command.
qemu-system-riscv64 -nographic \
-drive file=Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT.fd,if=pflash,format=raw,unit=1 \
-machine virt -smp 16 -m 2G \
-kernel arch/riscv/boot/Image \
-initrd buildroot/output/images/rootfs.cpio \
-append "root=/dev/ram ro console=hvc0 earlycon=sbi"
Sunil V L (8):
hw/riscv/virt: Add OEM_ID and OEM_TABLE_ID fields hw/riscv/virt: Add a switch to disable ACPI hw/riscv/virt: Add memmap pointer to RiscVVirtState hw/riscv/virt: Enable basic ACPI infrastructure hw/riscv/virt: virt-acpi-build.c: Add RINTC in MADT hw/riscv/virt: virt-acpi-build.c: Add RHCT Table hw/riscv/virt.c: Initialize the ACPI tables
MAINTAINERS: Add entry for RISC-V ACPI
MAINTAINERS | 18 +- hw/riscv/Kconfig | 1 + hw/riscv/meson.build | 1 + hw/riscv/virt-acpi-build.c | 396 +++++++++++++++++++++++++++++++++++++ hw/riscv/virt.c | 40 ++++ include/hw/riscv/virt.h | 6 + 6 files changed, 456 insertions(+), 6 deletions(-) create mode 100644 hw/riscv/virt-acpi-build.c
Signature · 1 line
2.34.1
PATCH v4 1/8 hw/riscv/virt: Add OEM_ID and OEM_TABLE_ID fields
ACPI needs OEM_ID and OEM_TABLE_ID for the machine. Add these fields in the RISCVVirtState structure and initialize with default values.
--- hw/riscv/virt.c | 5 +++++ include/hw/riscv/virt.h | 2 ++ 2 files changed, 7 insertions(+)
hw/riscv/virt.c +5 -0
@@ -49,6 +49,7 @@#include "hw/pci/pci.h" #include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" +#include "hw/acpi/aml-build.h" /* * The virt machine physical address space used by some of the devices
@@ -1521,6 +1522,10 @@ static void virt_machine_init(MachineState *machine)static void virt_machine_instance_init (Object *obj) { +RISCVVirtState *s =RISCV_VIRT_MACHINE (obj); + + s->oem_id =g_strndup (ACPI_BUILD_APPNAME6 ,6 ); + s->oem_table_id =g_strndup (ACPI_BUILD_APPNAME8 ,8 ); }static char *virt_get_aia_guests (Object *obj,Error **errp)
include/hw/riscv/virt.h +2 -0
@@ -56,6 +56,8 @@ struct RISCVVirtState {bool have_aclint;RISCVVirtAIAType aia_type;int aia_guests; +char *oem_id; +char *oem_table_id; };enum {
Signature · 1 line
2.34.1
PATCH v4 2/8 hw/riscv/virt: Add a switch to disable ACPI
In reply to Sunil V LACPI will be enabled by default. Add a switch to turn off for testing and debug purposes.
--- hw/riscv/virt.c | 29 +++++++++++++++++++++++++++++ include/hw/riscv/virt.h | 2 ++ 2 files changed, 31 insertions(+)
hw/riscv/virt.c +29 -0
@@ -50,6 +50,7 @@#include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" #include "hw/acpi/aml-build.h" +#include "qapi/qapi-visit-common.h" /* * The virt machine physical address space used by some of the devices
@@ -1526,6 +1527,7 @@ static void virt_machine_instance_init(Object *obj) s->oem_id =g_strndup (ACPI_BUILD_APPNAME6 ,6 ); s->oem_table_id =g_strndup (ACPI_BUILD_APPNAME8 ,8 ); + s->acpi =ON_OFF_AUTO_AUTO ; }static char *virt_get_aia_guests (Object *obj,Error **errp)
@@ -1600,6 +1602,28 @@ static void virt_set_aclint(Object *obj, bool value, Error **errp) s->have_aclint = value; } +bool virt_is_acpi_enabled (RISCVVirtState *s) +{ +return s->acpi !=ON_OFF_AUTO_OFF ; +} + +static void virt_get_acpi (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVVirtState *s =RISCV_VIRT_MACHINE (obj); +OnOffAuto acpi = s->acpi; + +visit_type_OnOffAuto (v, name, &acpi, errp); +} + +static void virt_set_acpi (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVVirtState *s =RISCV_VIRT_MACHINE (obj); + +visit_type_OnOffAuto (v, name, &s->acpi, errp); +} +static HotplugHandler *virt_machine_get_hotplug_handler (MachineState *machine,DeviceState *dev) {
@@ -1671,6 +1695,11 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)sprintf (str,"Set number of guest MMIO pages for AIA IMSIC. Valid value " "should be between 0 and %d." ,VIRT_IRQCHIP_MAX_GUESTS );object_class_property_set_description (oc,"aia-guests" , str); +object_class_property_add (oc,"acpi" ,"OnOffAuto" , + virt_get_acpi, virt_set_acpi, +NULL ,NULL ); +object_class_property_set_description (oc,"acpi" , +"Enable ACPI" ); }static const TypeInfo virt_machine_typeinfo = {
include/hw/riscv/virt.h +2 -0
@@ -58,6 +58,7 @@ struct RISCVVirtState {int aia_guests;char *oem_id;char *oem_table_id; +OnOffAuto acpi; };enum {
@@ -123,4 +124,5 @@ enum {#define FDT_APLIC_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ 1 + FDT_APLIC_INT_CELLS) +bool virt_is_acpi_enabled (RISCVVirtState *s);#endif
Signature · 1 line
2.34.1
PATCH v4 3/8 hw/riscv/virt: Add memmap pointer to RiscVVirtState
In reply to Sunil V Lmemmap needs to be exported outside of virt.c so that modules like acpi can use it. Hence, add a pointer field in RiscVVirtState structure and initialize it with the memorymap.
--- hw/riscv/virt.c | 2 ++ include/hw/riscv/virt.h | 1 + 2 files changed, 3 insertions(+)
hw/riscv/virt.c +2 -0
@@ -1459,6 +1459,8 @@ static void virt_machine_init(MachineState *machine)ROUND_UP (virt_high_pcie_memmap.base, virt_high_pcie_memmap.size); } + s->memmap = virt_memmap; +/* register system main memory (actual RAM) */ memory_region_add_subregion (system_memory, memmap[VIRT_DRAM ].base, machine->ram);
include/hw/riscv/virt.h +1 -0
@@ -59,6 +59,7 @@ struct RISCVVirtState {char *oem_id;char *oem_table_id;OnOffAuto acpi; +const MemMapEntry *memmap; };enum {
Signature · 1 line
2.34.1
PATCH v4 4/8 hw/riscv/virt: Enable basic ACPI infrastructure
In reply to Sunil V LAdd basic ACPI infrastructure for RISC-V with below tables.
1) DSDT with below basic objects
- CPUs
- fw_cfg
2) FADT revision 6 with HW_REDUCED flag
3) XSDT
4) RSDP
Add this functionality in a new file virt-acpi-build.c and enable building this infrastructure.
--- hw/riscv/Kconfig | 1 + hw/riscv/meson.build | 1 + hw/riscv/virt-acpi-build.c | 276 +++++++++++++++++++++++++++++++++++++ include/hw/riscv/virt.h | 1 + 4 files changed, 279 insertions(+) create mode 100644 hw/riscv/virt-acpi-build.c
hw/riscv/Kconfig +1 -0
@@ -44,6 +44,7 @@ config RISCV_VIRT select VIRTIO_MMIO select FW_CFG_DMA select PLATFORM_BUS + select ACPI config SHAKTI_C bool
hw/riscv/meson.build +1 -0
@@ -9,5 +9,6 @@ riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) +riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) hw_arch += {'riscv': riscv_ss}
hw/riscv/virt-acpi-build.c new file +276 -0
276 lines not on this page · raw message
include/hw/riscv/virt.h +1 -0
@@ -126,4 +126,5 @@ enum { 1 + FDT_APLIC_INT_CELLS)bool virt_is_acpi_enabled (RISCVVirtState *s); +void virt_acpi_setup (RISCVVirtState *vms);#endif
Signature · 1 line
2.34.1
PATCH v4 5/8 hw/riscv/virt: virt-acpi-build.c: Add RINTC in MADT
In reply to Sunil V LAdd Multiple APIC Description Table (MADT) with the RINTC structure for each cpu.
--- hw/riscv/virt-acpi-build.c | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
hw/riscv/virt-acpi-build.c +44 -0
@@ -32,6 +32,7 @@#include "sysemu/reset.h" #include "migration/vmstate.h" #include "hw/riscv/virt.h" +#include "hw/riscv/numa.h" #define ACPI_BUILD_TABLE_SIZE 0x20000
@@ -132,6 +133,46 @@ static void build_dsdt(GArray *table_data,free_aml_allocator (); } +/* MADT */ +static void build_madt (GArray *table_data, +BIOSLinker *linker, +RISCVVirtState *s) +{ +MachineState *ms =MACHINE (s); +int socket; +uint16_t base_hartid =0 ; +uint32_t cpu_id =0 ; + +AcpiTable table = { .sig ="APIC" , .rev =6 , .oem_id = s->oem_id, + .oem_table_id = s->oem_table_id }; + +acpi_table_begin (&table, table_data); +/* Local Interrupt Controller Address */ +build_append_int_noprefix (table_data,0 ,4 ); +build_append_int_noprefix (table_data,0 ,4 );/* MADT Flags */ + +/* RISC-V Local INTC structures per HART */ +for (socket =0 ; socket <riscv_socket_count (ms); socket++) { + base_hartid =riscv_socket_first_hartid (ms, socket); + +for (int i =0 ; i < s->soc[socket].num_harts; i++) { +build_append_int_noprefix (table_data,0x18 ,1 );/* Type */ +build_append_int_noprefix (table_data,20 ,1 );/* Length */ +build_append_int_noprefix (table_data,1 ,1 );/* Version */ +build_append_int_noprefix (table_data,0 ,1 );/* Reserved */ +build_append_int_noprefix (table_data,1 ,4 );/* Flags */ +build_append_int_noprefix (table_data, + (base_hartid + i),8 );/* Hart ID */ + +/* ACPI Processor UID */ +build_append_int_noprefix (table_data, cpu_id,4 ); + cpu_id++; + } + } + +acpi_table_end (linker, &table); +} +static void virt_acpi_build (RISCVVirtState *s,AcpiBuildTables *tables) {GArray *table_offsets;
@@ -153,6 +194,9 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)acpi_add_table (table_offsets, tables_blob);build_fadt_rev6 (tables_blob, tables->linker, s, dsdt); +acpi_add_table (table_offsets, tables_blob); +build_madt (tables_blob, tables->linker, s); +/* XSDT is pointed to by RSDP */ xsdt = tables_blob->len; build_xsdt(tables_blob, tables->linker, table_offsets, s->oem_id,
Signature · 1 line
2.34.1
Re: [PATCH V4 5/8] hw/riscv/virt: virt-acpi-build.c: Add RINTC in MADT
Quoted 23 lines · On Fri, 24 Feb 2023 14:06:58 +0530 Sunil V L <[email protected]> wrote:
Add Multiple APIC Description Table (MADT) with the RINTC structure for each cpu.
Signed-off-by Sunil V L <[email protected]>Acked-by Alistair Francis <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- hw/riscv/virt-acpi-build.c | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)hw/riscv/virt-acpi-build.c +1
-0@@ -32,6 +32,7 @@#include "sysemu/reset.h" #include "migration/vmstate.h" #include "hw/riscv/virt.h" +#include "hw/riscv/numa.h" #define ACPI_BUILD_TABLE_SIZE 0x20000
hw/riscv/virt-acpi-build.c static void build_dsdt(GArray *table_data, · line 136
Quoted 4 lines
hw/riscv/virt-acpi-build.c +1
-0@@ -132,6 +133,46 @@ static void build_dsdt(GArray *table_data,free_aml_allocator (); } +/* MADT */
see build_srat() how this comment must look like
Quoted 22 lines
hw/riscv/virt-acpi-build.c +22
-0+static void build_madt (GArray *table_data, +BIOSLinker *linker, +RISCVVirtState *s) +{ +MachineState *ms =MACHINE (s); +int socket; +uint16_t base_hartid =0 ; +uint32_t cpu_id =0 ; + +AcpiTable table = { .sig ="APIC" , .rev =6 , .oem_id = s->oem_id, + .oem_table_id = s->oem_table_id }; + +acpi_table_begin (&table, table_data); +/* Local Interrupt Controller Address */ +build_append_int_noprefix (table_data,0 ,4 ); +build_append_int_noprefix (table_data,0 ,4 );/* MADT Flags */ + +/* RISC-V Local INTC structures per HART */ +for (socket =0 ; socket <riscv_socket_count (ms); socket++) { + base_hartid =riscv_socket_first_hartid (ms, socket); + +for (int i =0 ; i < s->soc[socket].num_harts; i++) {
hw/riscv/virt-acpi-build.c static void build_dsdt(GArray *table_data, · line 168
Quoted 10 lines
hw/riscv/virt-acpi-build.c +10
-0+build_append_int_noprefix (table_data,0x18 ,1 );/* Type */ +build_append_int_noprefix (table_data,20 ,1 );/* Length */ +build_append_int_noprefix (table_data,1 ,1 );/* Version */ +build_append_int_noprefix (table_data,0 ,1 );/* Reserved */ +build_append_int_noprefix (table_data,1 ,4 );/* Flags */ +build_append_int_noprefix (table_data, + (base_hartid + i),8 );/* Hart ID */ + +/* ACPI Processor UID */ +build_append_int_noprefix (table_data, cpu_id,4 );
cpu_id here seems to be unrelated to one in DSDT.
Could you explain how socket/hartid and cpu_id are related to each other?
Quoted 20 lines
hw/riscv/virt-acpi-build.c +10
-0+ cpu_id++; + } + } + +acpi_table_end (linker, &table); +} +static void virt_acpi_build (RISCVVirtState *s,AcpiBuildTables *tables) {GArray *table_offsets;@@ -153,6 +194,9 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)acpi_add_table (table_offsets, tables_blob);build_fadt_rev6 (tables_blob, tables->linker, s, dsdt); +acpi_add_table (table_offsets, tables_blob); +build_madt (tables_blob, tables->linker, s); +/* XSDT is pointed to by RSDP */ xsdt = tables_blob->len; build_xsdt(tables_blob, tables->linker, table_offsets, s->oem_id,
Re: [PATCH V4 5/8] hw/riscv/virt: virt-acpi-build.c: Add RINTC in MADT
Hi Igor,
Quoted 25 lines · Igor Mammedov
Quoted 22 lines · On Fri, 24 Feb 2023 14:06:58 +0530 Sunil V L <[email protected]> wrote:
Add Multiple APIC Description Table (MADT) with the RINTC structure for each cpu.
Signed-off-by Sunil V L <[email protected]>Acked-by Alistair Francis <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- hw/riscv/virt-acpi-build.c | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)hw/riscv/virt-acpi-build.c +1
-0@@ -32,6 +32,7 @@#include "sysemu/reset.h" #include "migration/vmstate.h" #include "hw/riscv/virt.h" +#include "hw/riscv/numa.h" #define ACPI_BUILD_TABLE_SIZE 0x20000
Quoted 8 lines
hw/riscv/virt-acpi-build.c static void build_dsdt(GArray *table_data, · line 136
Quoted 5 lines
hw/riscv/virt-acpi-build.c +1
-0@@ -132,6 +133,46 @@ static void build_dsdt(GArray *table_data,free_aml_allocator (); } +/* MADT */ see
build_srat()how this comment must look like
Currently, even though ECRs are approved, the ACPI spec is not released for these MADT structures. I can add the spec version for the generic MADT but not for the RINTC. Same issue with a new table RHCT. What is the recommendation in such case?
Quoted 27 lines
Quoted 27 lines
hw/riscv/virt-acpi-build.c +27
-0+static void build_madt (GArray *table_data, +BIOSLinker *linker, +RISCVVirtState *s) +{ +MachineState *ms =MACHINE (s); +int socket; +uint16_t base_hartid =0 ; +uint32_t cpu_id =0 ; + +AcpiTable table = { .sig ="APIC" , .rev =6 , .oem_id = s->oem_id, + .oem_table_id = s->oem_table_id }; + +acpi_table_begin (&table, table_data); +/* Local Interrupt Controller Address */ +build_append_int_noprefix (table_data,0 ,4 ); +build_append_int_noprefix (table_data,0 ,4 );/* MADT Flags */ + +/* RISC-V Local INTC structures per HART */ +for (socket =0 ; socket <riscv_socket_count (ms); socket++) { + base_hartid =riscv_socket_first_hartid (ms, socket); + +for (int i =0 ; i < s->soc[socket].num_harts; i++) { +build_append_int_noprefix (table_data,0x18 ,1 );/* Type */ +build_append_int_noprefix (table_data,20 ,1 );/* Length */ +build_append_int_noprefix (table_data,1 ,1 );/* Version */ +build_append_int_noprefix (table_data,0 ,1 );/* Reserved */ +build_append_int_noprefix (table_data,1 ,4 );/* Flags */
Quoted 9 lines
hw/riscv/virt-acpi-build.c static void build_dsdt(GArray *table_data, · line 168
Quoted 5 lines
hw/riscv/virt-acpi-build.c +5
-0+build_append_int_noprefix (table_data, + (base_hartid + i),8 );/* Hart ID */ + +/* ACPI Processor UID */ +build_append_int_noprefix (table_data, cpu_id,4 );
cpu_idhere seems to be unrelated to one in DSDT.
Could you explain how socket/hartid andcpu_idare related to each other?
cpu_id should match the _UID. I needed two loops here to get the base_hartid of the socket. hart_id is the unique ID for each hart similar to MPIDR / APIC ID. I understand your point. Let me make DSDT also created using two loops so that both match.
Thank you very much for your review!
Sunil
Re: [PATCH V4 5/8] hw/riscv/virt: virt-acpi-build.c: Add RINTC in MADT
Quoted 32 lines · On Fri, 24 Feb 2023 19:56:58 +0530 Sunil V L <[email protected]> wrote:
Hi Igor,
Quoted 29 lines · Igor Mammedov
Quoted 26 lines · On Fri, 24 Feb 2023 14:06:58 +0530 Sunil V L <[email protected]> wrote:
Add Multiple APIC Description Table (MADT) with the RINTC structure for each cpu.
Signed-off-by Sunil V L <[email protected]>Acked-by Alistair Francis <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- hw/riscv/virt-acpi-build.c | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)hw/riscv/virt-acpi-build.c +1
-0@@ -32,6 +32,7 @@#include "sysemu/reset.h" #include "migration/vmstate.h" #include "hw/riscv/virt.h" +#include "hw/riscv/numa.h" #define ACPI_BUILD_TABLE_SIZE 0x20000@@ -132,6 +133,46 @@ static void build_dsdt(GArray *table_data,free_aml_allocator (); }
Quoted 8 lines
Quoted 4 lines
hw/riscv/virt-acpi-build.c static void build_dsdt(GArray *table_data, · line 136
Quoted 1 line
hw/riscv/virt-acpi-build.c +1
-0+/* MADT */ see
build_srat()how this comment must look likeCurrently, even though ECRs are approved, the ACPI spec is not released for these MADT structures. I can add the spec version for the generic MADT but not for the RINTC. Same issue with a new table RHCT. What is the recommendation in such case?
ther must be some draft variant of spec or a ticket where it was approved or a reference impl. somewhere.
Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
hw/riscv/virt-acpi-build.c +27
-0+static void build_madt (GArray *table_data, +BIOSLinker *linker, +RISCVVirtState *s) +{ +MachineState *ms =MACHINE (s); +int socket; +uint16_t base_hartid =0 ; +uint32_t cpu_id =0 ; + +AcpiTable table = { .sig ="APIC" , .rev =6 , .oem_id = s->oem_id, + .oem_table_id = s->oem_table_id }; + +acpi_table_begin (&table, table_data); +/* Local Interrupt Controller Address */ +build_append_int_noprefix (table_data,0 ,4 ); +build_append_int_noprefix (table_data,0 ,4 );/* MADT Flags */ + +/* RISC-V Local INTC structures per HART */ +for (socket =0 ; socket <riscv_socket_count (ms); socket++) { + base_hartid =riscv_socket_first_hartid (ms, socket); + +for (int i =0 ; i < s->soc[socket].num_harts; i++) { +build_append_int_noprefix (table_data,0x18 ,1 );/* Type */ +build_append_int_noprefix (table_data,20 ,1 );/* Length */ +build_append_int_noprefix (table_data,1 ,1 );/* Version */ +build_append_int_noprefix (table_data,0 ,1 );/* Reserved */ +build_append_int_noprefix (table_data,1 ,4 );/* Flags */ Quoted 9 lines
hw/riscv/virt-acpi-build.c static void build_dsdt(GArray *table_data, · line 168
Quoted 5 lines
hw/riscv/virt-acpi-build.c +5
-0+build_append_int_noprefix (table_data, + (base_hartid + i),8 );/* Hart ID */ + +/* ACPI Processor UID */ +build_append_int_noprefix (table_data, cpu_id,4 );
cpu_idhere seems to be unrelated to one in DSDT.
Could you explain how socket/hartid andcpu_idare related to each other?
Quoted 4 lines
cpu_idshould match the_UID. I needed two loops here to get thebase_hartidof the socket.hart_idis the unique ID for each hart similar to MPIDR / APIC ID. I understand your point. Let me make DSDT also created using two loops so that both match.
Why not reuse possible CPUs to describe topology there and then use ids from it to build ACPI tables instead of inventing your own cpu topo all over the place?
PS: look for possible_cpus and how it's used (virt-arm already uses it although partially). And I'd like to avoid adding new ad-hoc ways to describe CPU topology is current possible_cpu ca do the job.
Quoted 3 lines
Thank you very much for your review!
Sunil
Re: [PATCH V4 5/8] hw/riscv/virt: virt-acpi-build.c: Add RINTC in MADT
Quoted 39 lines · Igor Mammedov
Quoted 36 lines · On Fri, 24 Feb 2023 19:56:58 +0530 Sunil V L <[email protected]> wrote:
Hi Igor,
Quoted 33 lines · Igor Mammedov
Quoted 23 lines · On Fri, 24 Feb 2023 14:06:58 +0530 Sunil V L <[email protected]> wrote:
Add Multiple APIC Description Table (MADT) with the RINTC structure for each cpu.
Signed-off-by Sunil V L <[email protected]>Acked-by Alistair Francis <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- hw/riscv/virt-acpi-build.c | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)hw/riscv/virt-acpi-build.c +1
-0@@ -32,6 +32,7 @@#include "sysemu/reset.h" #include "migration/vmstate.h" #include "hw/riscv/virt.h" +#include "hw/riscv/numa.h" #define ACPI_BUILD_TABLE_SIZE 0x20000hw/riscv/virt-acpi-build.c static void build_dsdt(GArray *table_data, · line 136
Quoted 4 lines
hw/riscv/virt-acpi-build.c +1
-0@@ -132,6 +133,46 @@ static void build_dsdt(GArray *table_data,free_aml_allocator (); } +/* MADT */ see
build_srat()how this comment must look like
Quoted 8 lines
Quoted 4 lines
Currently, even though ECRs are approved, the ACPI spec is not released for these MADT structures. I can add the spec version for the generic MADT but not for the RINTC. Same issue with a new table RHCT. What is the recommendation in such case?
ther must be some draft variant of spec or a ticket where it was approved or a reference impl. somewhere.
Sure, I can add the ticket ID. Thanks!
Quoted 42 lines
Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
hw/riscv/virt-acpi-build.c +27
-0+static void build_madt (GArray *table_data, +BIOSLinker *linker, +RISCVVirtState *s) +{ +MachineState *ms =MACHINE (s); +int socket; +uint16_t base_hartid =0 ; +uint32_t cpu_id =0 ; + +AcpiTable table = { .sig ="APIC" , .rev =6 , .oem_id = s->oem_id, + .oem_table_id = s->oem_table_id }; + +acpi_table_begin (&table, table_data); +/* Local Interrupt Controller Address */ +build_append_int_noprefix (table_data,0 ,4 ); +build_append_int_noprefix (table_data,0 ,4 );/* MADT Flags */ + +/* RISC-V Local INTC structures per HART */ +for (socket =0 ; socket <riscv_socket_count (ms); socket++) { + base_hartid =riscv_socket_first_hartid (ms, socket); + +for (int i =0 ; i < s->soc[socket].num_harts; i++) { +build_append_int_noprefix (table_data,0x18 ,1 );/* Type */ +build_append_int_noprefix (table_data,20 ,1 );/* Length */ +build_append_int_noprefix (table_data,1 ,1 );/* Version */ +build_append_int_noprefix (table_data,0 ,1 );/* Reserved */ +build_append_int_noprefix (table_data,1 ,4 );/* Flags */ Quoted 9 lines
hw/riscv/virt-acpi-build.c static void build_dsdt(GArray *table_data, · line 168
Quoted 5 lines
hw/riscv/virt-acpi-build.c +5
-0+build_append_int_noprefix (table_data, + (base_hartid + i),8 );/* Hart ID */ + +/* ACPI Processor UID */ +build_append_int_noprefix (table_data, cpu_id,4 );
cpu_idhere seems to be unrelated to one in DSDT.
Could you explain how socket/hartid andcpu_idare related to each other?Quoted 4 lines
cpu_idshould match the_UID. I needed two loops here to get thebase_hartidof the socket.hart_idis the unique ID for each hart similar to MPIDR / APIC ID. I understand your point. Let me make DSDT also created using two loops so that both match.
Quoted 7 lines
Why not reuse possible CPUs to describe topology there and then use ids from it to build ACPI tables instead of inventing your own cpu topo all over the place?
PS: look for
possible_cpusand how it's used (virt-arm already uses it although partially). And I'd like to avoid adding new ad-hoc ways to describe CPU topology is currentpossible_cpuca do the job.
Okay, sure. Let me take a look at possible_cpus and use in cpu topology. Thanks!
Re: [PATCH V4 5/8] hw/riscv/virt: virt-acpi-build.c: Add RINTC in MADT
Quoted 45 lines · On Tue, 28 Feb 2023 13:04:36 +0530 Sunil V L <[email protected]> wrote:
Quoted 44 lines · Igor Mammedov
Quoted 40 lines · On Fri, 24 Feb 2023 19:56:58 +0530 Sunil V L <[email protected]> wrote:
Hi Igor,
Quoted 25 lines · Igor Mammedov
Quoted 22 lines · On Fri, 24 Feb 2023 14:06:58 +0530 Sunil V L <[email protected]> wrote:
Add Multiple APIC Description Table (MADT) with the RINTC structure for each cpu.
Signed-off-by Sunil V L <[email protected]>Acked-by Alistair Francis <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- hw/riscv/virt-acpi-build.c | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)hw/riscv/virt-acpi-build.c +1
-0@@ -32,6 +32,7 @@#include "sysemu/reset.h" #include "migration/vmstate.h" #include "hw/riscv/virt.h" +#include "hw/riscv/numa.h" #define ACPI_BUILD_TABLE_SIZE 0x20000Quoted 8 lines
hw/riscv/virt-acpi-build.c static void build_dsdt(GArray *table_data, · line 136
Quoted 5 lines
hw/riscv/virt-acpi-build.c +1
-0@@ -132,6 +133,46 @@ static void build_dsdt(GArray *table_data,free_aml_allocator (); } +/* MADT */ see
build_srat()how this comment must look likeCurrently, even though ECRs are approved, the ACPI spec is not released for these MADT structures. I can add the spec version for the generic MADT but not for the RINTC. Same issue with a new table RHCT. What is the recommendation in such case?
Quoted 4 lines
Quoted 3 lines
ther must be some draft variant of spec or a ticket where it was approved or a reference impl. somewhere.
Sure, I can add the ticket ID. Thanks!
and a link, later when new spec is published we can update it to rev/chapter format.
Quoted 47 lines
Quoted 47 lines
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
hw/riscv/virt-acpi-build.c +27
-0+static void build_madt (GArray *table_data, +BIOSLinker *linker, +RISCVVirtState *s) +{ +MachineState *ms =MACHINE (s); +int socket; +uint16_t base_hartid =0 ; +uint32_t cpu_id =0 ; + +AcpiTable table = { .sig ="APIC" , .rev =6 , .oem_id = s->oem_id, + .oem_table_id = s->oem_table_id }; + +acpi_table_begin (&table, table_data); +/* Local Interrupt Controller Address */ +build_append_int_noprefix (table_data,0 ,4 ); +build_append_int_noprefix (table_data,0 ,4 );/* MADT Flags */ + +/* RISC-V Local INTC structures per HART */ +for (socket =0 ; socket <riscv_socket_count (ms); socket++) { + base_hartid =riscv_socket_first_hartid (ms, socket); + +for (int i =0 ; i < s->soc[socket].num_harts; i++) { +build_append_int_noprefix (table_data,0x18 ,1 );/* Type */ +build_append_int_noprefix (table_data,20 ,1 );/* Length */ +build_append_int_noprefix (table_data,1 ,1 );/* Version */ +build_append_int_noprefix (table_data,0 ,1 );/* Reserved */ +build_append_int_noprefix (table_data,1 ,4 );/* Flags */ Quoted 9 lines
hw/riscv/virt-acpi-build.c static void build_dsdt(GArray *table_data, · line 168
Quoted 5 lines
hw/riscv/virt-acpi-build.c +5
-0+build_append_int_noprefix (table_data, + (base_hartid + i),8 );/* Hart ID */ + +/* ACPI Processor UID */ +build_append_int_noprefix (table_data, cpu_id,4 );
cpu_idhere seems to be unrelated to one in DSDT.
Could you explain how socket/hartid andcpu_idare related to each other?Quoted 4 lines
cpu_idshould match the_UID. I needed two loops here to get thebase_hartidof the socket.hart_idis the unique ID for each hart similar to MPIDR / APIC ID. I understand your point. Let me make DSDT also created using two loops so that both match.Why not reuse possible CPUs to describe topology there and then use ids from it to build ACPI tables instead of inventing your own cpu topo all over the place?
Quoted 6 lines
Quoted 3 lines
PS: look for
possible_cpusand how it's used (virt-arm already uses it although partially). And I'd like to avoid adding new ad-hoc ways to describe CPU topology is currentpossible_cpuca do the job.Okay, sure. Let me take a look at
possible_cpusand use in cpu topology. Thanks!
maybe following could be of help:
hw/i386/acpi-common.c:acpi_build_madt
and see how madt_cpu is used.
PATCH v4 6/8 hw/riscv/virt: virt-acpi-build.c: Add RHCT Table
In reply to Sunil V LRISC-V ACPI platforms need to provide RISC-V Hart Capabilities Table (RHCT). Add this to the ACPI tables.
--- hw/riscv/virt-acpi-build.c | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
hw/riscv/virt-acpi-build.c +76 -0
@@ -33,6 +33,7 @@#include "migration/vmstate.h" #include "hw/riscv/virt.h" #include "hw/riscv/numa.h" +#include "hw/intc/riscv_aclint.h" #define ACPI_BUILD_TABLE_SIZE 0x20000
@@ -83,6 +84,78 @@ static void acpi_dsdt_add_fw_cfg(Aml *scope, const MemMapEntry *fw_cfg_memmap)aml_append (scope, dev); } +#define RHCT_NODE_ARRAY_OFFSET 56 +static void build_rhct (GArray *table_data, +BIOSLinker *linker, +RISCVVirtState *s) +{ +MachineState *ms =MACHINE (s); +uint32_t acpi_proc_id =0 ; +int i, socket; +RISCVCPU *cpu; +char *isa; +size_t len, aligned_len; +uint32_t isa_offset, num_rhct_nodes; + +AcpiTable table = { .sig ="RHCT" , .rev =1 , .oem_id = s->oem_id, + .oem_table_id = s->oem_table_id }; + +acpi_table_begin (&table, table_data); + +build_append_int_noprefix (table_data,0x0 ,4 );/* Reserved */ + +/* Time Base Frequency */ +build_append_int_noprefix (table_data, +RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ ,8 ); + +/* ISA + N hart info */ + num_rhct_nodes =1 + ms->smp.cpus; + +/* Number of RHCT nodes*/ +build_append_int_noprefix (table_data, num_rhct_nodes,4 ); + +/* Offset to the RHCT node array */ +build_append_int_noprefix (table_data,RHCT_NODE_ARRAY_OFFSET ,4 ); + +/* ISA string node */ + isa_offset = table_data->len - table.table_offset; +build_append_int_noprefix (table_data,0 ,2 );/* Type 0 */ + + cpu = &s->soc[0 ].harts[0 ]; + isa =riscv_isa_string (cpu); + len =8 +strlen (isa) +1 ; + aligned_len = (len %2 ) ? (len +1 ) : len; + +build_append_int_noprefix (table_data, aligned_len,2 );/* Length */ +build_append_int_noprefix (table_data,0x1 ,2 );/* Revision */ + +/* ISA string length including NUL */ +build_append_int_noprefix (table_data,strlen (isa) +1 ,2 ); +g_array_append_vals (table_data, isa,strlen (isa) +1 );/* ISA string */ + +if (aligned_len != len) { +build_append_int_noprefix (table_data,0x0 ,1 );/* Optional Padding */ + } + +for (socket =0 ; socket <riscv_socket_count (ms); socket++) { +for (i =0 ; i < s->soc[socket].num_harts; i++) { +build_append_int_noprefix (table_data,0xFFFF ,2 );/* Type */ +build_append_int_noprefix (table_data,16 ,2 );/* Length */ +build_append_int_noprefix (table_data,0x1 ,2 );/* Revision */ +build_append_int_noprefix (table_data,1 ,2 );/* Number of offsets */ + +/* ACPI Processor UID */ +build_append_int_noprefix (table_data, acpi_proc_id,4 ); + +/* Offsets[0] */ +build_append_int_noprefix (table_data, isa_offset,4 ); + acpi_proc_id++; + } + } + +acpi_table_end (linker, &table); +} +/* FADT */ static void build_fadt_rev6(GArray *table_data, BIOSLinker *linker,
@@ -197,6 +270,9 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)acpi_add_table (table_offsets, tables_blob);build_madt (tables_blob, tables->linker, s); +acpi_add_table (table_offsets, tables_blob); +build_rhct (tables_blob, tables->linker, s); +/* XSDT is pointed to by RSDP */ xsdt = tables_blob->len; build_xsdt(tables_blob, tables->linker, table_offsets, s->oem_id,
Signature · 1 line
2.34.1
Re: [PATCH V4 6/8] hw/riscv/virt: virt-acpi-build.c: Add RHCT Table
Quoted 22 lines · On Fri, 24 Feb 2023 14:06:59 +0530 Sunil V L <[email protected]> wrote:
RISC-V ACPI platforms need to provide RISC-V Hart Capabilities Table (RHCT). Add this to the ACPI tables.
Signed-off-by Sunil V L <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- hw/riscv/virt-acpi-build.c | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)hw/riscv/virt-acpi-build.c +1
-0@@ -33,6 +33,7 @@#include "migration/vmstate.h" #include "hw/riscv/virt.h" #include "hw/riscv/numa.h" +#include "hw/intc/riscv_aclint.h" #define ACPI_BUILD_TABLE_SIZE 0x20000
hw/riscv/virt-acpi-build.c static void acpi_dsdt_add_fw_cfg(Aml *scope, const MemMapEntry *fw_cfg_memmap) · line 87
Quoted 4 lines
hw/riscv/virt-acpi-build.c +1
-0@@ -83,6 +84,78 @@ static void acpi_dsdt_add_fw_cfg(Aml *scope, const MemMapEntry *fw_cfg_memmap)aml_append (scope, dev); } +#define RHCT_NODE_ARRAY_OFFSET 56
same as previous patch, here should be proper comment otherwise reviewer has no clue where to look for reference.
Quoted 84 lines
hw/riscv/virt-acpi-build.c +74
-0+static void build_rhct (GArray *table_data, +BIOSLinker *linker, +RISCVVirtState *s) +{ +MachineState *ms =MACHINE (s); +uint32_t acpi_proc_id =0 ; +int i, socket; +RISCVCPU *cpu; +char *isa; +size_t len, aligned_len; +uint32_t isa_offset, num_rhct_nodes; + +AcpiTable table = { .sig ="RHCT" , .rev =1 , .oem_id = s->oem_id, + .oem_table_id = s->oem_table_id }; + +acpi_table_begin (&table, table_data); + +build_append_int_noprefix (table_data,0x0 ,4 );/* Reserved */ + +/* Time Base Frequency */ +build_append_int_noprefix (table_data, +RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ ,8 ); + +/* ISA + N hart info */ + num_rhct_nodes =1 + ms->smp.cpus; + +/* Number of RHCT nodes*/ +build_append_int_noprefix (table_data, num_rhct_nodes,4 ); + +/* Offset to the RHCT node array */ +build_append_int_noprefix (table_data,RHCT_NODE_ARRAY_OFFSET ,4 ); + +/* ISA string node */ + isa_offset = table_data->len - table.table_offset; +build_append_int_noprefix (table_data,0 ,2 );/* Type 0 */ + + cpu = &s->soc[0 ].harts[0 ]; + isa =riscv_isa_string (cpu); + len =8 +strlen (isa) +1 ; + aligned_len = (len %2 ) ? (len +1 ) : len; + +build_append_int_noprefix (table_data, aligned_len,2 );/* Length */ +build_append_int_noprefix (table_data,0x1 ,2 );/* Revision */ + +/* ISA string length including NUL */ +build_append_int_noprefix (table_data,strlen (isa) +1 ,2 ); +g_array_append_vals (table_data, isa,strlen (isa) +1 );/* ISA string */ + +if (aligned_len != len) { +build_append_int_noprefix (table_data,0x0 ,1 );/* Optional Padding */ + } + +for (socket =0 ; socket <riscv_socket_count (ms); socket++) { +for (i =0 ; i < s->soc[socket].num_harts; i++) { +build_append_int_noprefix (table_data,0xFFFF ,2 );/* Type */ +build_append_int_noprefix (table_data,16 ,2 );/* Length */ +build_append_int_noprefix (table_data,0x1 ,2 );/* Revision */ +build_append_int_noprefix (table_data,1 ,2 );/* Number of offsets */ + +/* ACPI Processor UID */ +build_append_int_noprefix (table_data, acpi_proc_id,4 ); + +/* Offsets[0] */ +build_append_int_noprefix (table_data, isa_offset,4 ); + acpi_proc_id++; + } + } + +acpi_table_end (linker, &table); +} +/* FADT */ static void build_fadt_rev6(GArray *table_data, BIOSLinker *linker,@@ -197,6 +270,9 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)acpi_add_table (table_offsets, tables_blob);build_madt (tables_blob, tables->linker, s); +acpi_add_table (table_offsets, tables_blob); +build_rhct (tables_blob, tables->linker, s); +/* XSDT is pointed to by RSDP */ xsdt = tables_blob->len; build_xsdt(tables_blob, tables->linker, table_offsets, s->oem_id,
PATCH v4 7/8 hw/riscv/virt.c: Initialize the ACPI tables
In reply to Sunil V LInitialize the ACPI tables if the acpi option is not disabled.
--- hw/riscv/virt.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/riscv/virt.c +4 -0
@@ -1324,6 +1324,10 @@ static void virt_machine_done(Notifier *notifier, void *data)if (kvm_enabled ()) {riscv_setup_direct_kernel (kernel_entry, fdt_load_addr); } + +if (virt_is_acpi_enabled (s)) { +virt_acpi_setup (s); + } }static void virt_machine_init (MachineState *machine)
Signature · 1 line
2.34.1
PATCH v4 8/8 MAINTAINERS: Add entry for RISC-V ACPI
In reply to Sunil V LRISC-V ACPI related functionality for virt machine is added in virt-acpi-build.c. Add the maintainer entry after moving the ARM ACPI entry under the main ACPI entry.
--- MAINTAINERS | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
MAINTAINERS +12 -6
@@ -994,12 +994,6 @@ S: Maintained F: hw/ssi/xlnx-versal-ospi.c F: include/hw/ssi/xlnx-versal-ospi.h -ARM ACPI Subsystem -M: Shannon Zhao <[email protected]> -L: [email protected] -S: Maintained -F: hw/arm/virt-acpi-build.c - STM32F100 M: Alexandre Iooss <[email protected]> L: [email protected]
@@ -1907,6 +1901,18 @@ F: hw/acpi/ghes.c F: include/hw/acpi/ghes.h F: docs/specs/acpi_hest_ghes.rst +ARM ACPI Subsystem +M: Shannon Zhao <[email protected]> +L: [email protected] +S: Maintained +F: hw/arm/virt-acpi-build.c + +RISC-V ACPI Subsystem +M: Sunil V L <[email protected]> +L: [email protected] +S: Maintained +F: hw/riscv/virt-acpi-build.c + ppc4xx L: [email protected] S: Orphan
Signature · 1 line
2.34.1
Re: [PATCH V4 8/8] MAINTAINERS: Add entry for RISC-V ACPI
Quoted 51 lines · Sunil V L
RISC-V ACPI related functionality for virt machine is added in
virt-acpi-build.c. Add the maintainer entry after moving the ARM ACPI entry under the main ACPI entry.Signed-off-by Sunil V L <[email protected]>Reviewed-by Bin Meng <[email protected]>Acked-by Alistair Francis <[email protected]>Reviewed-by Andrew Jones <[email protected]>--- MAINTAINERS | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)MAINTAINERS +12
-6@@ -994,12 +994,6 @@ S: Maintained F: hw/ssi/xlnx-versal-ospi.c F: include/hw/ssi/xlnx-versal-ospi.h -ARM ACPI Subsystem -M: Shannon Zhao <[email protected]> -L: [email protected] -S: Maintained -F: hw/arm/virt-acpi-build.c - STM32F100 M: Alexandre Iooss <[email protected]> L: [email protected]@@ -1907,6 +1901,18 @@ F: hw/acpi/ghes.c F: include/hw/acpi/ghes.h F: docs/specs/acpi_hest_ghes.rst +ARM ACPI Subsystem +M: Shannon Zhao <[email protected]> +L: [email protected] +S: Maintained +F: hw/arm/virt-acpi-build.c + +RISC-V ACPI Subsystem +M: Sunil V L <[email protected]> +L: [email protected] +S: Maintained +F: hw/riscv/virt-acpi-build.c + ppc4xx L: [email protected] S: OrphanSignature · 1 line
2.34.1
I probably would have put these sections directly under the main ACPI section, "ACPI/SMBIOS", as these are "main" arch-specific sections, but I wouldn't respin the series for that.
Maybe whichever maintainer picks up the patches can put the sections in their preferred location.
Thanks,
drew