Skip to content

Commit f6cf388

Browse files
jnikulatursulin
authored andcommitted
drm/i915: use mock device info for creating mock device
Instead of modifying the device info on the fly, use static const mock device info. It's not okay to modify device info at runtime; we've added separate runtime info for info that needs to be modified at runtime. We've added safeguards to device info to prevent it from being modified, but commit 5e352e3 ("drm/i915: preparation for using PAT index") just cast the const away and modified it anyway. This prevents device info from being moved to rodata. Fixes: 5e352e3 ("drm/i915: preparation for using PAT index") Suggested-by: Tvrtko Ursulin <[email protected]> Cc: Fei Yang <[email protected]> Cc: Andi Shyti <[email protected]> Cc: Andrzej Hajda <[email protected]> Cc: Matt Roper <[email protected]> Signed-off-by: Jani Nikula <[email protected]> Reviewed-by: Tvrtko Ursulin <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Reviewed-by: Andrzej Hajda <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/b0db62045a96a3fd4cf123685da88cc777f9b485.1687878757.git.jani.nikula@intel.com (cherry picked from commit ecc7a3c) Signed-off-by: Tvrtko Ursulin <[email protected]>
1 parent fdffb7d commit f6cf388

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

drivers/gpu/drm/i915/selftests/mock_gem_device.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,31 @@ static void mock_gt_probe(struct drm_i915_private *i915)
118118
i915->gt[0]->name = "Mock GT";
119119
}
120120

121+
static const struct intel_device_info mock_info = {
122+
.__runtime.graphics.ip.ver = -1,
123+
.__runtime.page_sizes = (I915_GTT_PAGE_SIZE_4K |
124+
I915_GTT_PAGE_SIZE_64K |
125+
I915_GTT_PAGE_SIZE_2M),
126+
.__runtime.memory_regions = REGION_SMEM,
127+
.__runtime.platform_engine_mask = BIT(0),
128+
129+
/* simply use legacy cache level for mock device */
130+
.max_pat_index = 3,
131+
.cachelevel_to_pat = {
132+
[I915_CACHE_NONE] = 0,
133+
[I915_CACHE_LLC] = 1,
134+
[I915_CACHE_L3_LLC] = 2,
135+
[I915_CACHE_WT] = 3,
136+
},
137+
};
138+
121139
struct drm_i915_private *mock_gem_device(void)
122140
{
123141
#if IS_ENABLED(CONFIG_IOMMU_API) && defined(CONFIG_INTEL_IOMMU)
124142
static struct dev_iommu fake_iommu = { .priv = (void *)-1 };
125143
#endif
126144
struct drm_i915_private *i915;
127-
struct intel_device_info *i915_info;
128145
struct pci_dev *pdev;
129-
unsigned int i;
130146
int ret;
131147

132148
pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
@@ -159,37 +175,25 @@ struct drm_i915_private *mock_gem_device(void)
159175

160176
pci_set_drvdata(pdev, i915);
161177

178+
/* Device parameters start as a copy of module parameters. */
179+
i915_params_copy(&i915->params, &i915_modparams);
180+
181+
/* Set up device info and initial runtime info. */
182+
intel_device_info_driver_create(i915, pdev->device, &mock_info);
183+
162184
dev_pm_domain_set(&pdev->dev, &pm_domain);
163185
pm_runtime_enable(&pdev->dev);
164186
pm_runtime_dont_use_autosuspend(&pdev->dev);
165187
if (pm_runtime_enabled(&pdev->dev))
166188
WARN_ON(pm_runtime_get_sync(&pdev->dev));
167189

168-
169-
i915_params_copy(&i915->params, &i915_modparams);
170-
171190
intel_runtime_pm_init_early(&i915->runtime_pm);
172191
/* wakeref tracking has significant overhead */
173192
i915->runtime_pm.no_wakeref_tracking = true;
174193

175194
/* Using the global GTT may ask questions about KMS users, so prepare */
176195
drm_mode_config_init(&i915->drm);
177196

178-
RUNTIME_INFO(i915)->graphics.ip.ver = -1;
179-
180-
RUNTIME_INFO(i915)->page_sizes =
181-
I915_GTT_PAGE_SIZE_4K |
182-
I915_GTT_PAGE_SIZE_64K |
183-
I915_GTT_PAGE_SIZE_2M;
184-
185-
RUNTIME_INFO(i915)->memory_regions = REGION_SMEM;
186-
187-
/* simply use legacy cache level for mock device */
188-
i915_info = (struct intel_device_info *)INTEL_INFO(i915);
189-
i915_info->max_pat_index = 3;
190-
for (i = 0; i < I915_MAX_CACHE_LEVEL; i++)
191-
i915_info->cachelevel_to_pat[i] = i;
192-
193197
intel_memory_regions_hw_probe(i915);
194198

195199
spin_lock_init(&i915->gpu_error.lock);
@@ -223,7 +227,6 @@ struct drm_i915_private *mock_gem_device(void)
223227
mock_init_ggtt(to_gt(i915));
224228
to_gt(i915)->vm = i915_vm_get(&to_gt(i915)->ggtt->vm);
225229

226-
RUNTIME_INFO(i915)->platform_engine_mask = BIT(0);
227230
to_gt(i915)->info.engine_mask = BIT(0);
228231

229232
to_gt(i915)->engine[RCS0] = mock_engine(i915, "mock", RCS0);

0 commit comments

Comments
 (0)