1 // SPDX-License-Identifier: MIT
3 * Copyright © 2022 Intel Corporation
6 #include "gt/intel_engine_regs.h"
10 #include "i915_ioctl.h"
12 #include "intel_runtime_pm.h"
13 #include "intel_uncore.h"
16 * This file is for small ioctl functions that are out of place everywhere else,
17 * and not big enough to warrant a file of their own.
19 * This is not the dumping ground for random ioctls.
22 struct reg_whitelist {
23 i915_reg_t offset_ldw;
24 i915_reg_t offset_udw;
30 static const struct reg_whitelist reg_read_whitelist[] = {
32 .offset_ldw = RING_TIMESTAMP(RENDER_RING_BASE),
33 .offset_udw = RING_TIMESTAMP_UDW(RENDER_RING_BASE),
34 .min_graphics_ver = 4,
35 .max_graphics_ver = 12,
40 int i915_reg_read_ioctl(struct drm_device *dev,
41 void *data, struct drm_file *unused)
43 struct drm_i915_private *i915 = to_i915(dev);
44 struct intel_uncore *uncore = &i915->uncore;
45 struct drm_i915_reg_read *reg = data;
46 struct reg_whitelist const *entry;
47 intel_wakeref_t wakeref;
52 entry = reg_read_whitelist;
53 remain = ARRAY_SIZE(reg_read_whitelist);
55 u32 entry_offset = i915_mmio_reg_offset(entry->offset_ldw);
57 GEM_BUG_ON(!is_power_of_2(entry->size));
58 GEM_BUG_ON(entry->size > 8);
59 GEM_BUG_ON(entry_offset & (entry->size - 1));
61 if (IS_GRAPHICS_VER(i915, entry->min_graphics_ver, entry->max_graphics_ver) &&
62 entry_offset == (reg->offset & -entry->size))
71 flags = reg->offset & (entry->size - 1);
73 with_intel_runtime_pm(&i915->runtime_pm, wakeref) {
74 if (entry->size == 8 && flags == I915_REG_READ_8B_WA)
75 reg->val = intel_uncore_read64_2x32(uncore,
78 else if (entry->size == 8 && flags == 0)
79 reg->val = intel_uncore_read64(uncore,
81 else if (entry->size == 4 && flags == 0)
82 reg->val = intel_uncore_read(uncore, entry->offset_ldw);
83 else if (entry->size == 2 && flags == 0)
84 reg->val = intel_uncore_read16(uncore,
86 else if (entry->size == 1 && flags == 0)
87 reg->val = intel_uncore_read8(uncore,