drm-shim: Add io region handling in mmap

This allows to replace mappings of io regions.

Signed-off-by: Mary Guillemard <mary.guillemard@collabora.com>
Reviewed-by: Brezillon Boris <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28241>
This commit is contained in:
Mary Guillemard
2024-03-19 09:33:08 +01:00
committed by Marge Bot
parent 4d4b1820ca
commit 9c92d92ab9
2 changed files with 24 additions and 0 deletions

View File

@@ -413,6 +413,15 @@ drm_shim_bo_get_mmap_offset(struct shim_fd *shim_fd, struct shim_bo *bo)
return bo->mem_addr; return bo->mem_addr;
} }
void
drm_shim_init_iomem_region(off64_t offset, size_t size,
void *(*mmap_handler)(size_t, int, int, off64_t))
{
shim_device.iomem_region.mmap = mmap_handler;
shim_device.iomem_region.start = offset;
shim_device.iomem_region.size = size;
}
/* For mmap() on the DRM fd, look up the BO from the "offset" and map the BO's /* For mmap() on the DRM fd, look up the BO from the "offset" and map the BO's
* fd. * fd.
*/ */
@@ -420,6 +429,12 @@ void *
drm_shim_mmap(struct shim_fd *shim_fd, size_t length, int prot, int flags, drm_shim_mmap(struct shim_fd *shim_fd, size_t length, int prot, int flags,
int fd, off64_t offset) int fd, off64_t offset)
{ {
if (shim_device.iomem_region.mmap &&
offset >= shim_device.iomem_region.start &&
offset + length <= shim_device.iomem_region.start + shim_device.iomem_region.size) {
return shim_device.iomem_region.mmap(length, prot, flags, offset);
}
mtx_lock(&shim_device.mem_lock); mtx_lock(&shim_device.mem_lock);
struct shim_bo *bo = _mesa_hash_table_u64_search(shim_device.offset_map, offset); struct shim_bo *bo = _mesa_hash_table_u64_search(shim_device.offset_map, offset);
mtx_unlock(&shim_device.mem_lock); mtx_unlock(&shim_device.mem_lock);

View File

@@ -44,6 +44,13 @@ struct shim_device {
/* Mapping from mmap offset to shim_bo */ /* Mapping from mmap offset to shim_bo */
struct hash_table_u64 *offset_map; struct hash_table_u64 *offset_map;
/* IOMEM region */
struct {
off64_t start;
size_t size;
void *(*mmap)(size_t length, int prot, int flags, off64_t offset);
} iomem_region;
mtx_t mem_lock; mtx_t mem_lock;
/* Heap from which shim_bo are allocated */ /* Heap from which shim_bo are allocated */
struct util_vma_heap mem_heap; struct util_vma_heap mem_heap;
@@ -101,6 +108,8 @@ struct shim_bo *drm_shim_bo_lookup(struct shim_fd *shim_fd, int handle);
int drm_shim_bo_get_handle(struct shim_fd *shim_fd, struct shim_bo *bo); int drm_shim_bo_get_handle(struct shim_fd *shim_fd, struct shim_bo *bo);
uint64_t drm_shim_bo_get_mmap_offset(struct shim_fd *shim_fd, uint64_t drm_shim_bo_get_mmap_offset(struct shim_fd *shim_fd,
struct shim_bo *bo); struct shim_bo *bo);
void drm_shim_init_iomem_region(off64_t offset, size_t size,
void *(*mmap_handler)(size_t, int, int, off64_t));
/* driver-specific hooks. */ /* driver-specific hooks. */
void drm_shim_driver_init(void); void drm_shim_driver_init(void);