[PATCH 04/31] drm/i915/uapi: Extend query ioctl to return hwconfig table
Ramalingam C
ramalingam.c at intel.com
Fri Feb 11 15:00:25 UTC 2022
From: Rodrigo Vivi <rodrigo.vivi at intel.com>
GuC contains a consolidated table with all needed information for the
device in use.
Right now this information is spread and hardcoded to all the components
including GuC, i915 and all user space components. The goal here is
to consolidate the definition into GuC in a way that all interested
components can grab the very latest and synchronized information using
this simple query.
As most of other queries, this one can be called twice,
one with item.length=0, so it can determine the exact buffer size,
then allocate the user memory and call it again for grabbing the
table. Simple as this:
memset(&item, 0, sizeof(item));
item.query_id = DRM_I915_QUERY_HWCONCFIG_TABLE;
query.items_ptr = (int64_t) &item;
query.num_items = 1;
ioctl(fd, DRM_IOCTL_I915_QUERY, query, sizeof(query));
if (item.size <= 0)
return -ENOENT;
data = malloc(item.length);
item.data_ptr = (int64_t) &data;
ioctl(fd, DRM_IOCTL_I915_QUERY, query, sizeof(query));
// Parses the data accordingly ...
The returned array is a simple and flexible KLV (Key/Length/Value)
formatted table. For instance it could be simple as this:
enum device_attr {
ATTR_EUS_PER_SSLICE = 0,
ATTR_SOME_MASK = 1,
};
static const u32 hwconfig[] = {
ATTR_EUS_PER_SSLICE,
1, // Value Length in DWords
8, // Value
ATTR_SOME_MASK,
3,
0x00FFFFFFFF, 0xFFFFFFFF, 0xFF000000, // Value
};
static const u32 table_size = sizeof(hwconfig) / sizeof(hwconfig[0]));
It is important to highlight though that the device attribute ids are
common across multiple components including GuC, i915 and user space
components. The definition of the actual and current attributes can be
found in the header file: intel_guc_hwconfig_types.h
Cc: Tvrtko Ursulin <tvrtko.ursulin at linux.intel.com>
Cc: Kenneth Graunke <kenneth.w.graunke at intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko at intel.com>
Cc: Slawomir Milczarek <slawomir.milczarek at intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi at intel.com>
Signed-off-by: Ramalingam C <ramalingam.c at intel.com>
---
drivers/gpu/drm/i915/i915_query.c | 29 +++++++++++++++++++++++++++++
include/uapi/drm/i915_drm.h | 1 +
2 files changed, 30 insertions(+)
diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c
index 2dfbc22857a3..0aff3b9becd6 100644
--- a/drivers/gpu/drm/i915/i915_query.c
+++ b/drivers/gpu/drm/i915/i915_query.c
@@ -479,12 +479,38 @@ static int query_memregion_info(struct drm_i915_private *i915,
return total_length;
}
+static int query_hwconfig_table(struct drm_i915_private *i915,
+ struct drm_i915_query_item *query_item)
+{
+ struct intel_guc_hwconfig *hwconfig = &to_gt(i915)->uc.guc.hwconfig;
+
+ if (!hwconfig->size || !hwconfig->ptr)
+ return -ENODEV;
+
+ if (query_item->length == 0)
+ return hwconfig->size;
+
+ if (query_item->length < hwconfig->size) {
+ drm_dbg(&i915->drm, "Invalid query hwconfig table size=%u expected=%u\n",
+ query_item->length, hwconfig->size);
+ return -EINVAL;
+ }
+
+ if (copy_to_user(u64_to_user_ptr(query_item->data_ptr),
+ hwconfig->ptr, hwconfig->size))
+ return -EFAULT;
+
+ return hwconfig->size;
+}
+
static int (* const i915_query_funcs[])(struct drm_i915_private *dev_priv,
struct drm_i915_query_item *query_item) = {
query_topology_info,
query_engine_info,
query_perf_config,
query_memregion_info,
+ NULL, /* 5 is reserved */
+ query_hwconfig_table,
};
int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
@@ -518,6 +544,9 @@ int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
if (func_idx < ARRAY_SIZE(i915_query_funcs)) {
func_idx = array_index_nospec(func_idx,
ARRAY_SIZE(i915_query_funcs));
+ if (!i915_query_funcs[func_idx])
+ return -EINVAL;
+
ret = i915_query_funcs[func_idx](dev_priv, &item);
}
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
index 914ebd9290e5..5e678917da70 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -2685,6 +2685,7 @@ struct drm_i915_query_item {
#define DRM_I915_QUERY_ENGINE_INFO 2
#define DRM_I915_QUERY_PERF_CONFIG 3
#define DRM_I915_QUERY_MEMORY_REGIONS 4
+#define DRM_I915_QUERY_HWCONFIG_TABLE 6
/* Must be kept compact -- no holes and well documented */
/**
--
2.20.1
More information about the Intel-gfx-trybot
mailing list