Module: Mesa Branch: main Commit: 7a9c471009c656ca05c810a5f06acf2285c8463e URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7a9c471009c656ca05c810a5f06acf2285c8463e
Author: Boris Brezillon <[email protected]> Date: Mon Nov 20 17:46:15 2023 +0100 panfrost: Add a VM to panfrost_device The current code assumes the logical device comes with a VM, so let's explicitly create this default VM so we can map BOs with the kmod API. Signed-off-by: Boris Brezillon <[email protected]> Reviewed-by: Erik Faye-Lund <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26357> --- src/panfrost/lib/pan_device.h | 3 +++ src/panfrost/lib/pan_props.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/panfrost/lib/pan_device.h b/src/panfrost/lib/pan_device.h index 5df6d6db189..bbf94dc305d 100644 --- a/src/panfrost/lib/pan_device.h +++ b/src/panfrost/lib/pan_device.h @@ -137,6 +137,9 @@ struct panfrost_device { /* Cached pan_kmod_dev_props properties queried at device create time. */ struct pan_kmod_dev_props props; + + /* VM attached to this device. */ + struct pan_kmod_vm *vm; } kmod; /* For pandecode */ diff --git a/src/panfrost/lib/pan_props.c b/src/panfrost/lib/pan_props.c index f155031e5cd..b3fcf606d3b 100644 --- a/src/panfrost/lib/pan_props.c +++ b/src/panfrost/lib/pan_props.c @@ -191,6 +191,24 @@ panfrost_query_optimal_tib_size(const struct panfrost_device *dev) return dev->model->tilebuffer_size / 2; } +static uint64_t +panfrost_clamp_to_usable_va_range(const struct panfrost_device *dev, + uint64_t va) +{ + struct pan_kmod_va_range user_va_range = + pan_kmod_dev_query_user_va_range(dev->kmod.dev); + + if (va < user_va_range.start) + return user_va_range.start; + else if (va > user_va_range.start + user_va_range.size) + return user_va_range.start + user_va_range.size; + + return va; +} + +/* Always reserve the lower 32MB. */ +#define PANFROST_VA_RESERVE_BOTTOM 0x2000000ull + void panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev) { @@ -211,6 +229,19 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev) if (!dev->model) goto err_free_kmod_dev; + /* 32bit address space, with the lower 32MB reserved. We clamp + * things so it matches kmod VA range limitations. + */ + uint64_t user_va_start = + panfrost_clamp_to_usable_va_range(dev, PANFROST_VA_RESERVE_BOTTOM); + uint64_t user_va_end = + panfrost_clamp_to_usable_va_range(dev, 1ull << 32); + + dev->kmod.vm = + pan_kmod_vm_create(dev->kmod.dev, PAN_KMOD_VM_FLAG_AUTO_VA, user_va_start, + user_va_end - user_va_start); + if (!dev->kmod.vm) + goto err_free_kmod_dev; dev->core_count = panfrost_query_core_count(dev, &dev->core_id_range); dev->thread_tls_alloc = panfrost_query_thread_tls_alloc(dev, dev->arch); @@ -275,6 +306,9 @@ panfrost_close_device(struct panfrost_device *dev) util_sparse_array_finish(&dev->bo_map); } + if (dev->kmod.vm) + pan_kmod_vm_destroy(dev->kmod.vm); + if (dev->kmod.dev) pan_kmod_dev_destroy(dev->kmod.dev); }
