riscv: Add RISC-V svpbmt extension supports
Subsystems (2)
cover riscv: Add RISC-V svpbmt extension supports
From: Fu Wei <[email protected]>
This patch follows the standard pure RISC-V Svpbmt extension in privilege spec to solve the non-coherent SOC DMA synchronization issues.
Wei Fu (2):
dt-bindings: riscv: Add mmu-supports with svpbmt
riscv: Add RISC-V svpbmt supports
.../devicetree/bindings/riscv/cpus.yaml | 5 +++ arch/riscv/include/asm/fixmap.h | 2 +- arch/riscv/include/asm/pgtable-64.h | 8 ++-- arch/riscv/include/asm/pgtable-bits.h | 41 ++++++++++++++++++- arch/riscv/include/asm/pgtable.h | 39 ++++++++++++++---- arch/riscv/kernel/cpufeature.c | 32 +++++++++++++++ arch/riscv/mm/init.c | 5 +++ 7 files changed, 117 insertions(+), 15 deletions(-)
Signature · 1 line
2.25.4
PATCH 1/2 dt-bindings: riscv: Add mmu-supports with svpbmt
From: Wei Fu <[email protected]>
Previous patch has added svpbmt in arch/riscv and changed the DT mmu-type. Update dt-bindings related property here.
--- Documentation/devicetree/bindings/riscv/cpus.yaml | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/riscv/cpus.yaml +5 -0
@@ -59,6 +59,11 @@ properties: - riscv,sv48 - riscv,none + mmu-supports-svpbmt: + description: + Describes the CPU's mmu-supports-svpbmt support + $ref: '/schemas/types.yaml#/definitions/phandle' + riscv,isa: description: Identifies the specific RISC-V instruction set architecture
Signature · 1 line
2.25.4
PATCH 2/2 riscv: Add RISC-V svpbmt extension supports
In reply to [email protected]From: Wei Fu <[email protected]>
This patch follows the standard pure RISC-V Svpbmt extension in privilege spec to solve the non-coherent SOC dma synchronization issues.
Here is the svpbmt PTE format:
| 63 | 62-61 | 60-8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
N MT RSW D A G U X W R V
^Of the Reserved bits [63:54] in a leaf PTE, the high bit is already allocated (as the N bit), so bits [62:61] are used as the MT (aka MemType) field. This field specifies one of three memory types that are close equivalents (or equivalent in effect) to the three main x86 and ARMv8 memory types - as shown in the following table.
RISC-V
Encoding &
MemType RISC-V Description ---------- ------------------------------------------------ 00 - PMA Normal Cacheable, No change to implied PMA memory type 01 - NC Non-cacheable, idempotent, weakly-ordered Main Memory 10 - IO Non-cacheable, non-idempotent, strongly-ordered I/O memory 11 - Rsvd Reserved for future standard use
The standard protection_map[] needn't be modified because the "PMA" type keeps the highest bits zero. And the whole modification is limited in the arch/riscv/* and using a global variable (__riscv_svpbmt) as _PAGE_DMA_MASK/IO/NC for pgprot_noncached (&writecombine) in pgtable.h. We also add _PAGE_CHG_MASK to filter PFN than before.
Enable it in devicetree - (Add "mmu-supports-svpbmt" in cpu node)
- mmu-supports-svpbmt
---
Changes since V3:
- Change primary author to "Wei Fu <[email protected]>"
- Add mmu-supports-svpbmt in cpu node
Changes since V2:
- Seperate DT modification into another patch
- Move riscv_svpbmt() into riscv_fill_hwcap()
- Fixup print_mmu()
- Make __riscv_svpbmt updated only when all CPU nodes have "svpmbt" in the "mmu-type" DT property
- Define _PAGE_MT_MASK as (_PAGE_MT_PMA | _PAGE_MT_NC | _PAGE_MT_IO)
- Change u64 to unsigned long in _PAGE_MT_XXX
- Change __riscv_svpbmt.mt[] to __riscv_svpbmt.mt_xxx
- Optimize some misleading names
--- arch/riscv/include/asm/fixmap.h | 2 +- arch/riscv/include/asm/pgtable-64.h | 8 ++++-- arch/riscv/include/asm/pgtable-bits.h | 41 +++++++++++++++++++++++++-- arch/riscv/include/asm/pgtable.h | 39 +++++++++++++++++++------ arch/riscv/kernel/cpufeature.c | 32 +++++++++++++++++++++ arch/riscv/mm/init.c | 5 ++++ 6 files changed, 112 insertions(+), 15 deletions(-)
arch/riscv/include/asm/fixmap.h +1 -1
@@ -43,7 +43,7 @@ enum fixed_addresses { __end_of_fixed_addresses }; -#define FIXMAP_PAGE_IO PAGE_KERNEL +#define FIXMAP_PAGE_IO PAGE_IOREMAP#define __early_set_fixmap __set_fixmap
arch/riscv/include/asm/pgtable-64.h +5 -3
@@ -61,12 +61,14 @@ static inline void pud_clear(pud_t *pudp)static inline pmd_t *pud_pgtable (pud_t pud) { -return (pmd_t *)pfn_to_virt (pud_val (pud) >> _PAGE_PFN_SHIFT); +return (pmd_t *)pfn_to_virt ((pud_val (pud) & _PAGE_CHG_MASK) + >> _PAGE_PFN_SHIFT); }static inline struct page *pud_page (pud_t pud) { -return pfn_to_page (pud_val (pud) >> _PAGE_PFN_SHIFT); +return pfn_to_page ((pud_val (pud) & _PAGE_CHG_MASK) + >> _PAGE_PFN_SHIFT); }static inline pmd_t pfn_pmd (unsigned long pfn,pgprot_t prot)
@@ -76,7 +78,7 @@ static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot)static inline unsigned long _pmd_pfn (pmd_t pmd) { -return pmd_val (pmd) >> _PAGE_PFN_SHIFT; +return (pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT; }#define mk_pmd (page, prot) pfn_pmd(page_to_pfn(page), prot)
arch/riscv/include/asm/pgtable-bits.h +39 -2
59 lines not on this page · raw message
arch/riscv/include/asm/pgtable.h +30 -9
@@ -136,7 +136,8 @@ | _PAGE_PRESENT \ | _PAGE_ACCESSED \ | _PAGE_DIRTY \ - | _PAGE_GLOBAL) + | _PAGE_GLOBAL \ + | _PAGE_MT_PMA)#define PAGE_KERNEL __pgprot(_PAGE_KERNEL)#define PAGE_KERNEL_READ __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
@@ -146,11 +147,9 @@#define PAGE_TABLE __pgprot(_PAGE_TABLE) -/* -* The RISC-V ISA doesn't yet specify how to query or modify PMAs, so we can't -* change the properties of memory regions. -*/ -#define _PAGE_IOREMAP _PAGE_KERNEL +#define _PAGE_IOREMAP ((_PAGE_KERNEL & ~_PAGE_MT_MASK) | _PAGE_MT_IO) + +#define PAGE_IOREMAP __pgprot(_PAGE_IOREMAP)extern pgd_t swapper_pg_dir[];
@@ -230,12 +229,12 @@ static inline unsigned long _pgd_pfn(pgd_t pgd)static inline struct page *pmd_page (pmd_t pmd) { -return pfn_to_page (pmd_val (pmd) >> _PAGE_PFN_SHIFT); +return pfn_to_page ((pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT); }static inline unsigned long pmd_page_vaddr (pmd_t pmd) { -return (unsigned long )pfn_to_virt (pmd_val (pmd) >> _PAGE_PFN_SHIFT); +return (unsigned long )pfn_to_virt ((pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT); }static inline pte_t pmd_pte (pmd_t pmd)
@@ -251,7 +250,7 @@ static inline pte_t pud_pte(pud_t pud)/* Yields the page frame number (PFN) of a page table entry */ static inline unsigned long pte_pfn (pte_t pte) { -return (pte_val (pte) >> _PAGE_PFN_SHIFT); +return ((pte_val (pte) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT); }#define pte_page (x) pfn_to_page(pte_pfn(x))
@@ -490,6 +489,28 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,return ptep_test_and_clear_young (vma, address, ptep); } +#define pgprot_noncached pgprot_noncached +static inline pgprot_t pgprot_noncached (pgprot_t _prot) +{ +unsigned long prot =pgprot_val (_prot); + + prot &= ~_PAGE_MT_MASK; + prot |= _PAGE_MT_IO; + +return __pgprot (prot); +} + +#define pgprot_writecombine pgprot_writecombine +static inline pgprot_t pgprot_writecombine (pgprot_t _prot) +{ +unsigned long prot =pgprot_val (_prot); + + prot &= ~_PAGE_MT_MASK; + prot |= _PAGE_MT_NC; + +return __pgprot (prot); +} +/* * THP functions */
arch/riscv/kernel/cpufeature.c +32 -0
@@ -8,6 +8,7 @@#include <linux/bitmap.h> #include <linux/of.h> +#include <linux/pgtable.h> #include <asm/processor.h> #include <asm/hwcap.h> #include <asm/smp.h>
@@ -59,6 +60,35 @@ bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, int bit) }EXPORT_SYMBOL_GPL (__riscv_isa_extension_available); +static void __init mmu_supports_svpbmt (void ) +{ +#if defined(CONFIG_MMU ) && defined(CONFIG_64BIT ) +struct device_node *node; +const char *str; + +for_each_of_cpu_node (node) { +if (of_property_read_string (node,"mmu-type" , &str)) +continue ; + +if (!strncmp (str +6 ,"none" ,4 )) +continue ; + +if (!of_property_read_bool (node,"mmu-supports-svpbmt" )) +return ; + } + + __riscv_svpbmt.mask = _SVPBMT_MASK; + __riscv_svpbmt.mt_pma = _SVPBMT_PMA; + __riscv_svpbmt.mt_nc = _SVPBMT_NC; + __riscv_svpbmt.mt_io = _SVPBMT_IO; +#endif +} + +static void __init mmu_supports (void ) +{ +mmu_supports_svpbmt (); +} +void __init riscv_fill_hwcap (void ) {struct device_node *node;
@@ -67,6 +97,8 @@ void __init riscv_fill_hwcap(void)size_t i, j, isa_len;static unsigned long isa2hwcap[256 ] = {0 }; +mmu_supports (); + isa2hwcap['i' ] = isa2hwcap['I' ] =COMPAT_HWCAP_ISA_I ; isa2hwcap['m' ] = isa2hwcap['M' ] =COMPAT_HWCAP_ISA_M ; isa2hwcap['a' ] = isa2hwcap['A' ] =COMPAT_HWCAP_ISA_A ;
arch/riscv/mm/init.c +5 -0
@@ -855,3 +855,8 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, return vmemmap_populate_basepages(start, end, node, NULL); }#endif + +#ifdef CONFIG_64BIT +struct __riscv_svpbmt_struct __riscv_svpbmt__ro_after_init ; +EXPORT_SYMBOL (__riscv_svpbmt); +#endif
Signature · 1 line
2.25.4
Please add V3 in the prefix, I think you need to resend it with PATCH V3 and abandon this one.
Quoted 23 lines · On Wed, Oct 13, 2021 at 2:34 AM <[email protected]> wrote:
From: Fu Wei <[email protected]>
This patch follows the standard pure RISC-V Svpbmt extension in privilege spec to solve the non-coherent SOC DMA synchronization issues.
Wei Fu (2):
dt-bindings: riscv: Add mmu-supports with svpbmt
riscv: Add RISC-V svpbmt supports.../devicetree/bindings/riscv/cpus.yaml | 5 +++ arch/riscv/include/asm/fixmap.h | 2 +- arch/riscv/include/asm/pgtable-64.h | 8 ++-- arch/riscv/include/asm/pgtable-bits.h | 41 ++++++++++++++++++- arch/riscv/include/asm/pgtable.h | 39 ++++++++++++++---- arch/riscv/kernel/cpufeature.c | 32 +++++++++++++++ arch/riscv/mm/init.c | 5 +++ 7 files changed, 117 insertions(+), 15 deletions(-)--
2.25.4
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/