Skip to content

Commit

Permalink
RISC-V: Move riscv_init_cbom_blocksize() to cacheflush.c
Browse files Browse the repository at this point in the history
The riscv_cbom_block_size parsing from DT belongs to cacheflush.c which
is home for all cache maintenance related stuff so let us move the
riscv_init_cbom_blocksize() and riscv_cbom_block_size to cacheflush.c.

Co-developed-by: Mayuresh Chitale <mchitale@ventanamicro.com>
Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
[Rebased on Palmer Dabbelt's cleanup.]
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
  • Loading branch information
avpatel authored and jones-drew committed Sep 5, 2022
1 parent af36128 commit 61c4042
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
2 changes: 2 additions & 0 deletions arch/riscv/include/asm/cacheflush.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void flush_icache_mm(struct mm_struct *mm, bool local);

#endif /* CONFIG_SMP */

extern unsigned int riscv_cbom_block_size;

#ifdef CONFIG_RISCV_ISA_ZICBOM
void riscv_init_cbom_blocksize(void);
#else
Expand Down
40 changes: 40 additions & 0 deletions arch/riscv/mm/cacheflush.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright (C) 2017 SiFive
*/

#include <linux/of.h>
#include <linux/of_device.h>
#include <asm/cacheflush.h>

#ifdef CONFIG_SMP
Expand Down Expand Up @@ -86,3 +88,41 @@ void flush_icache_pte(pte_t pte)
flush_icache_all();
}
#endif /* CONFIG_MMU */

unsigned int riscv_cbom_block_size;

#ifdef CONFIG_RISCV_ISA_ZICBOM
void riscv_init_cbom_blocksize(void)
{
struct device_node *node;
unsigned long cbom_hartid;
u32 val, probed_block_size;
int ret;

probed_block_size = 0;
for_each_of_cpu_node(node) {
unsigned long hartid;

ret = riscv_of_processor_hartid(node, &hartid);
if (ret)
continue;

/* set block-size for cbom extension if available */
ret = of_property_read_u32(node, "riscv,cbom-block-size", &val);
if (ret)
continue;

if (!probed_block_size) {
probed_block_size = val;
cbom_hartid = hartid;
} else {
if (probed_block_size != val)
pr_warn("cbom-block-size mismatched between harts %lu and %lu\n",
cbom_hartid, hartid);
}
}

if (probed_block_size)
riscv_cbom_block_size = probed_block_size;
}
#endif
39 changes: 0 additions & 39 deletions arch/riscv/mm/dma-noncoherent.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
#include <linux/dma-direct.h>
#include <linux/dma-map-ops.h>
#include <linux/mm.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <asm/cacheflush.h>

static unsigned int riscv_cbom_block_size;
static bool noncoherent_supported;

void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
Expand Down Expand Up @@ -75,42 +72,6 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
dev->dma_coherent = coherent;
}

#ifdef CONFIG_RISCV_ISA_ZICBOM
void riscv_init_cbom_blocksize(void)
{
struct device_node *node;
unsigned long cbom_hartid;
u32 val, probed_block_size;
int ret;

probed_block_size = 0;
for_each_of_cpu_node(node) {
unsigned long hartid;

ret = riscv_of_processor_hartid(node, &hartid);
if (ret)
continue;

/* set block-size for cbom extension if available */
ret = of_property_read_u32(node, "riscv,cbom-block-size", &val);
if (ret)
continue;

if (!probed_block_size) {
probed_block_size = val;
cbom_hartid = hartid;
} else {
if (probed_block_size != val)
pr_warn("cbom-block-size mismatched between harts %lu and %lu\n",
cbom_hartid, hartid);
}
}

if (probed_block_size)
riscv_cbom_block_size = probed_block_size;
}
#endif

void riscv_noncoherent_supported(void)
{
WARN(!riscv_cbom_block_size,
Expand Down

0 comments on commit 61c4042

Please sign in to comment.