mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Drew Fustini <fustini@kernel.org>
Cc: "Adrien Ricciardi" <aricciardi@baylibre.com>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Atish Patra" <atish.patra@linux.dev>,
	"Babu Moger" <babu.moger@amd.com>,
	"Ben Horgan" <ben.horgan@arm.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Chen Pei" <cp0613@linux.alibaba.com>,
	"Conor Dooley" <conor.dooley@microchip.com>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Dave Martin" <Dave.Martin@arm.com>,
	"Fenghua Yu" <fenghuay@nvidia.com>,
	"Gong Shuai" <gong.shuai@sanechips.com.cn>,
	"Gong Shuai" <gsh517@gmail.com>,
	guo.wenjia23@zte.com.cn, "James Morse" <james.morse@arm.com>,
	"Kornel Dulęba" <mindal@semihalf.com>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	liu.qingtao2@zte.com.cn,
	"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Paul Walmsley" <pjw@kernel.org>,
	"Peter Newman" <peternewman@google.com>,
	"Radim Krčmář" <radim.krcmar@oss.qualcomm.com>,
	"Reinette Chatre" <reinette.chatre@intel.com>,
	"Rob Herring" <robh@kernel.org>,
	"Samuel Holland" <samuel.holland@sifive.com>,
	"Sunil V L" <sunilvl@oss.qualcomm.com>,
	"Tony Luck" <tony.luck@intel.com>,
	"Weiwei Li" <liwei1518@gmail.com>,
	"yunhui cui" <cuiyunhui@bytedance.com>,
	"Zhanpeng Zhang" <zhangzhanpeng.jasper@bytedance.com>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Shaopeng Tan" <tan.shaopeng@jp.fujitsu.com>,
	"Zeng Heng" <zengheng@picoheart.com>,
	linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
	x86@kernel.org, devicetree@vger.kernel.org,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH v12 5/5] riscv_cbqri: Add CBQRI capacity allocation platform driver
Date: Thu, 19 Nov 2026 00:00:00 +0000	[thread overview]
Message-ID: <20261119000000.1b43ba35@jic23-hlaptop> (raw)
In-Reply-To: <20261114-dfustini-atl-sc-cbqri-dt-v12-5-6ef1f627072d@kernel.org>

On Sat, 14 Nov 2026 14:06:25 -0800
Drew Fustini <fustini@kernel.org> wrote:

> Add a platform driver for CBQRI capacity controllers described in
> device tree with the riscv,cbqri-capacity-controller compatible.
> 
> The controller node points at the cache it governs with a
> riscv,cbqri-cache phandle. The driver maps the register block, looks
> that cache up in cacheinfo and uses its cache id as the resctrl domain
> id, so the binding does not need to carry a CPU mask. The controller is
> then handed to the CBQRI core, which probes its capabilities and decides
> whether to expose it through resctrl. Only an L2 or L3 cache is
> accepted, since those are the cache levels resctrl has resources for.
> 
> Nothing is vendor-specific and reg is the CBQRI register block itself,
> so any SoC that describes a CBQRI capacity controller in device tree can
> use the driver unchanged.
> 
> Tested-by: Chen Pei <cp0613@linux.alibaba.com>
> Tested-by: Zeng Heng <zengheng@picoheart.com>
> Reviewed-by: Zeng Heng <zengheng@picoheart.com>
> Signed-off-by: Drew Fustini <fustini@kernel.org>

Sorry, late to the game and pretty much a drive by review.

Still a few things below that will leave you with more readable
and probably less fragile code.

Jonathan

> diff --git a/drivers/resctrl/cbqri_capacity.c b/drivers/resctrl/cbqri_capacity.c
> new file mode 100644
> index 000000000000..6f3d06c4f74b
> --- /dev/null
> +++ b/drivers/resctrl/cbqri_capacity.c

> +static int cbqri_capacity_probe(struct platform_device *pdev)
> +{

Noted in the ACPI patch that you can save some effort there
by a few tweaks that probably make sense here anyway.

> +	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");
It's a probe, use
		return dev_err_probe(dev, ret, "missing riscv,cbqri-rcid\n);
same for all these paths.  Sure we won't defer but it does nice formatting
and tends to save a couple of lines every time!

With the __free() magic, you can do this for all the returns in this
function.

> +		return ret;
> +	}
> +
> +	cache_np = of_parse_phandle(dev->of_node, "riscv,cbqri-cache", 0);
Follow on from glancing at the acpi and then finding this elsewhere in my
inbox.
	struct device_node *cache_np __free(device_node) =
		of_parse_phandle(dev->of_node, "riscv,cbqri-cache", 0);
and drop all the goto iritiations.

> +	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);
> +	if (ret) {
> +		dev_err(dev, "%pOF: missing cache-level\n", cache_np);
> +		goto out_put;
> +	}
> +
> +	if (cache_level != 2 && cache_level != 3) {
> +		dev_err(dev, "%pOF: unsupported cache-level %u\n",
> +			cache_np, cache_level);
> +		ret = -EINVAL;
> +		goto out_put;
> +	}
> +
> +	/*
> +	 * Associate the controller with its cache instance via cacheinfo.
> +	 * The matching cache provides the cache id used as the resctrl
> +	 * domain id.
> +	 *
> +	 * Taking the first leaf at the level is sufficient because a
> +	 * unified cache node yields one cacheinfo leaf and
> +	 * cache_setup_of_node() walks one cache node per leaf past L1, so
> +	 * the first leaf at the level has that level's node as fw_token.
> +	 *
> +	 * get_cpu_cacheinfo_level() returns the leaf only when cacheinfo
> +	 * assigned it an id (CACHE_ID), which the resctrl domain id needs.
> +	 */
> +	cpus_read_lock();
> +	for_each_online_cpu(cpu) {
> +		struct cacheinfo *ci = get_cpu_cacheinfo_level(cpu, cache_level);
> +
> +		if (ci && ci->fw_token == cache_np) {
> +			cache_id = ci->id;
> +			found = true;
> +			break;
> +		}
> +	}
> +	cpus_read_unlock();
> +
> +	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);
> +		ret = -ENODEV;
> +		goto out_put;
> +	}
> +
> +	info.type = CBQRI_CONTROLLER_TYPE_CAPACITY;
> +	info.base = base;
> +	info.addr = res->start;
> +	info.size = resource_size(res);
> +	info.rcid_count = rcid_count;
> +	info.cache_id = cache_id;
> +	info.cache_level = cache_level;
	info = (struct cbqri_controller_info) {
		.type = CBQRI_CONTROLLER_TYPE_CAPACITY,
		.base = base,
		.addr = res->start,
		.size = resource_size,
	...

Might as well as you nicely set everything here.
It's more readable and also makes it clear anything not set
is zeroed without anyone having to go check the = { }; above.


	};
> +
> +	ret = riscv_cbqri_register_cc(&info);
> +	if (ret) {
> +		dev_err(dev, "failed to register capacity controller: %d\n", ret);
> +		goto out_put;
> +	}
> +
> +	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;
> +}



      reply	other threads:[~2026-11-19  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 22:06 [PATCH v12 0/5] riscv: Add initial CBQRI resctrl support Drew Fustini
2026-11-14 22:06 ` [PATCH v12 1/5] riscv_cbqri: Add capacity controller core Drew Fustini
2026-11-19  0:08   ` Jonathan Cameron
2026-11-14 22:06 ` [PATCH v12 2/5] riscv_cbqri: resctrl: Add cache allocation via capacity block mask Drew Fustini
2026-11-14 22:06 ` [PATCH v12 3/5] riscv_cbqri: Make RESCTRL_FS available on RISC-V Drew Fustini
2026-11-14 22:06 ` [PATCH v12 4/5] dt-bindings: riscv: Add binding for CBQRI controllers Drew Fustini
2026-11-14 22:06 ` [PATCH v12 5/5] riscv_cbqri: Add CBQRI capacity allocation platform driver Drew Fustini
2026-11-19  0:00   ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119000000.1b43ba35@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=Dave.Martin@arm.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=aricciardi@baylibre.com \
    --cc=atish.patra@linux.dev \
    --cc=babu.moger@amd.com \
    --cc=ben.horgan@arm.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=conor.dooley@microchip.com \
    --cc=cp0613@linux.alibaba.com \
    --cc=cuiyunhui@bytedance.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=fenghuay@nvidia.com \
    --cc=fustini@kernel.org \
    --cc=gong.shuai@sanechips.com.cn \
    --cc=gsh517@gmail.com \
    --cc=guo.wenjia23@zte.com.cn \
    --cc=james.morse@arm.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=liu.qingtao2@zte.com.cn \
    --cc=liwei1518@gmail.com \
    --cc=mindal@semihalf.com \
    --cc=palmer@dabbelt.com \
    --cc=peternewman@google.com \
    --cc=pjw@kernel.org \
    --cc=radim.krcmar@oss.qualcomm.com \
    --cc=reinette.chatre@intel.com \
    --cc=robh@kernel.org \
    --cc=samuel.holland@sifive.com \
    --cc=sunilvl@oss.qualcomm.com \
    --cc=tan.shaopeng@jp.fujitsu.com \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    --cc=zengheng@picoheart.com \
    --cc=zhangzhanpeng.jasper@bytedance.com \
    --cc=zhiwei_liu@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®