Skip to content

Commit

Permalink
RISC-V: Fix ioremap_cache() and ioremap_wc() for systems with Svpbmt
Browse files Browse the repository at this point in the history
Currently, all flavors of ioremap_xyz() function maps to the generic
ioremap() which means any ioremap_xyz() call will always map the
target memory as IO using _PAGE_IOREMAP page attributes. This breaks
ioremap_cache() and ioremap_wc() on systems with Svpbmt because memory
remapped using ioremap_cache() and ioremap_wc() will use _PAGE_IOREMAP
page attributes.

To address above (just like other architectures), we implement RISC-V
specific ioremap_cache() and ioremap_wc() which maps memory using page
attributes as defined by the Svpbmt specification.

Fixes: ff689fd ("riscv: add RISC-V Svpbmt extension support")
Co-developed-by: Mayuresh Chitale <mchitale@ventanamicro.com>
Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
  • Loading branch information
avpatel committed Aug 29, 2022
1 parent 589a9e7 commit b3001d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions arch/riscv/include/asm/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ __io_writes_outs(outs, u64, q, __io_pbr(), __io_paw())
#define outsq(addr, buffer, count) __outsq((void __iomem *)addr, buffer, count)
#endif

#ifdef CONFIG_MMU
#define ioremap_wc(addr, size) \
ioremap_prot((addr), (size), _PAGE_IOREMAP_WC)
#endif

#include <asm-generic/io.h>

#ifdef CONFIG_MMU
#define ioremap_cache(addr, size) \
ioremap_prot((addr), (size), _PAGE_KERNEL)
#endif

#endif /* _ASM_RISCV_IO_H */
2 changes: 2 additions & 0 deletions arch/riscv/include/asm/pgtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ extern struct pt_alloc_ops pt_ops __initdata;
#define PAGE_TABLE __pgprot(_PAGE_TABLE)

#define _PAGE_IOREMAP ((_PAGE_KERNEL & ~_PAGE_MTMASK) | _PAGE_IO)
#define _PAGE_IOREMAP_WC ((_PAGE_KERNEL & ~_PAGE_MTMASK) | \
_PAGE_NOCACHE)
#define PAGE_KERNEL_IO __pgprot(_PAGE_IOREMAP)

extern pgd_t swapper_pg_dir[];
Expand Down

0 comments on commit b3001d3

Please sign in to comment.