All of lore.kernel.org
 help / color / mirror / Atom feed
From: Conor Dooley <conor@kernel.org>
To: Hui Min Mina Chou <minachou@andestech.com>
Cc: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, geert+renesas@glider.be,
	prabhakar.mahadev-lad.rj@bp.renesas.com, magnus.damm@gmail.com,
	ben717@andestech.com, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, jonathan.cameron@huawei.com,
	devicetree@vger.kernel.org, linux-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	tim609@andestech.com, alex749@andestech.com, az70021@gmail.com
Subject: Re: [PATCH 2/7] cache: andes_llcache: refactor initialization and cache operations
Date: Mon, 30 Mar 2026 17:05:56 +0100	[thread overview]
Message-ID: <20260330-profane-blighted-ac25a752164e@spud> (raw)
In-Reply-To: <20260330102724.1012470-3-minachou@andestech.com>

[-- Attachment #1: Type: text/plain, Size: 4492 bytes --]

On Mon, Mar 30, 2026 at 06:27:19PM +0800, Hui Min Mina Chou wrote:
> This patch cleans up the Andes LLC cache driver:
>  - improved error handling in andes_cache_init() by using goto labels

I don't agree that this is an improvement. There's no meaningful
teardown shared.

>  - updated andes_dma_cache_inv/wback() to check for !size instead of
>    start == end
>  - cache-line-size mismatch from an error to a warning
>  - Use ALIGN and ALIGN_DOWN helpers instead of the alignment logic in
>    andes_dma_cache_inv() and andes_dma_cache_wback().
> 
> Signed-off-by: Hui Min Mina Chou <minachou@andestech.com>
> ---
>  drivers/cache/andes_llcache.c | 56 ++++++++++++++++++-----------------
>  1 file changed, 29 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/cache/andes_llcache.c b/drivers/cache/andes_llcache.c
> index d5e382f3c801..d318b8009f7f 100644
> --- a/drivers/cache/andes_llcache.c
> +++ b/drivers/cache/andes_llcache.c
> @@ -111,21 +111,17 @@ static void andes_dma_cache_inv(phys_addr_t paddr, size_t size)
>  {
>  	unsigned long start = (unsigned long)phys_to_virt(paddr);
>  	unsigned long end = start + size;
> -	unsigned long line_size;
> +	unsigned long line_size = andes_priv.andes_cache_line_size;
>  	unsigned long flags;
>  
> -	if (unlikely(start == end))
> +	if (unlikely(!size))
>  		return;
>  
> -	line_size = andes_priv.andes_cache_line_size;
> -
> -	start = start & (~(line_size - 1));
> -	end = ((end + line_size - 1) & (~(line_size - 1)));
> +	start = ALIGN_DOWN(start, line_size);
> +	end = ALIGN(end, line_size);
>  
>  	local_irq_save(flags);
> -
>  	andes_cpu_dcache_inval_range(start, end);
> -
>  	local_irq_restore(flags);
>  }
>  
> @@ -133,15 +129,15 @@ static void andes_dma_cache_wback(phys_addr_t paddr, size_t size)
>  {
>  	unsigned long start = (unsigned long)phys_to_virt(paddr);
>  	unsigned long end = start + size;
> -	unsigned long line_size;
> +	unsigned long line_size = andes_priv.andes_cache_line_size;
>  	unsigned long flags;
>  
> -	if (unlikely(start == end))
> +	if (unlikely(!size))
>  		return;
>  
> -	line_size = andes_priv.andes_cache_line_size;
> -	start = start & (~(line_size - 1));
> -	end = ((end + line_size - 1) & (~(line_size - 1)));
> +	start = ALIGN_DOWN(start, line_size);
> +	end = ALIGN(end, line_size);
> +
>  	local_irq_save(flags);
>  	andes_cpu_dcache_wb_range(start, end);
>  	local_irq_restore(flags);
> @@ -159,14 +155,13 @@ static int andes_get_llc_line_size(struct device_node *np)
>  
>  	ret = of_property_read_u32(np, "cache-line-size", &andes_priv.andes_cache_line_size);
>  	if (ret) {
> -		pr_err("Failed to get cache-line-size, defaulting to 64 bytes\n");
> +		pr_err("Cache: Failed to get cache-line-size\n");
>  		return ret;
>  	}
>  
>  	if (andes_priv.andes_cache_line_size != ANDES_CACHE_LINE_SIZE) {
> -		pr_err("Expected cache-line-size to be 64 bytes (found:%u)\n",
> -		       andes_priv.andes_cache_line_size);
> -		return -EINVAL;
> +		pr_warn("Cache: Expected cache-line-size to be 64 bytes (found:%u)\n",
> +			andes_priv.andes_cache_line_size);
>  	}
>  
>  	return 0;
> @@ -186,16 +181,18 @@ static const struct of_device_id andes_cache_ids[] = {
>  static int __init andes_cache_init(void)
>  {
>  	struct resource res;
> -	int ret;
> +	int ret = 0;
>  
>  	struct device_node *np __free(device_node) =
>  		of_find_matching_node(NULL, andes_cache_ids);
> -	if (!of_device_is_available(np))
> -		return -ENODEV;
> +	if (!of_device_is_available(np)) {
> +		ret = -ENODEV;
> +		goto err_ret;
> +	}
>  
>  	ret = of_address_to_resource(np, 0, &res);
>  	if (ret)
> -		return ret;
> +		goto err_ret;
>  
>  	/*
>  	 * If IOCP is present on the Andes AX45MP core riscv_cbom_block_size
> @@ -208,17 +205,22 @@ static int __init andes_cache_init(void)
>  		return 0;
>  
>  	andes_priv.llc_base = ioremap(res.start, resource_size(&res));
> -	if (!andes_priv.llc_base)
> -		return -ENOMEM;
> +	if (!andes_priv.llc_base) {
> +		ret = -ENOMEM;
> +		goto err_ret;
> +	}
>  
>  	ret = andes_get_llc_line_size(np);
> -	if (ret) {
> -		iounmap(andes_priv.llc_base);
> -		return ret;
> -	}
> +	if (ret)
> +		goto err_unmap;
>  
>  	riscv_noncoherent_register_cache_ops(&andes_cmo_ops);
>  
>  	return 0;
> +
> +err_unmap:
> +	iounmap(andes_priv.llc_base);
> +err_ret:
> +	return ret;
>  }
>  early_initcall(andes_cache_init);
> -- 
> 2.34.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Conor Dooley <conor@kernel.org>
To: Hui Min Mina Chou <minachou@andestech.com>
Cc: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, geert+renesas@glider.be,
	prabhakar.mahadev-lad.rj@bp.renesas.com, magnus.damm@gmail.com,
	ben717@andestech.com, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, jonathan.cameron@huawei.com,
	devicetree@vger.kernel.org, linux-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	tim609@andestech.com, alex749@andestech.com, az70021@gmail.com
Subject: Re: [PATCH 2/7] cache: andes_llcache: refactor initialization and cache operations
Date: Mon, 30 Mar 2026 17:05:56 +0100	[thread overview]
Message-ID: <20260330-profane-blighted-ac25a752164e@spud> (raw)
In-Reply-To: <20260330102724.1012470-3-minachou@andestech.com>


[-- Attachment #1.1: Type: text/plain, Size: 4492 bytes --]

On Mon, Mar 30, 2026 at 06:27:19PM +0800, Hui Min Mina Chou wrote:
> This patch cleans up the Andes LLC cache driver:
>  - improved error handling in andes_cache_init() by using goto labels

I don't agree that this is an improvement. There's no meaningful
teardown shared.

>  - updated andes_dma_cache_inv/wback() to check for !size instead of
>    start == end
>  - cache-line-size mismatch from an error to a warning
>  - Use ALIGN and ALIGN_DOWN helpers instead of the alignment logic in
>    andes_dma_cache_inv() and andes_dma_cache_wback().
> 
> Signed-off-by: Hui Min Mina Chou <minachou@andestech.com>
> ---
>  drivers/cache/andes_llcache.c | 56 ++++++++++++++++++-----------------
>  1 file changed, 29 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/cache/andes_llcache.c b/drivers/cache/andes_llcache.c
> index d5e382f3c801..d318b8009f7f 100644
> --- a/drivers/cache/andes_llcache.c
> +++ b/drivers/cache/andes_llcache.c
> @@ -111,21 +111,17 @@ static void andes_dma_cache_inv(phys_addr_t paddr, size_t size)
>  {
>  	unsigned long start = (unsigned long)phys_to_virt(paddr);
>  	unsigned long end = start + size;
> -	unsigned long line_size;
> +	unsigned long line_size = andes_priv.andes_cache_line_size;
>  	unsigned long flags;
>  
> -	if (unlikely(start == end))
> +	if (unlikely(!size))
>  		return;
>  
> -	line_size = andes_priv.andes_cache_line_size;
> -
> -	start = start & (~(line_size - 1));
> -	end = ((end + line_size - 1) & (~(line_size - 1)));
> +	start = ALIGN_DOWN(start, line_size);
> +	end = ALIGN(end, line_size);
>  
>  	local_irq_save(flags);
> -
>  	andes_cpu_dcache_inval_range(start, end);
> -
>  	local_irq_restore(flags);
>  }
>  
> @@ -133,15 +129,15 @@ static void andes_dma_cache_wback(phys_addr_t paddr, size_t size)
>  {
>  	unsigned long start = (unsigned long)phys_to_virt(paddr);
>  	unsigned long end = start + size;
> -	unsigned long line_size;
> +	unsigned long line_size = andes_priv.andes_cache_line_size;
>  	unsigned long flags;
>  
> -	if (unlikely(start == end))
> +	if (unlikely(!size))
>  		return;
>  
> -	line_size = andes_priv.andes_cache_line_size;
> -	start = start & (~(line_size - 1));
> -	end = ((end + line_size - 1) & (~(line_size - 1)));
> +	start = ALIGN_DOWN(start, line_size);
> +	end = ALIGN(end, line_size);
> +
>  	local_irq_save(flags);
>  	andes_cpu_dcache_wb_range(start, end);
>  	local_irq_restore(flags);
> @@ -159,14 +155,13 @@ static int andes_get_llc_line_size(struct device_node *np)
>  
>  	ret = of_property_read_u32(np, "cache-line-size", &andes_priv.andes_cache_line_size);
>  	if (ret) {
> -		pr_err("Failed to get cache-line-size, defaulting to 64 bytes\n");
> +		pr_err("Cache: Failed to get cache-line-size\n");
>  		return ret;
>  	}
>  
>  	if (andes_priv.andes_cache_line_size != ANDES_CACHE_LINE_SIZE) {
> -		pr_err("Expected cache-line-size to be 64 bytes (found:%u)\n",
> -		       andes_priv.andes_cache_line_size);
> -		return -EINVAL;
> +		pr_warn("Cache: Expected cache-line-size to be 64 bytes (found:%u)\n",
> +			andes_priv.andes_cache_line_size);
>  	}
>  
>  	return 0;
> @@ -186,16 +181,18 @@ static const struct of_device_id andes_cache_ids[] = {
>  static int __init andes_cache_init(void)
>  {
>  	struct resource res;
> -	int ret;
> +	int ret = 0;
>  
>  	struct device_node *np __free(device_node) =
>  		of_find_matching_node(NULL, andes_cache_ids);
> -	if (!of_device_is_available(np))
> -		return -ENODEV;
> +	if (!of_device_is_available(np)) {
> +		ret = -ENODEV;
> +		goto err_ret;
> +	}
>  
>  	ret = of_address_to_resource(np, 0, &res);
>  	if (ret)
> -		return ret;
> +		goto err_ret;
>  
>  	/*
>  	 * If IOCP is present on the Andes AX45MP core riscv_cbom_block_size
> @@ -208,17 +205,22 @@ static int __init andes_cache_init(void)
>  		return 0;
>  
>  	andes_priv.llc_base = ioremap(res.start, resource_size(&res));
> -	if (!andes_priv.llc_base)
> -		return -ENOMEM;
> +	if (!andes_priv.llc_base) {
> +		ret = -ENOMEM;
> +		goto err_ret;
> +	}
>  
>  	ret = andes_get_llc_line_size(np);
> -	if (ret) {
> -		iounmap(andes_priv.llc_base);
> -		return ret;
> -	}
> +	if (ret)
> +		goto err_unmap;
>  
>  	riscv_noncoherent_register_cache_ops(&andes_cmo_ops);
>  
>  	return 0;
> +
> +err_unmap:
> +	iounmap(andes_priv.llc_base);
> +err_ret:
> +	return ret;
>  }
>  early_initcall(andes_cache_init);
> -- 
> 2.34.1
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  parent reply	other threads:[~2026-03-30 16:06 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-30 10:27 [PATCH 0/7] refactor Andes cache driver for generic platform support Hui Min Mina Chou
2026-03-30 10:27 ` Hui Min Mina Chou
2026-03-30 10:27 ` [PATCH 1/7] cache: ax45mp_cache: refactor cache driver for generic Andes " Hui Min Mina Chou
2026-03-30 10:27   ` Hui Min Mina Chou
2026-03-30 13:01   ` Krzysztof Kozlowski
2026-03-30 13:01     ` Krzysztof Kozlowski
2026-03-30 15:54   ` Conor Dooley
2026-03-30 15:54     ` Conor Dooley
2026-04-01  2:30     ` Mina Chou
2026-04-01  2:30       ` Mina Chou
2026-04-01  9:25       ` Conor Dooley
2026-04-01  9:25         ` Conor Dooley
2026-03-30 10:27 ` [PATCH 2/7] cache: andes_llcache: refactor initialization and cache operations Hui Min Mina Chou
2026-03-30 10:27   ` Hui Min Mina Chou
2026-03-30 13:02   ` Krzysztof Kozlowski
2026-03-30 13:02     ` Krzysztof Kozlowski
2026-03-30 15:23     ` Conor Dooley
2026-03-30 15:23       ` Conor Dooley
2026-03-30 16:05   ` Conor Dooley [this message]
2026-03-30 16:05     ` Conor Dooley
2026-03-31  8:31   ` Krzysztof Kozlowski
2026-03-31  8:31     ` Krzysztof Kozlowski
2026-03-30 10:27 ` [PATCH 3/7] cache: andes_llcache: improve performance of LLC operation Hui Min Mina Chou
2026-03-30 10:27   ` Hui Min Mina Chou
2026-03-30 16:04   ` Conor Dooley
2026-03-30 16:04     ` Conor Dooley
2026-03-30 10:27 ` [PATCH 4/7] cache: andes_llcache: centralize cache ops and use native WBINVAL Hui Min Mina Chou
2026-03-30 10:27   ` Hui Min Mina Chou
2026-03-30 10:27 ` [PATCH 5/7] dt-bindings: cache: ax45mp-cache: rename ax45mp-cache to llcache Hui Min Mina Chou
2026-03-30 10:27   ` Hui Min Mina Chou
2026-03-30 12:51   ` Rob Herring (Arm)
2026-03-30 12:51     ` Rob Herring (Arm)
2026-03-30 13:00   ` Krzysztof Kozlowski
2026-03-30 13:00     ` Krzysztof Kozlowski
2026-03-30 15:29     ` Conor Dooley
2026-03-30 15:29       ` Conor Dooley
2026-03-30 15:28   ` Conor Dooley
2026-03-30 15:28     ` Conor Dooley
2026-03-30 10:27 ` [PATCH 6/7] dts: riscv: update cache compatible strings to LLC Hui Min Mina Chou
2026-03-30 10:27   ` Hui Min Mina Chou
2026-03-30 13:03   ` Krzysztof Kozlowski
2026-03-30 13:03     ` Krzysztof Kozlowski
2026-03-30 10:27 ` [PATCH 7/7] MAINTAINERS: Add maintainers for Andes cache driver Hui Min Mina Chou
2026-03-30 10:27   ` Hui Min Mina Chou

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=20260330-profane-blighted-ac25a752164e@spud \
    --to=conor@kernel.org \
    --cc=alex749@andestech.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=az70021@gmail.com \
    --cc=ben717@andestech.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=jonathan.cameron@huawei.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=magnus.damm@gmail.com \
    --cc=minachou@andestech.com \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=robh@kernel.org \
    --cc=tim609@andestech.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.