1c349dbc7Sjsg /*
2c349dbc7Sjsg * SPDX-License-Identifier: MIT
3c349dbc7Sjsg */
4c349dbc7Sjsg
5c349dbc7Sjsg #include "gem/i915_gem_mman.h"
6c349dbc7Sjsg #include "gt/intel_engine_user.h"
7c349dbc7Sjsg
8*f005ef32Sjsg #include "pxp/intel_pxp.h"
9*f005ef32Sjsg
101bb76ff1Sjsg #include "i915_cmd_parser.h"
11c349dbc7Sjsg #include "i915_drv.h"
121bb76ff1Sjsg #include "i915_getparam.h"
13c349dbc7Sjsg #include "i915_perf.h"
14c349dbc7Sjsg
i915_getparam_ioctl(struct drm_device * dev,void * data,struct drm_file * file_priv)15c349dbc7Sjsg int i915_getparam_ioctl(struct drm_device *dev, void *data,
16c349dbc7Sjsg struct drm_file *file_priv)
17c349dbc7Sjsg {
18c349dbc7Sjsg struct drm_i915_private *i915 = to_i915(dev);
195ca02815Sjsg struct pci_dev *pdev = i915->drm.pdev;
201bb76ff1Sjsg const struct sseu_dev_info *sseu = &to_gt(i915)->info.sseu;
21c349dbc7Sjsg drm_i915_getparam_t *param = data;
225ca02815Sjsg int value = 0;
23c349dbc7Sjsg
24c349dbc7Sjsg switch (param->param) {
25c349dbc7Sjsg case I915_PARAM_IRQ_ACTIVE:
26c349dbc7Sjsg case I915_PARAM_ALLOW_BATCHBUFFER:
27c349dbc7Sjsg case I915_PARAM_LAST_DISPATCH:
28c349dbc7Sjsg case I915_PARAM_HAS_EXEC_CONSTANTS:
29c349dbc7Sjsg /* Reject all old ums/dri params. */
30c349dbc7Sjsg return -ENODEV;
31c349dbc7Sjsg case I915_PARAM_CHIPSET_ID:
325ca02815Sjsg value = pdev->device;
33c349dbc7Sjsg break;
34c349dbc7Sjsg case I915_PARAM_REVISION:
355ca02815Sjsg value = pdev->revision;
36c349dbc7Sjsg break;
37c349dbc7Sjsg case I915_PARAM_NUM_FENCES_AVAIL:
381bb76ff1Sjsg value = to_gt(i915)->ggtt->num_fences;
39c349dbc7Sjsg break;
40c349dbc7Sjsg case I915_PARAM_HAS_OVERLAY:
411bb76ff1Sjsg value = !!i915->display.overlay;
42c349dbc7Sjsg break;
43c349dbc7Sjsg case I915_PARAM_HAS_BSD:
44c349dbc7Sjsg value = !!intel_engine_lookup_user(i915,
45c349dbc7Sjsg I915_ENGINE_CLASS_VIDEO, 0);
46c349dbc7Sjsg break;
47c349dbc7Sjsg case I915_PARAM_HAS_BLT:
48c349dbc7Sjsg value = !!intel_engine_lookup_user(i915,
49c349dbc7Sjsg I915_ENGINE_CLASS_COPY, 0);
50c349dbc7Sjsg break;
51c349dbc7Sjsg case I915_PARAM_HAS_VEBOX:
52c349dbc7Sjsg value = !!intel_engine_lookup_user(i915,
53c349dbc7Sjsg I915_ENGINE_CLASS_VIDEO_ENHANCE, 0);
54c349dbc7Sjsg break;
55c349dbc7Sjsg case I915_PARAM_HAS_BSD2:
56c349dbc7Sjsg value = !!intel_engine_lookup_user(i915,
57c349dbc7Sjsg I915_ENGINE_CLASS_VIDEO, 1);
58c349dbc7Sjsg break;
59c349dbc7Sjsg case I915_PARAM_HAS_LLC:
60c349dbc7Sjsg value = HAS_LLC(i915);
61c349dbc7Sjsg break;
62c349dbc7Sjsg case I915_PARAM_HAS_WT:
63c349dbc7Sjsg value = HAS_WT(i915);
64c349dbc7Sjsg break;
65c349dbc7Sjsg case I915_PARAM_HAS_ALIASING_PPGTT:
66c349dbc7Sjsg value = INTEL_PPGTT(i915);
67c349dbc7Sjsg break;
68c349dbc7Sjsg case I915_PARAM_HAS_SEMAPHORES:
69c349dbc7Sjsg value = !!(i915->caps.scheduler & I915_SCHEDULER_CAP_SEMAPHORES);
70c349dbc7Sjsg break;
71c349dbc7Sjsg case I915_PARAM_HAS_SECURE_BATCHES:
72c349dbc7Sjsg value = HAS_SECURE_BATCHES(i915) && capable(CAP_SYS_ADMIN);
73c349dbc7Sjsg break;
74c349dbc7Sjsg case I915_PARAM_CMD_PARSER_VERSION:
75c349dbc7Sjsg value = i915_cmd_parser_get_version(i915);
76c349dbc7Sjsg break;
77c349dbc7Sjsg case I915_PARAM_SUBSLICE_TOTAL:
78c349dbc7Sjsg value = intel_sseu_subslice_total(sseu);
79c349dbc7Sjsg if (!value)
80c349dbc7Sjsg return -ENODEV;
81c349dbc7Sjsg break;
82c349dbc7Sjsg case I915_PARAM_EU_TOTAL:
83c349dbc7Sjsg value = sseu->eu_total;
84c349dbc7Sjsg if (!value)
85c349dbc7Sjsg return -ENODEV;
86c349dbc7Sjsg break;
87c349dbc7Sjsg case I915_PARAM_HAS_GPU_RESET:
88ad8b1aafSjsg value = i915->params.enable_hangcheck &&
891bb76ff1Sjsg intel_has_gpu_reset(to_gt(i915));
901bb76ff1Sjsg if (value && intel_has_reset_engine(to_gt(i915)))
91c349dbc7Sjsg value = 2;
92c349dbc7Sjsg break;
93c349dbc7Sjsg case I915_PARAM_HAS_RESOURCE_STREAMER:
94c349dbc7Sjsg value = 0;
95c349dbc7Sjsg break;
96c349dbc7Sjsg case I915_PARAM_HAS_POOLED_EU:
97c349dbc7Sjsg value = HAS_POOLED_EU(i915);
98c349dbc7Sjsg break;
99c349dbc7Sjsg case I915_PARAM_MIN_EU_IN_POOL:
100c349dbc7Sjsg value = sseu->min_eu_in_pool;
101c349dbc7Sjsg break;
102c349dbc7Sjsg case I915_PARAM_HUC_STATUS:
103*f005ef32Sjsg /* On platform with a media GT, the HuC is on that GT */
104*f005ef32Sjsg if (i915->media_gt)
105*f005ef32Sjsg value = intel_huc_check_status(&i915->media_gt->uc.huc);
106*f005ef32Sjsg else
1071bb76ff1Sjsg value = intel_huc_check_status(&to_gt(i915)->uc.huc);
108c349dbc7Sjsg if (value < 0)
109c349dbc7Sjsg return value;
110c349dbc7Sjsg break;
111*f005ef32Sjsg case I915_PARAM_PXP_STATUS:
112*f005ef32Sjsg value = intel_pxp_get_readiness_status(i915->pxp);
113*f005ef32Sjsg if (value < 0)
114*f005ef32Sjsg return value;
115*f005ef32Sjsg break;
116c349dbc7Sjsg case I915_PARAM_MMAP_GTT_VERSION:
117c349dbc7Sjsg /* Though we've started our numbering from 1, and so class all
118c349dbc7Sjsg * earlier versions as 0, in effect their value is undefined as
119c349dbc7Sjsg * the ioctl will report EINVAL for the unknown param!
120c349dbc7Sjsg */
121c349dbc7Sjsg value = i915_gem_mmap_gtt_version();
122c349dbc7Sjsg break;
123c349dbc7Sjsg case I915_PARAM_HAS_SCHEDULER:
124c349dbc7Sjsg value = i915->caps.scheduler;
125c349dbc7Sjsg break;
126c349dbc7Sjsg
127c349dbc7Sjsg case I915_PARAM_MMAP_VERSION:
128c349dbc7Sjsg /* Remember to bump this if the version changes! */
129c349dbc7Sjsg case I915_PARAM_HAS_GEM:
130c349dbc7Sjsg case I915_PARAM_HAS_PAGEFLIPPING:
131c349dbc7Sjsg case I915_PARAM_HAS_EXECBUF2: /* depends on GEM */
132c349dbc7Sjsg case I915_PARAM_HAS_RELAXED_FENCING:
133c349dbc7Sjsg case I915_PARAM_HAS_COHERENT_RINGS:
134c349dbc7Sjsg case I915_PARAM_HAS_RELAXED_DELTA:
135c349dbc7Sjsg case I915_PARAM_HAS_GEN7_SOL_RESET:
136c349dbc7Sjsg case I915_PARAM_HAS_WAIT_TIMEOUT:
137c349dbc7Sjsg case I915_PARAM_HAS_PRIME_VMAP_FLUSH:
138c349dbc7Sjsg case I915_PARAM_HAS_PINNED_BATCHES:
139c349dbc7Sjsg case I915_PARAM_HAS_EXEC_NO_RELOC:
140c349dbc7Sjsg case I915_PARAM_HAS_EXEC_HANDLE_LUT:
141c349dbc7Sjsg case I915_PARAM_HAS_COHERENT_PHYS_GTT:
142c349dbc7Sjsg case I915_PARAM_HAS_EXEC_SOFTPIN:
143c349dbc7Sjsg case I915_PARAM_HAS_EXEC_ASYNC:
144c349dbc7Sjsg case I915_PARAM_HAS_EXEC_FENCE:
145c349dbc7Sjsg case I915_PARAM_HAS_EXEC_CAPTURE:
146c349dbc7Sjsg case I915_PARAM_HAS_EXEC_BATCH_FIRST:
147c349dbc7Sjsg case I915_PARAM_HAS_EXEC_FENCE_ARRAY:
148c349dbc7Sjsg case I915_PARAM_HAS_EXEC_SUBMIT_FENCE:
149ad8b1aafSjsg case I915_PARAM_HAS_EXEC_TIMELINE_FENCES:
1505ca02815Sjsg case I915_PARAM_HAS_USERPTR_PROBE:
151c349dbc7Sjsg /* For the time being all of these are always true;
152c349dbc7Sjsg * if some supported hardware does not have one of these
153c349dbc7Sjsg * features this value needs to be provided from
154c349dbc7Sjsg * INTEL_INFO(), a feature macro, or similar.
155c349dbc7Sjsg */
156c349dbc7Sjsg value = 1;
157c349dbc7Sjsg break;
158c349dbc7Sjsg case I915_PARAM_HAS_CONTEXT_ISOLATION:
159c349dbc7Sjsg value = intel_engines_has_context_isolation(i915);
160c349dbc7Sjsg break;
161c349dbc7Sjsg case I915_PARAM_SLICE_MASK:
1621bb76ff1Sjsg /* Not supported from Xe_HP onward; use topology queries */
1631bb76ff1Sjsg if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 50))
1641bb76ff1Sjsg return -EINVAL;
1651bb76ff1Sjsg
166c349dbc7Sjsg value = sseu->slice_mask;
167c349dbc7Sjsg if (!value)
168c349dbc7Sjsg return -ENODEV;
169c349dbc7Sjsg break;
170c349dbc7Sjsg case I915_PARAM_SUBSLICE_MASK:
1711bb76ff1Sjsg /* Not supported from Xe_HP onward; use topology queries */
1721bb76ff1Sjsg if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 50))
1731bb76ff1Sjsg return -EINVAL;
1741bb76ff1Sjsg
1755ca02815Sjsg /* Only copy bits from the first slice */
1761bb76ff1Sjsg value = intel_sseu_get_hsw_subslices(sseu, 0);
177c349dbc7Sjsg if (!value)
178c349dbc7Sjsg return -ENODEV;
179c349dbc7Sjsg break;
180c349dbc7Sjsg case I915_PARAM_CS_TIMESTAMP_FREQUENCY:
1811bb76ff1Sjsg value = to_gt(i915)->clock_frequency;
182c349dbc7Sjsg break;
183c349dbc7Sjsg case I915_PARAM_MMAP_GTT_COHERENT:
184c349dbc7Sjsg value = INTEL_INFO(i915)->has_coherent_ggtt;
185c349dbc7Sjsg break;
186c349dbc7Sjsg case I915_PARAM_PERF_REVISION:
187*f005ef32Sjsg value = i915_perf_ioctl_version(i915);
188*f005ef32Sjsg break;
189*f005ef32Sjsg case I915_PARAM_OA_TIMESTAMP_FREQUENCY:
190*f005ef32Sjsg value = i915_perf_oa_timestamp_frequency(i915);
191c349dbc7Sjsg break;
192c349dbc7Sjsg default:
193*f005ef32Sjsg drm_dbg(&i915->drm, "Unknown parameter %d\n", param->param);
194c349dbc7Sjsg return -EINVAL;
195c349dbc7Sjsg }
196c349dbc7Sjsg
197c349dbc7Sjsg if (put_user(value, param->value))
198c349dbc7Sjsg return -EFAULT;
199c349dbc7Sjsg
200c349dbc7Sjsg return 0;
201c349dbc7Sjsg }
202