mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
c822e05918
With the introduction of asymmetric slices in CNL, we cannot rely on the previous SUBSLICE_MASK getparam to tell userspace what subslices are available. Here we introduce a more detailed way of querying the Gen's GPU topology that doesn't aggregate numbers. This is essential for monitoring parts of the GPU with the OA unit, because counters need to be normalized to the number of EUs/subslices/slices. The current aggregated numbers like EU_TOTAL do not gives us sufficient information. The Mesa series making use of this API is : https://patchwork.freedesktop.org/series/38795/ As a bonus we can draw representations of the GPU : https://imgur.com/a/vuqpa v2: Rename uapi struct s/_mask/_info/ (Tvrtko) Report max_slice/subslice/eus_per_subslice rather than strides (Tvrtko) Add uapi macros to read data from *_info structs (Tvrtko) v3: Use !!(v & DRM_I915_BIT()) for uapi macros instead of custom shifts (Tvrtko) v4: factorize query item writting (Tvrtko) tweak uapi struct/define names (Tvrtko) v5: Replace ALIGN() macro (Chris) v6: Updated uapi comments (Tvrtko) Moved flags != 0 checks into vfuncs (Tvrtko) v7: Use access_ok() before copying anything, to avoid overflows (Chris) Switch BUG_ON() to GEM_WARN_ON() (Tvrtko) v8: Tweak uapi comments style to match the coding style (Lionel) v9: Fix error in comment about computation of enabled subslice (Tvrtko) v10: Fix/update comments in uAPI (Sagar) v11: Drop drm_i915_query_(slice|subslice|eu)_info in favor of a single drm_i915_query_topology_info (Joonas) v12: Add subslice_stride/eu_stride in drm_i915_query_topology_info (Joonas) v13: Fix comment in uAPI (Joonas) Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Acked-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20180306122857.27317-7-lionel.g.landwerlin@intel.com
126 lines
3.3 KiB
C
126 lines
3.3 KiB
C
/*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
* Copyright © 2018 Intel Corporation
|
|
*/
|
|
|
|
#include "i915_drv.h"
|
|
#include "i915_query.h"
|
|
#include <uapi/drm/i915_drm.h>
|
|
|
|
static int query_topology_info(struct drm_i915_private *dev_priv,
|
|
struct drm_i915_query_item *query_item)
|
|
{
|
|
const struct sseu_dev_info *sseu = &INTEL_INFO(dev_priv)->sseu;
|
|
struct drm_i915_query_topology_info topo;
|
|
u32 slice_length, subslice_length, eu_length, total_length;
|
|
|
|
if (query_item->flags != 0)
|
|
return -EINVAL;
|
|
|
|
if (sseu->max_slices == 0)
|
|
return -ENODEV;
|
|
|
|
BUILD_BUG_ON(sizeof(u8) != sizeof(sseu->slice_mask));
|
|
|
|
slice_length = sizeof(sseu->slice_mask);
|
|
subslice_length = sseu->max_slices *
|
|
DIV_ROUND_UP(sseu->max_subslices,
|
|
sizeof(sseu->subslice_mask[0]) * BITS_PER_BYTE);
|
|
eu_length = sseu->max_slices * sseu->max_subslices *
|
|
DIV_ROUND_UP(sseu->max_eus_per_subslice, BITS_PER_BYTE);
|
|
|
|
total_length = sizeof(topo) + slice_length + subslice_length + eu_length;
|
|
|
|
if (query_item->length == 0)
|
|
return total_length;
|
|
|
|
if (query_item->length < total_length)
|
|
return -EINVAL;
|
|
|
|
if (copy_from_user(&topo, u64_to_user_ptr(query_item->data_ptr),
|
|
sizeof(topo)))
|
|
return -EFAULT;
|
|
|
|
if (topo.flags != 0)
|
|
return -EINVAL;
|
|
|
|
if (!access_ok(VERIFY_WRITE, u64_to_user_ptr(query_item->data_ptr),
|
|
total_length))
|
|
return -EFAULT;
|
|
|
|
memset(&topo, 0, sizeof(topo));
|
|
topo.max_slices = sseu->max_slices;
|
|
topo.max_subslices = sseu->max_subslices;
|
|
topo.max_eus_per_subslice = sseu->max_eus_per_subslice;
|
|
|
|
topo.subslice_offset = slice_length;
|
|
topo.subslice_stride = DIV_ROUND_UP(sseu->max_subslices, BITS_PER_BYTE);
|
|
topo.eu_offset = slice_length + subslice_length;
|
|
topo.eu_stride =
|
|
DIV_ROUND_UP(sseu->max_eus_per_subslice, BITS_PER_BYTE);
|
|
|
|
if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr),
|
|
&topo, sizeof(topo)))
|
|
return -EFAULT;
|
|
|
|
if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr + sizeof(topo)),
|
|
&sseu->slice_mask, slice_length))
|
|
return -EFAULT;
|
|
|
|
if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr +
|
|
sizeof(topo) + slice_length),
|
|
sseu->subslice_mask, subslice_length))
|
|
return -EFAULT;
|
|
|
|
if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr +
|
|
sizeof(topo) +
|
|
slice_length + subslice_length),
|
|
sseu->eu_mask, eu_length))
|
|
return -EFAULT;
|
|
|
|
return total_length;
|
|
}
|
|
|
|
static int (* const i915_query_funcs[])(struct drm_i915_private *dev_priv,
|
|
struct drm_i915_query_item *query_item) = {
|
|
query_topology_info,
|
|
};
|
|
|
|
int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
|
|
{
|
|
struct drm_i915_private *dev_priv = to_i915(dev);
|
|
struct drm_i915_query *args = data;
|
|
struct drm_i915_query_item __user *user_item_ptr =
|
|
u64_to_user_ptr(args->items_ptr);
|
|
u32 i;
|
|
|
|
if (args->flags != 0)
|
|
return -EINVAL;
|
|
|
|
for (i = 0; i < args->num_items; i++, user_item_ptr++) {
|
|
struct drm_i915_query_item item;
|
|
u64 func_idx;
|
|
int ret;
|
|
|
|
if (copy_from_user(&item, user_item_ptr, sizeof(item)))
|
|
return -EFAULT;
|
|
|
|
if (item.query_id == 0)
|
|
return -EINVAL;
|
|
|
|
func_idx = item.query_id - 1;
|
|
|
|
if (func_idx < ARRAY_SIZE(i915_query_funcs))
|
|
ret = i915_query_funcs[func_idx](dev_priv, &item);
|
|
else
|
|
ret = -EINVAL;
|
|
|
|
/* Only write the length back to userspace if they differ. */
|
|
if (ret != item.length && put_user(ret, &user_item_ptr->length))
|
|
return -EFAULT;
|
|
}
|
|
|
|
return 0;
|
|
}
|