mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 21:50:12 +01:00
intel: Share function to do device query in Xe KMD
A "dance" is required with this uAPI, first we need to ask KMD what is the size of the giving query id, then memory needs to be allocated to match that size and then query again with the memory address set and at this time Xe KMD will copy the query data to memory. This dance was being duplicated in xe_engine_get_info() and anv_xe_physical_device_get_parameters() and the next patch will also use it in Iris, so here adding it common/xe and re-using as much as possible. There is one more implementation of this function in intel/dev but due to how libs are linked intel/dev can't depend on to intel/common. 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/26325>
This commit is contained in:
parent
c5e37e7c39
commit
6a245e4eea
5 changed files with 54 additions and 34 deletions
|
|
@ -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',
|
||||
|
|
|
|||
34
src/intel/common/xe/intel_device_query.c
Normal file
34
src/intel/common/xe/intel_device_query.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
10
src/intel/common/xe/intel_device_query.h
Normal file
10
src/intel/common/xe/intel_device_query.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Copyright 2023 Intel Corporation
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void *xe_device_query_alloc_fetch(int fd, uint32_t query_id, uint32_t *len);
|
||||
|
|
@ -25,6 +25,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#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) *
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue