1 /*
2 * Copyright 2023 Intel Corporation
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "xe/intel_device_query.h"
7
8 #include "drm-uapi/xe_drm.h"
9
10 #include "common/intel_gem.h"
11
12 void *
xe_device_query_alloc_fetch(int fd,uint32_t query_id,uint32_t * len)13 xe_device_query_alloc_fetch(int fd, uint32_t query_id, uint32_t *len)
14 {
15 struct drm_xe_device_query query = {
16 .query = query_id,
17 };
18 if (intel_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query))
19 return NULL;
20
21 void *data = calloc(1, query.size);
22 if (!data)
23 return NULL;
24
25 query.data = (uintptr_t)data;
26 if (intel_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query)) {
27 free(data);
28 return NULL;
29 }
30
31 if (len)
32 *len = query.size;
33 return data;
34 }
35