diff --git a/src/intel/common/meson.build b/src/intel/common/meson.build index a92407dbff6..979ca09cb82 100644 --- a/src/intel/common/meson.build +++ b/src/intel/common/meson.build @@ -25,6 +25,8 @@ files_libintel_common = files( 'i915/intel_engine.h', 'i915/intel_gem.c', 'i915/intel_gem.h', + 'xe/intel_device_query.c', + 'xe/intel_device_query.h', 'xe/intel_engine.c', 'xe/intel_engine.h', 'xe/intel_gem.c', diff --git a/src/intel/common/xe/intel_device_query.c b/src/intel/common/xe/intel_device_query.c new file mode 100644 index 00000000000..af75a5538a7 --- /dev/null +++ b/src/intel/common/xe/intel_device_query.c @@ -0,0 +1,34 @@ +/* + * Copyright 2023 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#include "xe/intel_device_query.h" + +#include "drm-uapi/xe_drm.h" + +#include "common/intel_gem.h" + +void * +xe_device_query_alloc_fetch(int fd, uint32_t query_id, uint32_t *len) +{ + struct drm_xe_device_query query = { + .query = query_id, + }; + if (intel_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query)) + return NULL; + + void *data = calloc(1, query.size); + if (!data) + return NULL; + + query.data = (uintptr_t)data; + if (intel_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query)) { + free(data); + return NULL; + } + + if (len) + *len = query.size; + return data; +} diff --git a/src/intel/common/xe/intel_device_query.h b/src/intel/common/xe/intel_device_query.h new file mode 100644 index 00000000000..5c09ccc15a5 --- /dev/null +++ b/src/intel/common/xe/intel_device_query.h @@ -0,0 +1,10 @@ +/* + * Copyright 2023 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +void *xe_device_query_alloc_fetch(int fd, uint32_t query_id, uint32_t *len); diff --git a/src/intel/common/xe/intel_engine.c b/src/intel/common/xe/intel_engine.c index 43e173e8160..67ba34faab5 100644 --- a/src/intel/common/xe/intel_engine.c +++ b/src/intel/common/xe/intel_engine.c @@ -25,6 +25,7 @@ #include #include "common/intel_gem.h" +#include "common/xe/intel_device_query.h" #include "drm-uapi/xe_drm.h" @@ -69,21 +70,14 @@ intel_engine_class_to_xe(enum intel_engine_class intel) struct intel_query_engine_info * xe_engine_get_info(int fd) { - struct drm_xe_device_query query = { - .query = DRM_XE_DEVICE_QUERY_ENGINES, - }; - if (intel_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query)) - return NULL; + struct drm_xe_engine_class_instance *xe_engines; + uint32_t len; - struct drm_xe_engine_class_instance *xe_engines = calloc(1, query.size); + xe_engines = xe_device_query_alloc_fetch(fd, DRM_XE_DEVICE_QUERY_ENGINES, &len); if (!xe_engines) return NULL; - query.data = (uintptr_t)xe_engines; - if (intel_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query)) - goto error_free_xe_engines; - - const uint32_t engines_count = query.size / sizeof(*xe_engines); + const uint32_t engines_count = len / sizeof(*xe_engines); struct intel_query_engine_info *intel_engines_info; intel_engines_info = calloc(1, sizeof(*intel_engines_info) + sizeof(*intel_engines_info->engines) * diff --git a/src/intel/vulkan/xe/anv_device.c b/src/intel/vulkan/xe/anv_device.c index ac790ef18b3..3b4cc69a117 100644 --- a/src/intel/vulkan/xe/anv_device.c +++ b/src/intel/vulkan/xe/anv_device.c @@ -26,6 +26,8 @@ #include "drm-uapi/gpu_scheduler.h" #include "drm-uapi/xe_drm.h" +#include "common/xe/intel_device_query.h" + bool anv_xe_device_destroy_vm(struct anv_device *device) { struct drm_xe_vm_destroy destroy = { @@ -63,34 +65,12 @@ drm_sched_priority_to_vk_priority(enum drm_sched_priority drm_sched_priority) } } -static void * -xe_query_alloc_fetch(struct anv_physical_device *device, uint32_t query_id) -{ - struct drm_xe_device_query query = { - .query = query_id, - }; - if (intel_ioctl(device->local_fd, DRM_IOCTL_XE_DEVICE_QUERY, &query)) - return NULL; - - void *data = calloc(1, query.size); - if (!data) - return NULL; - - query.data = (uintptr_t)data; - if (intel_ioctl(device->local_fd, DRM_IOCTL_XE_DEVICE_QUERY, &query)) { - free(data); - return NULL; - } - - return data; -} - VkResult anv_xe_physical_device_get_parameters(struct anv_physical_device *device) { struct drm_xe_query_config *config; - config = xe_query_alloc_fetch(device, DRM_XE_DEVICE_QUERY_CONFIG); + config = xe_device_query_alloc_fetch(device->local_fd, DRM_XE_DEVICE_QUERY_CONFIG, NULL); if (!config) return vk_errorf(device, VK_ERROR_INITIALIZATION_FAILED, "unable to query device config");