iris: Add initial skeleton of kmd backend

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21369>
This commit is contained in:
José Roberto de Souza 2023-02-10 10:19:19 -08:00 committed by Marge Bot
parent cebffb404f
commit 23f8b5b7a2
5 changed files with 191 additions and 65 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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 <stdlib.h>
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;
}
}

View file

@ -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 <stdint.h>
#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);

View file

@ -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',