2 * SPDX-License-Identifier: MIT
4 * Copyright © 2018 Intel Corporation
8 #include "i915_query.h"
9 #include <uapi/drm/i915_drm.h>
11 static int query_topology_info(struct drm_i915_private *dev_priv,
12 struct drm_i915_query_item *query_item)
14 const struct sseu_dev_info *sseu = &INTEL_INFO(dev_priv)->sseu;
15 struct drm_i915_query_topology_info topo;
16 u32 slice_length, subslice_length, eu_length, total_length;
18 if (query_item->flags != 0)
21 if (sseu->max_slices == 0)
24 BUILD_BUG_ON(sizeof(u8) != sizeof(sseu->slice_mask));
26 slice_length = sizeof(sseu->slice_mask);
27 subslice_length = sseu->max_slices *
28 DIV_ROUND_UP(sseu->max_subslices,
29 sizeof(sseu->subslice_mask[0]) * BITS_PER_BYTE);
30 eu_length = sseu->max_slices * sseu->max_subslices *
31 DIV_ROUND_UP(sseu->max_eus_per_subslice, BITS_PER_BYTE);
33 total_length = sizeof(topo) + slice_length + subslice_length + eu_length;
35 if (query_item->length == 0)
38 if (query_item->length < total_length)
41 if (copy_from_user(&topo, u64_to_user_ptr(query_item->data_ptr),
48 if (!access_ok(VERIFY_WRITE, u64_to_user_ptr(query_item->data_ptr),
52 memset(&topo, 0, sizeof(topo));
53 topo.max_slices = sseu->max_slices;
54 topo.max_subslices = sseu->max_subslices;
55 topo.max_eus_per_subslice = sseu->max_eus_per_subslice;
57 topo.subslice_offset = slice_length;
58 topo.subslice_stride = DIV_ROUND_UP(sseu->max_subslices, BITS_PER_BYTE);
59 topo.eu_offset = slice_length + subslice_length;
61 DIV_ROUND_UP(sseu->max_eus_per_subslice, BITS_PER_BYTE);
63 if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr),
67 if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr + sizeof(topo)),
68 &sseu->slice_mask, slice_length))
71 if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr +
72 sizeof(topo) + slice_length),
73 sseu->subslice_mask, subslice_length))
76 if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr +
78 slice_length + subslice_length),
79 sseu->eu_mask, eu_length))
85 static int (* const i915_query_funcs[])(struct drm_i915_private *dev_priv,
86 struct drm_i915_query_item *query_item) = {
90 int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
92 struct drm_i915_private *dev_priv = to_i915(dev);
93 struct drm_i915_query *args = data;
94 struct drm_i915_query_item __user *user_item_ptr =
95 u64_to_user_ptr(args->items_ptr);
101 for (i = 0; i < args->num_items; i++, user_item_ptr++) {
102 struct drm_i915_query_item item;
106 if (copy_from_user(&item, user_item_ptr, sizeof(item)))
109 if (item.query_id == 0)
112 func_idx = item.query_id - 1;
114 if (func_idx < ARRAY_SIZE(i915_query_funcs))
115 ret = i915_query_funcs[func_idx](dev_priv, &item);
119 /* Only write the length back to userspace if they differ. */
120 if (ret != item.length && put_user(ret, &user_item_ptr->length))