mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] ACPI: RISC-V: Add support for the RQSC table
@ 2026-11-17 22:11 Drew Fustini (Tenstorrent)
  2026-11-17 22:11 ` [PATCH 1/3] ACPI: RISC-V: Add RQSC table definitions Drew Fustini (Tenstorrent)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Drew Fustini (Tenstorrent) @ 2026-11-17 22:11 UTC (permalink / raw)
  To: Sunil V L
  Cc: Rafael J. Wysocki, Len Brown, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Atish Patra, Anup Patel, Chen Pei,
	yunhui cui, Reinette Chatre, Radim Krčmář,
	Zeng Heng, Conor Dooley, Ben Horgan, James Morse, Tony Luck,
	Adrien Ricciardi, Zhanpeng Zhang, Gong Shuai, Gong Shuai,
	Weiwei Li, Liu Zhiwei, Kornel Dulęba, Samuel Holland,
	guo.wenjia23, liu.qingtao2, Dave Martin, Babu Moger, Fenghua Yu,
	Peter Newman, Shaopeng Tan, Jonathan Cameron, Catalin Marinas,
	linux-acpi, linux-riscv, linux-kernel, Drew Fustini (Tenstorrent)

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.3

The 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/20260601-ssqosid-cbqri-rqsc-v7-0-v6-0-baf00f50028a@kernel.org/
[5] https://lore.kernel.org/all/20261114-dfustini-atl-sc-cbqri-dt-v12-0-6ef1f627072d@kernel.org/
[6] https://lore.kernel.org/qemu-devel/20261113-riscv-rqsc-v2-0-34d47fa4141e@kernel.org/

Signed-off-by: Drew Fustini (Tenstorrent) <fustini@kernel.org>
---
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,
--  
Drew Fustini (Tenstorrent) <fustini@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] ACPI: RISC-V: Add RQSC table definitions
  2026-11-17 22:11 [PATCH 0/3] ACPI: RISC-V: Add support for the RQSC table Drew Fustini (Tenstorrent)
@ 2026-11-17 22:11 ` Drew Fustini (Tenstorrent)
  2026-11-17 22:11 ` [PATCH 2/3] ACPI: RISC-V: Enumerate CBQRI controllers from the RQSC table Drew Fustini (Tenstorrent)
  2026-11-17 22:11 ` [PATCH 3/3] riscv_cbqri: Bind to RQSC platform devices Drew Fustini (Tenstorrent)
  2 siblings, 0 replies; 4+ messages in thread
From: Drew Fustini (Tenstorrent) @ 2026-11-17 22:11 UTC (permalink / raw)
  To: Sunil V L
  Cc: Rafael J. Wysocki, Len Brown, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Atish Patra, Anup Patel, Chen Pei,
	yunhui cui, Reinette Chatre, Radim Krčmář,
	Zeng Heng, Conor Dooley, Ben Horgan, James Morse, Tony Luck,
	Adrien Ricciardi, Zhanpeng Zhang, Gong Shuai, Gong Shuai,
	Weiwei Li, Liu Zhiwei, Kornel Dulęba, Samuel Holland,
	guo.wenjia23, liu.qingtao2, Dave Martin, Babu Moger, Fenghua Yu,
	Peter Newman, Shaopeng Tan, Jonathan Cameron, Catalin Marinas,
	linux-acpi, linux-riscv, linux-kernel, 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/riscv until ACPICA carries them
in actbl2.h.

Link: https://github.com/open-acpica/acpica/pull/1262
Signed-off-by: Drew Fustini (Tenstorrent) <fustini@kernel.org>
---
 drivers/acpi/riscv/rqsc.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/drivers/acpi/riscv/rqsc.h b/drivers/acpi/riscv/rqsc.h
new file mode 100644
index 000000000000..d9a4ce0f1c10
--- /dev/null
+++ b/drivers/acpi/riscv/rqsc.h
@@ -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 */

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] ACPI: RISC-V: Enumerate CBQRI controllers from the RQSC table
  2026-11-17 22:11 [PATCH 0/3] ACPI: RISC-V: Add support for the RQSC table Drew Fustini (Tenstorrent)
  2026-11-17 22:11 ` [PATCH 1/3] ACPI: RISC-V: Add RQSC table definitions Drew Fustini (Tenstorrent)
@ 2026-11-17 22:11 ` Drew Fustini (Tenstorrent)
  2026-11-17 22:11 ` [PATCH 3/3] riscv_cbqri: Bind to RQSC platform devices Drew Fustini (Tenstorrent)
  2 siblings, 0 replies; 4+ messages in thread
From: Drew Fustini (Tenstorrent) @ 2026-11-17 22:11 UTC (permalink / raw)
  To: Sunil V L
  Cc: Rafael J. Wysocki, Len Brown, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Atish Patra, Anup Patel, Chen Pei,
	yunhui cui, Reinette Chatre, Radim Krčmář,
	Zeng Heng, Conor Dooley, Ben Horgan, James Morse, Tony Luck,
	Adrien Ricciardi, Zhanpeng Zhang, Gong Shuai, Gong Shuai,
	Weiwei Li, Liu Zhiwei, Kornel Dulęba, Samuel Holland,
	guo.wenjia23, liu.qingtao2, Dave Martin, Babu Moger, Fenghua Yu,
	Peter Newman, Shaopeng Tan, Jonathan Cameron, Catalin Marinas,
	linux-acpi, linux-riscv, linux-kernel, 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.

Signed-off-by: Drew Fustini (Tenstorrent) <fustini@kernel.org>
---
 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(+)

diff --git a/drivers/acpi/riscv/Kconfig b/drivers/acpi/riscv/Kconfig
index 046296a18d00..2f2304bf0681 100644
--- a/drivers/acpi/riscv/Kconfig
+++ b/drivers/acpi/riscv/Kconfig
@@ -5,3 +5,6 @@
 
 config ACPI_RIMT
 	bool
+
+config ACPI_RQSC
+	bool
diff --git a/drivers/acpi/riscv/Makefile b/drivers/acpi/riscv/Makefile
index 1284a076fa88..b4bcfa4826d8 100644
--- a/drivers/acpi/riscv/Makefile
+++ b/drivers/acpi/riscv/Makefile
@@ -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
diff --git a/drivers/acpi/riscv/init.c b/drivers/acpi/riscv/init.c
index 7c00f7995e86..9fdd5f1bcc5f 100644
--- a/drivers/acpi/riscv/init.c
+++ b/drivers/acpi/riscv/init.c
@@ -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();
 }
diff --git a/drivers/acpi/riscv/init.h b/drivers/acpi/riscv/init.h
index 1680aa2aaf23..176459e356b7 100644
--- a/drivers/acpi/riscv/init.h
+++ b/drivers/acpi/riscv/init.h
@@ -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);
diff --git a/drivers/acpi/riscv/rqsc.c b/drivers/acpi/riscv/rqsc.c
new file mode 100644
index 000000000000..262fd5755d29
--- /dev/null
+++ b/drivers/acpi/riscv/rqsc.c
@@ -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
+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));
+	/* 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] riscv_cbqri: Bind to RQSC platform devices
  2026-11-17 22:11 [PATCH 0/3] ACPI: RISC-V: Add support for the RQSC table Drew Fustini (Tenstorrent)
  2026-11-17 22:11 ` [PATCH 1/3] ACPI: RISC-V: Add RQSC table definitions Drew Fustini (Tenstorrent)
  2026-11-17 22:11 ` [PATCH 2/3] ACPI: RISC-V: Enumerate CBQRI controllers from the RQSC table Drew Fustini (Tenstorrent)
@ 2026-11-17 22:11 ` Drew Fustini (Tenstorrent)
  2 siblings, 0 replies; 4+ messages in thread
From: Drew Fustini (Tenstorrent) @ 2026-11-17 22:11 UTC (permalink / raw)
  To: Sunil V L
  Cc: Rafael J. Wysocki, Len Brown, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Atish Patra, Anup Patel, Chen Pei,
	yunhui cui, Reinette Chatre, Radim Krčmář,
	Zeng Heng, Conor Dooley, Ben Horgan, James Morse, Tony Luck,
	Adrien Ricciardi, Zhanpeng Zhang, Gong Shuai, Gong Shuai,
	Weiwei Li, Liu Zhiwei, Kornel Dulęba, Samuel Holland,
	guo.wenjia23, liu.qingtao2, Dave Martin, Babu Moger, Fenghua Yu,
	Peter Newman, Shaopeng Tan, Jonathan Cameron, Catalin Marinas,
	linux-acpi, linux-riscv, linux-kernel, 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.

Signed-off-by: Drew Fustini (Tenstorrent) <fustini@kernel.org>
---
 drivers/resctrl/Kconfig          |  11 ++--
 drivers/resctrl/cbqri_capacity.c | 111 ++++++++++++++++++++++++++++-----------
 2 files changed, 87 insertions(+), 35 deletions(-)

diff --git a/drivers/resctrl/Kconfig b/drivers/resctrl/Kconfig
index 844dfd75e2aa..491c867f8c5c 100644
--- a/drivers/resctrl/Kconfig
+++ b/drivers/resctrl/Kconfig
@@ -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
 
diff --git a/drivers/resctrl/cbqri_capacity.c b/drivers/resctrl/cbqri_capacity.c
index 6f3d06c4f74b..7013f1a50ffd 100644
--- a/drivers/resctrl/cbqri_capacity.c
+++ b/drivers/resctrl/cbqri_capacity.c
@@ -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;
@@ -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;
 	}
 
 	dev_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[] = {

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-17 22:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 22:11 [PATCH 0/3] ACPI: RISC-V: Add support for the RQSC table Drew Fustini (Tenstorrent)
2026-11-17 22:11 ` [PATCH 1/3] ACPI: RISC-V: Add RQSC table definitions Drew Fustini (Tenstorrent)
2026-11-17 22:11 ` [PATCH 2/3] ACPI: RISC-V: Enumerate CBQRI controllers from the RQSC table Drew Fustini (Tenstorrent)
2026-11-17 22:11 ` [PATCH 3/3] riscv_cbqri: Bind to RQSC platform devices Drew Fustini (Tenstorrent)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®