|
30 | 30 | #include <drm/i915_drm.h>
|
31 | 31 | #include "i915_drv.h"
|
32 | 32 |
|
33 |
| -#define KB(x) ((x) * 1024) |
34 |
| -#define MB(x) (KB(x) * 1024) |
35 |
| - |
36 | 33 | /*
|
37 | 34 | * The BIOS typically reserves some of the system's memory for the exclusive
|
38 | 35 | * 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,
|
81 | 78 |
|
82 | 79 | static dma_addr_t i915_stolen_to_dma(struct drm_i915_private *dev_priv)
|
83 | 80 | {
|
84 |
| - struct pci_dev *pdev = dev_priv->drm.pdev; |
85 | 81 | struct i915_ggtt *ggtt = &dev_priv->ggtt;
|
| 82 | + dma_addr_t base = intel_graphics_stolen_res.start; |
86 | 83 | 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); |
168 | 84 |
|
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)); |
191 | 86 |
|
192 | 87 | if (base == 0 || add_overflows(base, ggtt->stolen_size))
|
193 | 88 | return 0;
|
|
0 commit comments