intel: Pull anv_i915_query into common code
We also add a helper which contains the standard query+alloc+query pattern used by anv_gem_get_engine_info(). The caller is required to free the pointer. These are declared static inline not because we care about the performance of these helpers but because we're going to use them in the intel_device_info code and we don't want a link dependency. Reviewed-by: Paulo Zanoni <paulo.r.zanoni@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11770>
This commit is contained in:

committed by
Marge Bot

parent
b664481ba9
commit
ffdf4d7683
@@ -24,9 +24,13 @@
|
||||
#ifndef INTEL_GEM_H
|
||||
#define INTEL_GEM_H
|
||||
|
||||
#include "drm-uapi/i915_drm.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
@@ -72,6 +76,66 @@ intel_ioctl(int fd, unsigned long request, void *arg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper around DRM_IOCTL_I915_QUERY
|
||||
*
|
||||
* Unfortunately, the error semantics of this ioctl are rather annoying so
|
||||
* it's better to have a common helper.
|
||||
*/
|
||||
static inline int
|
||||
intel_i915_query(int fd, uint64_t query_id, void *buffer,
|
||||
int32_t *buffer_len)
|
||||
{
|
||||
struct drm_i915_query_item item = {
|
||||
.query_id = query_id,
|
||||
.length = *buffer_len,
|
||||
.data_ptr = (uintptr_t)buffer,
|
||||
};
|
||||
|
||||
struct drm_i915_query args = {
|
||||
.num_items = 1,
|
||||
.flags = 0,
|
||||
.items_ptr = (uintptr_t)&item,
|
||||
};
|
||||
|
||||
int ret = intel_ioctl(fd, DRM_IOCTL_I915_QUERY, &args);
|
||||
if (ret != 0)
|
||||
return -errno;
|
||||
else if (item.length < 0)
|
||||
return item.length;
|
||||
|
||||
*buffer_len = item.length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for the given data, allocating as needed
|
||||
*
|
||||
* The caller is responsible for freeing the returned pointer.
|
||||
*/
|
||||
static inline void *
|
||||
intel_i915_query_alloc(int fd, uint64_t query_id)
|
||||
{
|
||||
int32_t length = 0;
|
||||
int ret = intel_i915_query(fd, query_id, NULL, &length);
|
||||
if (ret < 0)
|
||||
return NULL;
|
||||
|
||||
void *data = calloc(1, length);
|
||||
assert(data != NULL); /* This shouldn't happen in practice */
|
||||
if (data == NULL)
|
||||
return NULL;
|
||||
|
||||
ret = intel_i915_query(fd, query_id, data, &length);
|
||||
assert(ret == 0); /* We should have caught the error above */
|
||||
if (ret < 0) {
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
bool intel_gem_supports_syncobj_wait(int fd);
|
||||
|
||||
#endif /* INTEL_GEM_H */
|
||||
|
@@ -770,50 +770,10 @@ anv_gem_syncobj_timeline_query(struct anv_device *device,
|
||||
return intel_ioctl(device->fd, DRM_IOCTL_SYNCOBJ_QUERY, &args);
|
||||
}
|
||||
|
||||
int
|
||||
anv_i915_query(int fd, uint64_t query_id, void *buffer,
|
||||
int32_t *buffer_len)
|
||||
{
|
||||
struct drm_i915_query_item item = {
|
||||
.query_id = query_id,
|
||||
.length = *buffer_len,
|
||||
.data_ptr = (uintptr_t)buffer,
|
||||
};
|
||||
|
||||
struct drm_i915_query args = {
|
||||
.num_items = 1,
|
||||
.flags = 0,
|
||||
.items_ptr = (uintptr_t)&item,
|
||||
};
|
||||
|
||||
int ret = intel_ioctl(fd, DRM_IOCTL_I915_QUERY, &args);
|
||||
if (ret != 0)
|
||||
return -errno;
|
||||
else if (item.length < 0)
|
||||
return item.length;
|
||||
|
||||
*buffer_len = item.length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct drm_i915_query_engine_info *
|
||||
anv_gem_get_engine_info(int fd)
|
||||
{
|
||||
int32_t length = 0;
|
||||
int ret = anv_i915_query(fd, DRM_I915_QUERY_ENGINE_INFO, NULL, &length);
|
||||
if (ret < 0)
|
||||
return NULL;
|
||||
|
||||
struct drm_i915_query_engine_info *info = calloc(1, length);
|
||||
ret = anv_i915_query(fd, DRM_I915_QUERY_ENGINE_INFO, info, &length);
|
||||
assert(ret == 0);
|
||||
|
||||
if (ret < 0) {
|
||||
free(info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return info;
|
||||
return intel_i915_query_alloc(fd, DRM_I915_QUERY_ENGINE_INFO);
|
||||
}
|
||||
|
||||
int
|
||||
|
Reference in New Issue
Block a user