Skip to content

Commit f29c738

Browse files
vsyrjalaJiri Slaby
authored andcommitted
drm/i915: Don't clobber the GTT when it's within stolen memory
commit f1e1c21 upstream. On most gen2-4 platforms the GTT can be (or maybe always is?) inside the stolen memory region. If that's the case, reduce the size of the stolen memory appropriately to make make sure we don't clobber the GTT. v2: Deal with gen4 36 bit physical address Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=80151 Acked-by: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
1 parent d5a2e14 commit f29c738

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎drivers/gpu/drm/i915/i915_gem_stolen.c‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,50 @@ static unsigned long i915_stolen_to_physical(struct drm_device *dev)
7474
if (base == 0)
7575
return 0;
7676

77+
/* make sure we don't clobber the GTT if it's within stolen memory */
78+
if (INTEL_INFO(dev)->gen <= 4 && !IS_G33(dev) && !IS_G4X(dev)) {
79+
struct {
80+
u32 start, end;
81+
} stolen[2] = {
82+
{ .start = base, .end = base + dev_priv->gtt.stolen_size, },
83+
{ .start = base, .end = base + dev_priv->gtt.stolen_size, },
84+
};
85+
u64 gtt_start, gtt_end;
86+
87+
gtt_start = I915_READ(PGTBL_CTL);
88+
if (IS_GEN4(dev))
89+
gtt_start = (gtt_start & PGTBL_ADDRESS_LO_MASK) |
90+
(gtt_start & PGTBL_ADDRESS_HI_MASK) << 28;
91+
else
92+
gtt_start &= PGTBL_ADDRESS_LO_MASK;
93+
gtt_end = gtt_start + gtt_total_entries(dev_priv->gtt) * 4;
94+
95+
if (gtt_start >= stolen[0].start && gtt_start < stolen[0].end)
96+
stolen[0].end = gtt_start;
97+
if (gtt_end > stolen[1].start && gtt_end <= stolen[1].end)
98+
stolen[1].start = gtt_end;
99+
100+
/* pick the larger of the two chunks */
101+
if (stolen[0].end - stolen[0].start >
102+
stolen[1].end - stolen[1].start) {
103+
base = stolen[0].start;
104+
dev_priv->gtt.stolen_size = stolen[0].end - stolen[0].start;
105+
} else {
106+
base = stolen[1].start;
107+
dev_priv->gtt.stolen_size = stolen[1].end - stolen[1].start;
108+
}
109+
110+
if (stolen[0].start != stolen[1].start ||
111+
stolen[0].end != stolen[1].end) {
112+
DRM_DEBUG_KMS("GTT within stolen memory at 0x%llx-0x%llx\n",
113+
(unsigned long long) gtt_start,
114+
(unsigned long long) gtt_end - 1);
115+
DRM_DEBUG_KMS("Stolen memory adjusted to 0x%x-0x%x\n",
116+
base, base + (u32) dev_priv->gtt.stolen_size - 1);
117+
}
118+
}
119+
120+
77121
/* Verify that nothing else uses this physical address. Stolen
78122
* memory should be reserved by the BIOS and hidden from the
79123
* kernel. So if the region is already marked as busy, something

‎drivers/gpu/drm/i915/i915_reg.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@
570570
/*
571571
* Instruction and interrupt control regs
572572
*/
573+
#define PGTBL_CTL 0x02020
574+
#define PGTBL_ADDRESS_LO_MASK 0xfffff000 /* bits [31:12] */
575+
#define PGTBL_ADDRESS_HI_MASK 0x000000f0 /* bits [35:32] (gen4) */
573576
#define PGTBL_ER 0x02024
574577
#define RENDER_RING_BASE 0x02000
575578
#define BSD_RING_BASE 0x04000

0 commit comments

Comments
 (0)