From 546bc893f1d61763f96221583e707ec6f23267d1 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 11 Apr 2025 11:57:56 -0400 Subject: [PATCH] asahi: add sparse emu helpers Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/agx_device.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/asahi/lib/agx_device.h b/src/asahi/lib/agx_device.h index 0ab6ed6a4de..f1837e51d7d 100644 --- a/src/asahi/lib/agx_device.h +++ b/src/asahi/lib/agx_device.h @@ -177,6 +177,27 @@ struct agx_device { struct u_printf_ctx printf; }; +/* + * Determine if an address is in the read-only section. See the documentation + * for sparse_ro_offset. + */ +static inline bool +agx_addr_is_ro(struct agx_device *dev, uint64_t addr) +{ + return (addr & dev->sparse_ro_offset); +} + +/* + * Convert a read-write address to its read-only shadow address. See the + * documentation for sparse_ro_offset. + */ +static inline uint64_t +agx_rw_addr_to_ro(struct agx_device *dev, uint64_t addr) +{ + assert(!agx_addr_is_ro(dev, addr)); + return addr + dev->sparse_ro_offset; +} + static inline void * agx_bo_map(struct agx_bo *bo) {