Skip to contentSkip to conversation

drm/ttm: add pgprot handling for RISC-V

PATCH In review Icenowy Zheng 4 participants 6 messages Oct 20, 2025 – Oct 28, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/ttm: add pgprot handling for RISC-V

The RISC-V Svpbmt privileged extension provides support for overriding page memory coherency attributes, and, along with vendor extensions like Xtheadmae, supports pgprot_{writecombine,noncached} on RISC-V.

Adapt the codepath that maps ttm_write_combined to pgprot_writecombine and ttm_noncached to pgprot_noncached to RISC-V, to allow proper page access attributes.

---
Changes in v2:
- Added Han Gao's test tag.

 drivers/gpu/drm/ttm/ttm_module.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_module.c +2 -1
index b3fffe7b5062a..aa137ead5cc59 100644
@@ -74,7 +74,8 @@ pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
 #endif /* CONFIG_UML */
 #endif /* __i386__ || __x86_64__ */
 #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
-	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__)
+	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__) || \
+	defined(__riscv)
 	if (caching == ttm_write_combined)
 		tmp = pgprot_writecombine(tmp);
 	else
Signature · 1 line
2.51.0
#1 lore raw
Quoted 22 lines · Icenowy Zheng

The RISC-V Svpbmt privileged extension provides support for overriding page memory coherency attributes, and, along with vendor extensions like Xtheadmae, supports pgprot_{writecombine,noncached} on RISC-V.

Adapt the codepath that maps ttm_write_combined to pgprot_writecombine and ttm_noncached to pgprot_noncached to RISC-V, to allow proper page access attributes.

---
Changes in v2:
- Added Han Gao's test tag.

 drivers/gpu/drm/ttm/ttm_module.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_module.c +0 -0
index b3fffe7b5062a..aa137ead5cc59 100644

drivers/gpu/drm/ttm/ttm_module.c pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp) · line 78

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_module.c +2 -1
@@ -74,7 +74,8 @@ pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
 #endif /* CONFIG_UML */
 #endif /* __i386__ || __x86_64__ */
 #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
-	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__)
+	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__) || \
+	defined(__riscv)

Looks reasonable, but does that work on all RISC-V variants?

And while at it maybe please fix the indentation, using a tab here is probably not very adequate. In other words make the defined() match the one on the first line.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/ttm/ttm_module.c +0 -0
 	if (caching == ttm_write_combined)
 		tmp = pgprot_writecombine(tmp);
 	else
#2 lore raw

Tested on sophgo sg2042/sophgo sg2044/ultrarisc dp1000.

Quoted 49 lines · On Mon, Oct 27, 2025 at 15:57 Christian König <[email protected]> wrote:
Quoted 10 lines · Icenowy Zheng

The RISC-V Svpbmt privileged extension provides support for overriding page memory coherency attributes, and, along with vendor extensions like Xtheadmae, supports pgprot_{writecombine,noncached} on RISC-V.

Adapt the codepath that maps ttm_write_combined to pgprot_writecombine and ttm_noncached to pgprot_noncached to RISC-V, to allow proper page access attributes.

Review

Quoted 8 lines

---
Changes in v2:
- Added Han Gao's test tag.

 drivers/gpu/drm/ttm/ttm_module.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_module.c

drivers/gpu/drm/ttm/ttm_module.c pgprot_t ttm_prot_from_caching(enum ttm_caching

Quoted 4 lines

index b3fffe7b5062a..aa137ead5cc59 100644

drivers/gpu/drm/ttm/ttm_module.c +0 -0
@@ -74,7 +74,8 @@ pgprot_t ttm_prot_from_caching(enum ttm_caching

caching, pgprot_t tmp)

drivers/gpu/drm/ttm/ttm_module.c pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)

Quoted 5 lines
drivers/gpu/drm/ttm/ttm_module.c +1 -1
 #endif /* CONFIG_UML */
 #endif /* __i386__ || __x86_64__ */
 #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
-     defined(__powerpc__) || defined(__mips__) || defined(__loongarch__)
+     defined(__powerpc__) || defined(__mips__) ||

defined(__loongarch__) || \

drivers/gpu/drm/ttm/ttm_module.c pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp) · line 78

Quoted 1 line
drivers/gpu/drm/ttm/ttm_module.c +1 -0
+     defined(__riscv)

Looks reasonable, but does that work on all RISC-V variants?

And while at it maybe please fix the indentation, using a tab here is probably not very adequate. In other words make the defined() match the one on the first line.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/ttm/ttm_module.c +0 -0
      if (caching == ttm_write_combined)
              tmp = pgprot_writecombine(tmp);
      else
maintainer
#3 lore raw
In reply to Christian König
Quoted 8 lines · Christian König
Quoted 7 lines · Icenowy Zheng

The RISC-V Svpbmt privileged extension provides support for overriding page memory coherency attributes, and, along with vendor extensions like Xtheadmae, supports pgprot_{writecombine,noncached} on RISC-V.

Adapt the codepath that maps ttm_write_combined to pgprot_writecombine and ttm_noncached to pgprot_noncached to RISC-V, to allow proper page access attributes.

[ ... ]

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_module.c +0 -0
index b3fffe7b5062a..aa137ead5cc59 100644
@@ -74,7 +74,8 @@ pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_module.c pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp) · line 78

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_module.c +2 -1
 #endif /* CONFIG_UML */
 #endif /* __i386__ || __x86_64__ */
 #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
-	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__)
+	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__) || \
+	defined(__riscv)

Looks reasonable, but does that work on all RISC-V variants?

From an RISC-V architectural perspective, yes.

Of course there might be a hardware bug in some given manufacturer's implementation, but then again, that could happen on the other architectures as well.

- Paul

#4 lore raw
Quoted 27 lines · Paul Walmsley
Quoted 8 lines · Christian König
Quoted 7 lines · Icenowy Zheng

The RISC-V Svpbmt privileged extension provides support for overriding page memory coherency attributes, and, along with vendor extensions like Xtheadmae, supports pgprot_{writecombine,noncached} on RISC-V.

Adapt the codepath that maps ttm_write_combined to pgprot_writecombine and ttm_noncached to pgprot_noncached to RISC-V, to allow proper page access attributes.

[ ... ]

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_module.c +0 -0
index b3fffe7b5062a..aa137ead5cc59 100644
@@ -74,7 +74,8 @@ pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_module.c pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp) · line 78

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_module.c +2 -1
 #endif /* CONFIG_UML */
 #endif /* __i386__ || __x86_64__ */
 #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
-	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__)
+	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__) || \
+	defined(__riscv)

Looks reasonable, but does that work on all RISC-V variants?

Quoted 5 lines

From an RISC-V architectural perspective, yes.

Of course there might be a hardware bug in some given manufacturer's implementation, but then again, that could happen on the other architectures as well.

I've added my acked-by and pushed it to drm-misc-next.

Regards,
Christian.

Quoted 3 lines

- Paul

#5 lore raw
In reply to Christian König

Tested on sophgo sg2042/sophgo sg2044/ultrarisc dp1000.

Quoted 44 lines · Christian König
Quoted 22 lines · Icenowy Zheng

The RISC-V Svpbmt privileged extension provides support for overriding page memory coherency attributes, and, along with vendor extensions like Xtheadmae, supports pgprot_{writecombine,noncached} on RISC-V.

Adapt the codepath that maps ttm_write_combined to pgprot_writecombine and ttm_noncached to pgprot_noncached to RISC-V, to allow proper page access attributes.

---
Changes in v2:
- Added Han Gao's test tag.

 drivers/gpu/drm/ttm/ttm_module.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_module.c +0 -0
index b3fffe7b5062a..aa137ead5cc59 100644

drivers/gpu/drm/ttm/ttm_module.c pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp) · line 78

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_module.c +2 -1
@@ -74,7 +74,8 @@ pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
 #endif /* CONFIG_UML */
 #endif /* __i386__ || __x86_64__ */
 #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
-     defined(__powerpc__) || defined(__mips__) || defined(__loongarch__)
+     defined(__powerpc__) || defined(__mips__) || defined(__loongarch__) || \
+     defined(__riscv)

Looks reasonable, but does that work on all RISC-V variants?

And while at it maybe please fix the indentation, using a tab here is probably not very adequate. In other words make the defined() match the one on the first line.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/ttm/ttm_module.c +0 -0
      if (caching == ttm_write_combined)
              tmp = pgprot_writecombine(tmp);
      else