From nobody Mon Nov 23 04:34:26 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1794611719; cv=none; d=zohomail.com; s=zohoarc; b=cbXY2/dN6adjqzbTduRipJQ75KhaDXIbYhlLxDztFDbrlgcG3PIbr+M7Xjvkly3hHKiiYcN3HK3E9uQV53P3A3HnlqOsoqAt4xwDdT1WoIJkSwtKVdVGDGL+9p0dIVSvJ2uOMqkcwP+hmq2meunp9xw3H8keiOcg1zoWL6/ud5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794611719; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3VJ5VKKHRksAaEHKGJL9GJuFhNx/L3ly7jYl1xcj/1M=; b=Y+X6u7OC688usAtyMum9gliHbiVr0O4QN+BUG1kbfT0gml3U5lztpTVCR67+h5Vwc2UtpP6At7sx4VI+orUn4426PT1nfniRSuOAnBmKKTAbHH6FTjkcVD8qgKZmjperFABheBO6K7PuLLlI7vT58bR8hbPU1gEdYQHlFy7fg34= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794611719175746.102201535483; Fri, 13 Nov 2026 15:15:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xS0TA-0000TG-Bu; Fri, 13 Nov 2026 18:14:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xS0T6-0000P7-8w; Fri, 13 Nov 2026 18:14:04 -0500 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xS0T2-00027x-OA; Fri, 13 Nov 2026 18:14:03 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id D137742DC8; Fri, 13 Nov 2026 23:13:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 732CF1F000C7; Fri, 13 Nov 2026 23:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794611631; bh=3VJ5VKKHRksAaEHKGJL9GJuFhNx/L3ly7jYl1xcj/1M=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=YHInhJiM36dCD4Th9g/MJ8X35hirbqXVXKqU/WSEikePU5ombWT/jufL1FVHrOXKl 4E4QraGvmBeRz7pBeogrXEUNAbKXojgETN2qO3bZxeFK0sen3cnNEKEvyWrysZHboE JPVKLloW/GMu69FKNNJZlLVRf0oS3kqSTzZkUi+D1/z5uEF1IAtNPJ0JlLS2P/AMsi j0h5cq386tiXVfPLEHLmXKuBMyERhFQsvBKhEnMdEEP5t1+AWNL1us8zDwn5is+q1z ME8Srt5sKmrhccOnkjVKIv/yGXBS6tn+wigydkHaYp0VnGGELAzyp/njT8H2Dn/5yD xZhv9uyhqmH8w== From: Drew Fustini Date: Fri, 13 Nov 2026 15:12:39 -0800 Subject: [PATCH v2 1/2] hw/riscv: add cache_level and node properties to CBQRI controllers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-riscv-rqsc-v2-1-34d47fa4141e@kernel.org> References: <20261113-riscv-rqsc-v2-0-34d47fa4141e@kernel.org> In-Reply-To: <20261113-riscv-rqsc-v2-0-34d47fa4141e@kernel.org> To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Sunil V L , Anup Patel , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu , Paolo Bonzini , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , yunhui cui , Chen Pei , guo.wenjia23@zte.com.cn, liu.qingtao2@zte.com.cn, Jinjie Ruan , Jinjie Ruan <2118537295@qq.com>, "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Vasudevan Srinivasan , Drew Fustini X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3686; i=fustini@kernel.org; h=from:subject:message-id; bh=C8GjMMtR0kTO2e1y7gN/VjOKEDesqqxWM7KvRC87P9Q=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWR9n7nuYfuE1DnLduZLeHk88lrnsoPpl8HE4iO6VpMiP wVesQ2d0lHKwiDGxSArpsiy6UPehSVeoV8XzH+xDWYOKxPIEAYuTgGYiMhdRoaF3xh+WP6ZNae/ W2rzkyKp2WvZZB753LD6WnspM71cSD2d4b83C89a3g87ut8sZ91YGGcyM9nzqJhu5WTxDCnb6Bd X0xgB X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=fustini@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1794611720356158500 The ACPI RQSC table specifies which cache a capacity controller backs and which proximity domain a bandwidth controller serves. Add a cache_level property to the capacity controller. It accepts 2 or 3, the unified cache levels that the smp-cache option can place and the PPTT can describe, and defaults to 2. Add a node property to the bandwidth controller. It defaults to 0 and rejects a node the machine does not have. Signed-off-by: Drew Fustini --- hw/riscv/cbqri_bandwidth.c | 13 +++++++++++++ hw/riscv/cbqri_capacity.c | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/hw/riscv/cbqri_bandwidth.c b/hw/riscv/cbqri_bandwidth.c index bd8cf2b50e4c..6c33d1738d27 100644 --- a/hw/riscv/cbqri_bandwidth.c +++ b/hw/riscv/cbqri_bandwidth.c @@ -17,7 +17,9 @@ #include "hw/core/sysbus.h" #include "migration/vmstate.h" #include "target/riscv/cpu.h" +#include "hw/core/boards.h" #include "hw/riscv/cbqri.h" +#include "system/numa.h" =20 /* Property defaults, shared with riscv_cbqri_bc_caps_init() */ #define BC_DEFAULT_MAX_MCIDS 256 @@ -139,6 +141,7 @@ typedef struct RiscvCbqriBandwidthState { =20 uint16_t nbwblks; uint16_t mrbwb; + uint32_t node; =20 bool supports_at_code; =20 @@ -542,12 +545,21 @@ static const MemoryRegionOps riscv_cbqri_bc_ops =3D { static void riscv_cbqri_bc_realize(DeviceState *dev, Error **errp) { RiscvCbqriBandwidthState *bc =3D RISCV_CBQRI_BC(dev); + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int nb_nodes =3D ms->numa_state ? ms->numa_state->num_nodes := 0; =20 if (!bc->mmio_base) { error_setg(errp, "mmio_base property not set"); return; } =20 + /* Without -numa there is a single implicit node 0. */ + if (bc->node >=3D MAX(nb_nodes, 1)) { + error_setg(errp, "node %u out of range, %u NUMA node(s)", + bc->node, MAX(nb_nodes, 1)); + return; + } + if (bc->nb_rcids =3D=3D 0) { error_setg(errp, "max_rcids must be at least 1"); return; @@ -638,6 +650,7 @@ static const Property riscv_cbqri_bc_properties[] =3D { BC_DEFAULT_NBWBLKS), DEFINE_PROP_UINT16("mrbwb", RiscvCbqriBandwidthState, mrbwb, BC_DEFAULT_MRBWB), + DEFINE_PROP_UINT32("node", RiscvCbqriBandwidthState, node, 0), =20 DEFINE_PROP_BOOL("at_code", RiscvCbqriBandwidthState, supports_at_code, true), diff --git a/hw/riscv/cbqri_capacity.c b/hw/riscv/cbqri_capacity.c index 0c572aa8b02f..1585cad1d073 100644 --- a/hw/riscv/cbqri_capacity.c +++ b/hw/riscv/cbqri_capacity.c @@ -127,6 +127,7 @@ typedef struct RiscvCbqriCapacityState { uint16_t nb_rcids; =20 uint16_t ncblks; + uint8_t cache_level; =20 bool supports_at_code; =20 @@ -591,6 +592,11 @@ static void riscv_cbqri_cc_realize(DeviceState *dev, E= rror **errp) return; } =20 + if (cc->cache_level !=3D 2 && cc->cache_level !=3D 3) { + error_setg(errp, "cache_level must be 2 or 3"); + return; + } + if (cc->nb_rcids =3D=3D 0) { error_setg(errp, "max_rcids must be at least 1"); return; @@ -666,6 +672,8 @@ static const Property riscv_cbqri_cc_properties[] =3D { CC_DEFAULT_MAX_RCIDS), DEFINE_PROP_UINT16("ncblks", RiscvCbqriCapacityState, ncblks, CC_DEFAULT_NCBLKS), + DEFINE_PROP_UINT8("cache_level", RiscvCbqriCapacityState, + cache_level, 2), =20 DEFINE_PROP_BOOL("at_code", RiscvCbqriCapacityState, supports_at_code, true), --=20 2.43.0 From nobody Mon Nov 23 04:34:26 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1794611675; cv=none; d=zohomail.com; s=zohoarc; b=n8GljmRRwoJ/QFZL0X+b9ruqYGPUrPg1MPKnDdn4qI4CRBluB1bMQQ0EFhqmATCqoJ96fc9VCQl/ehxkdXPGJ4wKdiExy7aSkcxIChYGR1CLT/Jjol1BDDZM381iwqtiLmyrVFkbuFFpp3jhdkjdJvgC0MFyKWE30F2LKjsyR2A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794611675; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=taX31sIGuvqf5m/KG4d2PcGlzMGN1v3wG7kekRtE/V4=; b=Z6+lpfVrWoRagUkF9poROe5HwrgQCqR7va0H5wDWVPUNcpXGxKVRpYaFAfIZOD+HJbq95HUl93wqeXUQKt59tQApD1a1tmkzfdkIiNzCzESZ0KjDCcrT15RslB4MboyHlByqPjOGnb9i/JqwBdT1Y+r5vR6WMA9rN6NjcNCeyt0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794611675032905.837895420223; Fri, 13 Nov 2026 15:14:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xS0T8-0000Qe-PK; Fri, 13 Nov 2026 18:14:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xS0T5-0000Lq-DB; Fri, 13 Nov 2026 18:14:03 -0500 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xS0T2-00027z-Ni; Fri, 13 Nov 2026 18:14:03 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 44E84623FC; Fri, 13 Nov 2026 23:13:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEE701F000C5; Fri, 13 Nov 2026 23:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794611632; bh=taX31sIGuvqf5m/KG4d2PcGlzMGN1v3wG7kekRtE/V4=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=hYDiuW8AzaeF4HSsIvPxycV4QSR0K+du/CSBprLNgMcKt/9xY+L/ET1yMgt29Qnjw SbRYYjyj/ITavfvhCYi1OcyteCsn8aPU+ew2usMNKBa15UUI8xMgukD9qAzfYLwKww /tCDuy1mwo4Zx6PNLAFWBRi4E3glTrDDE6uXd3aMj3l+XpmwbqP54l8FvEXXmcrBw+ BI4qyByazXfJOsk47I/j5hadFP8p4w3eoBkeGaIdlWKkpd4VYttsxl+9zRwJ/z+QsN cP+247LyF3TaA6xCb46gcdUOjfoLkKUZmlMzV32KaXlqAADv5A+c96eOQQB7CbdwO5 BTtSOEDJmts0A== From: Drew Fustini Date: Fri, 13 Nov 2026 15:12:40 -0800 Subject: [PATCH v2 2/2] hw/riscv: add support for ACPI RQSC table MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261113-riscv-rqsc-v2-2-34d47fa4141e@kernel.org> References: <20261113-riscv-rqsc-v2-0-34d47fa4141e@kernel.org> In-Reply-To: <20261113-riscv-rqsc-v2-0-34d47fa4141e@kernel.org> To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Palmer Dabbelt , Alistair Francis , Sunil V L , Anup Patel , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu , Paolo Bonzini , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , yunhui cui , Chen Pei , guo.wenjia23@zte.com.cn, liu.qingtao2@zte.com.cn, Jinjie Ruan , Jinjie Ruan <2118537295@qq.com>, "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Vasudevan Srinivasan , Drew Fustini X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=16109; i=fustini@kernel.org; h=from:subject:message-id; bh=fFrjZvdW3fBA21bmKhGQnQuRzi1HnGXQODhP+uwwXOM=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWR9n7kuKSph8wM9DhmxWju17Uu8Dzzd3NBwdMLL9Ze/y m4Ir9Ze2FHKwiDGxSArpsiy6UPehSVeoV8XzH+xDWYOKxPIEAYuTgGYyMd4RoYpvjxN0qpi7zwl L2T+vlaZl/As92OGjr4Oh3/ntnflVjeAKtw/fDg57dn5Y+y9XOktFSllb4tyd4bsf77b0M6O4/J GJgA= X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c04:e001:324:0:1991:8:25; envelope-from=fustini@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1794611676217158500 Build the ACPI RISC-V Quality of Service Controllers (RQSC) table for the virt machine when CBQRI controllers are present. A capacity controller is described by the PPTT Cache ID of the cache it backs and a bandwidth controller by the SRAT proximity domain of its NUMA node. Make RISCV_VIRT select RISCV_CBQRI as the table code calls into the CBQRI devices. Link: https://github.com/riscv-non-isa/riscv-rqsc/releases/tag/v1.0.0 Co-developed-by: Vasudevan Srinivasan Signed-off-by: Vasudevan Srinivasan Signed-off-by: Drew Fustini --- hw/riscv/Kconfig | 2 +- hw/riscv/cbqri_bandwidth.c | 13 ++ hw/riscv/cbqri_capacity.c | 13 ++ hw/riscv/virt-acpi-build.c | 298 +++++++++++++++++++++++++++++++++++++++++= +++- include/hw/riscv/cbqri.h | 20 +++ 5 files changed, 344 insertions(+), 2 deletions(-) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index 98bdebb4b814..47dda3e52d20 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -71,7 +71,7 @@ config RISCV_VIRT select PLATFORM_BUS select ACPI select ACPI_PCI - imply RISCV_CBQRI + select RISCV_CBQRI =20 config RISCV_SERVER_PLATFORM_REF bool diff --git a/hw/riscv/cbqri_bandwidth.c b/hw/riscv/cbqri_bandwidth.c index 6c33d1738d27..c55709d662f2 100644 --- a/hw/riscv/cbqri_bandwidth.c +++ b/hw/riscv/cbqri_bandwidth.c @@ -760,4 +760,17 @@ DeviceState *riscv_cbqri_bc_create(hwaddr addr, return dev; } =20 +void riscv_cbqri_bc_get_details(DeviceState *ds, const char *type, + RqscController *rqsc) +{ + if (strcmp(type, TYPE_RISCV_CBQRI_BC) =3D=3D 0) { + RiscvCbqriBandwidthState *bcs =3D RISCV_CBQRI_BC(ds); + rqsc->type =3D RQSC_CONTROLLER_TYPE_BANDWIDTH; + rqsc->mmio_base =3D bcs->mmio_base; + rqsc->rcid_count =3D bcs->nb_rcids; + rqsc->mcid_count =3D bcs->nb_mcids; + rqsc->node =3D bcs->node; + } +} + type_init(riscv_cbqri_bc_register_types) diff --git a/hw/riscv/cbqri_capacity.c b/hw/riscv/cbqri_capacity.c index 1585cad1d073..3ebc8a1cc26d 100644 --- a/hw/riscv/cbqri_capacity.c +++ b/hw/riscv/cbqri_capacity.c @@ -776,4 +776,17 @@ DeviceState *riscv_cbqri_cc_create(hwaddr addr, return dev; } =20 +void riscv_cbqri_cc_get_details(DeviceState *ds, const char *type, + RqscController *rqsc) +{ + if (strcmp(type, TYPE_RISCV_CBQRI_CC) =3D=3D 0) { + RiscvCbqriCapacityState *ccs =3D RISCV_CBQRI_CC(ds); + rqsc->type =3D RQSC_CONTROLLER_TYPE_CAPACITY; + rqsc->mmio_base =3D ccs->mmio_base; + rqsc->rcid_count =3D ccs->nb_rcids; + rqsc->mcid_count =3D ccs->nb_mcids; + rqsc->cache_level =3D ccs->cache_level; + } +} + type_init(riscv_cbqri_cc_register_types) diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c index 8254f1294a72..c8a720eb568c 100644 --- a/hw/riscv/virt-acpi-build.c +++ b/hw/riscv/virt-acpi-build.c @@ -34,6 +34,7 @@ #include "hw/pci-host/gpex.h" #include "hw/riscv/virt.h" #include "hw/riscv/numa.h" +#include "hw/riscv/cbqri.h" #include "hw/virtio/virtio-acpi.h" #include "kvm/kvm_riscv.h" #include "migration/vmstate.h" @@ -279,6 +280,295 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, RI= SCVVirtState *s) /* RHCT Node[N] starts at offset 56 */ #define RHCT_NODE_ARRAY_OFFSET 56 =20 +/* + * RISC-V Quality of Service Controllers (RQSC) table, v1.0 + * https://github.com/riscv-non-isa/riscv-rqsc/releases/tag/v1.0.0 + */ + +/* RQSC Resource Type and Resource ID Type */ +#define RQSC_RESOURCE_TYPE_CACHE 0 +#define RQSC_RESOURCE_TYPE_MEMORY 1 +#define RQSC_RESOURCE_ID_TYPE_PROCESSOR_CACHE 0 +#define RQSC_RESOURCE_ID_TYPE_MEMORY_RANGE 1 + +#define RQSC_MAX_CONTROLLERS 10 + +/* PPTT nodes start after the 36-byte table header */ +#define PPTT_NODE_ARRAY_OFFSET 36 +/* PPTT revision 3 Cache Type Structure */ +#define PPTT_NODE_TYPE_CACHE 1 +#define PPTT_CACHE_NODE_LEN 28 +#define PPTT_CACHE_ID_OFFSET 24 + +static bool virt_has_cbqri(RISCVVirtState *vs) +{ + BusChild *kid; + + if (!vs->platform_bus_dev) { + return false; + } + + QTAILQ_FOREACH(kid, &vs->platform_bus_dev->parent_bus->children, sibli= ng) { + const char *type =3D object_get_typename(OBJECT(kid->child)); + + if (!strcmp(type, TYPE_RISCV_CBQRI_BC) || + !strcmp(type, TYPE_RISCV_CBQRI_CC)) { + return true; + } + } + + return false; +} + +static int rqsc_cmp_mmio_base(const void *a, const void *b) +{ + const RqscController *x =3D a, *y =3D b; + + return x->mmio_base < y->mmio_base ? -1 : x->mmio_base > y->mmio_base; +} + +static unsigned int gather_cbqri_details(RISCVVirtState *vs, + RqscController rqsc[]) +{ + BusChild *kid; + unsigned int count =3D 0; + + if (!vs->platform_bus_dev) { + return 0; + } + + QTAILQ_FOREACH(kid, &vs->platform_bus_dev->parent_bus->children, sibli= ng) { + const char *type =3D object_get_typename(OBJECT(kid->child)); + bool is_bc =3D !strcmp(type, TYPE_RISCV_CBQRI_BC); + bool is_cc =3D !strcmp(type, TYPE_RISCV_CBQRI_CC); + + if (!is_bc && !is_cc) { + continue; + } + + if (count =3D=3D RQSC_MAX_CONTROLLERS) { + error_setg(&error_fatal, "RQSC: more than %d CBQRI controllers= ", + RQSC_MAX_CONTROLLERS); + } + + if (is_bc) { + riscv_cbqri_bc_get_details(kid->child, type, &rqsc[count]); + } else { + riscv_cbqri_cc_get_details(kid->child, type, &rqsc[count]); + } + count++; + } + + /* + * The bus lists its children newest first. Order the controllers by + * address so that the n-th capacity controller of a cache level is + * the one backing the n-th cache of that level. + */ + qsort(rqsc, count, sizeof(*rqsc), rqsc_cmp_mmio_base); + + return count; +} + +/* + * Return the PPTT Cache ID of one unified cache of the given level. The + * topology containers that hold a cache of that level are counted from 0 + * in possible_cpus order, and idx selects the container. build_pptt() + * derives the ID with PPTT_CACHE_ID() from the cache type and level plus + * the first CPU of the container, so walk possible_cpus the way it does. + * Return -1 when there is no such cache and store in num_caches how many + * caches of that level the topology has, 0 when no smp-cache option places + * that level. + */ +static int64_t rqsc_pptt_cache_id(MachineState *ms, unsigned int level, + unsigned int idx, unsigned int *num_cach= es) +{ + const CPUArchIdList *cpus =3D ms->possible_cpus; + int64_t socket_id =3D -1, cluster_id =3D -1, core_id =3D -1; + unsigned int n, found =3D 0; + CpuTopologyLevel topo; + + *num_caches =3D 0; + + switch (level) { + case 2: + topo =3D machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2); + break; + case 3: + topo =3D machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3); + break; + default: + return -1; + } + + for (n =3D 0; n < cpus->len; n++) { + const CpuInstanceProperties *p =3D &cpus->cpus[n].props; + bool first; + + switch (topo) { + case CPU_TOPOLOGY_LEVEL_SOCKET: + first =3D p->socket_id !=3D socket_id; + break; + case CPU_TOPOLOGY_LEVEL_CLUSTER: + first =3D p->socket_id !=3D socket_id || p->cluster_id !=3D cl= uster_id; + break; + case CPU_TOPOLOGY_LEVEL_CORE: + first =3D p->socket_id !=3D socket_id || + p->cluster_id !=3D cluster_id || p->core_id !=3D core_= id; + break; + default: + return -1; + } + + if (!first) { + continue; + } + + socket_id =3D p->socket_id; + cluster_id =3D p->cluster_id; + core_id =3D p->core_id; + + if (found++ =3D=3D idx) { + return PPTT_CACHE_ID(UNIFIED_CACHE, level, n); + } + } + + *num_caches =3D found; + return -1; +} + +/* + * Whether the PPTT at pptt_start holds a Cache Type Structure with the + * given Cache ID. build_pptt() does not emit every cache level for every + * smp-cache layout, for example an L3 cache placed at core level. + */ +static bool rqsc_pptt_has_cache_id(GArray *table_data, unsigned int pptt_s= tart, + uint32_t id) +{ + const uint8_t *pptt =3D (const uint8_t *)table_data->data + pptt_start; + uint32_t len =3D ldl_le_p(pptt + 4); + uint32_t off =3D PPTT_NODE_ARRAY_OFFSET; + + while (off + PPTT_CACHE_NODE_LEN <=3D len) { + uint8_t node_len =3D pptt[off + 1]; + + if (pptt[off] =3D=3D PPTT_NODE_TYPE_CACHE && + node_len >=3D PPTT_CACHE_NODE_LEN && + ldl_le_p(pptt + off + PPTT_CACHE_ID_OFFSET) =3D=3D id) { + return true; + } + if (!node_len) { + break; + } + off +=3D node_len; + } + + return false; +} + +static void build_rqsc(GArray *table_data, BIOSLinker *linker, + RISCVVirtState *s, unsigned int pptt_start) +{ + MachineState *ms =3D MACHINE(s); + RqscController rqsc[RQSC_MAX_CONTROLLERS]; + unsigned int num, i, nr_cc[4] =3D {}; + AcpiTable table =3D { .sig =3D "RQSC", .rev =3D 1, .oem_id =3D s->oem_= id, + .oem_table_id =3D s->oem_table_id }; + + acpi_table_begin(&table, table_data); + + num =3D gather_cbqri_details(s, rqsc); + + /* Number of QoS Controllers */ + build_append_int_noprefix(table_data, num, 4); + + for (i =3D 0; i < num; i++) { + bool is_cc =3D rqsc[i].type =3D=3D RQSC_CONTROLLER_TYPE_CAPACITY; + /* A Memory resource carries 8 bytes of Bandwidth per Block */ + unsigned int res_len =3D is_cc ? 20 : 28; + uint8_t res_type, id_type; + int64_t id; + + if (is_cc) { + unsigned int level =3D rqsc[i].cache_level; + unsigned int num_caches; + + res_type =3D RQSC_RESOURCE_TYPE_CACHE; + id_type =3D RQSC_RESOURCE_ID_TYPE_PROCESSOR_CACHE; + id =3D rqsc_pptt_cache_id(ms, level, nr_cc[level]++, &num_cach= es); + if (id < 0 && !num_caches) { + error_setg(&error_fatal, + "CBQRI capacity controller at 0x%" PRIx64 + " backs an L%u cache, but no smp-cache option" + " places the L%u cache", + rqsc[i].mmio_base, level, level); + } else if (id < 0) { + error_setg(&error_fatal, + "CBQRI capacity controller at 0x%" PRIx64 + " is L%u controller %u, but the smp-cache" + " topology has only %u L%u cache%s", + rqsc[i].mmio_base, level, nr_cc[level] - 1, + num_caches, level, num_caches =3D=3D 1 ? "" : "= s"); + } else if (!rqsc_pptt_has_cache_id(table_data, pptt_start, id)= ) { + error_setg(&error_fatal, + "CBQRI capacity controller at 0x%" PRIx64 + " backs an L%u cache, but the PPTT has no L%u" + " cache with ID 0x%" PRIx64, + rqsc[i].mmio_base, level, level, (uint64_t)id); + } + } else { + res_type =3D RQSC_RESOURCE_TYPE_MEMORY; + id_type =3D RQSC_RESOURCE_ID_TYPE_MEMORY_RANGE; + id =3D rqsc[i].node; + } + + /* Controller Type */ + build_append_int_noprefix(table_data, rqsc[i].type, 1); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 1); + /* Length */ + build_append_int_noprefix(table_data, 24 + res_len, 2); + /* Register Interface Address */ + build_append_gas(table_data, + AML_AS_SYSTEM_MEMORY, + 0, + 0, + 4, + rqsc[i].mmio_base); + /* RCID Count */ + build_append_int_noprefix(table_data, rqsc[i].rcid_count, 2); + /* MCID Count */ + build_append_int_noprefix(table_data, rqsc[i].mcid_count, 2); + /* Controller Flags */ + build_append_int_noprefix(table_data, 0, 2); + /* Number of Resources, one per controller */ + build_append_int_noprefix(table_data, 1, 2); + + /* Resource Structure */ + /* Resource Type */ + build_append_int_noprefix(table_data, res_type, 1); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 1); + /* Length of Resource Structure */ + build_append_int_noprefix(table_data, res_len, 2); + /* Resource Flags */ + build_append_int_noprefix(table_data, 0, 2); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 1); + /* Resource ID Type */ + build_append_int_noprefix(table_data, id_type, 1); + /* Resource ID 1: PPTT Cache ID or SRAT Proximity Domain */ + build_append_int_noprefix(table_data, id, 8); + /* Resource ID 2 */ + build_append_int_noprefix(table_data, 0, 4); + if (!is_cc) { + /* Bandwidth per Block, 0 means not provided */ + build_append_int_noprefix(table_data, 0, 8); + } + } + + acpi_table_end(linker, &table); +} + /* * ACPI spec, Revision 6.6 * 5.2.37 RISC-V Hart Capabilities Table (RHCT) @@ -879,7 +1169,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, RIS= CVVirtState *vms) static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) { GArray *table_offsets; - unsigned dsdt, xsdt; + unsigned dsdt, xsdt, pptt_start; GArray *tables_blob =3D tables->table_data; MachineState *ms =3D MACHINE(s); CPUCoreCaches caches[CPU_MAX_CACHES]; @@ -913,9 +1203,15 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBu= ildTables *tables) } =20 acpi_add_table(table_offsets, tables_blob); + pptt_start =3D tables_blob->len; build_pptt(tables_blob, tables->linker, ms, s->oem_id, s->oem_table_id, num_caches, caches); =20 + if (virt_has_cbqri(s)) { + acpi_add_table(table_offsets, tables_blob); + build_rqsc(tables_blob, tables->linker, s, pptt_start); + } + acpi_add_table(table_offsets, tables_blob); =20 if (ms->acpi_spcr_enabled) { diff --git a/include/hw/riscv/cbqri.h b/include/hw/riscv/cbqri.h index 10b64613599f..bb0b961b3a43 100644 --- a/include/hw/riscv/cbqri.h +++ b/include/hw/riscv/cbqri.h @@ -78,4 +78,24 @@ DeviceState *riscv_cbqri_cc_create(hwaddr addr, const RiscvCbqriCapacityCaps *caps); DeviceState *riscv_cbqri_bc_create(hwaddr addr, const RiscvCbqriBandwidthCaps *caps); + +/* RQSC QoS Controller Type */ +#define RQSC_CONTROLLER_TYPE_CAPACITY 0 +#define RQSC_CONTROLLER_TYPE_BANDWIDTH 1 + +/* What the ACPI RQSC table reports about one CBQRI controller */ +typedef struct RqscController { + uint8_t type; /* RQSC_CONTROLLER_TYPE_* */ + uint64_t mmio_base; + uint16_t rcid_count; + uint16_t mcid_count; + uint8_t cache_level; /* capacity controllers */ + uint32_t node; /* bandwidth controllers */ +} RqscController; + +void riscv_cbqri_bc_get_details(DeviceState *ds, const char *type, + RqscController *rqsc); +void riscv_cbqri_cc_get_details(DeviceState *ds, const char *type, + RqscController *rqsc); + #endif --=20 2.43.0