Linux Power Management development
 help / color / mirror / Atom feed
From: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
To: Huacai Chen <chenhuacai@loongson.cn>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Huacai Chen <chenhuacai@kernel.org>
Cc: loongarch@lists.linux.dev, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, Xuerui Wang <kernel@xen0n.name>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>,
	stable@vger.kernel.org, zhongqiu.han@oss.qualcomm.com
Subject: Re: [PATCH 5/5] cpufreq: loongson3: Replace IOCSR read/write with MMIO ones
Date: Thu, 20 Aug 2026 20:57:03 +0800	[thread overview]
Message-ID: <a4b1ff9d-f71b-4cde-b225-70568ca8ba8b@oss.qualcomm.com> (raw)
In-Reply-To: <20260818123921.3600606-6-chenhuacai@loongson.cn>

On 8/18/2026 8:39 PM, Huacai Chen wrote:
> Our server productions (e.g. Loongson-3D6000/3E6000) can have multiple
> nodes in one package and SMC mailboxes are also per-node. However, IOCSR
> read/write can only perform on the current node, while sometimes we want
> to perform on other nodes (e.g. when switch governor, the get and target
> callbacks are not run on target core). So replace IOCSR read/write with
> MMIO ones.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>   drivers/cpufreq/loongson3_cpufreq.c | 31 ++++++++++++++++++++++-------
>   1 file changed, 24 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/cpufreq/loongson3_cpufreq.c b/drivers/cpufreq/loongson3_cpufreq.c
> index c75c0e30e881..e5062cd62390 100644
> --- a/drivers/cpufreq/loongson3_cpufreq.c
> +++ b/drivers/cpufreq/loongson3_cpufreq.c
> @@ -164,6 +164,12 @@ union smc_message {
>   
>   #define FREQ_MAX_LEVEL			16
>   
> +#define MMIO_SMCMBX(node) \
> +	((void __iomem *)(IO_BASE | (u64)(node) << NODE_ADDRSPACE_SHIFT | LOONGSON_REG_BASE | LOONGARCH_IOCSR_SMCMBX))
> +
> +#define MMIO_MISC_FUNC(node) \
> +	((void __iomem *)(IO_BASE | (u64)(node) << NODE_ADDRSPACE_SHIFT | LOONGSON_REG_BASE | LOONGARCH_IOCSR_MISC_FUNC))
> +
>   struct loongson3_freq_data {
>   	unsigned int def_freq_level;
>   	struct cpufreq_frequency_table table[];
> @@ -176,13 +182,25 @@ static DEFINE_PER_CPU(struct loongson3_freq_data *, freq_data);
>   static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 extra)
>   {
>   	int retries;
> -	unsigned int cpu = raw_smp_processor_id();
> -	unsigned int nid = cpu_to_node(cpu);
> +	unsigned int cpu, nid;
>   	union smc_message msg, last;
>   
> +	switch (cmd) {
> +	case CMD_GET_FREQ_INFO:
> +	case CMD_SET_FREQ_INFO:
> +	case CMD_GET_FREQ_LEVEL_NUM:
> +	case CMD_GET_FREQ_LEVEL_INFO:
> +	case CMD_GET_FREQ_BOOST_LEVEL:
> +		cpu = cpu_number_map(id);

cpu_number_map() is undefined when CONFIG_SMP=n. Wouldn't that result in
a build failure?


> +		break;
> +	default:
> +		cpu = raw_smp_processor_id();
> +	}
> +	nid = cpu_to_node(cpu);
> +
>   	mutex_lock(&cpufreq_mutex[nid]);
>   
> -	last.value = iocsr_read32(LOONGARCH_IOCSR_SMCMBX);
> +	last.value = readl(MMIO_SMCMBX(nid));
>   	if (!last.complete) {
>   		mutex_unlock(&cpufreq_mutex[nid]);
>   		return -EPERM;
> @@ -195,12 +213,11 @@ static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 ext
>   	msg.extra	= extra;
>   	msg.complete	= 0;
>   
> -	iocsr_write32(msg.value, LOONGARCH_IOCSR_SMCMBX);
> -	iocsr_write32(iocsr_read32(LOONGARCH_IOCSR_MISC_FUNC) | IOCSR_MISC_FUNC_SOFT_INT,
> -		      LOONGARCH_IOCSR_MISC_FUNC);
> +	writel(msg.value, MMIO_SMCMBX(nid));
> +	writel(readl(MMIO_MISC_FUNC(nid)) | IOCSR_MISC_FUNC_SOFT_INT, MMIO_MISC_FUNC(nid));
>   
>   	for (retries = 0; retries < 10000; retries++) {
> -		msg.value = iocsr_read32(LOONGARCH_IOCSR_SMCMBX);
> +		msg.value = readl(MMIO_SMCMBX(nid));
>   		if (msg.complete)
>   			break;
>   


Please ignore this comments if you do not think it is worth addressing:

A separate issue, it seems that DVFS and Boost feature is set in
loongson3_cpufreq_probe(), what if about on other nodes (non-boot cpu
node) and what if cpu hotplug?

static int loongson3_cpufreq_probe(struct platform_device *pdev)
{
	int i, ret;

	for (i = 0; i < MAX_PACKAGES; i++) {
		ret = devm_mutex_init(&pdev->dev, &cpufreq_mutex[i]);
		if (ret)
			return ret;
	}

	ret = do_service_request(0, 0, CMD_GET_VERSION, 0, 0);
	if (ret <= 0)
		return -EPERM;

	ret = do_service_request(FEATURE_DVFS, 0, CMD_SET_FEATURE,
				 FEATURE_DVFS_ENABLE | FEATURE_DVFS_BOOST, 0);
	if (ret < 0)
		return -EPERM;

......

}


-- 
Thx and BRs,
Zhongqiu Han

  reply	other threads:[~2026-08-20 12:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 12:39 [PATCH 0/5] cpufreq: loongson3: Fix wrong behaviors on multi-node servers Huacai Chen
2026-08-18 12:39 ` [PATCH 1/5] cpufreq: loongson3: Make this drvier depend on MACH_LOONGSON64 Huacai Chen
2026-08-20  9:23   ` Zhongqiu Han
2026-08-18 12:39 ` [PATCH 2/5] cpufreq: loongson3: Adjust the width of id and val in smc_message Huacai Chen
2026-08-20 10:03   ` Zhongqiu Han
2026-08-18 12:39 ` [PATCH 3/5] cpufreq: loongson3: Replace per-package mutex with per-node Huacai Chen
2026-08-20 11:34   ` Zhongqiu Han
2026-08-20 12:35     ` Zhongqiu Han
2026-08-21  4:54       ` Xi Ruoyao
2026-08-18 12:39 ` [PATCH 4/5] cpufreq: loongson3: Use global physical CPU ID in get/target callbacks Huacai Chen
2026-08-20 12:23   ` Zhongqiu Han
2026-08-18 12:39 ` [PATCH 5/5] cpufreq: loongson3: Replace IOCSR read/write with MMIO ones Huacai Chen
2026-08-20 12:57   ` Zhongqiu Han [this message]
2026-08-21  5:01   ` Xi Ruoyao

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=a4b1ff9d-f71b-4cde-b225-70568ca8ba8b@oss.qualcomm.com \
    --to=zhongqiu.han@oss.qualcomm.com \
    --cc=chenhuacai@kernel.org \
    --cc=chenhuacai@loongson.cn \
    --cc=jiaxun.yang@flygoat.com \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=rafael@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=viresh.kumar@linaro.org \
    /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