diff --git a/src/gallium/drivers/iris/i915/iris_bufmgr.c b/src/gallium/drivers/iris/i915/iris_bufmgr.c new file mode 100644 index 00000000000..67fa6332db7 --- /dev/null +++ b/src/gallium/drivers/iris/i915/iris_bufmgr.c @@ -0,0 +1,44 @@ +/* + * Copyright © 2023 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#include "i915/iris_bufmgr.h" + +#include "common/intel_gem.h" +#include "iris/iris_bufmgr.h" + +#include "drm-uapi/i915_drm.h" + +bool +iris_i915_bo_madvise(struct iris_bo *bo, enum iris_madvice state) +{ + uint32_t i915_state = state == IRIS_MADVICE_WILL_NEED ? + I915_MADV_WILLNEED : I915_MADV_DONTNEED; + struct drm_i915_gem_madvise madv = { + .handle = bo->gem_handle, + .madv = i915_state, + .retained = 1, + }; + + intel_ioctl(iris_bufmgr_get_fd(bo->bufmgr), DRM_IOCTL_I915_GEM_MADVISE, &madv); + + return madv.retained; +} diff --git a/src/gallium/drivers/iris/i915/iris_bufmgr.h b/src/gallium/drivers/iris/i915/iris_bufmgr.h new file mode 100644 index 00000000000..02d85db47b2 --- /dev/null +++ b/src/gallium/drivers/iris/i915/iris_bufmgr.h @@ -0,0 +1,30 @@ +/* + * Copyright © 2023 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#pragma once + +#include + +struct iris_bo; +enum iris_madvice; + +bool iris_i915_bo_madvise(struct iris_bo *bo, enum iris_madvice state); diff --git a/src/gallium/drivers/iris/i915/iris_kmd_backend.c b/src/gallium/drivers/iris/i915/iris_kmd_backend.c index 99e2a7aec89..b40fda9c7ea 100644 --- a/src/gallium/drivers/iris/i915/iris_kmd_backend.c +++ b/src/gallium/drivers/iris/i915/iris_kmd_backend.c @@ -26,7 +26,7 @@ #include "drm-uapi/i915_drm.h" -#include "iris_bufmgr.h" +#include "iris/iris_bufmgr.h" static uint32_t i915_gem_create(struct iris_bufmgr *bufmgr, diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index 88535025bb7..56286594b2c 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -66,6 +66,7 @@ #include "iris_context.h" #include "string.h" #include "iris_kmd_backend.h" +#include "i915/iris_bufmgr.h" #include "drm-uapi/i915_drm.h" @@ -527,21 +528,31 @@ iris_bo_busy(struct iris_bo *bo) return busy; } -int -iris_bo_madvise(struct iris_bo *bo, int state) +/** + * Specify the volatility of the buffer. + * \param bo Buffer to create a name for + * \param state The purgeable status + * + * Use IRIS_MADVICE_DONT_NEED to mark the buffer as purgeable, and it will be + * reclaimed under memory pressure. If you subsequently require the buffer, + * then you must pass IRIS_MADVICE_WILL_NEED to mark the buffer as required. + * + * Returns true if the buffer was retained, or false if it was discarded + * whilst marked as IRIS_MADVICE_DONT_NEED. + */ +static bool +iris_bo_madvise(struct iris_bo *bo, enum iris_madvice state) { /* We can't madvise suballocated BOs. */ assert(iris_bo_is_real(bo)); - struct drm_i915_gem_madvise madv = { - .handle = bo->gem_handle, - .madv = state, - .retained = 1, - }; - - intel_ioctl(bo->bufmgr->fd, DRM_IOCTL_I915_GEM_MADVISE, &madv); - - return madv.retained; + switch (iris_bufmgr_get_device_info(bo->bufmgr)->kmd_type) { + case INTEL_KMD_TYPE_I915: + return iris_i915_bo_madvise(bo, state); + default: + unreachable("missing"); + return false; + } } static struct iris_bo * @@ -905,7 +916,7 @@ alloc_bo_from_cache(struct iris_bufmgr *bufmgr, list_del(&cur->head); /* Tell the kernel we need this BO. If it still exists, we're done! */ - if (iris_bo_madvise(cur, I915_MADV_WILLNEED)) { + if (iris_bo_madvise(cur, IRIS_MADVICE_WILL_NEED)) { bo = cur; break; } @@ -1439,7 +1450,7 @@ bo_unreference_final(struct iris_bo *bo, time_t time) if (bo->real.reusable) bucket = bucket_for_size(bufmgr, bo->size, bo->real.heap); /* Put the buffer into our internal cache for reuse if we can. */ - if (bucket && iris_bo_madvise(bo, I915_MADV_DONTNEED)) { + if (bucket && iris_bo_madvise(bo, IRIS_MADVICE_DONT_NEED)) { bo->real.free_time = time; bo->name = NULL; diff --git a/src/gallium/drivers/iris/iris_bufmgr.h b/src/gallium/drivers/iris/iris_bufmgr.h index 9f891de08b6..79bd78b1020 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.h +++ b/src/gallium/drivers/iris/iris_bufmgr.h @@ -472,20 +472,6 @@ void iris_bo_mark_exported(struct iris_bo *bo); */ bool iris_bo_busy(struct iris_bo *bo); -/** - * Specify the volatility of the buffer. - * \param bo Buffer to create a name for - * \param madv The purgeable status - * - * Use I915_MADV_DONTNEED to mark the buffer as purgeable, and it will be - * reclaimed under memory pressure. If you subsequently require the buffer, - * then you must pass I915_MADV_WILLNEED to mark the buffer as required. - * - * Returns 1 if the buffer was retained, or 0 if it was discarded whilst - * marked as I915_MADV_DONTNEED. - */ -int iris_bo_madvise(struct iris_bo *bo, int madv); - struct iris_bufmgr *iris_bufmgr_get_for_fd(int fd, bool bo_reuse); int iris_bufmgr_get_fd(struct iris_bufmgr *bufmgr); @@ -597,4 +583,9 @@ uint64_t iris_bufmgr_vram_size(struct iris_bufmgr *bufmgr); uint64_t iris_bufmgr_sram_size(struct iris_bufmgr *bufmgr); const struct intel_device_info *iris_bufmgr_get_device_info(struct iris_bufmgr *bufmgr); +enum iris_madvice { + IRIS_MADVICE_WILL_NEED = 0, + IRIS_MADVICE_DONT_NEED = 1, +}; + #endif /* IRIS_BUFMGR_H */ diff --git a/src/gallium/drivers/iris/meson.build b/src/gallium/drivers/iris/meson.build index f1eea4aaba5..7cb198322c2 100644 --- a/src/gallium/drivers/iris/meson.build +++ b/src/gallium/drivers/iris/meson.build @@ -19,6 +19,8 @@ # SOFTWARE. files_libiris = files( + 'i915/iris_bufmgr.c', + 'i915/iris_bufmgr.h', 'i915/iris_kmd_backend.c', 'driinfo_iris.h', 'iris_batch.c',