ACPI: RISC-V: Add support for the RQSC table
Subsystems (3)
cover ACPI: RISC-V: Add support for the RQSC table
Add support for the ACPI RISC-V Quality of Service Controllers (RQSC) table [1] that describes the CBQRI controllers [2] present in a system. Create a platform device for each controller so that the same CBQRI driver can bind on device tree and ACPI systems.
Patch 1 adds the table definitions. They stay in drivers/acpi/riscv until ACPICA carries them [3]. Patch 2 parses the table and creates the platform devices. It is derived from the large RFC series that implemented all of CBQRI [4]. Patch 3 makes the CBQRI capacity driver bind to the capacity controller devices. I plan to add support for bandwidth controller devices once the resctrl generic schema lands.
This series depends on:
- "riscv: Add initial CBQRI resctrl support" v12 [5]
Tested on QEMU virt with the RQSC table support [6], two L2 capacity controllers, one L3 capacity controller and one bandwidth controller:
ACPI: RQSC 0x00000000BDD5B000 0000E0 (v01 BOCHS BXPC 00000001 BXPC 00000001)
ACPI: RQSC: 4 CBQRI controllers
# ls /sys/bus/platform/devices | grep cbqri cbqri-bandwidth.2 cbqri-capacity.0 cbqri-capacity.1 cbqri-capacity.3
# grep cbqri /proc/iomem
04820000-04820fff : cbqri-capacity.0
04820000-04820fff : cbqri-capacity.0 cbqri-capacity.0
04821000-04821fff : cbqri-capacity.1
04821000-04821fff : cbqri-capacity.1 cbqri-capacity.1
04828000-04828fff : cbqri-bandwidth.2
0482b000-0482bfff : cbqri-capacity.3
0482b000-0482bfff : cbqri-capacity.3 cbqri-capacity.3The capacity driver binds and resctrl shows the L2 and L3 domains:
cbqri-capacity cbqri-capacity.0: registered L2 capacity controller at 0x0000000004820000 (cache_id=33685504, rcid=64) cbqri-capacity cbqri-capacity.1: registered L2 capacity controller at 0x0000000004821000 (cache_id=33685508, rcid=64) cbqri-capacity cbqri-capacity.3: registered L3 capacity controller at 0x000000000482b000 (cache_id=33751040, rcid=64)
# mount -t resctrl resctrl /sys/fs/resctrl # cat /sys/fs/resctrl/schemata L2:33685504=fff;33685508=fff L3:33751040=ffff
[1] https://github.com/riscv-non-isa/riscv-rqsc/releases/tag/v1.0.0
[2] https://github.com/riscv-non-isa/riscv-cbqri/releases/tag/v1.0
[3] https://github.com/open-acpica/acpica/pull/1262
[4] https://lore.kernel.org/all/[email protected]/
[5] https://lore.kernel.org/all/[email protected]/
[6] https://lore.kernel.org/qemu-devel/[email protected]/
---
Drew Fustini (Tenstorrent) (3):
ACPI: RISC-V: Add RQSC table definitions
ACPI: RISC-V: Enumerate CBQRI controllers from the RQSC table
riscv_cbqri: Bind to RQSC platform devices
drivers/acpi/riscv/Kconfig | 3 + drivers/acpi/riscv/Makefile | 1 + drivers/acpi/riscv/init.c | 2 + drivers/acpi/riscv/init.h | 1 + drivers/acpi/riscv/rqsc.c | 210 +++++++++++++++++++++++++++++++++++++++ drivers/acpi/riscv/rqsc.h | 67 +++++++++++++ drivers/resctrl/Kconfig | 11 +- drivers/resctrl/cbqri_capacity.c | 111 +++++++++++++++------ 8 files changed, 371 insertions(+), 35 deletions(-)
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261108-acpi-rqsc-6df871ab608a
prerequisite-change-id: 20260610-dfustini-atl-sc-cbqri-dt-410c8e2711dd:v12
prerequisite-patch-id: 492fe81aa4f3c885ac5bb48252def2fdc5527275
prerequisite-patch-id: b4f0bd4bf660c92dbf4ca0c7d871c1550b66df0d
prerequisite-patch-id: a2e36f0788f8e11c708d162dce653351dd99c4f0
prerequisite-patch-id: d1d359c5cf89b2b5018d64ca8f320892f6dbcca2
prerequisite-patch-id: 5b7fea6f1ad8f2137ffe45681d56b83e17f7cb2a
Best regards,
Signature · 1 line
Drew Fustini (Tenstorrent) <[email protected]>
PATCH 1/3 ACPI: RISC-V: Add RQSC table definitions
The RISC-V Quality of Service Controllers (RQSC) table describes the CBQRI capacity and bandwidth controllers in a system. RQSC v1.0 was ratified in June 2026. Add structure definitions for RQSC.
The definitions stay in drivers/acpi/riscv until ACPICA carries them in actbl2.h.
--- drivers/acpi/riscv/rqsc.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
drivers/acpi/riscv/rqsc.h new file +67 -0
@@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Definitions for the RISC-V Quality of Service Controllers (RQSC) ACPI +* table, kept here until ACPICA carries them in actbl2.h. +*/ +#ifndef _DRIVERS_ACPI_RISCV_RQSC_H +#define _DRIVERS_ACPI_RISCV_RQSC_H + +#include <linux/acpi.h> +#include <linux/types.h> + +#define ACPI_SIG_RQSC "RQSC"/* RISC-V Quality of Service Controllers Table */ + +#define ACPI_RQSC_REVISION 1 + +/* QoS Controller Type */ +#define ACPI_RQSC_CONTROLLER_TYPE_CAPACITY 0 +#define ACPI_RQSC_CONTROLLER_TYPE_BANDWIDTH 1 + +/* Resource Type */ +#define ACPI_RQSC_RESOURCE_TYPE_CACHE 0 +#define ACPI_RQSC_RESOURCE_TYPE_MEMORY 1 + +/* Resource ID Type */ +#define ACPI_RQSC_RESOURCE_ID_TYPE_PROCESSOR_CACHE 0 +#define ACPI_RQSC_RESOURCE_ID_TYPE_MEMORY_RANGE 1 +#define ACPI_RQSC_RESOURCE_ID_TYPE_MEMORY_SIDE_CACHE 2 +#define ACPI_RQSC_RESOURCE_ID_TYPE_ACPI_DEVICE 3 +#define ACPI_RQSC_RESOURCE_ID_TYPE_PCI_DEVICE 4 + +/* Controller Flags */ +#define ACPI_RQSC_CONTROLLER_ZERO_BLOCKS (1)/* Zero blocks can be allocated to an RCID */ + +struct acpi_rqsc_resource { +u8 type; +u8 reserved; +u16 length; +u16 flags; +u8 reserved2; +u8 id_type; +u64 id1; +u32 id2; +} __packed; + +/* Resource Specific Data that follows a memory resource */ +struct acpi_rqsc_memory_data { +u64 bandwidth_per_block;/* In bytes per second, 0 if not provided */ +} __packed; + +struct acpi_rqsc_controller { +u8 type; +u8 reserved; +u16 length; +struct acpi_generic_address address; +u16 rcid_count; +u16 mcid_count; +u16 flags; +u16 num_resources; +/* Followed by num_resources struct acpi_rqsc_resource */ +} __packed; + +struct acpi_table_rqsc { +struct acpi_table_header header;/* Common ACPI table header */ +u32 num_controllers; +} __packed; + +#endif /* _DRIVERS_ACPI_RISCV_RQSC_H */
Signature · 1 line
2.43.0
Re: [PATCH 1/3] ACPI: RISC-V: Add RQSC table definitions
Quoted 6 lines · On Tue, 17 Nov 2026 14:11:27 -0800 "Drew Fustini (Tenstorrent)"…
The RISC-V Quality of Service Controllers (RQSC) table describes the CBQRI capacity and bandwidth controllers in a system. RQSC v1.0 was ratified in June 2026. Add structure definitions for RQSC.
The definitions stay in
drivers/acpi/riscvuntil ACPICA carries them inactbl2.h.
Hi Drew,
This seems unusual. Normal path for this has been to put them in the right place and just flag the pull request as you have done. Then no one merges the series until acpica pick them up and Rafael pulls that in. That way it 'should' not require a change, Rafael just ignores that patch and picks up the rest.
I haven't been paying attention so maybe this is being done differently here for some reason.
Has added benefit that no one reads the patch as it is another projects problem :)
J
Quoted 3 lines
Re: [PATCH 1/3] ACPI: RISC-V: Add RQSC table definitions
Quoted 18 lines · Jonathan Cameron
Quoted 6 lines · On Tue, 17 Nov 2026 14:11:27 -0800 "Drew Fustini (Tenstorrent)"…
The RISC-V Quality of Service Controllers (RQSC) table describes the CBQRI capacity and bandwidth controllers in a system. RQSC v1.0 was ratified in June 2026. Add structure definitions for RQSC.
The definitions stay in
drivers/acpi/riscvuntil ACPICA carries them inactbl2.h.Hi Drew,
This seems unusual. Normal path for this has been to put them in the right place and just flag the pull request as you have done. Then no one merges the series until acpica pick them up and Rafael pulls that in. That way it 'should' not require a change, Rafael just ignores that patch and picks up the rest.
Quoted 5 lines
I haven't been paying attention so maybe this is being done differently here for some reason.
Has added benefit that no one reads the patch as it is another projects problem :)
Thanks for taking a look at this series. There is no special reason, just my lack of experience with ACPI. I will switch to the actbl2.h patch generated by the ACPICA linuxize process.
Drew
PATCH 2/3 ACPI: RISC-V: Enumerate CBQRI controllers from the RQSC table
In reply to Drew Fustini (Tenstorrent)Walk the RQSC table at ACPI init and create a platform device for each CBQRI controller, so one platform driver can serve device tree and ACPI systems. Nothing selects ACPI_RQSC until the CBQRI driver can bind to these devices.
--- drivers/acpi/riscv/Kconfig | 3 + drivers/acpi/riscv/Makefile | 1 + drivers/acpi/riscv/init.c | 2 + drivers/acpi/riscv/init.h | 1 + drivers/acpi/riscv/rqsc.c | 210 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 217 insertions(+)
drivers/acpi/riscv/Kconfig +3 -0
@@ -5,3 +5,6 @@ config ACPI_RIMT bool + +config ACPI_RQSC + bool
drivers/acpi/riscv/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-y += rhct.o init.o irq.o obj-$(CONFIG_ACPI_PROCESSOR_IDLE) += cpuidle.o obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o obj-$(CONFIG_ACPI_RIMT) += rimt.o +obj-$(CONFIG_ACPI_RQSC) += rqsc.o
drivers/acpi/riscv/init.c +2 -0
@@ -12,4 +12,6 @@ void __init acpi_arch_init(void)riscv_acpi_init_gsi_mapping ();if (IS_ENABLED (CONFIG_ACPI_RIMT ))riscv_acpi_rimt_init (); +if (IS_ENABLED (CONFIG_ACPI_RQSC )) +riscv_acpi_rqsc_init (); }
drivers/acpi/riscv/init.h +1 -0
@@ -3,3 +3,4 @@void __init riscv_acpi_init_gsi_mapping (void );void __init riscv_acpi_rimt_init (void ); +void __init riscv_acpi_rqsc_init (void );
drivers/acpi/riscv/rqsc.c new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 2/3] ACPI: RISC-V: Enumerate CBQRI controllers from the RQSC table
Quoted 6 lines · On Tue, 17 Nov 2026 14:11:28 -0800 "Drew Fustini (Tenstorrent)"…
Walk the RQSC table at ACPI init and create a platform device for each CBQRI controller, so one platform driver can serve device tree and ACPI systems. Nothing selects
ACPI_RQSCuntil the CBQRI driver can bind to these devices.Signed-off-by Drew Fustini (Tenstorrent) <[email protected]>
Hi Drew
Very much a drive by review as I haven't even opened the spec yet ;)
Anyhow, various comments inline. Most code readability suggestions.
Thanks,
Jonathan
drivers/acpi/riscv/rqsc.c
Quoted 6 lines
drivers/acpi/riscv/rqsc.c new file +0
-0@@ -0,0 +1,210 @@
"
drivers/acpi/riscv/rqsc.c line 26
Quoted 6 lines
drivers/acpi/riscv/rqsc.c new file +6
-0+ +static struct platform_device *__init +rqsc_add_device (unsigned int idx,const struct acpi_rqsc_controller *ctrl, +const struct acpi_rqsc_resource *res) +{ +bool is_cc = ctrl->type ==ACPI_RQSC_CONTROLLER_TYPE_CAPACITY ;
Not a fan of a bool when we might get more types at some point. If you want to do something like this have a trivial helper bool rqsc_ctrl_is_cc() and use it inline.
drivers/acpi/riscv/rqsc.c line 29
Quoted 3 lines
drivers/acpi/riscv/rqsc.c new file +3
-0+ struct platform_device *pdev __free(platform_device_put) = +platform_device_alloc (is_cc ?"cbqri-capacity" :"cbqri-bandwidth" , + idx);
Not particularly readable or extensible if more types show up.
I'd use a switch that sets the string. Declare the pdev and __free after that.
drivers/acpi/riscv/rqsc.c line 38
Quoted 9 lines
drivers/acpi/riscv/rqsc.c new file +9
-0+phys_addr_t addr = ctrl->address.address; +/* The GAS carries no length, so claim up to the end of the page. */ +struct resource mem =DEFINE_RES_MEM (addr,PAGE_SIZE -offset_in_page (addr)); +/* rcid, mcid, cache id and a sentinel */ +struct property_entry props[4 ] = {}; +unsigned int n =0 ; +int ret; + +if (!pdev)
Drag the pdev alloc down to just above this. Having it burried in allocations is not easy to read when you only check for success all the way down here.
Quoted 33 lines
drivers/acpi/riscv/rqsc.c new file +32
-0+return ERR_PTR (-ENOMEM ); + + ret =platform_device_add_resources (pdev, &mem,1 ); +if (ret) +return ERR_PTR (ret); + + props[n++] =PROPERTY_ENTRY_U32 ("riscv,cbqri-rcid" , ctrl->rcid_count); + props[n++] =PROPERTY_ENTRY_U32 ("riscv,cbqri-mcid" , ctrl->mcid_count); +if (is_cc) + props[n++] =PROPERTY_ENTRY_U32 ("riscv,cbqri-cache-id" , +lower_32_bits (res->id1)); +else +set_dev_node (&pdev->dev,pxm_to_node (lower_32_bits (res->id1))); + + ret =device_create_managed_software_node (&pdev->dev, props,NULL ); +if (ret) +return ERR_PTR (ret); + + ret =platform_device_add (pdev); +if (ret) +return ERR_PTR (ret); + +return_ptr (pdev); +} + +static void __init rqsc_parse (const struct acpi_table_rqsc *rqsc) +{ +const void *end = (const void *)rqsc + rqsc->header.length; +const struct acpi_rqsc_controller *ctrl = (const void *)(rqsc +1 ); +unsigned int idx =0 , added =0 ; + +while ((const void *)ctrl < end) {
drivers/acpi/riscv/rqsc.c line 109
Quoted 10 lines
drivers/acpi/riscv/rqsc.c new file +10
-0+const struct acpi_rqsc_resource *res = (const void *)(ctrl +1 ); +struct platform_device *pdev; +phys_addr_t addr; + +/* +* The controller structure must fit and stay inside the +* table. Anything else is corruption and the remaining +* entries cannot be trusted. +*/ + if ((const void *)ctrl + sizeof(*ctrl) > end ||
if ((const void *)(ctrl + 1) > end ?
Which looks familiar. Isn't that
if ((const void *)res > end)
Maybe that is a little confusing as res might be zero size. For that matter I'd not set res until after this check because it might take an invalid value. Doesn't matter as such but is confusing to read.
Quoted 18 lines
drivers/acpi/riscv/rqsc.c new file +18
-0+ ctrl->length < sizeof(*ctrl) || + (const void *)ctrl + ctrl->length > end) { +pr_err ("entry %u is malformed, stopping\n" , idx); +break ; + } + + addr = ctrl->address.address; + +if (ctrl->type !=ACPI_RQSC_CONTROLLER_TYPE_CAPACITY && + ctrl->type !=ACPI_RQSC_CONTROLLER_TYPE_BANDWIDTH ) { +pr_warn ("controller at %pa: unknown type %u, skipping\n" , + &addr, ctrl->type); + goto next; + } + +if (ctrl->address.space_id !=ACPI_ADR_SPACE_SYSTEM_MEMORY || !addr) { +pr_warn ("entry %u: no usable register interface address, skipping\n" , + idx);
drivers/acpi/riscv/rqsc.c line 137
Quoted 10 lines
drivers/acpi/riscv/rqsc.c new file +10
-0+ goto next; + } + +if (!ctrl->rcid_count && !ctrl->mcid_count) { +pr_warn ("controller at %pa: no RCIDs and no MCIDs, skipping\n" , + &addr); + goto next; + } + + if (!ctrl->num_resources ||
Little fiddly but I'd split this. The reason being that the next check if kind of checking for only one resource, but you only confirm that is ok with pr_warn() path that follows. So maybe
if (!ctrl->num_resources) {
pr_warn("controller at %pa: no resource, skipping\n",
&addr);I'd go a bit long on lines - not sure ACPI is that fussy as subsystem go.
goto next;
}
if (ctrl->num_resources > 1)
pr_warn("controller at %pa: %u resources, using the first\n",
&addr, ctrl->num_resources);//now we have clarity that we only care about first resource.
if (ctrl->length < sizeof(*ctrl) + sizeof(*res) ||
res->length < sizeof(*res)) {
pr_warn("controller at %pa: no usable resource, skipping\n",
&addr);
goto next;
}Quoted 8 lines
drivers/acpi/riscv/rqsc.c new file +8
-0+ ctrl->length < sizeof(*ctrl) + sizeof(*res) || + res->length < sizeof(*res)) { +pr_warn ("controller at %pa: no usable resource, skipping\n" , + &addr); + goto next; + } + +if (ctrl->num_resources >1 )
drivers/acpi/riscv/rqsc.c line 155
Quoted 10 lines
drivers/acpi/riscv/rqsc.c new file +10
-0+pr_warn ("controller at %pa: %u resources, using the first\n" , + &addr, ctrl->num_resources); + +if (!rqsc_resource_ok (ctrl, res, addr)) + goto next; + + pdev =rqsc_add_device (idx, ctrl, res); +if (IS_ERR (pdev)) { +pr_warn ("controller at %pa: failed to add device: %pe\n" , + &addr, pdev);
This feels like the sort of thing you should just fail init on. Papering over bits of the table that don't like you expect might be dealing with changes that have been made. Failing to add a device is something much worse.
drivers/acpi/riscv/rqsc.c line 162
Quoted 7 lines
drivers/acpi/riscv/rqsc.c new file +7
-0+ goto next; + } + + added++; +next: + ctrl = (const void *)ctrl + ctrl->length; + idx++;
Could you turn this whole thing into a do { } while() and update these conditions in the while bit? Then the various gotos become continues.
Quoted 5 lines
drivers/acpi/riscv/rqsc.c new file +5
-0+ } + +if (idx != rqsc->num_controllers) +pr_warn ("table announces %u controllers, found %u\n" , + rqsc->num_controllers, idx);
drivers/acpi/riscv/rqsc.c line 177
Quoted 10 lines
drivers/acpi/riscv/rqsc.c new file +10
-0+ +if (added) +pr_info ("%u CBQRI controllers\n" , added); +else +pr_warn ("no usable CBQRI controller\n" ); +} + +void __init riscv_acpi_rqsc_init (void ) +{ + struct acpi_table_header *table __free(acpi_put_table) = NULL;
See cleanup.h That needs to move to next to the constructor.
drivers/acpi/riscv/rqsc.c line 182
Quoted 5 lines
drivers/acpi/riscv/rqsc.c new file +5
-0+acpi_status status; + +BUILD_BUG_ON (sizeof (struct acpi_rqsc_resource ) !=20 ); +BUILD_BUG_ON (sizeof (struct acpi_rqsc_controller ) !=24 ); +BUILD_BUG_ON (sizeof (struct acpi_table_rqsc ) !=40 );
It's an ACPI table. You should be updating it only in a safe forwards compatible way. Hence I'd not normally expect hard checks that will fail if it changes in acpica.
Quoted 1 line
+
Declare the struct .. * table _free() down here.
drivers/acpi/riscv/rqsc.c line 196
Quoted 13 lines
drivers/acpi/riscv/rqsc.c new file +13
-0+ status =acpi_get_table (ACPI_SIG_RQSC ,0 , &table); +if (status ==AE_NOT_FOUND ) +return ; + +if (ACPI_FAILURE (status)) { +pr_err ("failed to get table: %s\n" , +acpi_format_exception (status)); +return ; + } + +/* +* A later revision could extend the fixed header, which would +* shift the first controller structure. Stop rather than guess.
That would be an ACPI spec bug. Sure they have happened a few times (usually when assumption was no one had implemented something that needed a fix) but the rules for ACPI are very strict that any change even with a version tick should not make incompatible changes. You add stuff and sometime reserve things that previously had values, but you don't move fields around unless there is an offset indicator or size value in the structure to allow you to do that.
If riscv isn't keeping to that, I'd suggest working to make sure people understand this. We can't have a regression because someone put that sort of change in the spec.
drivers/acpi/riscv/rqsc.c line 200
Quoted 4 lines
drivers/acpi/riscv/rqsc.c new file +4
-0+*/ +if (table->revision !=ACPI_RQSC_REVISION ) { +pr_err ("table revision %u, expected %u\n" , + table->revision,ACPI_RQSC_REVISION );
Likewise, that rings alarm bells about the spec process if there is any likelihood of that being needed. The only similar instances that I've seen were where things accidentally broke and we had to deal with that - and HMAT where this happened we at least landed support for v1 and v2 at the same time.
Quoted 11 lines
drivers/acpi/riscv/rqsc.c new file +10
-0+return ; + } + +if (table->length <sizeof (struct acpi_table_rqsc )) { +pr_err ("table truncated: length %u\n" , table->length); +return ; + } + +rqsc_parse ((const struct acpi_table_rqsc *)table); +}
Re: [PATCH 2/3] ACPI: RISC-V: Enumerate CBQRI controllers from the RQSC table
Quoted 11 lines · Jonathan Cameron
Quoted 6 lines · On Tue, 17 Nov 2026 14:11:28 -0800 "Drew Fustini (Tenstorrent)"…
Walk the RQSC table at ACPI init and create a platform device for each CBQRI controller, so one platform driver can serve device tree and ACPI systems. Nothing selects
ACPI_RQSCuntil the CBQRI driver can bind to these devices.Signed-off-by Drew Fustini (Tenstorrent) <[email protected]>Hi Drew
Quoted 7 lines
Very much a drive by review as I haven't even opened the spec yet ;)
Anyhow, various comments inline. Most code readability suggestions.
Thanks,
Jonathan
Hi! Thanks for taking the time to look at these patches. It's helpful to have your perspective even if you haven't looked at the details of the risc-v spec.
Quoted 18 lines
drivers/acpi/riscv/rqsc.c
Quoted 6 lines
drivers/acpi/riscv/rqsc.c new file +0
-0@@ -0,0 +1,210 @@"
drivers/acpi/riscv/rqsc.c line 26
Quoted 6 lines
drivers/acpi/riscv/rqsc.c new file +6
-0+ +static struct platform_device *__init +rqsc_add_device (unsigned int idx,const struct acpi_rqsc_controller *ctrl, +const struct acpi_rqsc_resource *res) +{ +bool is_cc = ctrl->type ==ACPI_RQSC_CONTROLLER_TYPE_CAPACITY ;Not a fan of a bool when we might get more types at some point. If you want to do something like this have a trivial helper bool
rqsc_ctrl_is_cc()and use it inline.
Quoted 6 lines
drivers/acpi/riscv/rqsc.c line 29
Quoted 3 lines
drivers/acpi/riscv/rqsc.c new file +3
-0+ struct platform_device *pdev __free(platform_device_put) = +platform_device_alloc (is_cc ?"cbqri-capacity" :"cbqri-bandwidth" , + idx);Not particularly readable or extensible if more types show up.
I'd use a switch that sets the string. Declare the pdev and__freeafter that.
Good point. I'll drop the bool and add a switch for the controller type.
Quoted 5 lines
drivers/acpi/riscv/rqsc.c line 38
Quoted 1 line
drivers/acpi/riscv/rqsc.c new file +1
-0+if (!pdev)Drag the pdev alloc down to just above this. Having it burried in allocations is not easy to read when you only check for success all the way down here.
Will do.
[..]
Quoted 19 lines
Quoted 7 lines
drivers/acpi/riscv/rqsc.c new file +7
-0+static void __init rqsc_parse (const struct acpi_table_rqsc *rqsc) +{ +const void *end = (const void *)rqsc + rqsc->header.length; +const struct acpi_rqsc_controller *ctrl = (const void *)(rqsc +1 ); +unsigned int idx =0 , added =0 ; + +while ((const void *)ctrl < end) {drivers/acpi/riscv/rqsc.c line 109
Quoted 10 lines
drivers/acpi/riscv/rqsc.c new file +10
-0+const struct acpi_rqsc_resource *res = (const void *)(ctrl +1 ); +struct platform_device *pdev; +phys_addr_t addr; + +/* +* The controller structure must fit and stay inside the +* table. Anything else is corruption and the remaining +* entries cannot be trusted. +*/ + if ((const void *)ctrl + sizeof(*ctrl) > end ||if ((const void *)(ctrl + 1) > end ?
Quoted 8 lines
Which looks familiar. Isn't that
if ((const void *)res > end)
Maybe that is a little confusing as res might be zero size. For that matter I'd not set res until after this check because it might take an invalid value. Doesn't matter as such but is confusing to read.
That makes sense. I'll move res to after the check.
Quoted 45 lines
Quoted 18 lines
drivers/acpi/riscv/rqsc.c new file +18
-0+ ctrl->length < sizeof(*ctrl) || + (const void *)ctrl + ctrl->length > end) { +pr_err ("entry %u is malformed, stopping\n" , idx); +break ; + } + + addr = ctrl->address.address; + +if (ctrl->type !=ACPI_RQSC_CONTROLLER_TYPE_CAPACITY && + ctrl->type !=ACPI_RQSC_CONTROLLER_TYPE_BANDWIDTH ) { +pr_warn ("controller at %pa: unknown type %u, skipping\n" , + &addr, ctrl->type); + goto next; + } + +if (ctrl->address.space_id !=ACPI_ADR_SPACE_SYSTEM_MEMORY || !addr) { +pr_warn ("entry %u: no usable register interface address, skipping\n" , + idx);drivers/acpi/riscv/rqsc.c line 137
Quoted 10 lines
drivers/acpi/riscv/rqsc.c new file +10
-0+ goto next; + } + +if (!ctrl->rcid_count && !ctrl->mcid_count) { +pr_warn ("controller at %pa: no RCIDs and no MCIDs, skipping\n" , + &addr); + goto next; + } + + if (!ctrl->num_resources ||Little fiddly but I'd split this. The reason being that the next check if kind of checking for only one resource, but you only confirm that is ok with
pr_warn()path that follows. So maybeif (!ctrl->num_resources) { pr_warn("controller at %pa: no resource, skipping\n", &addr);I'd go a bit long on lines - not sure ACPI is that fussy as subsystem go.
goto next; } if (ctrl->num_resources > 1) pr_warn("controller at %pa: %u resources, using the first\n", &addr, ctrl->num_resources);
Quoted 7 lines
//now we have clarity that we only care about first resource.
if (ctrl->length < sizeof(*ctrl) + sizeof(*res) || res->length < sizeof(*res)) { pr_warn("controller at %pa: no usable resource, skipping\n", &addr); goto next; }
I agree it does look simpler that way so I'll split it up.
Quoted 15 lines
Quoted 15 lines
drivers/acpi/riscv/rqsc.c new file +15
-0+ ctrl->length < sizeof(*ctrl) + sizeof(*res) || + res->length < sizeof(*res)) { +pr_warn ("controller at %pa: no usable resource, skipping\n" , + &addr); + goto next; + } + +if (ctrl->num_resources >1 ) +pr_warn ("controller at %pa: %u resources, using the first\n" , + &addr, ctrl->num_resources); + +if (!rqsc_resource_ok (ctrl, res, addr)) + goto next; + + pdev =rqsc_add_device (idx, ctrl, res);
Quoted 8 lines
drivers/acpi/riscv/rqsc.c line 155
Quoted 3 lines
drivers/acpi/riscv/rqsc.c new file +3
-0+if (IS_ERR (pdev)) { +pr_warn ("controller at %pa: failed to add device: %pe\n" , + &addr, pdev);This feels like the sort of thing you should just fail init on. Papering over bits of the table that don't like you expect might be dealing with changes that have been made. Failing to add a device is something much worse.
Okay, I'll make the parsing stop when this happens.
Quoted 11 lines
drivers/acpi/riscv/rqsc.c line 162
Quoted 8 lines
drivers/acpi/riscv/rqsc.c new file +7
-0+ goto next; + } + + added++; +next: + ctrl = (const void *)ctrl + ctrl->length; + idx++;Could you turn this whole thing into a do { }
while()and update these conditions in the while bit? Then the various gotos become continues.
I think a for loop is better as it keeps the bounds check before the first entry, but I'll move the increment into the for statement so the gotos become continue.
Quoted 9 lines
Quoted 9 lines
drivers/acpi/riscv/rqsc.c new file +9
-0+ } + +if (idx != rqsc->num_controllers) +pr_warn ("table announces %u controllers, found %u\n" , + rqsc->num_controllers, idx); + +if (added) +pr_info ("%u CBQRI controllers\n" , added); +else
Quoted 8 lines
drivers/acpi/riscv/rqsc.c line 177
Quoted 6 lines
drivers/acpi/riscv/rqsc.c new file +6
-0+pr_warn ("no usable CBQRI controller\n" ); +} + +void __init riscv_acpi_rqsc_init (void ) +{ + struct acpi_table_header *table __free(acpi_put_table) = NULL;See
cleanup.hThat needs to move to next to the constructor.
Okay, I will move it.
Quoted 9 lines
drivers/acpi/riscv/rqsc.c line 182
Quoted 6 lines
drivers/acpi/riscv/rqsc.c new file +5
-0+acpi_status status; + +BUILD_BUG_ON (sizeof (struct acpi_rqsc_resource ) !=20 ); +BUILD_BUG_ON (sizeof (struct acpi_rqsc_controller ) !=24 ); +BUILD_BUG_ON (sizeof (struct acpi_table_rqsc ) !=40 );It's an ACPI table. You should be updating it only in a safe forwards compatible way. Hence I'd not normally expect hard checks that will fail if it changes in acpica.
Thanks for the advice as I am new to ACPI. I will drop the checks.
Quoted 29 lines
drivers/acpi/riscv/rqsc.c line 101
Quoted 1 line
drivers/acpi/riscv/rqsc.c new file +1
-0+Declare the struct .. * table
_free()down here.drivers/acpi/riscv/rqsc.c line 196
Quoted 13 lines
drivers/acpi/riscv/rqsc.c new file +13
-0+ status =acpi_get_table (ACPI_SIG_RQSC ,0 , &table); +if (status ==AE_NOT_FOUND ) +return ; + +if (ACPI_FAILURE (status)) { +pr_err ("failed to get table: %s\n" , +acpi_format_exception (status)); +return ; + } + +/* +* A later revision could extend the fixed header, which would +* shift the first controller structure. Stop rather than guess. That would be an ACPI spec bug. Sure they have happened a few times (usually when assumption was no one had implemented something that needed a fix) but the rules for ACPI are very strict that any change even with a version tick should not make incompatible changes. You add stuff and sometime reserve things that previously had values, but you don't move fields around unless there is an offset indicator or size value in the structure to allow you to do that.
If riscv isn't keeping to that, I'd suggest working to make sure people understand this. We can't have a regression because someone put that sort of change in the spec.
Quoted 10 lines
drivers/acpi/riscv/rqsc.c line 200
Quoted 4 lines
drivers/acpi/riscv/rqsc.c new file +4
-0+*/ +if (table->revision !=ACPI_RQSC_REVISION ) { +pr_err ("table revision %u, expected %u\n" , + table->revision,ACPI_RQSC_REVISION );Likewise, that rings alarm bells about the spec process if there is any likelihood of that being needed. The only similar instances that I've seen were where things accidentally broke and we had to deal with that - and HMAT where this happened we at least landed support for v1 and v2 at the same time.
The RQSC spec doesn't suggest later revs would move fields. I think I just lack experience with ACPI and was being too cautious with these checks. I'll drop the comment and the check.
Thanks,
Drew
Re: [External] [PATCH 2/3] ACPI: RISC-V: Enumerate CBQRI controllers from the RQSC table
In reply to Drew Fustini (Tenstorrent)Hi Drew,
Quoted 83 lines · Drew Fustini (Tenstorrent)
Walk the RQSC table at ACPI init and create a platform device for each CBQRI controller, so one platform driver can serve device tree and ACPI systems. Nothing selects
ACPI_RQSCuntil the CBQRI driver can bind to these devices.Signed-off-by Drew Fustini (Tenstorrent) <[email protected]>--- drivers/acpi/riscv/Kconfig | 3 + drivers/acpi/riscv/Makefile | 1 + drivers/acpi/riscv/init.c | 2 + drivers/acpi/riscv/init.h | 1 + drivers/acpi/riscv/rqsc.c | 210 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 217 insertions(+)drivers/acpi/riscv/Kconfig +3
-0@@ -5,3 +5,6 @@ config ACPI_RIMT bool + +config ACPI_RQSC + booldrivers/acpi/riscv/Makefile +1
-0@@ -3,3 +3,4 @@ obj-y += rhct.o init.o irq.o obj-$(CONFIG_ACPI_PROCESSOR_IDLE) += cpuidle.o obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o obj-$(CONFIG_ACPI_RIMT) += rimt.o +obj-$(CONFIG_ACPI_RQSC) += rqsc.odrivers/acpi/riscv/init.c +2
-0@@ -12,4 +12,6 @@ void __init acpi_arch_init(void)riscv_acpi_init_gsi_mapping ();if (IS_ENABLED (CONFIG_ACPI_RIMT ))riscv_acpi_rimt_init (); +if (IS_ENABLED (CONFIG_ACPI_RQSC )) +riscv_acpi_rqsc_init (); }drivers/acpi/riscv/init.h +1
-0@@ -3,3 +3,4 @@void __init riscv_acpi_init_gsi_mapping (void );void __init riscv_acpi_rimt_init (void ); +void __init riscv_acpi_rqsc_init (void );drivers/acpi/riscv/rqsc.c new file +22
-0@@ -0,0 +1,210 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Create a platform device for each CBQRI controller described by the ACPI +* RISC-V Quality of Service Controllers (RQSC) table. +*/ + +#define pr_fmt (fmt) "ACPI: RQSC: " fmt + +#include <linux/acpi.h> +#include <linux/bug.h> +#include <linux/cleanup.h> +#include <linux/err.h> +#include <linux/ioport.h> +#include <linux/mm.h> +#include <linux/platform_device.h> +#include <linux/property.h> +#include <linux/wordpart.h> + +#include "init.h" +#include "rqsc.h" + +static struct platform_device * __init
drivers/acpi/riscv/rqsc.c line 32
Quoted 10 lines
drivers/acpi/riscv/rqsc.c new file +10
-0+rqsc_add_device(unsigned int idx, const struct acpi_rqsc_controller *ctrl, + const struct acpi_rqsc_resource *res) +{ + bool is_cc = ctrl->type == ACPI_RQSC_CONTROLLER_TYPE_CAPACITY; + struct platform_device *pdev __free(platform_device_put) = +platform_device_alloc (is_cc ?"cbqri-capacity" :"cbqri-bandwidth" , + idx); +phys_addr_t addr = ctrl->address.address; +/* The GAS carries no length, so claim up to the end of the page. */ +struct resource mem =DEFINE_RES_MEM (addr,PAGE_SIZE -offset_in_page (addr));
In the QEMU test shown in the cover letter, the controller base addresses are page-aligned and lie in separate pages, so the resources do not overlap. However, if two non-overlapping 48-byte register blocks are located at 0x4820000 and 0x4820040, their resources would both extend to 0x4820fff, causing one controller's probe to fail with -EBUSY when requesting the MMIO region.
Since RQSC provides the base address but does not define the MMIO size, could we first request and map the fixed 8-byte cc_capabilities register to read NCBLKS, then release the temporary mapping and reservation, update the platform resource, and request/map the calculated register span?
For a capacity controller, cc_block_mask starts at offset 0x20 and its size is roundup(NCBLKS, 64) / 8 bytes. With cc_cunits following it, the span can be calculated as:
span = 0x20 + roundup(NCBLKS, 64) / 8 + 8;
This would make the MMIO resource follow the CBQRI register layout without depending on the kernel page boundary.
Thanks,
Yunhui
Quoted 182 lines
drivers/acpi/riscv/rqsc.c new file +178
-1+/* rcid, mcid, cache id and a sentinel */ +struct property_entry props[4 ] = {}; +unsigned int n =0 ; +int ret; + +if (!pdev) +return ERR_PTR (-ENOMEM ); + + ret =platform_device_add_resources (pdev, &mem,1 ); +if (ret) +return ERR_PTR (ret); + + props[n++] =PROPERTY_ENTRY_U32 ("riscv,cbqri-rcid" , ctrl->rcid_count); + props[n++] =PROPERTY_ENTRY_U32 ("riscv,cbqri-mcid" , ctrl->mcid_count); +if (is_cc) + props[n++] =PROPERTY_ENTRY_U32 ("riscv,cbqri-cache-id" , +lower_32_bits (res->id1)); +else +set_dev_node (&pdev->dev,pxm_to_node (lower_32_bits (res->id1))); + + ret =device_create_managed_software_node (&pdev->dev, props,NULL ); +if (ret) +return ERR_PTR (ret); + + ret =platform_device_add (pdev); +if (ret) +return ERR_PTR (ret); + +return_ptr (pdev); +} + +/* +* Check the one resource the controller is described with. A capacity +* controller names a processor cache by PPTT Cache ID, a bandwidth +* controller a memory range by SRAT proximity domain. Both IDs are +* the low 32 bits of Resource ID 1, the upper half is reserved. +*/ +static bool __init rqsc_resource_ok (const struct acpi_rqsc_controller *ctrl, +const struct acpi_rqsc_resource *res, +phys_addr_t addr) +{ +u8 want_type, want_id_type; + +if (ctrl->type ==ACPI_RQSC_CONTROLLER_TYPE_CAPACITY ) { + want_type =ACPI_RQSC_RESOURCE_TYPE_CACHE ; + want_id_type =ACPI_RQSC_RESOURCE_ID_TYPE_PROCESSOR_CACHE ; + }else { + want_type =ACPI_RQSC_RESOURCE_TYPE_MEMORY ; + want_id_type =ACPI_RQSC_RESOURCE_ID_TYPE_MEMORY_RANGE ; + } + +if (res->type != want_type || res->id_type != want_id_type) { +pr_warn ("controller at %pa: resource type %u id type %u does not match controller type %u, skipping\n" , + &addr, res->type, res->id_type, ctrl->type); +return false; + } + +return true; +} + +static void __init rqsc_parse (const struct acpi_table_rqsc *rqsc) +{ +const void *end = (const void *)rqsc + rqsc->header.length; +const struct acpi_rqsc_controller *ctrl = (const void *)(rqsc +1 ); +unsigned int idx =0 , added =0 ; + +while ((const void *)ctrl < end) { +const struct acpi_rqsc_resource *res = (const void *)(ctrl +1 ); +struct platform_device *pdev; +phys_addr_t addr; + +/* +* The controller structure must fit and stay inside the +* table. Anything else is corruption and the remaining +* entries cannot be trusted. +*/ +if ((const void *)ctrl +sizeof (*ctrl) > end || + ctrl->length <sizeof (*ctrl) || + (const void *)ctrl + ctrl->length > end) { +pr_err ("entry %u is malformed, stopping\n" , idx); +break ; + } + + addr = ctrl->address.address; + +if (ctrl->type !=ACPI_RQSC_CONTROLLER_TYPE_CAPACITY && + ctrl->type !=ACPI_RQSC_CONTROLLER_TYPE_BANDWIDTH ) { +pr_warn ("controller at %pa: unknown type %u, skipping\n" , + &addr, ctrl->type); + goto next; + } + +if (ctrl->address.space_id !=ACPI_ADR_SPACE_SYSTEM_MEMORY || !addr) { +pr_warn ("entry %u: no usable register interface address, skipping\n" , + idx); + goto next; + } + +if (!ctrl->rcid_count && !ctrl->mcid_count) { +pr_warn ("controller at %pa: no RCIDs and no MCIDs, skipping\n" , + &addr); + goto next; + } + +if (!ctrl->num_resources || + ctrl->length <sizeof (*ctrl) +sizeof (*res) || + res->length <sizeof (*res)) { +pr_warn ("controller at %pa: no usable resource, skipping\n" , + &addr); + goto next; + } + +if (ctrl->num_resources >1 ) +pr_warn ("controller at %pa: %u resources, using the first\n" , + &addr, ctrl->num_resources); + +if (!rqsc_resource_ok (ctrl, res, addr)) + goto next; + + pdev =rqsc_add_device (idx, ctrl, res); +if (IS_ERR (pdev)) { +pr_warn ("controller at %pa: failed to add device: %pe\n" , + &addr, pdev); + goto next; + } + + added++; +next: + ctrl = (const void *)ctrl + ctrl->length; + idx++; + } + +if (idx != rqsc->num_controllers) +pr_warn ("table announces %u controllers, found %u\n" , + rqsc->num_controllers, idx); + +if (added) +pr_info ("%u CBQRI controllers\n" , added); +else +pr_warn ("no usable CBQRI controller\n" ); +} + +void __init riscv_acpi_rqsc_init (void ) +{ + struct acpi_table_header *table __free(acpi_put_table) = NULL; +acpi_status status; + +BUILD_BUG_ON (sizeof (struct acpi_rqsc_resource ) !=20 ); +BUILD_BUG_ON (sizeof (struct acpi_rqsc_controller ) !=24 ); +BUILD_BUG_ON (sizeof (struct acpi_table_rqsc ) !=40 ); + + status =acpi_get_table (ACPI_SIG_RQSC ,0 , &table); +if (status ==AE_NOT_FOUND ) +return ; + +if (ACPI_FAILURE (status)) { +pr_err ("failed to get table: %s\n" , +acpi_format_exception (status)); +return ; + } + +/* +* A later revision could extend the fixed header, which would +* shift the first controller structure. Stop rather than guess. +*/ +if (table->revision !=ACPI_RQSC_REVISION ) { +pr_err ("table revision %u, expected %u\n" , + table->revision,ACPI_RQSC_REVISION ); +return ; + } + +if (table->length <sizeof (struct acpi_table_rqsc )) { +pr_err ("table truncated: length %u\n" , table->length); +return ; + } + +rqsc_parse ((const struct acpi_table_rqsc *)table); +} --2.43.0
PATCH 3/3 riscv_cbqri: Bind to RQSC platform devices
In reply to Drew Fustini (Tenstorrent)Let the capacity controller driver probe the "cbqri-capacity" platform devices created from the RQSC table. The cache is named by its PPTT Cache ID and the PPTT gives its level. Select ACPI_RQSC so the table is parsed and drop the OF dependency.
No change for device tree systems.
--- drivers/resctrl/Kconfig | 11 ++-- drivers/resctrl/cbqri_capacity.c | 111 ++++++++++++++++++++++++++++----------- 2 files changed, 87 insertions(+), 35 deletions(-)
drivers/resctrl/Kconfig +6 -5
@@ -35,6 +35,7 @@ config ARM64_MPAM_RESCTRL_FS menuconfig RISCV_CBQRI bool "RISC-V CBQRI support" depends on RISCV && RISCV_ISA_SSQOSID + select ACPI_RQSC if ACPI select ARCH_HAS_CPU_RESCTRL default y help
@@ -47,14 +48,14 @@ if RISCV_CBQRI config RISCV_CBQRI_CAPACITY bool "RISC-V CBQRI cache capacity-allocation controller" - depends on OF help Enable driver for a RISC-V CBQRI capacity controller that - governs a CPU cache, matching the "riscv,cbqri-capacity-controller" - compatible. The controller's cache phandle gives the cache level and - id, which the driver registers as a resctrl cache-allocation resource. + governs a CPU cache, described in device tree by the + "riscv,cbqri-capacity-controller" compatible or in ACPI by the RQSC + table. The firmware description gives the cache level and id, which + the driver registers as a resctrl cache-allocation resource. - Say N unless your device tree describes a CBQRI capacity controller. + Say N unless your firmware describes a CBQRI capacity controller. endif
drivers/resctrl/cbqri_capacity.c +81 -30
173 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 3/3] riscv_cbqri: Bind to RQSC platform devices
Quoted 8 lines · On Tue, 17 Nov 2026 14:11:29 -0800 "Drew Fustini (Tenstorrent)"…
Let the capacity controller driver probe the "cbqri-capacity" platform devices created from the RQSC table. The cache is named by its PPTT Cache ID and the PPTT gives its level. Select
ACPI_RQSCso the table is parsed and drop the OF dependency.No change for device tree systems.
Signed-off-by Drew Fustini (Tenstorrent) <[email protected]>
Has the DT support landed? If not feels like a few tweaks in that would make this less noisy.
If not, see below for one tidy up I'd make here if you can't push it back to that series.
You almost never want to do manual device_node puts these days!
It's one of the nicest places to use the cleanup.h magic.
Quoted 56 lines
--- drivers/resctrl/Kconfig | 11 ++-- drivers/resctrl/cbqri_capacity.c | 111 ++++++++++++++++++++++++++++----------- 2 files changed, 87 insertions(+), 35 deletions(-)drivers/resctrl/Kconfig +6
-5@@ -35,6 +35,7 @@ config ARM64_MPAM_RESCTRL_FS menuconfig RISCV_CBQRI bool "RISC-V CBQRI support" depends on RISCV && RISCV_ISA_SSQOSID + select ACPI_RQSC if ACPI select ARCH_HAS_CPU_RESCTRL default y help@@ -47,14 +48,14 @@ if RISCV_CBQRI config RISCV_CBQRI_CAPACITY bool "RISC-V CBQRI cache capacity-allocation controller" - depends on OF help Enable driver for a RISC-V CBQRI capacity controller that - governs a CPU cache, matching the "riscv,cbqri-capacity-controller" - compatible. The controller's cache phandle gives the cache level and - id, which the driver registers as a resctrl cache-allocation resource. + governs a CPU cache, described in device tree by the + "riscv,cbqri-capacity-controller" compatible or in ACPI by the RQSC + table. The firmware description gives the cache level and id, which + the driver registers as a resctrl cache-allocation resource. - Say N unless your device tree describes a CBQRI capacity controller. + Say N unless your firmware describes a CBQRI capacity controller. endifdrivers/resctrl/cbqri_capacity.c +2
-7-static int cbqri_capacity_probe (struct platform_device *pdev) +static int cbqri_capacity_of_cache (struct device *dev,u32 *cache_level, +u32 *cache_id) { -struct device *dev = &pdev->dev; -struct cbqri_controller_info info = {};struct device_node *cache_np; -struct resource *res; -void __iomem *base; -u32 rcid_count, cache_level, cache_id;bool found = false;int cpu, ret; - base =devm_platform_get_and_ioremap_resource (pdev,0 , &res);
drivers/resctrl/cbqri_capacity.c line 32
Quoted 10 lines
drivers/resctrl/cbqri_capacity.c +0
-9-if (IS_ERR (base)) -return PTR_ERR (base); - - ret =of_property_read_u32 (dev->of_node,"riscv,cbqri-rcid" , &rcid_count); -if (ret) { -dev_err (dev,"missing riscv,cbqri-rcid\n" ); -return ret; - } - cache_np =of_parse_phandle (dev->of_node,"riscv,cbqri-cache" ,0 );
Whilst you are here.
struct device_node *cache_np __free(device_node) = of_parse_phandle();
and drop all the gotos. I haven't checked but if there is a path where you want to hang on to it, no_free_ptr() that.
Quoted 48 lines
drivers/resctrl/cbqri_capacity.c +10
-7if (!cache_np) {dev_err (dev,"missing riscv,cbqri-cache phandle\n" );return -EINVAL ; } - ret =of_property_read_u32 (cache_np,"cache-level" , &cache_level); + ret =of_property_read_u32 (cache_np,"cache-level" , cache_level);if (ret) {dev_err (dev,"%pOF: missing cache-level\n" , cache_np); goto out_put; } -if (cache_level !=2 && cache_level !=3 ) { +if (*cache_level !=2 && *cache_level !=3 ) {dev_err (dev,"%pOF: unsupported cache-level %u\n" , - cache_np, cache_level); + cache_np, *cache_level); ret = -EINVAL ; goto out_put; }@@ -73,10 +63,10 @@ static int cbqri_capacity_probe(struct platform_device *pdev)*/ cpus_read_lock ();for_each_online_cpu (cpu) { -struct cacheinfo *ci =get_cpu_cacheinfo_level (cpu, cache_level); +struct cacheinfo *ci =get_cpu_cacheinfo_level (cpu, *cache_level);if (ci && ci->fw_token == cache_np) { - cache_id = ci->id; + *cache_id = ci->id; found = true;break ; }@@ -85,11 +75,74 @@ static int cbqri_capacity_probe(struct platform_device *pdev)if (!found) {dev_err (dev,"%pOF: no online hart reports an L%u cache with a cache id for this node\n" , - cache_np, cache_level); + cache_np, *cache_level); ret = -ENODEV ; - goto out_put; } +out_put: +of_node_put (cache_np); +return ret; +}
Re: [PATCH 3/3] riscv_cbqri: Bind to RQSC platform devices
Quoted 10 lines · Jonathan Cameron
Quoted 7 lines · On Tue, 17 Nov 2026 14:11:29 -0800 "Drew Fustini (Tenstorrent)"…
Let the capacity controller driver probe the "cbqri-capacity" platform devices created from the RQSC table. The cache is named by its PPTT Cache ID and the PPTT gives its level. Select
ACPI_RQSCso the table is parsed and drop the OF dependency.No change for device tree systems.
Quoted 7 lines
Quoted 1 line
Signed-off-by Drew Fustini (Tenstorrent) <[email protected]>Has the DT support landed? If not feels like a few tweaks in that would make this less noisy.
If not, see below for one tidy up I'd make here if you can't push it back to that series.
Sure, I will roll the changes around cbqri_capacity_of_cache() into a v13 and leave that out of this patch.
Quoted 3 lines
You almost never want to do manual
device_nodeputs these days!It's one of the nicest places to use the
cleanup.hmagic.
Good idea, I will use it for device_node.
Quoted 6 lines
Quoted 1 line
cache_np=of_parse_phandle(dev->of_node, "riscv,cbqri-cache", 0);Whilst you are here.
struct device_node *cache_np __free(device_node) = of_parse_phandle();and drop all the gotos. I haven't checked but if there is a path where you want to hang on to it,
no_free_ptr()that.
Will do. There should not be a need for no_free_ptr() for this one.
Thanks,
Drew
Re: [External] [PATCH 3/3] riscv_cbqri: Bind to RQSC platform devices
In reply to Drew Fustini (Tenstorrent)Hi Drew,
Quoted 211 lines · Drew Fustini (Tenstorrent)
Let the capacity controller driver probe the "cbqri-capacity" platform devices created from the RQSC table. The cache is named by its PPTT Cache ID and the PPTT gives its level. Select
ACPI_RQSCso the table is parsed and drop the OF dependency.No change for device tree systems.
Signed-off-by Drew Fustini (Tenstorrent) <[email protected]>--- drivers/resctrl/Kconfig | 11 ++-- drivers/resctrl/cbqri_capacity.c | 111 ++++++++++++++++++++++++++++----------- 2 files changed, 87 insertions(+), 35 deletions(-)drivers/resctrl/Kconfig +6
-5@@ -35,6 +35,7 @@ config ARM64_MPAM_RESCTRL_FS menuconfig RISCV_CBQRI bool "RISC-V CBQRI support" depends on RISCV && RISCV_ISA_SSQOSID + select ACPI_RQSC if ACPI select ARCH_HAS_CPU_RESCTRL default y help@@ -47,14 +48,14 @@ if RISCV_CBQRI config RISCV_CBQRI_CAPACITY bool "RISC-V CBQRI cache capacity-allocation controller" - depends on OF help Enable driver for a RISC-V CBQRI capacity controller that - governs a CPU cache, matching the "riscv,cbqri-capacity-controller" - compatible. The controller's cache phandle gives the cache level and - id, which the driver registers as a resctrl cache-allocation resource. + governs a CPU cache, described in device tree by the + "riscv,cbqri-capacity-controller" compatible or in ACPI by the RQSC + table. The firmware description gives the cache level and id, which + the driver registers as a resctrl cache-allocation resource. - Say N unless your device tree describes a CBQRI capacity controller. + Say N unless your firmware describes a CBQRI capacity controller. endifdrivers/resctrl/cbqri_capacity.c +79
-26@@ -3,11 +3,14 @@* Platform driver for a RISC-V CBQRI capacity controller that backs a CPU * cache. The controller is described in device tree by the generic * "riscv,cbqri-capacity-controller" compatible together with a phandle to the -* cache node it governs. The driver hands it to the CBQRI core, which probes -* the capabilities register and exposes a controller that supports allocation -* as the resctrl cache allocation resource for that cache. +* cache node it governs, or in ACPI by the RQSC table, whose parser creates a +* "cbqri-capacity" platform device that carries the PPTT Cache ID of the +* cache. The driver hands it to the CBQRI core, which probes the capabilities +* register and exposes a controller that supports allocation as the resctrl +* cache allocation resource for that cache. */ +#include <linux/acpi.h> #include <linux/cacheinfo.h> #include <linux/cpu.h> #include <linux/device-id/of.h> @@ -15,45 +18,32 @@#include <linux/ioport.h> #include <linux/of.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/riscv_cbqri.h> #include <linux/types.h> -static int cbqri_capacity_probe (struct platform_device *pdev) +static int cbqri_capacity_of_cache (struct device *dev,u32 *cache_level, +u32 *cache_id) { -struct device *dev = &pdev->dev; -struct cbqri_controller_info info = {};struct device_node *cache_np; -struct resource *res; -void __iomem *base; -u32 rcid_count, cache_level, cache_id;bool found = false;int cpu, ret; - base =devm_platform_get_and_ioremap_resource (pdev,0 , &res); -if (IS_ERR (base)) -return PTR_ERR (base); - - ret =of_property_read_u32 (dev->of_node,"riscv,cbqri-rcid" , &rcid_count); -if (ret) { -dev_err (dev,"missing riscv,cbqri-rcid\n" ); -return ret; - } - cache_np =of_parse_phandle (dev->of_node,"riscv,cbqri-cache" ,0 );if (!cache_np) {dev_err (dev,"missing riscv,cbqri-cache phandle\n" );return -EINVAL ; } - ret =of_property_read_u32 (cache_np,"cache-level" , &cache_level); + ret =of_property_read_u32 (cache_np,"cache-level" , cache_level);if (ret) {dev_err (dev,"%pOF: missing cache-level\n" , cache_np); goto out_put; } -if (cache_level !=2 && cache_level !=3 ) { +if (*cache_level !=2 && *cache_level !=3 ) {dev_err (dev,"%pOF: unsupported cache-level %u\n" , - cache_np, cache_level); + cache_np, *cache_level); ret = -EINVAL ; goto out_put; }@@ -73,10 +63,10 @@ static int cbqri_capacity_probe(struct platform_device *pdev)*/ cpus_read_lock ();for_each_online_cpu (cpu) { -struct cacheinfo *ci =get_cpu_cacheinfo_level (cpu, cache_level); +struct cacheinfo *ci =get_cpu_cacheinfo_level (cpu, *cache_level);if (ci && ci->fw_token == cache_np) { - cache_id = ci->id; + *cache_id = ci->id; found = true;break ; }@@ -85,11 +75,74 @@ static int cbqri_capacity_probe(struct platform_device *pdev)if (!found) {dev_err (dev,"%pOF: no online hart reports an L%u cache with a cache id for this node\n" , - cache_np, cache_level); + cache_np, *cache_level); ret = -ENODEV ; - goto out_put; } +out_put: +of_node_put (cache_np); +return ret; +} + +/* +* The RQSC table names the cache by its PPTT Cache ID, which the table parser +* passes on in the riscv,cbqri-cache-id property. cacheinfo takes the cache +* id from the same PPTT field, and the PPTT gives the level of the cache. +*/ +static int cbqri_capacity_acpi_cache (struct device *dev,u32 *cache_level, +u32 *cache_id) +{ +int level, ret; + + ret =device_property_read_u32 (dev,"riscv,cbqri-cache-id" , cache_id); +if (ret) { +dev_err (dev,"missing riscv,cbqri-cache-id\n" ); +return ret; + } + + level =find_acpi_cache_level_from_id (*cache_id); +if (level <0 ) { +dev_err (dev,"no PPTT cache with Cache ID %u\n" , *cache_id); +return level; + } + +if (level !=2 && level !=3 ) { +dev_err (dev,"unsupported cache level %d for Cache ID %u\n" , + level, *cache_id); +return -EINVAL ; + } + + *cache_level = level; + +return 0 ; +} + +static int cbqri_capacity_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct cbqri_controller_info info = {}; +struct resource *res; +void __iomem *base; +u32 rcid_count, cache_level, cache_id; +int ret; + + base =devm_platform_get_and_ioremap_resource (pdev,0 , &res); +if (IS_ERR (base)) +return PTR_ERR (base); + + ret =device_property_read_u32 (dev,"riscv,cbqri-rcid" , &rcid_count); +if (ret) { +dev_err (dev,"missing riscv,cbqri-rcid\n" ); +return ret; + } + +if (dev->of_node) + ret =cbqri_capacity_of_cache (dev, &cache_level, &cache_id); +else + ret =cbqri_capacity_acpi_cache (dev, &cache_level, &cache_id); +if (ret) +return ret; + info.type =CBQRI_CONTROLLER_TYPE_CAPACITY ; info.base = base; info.addr = res->start;
drivers/resctrl/cbqri_capacity.c static int cbqri_capacity_probe(struct platform_device *pdev) · line 158
Quoted 6 lines
drivers/resctrl/cbqri_capacity.c +1
-1@@ -101,15 +154,13 @@ static int cbqri_capacity_probe(struct platform_device *pdev) ret =riscv_cbqri_register_cc (&info);if (ret) {dev_err (dev,"failed to register capacity controller: %d\n" , ret); - goto out_put; +return ret; }
The same multiple-controller case applies to RQSC-described devices here:
https://lore.kernel.org/all/CAEEQ3w=voZYrfcMuKC_SQG9U8hYN_thcc02nf_PgMu5UyuG32Q@mail.gmail.com/
Quoted 13 lines
drivers/resctrl/cbqri_capacity.c +1
-4dev_info (dev,"registered L%u capacity controller at %pa (cache_id=%u, rcid=%u)\n" , cache_level, &info.addr, cache_id, rcid_count); -out_put: -of_node_put (cache_np); -return ret; +return 0 ; }static const struct of_device_id cbqri_capacity_of_match[] = { --
Quoted 2 lines
2.43.0
Thanks,
Yunhui
Re: [External] [PATCH 3/3] riscv_cbqri: Bind to RQSC platform devices
Quoted 1 line · yunhui cui
Hi Drew,
Hi!
[..]
Quoted 11 lines
drivers/resctrl/cbqri_capacity.c static int cbqri_capacity_probe(struct platform_device *pdev) · line 158
Quoted 7 lines
drivers/resctrl/cbqri_capacity.c +1
-1@@ -101,15 +154,13 @@ static int cbqri_capacity_probe(struct platform_device *pdev) ret =riscv_cbqri_register_cc (&info);if (ret) {dev_err (dev,"failed to register capacity controller: %d\n" , ret); - goto out_put; +return ret; }The same multiple-controller case applies to RQSC-described devices here:
https://lore.kernel.org/all/CAEEQ3w=voZYrfcMuKC_SQG9U8hYN_thcc02nf_PgMu5UyuG32Q@mail.gmail.com/
I would prefer to handle that scenario in a future series as I am not sure how I would test it.
Do you have hardware that you can test it on?
Thanks,
Drew