Skip to content

Commit f773568

Browse files
matt-auldjlahtine-intel
authored andcommitted
drm/i915: nuke the duplicated stolen discovery
We duplicate the stolen discovery code in early-quirks and in i915, however now that the stolen region is exported as a resource from early-quirks we can nuke the duplication. v2: check overflows_type Signed-off-by: Matthew Auld <[email protected]> Cc: Joonas Lahtinen <[email protected]> Cc: Chris Wilson <[email protected]> Cc: Paulo Zanoni <[email protected]> Reviewed-by: Chris Wilson <[email protected]> Signed-off-by: Joonas Lahtinen <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 3b51b6f commit f773568

File tree

2 files changed

+5
-155
lines changed

2 files changed

+5
-155
lines changed

drivers/gpu/drm/i915/i915_gem_gtt.c

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,50 +2949,6 @@ static unsigned int chv_get_total_gtt_size(u16 gmch_ctrl)
29492949
return 0;
29502950
}
29512951

2952-
static size_t gen6_get_stolen_size(u16 snb_gmch_ctl)
2953-
{
2954-
snb_gmch_ctl >>= SNB_GMCH_GMS_SHIFT;
2955-
snb_gmch_ctl &= SNB_GMCH_GMS_MASK;
2956-
return (size_t)snb_gmch_ctl << 25; /* 32 MB units */
2957-
}
2958-
2959-
static size_t gen8_get_stolen_size(u16 bdw_gmch_ctl)
2960-
{
2961-
bdw_gmch_ctl >>= BDW_GMCH_GMS_SHIFT;
2962-
bdw_gmch_ctl &= BDW_GMCH_GMS_MASK;
2963-
return (size_t)bdw_gmch_ctl << 25; /* 32 MB units */
2964-
}
2965-
2966-
static size_t chv_get_stolen_size(u16 gmch_ctrl)
2967-
{
2968-
gmch_ctrl >>= SNB_GMCH_GMS_SHIFT;
2969-
gmch_ctrl &= SNB_GMCH_GMS_MASK;
2970-
2971-
/*
2972-
* 0x0 to 0x10: 32MB increments starting at 0MB
2973-
* 0x11 to 0x16: 4MB increments starting at 8MB
2974-
* 0x17 to 0x1d: 4MB increments start at 36MB
2975-
*/
2976-
if (gmch_ctrl < 0x11)
2977-
return (size_t)gmch_ctrl << 25;
2978-
else if (gmch_ctrl < 0x17)
2979-
return (size_t)(gmch_ctrl - 0x11 + 2) << 22;
2980-
else
2981-
return (size_t)(gmch_ctrl - 0x17 + 9) << 22;
2982-
}
2983-
2984-
static size_t gen9_get_stolen_size(u16 gen9_gmch_ctl)
2985-
{
2986-
gen9_gmch_ctl >>= BDW_GMCH_GMS_SHIFT;
2987-
gen9_gmch_ctl &= BDW_GMCH_GMS_MASK;
2988-
2989-
if (gen9_gmch_ctl < 0xf0)
2990-
return (size_t)gen9_gmch_ctl << 25; /* 32 MB units */
2991-
else
2992-
/* 4MB increments starting at 0xf0 for 4MB */
2993-
return (size_t)(gen9_gmch_ctl - 0xf0 + 1) << 22;
2994-
}
2995-
29962952
static int ggtt_probe_common(struct i915_ggtt *ggtt, u64 size)
29972953
{
29982954
struct drm_i915_private *dev_priv = ggtt->base.i915;
@@ -3343,14 +3299,13 @@ static int gen8_gmch_probe(struct i915_ggtt *ggtt)
33433299

33443300
pci_read_config_word(pdev, SNB_GMCH_CTRL, &snb_gmch_ctl);
33453301

3302+
ggtt->stolen_size = resource_size(&intel_graphics_stolen_res);
3303+
33463304
if (INTEL_GEN(dev_priv) >= 9) {
3347-
ggtt->stolen_size = gen9_get_stolen_size(snb_gmch_ctl);
33483305
size = gen8_get_total_gtt_size(snb_gmch_ctl);
33493306
} else if (IS_CHERRYVIEW(dev_priv)) {
3350-
ggtt->stolen_size = chv_get_stolen_size(snb_gmch_ctl);
33513307
size = chv_get_total_gtt_size(snb_gmch_ctl);
33523308
} else {
3353-
ggtt->stolen_size = gen8_get_stolen_size(snb_gmch_ctl);
33543309
size = gen8_get_total_gtt_size(snb_gmch_ctl);
33553310
}
33563311

@@ -3408,7 +3363,7 @@ static int gen6_gmch_probe(struct i915_ggtt *ggtt)
34083363
DRM_ERROR("Can't set DMA mask/consistent mask (%d)\n", err);
34093364
pci_read_config_word(pdev, SNB_GMCH_CTRL, &snb_gmch_ctl);
34103365

3411-
ggtt->stolen_size = gen6_get_stolen_size(snb_gmch_ctl);
3366+
ggtt->stolen_size = resource_size(&intel_graphics_stolen_res);
34123367

34133368
size = gen6_get_total_gtt_size(snb_gmch_ctl);
34143369
ggtt->base.total = (size / sizeof(gen6_pte_t)) << PAGE_SHIFT;

drivers/gpu/drm/i915/i915_gem_stolen.c

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
#include <drm/i915_drm.h>
3131
#include "i915_drv.h"
3232

33-
#define KB(x) ((x) * 1024)
34-
#define MB(x) (KB(x) * 1024)
35-
3633
/*
3734
* The BIOS typically reserves some of the system's memory for the exclusive
3835
* use of the integrated graphics. This memory is no longer available for
@@ -81,113 +78,11 @@ void i915_gem_stolen_remove_node(struct drm_i915_private *dev_priv,
8178

8279
static dma_addr_t i915_stolen_to_dma(struct drm_i915_private *dev_priv)
8380
{
84-
struct pci_dev *pdev = dev_priv->drm.pdev;
8581
struct i915_ggtt *ggtt = &dev_priv->ggtt;
82+
dma_addr_t base = intel_graphics_stolen_res.start;
8683
struct resource *r;
87-
dma_addr_t base;
88-
89-
/* Almost universally we can find the Graphics Base of Stolen Memory
90-
* at register BSM (0x5c) in the igfx configuration space. On a few
91-
* (desktop) machines this is also mirrored in the bridge device at
92-
* different locations, or in the MCHBAR.
93-
*
94-
* On 865 we just check the TOUD register.
95-
*
96-
* On 830/845/85x the stolen memory base isn't available in any
97-
* register. We need to calculate it as TOM-TSEG_SIZE-stolen_size.
98-
*
99-
*/
100-
base = 0;
101-
if (INTEL_GEN(dev_priv) >= 3) {
102-
u32 bsm;
103-
104-
pci_read_config_dword(pdev, INTEL_BSM, &bsm);
105-
106-
base = bsm & INTEL_BSM_MASK;
107-
} else if (IS_I865G(dev_priv)) {
108-
u32 tseg_size = 0;
109-
u16 toud = 0;
110-
u8 tmp;
111-
112-
pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
113-
I845_ESMRAMC, &tmp);
114-
115-
if (tmp & TSEG_ENABLE) {
116-
switch (tmp & I845_TSEG_SIZE_MASK) {
117-
case I845_TSEG_SIZE_512K:
118-
tseg_size = KB(512);
119-
break;
120-
case I845_TSEG_SIZE_1M:
121-
tseg_size = MB(1);
122-
break;
123-
}
124-
}
125-
126-
pci_bus_read_config_word(pdev->bus, PCI_DEVFN(0, 0),
127-
I865_TOUD, &toud);
128-
129-
base = (toud << 16) + tseg_size;
130-
} else if (IS_I85X(dev_priv)) {
131-
u32 tseg_size = 0;
132-
u32 tom;
133-
u8 tmp;
134-
135-
pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
136-
I85X_ESMRAMC, &tmp);
137-
138-
if (tmp & TSEG_ENABLE)
139-
tseg_size = MB(1);
140-
141-
pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 1),
142-
I85X_DRB3, &tmp);
143-
tom = tmp * MB(32);
144-
145-
base = tom - tseg_size - ggtt->stolen_size;
146-
} else if (IS_I845G(dev_priv)) {
147-
u32 tseg_size = 0;
148-
u32 tom;
149-
u8 tmp;
150-
151-
pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
152-
I845_ESMRAMC, &tmp);
153-
154-
if (tmp & TSEG_ENABLE) {
155-
switch (tmp & I845_TSEG_SIZE_MASK) {
156-
case I845_TSEG_SIZE_512K:
157-
tseg_size = KB(512);
158-
break;
159-
case I845_TSEG_SIZE_1M:
160-
tseg_size = MB(1);
161-
break;
162-
}
163-
}
164-
165-
pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
166-
I830_DRB3, &tmp);
167-
tom = tmp * MB(32);
16884

169-
base = tom - tseg_size - ggtt->stolen_size;
170-
} else if (IS_I830(dev_priv)) {
171-
u32 tseg_size = 0;
172-
u32 tom;
173-
u8 tmp;
174-
175-
pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
176-
I830_ESMRAMC, &tmp);
177-
178-
if (tmp & TSEG_ENABLE) {
179-
if (tmp & I830_TSEG_SIZE_1M)
180-
tseg_size = MB(1);
181-
else
182-
tseg_size = KB(512);
183-
}
184-
185-
pci_bus_read_config_byte(pdev->bus, PCI_DEVFN(0, 0),
186-
I830_DRB3, &tmp);
187-
tom = tmp * MB(32);
188-
189-
base = tom - tseg_size - ggtt->stolen_size;
190-
}
85+
GEM_BUG_ON(overflows_type(intel_graphics_stolen_res.start, base));
19186

19287
if (base == 0 || add_overflows(base, ggtt->stolen_size))
19388
return 0;

0 commit comments

Comments
 (0)