[kvm-unit-tests PATCH 4/7] riscv: Add ACPI support for ISA string discovery

Xiang W wangxiang at iscas.ac.cn
Tue Oct 6 05:48:33 PDT 2026


在 2026-09-30三的 12:15 +0200,Andrew Jones写道:
> On Thu, Sep 24, 2026 at 11:39:42AM +0800, Xiang W wrote:
> > When a DT is not provided, walk the RHCT Hart Info nodes and parse
> > the referenced ISA String node instead of aborting in isa_init()
> > and cpu_has_extension_name().
> > 
> > Match the current hart by ACPI UID (DT still matches by hartid)
> > and feed the ISA string into the existing isa_parse() helper so
> > extension detection is shared by both firmware descriptions.
> > 
> > Rename isa_info.hartid to isa_info.id so the same iterator state
> > can hold either identifier.
> > 
> > Signed-off-by: Xiang W <wangxiang at iscas.ac.cn>
> > ---
> >  lib/acpi.h      | 28 ++++++++++++++++++++
> >  lib/riscv/isa.c | 68 ++++++++++++++++++++++++++++++++++++++++++++-----
> >  2 files changed, 89 insertions(+), 7 deletions(-)
> > 
> > diff --git a/lib/acpi.h b/lib/acpi.h
> > index 2597e8ce..3db382b7 100644
> > --- a/lib/acpi.h
> > +++ b/lib/acpi.h
> > @@ -337,6 +337,34 @@ struct acpi_table_rhct {
> >  	u32 node_offset;
> >  };
> >  
> > +#define ACPI_RHCT_NODE_HEADER_DEF \
> > +	u16 type;	\
> > +	u16 length;	\
> > +	u16 revision;	\
> > +
> > +struct acpi_rhct_node {
> > +	ACPI_RHCT_NODE_HEADER_DEF
> > +	char data[];
> > +};
> > +
> > +enum acpi_rhct_node_type {
> > +	RHCT_NODE_ISA_STRING = 0x0,
> > +	RHCT_NODE_HART_INFO = 0xFFFF
> 
> ACPI_RHCT_NODE_TYPE_ISA_STRING
> ACPI_RHCT_NODE_TYPE_HART_INFO
> 
> > +};
> > +
> > +struct acpi_rhct_node_isa_string {
> > +	ACPI_RHCT_NODE_HEADER_DEF
> > +	u16 isa_length;
> > +	char isa[];
> > +};
> > +
> > +struct acpi_rhct_node_hart_info {
> > +	ACPI_RHCT_NODE_HEADER_DEF
> > +	u16 num_offsets;
> > +	u32 uid;
> > +	u32 nodes[];
> > +};
> > +
> >  /* Reset to default packing */
> >  #pragma pack()
> >  
> > diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
> > index bc1c9c72..b0257979 100644
> > --- a/lib/riscv/isa.c
> > +++ b/lib/riscv/isa.c
> > @@ -12,7 +12,7 @@
> >  typedef void (*isa_func_t)(const char *, int, void *);
> >  
> >  struct isa_info {
> > -	unsigned long hartid;
> > +	unsigned long id;
> >  	isa_func_t func;
> >  	void *data;
> >  };
> > @@ -74,7 +74,7 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
> >  	const struct fdt_property *prop;
> >  	int len;
> >  
> > -	if (hartid != info->hartid)
> > +	if (hartid != info->id)
> >  		return;
> >  
> >  	prop = fdt_get_property(dt_fdt(), cpu_node, "riscv,isa", &len);
> > @@ -83,32 +83,80 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
> >  	isa_parse(prop->data, len, info);
> >  }
> >  
> > -static void isa_init_acpi(void)
> > +#ifdef CONFIG_EFI
> > +#include <acpi.h>
> > +
> > +static void isa_parse_acpi(struct acpi_table_rhct *rhct, struct acpi_rhct_node_hart_info *hart_info, void *data)
> 
> Let's keep it under 100
> 
> static void isa_parse_acpi(struct acpi_table_rhct *rhct,
> 			   struct acpi_rhct_node_hart_info *hart_info, void *data)
> 
> > +{
> > +	u32 offset;
> > +	struct acpi_rhct_node *node;
> > +	struct acpi_rhct_node_isa_string *isa_string;
> > +	struct isa_info *info = (struct isa_info *)data;
> > +
> > +	if (hart_info->uid != info->id)
> > +		return;
> > +
> > +	for (int i = 0; i < hart_info->num_offsets; i++) {
> > +		offset = hart_info->nodes[i];
> > +		if (offset >= rhct->length)
> > +			break;
> > +		node = (void *)rhct + offset;
> > +		if (node->type == RHCT_NODE_ISA_STRING) {
> > +			isa_string = (void *) node;
> 
>  isa_string = (void *)node
> 
> I thought checkpatch would catch something like that. Did you run it?

Below is my checkpatch execution log; assigning a `void*` pointer to a pointer
of another type passes the checkpatch validation.

➜  kvm-unit-tests git:(brs-i_v1) ./scripts/checkpatch.pl -g HEAD^^^                                                     
WARNING: macros should not use a trailing semicolon
#32: FILE: lib/acpi.h:340:
+#define ACPI_RHCT_NODE_HEADER_DEF \
+	u16 type;	\
+	u16 length;	\
+	u16 revision;	\
+

WARNING: line length of 112 exceeds 100 columns
#93: FILE: lib/riscv/isa.c:89:
+static void isa_parse_acpi(struct acpi_table_rhct *rhct, struct acpi_rhct_node_hart_info *hart_info, void *data)

WARNING: line length of 102 exceeds 100 columns
#116: FILE: lib/riscv/isa.c:112:
+	void (*func)(struct acpi_table_rhct *, struct acpi_rhct_node_hart_info *, void *), void *data)

WARNING: Missing a blank line after declarations
#123: FILE: lib/riscv/isa.c:118:
+	struct acpi_rhct_node_hart_info *hart_info;
+	rhct = find_acpi_table_addr(RHCT_SIGNATURE);

total: 0 errors, 4 warnings, 151 lines checked

Commit ca687690a06e ("riscv: Add ACPI support for ISA string discovery") has no obvious style problems and is ready for submission.

> 
> > +			isa_parse(isa_string->isa, isa_string->isa_length, info);
> > +		}
> > +	}
> > +}
> > +
> > +static void acpi_rhct_for_each_hart(
> > +	void (*func)(struct acpi_table_rhct *, struct acpi_rhct_node_hart_info *, void *), void *data)
> 
> static void acpi_rhct_for_each_hart(void (*func)(struct acpi_table_rhct *,
> 						 struct acpi_rhct_node_hart_info *,
> 						 void *), void *data)
> 
> >  {
> > -	assert_msg(false, "ACPI not available");
> > +	u32 offset;
> > +	struct acpi_table_rhct *rhct;
> > +	struct acpi_rhct_node *node;
> > +	struct acpi_rhct_node_hart_info *hart_info;
> 
> Need a blank line here. I'm thinking checkpatch wasn't run, since I'm sure
> that would have been caught.
> 
> Thanks,
> drew




More information about the kvm-riscv mailing list