Skip to content

RFC riscv: Add DMA_COHERENT support

[email protected] linux-arch linux-riscv linux-sunxi lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest3 patches 52 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3riscv: pgtable.h: Fixup _PAGE_CHG_MASK usagearch/riscv/include/asm/pgtable-64.h arch/riscv/include/asm/pgtable.h+8 -60 replies
2/3riscv: Add DMA_COHERENT for custom PTE attributesarch/riscv/Kconfig arch/riscv/include/asm/pgtable-bits.h arch/riscv/include/asm/pgtable.h+43 -40 replies
3/3riscv: Add SYNC_DMA_FOR_CPU/DEVICE for DMA_COHERENTarch/riscv/Kconfig arch/riscv/include/asm/pgtable.h arch/riscv/include/asm/sbi.h +3 more+97 -01 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH RFC 0/3] riscv: Add DMA_COHERENT support

From: Guo Ren <[email protected]>

The RISC-V ISA doesn't yet specify how to query or modify PMAs, so let vendors define the custom properties of memory regions in PTE.

This patchset helps SOC vendors to support their own custom interconnect coherent solution with PTE attributes.

For example, allwinner D1[1] uses T-HEAD C906 as main processor, C906 has two modes in MMU:
- Compatible mode, the same as the definitions in spec.
- Enhanced mode, add custom DMA_COHERENT attribute bits in PTE which not mentioned in spec.

Allwinner D1 needs the enhanced mode to support the DMA type device with non-coherent interconnect in its SOC. C906 uses BITS(63 - 59) as custom attribute bits in PTE.

Here is the config example for Allwinner D1:
CONFIG_RISCV_DMA_COHERENT=y
CONFIG_RISCV_PAGE_DMA_MASK=0xf800000000000000
CONFIG_RISCV_PAGE_CACHE=0x7000000000000000
CONFIG_RISCV_PAGE_DMA_NONCACHE=0x8000000000000000

Guo Ren (3):
riscv: pgtable.h: Fixup _PAGE_CHG_MASK usage
riscv: Add DMA_COHERENT for custom PTE attributes
riscv: Add SYNC_DMA_FOR_CPU/DEVICE for DMA_COHERENT

 arch/riscv/Kconfig                    | 31 ++++++++++++++++++++++++++
 arch/riscv/include/asm/pgtable-64.h   |  8 ++++---
 arch/riscv/include/asm/pgtable-bits.h | 13 ++++++++++-
 arch/riscv/include/asm/pgtable.h      | 26 +++++++++++++++++-----
 arch/riscv/include/asm/sbi.h          | 16 ++++++++++++++
 arch/riscv/kernel/sbi.c               | 19 ++++++++++++++++
 arch/riscv/mm/Makefile                |  4 ++++
 arch/riscv/mm/dma-mapping.c           | 41 +++++++++++++++++++++++++++++++++++
 8 files changed, 148 insertions(+), 10 deletions(-)
 create mode 100644 arch/riscv/mm/dma-mapping.c
Signature · 1 line
2.7.4