Skip to contentSkip to conversation

riscv: sbi: Add Andes vendor extension and PMA call wrappers

PATCH New Leo Yu-Chi Liang via qemu development 1 participant 2 messages Mar 19 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 riscv: sbi: Add Andes vendor extension and PMA call wrappers

Add support for the Andes SBI vendor extension (EXT_ID 0x0900031E) with function IDs for PMA (Physical Memory Attribute) operations:
probe, set, and free.

These SBI calls allow S-mode software to configure memory attributes through OpenSBI, which is needed for setting up noncached memory regions on Andes RISC-V platforms.

---
 arch/riscv/include/asm/sbi.h | 22 ++++++++++++++++
 arch/riscv/lib/sbi.c         | 51 ++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
arch/riscv/include/asm/sbi.h +22 -0
index 47124dbaac8..8642954d272 100644
@@ -37,6 +37,7 @@ enum sbi_ext_id {
 	SBI_EXT_FWFT = 0x46574654,
 	SBI_EXT_DBTR = 0x44425452,
 	SBI_EXT_MPXY = 0x4D505859,
+	SBI_EXT_ANDES = 0x0900031E,
 };
 
 enum sbi_ext_base_fid {
@@ -98,6 +99,23 @@ enum sbi_srst_reset_reason {
 	SBI_SRST_RESET_REASON_SYS_FAILURE,
 };
 
+enum sbi_ext_andes_fid {
+	SBI_EXT_ANDES_FID0 = 0,
+	SBI_EXT_ANDES_IOCP_SW_WORKAROUND,
+	SBI_EXT_ANDES_PMA_PROBE,
+	SBI_EXT_ANDES_PMA_SET,
+	SBI_EXT_ANDES_PMA_FREE,
+};
+
+/* Andes PMA configuration flags */
+#define ANDES_PMACFG_ETYP_OFFSET	0
+#define ANDES_PMACFG_ETYP_NAPOT	(3 << ANDES_PMACFG_ETYP_OFFSET)
+#define ANDES_PMACFG_ETYP_OFF		(0 << ANDES_PMACFG_ETYP_OFFSET)
+#define ANDES_PMACFG_ETYP_MASK		(3 << ANDES_PMACFG_ETYP_OFFSET)
+#define ANDES_PMACFG_MTYP_OFFSET		2
+#define ANDES_PMACFG_MTYP_MEM_NON_CACHE_BUF	(3 << ANDES_PMACFG_MTYP_OFFSET)
+#define ANDES_PMACFG_MTYP_DEV_NOBUF		(0 << ANDES_PMACFG_MTYP_OFFSET)
+
 enum sbi_ext_dbcn_fid {
 	SBI_EXT_DBCN_CONSOLE_WRITE = 0,
 	SBI_EXT_DBCN_CONSOLE_READ,
@@ -176,4 +194,8 @@ int sbi_get_mimpid(long *mimpid);
 void sbi_srst_reset(unsigned long type, unsigned long reason);
 int sbi_dbcn_write_byte(unsigned char ch);
 
+int sbi_pma_probe(void);
+int sbi_pma_set(unsigned long pa, unsigned long size, unsigned long flags);
+int sbi_pma_free(unsigned long pa);
+
 #endif
arch/riscv/lib/sbi.c +51 -0

57 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/6 riscv: Extend noncached memory support to RISC-V

Extend the SYS_HAS_NONCACHED_MEMORY Kconfig to support RISC-V in addition to ARM and MIPS, and add FTMAC100 to the list of drivers that benefit from noncached memory.

The ftmac100 DMA descriptors needs to be marked uncacheable to stay coherent for SW and HW on noncoherent platforms.

Also add MMU_SECTION_SIZE definition (1MB) to the RISC-V system header, matching the MIPS convention used by the noncached memory infrastructure.

---
 arch/Kconfig                    | 2 +-
 arch/riscv/include/asm/system.h | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
arch/Kconfig +1 -1
index fb3e8d598e7..b05f249b661 100644
@@ -529,7 +529,7 @@ endmenu
 
 config SYS_HAS_NONCACHED_MEMORY
 	bool "Enable reserving a non-cached memory area for drivers"
-	depends on (ARM || MIPS) && (RTL8169 || MEDIATEK_ETH)
+	depends on (ARM || MIPS || RISCV) && (RTL8169 || MEDIATEK_ETH || FTMAC100)
 	help
 	  This is useful for drivers that would otherwise require a lot of
 	  explicit cache maintenance. For some drivers it's also impossible to
arch/riscv/include/asm/system.h +6 -0
index 87a804bfd5f..b71bbeef1e2 100644
@@ -25,6 +25,12 @@ struct event;
         csr_set(CSR_SSTATUS, __flags & SR_SIE); \
     } while (0)
 
+#ifdef CONFIG_SYS_NONCACHED_MEMORY
+/* 1MB granularity */
+#define MMU_SECTION_SHIFT	20
+#define MMU_SECTION_SIZE	BIT(MMU_SECTION_SHIFT)
+#endif /* CONFIG_SYS_NONCACHED_MEMORY */
+
 /* Hook to set up the CPU (called from SPL too) */
 int riscv_cpu_setup(void);
 
Signature · 1 line
2.34.1