From 23f8b5b7a21ee77d1233dab803fa2d60ad0235fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Fri, 10 Feb 2023 10:19:19 -0800 Subject: [PATCH] iris: Add initial skeleton of kmd backend MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: José Roberto de Souza Reviewed-by: Lionel Landwerlin Part-of: --- src/gallium/drivers/iris/i915/iris_kmd_backend.c | 100 +++++++++++++++++++++++ src/gallium/drivers/iris/iris_bufmgr.c | 71 ++-------------- src/gallium/drivers/iris/iris_kmd_backend.c | 37 +++++++++ src/gallium/drivers/iris/iris_kmd_backend.h | 45 ++++++++++ src/gallium/drivers/iris/meson.build | 3 + 5 files changed, 191 insertions(+), 65 deletions(-) create mode 100644 src/gallium/drivers/iris/i915/iris_kmd_backend.c create mode 100644 src/gallium/drivers/iris/iris_kmd_backend.c create mode 100644 src/gallium/drivers/iris/iris_kmd_backend.h diff --git a/src/gallium/drivers/iris/i915/iris_kmd_backend.c b/src/gallium/drivers/iris/i915/iris_kmd_backend.c new file mode 100644 index 0000000..99e2a7a --- /dev/null +++ b/src/gallium/drivers/iris/i915/iris_kmd_backend.c @@ -0,0 +1,100 @@ +/* + * 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 "iris/iris_kmd_backend.h" + +#include "common/intel_gem.h" + +#include "drm-uapi/i915_drm.h" + +#include "iris_bufmgr.h" + +static uint32_t +i915_gem_create(struct iris_bufmgr *bufmgr, + const struct intel_memory_class_instance **regions, + uint16_t regions_count, uint64_t size, + enum iris_heap heap_flags, unsigned alloc_flags) +{ + if (unlikely(!iris_bufmgr_get_device_info(bufmgr)->mem.use_class_instance)) { + struct drm_i915_gem_create create_legacy = { .size = size }; + + assert(regions_count == 1 && + regions[0]->klass == I915_MEMORY_CLASS_SYSTEM); + + /* All new BOs we get from the kernel are zeroed, so we don't need to + * worry about that here. + */ + if (intel_ioctl(iris_bufmgr_get_fd(bufmgr), DRM_IOCTL_I915_GEM_CREATE, + &create_legacy)) + return 0; + + return create_legacy.handle; + } + + struct drm_i915_gem_memory_class_instance i915_regions[2]; + assert(regions_count <= ARRAY_SIZE(i915_regions)); + for (uint16_t i = 0; i < regions_count; i++) { + i915_regions[i].memory_class = regions[i]->klass; + i915_regions[i].memory_instance = regions[i]->instance; + } + + struct drm_i915_gem_create_ext create = { + .size = size, + }; + struct drm_i915_gem_create_ext_memory_regions ext_regions = { + .base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS }, + .num_regions = regions_count, + .regions = (uintptr_t)i915_regions, + }; + intel_gem_add_ext(&create.extensions, + I915_GEM_CREATE_EXT_MEMORY_REGIONS, + &ext_regions.base); + + if (iris_bufmgr_vram_size(bufmgr) > 0 && + !intel_vram_all_mappable(iris_bufmgr_get_device_info(bufmgr)) && + heap_flags == IRIS_HEAP_DEVICE_LOCAL_PREFERRED) + create.flags |= I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS; + + /* Protected param */ + struct drm_i915_gem_create_ext_protected_content protected_param = { + .flags = 0, + }; + if (alloc_flags & BO_ALLOC_PROTECTED) { + intel_gem_add_ext(&create.extensions, + I915_GEM_CREATE_EXT_PROTECTED_CONTENT, + &protected_param.base); + } + + if (intel_ioctl(iris_bufmgr_get_fd(bufmgr), DRM_IOCTL_I915_GEM_CREATE_EXT, + &create)) + return 0; + + return create.handle; +} + +const struct iris_kmd_backend *i915_get_backend(void) +{ + static const struct iris_kmd_backend i915_backend = { + .gem_create = i915_gem_create, + }; + return &i915_backend; +} diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index ff1ea37..8853502 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -65,6 +65,7 @@ #include "iris_bufmgr.h" #include "iris_context.h" #include "string.h" +#include "iris_kmd_backend.h" #include "drm-uapi/i915_drm.h" @@ -232,6 +233,7 @@ struct iris_bufmgr { int next_screen_id; struct intel_device_info devinfo; + const struct iris_kmd_backend *kmd_backend; bool bo_reuse:1; bool use_global_vm:1; @@ -967,69 +969,6 @@ i915_gem_set_domain(struct iris_bufmgr *bufmgr, uint32_t handle, DRM_IOCTL_I915_GEM_SET_DOMAIN, &sd); } -static uint32_t -i915_gem_create(struct iris_bufmgr *bufmgr, - const struct intel_memory_class_instance **regions, - uint16_t regions_count, uint64_t size, - enum iris_heap heap_flags, unsigned alloc_flags) -{ - if (unlikely(!iris_bufmgr_get_device_info(bufmgr)->mem.use_class_instance)) { - struct drm_i915_gem_create create_legacy = { .size = size }; - - assert(regions_count == 1 && - regions[0]->klass == I915_MEMORY_CLASS_SYSTEM); - - /* All new BOs we get from the kernel are zeroed, so we don't need to - * worry about that here. - */ - if (intel_ioctl(iris_bufmgr_get_fd(bufmgr), DRM_IOCTL_I915_GEM_CREATE, - &create_legacy)) - return 0; - - return create_legacy.handle; - } - - struct drm_i915_gem_memory_class_instance i915_regions[2]; - assert(regions_count <= ARRAY_SIZE(i915_regions)); - for (uint16_t i = 0; i < regions_count; i++) { - i915_regions[i].memory_class = regions[i]->klass; - i915_regions[i].memory_instance = regions[i]->instance; - } - - struct drm_i915_gem_create_ext create = { - .size = size, - }; - struct drm_i915_gem_create_ext_memory_regions ext_regions = { - .base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS }, - .num_regions = regions_count, - .regions = (uintptr_t)i915_regions, - }; - intel_gem_add_ext(&create.extensions, - I915_GEM_CREATE_EXT_MEMORY_REGIONS, - &ext_regions.base); - - if (iris_bufmgr_vram_size(bufmgr) > 0 && - !intel_vram_all_mappable(iris_bufmgr_get_device_info(bufmgr)) && - heap_flags == IRIS_HEAP_DEVICE_LOCAL_PREFERRED) - create.flags |= I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS; - - /* Protected param */ - struct drm_i915_gem_create_ext_protected_content protected_param = { - .flags = 0, - }; - if (alloc_flags & BO_ALLOC_PROTECTED) { - intel_gem_add_ext(&create.extensions, - I915_GEM_CREATE_EXT_PROTECTED_CONTENT, - &protected_param.base); - } - - if (intel_ioctl(iris_bufmgr_get_fd(bufmgr), DRM_IOCTL_I915_GEM_CREATE_EXT, - &create)) - return 0; - - return create.handle; -} - static struct iris_bo * alloc_fresh_bo(struct iris_bufmgr *bufmgr, uint64_t bo_size, unsigned flags) { @@ -1062,8 +1001,9 @@ alloc_fresh_bo(struct iris_bufmgr *bufmgr, uint64_t bo_size, unsigned flags) regions[num_regions++] = bufmgr->sys.region; } - bo->gem_handle = i915_gem_create(bufmgr, regions, num_regions, bo_size, - bo->real.heap, flags); + bo->gem_handle = bufmgr->kmd_backend->gem_create(bufmgr, regions, + num_regions, bo_size, + bo->real.heap, flags); if (bo->gem_handle == 0) { free(bo); return NULL; @@ -2427,6 +2367,7 @@ iris_bufmgr_create(struct intel_device_info *devinfo, int fd, bool bo_reuse) devinfo = &bufmgr->devinfo; bufmgr->bo_reuse = bo_reuse; iris_bufmgr_get_meminfo(bufmgr, devinfo); + bufmgr->kmd_backend = iris_kmd_backend_get(devinfo->kmd_type); struct intel_query_engine_info *engine_info; engine_info = intel_engine_get_info(bufmgr->fd, bufmgr->devinfo.kmd_type); diff --git a/src/gallium/drivers/iris/iris_kmd_backend.c b/src/gallium/drivers/iris/iris_kmd_backend.c new file mode 100644 index 0000000..2781ec3 --- /dev/null +++ b/src/gallium/drivers/iris/iris_kmd_backend.c @@ -0,0 +1,37 @@ +/* + * 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 "iris_kmd_backend.h" + +#include + +const struct iris_kmd_backend * +iris_kmd_backend_get(enum intel_kmd_type type) +{ + switch (type) { + case INTEL_KMD_TYPE_I915: + return i915_get_backend(); + default: + return NULL; + } +} diff --git a/src/gallium/drivers/iris/iris_kmd_backend.h b/src/gallium/drivers/iris/iris_kmd_backend.h new file mode 100644 index 0000000..5f1faab --- /dev/null +++ b/src/gallium/drivers/iris/iris_kmd_backend.h @@ -0,0 +1,45 @@ +/* + * 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 + +#include "dev/intel_device_info.h" +#include "dev/intel_kmd.h" + +struct iris_bufmgr; +enum iris_heap; + +struct iris_kmd_backend { + uint32_t (*gem_create)(struct iris_bufmgr *bufmgr, + const struct intel_memory_class_instance **regions, + uint16_t regions_count, uint64_t size, + enum iris_heap heap_flags, unsigned alloc_flags); +}; + +const struct iris_kmd_backend * +iris_kmd_backend_get(enum intel_kmd_type type); + +/* Internal functions, should not be called */ +const struct iris_kmd_backend *i915_get_backend(void); diff --git a/src/gallium/drivers/iris/meson.build b/src/gallium/drivers/iris/meson.build index dc1d018..f1eea4a 100644 --- a/src/gallium/drivers/iris/meson.build +++ b/src/gallium/drivers/iris/meson.build @@ -19,6 +19,7 @@ # SOFTWARE. files_libiris = files( + 'i915/iris_kmd_backend.c', 'driinfo_iris.h', 'iris_batch.c', 'iris_batch.h', @@ -39,6 +40,8 @@ files_libiris = files( 'iris_formats.c', 'iris_genx_macros.h', 'iris_genx_protos.h', + 'iris_kmd_backend.c', + 'iris_kmd_backend.h', 'iris_measure.c', 'iris_measure.h', 'iris_monitor.c', -- 2.7.4