blob: 9bc3a0b82b962909a2b453ee76a42a3bcd9f8795 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Intel AGPGART routines.
3 */
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/module.h>
6#include <linux/pci.h>
7#include <linux/init.h>
Ahmed S. Darwish1eaf1222007-02-06 18:08:28 +02008#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/pagemap.h>
10#include <linux/agp_backend.h>
11#include "agp.h"
12
Zhenyu Wang17661682009-07-27 12:59:57 +010013/*
14 * If we have Intel graphics, we're not going to have anything other than
15 * an Intel IOMMU. So make the correct use of the PCI DMA API contingent
16 * on the Intel IOMMU support (CONFIG_DMAR).
17 * Only newer chipsets need to bother with this, of course.
18 */
19#ifdef CONFIG_DMAR
20#define USE_PCI_DMA_API 1
21#endif
22
Carlos Martíne914a362008-01-24 10:34:09 +100023#define PCI_DEVICE_ID_INTEL_E7221_HB 0x2588
24#define PCI_DEVICE_ID_INTEL_E7221_IG 0x258a
Eric Anholt65c25aa2006-09-06 11:57:18 -040025#define PCI_DEVICE_ID_INTEL_82946GZ_HB 0x2970
26#define PCI_DEVICE_ID_INTEL_82946GZ_IG 0x2972
Zhenyu Wang9119f852008-01-23 15:49:26 +100027#define PCI_DEVICE_ID_INTEL_82G35_HB 0x2980
28#define PCI_DEVICE_ID_INTEL_82G35_IG 0x2982
Eric Anholt65c25aa2006-09-06 11:57:18 -040029#define PCI_DEVICE_ID_INTEL_82965Q_HB 0x2990
30#define PCI_DEVICE_ID_INTEL_82965Q_IG 0x2992
31#define PCI_DEVICE_ID_INTEL_82965G_HB 0x29A0
32#define PCI_DEVICE_ID_INTEL_82965G_IG 0x29A2
Wang Zhenyu4598af32007-04-09 08:51:36 +080033#define PCI_DEVICE_ID_INTEL_82965GM_HB 0x2A00
34#define PCI_DEVICE_ID_INTEL_82965GM_IG 0x2A02
Zhenyu Wangdde47872007-07-26 09:18:09 +080035#define PCI_DEVICE_ID_INTEL_82965GME_HB 0x2A10
Wang Zhenyuc8eebfd2007-05-31 11:34:06 +080036#define PCI_DEVICE_ID_INTEL_82965GME_IG 0x2A12
Zhenyu Wangdde47872007-07-26 09:18:09 +080037#define PCI_DEVICE_ID_INTEL_82945GME_HB 0x27AC
Wang Zhenyudf80b142007-05-31 11:51:12 +080038#define PCI_DEVICE_ID_INTEL_82945GME_IG 0x27AE
Shaohua Li21778322009-02-23 15:19:16 +080039#define PCI_DEVICE_ID_INTEL_IGDGM_HB 0xA010
40#define PCI_DEVICE_ID_INTEL_IGDGM_IG 0xA011
41#define PCI_DEVICE_ID_INTEL_IGDG_HB 0xA000
42#define PCI_DEVICE_ID_INTEL_IGDG_IG 0xA001
Wang Zhenyu874808c62007-06-06 11:16:25 +080043#define PCI_DEVICE_ID_INTEL_G33_HB 0x29C0
44#define PCI_DEVICE_ID_INTEL_G33_IG 0x29C2
45#define PCI_DEVICE_ID_INTEL_Q35_HB 0x29B0
46#define PCI_DEVICE_ID_INTEL_Q35_IG 0x29B2
47#define PCI_DEVICE_ID_INTEL_Q33_HB 0x29D0
48#define PCI_DEVICE_ID_INTEL_Q33_IG 0x29D2
Zhenyu Wang99d32bd2008-07-30 12:26:50 -070049#define PCI_DEVICE_ID_INTEL_GM45_HB 0x2A40
50#define PCI_DEVICE_ID_INTEL_GM45_IG 0x2A42
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100051#define PCI_DEVICE_ID_INTEL_IGD_E_HB 0x2E00
52#define PCI_DEVICE_ID_INTEL_IGD_E_IG 0x2E02
53#define PCI_DEVICE_ID_INTEL_Q45_HB 0x2E10
54#define PCI_DEVICE_ID_INTEL_Q45_IG 0x2E12
55#define PCI_DEVICE_ID_INTEL_G45_HB 0x2E20
56#define PCI_DEVICE_ID_INTEL_G45_IG 0x2E22
Zhenyu Wanga50ccc62008-11-17 14:39:00 +080057#define PCI_DEVICE_ID_INTEL_G41_HB 0x2E30
58#define PCI_DEVICE_ID_INTEL_G41_IG 0x2E32
Zhenyu Wang32cb0552009-06-05 15:38:36 +080059#define PCI_DEVICE_ID_INTEL_IGDNG_D_HB 0x0040
60#define PCI_DEVICE_ID_INTEL_IGDNG_D_IG 0x0042
61#define PCI_DEVICE_ID_INTEL_IGDNG_M_HB 0x0044
62#define PCI_DEVICE_ID_INTEL_IGDNG_M_IG 0x0046
Eric Anholt65c25aa2006-09-06 11:57:18 -040063
Dave Airlief011ae72008-01-25 11:23:04 +100064/* cover 915 and 945 variants */
65#define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \
66 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB || \
67 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB || \
68 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB || \
69 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB || \
70 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB)
71
Eric Anholt65c25aa2006-09-06 11:57:18 -040072#define IS_I965 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82946GZ_HB || \
Dave Airlief011ae72008-01-25 11:23:04 +100073 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82G35_HB || \
74 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \
75 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \
76 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \
Eric Anholt82e14a62008-10-14 11:28:58 -070077 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB)
Eric Anholt65c25aa2006-09-06 11:57:18 -040078
Wang Zhenyu874808c62007-06-06 11:16:25 +080079#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
80 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
Shaohua Li21778322009-02-23 15:19:16 +080081 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q33_HB || \
82 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDGM_HB || \
83 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDG_HB)
84
85#define IS_IGD (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDGM_HB || \
86 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDG_HB)
Eric Anholt65c25aa2006-09-06 11:57:18 -040087
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100088#define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_E_HB || \
89 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \
Eric Anholt82e14a62008-10-14 11:28:58 -070090 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \
Zhenyu Wanga50ccc62008-11-17 14:39:00 +080091 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB || \
Zhenyu Wang32cb0552009-06-05 15:38:36 +080092 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G41_HB || \
93 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDNG_D_HB || \
94 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDNG_M_HB)
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100095
Thomas Hellstroma030ce42007-01-23 10:33:43 +010096extern int agp_memory_reserved;
97
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* Intel 815 register */
100#define INTEL_815_APCONT 0x51
101#define INTEL_815_ATTBASE_MASK ~0x1FFFFFFF
102
103/* Intel i820 registers */
104#define INTEL_I820_RDCR 0x51
105#define INTEL_I820_ERRSTS 0xc8
106
107/* Intel i840 registers */
108#define INTEL_I840_MCHCFG 0x50
109#define INTEL_I840_ERRSTS 0xc8
110
111/* Intel i850 registers */
112#define INTEL_I850_MCHCFG 0x50
113#define INTEL_I850_ERRSTS 0xc8
114
115/* intel 915G registers */
116#define I915_GMADDR 0x18
117#define I915_MMADDR 0x10
118#define I915_PTEADDR 0x1C
119#define I915_GMCH_GMS_STOLEN_48M (0x6 << 4)
120#define I915_GMCH_GMS_STOLEN_64M (0x7 << 4)
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000121#define G33_GMCH_GMS_STOLEN_128M (0x8 << 4)
122#define G33_GMCH_GMS_STOLEN_256M (0x9 << 4)
123#define INTEL_GMCH_GMS_STOLEN_96M (0xa << 4)
124#define INTEL_GMCH_GMS_STOLEN_160M (0xb << 4)
125#define INTEL_GMCH_GMS_STOLEN_224M (0xc << 4)
126#define INTEL_GMCH_GMS_STOLEN_352M (0xd << 4)
127
Dave Airlie6c00a612007-10-29 18:06:10 +1000128#define I915_IFPADDR 0x60
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Eric Anholt65c25aa2006-09-06 11:57:18 -0400130/* Intel 965G registers */
131#define I965_MSAC 0x62
Dave Airlie6c00a612007-10-29 18:06:10 +1000132#define I965_IFPADDR 0x70
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134/* Intel 7505 registers */
135#define INTEL_I7505_APSIZE 0x74
136#define INTEL_I7505_NCAPID 0x60
137#define INTEL_I7505_NISTAT 0x6c
138#define INTEL_I7505_ATTBASE 0x78
139#define INTEL_I7505_ERRSTS 0x42
140#define INTEL_I7505_AGPCTRL 0x70
141#define INTEL_I7505_MCHCFG 0x50
142
Dave Jonese5524f32007-02-22 18:41:28 -0500143static const struct aper_size_info_fixed intel_i810_sizes[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
145 {64, 16384, 4},
146 /* The 32M mode still requires a 64k gatt */
147 {32, 8192, 4}
148};
149
150#define AGP_DCACHE_MEMORY 1
151#define AGP_PHYS_MEMORY 2
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100152#define INTEL_AGP_CACHED_MEMORY 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154static struct gatt_mask intel_i810_masks[] =
155{
156 {.mask = I810_PTE_VALID, .type = 0},
157 {.mask = (I810_PTE_VALID | I810_PTE_LOCAL), .type = AGP_DCACHE_MEMORY},
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100158 {.mask = I810_PTE_VALID, .type = 0},
159 {.mask = I810_PTE_VALID | I830_PTE_SYSTEM_CACHED,
160 .type = INTEL_AGP_CACHED_MEMORY}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161};
162
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800163static struct _intel_private {
164 struct pci_dev *pcidev; /* device one */
165 u8 __iomem *registers;
166 u32 __iomem *gtt; /* I915G */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 int num_dcache_entries;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800168 /* gtt_entries is the number of gtt entries that are already mapped
169 * to stolen memory. Stolen memory is larger than the memory mapped
170 * through gtt_entries, as it includes some reserved space for the BIOS
171 * popup and for the GTT.
172 */
173 int gtt_entries; /* i830+ */
Dave Airlie2162e6a2007-11-21 16:36:31 +1000174 union {
175 void __iomem *i9xx_flush_page;
176 void *i8xx_flush_page;
177 };
178 struct page *i8xx_page;
Dave Airlie6c00a612007-10-29 18:06:10 +1000179 struct resource ifp_resource;
Dave Airlie4d64dd92008-01-23 15:34:29 +1000180 int resource_valid;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800181} intel_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Zhenyu Wang17661682009-07-27 12:59:57 +0100183#ifdef USE_PCI_DMA_API
David Woodhousec2980d82009-07-29 08:39:26 +0100184static int intel_agp_map_page(struct page *page, dma_addr_t *ret)
Zhenyu Wang17661682009-07-27 12:59:57 +0100185{
David Woodhousec2980d82009-07-29 08:39:26 +0100186 *ret = pci_map_page(intel_private.pcidev, page, 0,
187 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
Zhenyu Wang17661682009-07-27 12:59:57 +0100188 if (pci_dma_mapping_error(intel_private.pcidev, *ret))
189 return -EINVAL;
190 return 0;
191}
192
David Woodhousec2980d82009-07-29 08:39:26 +0100193static void intel_agp_unmap_page(struct page *page, dma_addr_t dma)
Zhenyu Wang17661682009-07-27 12:59:57 +0100194{
David Woodhousec2980d82009-07-29 08:39:26 +0100195 pci_unmap_page(intel_private.pcidev, dma,
196 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
Zhenyu Wang17661682009-07-27 12:59:57 +0100197}
198
David Woodhouse91b8e302009-07-29 08:49:12 +0100199static void intel_agp_free_sglist(struct agp_memory *mem)
200{
David Woodhousef6927752009-07-29 09:28:45 +0100201 struct sg_table st;
David Woodhouse91b8e302009-07-29 08:49:12 +0100202
David Woodhousef6927752009-07-29 09:28:45 +0100203 st.sgl = mem->sg_list;
204 st.orig_nents = st.nents = mem->page_count;
205
206 sg_free_table(&st);
207
David Woodhouse91b8e302009-07-29 08:49:12 +0100208 mem->sg_list = NULL;
209 mem->num_sg = 0;
210}
211
Zhenyu Wang17661682009-07-27 12:59:57 +0100212static int intel_agp_map_memory(struct agp_memory *mem)
213{
David Woodhousef6927752009-07-29 09:28:45 +0100214 struct sg_table st;
Zhenyu Wang17661682009-07-27 12:59:57 +0100215 struct scatterlist *sg;
216 int i;
217
218 DBG("try mapping %lu pages\n", (unsigned long)mem->page_count);
219
David Woodhousef6927752009-07-29 09:28:45 +0100220 if (sg_alloc_table(&st, mem->page_count, GFP_KERNEL))
Zhenyu Wang17661682009-07-27 12:59:57 +0100221 return -ENOMEM;
Zhenyu Wang17661682009-07-27 12:59:57 +0100222
David Woodhousef6927752009-07-29 09:28:45 +0100223 mem->sg_list = sg = st.sgl;
224
Zhenyu Wang17661682009-07-27 12:59:57 +0100225 for (i = 0 ; i < mem->page_count; i++, sg = sg_next(sg))
226 sg_set_page(sg, mem->pages[i], PAGE_SIZE, 0);
227
228 mem->num_sg = pci_map_sg(intel_private.pcidev, mem->sg_list,
229 mem->page_count, PCI_DMA_BIDIRECTIONAL);
David Woodhouse91b8e302009-07-29 08:49:12 +0100230 if (unlikely(!mem->num_sg)) {
231 intel_agp_free_sglist(mem);
Zhenyu Wang17661682009-07-27 12:59:57 +0100232 return -ENOMEM;
233 }
234 return 0;
235}
236
237static void intel_agp_unmap_memory(struct agp_memory *mem)
238{
239 DBG("try unmapping %lu pages\n", (unsigned long)mem->page_count);
240
241 pci_unmap_sg(intel_private.pcidev, mem->sg_list,
242 mem->page_count, PCI_DMA_BIDIRECTIONAL);
David Woodhouse91b8e302009-07-29 08:49:12 +0100243 intel_agp_free_sglist(mem);
Zhenyu Wang17661682009-07-27 12:59:57 +0100244}
245
246static void intel_agp_insert_sg_entries(struct agp_memory *mem,
247 off_t pg_start, int mask_type)
248{
249 struct scatterlist *sg;
250 int i, j;
251
252 j = pg_start;
253
254 WARN_ON(!mem->num_sg);
255
256 if (mem->num_sg == mem->page_count) {
257 for_each_sg(mem->sg_list, sg, mem->page_count, i) {
258 writel(agp_bridge->driver->mask_memory(agp_bridge,
259 sg_dma_address(sg), mask_type),
260 intel_private.gtt+j);
261 j++;
262 }
263 } else {
264 /* sg may merge pages, but we have to seperate
265 * per-page addr for GTT */
266 unsigned int len, m;
267
268 for_each_sg(mem->sg_list, sg, mem->num_sg, i) {
269 len = sg_dma_len(sg) / PAGE_SIZE;
270 for (m = 0; m < len; m++) {
271 writel(agp_bridge->driver->mask_memory(agp_bridge,
272 sg_dma_address(sg) + m * PAGE_SIZE,
273 mask_type),
274 intel_private.gtt+j);
275 j++;
276 }
277 }
278 }
279 readl(intel_private.gtt+j-1);
280}
281
282#else
283
284static void intel_agp_insert_sg_entries(struct agp_memory *mem,
285 off_t pg_start, int mask_type)
286{
287 int i, j;
288
289 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
290 writel(agp_bridge->driver->mask_memory(agp_bridge,
David Woodhouse6a122352009-07-29 10:25:58 +0100291 page_to_phys(mem->pages[i]), mask_type),
Zhenyu Wang17661682009-07-27 12:59:57 +0100292 intel_private.gtt+j);
293 }
294
295 readl(intel_private.gtt+j-1);
296}
297
298#endif
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300static int intel_i810_fetch_size(void)
301{
302 u32 smram_miscc;
303 struct aper_size_info_fixed *values;
304
305 pci_read_config_dword(agp_bridge->dev, I810_SMRAM_MISCC, &smram_miscc);
306 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
307
308 if ((smram_miscc & I810_GMS) == I810_GMS_DISABLE) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700309 dev_warn(&agp_bridge->dev->dev, "i810 is disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return 0;
311 }
312 if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) {
313 agp_bridge->previous_size =
314 agp_bridge->current_size = (void *) (values + 1);
315 agp_bridge->aperture_size_idx = 1;
316 return values[1].size;
317 } else {
318 agp_bridge->previous_size =
319 agp_bridge->current_size = (void *) (values);
320 agp_bridge->aperture_size_idx = 0;
321 return values[0].size;
322 }
323
324 return 0;
325}
326
327static int intel_i810_configure(void)
328{
329 struct aper_size_info_fixed *current_size;
330 u32 temp;
331 int i;
332
333 current_size = A_SIZE_FIX(agp_bridge->current_size);
334
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800335 if (!intel_private.registers) {
336 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
Dave Jonese4ac5e42007-02-04 17:37:42 -0500337 temp &= 0xfff80000;
338
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800339 intel_private.registers = ioremap(temp, 128 * 4096);
340 if (!intel_private.registers) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700341 dev_err(&intel_private.pcidev->dev,
342 "can't remap memory\n");
Dave Jonese4ac5e42007-02-04 17:37:42 -0500343 return -ENOMEM;
344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800347 if ((readl(intel_private.registers+I810_DRAM_CTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) {
349 /* This will need to be dynamically assigned */
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700350 dev_info(&intel_private.pcidev->dev,
351 "detected 4MB dedicated video ram\n");
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800352 intel_private.num_dcache_entries = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800354 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800356 writel(agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
357 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 if (agp_bridge->driver->needs_scratch_page) {
360 for (i = 0; i < current_size->num_entries; i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800361 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
Keith Packard44d49442008-10-14 17:18:45 -0700363 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 }
365 global_cache_flush();
366 return 0;
367}
368
369static void intel_i810_cleanup(void)
370{
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800371 writel(0, intel_private.registers+I810_PGETBL_CTL);
372 readl(intel_private.registers); /* PCI Posting. */
373 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374}
375
376static void intel_i810_tlbflush(struct agp_memory *mem)
377{
378 return;
379}
380
381static void intel_i810_agp_enable(struct agp_bridge_data *bridge, u32 mode)
382{
383 return;
384}
385
386/* Exists to support ARGB cursors */
Dave Airlie07613ba2009-06-12 14:11:41 +1000387static struct page *i8xx_alloc_pages(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
Dave Airlief011ae72008-01-25 11:23:04 +1000389 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Linus Torvalds66c669b2006-11-22 14:55:29 -0800391 page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 if (page == NULL)
393 return NULL;
394
Arjan van de Ven6d238cc2008-01-30 13:34:06 +0100395 if (set_pages_uc(page, 4) < 0) {
396 set_pages_wb(page, 4);
Jan Beulich89cf7cc2007-04-02 14:50:14 +0100397 __free_pages(page, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return NULL;
399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 get_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 atomic_inc(&agp_bridge->current_memory_agp);
Dave Airlie07613ba2009-06-12 14:11:41 +1000402 return page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403}
404
Dave Airlie07613ba2009-06-12 14:11:41 +1000405static void i8xx_destroy_pages(struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Dave Airlie07613ba2009-06-12 14:11:41 +1000407 if (page == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 return;
409
Arjan van de Ven6d238cc2008-01-30 13:34:06 +0100410 set_pages_wb(page, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 put_page(page);
Jan Beulich89cf7cc2007-04-02 14:50:14 +0100412 __free_pages(page, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 atomic_dec(&agp_bridge->current_memory_agp);
414}
415
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100416static int intel_i830_type_to_mask_type(struct agp_bridge_data *bridge,
417 int type)
418{
419 if (type < AGP_USER_TYPES)
420 return type;
421 else if (type == AGP_USER_CACHED_MEMORY)
422 return INTEL_AGP_CACHED_MEMORY;
423 else
424 return 0;
425}
426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
428 int type)
429{
430 int i, j, num_entries;
431 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100432 int ret = -EINVAL;
433 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +0100435 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100436 goto out;
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +0100437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 temp = agp_bridge->current_size;
439 num_entries = A_SIZE_FIX(temp)->num_entries;
440
Dave Jones6a92a4e2006-02-28 00:54:25 -0500441 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100442 goto out_err;
443
Dave Jones6a92a4e2006-02-28 00:54:25 -0500444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 for (j = pg_start; j < (pg_start + mem->page_count); j++) {
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100446 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j))) {
447 ret = -EBUSY;
448 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 }
451
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100452 if (type != mem->type)
453 goto out_err;
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +0100454
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100455 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
456
457 switch (mask_type) {
458 case AGP_DCACHE_MEMORY:
459 if (!mem->is_flushed)
460 global_cache_flush();
461 for (i = pg_start; i < (pg_start + mem->page_count); i++) {
462 writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID,
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800463 intel_private.registers+I810_PTE_BASE+(i*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100464 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800465 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100466 break;
467 case AGP_PHYS_MEMORY:
468 case AGP_NORMAL_MEMORY:
469 if (!mem->is_flushed)
470 global_cache_flush();
471 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
472 writel(agp_bridge->driver->mask_memory(agp_bridge,
David Woodhouse6a122352009-07-29 10:25:58 +0100473 page_to_phys(mem->pages[i]), mask_type),
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800474 intel_private.registers+I810_PTE_BASE+(j*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100475 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800476 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100477 break;
478 default:
479 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100483out:
484 ret = 0;
485out_err:
Dave Airlie9516b032008-06-19 10:42:17 +1000486 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100487 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488}
489
490static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
491 int type)
492{
493 int i;
494
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +0100495 if (mem->page_count == 0)
496 return 0;
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800499 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800501 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 agp_bridge->driver->tlb_flush(mem);
504 return 0;
505}
506
507/*
508 * The i810/i830 requires a physical address to program its mouse
509 * pointer into hardware.
510 * However the Xserver still writes to it through the agp aperture.
511 */
512static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
513{
514 struct agp_memory *new;
Dave Airlie07613ba2009-06-12 14:11:41 +1000515 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 switch (pg_count) {
Dave Airlie07613ba2009-06-12 14:11:41 +1000518 case 1: page = agp_bridge->driver->agp_alloc_page(agp_bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 break;
520 case 4:
521 /* kludge to get 4 physical pages for ARGB cursor */
Dave Airlie07613ba2009-06-12 14:11:41 +1000522 page = i8xx_alloc_pages();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 break;
524 default:
525 return NULL;
526 }
527
Dave Airlie07613ba2009-06-12 14:11:41 +1000528 if (page == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 return NULL;
530
531 new = agp_create_memory(pg_count);
532 if (new == NULL)
533 return NULL;
534
Dave Airlie07613ba2009-06-12 14:11:41 +1000535 new->pages[0] = page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (pg_count == 4) {
537 /* kludge to get 4 physical pages for ARGB cursor */
Dave Airlie07613ba2009-06-12 14:11:41 +1000538 new->pages[1] = new->pages[0] + 1;
539 new->pages[2] = new->pages[1] + 1;
540 new->pages[3] = new->pages[2] + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 }
542 new->page_count = pg_count;
543 new->num_scratch_pages = pg_count;
544 new->type = AGP_PHYS_MEMORY;
Dave Airlie07613ba2009-06-12 14:11:41 +1000545 new->physical = page_to_phys(new->pages[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return new;
547}
548
549static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type)
550{
551 struct agp_memory *new;
552
553 if (type == AGP_DCACHE_MEMORY) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800554 if (pg_count != intel_private.num_dcache_entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return NULL;
556
557 new = agp_create_memory(1);
558 if (new == NULL)
559 return NULL;
560
561 new->type = AGP_DCACHE_MEMORY;
562 new->page_count = pg_count;
563 new->num_scratch_pages = 0;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100564 agp_free_page_array(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 return new;
566 }
567 if (type == AGP_PHYS_MEMORY)
568 return alloc_agpphysmem_i8xx(pg_count, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 return NULL;
570}
571
572static void intel_i810_free_by_type(struct agp_memory *curr)
573{
574 agp_free_key(curr->key);
Dave Jones6a92a4e2006-02-28 00:54:25 -0500575 if (curr->type == AGP_PHYS_MEMORY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 if (curr->page_count == 4)
Dave Airlie07613ba2009-06-12 14:11:41 +1000577 i8xx_destroy_pages(curr->pages[0]);
Alan Hourihane88d51962005-11-06 23:35:34 -0800578 else {
Dave Airlie07613ba2009-06-12 14:11:41 +1000579 agp_bridge->driver->agp_destroy_page(curr->pages[0],
Dave Airliea2721e92007-10-15 10:19:16 +1000580 AGP_PAGE_DESTROY_UNMAP);
Dave Airlie07613ba2009-06-12 14:11:41 +1000581 agp_bridge->driver->agp_destroy_page(curr->pages[0],
Dave Airliea2721e92007-10-15 10:19:16 +1000582 AGP_PAGE_DESTROY_FREE);
Alan Hourihane88d51962005-11-06 23:35:34 -0800583 }
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100584 agp_free_page_array(curr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586 kfree(curr);
587}
588
589static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge,
David Woodhouse2a4ceb62009-07-27 10:27:29 +0100590 dma_addr_t addr, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
592 /* Type checking must be done elsewhere */
593 return addr | bridge->driver->masks[type].mask;
594}
595
596static struct aper_size_info_fixed intel_i830_sizes[] =
597{
598 {128, 32768, 5},
599 /* The 64M mode still requires a 128k gatt */
600 {64, 16384, 5},
601 {256, 65536, 6},
Eric Anholt65c25aa2006-09-06 11:57:18 -0400602 {512, 131072, 7},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603};
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605static void intel_i830_init_gtt_entries(void)
606{
607 u16 gmch_ctrl;
608 int gtt_entries;
609 u8 rdct;
610 int local = 0;
611 static const int ddt[4] = { 0, 16, 32, 64 };
Eric Anholtc41e0de2006-12-19 12:57:24 -0800612 int size; /* reserved space (in kb) at the top of stolen memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Dave Airlief011ae72008-01-25 11:23:04 +1000614 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Eric Anholtc41e0de2006-12-19 12:57:24 -0800616 if (IS_I965) {
617 u32 pgetbl_ctl;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800618 pgetbl_ctl = readl(intel_private.registers+I810_PGETBL_CTL);
Eric Anholtc41e0de2006-12-19 12:57:24 -0800619
Eric Anholtc41e0de2006-12-19 12:57:24 -0800620 /* The 965 has a field telling us the size of the GTT,
621 * which may be larger than what is necessary to map the
622 * aperture.
623 */
624 switch (pgetbl_ctl & I965_PGETBL_SIZE_MASK) {
625 case I965_PGETBL_SIZE_128KB:
626 size = 128;
627 break;
628 case I965_PGETBL_SIZE_256KB:
629 size = 256;
630 break;
631 case I965_PGETBL_SIZE_512KB:
632 size = 512;
633 break;
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +1000634 case I965_PGETBL_SIZE_1MB:
635 size = 1024;
636 break;
637 case I965_PGETBL_SIZE_2MB:
638 size = 2048;
639 break;
640 case I965_PGETBL_SIZE_1_5MB:
641 size = 1024 + 512;
642 break;
Eric Anholtc41e0de2006-12-19 12:57:24 -0800643 default:
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700644 dev_info(&intel_private.pcidev->dev,
645 "unknown page table size, assuming 512KB\n");
Eric Anholtc41e0de2006-12-19 12:57:24 -0800646 size = 512;
647 }
648 size += 4; /* add in BIOS popup space */
Shaohua Li21778322009-02-23 15:19:16 +0800649 } else if (IS_G33 && !IS_IGD) {
Wang Zhenyu874808c62007-06-06 11:16:25 +0800650 /* G33's GTT size defined in gmch_ctrl */
651 switch (gmch_ctrl & G33_PGETBL_SIZE_MASK) {
652 case G33_PGETBL_SIZE_1M:
653 size = 1024;
654 break;
655 case G33_PGETBL_SIZE_2M:
656 size = 2048;
657 break;
658 default:
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700659 dev_info(&agp_bridge->dev->dev,
660 "unknown page table size 0x%x, assuming 512KB\n",
Wang Zhenyu874808c62007-06-06 11:16:25 +0800661 (gmch_ctrl & G33_PGETBL_SIZE_MASK));
662 size = 512;
663 }
664 size += 4;
Shaohua Li21778322009-02-23 15:19:16 +0800665 } else if (IS_G4X || IS_IGD) {
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000666 /* On 4 series hardware, GTT stolen is separate from graphics
Eric Anholt82e14a62008-10-14 11:28:58 -0700667 * stolen, ignore it in stolen gtt entries counting. However,
668 * 4KB of the stolen memory doesn't get mapped to the GTT.
669 */
670 size = 4;
Eric Anholtc41e0de2006-12-19 12:57:24 -0800671 } else {
672 /* On previous hardware, the GTT size was just what was
673 * required to map the aperture.
674 */
675 size = agp_bridge->driver->fetch_size() + 4;
676 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
679 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
680 switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
681 case I830_GMCH_GMS_STOLEN_512:
682 gtt_entries = KB(512) - KB(size);
683 break;
684 case I830_GMCH_GMS_STOLEN_1024:
685 gtt_entries = MB(1) - KB(size);
686 break;
687 case I830_GMCH_GMS_STOLEN_8192:
688 gtt_entries = MB(8) - KB(size);
689 break;
690 case I830_GMCH_GMS_LOCAL:
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800691 rdct = readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 gtt_entries = (I830_RDRAM_ND(rdct) + 1) *
693 MB(ddt[I830_RDRAM_DDT(rdct)]);
694 local = 1;
695 break;
696 default:
697 gtt_entries = 0;
698 break;
699 }
700 } else {
Dave Airliee67aa272007-09-18 22:46:35 -0700701 switch (gmch_ctrl & I855_GMCH_GMS_MASK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 case I855_GMCH_GMS_STOLEN_1M:
703 gtt_entries = MB(1) - KB(size);
704 break;
705 case I855_GMCH_GMS_STOLEN_4M:
706 gtt_entries = MB(4) - KB(size);
707 break;
708 case I855_GMCH_GMS_STOLEN_8M:
709 gtt_entries = MB(8) - KB(size);
710 break;
711 case I855_GMCH_GMS_STOLEN_16M:
712 gtt_entries = MB(16) - KB(size);
713 break;
714 case I855_GMCH_GMS_STOLEN_32M:
715 gtt_entries = MB(32) - KB(size);
716 break;
717 case I915_GMCH_GMS_STOLEN_48M:
718 /* Check it's really I915G */
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000719 if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 gtt_entries = MB(48) - KB(size);
721 else
722 gtt_entries = 0;
723 break;
724 case I915_GMCH_GMS_STOLEN_64M:
725 /* Check it's really I915G */
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000726 if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 gtt_entries = MB(64) - KB(size);
728 else
729 gtt_entries = 0;
Wang Zhenyu874808c62007-06-06 11:16:25 +0800730 break;
731 case G33_GMCH_GMS_STOLEN_128M:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000732 if (IS_G33 || IS_I965 || IS_G4X)
Wang Zhenyu874808c62007-06-06 11:16:25 +0800733 gtt_entries = MB(128) - KB(size);
734 else
735 gtt_entries = 0;
736 break;
737 case G33_GMCH_GMS_STOLEN_256M:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000738 if (IS_G33 || IS_I965 || IS_G4X)
Wang Zhenyu874808c62007-06-06 11:16:25 +0800739 gtt_entries = MB(256) - KB(size);
740 else
741 gtt_entries = 0;
742 break;
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000743 case INTEL_GMCH_GMS_STOLEN_96M:
744 if (IS_I965 || IS_G4X)
745 gtt_entries = MB(96) - KB(size);
746 else
747 gtt_entries = 0;
748 break;
749 case INTEL_GMCH_GMS_STOLEN_160M:
750 if (IS_I965 || IS_G4X)
751 gtt_entries = MB(160) - KB(size);
752 else
753 gtt_entries = 0;
754 break;
755 case INTEL_GMCH_GMS_STOLEN_224M:
756 if (IS_I965 || IS_G4X)
757 gtt_entries = MB(224) - KB(size);
758 else
759 gtt_entries = 0;
760 break;
761 case INTEL_GMCH_GMS_STOLEN_352M:
762 if (IS_I965 || IS_G4X)
763 gtt_entries = MB(352) - KB(size);
764 else
765 gtt_entries = 0;
766 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 default:
768 gtt_entries = 0;
769 break;
770 }
771 }
Lubomir Rintel9c1e8a42009-03-10 12:55:54 -0700772 if (gtt_entries > 0) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700773 dev_info(&agp_bridge->dev->dev, "detected %dK %s memory\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 gtt_entries / KB(1), local ? "local" : "stolen");
Lubomir Rintel9c1e8a42009-03-10 12:55:54 -0700775 gtt_entries /= KB(4);
776 } else {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700777 dev_info(&agp_bridge->dev->dev,
778 "no pre-allocated video memory detected\n");
Lubomir Rintel9c1e8a42009-03-10 12:55:54 -0700779 gtt_entries = 0;
780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800782 intel_private.gtt_entries = gtt_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783}
784
Dave Airlie2162e6a2007-11-21 16:36:31 +1000785static void intel_i830_fini_flush(void)
786{
787 kunmap(intel_private.i8xx_page);
788 intel_private.i8xx_flush_page = NULL;
789 unmap_page_from_agp(intel_private.i8xx_page);
Dave Airlie2162e6a2007-11-21 16:36:31 +1000790
791 __free_page(intel_private.i8xx_page);
Dave Airlie4d64dd92008-01-23 15:34:29 +1000792 intel_private.i8xx_page = NULL;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000793}
794
795static void intel_i830_setup_flush(void)
796{
Dave Airlie4d64dd92008-01-23 15:34:29 +1000797 /* return if we've already set the flush mechanism up */
798 if (intel_private.i8xx_page)
799 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000800
801 intel_private.i8xx_page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
Dave Airlief011ae72008-01-25 11:23:04 +1000802 if (!intel_private.i8xx_page)
Dave Airlie2162e6a2007-11-21 16:36:31 +1000803 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000804
805 /* make page uncached */
806 map_page_into_agp(intel_private.i8xx_page);
Dave Airlie2162e6a2007-11-21 16:36:31 +1000807
808 intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page);
809 if (!intel_private.i8xx_flush_page)
810 intel_i830_fini_flush();
811}
812
813static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
814{
815 unsigned int *pg = intel_private.i8xx_flush_page;
816 int i;
817
Dave Airlief011ae72008-01-25 11:23:04 +1000818 for (i = 0; i < 256; i += 2)
Dave Airlie2162e6a2007-11-21 16:36:31 +1000819 *(pg + i) = i;
Dave Airlief011ae72008-01-25 11:23:04 +1000820
Dave Airlie2162e6a2007-11-21 16:36:31 +1000821 wmb();
822}
823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824/* The intel i830 automatically initializes the agp aperture during POST.
825 * Use the memory already set aside for in the GTT.
826 */
827static int intel_i830_create_gatt_table(struct agp_bridge_data *bridge)
828{
829 int page_order;
830 struct aper_size_info_fixed *size;
831 int num_entries;
832 u32 temp;
833
834 size = agp_bridge->current_size;
835 page_order = size->page_order;
836 num_entries = size->num_entries;
837 agp_bridge->gatt_table_real = NULL;
838
Dave Airlief011ae72008-01-25 11:23:04 +1000839 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 temp &= 0xfff80000;
841
Dave Airlief011ae72008-01-25 11:23:04 +1000842 intel_private.registers = ioremap(temp, 128 * 4096);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800843 if (!intel_private.registers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 return -ENOMEM;
845
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800846 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 global_cache_flush(); /* FIXME: ?? */
848
849 /* we have to call this as early as possible after the MMIO base address is known */
850 intel_i830_init_gtt_entries();
851
852 agp_bridge->gatt_table = NULL;
853
854 agp_bridge->gatt_bus_addr = temp;
855
856 return 0;
857}
858
859/* Return the gatt table to a sane state. Use the top of stolen
860 * memory for the GTT.
861 */
862static int intel_i830_free_gatt_table(struct agp_bridge_data *bridge)
863{
864 return 0;
865}
866
867static int intel_i830_fetch_size(void)
868{
869 u16 gmch_ctrl;
870 struct aper_size_info_fixed *values;
871
872 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
873
874 if (agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82830_HB &&
875 agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82845G_HB) {
876 /* 855GM/852GM/865G has 128MB aperture size */
877 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
878 agp_bridge->aperture_size_idx = 0;
879 return values[0].size;
880 }
881
Dave Airlief011ae72008-01-25 11:23:04 +1000882 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
884 if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
885 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
886 agp_bridge->aperture_size_idx = 0;
887 return values[0].size;
888 } else {
889 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + 1);
890 agp_bridge->aperture_size_idx = 1;
891 return values[1].size;
892 }
893
894 return 0;
895}
896
897static int intel_i830_configure(void)
898{
899 struct aper_size_info_fixed *current_size;
900 u32 temp;
901 u16 gmch_ctrl;
902 int i;
903
904 current_size = A_SIZE_FIX(agp_bridge->current_size);
905
Dave Airlief011ae72008-01-25 11:23:04 +1000906 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
908
Dave Airlief011ae72008-01-25 11:23:04 +1000909 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 gmch_ctrl |= I830_GMCH_ENABLED;
Dave Airlief011ae72008-01-25 11:23:04 +1000911 pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800913 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
914 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 if (agp_bridge->driver->needs_scratch_page) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800917 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
918 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
Keith Packard44d49442008-10-14 17:18:45 -0700920 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 }
922
923 global_cache_flush();
Dave Airlie2162e6a2007-11-21 16:36:31 +1000924
925 intel_i830_setup_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 return 0;
927}
928
929static void intel_i830_cleanup(void)
930{
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800931 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
933
Dave Airlief011ae72008-01-25 11:23:04 +1000934static int intel_i830_insert_entries(struct agp_memory *mem, off_t pg_start,
935 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
Dave Airlief011ae72008-01-25 11:23:04 +1000937 int i, j, num_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100939 int ret = -EINVAL;
940 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +0100942 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100943 goto out;
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +0100944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 temp = agp_bridge->current_size;
946 num_entries = A_SIZE_FIX(temp)->num_entries;
947
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800948 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700949 dev_printk(KERN_DEBUG, &intel_private.pcidev->dev,
950 "pg_start == 0x%.8lx, intel_private.gtt_entries == 0x%.8x\n",
951 pg_start, intel_private.gtt_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700953 dev_info(&intel_private.pcidev->dev,
954 "trying to insert into local/stolen memory\n");
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100955 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 }
957
958 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100959 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 /* The i830 can't check the GTT for entries since its read only,
962 * depend on the caller to make the correct offset decisions.
963 */
964
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100965 if (type != mem->type)
966 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100968 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
969
970 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
971 mask_type != INTEL_AGP_CACHED_MEMORY)
972 goto out_err;
973
974 if (!mem->is_flushed)
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +0100975 global_cache_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
978 writel(agp_bridge->driver->mask_memory(agp_bridge,
David Woodhouse6a122352009-07-29 10:25:58 +0100979 page_to_phys(mem->pages[i]), mask_type),
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800980 intel_private.registers+I810_PTE_BASE+(j*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800982 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100984
985out:
986 ret = 0;
987out_err:
Dave Airlie9516b032008-06-19 10:42:17 +1000988 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100989 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990}
991
Dave Airlief011ae72008-01-25 11:23:04 +1000992static int intel_i830_remove_entries(struct agp_memory *mem, off_t pg_start,
993 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
995 int i;
996
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +0100997 if (mem->page_count == 0)
998 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001000 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001001 dev_info(&intel_private.pcidev->dev,
1002 "trying to disable local/stolen memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 return -EINVAL;
1004 }
1005
1006 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001007 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001009 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 agp_bridge->driver->tlb_flush(mem);
1012 return 0;
1013}
1014
Dave Airlief011ae72008-01-25 11:23:04 +10001015static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
1017 if (type == AGP_PHYS_MEMORY)
1018 return alloc_agpphysmem_i8xx(pg_count, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 /* always return NULL for other allocation types for now */
1020 return NULL;
1021}
1022
Dave Airlie6c00a612007-10-29 18:06:10 +10001023static int intel_alloc_chipset_flush_resource(void)
1024{
1025 int ret;
1026 ret = pci_bus_alloc_resource(agp_bridge->dev->bus, &intel_private.ifp_resource, PAGE_SIZE,
1027 PAGE_SIZE, PCIBIOS_MIN_MEM, 0,
1028 pcibios_align_resource, agp_bridge->dev);
Dave Airlie6c00a612007-10-29 18:06:10 +10001029
Dave Airlie2162e6a2007-11-21 16:36:31 +10001030 return ret;
Dave Airlie6c00a612007-10-29 18:06:10 +10001031}
1032
1033static void intel_i915_setup_chipset_flush(void)
1034{
1035 int ret;
1036 u32 temp;
1037
1038 pci_read_config_dword(agp_bridge->dev, I915_IFPADDR, &temp);
1039 if (!(temp & 0x1)) {
1040 intel_alloc_chipset_flush_resource();
Dave Airlie4d64dd92008-01-23 15:34:29 +10001041 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +10001042 pci_write_config_dword(agp_bridge->dev, I915_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
1043 } else {
1044 temp &= ~1;
1045
Dave Airlie4d64dd92008-01-23 15:34:29 +10001046 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +10001047 intel_private.ifp_resource.start = temp;
1048 intel_private.ifp_resource.end = temp + PAGE_SIZE;
1049 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
Dave Airlie4d64dd92008-01-23 15:34:29 +10001050 /* some BIOSes reserve this area in a pnp some don't */
1051 if (ret)
1052 intel_private.resource_valid = 0;
Dave Airlie6c00a612007-10-29 18:06:10 +10001053 }
1054}
1055
1056static void intel_i965_g33_setup_chipset_flush(void)
1057{
1058 u32 temp_hi, temp_lo;
1059 int ret;
1060
1061 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR + 4, &temp_hi);
1062 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR, &temp_lo);
1063
1064 if (!(temp_lo & 0x1)) {
1065
1066 intel_alloc_chipset_flush_resource();
1067
Dave Airlie4d64dd92008-01-23 15:34:29 +10001068 intel_private.resource_valid = 1;
Andrew Morton1fa4db72007-11-29 10:00:48 +10001069 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR + 4,
1070 upper_32_bits(intel_private.ifp_resource.start));
Dave Airlie6c00a612007-10-29 18:06:10 +10001071 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
Dave Airlie6c00a612007-10-29 18:06:10 +10001072 } else {
1073 u64 l64;
Dave Airlief011ae72008-01-25 11:23:04 +10001074
Dave Airlie6c00a612007-10-29 18:06:10 +10001075 temp_lo &= ~0x1;
1076 l64 = ((u64)temp_hi << 32) | temp_lo;
1077
Dave Airlie4d64dd92008-01-23 15:34:29 +10001078 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +10001079 intel_private.ifp_resource.start = l64;
1080 intel_private.ifp_resource.end = l64 + PAGE_SIZE;
1081 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
Dave Airlie4d64dd92008-01-23 15:34:29 +10001082 /* some BIOSes reserve this area in a pnp some don't */
1083 if (ret)
1084 intel_private.resource_valid = 0;
Dave Airlie6c00a612007-10-29 18:06:10 +10001085 }
1086}
1087
Dave Airlie2162e6a2007-11-21 16:36:31 +10001088static void intel_i9xx_setup_flush(void)
1089{
Dave Airlie4d64dd92008-01-23 15:34:29 +10001090 /* return if already configured */
1091 if (intel_private.ifp_resource.start)
1092 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +10001093
Dave Airlie4d64dd92008-01-23 15:34:29 +10001094 /* setup a resource for this object */
Dave Airlie2162e6a2007-11-21 16:36:31 +10001095 intel_private.ifp_resource.name = "Intel Flush Page";
1096 intel_private.ifp_resource.flags = IORESOURCE_MEM;
1097
1098 /* Setup chipset flush for 915 */
Zhenyu Wang7d15ddf2008-06-20 11:48:06 +10001099 if (IS_I965 || IS_G33 || IS_G4X) {
Dave Airlie2162e6a2007-11-21 16:36:31 +10001100 intel_i965_g33_setup_chipset_flush();
1101 } else {
1102 intel_i915_setup_chipset_flush();
1103 }
1104
1105 if (intel_private.ifp_resource.start) {
1106 intel_private.i9xx_flush_page = ioremap_nocache(intel_private.ifp_resource.start, PAGE_SIZE);
1107 if (!intel_private.i9xx_flush_page)
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001108 dev_info(&intel_private.pcidev->dev, "can't ioremap flush page - no chipset flushing");
Dave Airlie2162e6a2007-11-21 16:36:31 +10001109 }
1110}
1111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112static int intel_i915_configure(void)
1113{
1114 struct aper_size_info_fixed *current_size;
1115 u32 temp;
1116 u16 gmch_ctrl;
1117 int i;
1118
1119 current_size = A_SIZE_FIX(agp_bridge->current_size);
1120
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001121 pci_read_config_dword(intel_private.pcidev, I915_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1124
Dave Airlief011ae72008-01-25 11:23:04 +10001125 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 gmch_ctrl |= I830_GMCH_ENABLED;
Dave Airlief011ae72008-01-25 11:23:04 +10001127 pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001129 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
1130 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
1132 if (agp_bridge->driver->needs_scratch_page) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001133 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
David Woodhouse56ec4c12009-07-27 16:44:32 +01001134 writel(agp_bridge->scratch_page, intel_private.gtt+i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 }
Keith Packard44d49442008-10-14 17:18:45 -07001136 readl(intel_private.gtt+i-1); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 }
1138
1139 global_cache_flush();
Dave Airlie6c00a612007-10-29 18:06:10 +10001140
Dave Airlie2162e6a2007-11-21 16:36:31 +10001141 intel_i9xx_setup_flush();
Dave Airlief011ae72008-01-25 11:23:04 +10001142
David Woodhouseba3139f2009-08-05 08:12:40 +01001143#ifdef USE_PCI_DMA_API
1144 if (pci_set_dma_mask(intel_private.pcidev, DMA_BIT_MASK(36)))
1145 dev_err(&intel_private.pcidev->dev,
1146 "set gfx device dma mask 36bit failed!\n");
1147#endif
1148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 return 0;
1150}
1151
1152static void intel_i915_cleanup(void)
1153{
Dave Airlie2162e6a2007-11-21 16:36:31 +10001154 if (intel_private.i9xx_flush_page)
1155 iounmap(intel_private.i9xx_flush_page);
Dave Airlie4d64dd92008-01-23 15:34:29 +10001156 if (intel_private.resource_valid)
1157 release_resource(&intel_private.ifp_resource);
1158 intel_private.ifp_resource.start = 0;
1159 intel_private.resource_valid = 0;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001160 iounmap(intel_private.gtt);
1161 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162}
1163
Dave Airlie6c00a612007-10-29 18:06:10 +10001164static void intel_i915_chipset_flush(struct agp_bridge_data *bridge)
1165{
Dave Airlie2162e6a2007-11-21 16:36:31 +10001166 if (intel_private.i9xx_flush_page)
1167 writel(1, intel_private.i9xx_flush_page);
Dave Airlie6c00a612007-10-29 18:06:10 +10001168}
1169
Dave Airlief011ae72008-01-25 11:23:04 +10001170static int intel_i915_insert_entries(struct agp_memory *mem, off_t pg_start,
1171 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Zhenyu Wang17661682009-07-27 12:59:57 +01001173 int num_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001175 int ret = -EINVAL;
1176 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +01001178 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001179 goto out;
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +01001180
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 temp = agp_bridge->current_size;
1182 num_entries = A_SIZE_FIX(temp)->num_entries;
1183
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001184 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001185 dev_printk(KERN_DEBUG, &intel_private.pcidev->dev,
1186 "pg_start == 0x%.8lx, intel_private.gtt_entries == 0x%.8x\n",
1187 pg_start, intel_private.gtt_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001189 dev_info(&intel_private.pcidev->dev,
1190 "trying to insert into local/stolen memory\n");
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001191 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 }
1193
1194 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001195 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Zhenyu Wang17661682009-07-27 12:59:57 +01001197 /* The i915 can't check the GTT for entries since it's read only;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 * depend on the caller to make the correct offset decisions.
1199 */
1200
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001201 if (type != mem->type)
1202 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001204 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
1205
1206 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
1207 mask_type != INTEL_AGP_CACHED_MEMORY)
1208 goto out_err;
1209
1210 if (!mem->is_flushed)
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +01001211 global_cache_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Zhenyu Wang17661682009-07-27 12:59:57 +01001213 intel_agp_insert_sg_entries(mem, pg_start, mask_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001215
1216 out:
1217 ret = 0;
1218 out_err:
Dave Airlie9516b032008-06-19 10:42:17 +10001219 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001220 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
Dave Airlief011ae72008-01-25 11:23:04 +10001223static int intel_i915_remove_entries(struct agp_memory *mem, off_t pg_start,
1224 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225{
1226 int i;
1227
Thomas Hellstrom5aa80c722006-12-20 16:33:41 +01001228 if (mem->page_count == 0)
1229 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001231 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001232 dev_info(&intel_private.pcidev->dev,
1233 "trying to disable local/stolen memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 return -EINVAL;
1235 }
1236
Dave Airlief011ae72008-01-25 11:23:04 +10001237 for (i = pg_start; i < (mem->page_count + pg_start); i++)
David Woodhouse56ec4c12009-07-27 16:44:32 +01001238 writel(agp_bridge->scratch_page, intel_private.gtt+i);
Dave Airlief011ae72008-01-25 11:23:04 +10001239
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001240 readl(intel_private.gtt+i-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 agp_bridge->driver->tlb_flush(mem);
1243 return 0;
1244}
1245
Eric Anholtc41e0de2006-12-19 12:57:24 -08001246/* Return the aperture size by just checking the resource length. The effect
1247 * described in the spec of the MSAC registers is just changing of the
1248 * resource size.
1249 */
1250static int intel_i9xx_fetch_size(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
Ahmed S. Darwish1eaf1222007-02-06 18:08:28 +02001252 int num_sizes = ARRAY_SIZE(intel_i830_sizes);
Eric Anholtc41e0de2006-12-19 12:57:24 -08001253 int aper_size; /* size in megabytes */
1254 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001256 aper_size = pci_resource_len(intel_private.pcidev, 2) / MB(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Eric Anholtc41e0de2006-12-19 12:57:24 -08001258 for (i = 0; i < num_sizes; i++) {
1259 if (aper_size == intel_i830_sizes[i].size) {
1260 agp_bridge->current_size = intel_i830_sizes + i;
1261 agp_bridge->previous_size = agp_bridge->current_size;
1262 return aper_size;
1263 }
1264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Eric Anholtc41e0de2006-12-19 12:57:24 -08001266 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267}
1268
1269/* The intel i915 automatically initializes the agp aperture during POST.
1270 * Use the memory already set aside for in the GTT.
1271 */
1272static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
1273{
1274 int page_order;
1275 struct aper_size_info_fixed *size;
1276 int num_entries;
1277 u32 temp, temp2;
Zhenyu Wang47406222007-09-11 15:23:58 -07001278 int gtt_map_size = 256 * 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 size = agp_bridge->current_size;
1281 page_order = size->page_order;
1282 num_entries = size->num_entries;
1283 agp_bridge->gatt_table_real = NULL;
1284
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001285 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
Dave Airlief011ae72008-01-25 11:23:04 +10001286 pci_read_config_dword(intel_private.pcidev, I915_PTEADDR, &temp2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Zhenyu Wang47406222007-09-11 15:23:58 -07001288 if (IS_G33)
1289 gtt_map_size = 1024 * 1024; /* 1M on G33 */
1290 intel_private.gtt = ioremap(temp2, gtt_map_size);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001291 if (!intel_private.gtt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 return -ENOMEM;
1293
1294 temp &= 0xfff80000;
1295
Dave Airlief011ae72008-01-25 11:23:04 +10001296 intel_private.registers = ioremap(temp, 128 * 4096);
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001297 if (!intel_private.registers) {
1298 iounmap(intel_private.gtt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 return -ENOMEM;
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001302 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 global_cache_flush(); /* FIXME: ? */
1304
1305 /* we have to call this as early as possible after the MMIO base address is known */
1306 intel_i830_init_gtt_entries();
1307
1308 agp_bridge->gatt_table = NULL;
1309
1310 agp_bridge->gatt_bus_addr = temp;
1311
1312 return 0;
1313}
Linus Torvalds7d915a32006-11-22 09:37:54 -08001314
1315/*
1316 * The i965 supports 36-bit physical addresses, but to keep
1317 * the format of the GTT the same, the bits that don't fit
1318 * in a 32-bit word are shifted down to bits 4..7.
1319 *
1320 * Gcc is smart enough to notice that "(addr >> 28) & 0xf0"
1321 * is always zero on 32-bit architectures, so no need to make
1322 * this conditional.
1323 */
1324static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
David Woodhouse2a4ceb62009-07-27 10:27:29 +01001325 dma_addr_t addr, int type)
Linus Torvalds7d915a32006-11-22 09:37:54 -08001326{
1327 /* Shift high bits down */
1328 addr |= (addr >> 28) & 0xf0;
1329
1330 /* Type checking must be done elsewhere */
1331 return addr | bridge->driver->masks[type].mask;
1332}
1333
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001334static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size)
1335{
1336 switch (agp_bridge->dev->device) {
Zhenyu Wang99d32bd2008-07-30 12:26:50 -07001337 case PCI_DEVICE_ID_INTEL_GM45_HB:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001338 case PCI_DEVICE_ID_INTEL_IGD_E_HB:
1339 case PCI_DEVICE_ID_INTEL_Q45_HB:
1340 case PCI_DEVICE_ID_INTEL_G45_HB:
Zhenyu Wanga50ccc62008-11-17 14:39:00 +08001341 case PCI_DEVICE_ID_INTEL_G41_HB:
Zhenyu Wang32cb0552009-06-05 15:38:36 +08001342 case PCI_DEVICE_ID_INTEL_IGDNG_D_HB:
1343 case PCI_DEVICE_ID_INTEL_IGDNG_M_HB:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001344 *gtt_offset = *gtt_size = MB(2);
1345 break;
1346 default:
1347 *gtt_offset = *gtt_size = KB(512);
1348 }
1349}
1350
Eric Anholt65c25aa2006-09-06 11:57:18 -04001351/* The intel i965 automatically initializes the agp aperture during POST.
Eric Anholtc41e0de2006-12-19 12:57:24 -08001352 * Use the memory already set aside for in the GTT.
1353 */
Eric Anholt65c25aa2006-09-06 11:57:18 -04001354static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
1355{
Dave Airlie62c96b92008-06-19 14:27:53 +10001356 int page_order;
1357 struct aper_size_info_fixed *size;
1358 int num_entries;
1359 u32 temp;
1360 int gtt_offset, gtt_size;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001361
Dave Airlie62c96b92008-06-19 14:27:53 +10001362 size = agp_bridge->current_size;
1363 page_order = size->page_order;
1364 num_entries = size->num_entries;
1365 agp_bridge->gatt_table_real = NULL;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001366
Dave Airlie62c96b92008-06-19 14:27:53 +10001367 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001368
Dave Airlie62c96b92008-06-19 14:27:53 +10001369 temp &= 0xfff00000;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001370
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001371 intel_i965_get_gtt_range(&gtt_offset, &gtt_size);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001372
Dave Airlie62c96b92008-06-19 14:27:53 +10001373 intel_private.gtt = ioremap((temp + gtt_offset) , gtt_size);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001374
Dave Airlie62c96b92008-06-19 14:27:53 +10001375 if (!intel_private.gtt)
1376 return -ENOMEM;
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +10001377
Dave Airlie62c96b92008-06-19 14:27:53 +10001378 intel_private.registers = ioremap(temp, 128 * 4096);
1379 if (!intel_private.registers) {
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001380 iounmap(intel_private.gtt);
1381 return -ENOMEM;
1382 }
Eric Anholt65c25aa2006-09-06 11:57:18 -04001383
Dave Airlie62c96b92008-06-19 14:27:53 +10001384 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
1385 global_cache_flush(); /* FIXME: ? */
Eric Anholt65c25aa2006-09-06 11:57:18 -04001386
Dave Airlie62c96b92008-06-19 14:27:53 +10001387 /* we have to call this as early as possible after the MMIO base address is known */
1388 intel_i830_init_gtt_entries();
Eric Anholt65c25aa2006-09-06 11:57:18 -04001389
Dave Airlie62c96b92008-06-19 14:27:53 +10001390 agp_bridge->gatt_table = NULL;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001391
Dave Airlie62c96b92008-06-19 14:27:53 +10001392 agp_bridge->gatt_bus_addr = temp;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001393
Dave Airlie62c96b92008-06-19 14:27:53 +10001394 return 0;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001395}
1396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398static int intel_fetch_size(void)
1399{
1400 int i;
1401 u16 temp;
1402 struct aper_size_info_16 *values;
1403
1404 pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
1405 values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
1406
1407 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1408 if (temp == values[i].size_value) {
1409 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
1410 agp_bridge->aperture_size_idx = i;
1411 return values[i].size;
1412 }
1413 }
1414
1415 return 0;
1416}
1417
1418static int __intel_8xx_fetch_size(u8 temp)
1419{
1420 int i;
1421 struct aper_size_info_8 *values;
1422
1423 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
1424
1425 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1426 if (temp == values[i].size_value) {
1427 agp_bridge->previous_size =
1428 agp_bridge->current_size = (void *) (values + i);
1429 agp_bridge->aperture_size_idx = i;
1430 return values[i].size;
1431 }
1432 }
1433 return 0;
1434}
1435
1436static int intel_8xx_fetch_size(void)
1437{
1438 u8 temp;
1439
1440 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1441 return __intel_8xx_fetch_size(temp);
1442}
1443
1444static int intel_815_fetch_size(void)
1445{
1446 u8 temp;
1447
1448 /* Intel 815 chipsets have a _weird_ APSIZE register with only
1449 * one non-reserved bit, so mask the others out ... */
1450 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1451 temp &= (1 << 3);
1452
1453 return __intel_8xx_fetch_size(temp);
1454}
1455
1456static void intel_tlbflush(struct agp_memory *mem)
1457{
1458 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
1459 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1460}
1461
1462
1463static void intel_8xx_tlbflush(struct agp_memory *mem)
1464{
1465 u32 temp;
1466 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1467 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
1468 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1469 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
1470}
1471
1472
1473static void intel_cleanup(void)
1474{
1475 u16 temp;
1476 struct aper_size_info_16 *previous_size;
1477
1478 previous_size = A_SIZE_16(agp_bridge->previous_size);
1479 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1480 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1481 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1482}
1483
1484
1485static void intel_8xx_cleanup(void)
1486{
1487 u16 temp;
1488 struct aper_size_info_8 *previous_size;
1489
1490 previous_size = A_SIZE_8(agp_bridge->previous_size);
1491 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1492 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1493 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1494}
1495
1496
1497static int intel_configure(void)
1498{
1499 u32 temp;
1500 u16 temp2;
1501 struct aper_size_info_16 *current_size;
1502
1503 current_size = A_SIZE_16(agp_bridge->current_size);
1504
1505 /* aperture size */
1506 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1507
1508 /* address to map to */
1509 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1510 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1511
1512 /* attbase - aperture base */
1513 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1514
1515 /* agpctrl */
1516 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1517
1518 /* paccfg/nbxcfg */
1519 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1520 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
1521 (temp2 & ~(1 << 10)) | (1 << 9));
1522 /* clear any possible error conditions */
1523 pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
1524 return 0;
1525}
1526
1527static int intel_815_configure(void)
1528{
1529 u32 temp, addr;
1530 u8 temp2;
1531 struct aper_size_info_8 *current_size;
1532
1533 /* attbase - aperture base */
1534 /* the Intel 815 chipset spec. says that bits 29-31 in the
1535 * ATTBASE register are reserved -> try not to write them */
1536 if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001537 dev_emerg(&agp_bridge->dev->dev, "gatt bus addr too high");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 return -EINVAL;
1539 }
1540
1541 current_size = A_SIZE_8(agp_bridge->current_size);
1542
1543 /* aperture size */
1544 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1545 current_size->size_value);
1546
1547 /* address to map to */
1548 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1549 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1550
1551 pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
1552 addr &= INTEL_815_ATTBASE_MASK;
1553 addr |= agp_bridge->gatt_bus_addr;
1554 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
1555
1556 /* agpctrl */
1557 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1558
1559 /* apcont */
1560 pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
1561 pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
1562
1563 /* clear any possible error conditions */
1564 /* Oddness : this chipset seems to have no ERRSTS register ! */
1565 return 0;
1566}
1567
1568static void intel_820_tlbflush(struct agp_memory *mem)
1569{
1570 return;
1571}
1572
1573static void intel_820_cleanup(void)
1574{
1575 u8 temp;
1576 struct aper_size_info_8 *previous_size;
1577
1578 previous_size = A_SIZE_8(agp_bridge->previous_size);
1579 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
1580 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
1581 temp & ~(1 << 1));
1582 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1583 previous_size->size_value);
1584}
1585
1586
1587static int intel_820_configure(void)
1588{
1589 u32 temp;
1590 u8 temp2;
1591 struct aper_size_info_8 *current_size;
1592
1593 current_size = A_SIZE_8(agp_bridge->current_size);
1594
1595 /* aperture size */
1596 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1597
1598 /* address to map to */
1599 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1600 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1601
1602 /* attbase - aperture base */
1603 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1604
1605 /* agpctrl */
1606 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1607
1608 /* global enable aperture access */
1609 /* This flag is not accessed through MCHCFG register as in */
1610 /* i850 chipset. */
1611 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
1612 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
1613 /* clear any possible AGP-related error conditions */
1614 pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
1615 return 0;
1616}
1617
1618static int intel_840_configure(void)
1619{
1620 u32 temp;
1621 u16 temp2;
1622 struct aper_size_info_8 *current_size;
1623
1624 current_size = A_SIZE_8(agp_bridge->current_size);
1625
1626 /* aperture size */
1627 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1628
1629 /* address to map to */
1630 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1631 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1632
1633 /* attbase - aperture base */
1634 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1635
1636 /* agpctrl */
1637 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1638
1639 /* mcgcfg */
1640 pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
1641 pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
1642 /* clear any possible error conditions */
1643 pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
1644 return 0;
1645}
1646
1647static int intel_845_configure(void)
1648{
1649 u32 temp;
1650 u8 temp2;
1651 struct aper_size_info_8 *current_size;
1652
1653 current_size = A_SIZE_8(agp_bridge->current_size);
1654
1655 /* aperture size */
1656 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1657
Matthew Garrettb0825482005-07-29 14:03:39 -07001658 if (agp_bridge->apbase_config != 0) {
1659 pci_write_config_dword(agp_bridge->dev, AGP_APBASE,
1660 agp_bridge->apbase_config);
1661 } else {
1662 /* address to map to */
1663 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1664 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1665 agp_bridge->apbase_config = temp;
1666 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668 /* attbase - aperture base */
1669 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1670
1671 /* agpctrl */
1672 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1673
1674 /* agpm */
1675 pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
1676 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
1677 /* clear any possible error conditions */
1678 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
Dave Airlie2162e6a2007-11-21 16:36:31 +10001679
1680 intel_i830_setup_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 return 0;
1682}
1683
1684static int intel_850_configure(void)
1685{
1686 u32 temp;
1687 u16 temp2;
1688 struct aper_size_info_8 *current_size;
1689
1690 current_size = A_SIZE_8(agp_bridge->current_size);
1691
1692 /* aperture size */
1693 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1694
1695 /* address to map to */
1696 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1697 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1698
1699 /* attbase - aperture base */
1700 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1701
1702 /* agpctrl */
1703 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1704
1705 /* mcgcfg */
1706 pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
1707 pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
1708 /* clear any possible AGP-related error conditions */
1709 pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
1710 return 0;
1711}
1712
1713static int intel_860_configure(void)
1714{
1715 u32 temp;
1716 u16 temp2;
1717 struct aper_size_info_8 *current_size;
1718
1719 current_size = A_SIZE_8(agp_bridge->current_size);
1720
1721 /* aperture size */
1722 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1723
1724 /* address to map to */
1725 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1726 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1727
1728 /* attbase - aperture base */
1729 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1730
1731 /* agpctrl */
1732 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1733
1734 /* mcgcfg */
1735 pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
1736 pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
1737 /* clear any possible AGP-related error conditions */
1738 pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
1739 return 0;
1740}
1741
1742static int intel_830mp_configure(void)
1743{
1744 u32 temp;
1745 u16 temp2;
1746 struct aper_size_info_8 *current_size;
1747
1748 current_size = A_SIZE_8(agp_bridge->current_size);
1749
1750 /* aperture size */
1751 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1752
1753 /* address to map to */
1754 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1755 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1756
1757 /* attbase - aperture base */
1758 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1759
1760 /* agpctrl */
1761 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1762
1763 /* gmch */
1764 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1765 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
1766 /* clear any possible AGP-related error conditions */
1767 pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
1768 return 0;
1769}
1770
1771static int intel_7505_configure(void)
1772{
1773 u32 temp;
1774 u16 temp2;
1775 struct aper_size_info_8 *current_size;
1776
1777 current_size = A_SIZE_8(agp_bridge->current_size);
1778
1779 /* aperture size */
1780 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1781
1782 /* address to map to */
1783 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1784 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1785
1786 /* attbase - aperture base */
1787 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1788
1789 /* agpctrl */
1790 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1791
1792 /* mchcfg */
1793 pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
1794 pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
1795
1796 return 0;
1797}
1798
1799/* Setup function */
Dave Jonese5524f32007-02-22 18:41:28 -05001800static const struct gatt_mask intel_generic_masks[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801{
1802 {.mask = 0x00000017, .type = 0}
1803};
1804
Dave Jonese5524f32007-02-22 18:41:28 -05001805static const struct aper_size_info_8 intel_815_sizes[2] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806{
1807 {64, 16384, 4, 0},
1808 {32, 8192, 3, 8},
1809};
1810
Dave Jonese5524f32007-02-22 18:41:28 -05001811static const struct aper_size_info_8 intel_8xx_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812{
1813 {256, 65536, 6, 0},
1814 {128, 32768, 5, 32},
1815 {64, 16384, 4, 48},
1816 {32, 8192, 3, 56},
1817 {16, 4096, 2, 60},
1818 {8, 2048, 1, 62},
1819 {4, 1024, 0, 63}
1820};
1821
Dave Jonese5524f32007-02-22 18:41:28 -05001822static const struct aper_size_info_16 intel_generic_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823{
1824 {256, 65536, 6, 0},
1825 {128, 32768, 5, 32},
1826 {64, 16384, 4, 48},
1827 {32, 8192, 3, 56},
1828 {16, 4096, 2, 60},
1829 {8, 2048, 1, 62},
1830 {4, 1024, 0, 63}
1831};
1832
Dave Jonese5524f32007-02-22 18:41:28 -05001833static const struct aper_size_info_8 intel_830mp_sizes[4] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834{
1835 {256, 65536, 6, 0},
1836 {128, 32768, 5, 32},
1837 {64, 16384, 4, 48},
1838 {32, 8192, 3, 56}
1839};
1840
Dave Jonese5524f32007-02-22 18:41:28 -05001841static const struct agp_bridge_driver intel_generic_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 .owner = THIS_MODULE,
1843 .aperture_sizes = intel_generic_sizes,
1844 .size_type = U16_APER_SIZE,
1845 .num_aperture_sizes = 7,
1846 .configure = intel_configure,
1847 .fetch_size = intel_fetch_size,
1848 .cleanup = intel_cleanup,
1849 .tlb_flush = intel_tlbflush,
1850 .mask_memory = agp_generic_mask_memory,
1851 .masks = intel_generic_masks,
1852 .agp_enable = agp_generic_enable,
1853 .cache_flush = global_cache_flush,
1854 .create_gatt_table = agp_generic_create_gatt_table,
1855 .free_gatt_table = agp_generic_free_gatt_table,
1856 .insert_memory = agp_generic_insert_memory,
1857 .remove_memory = agp_generic_remove_memory,
1858 .alloc_by_type = agp_generic_alloc_by_type,
1859 .free_by_type = agp_generic_free_by_type,
1860 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001861 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001863 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001864 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865};
1866
Dave Jonese5524f32007-02-22 18:41:28 -05001867static const struct agp_bridge_driver intel_810_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 .owner = THIS_MODULE,
1869 .aperture_sizes = intel_i810_sizes,
1870 .size_type = FIXED_APER_SIZE,
1871 .num_aperture_sizes = 2,
Joe Perchesc7258012008-03-26 14:10:02 -07001872 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 .configure = intel_i810_configure,
1874 .fetch_size = intel_i810_fetch_size,
1875 .cleanup = intel_i810_cleanup,
1876 .tlb_flush = intel_i810_tlbflush,
1877 .mask_memory = intel_i810_mask_memory,
1878 .masks = intel_i810_masks,
1879 .agp_enable = intel_i810_agp_enable,
1880 .cache_flush = global_cache_flush,
1881 .create_gatt_table = agp_generic_create_gatt_table,
1882 .free_gatt_table = agp_generic_free_gatt_table,
1883 .insert_memory = intel_i810_insert_entries,
1884 .remove_memory = intel_i810_remove_entries,
1885 .alloc_by_type = intel_i810_alloc_by_type,
1886 .free_by_type = intel_i810_free_by_type,
1887 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001888 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001890 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001891 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892};
1893
Dave Jonese5524f32007-02-22 18:41:28 -05001894static const struct agp_bridge_driver intel_815_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 .owner = THIS_MODULE,
1896 .aperture_sizes = intel_815_sizes,
1897 .size_type = U8_APER_SIZE,
1898 .num_aperture_sizes = 2,
1899 .configure = intel_815_configure,
1900 .fetch_size = intel_815_fetch_size,
1901 .cleanup = intel_8xx_cleanup,
1902 .tlb_flush = intel_8xx_tlbflush,
1903 .mask_memory = agp_generic_mask_memory,
1904 .masks = intel_generic_masks,
1905 .agp_enable = agp_generic_enable,
1906 .cache_flush = global_cache_flush,
1907 .create_gatt_table = agp_generic_create_gatt_table,
1908 .free_gatt_table = agp_generic_free_gatt_table,
1909 .insert_memory = agp_generic_insert_memory,
1910 .remove_memory = agp_generic_remove_memory,
1911 .alloc_by_type = agp_generic_alloc_by_type,
1912 .free_by_type = agp_generic_free_by_type,
1913 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001914 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001916 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10001917 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918};
1919
Dave Jonese5524f32007-02-22 18:41:28 -05001920static const struct agp_bridge_driver intel_830_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 .owner = THIS_MODULE,
1922 .aperture_sizes = intel_i830_sizes,
1923 .size_type = FIXED_APER_SIZE,
Dave Jonesc14635e2006-09-06 11:59:35 -04001924 .num_aperture_sizes = 4,
Joe Perchesc7258012008-03-26 14:10:02 -07001925 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 .configure = intel_i830_configure,
1927 .fetch_size = intel_i830_fetch_size,
1928 .cleanup = intel_i830_cleanup,
1929 .tlb_flush = intel_i810_tlbflush,
1930 .mask_memory = intel_i810_mask_memory,
1931 .masks = intel_i810_masks,
1932 .agp_enable = intel_i810_agp_enable,
1933 .cache_flush = global_cache_flush,
1934 .create_gatt_table = intel_i830_create_gatt_table,
1935 .free_gatt_table = intel_i830_free_gatt_table,
1936 .insert_memory = intel_i830_insert_entries,
1937 .remove_memory = intel_i830_remove_entries,
1938 .alloc_by_type = intel_i830_alloc_by_type,
1939 .free_by_type = intel_i810_free_by_type,
1940 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001941 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001943 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001944 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie2162e6a2007-11-21 16:36:31 +10001945 .chipset_flush = intel_i830_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946};
1947
Dave Jonese5524f32007-02-22 18:41:28 -05001948static const struct agp_bridge_driver intel_820_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 .owner = THIS_MODULE,
1950 .aperture_sizes = intel_8xx_sizes,
1951 .size_type = U8_APER_SIZE,
1952 .num_aperture_sizes = 7,
1953 .configure = intel_820_configure,
1954 .fetch_size = intel_8xx_fetch_size,
1955 .cleanup = intel_820_cleanup,
1956 .tlb_flush = intel_820_tlbflush,
1957 .mask_memory = agp_generic_mask_memory,
1958 .masks = intel_generic_masks,
1959 .agp_enable = agp_generic_enable,
1960 .cache_flush = global_cache_flush,
1961 .create_gatt_table = agp_generic_create_gatt_table,
1962 .free_gatt_table = agp_generic_free_gatt_table,
1963 .insert_memory = agp_generic_insert_memory,
1964 .remove_memory = agp_generic_remove_memory,
1965 .alloc_by_type = agp_generic_alloc_by_type,
1966 .free_by_type = agp_generic_free_by_type,
1967 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001968 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001970 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001971 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972};
1973
Dave Jonese5524f32007-02-22 18:41:28 -05001974static const struct agp_bridge_driver intel_830mp_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 .owner = THIS_MODULE,
1976 .aperture_sizes = intel_830mp_sizes,
1977 .size_type = U8_APER_SIZE,
1978 .num_aperture_sizes = 4,
1979 .configure = intel_830mp_configure,
1980 .fetch_size = intel_8xx_fetch_size,
1981 .cleanup = intel_8xx_cleanup,
1982 .tlb_flush = intel_8xx_tlbflush,
1983 .mask_memory = agp_generic_mask_memory,
1984 .masks = intel_generic_masks,
1985 .agp_enable = agp_generic_enable,
1986 .cache_flush = global_cache_flush,
1987 .create_gatt_table = agp_generic_create_gatt_table,
1988 .free_gatt_table = agp_generic_free_gatt_table,
1989 .insert_memory = agp_generic_insert_memory,
1990 .remove_memory = agp_generic_remove_memory,
1991 .alloc_by_type = agp_generic_alloc_by_type,
1992 .free_by_type = agp_generic_free_by_type,
1993 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001994 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001996 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001997 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998};
1999
Dave Jonese5524f32007-02-22 18:41:28 -05002000static const struct agp_bridge_driver intel_840_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 .owner = THIS_MODULE,
2002 .aperture_sizes = intel_8xx_sizes,
2003 .size_type = U8_APER_SIZE,
2004 .num_aperture_sizes = 7,
2005 .configure = intel_840_configure,
2006 .fetch_size = intel_8xx_fetch_size,
2007 .cleanup = intel_8xx_cleanup,
2008 .tlb_flush = intel_8xx_tlbflush,
2009 .mask_memory = agp_generic_mask_memory,
2010 .masks = intel_generic_masks,
2011 .agp_enable = agp_generic_enable,
2012 .cache_flush = global_cache_flush,
2013 .create_gatt_table = agp_generic_create_gatt_table,
2014 .free_gatt_table = agp_generic_free_gatt_table,
2015 .insert_memory = agp_generic_insert_memory,
2016 .remove_memory = agp_generic_remove_memory,
2017 .alloc_by_type = agp_generic_alloc_by_type,
2018 .free_by_type = agp_generic_free_by_type,
2019 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002020 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002022 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002023 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024};
2025
Dave Jonese5524f32007-02-22 18:41:28 -05002026static const struct agp_bridge_driver intel_845_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 .owner = THIS_MODULE,
2028 .aperture_sizes = intel_8xx_sizes,
2029 .size_type = U8_APER_SIZE,
2030 .num_aperture_sizes = 7,
2031 .configure = intel_845_configure,
2032 .fetch_size = intel_8xx_fetch_size,
2033 .cleanup = intel_8xx_cleanup,
2034 .tlb_flush = intel_8xx_tlbflush,
2035 .mask_memory = agp_generic_mask_memory,
2036 .masks = intel_generic_masks,
2037 .agp_enable = agp_generic_enable,
2038 .cache_flush = global_cache_flush,
2039 .create_gatt_table = agp_generic_create_gatt_table,
2040 .free_gatt_table = agp_generic_free_gatt_table,
2041 .insert_memory = agp_generic_insert_memory,
2042 .remove_memory = agp_generic_remove_memory,
2043 .alloc_by_type = agp_generic_alloc_by_type,
2044 .free_by_type = agp_generic_free_by_type,
2045 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002046 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002048 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002049 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Dave Airlie2162e6a2007-11-21 16:36:31 +10002050 .chipset_flush = intel_i830_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051};
2052
Dave Jonese5524f32007-02-22 18:41:28 -05002053static const struct agp_bridge_driver intel_850_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 .owner = THIS_MODULE,
2055 .aperture_sizes = intel_8xx_sizes,
2056 .size_type = U8_APER_SIZE,
2057 .num_aperture_sizes = 7,
2058 .configure = intel_850_configure,
2059 .fetch_size = intel_8xx_fetch_size,
2060 .cleanup = intel_8xx_cleanup,
2061 .tlb_flush = intel_8xx_tlbflush,
2062 .mask_memory = agp_generic_mask_memory,
2063 .masks = intel_generic_masks,
2064 .agp_enable = agp_generic_enable,
2065 .cache_flush = global_cache_flush,
2066 .create_gatt_table = agp_generic_create_gatt_table,
2067 .free_gatt_table = agp_generic_free_gatt_table,
2068 .insert_memory = agp_generic_insert_memory,
2069 .remove_memory = agp_generic_remove_memory,
2070 .alloc_by_type = agp_generic_alloc_by_type,
2071 .free_by_type = agp_generic_free_by_type,
2072 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002073 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002075 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002076 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077};
2078
Dave Jonese5524f32007-02-22 18:41:28 -05002079static const struct agp_bridge_driver intel_860_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 .owner = THIS_MODULE,
2081 .aperture_sizes = intel_8xx_sizes,
2082 .size_type = U8_APER_SIZE,
2083 .num_aperture_sizes = 7,
2084 .configure = intel_860_configure,
2085 .fetch_size = intel_8xx_fetch_size,
2086 .cleanup = intel_8xx_cleanup,
2087 .tlb_flush = intel_8xx_tlbflush,
2088 .mask_memory = agp_generic_mask_memory,
2089 .masks = intel_generic_masks,
2090 .agp_enable = agp_generic_enable,
2091 .cache_flush = global_cache_flush,
2092 .create_gatt_table = agp_generic_create_gatt_table,
2093 .free_gatt_table = agp_generic_free_gatt_table,
2094 .insert_memory = agp_generic_insert_memory,
2095 .remove_memory = agp_generic_remove_memory,
2096 .alloc_by_type = agp_generic_alloc_by_type,
2097 .free_by_type = agp_generic_free_by_type,
2098 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002099 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002101 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002102 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103};
2104
Dave Jonese5524f32007-02-22 18:41:28 -05002105static const struct agp_bridge_driver intel_915_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 .owner = THIS_MODULE,
2107 .aperture_sizes = intel_i830_sizes,
2108 .size_type = FIXED_APER_SIZE,
Dave Jonesc14635e2006-09-06 11:59:35 -04002109 .num_aperture_sizes = 4,
Joe Perchesc7258012008-03-26 14:10:02 -07002110 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 .configure = intel_i915_configure,
Eric Anholtc41e0de2006-12-19 12:57:24 -08002112 .fetch_size = intel_i9xx_fetch_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 .cleanup = intel_i915_cleanup,
2114 .tlb_flush = intel_i810_tlbflush,
2115 .mask_memory = intel_i810_mask_memory,
2116 .masks = intel_i810_masks,
2117 .agp_enable = intel_i810_agp_enable,
2118 .cache_flush = global_cache_flush,
2119 .create_gatt_table = intel_i915_create_gatt_table,
2120 .free_gatt_table = intel_i830_free_gatt_table,
2121 .insert_memory = intel_i915_insert_entries,
2122 .remove_memory = intel_i915_remove_entries,
2123 .alloc_by_type = intel_i830_alloc_by_type,
2124 .free_by_type = intel_i810_free_by_type,
2125 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002126 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002128 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002129 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002130 .chipset_flush = intel_i915_chipset_flush,
Zhenyu Wang17661682009-07-27 12:59:57 +01002131#ifdef USE_PCI_DMA_API
2132 .agp_map_page = intel_agp_map_page,
2133 .agp_unmap_page = intel_agp_unmap_page,
2134 .agp_map_memory = intel_agp_map_memory,
2135 .agp_unmap_memory = intel_agp_unmap_memory,
2136#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137};
2138
Dave Jonese5524f32007-02-22 18:41:28 -05002139static const struct agp_bridge_driver intel_i965_driver = {
Dave Airlie62c96b92008-06-19 14:27:53 +10002140 .owner = THIS_MODULE,
2141 .aperture_sizes = intel_i830_sizes,
2142 .size_type = FIXED_APER_SIZE,
2143 .num_aperture_sizes = 4,
2144 .needs_scratch_page = true,
Dave Airlie0e480e52008-06-19 14:57:31 +10002145 .configure = intel_i915_configure,
2146 .fetch_size = intel_i9xx_fetch_size,
Dave Airlie62c96b92008-06-19 14:27:53 +10002147 .cleanup = intel_i915_cleanup,
2148 .tlb_flush = intel_i810_tlbflush,
2149 .mask_memory = intel_i965_mask_memory,
2150 .masks = intel_i810_masks,
2151 .agp_enable = intel_i810_agp_enable,
2152 .cache_flush = global_cache_flush,
2153 .create_gatt_table = intel_i965_create_gatt_table,
2154 .free_gatt_table = intel_i830_free_gatt_table,
2155 .insert_memory = intel_i915_insert_entries,
2156 .remove_memory = intel_i915_remove_entries,
2157 .alloc_by_type = intel_i830_alloc_by_type,
2158 .free_by_type = intel_i810_free_by_type,
2159 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002160 .agp_alloc_pages = agp_generic_alloc_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002161 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002162 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002163 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002164 .chipset_flush = intel_i915_chipset_flush,
Zhenyu Wang17661682009-07-27 12:59:57 +01002165#ifdef USE_PCI_DMA_API
2166 .agp_map_page = intel_agp_map_page,
2167 .agp_unmap_page = intel_agp_unmap_page,
2168 .agp_map_memory = intel_agp_map_memory,
2169 .agp_unmap_memory = intel_agp_unmap_memory,
2170#endif
Eric Anholt65c25aa2006-09-06 11:57:18 -04002171};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Dave Jonese5524f32007-02-22 18:41:28 -05002173static const struct agp_bridge_driver intel_7505_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 .owner = THIS_MODULE,
2175 .aperture_sizes = intel_8xx_sizes,
2176 .size_type = U8_APER_SIZE,
2177 .num_aperture_sizes = 7,
2178 .configure = intel_7505_configure,
2179 .fetch_size = intel_8xx_fetch_size,
2180 .cleanup = intel_8xx_cleanup,
2181 .tlb_flush = intel_8xx_tlbflush,
2182 .mask_memory = agp_generic_mask_memory,
2183 .masks = intel_generic_masks,
2184 .agp_enable = agp_generic_enable,
2185 .cache_flush = global_cache_flush,
2186 .create_gatt_table = agp_generic_create_gatt_table,
2187 .free_gatt_table = agp_generic_free_gatt_table,
2188 .insert_memory = agp_generic_insert_memory,
2189 .remove_memory = agp_generic_remove_memory,
2190 .alloc_by_type = agp_generic_alloc_by_type,
2191 .free_by_type = agp_generic_free_by_type,
2192 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002193 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002195 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002196 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197};
2198
Wang Zhenyu874808c62007-06-06 11:16:25 +08002199static const struct agp_bridge_driver intel_g33_driver = {
Dave Airlie62c96b92008-06-19 14:27:53 +10002200 .owner = THIS_MODULE,
2201 .aperture_sizes = intel_i830_sizes,
2202 .size_type = FIXED_APER_SIZE,
2203 .num_aperture_sizes = 4,
2204 .needs_scratch_page = true,
2205 .configure = intel_i915_configure,
2206 .fetch_size = intel_i9xx_fetch_size,
2207 .cleanup = intel_i915_cleanup,
2208 .tlb_flush = intel_i810_tlbflush,
2209 .mask_memory = intel_i965_mask_memory,
2210 .masks = intel_i810_masks,
2211 .agp_enable = intel_i810_agp_enable,
2212 .cache_flush = global_cache_flush,
2213 .create_gatt_table = intel_i915_create_gatt_table,
2214 .free_gatt_table = intel_i830_free_gatt_table,
2215 .insert_memory = intel_i915_insert_entries,
2216 .remove_memory = intel_i915_remove_entries,
2217 .alloc_by_type = intel_i830_alloc_by_type,
2218 .free_by_type = intel_i810_free_by_type,
2219 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002220 .agp_alloc_pages = agp_generic_alloc_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002221 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002222 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002223 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002224 .chipset_flush = intel_i915_chipset_flush,
Zhenyu Wang17661682009-07-27 12:59:57 +01002225#ifdef USE_PCI_DMA_API
2226 .agp_map_page = intel_agp_map_page,
2227 .agp_unmap_page = intel_agp_unmap_page,
2228 .agp_map_memory = intel_agp_map_memory,
2229 .agp_unmap_memory = intel_agp_unmap_memory,
2230#endif
Wang Zhenyu874808c62007-06-06 11:16:25 +08002231};
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002232
2233static int find_gmch(u16 device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234{
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002235 struct pci_dev *gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002237 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
2238 if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) {
2239 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL,
Dave Airlief011ae72008-01-25 11:23:04 +10002240 device, gmch_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 }
2242
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002243 if (!gmch_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 return 0;
2245
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002246 intel_private.pcidev = gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 return 1;
2248}
2249
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002250/* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of
2251 * driver and gmch_driver must be non-null, and find_gmch will determine
2252 * which one should be used if a gmch_chip_id is present.
2253 */
2254static const struct intel_driver_description {
2255 unsigned int chip_id;
2256 unsigned int gmch_chip_id;
Wang Zhenyu88889852007-06-14 10:01:04 +08002257 unsigned int multi_gmch_chip; /* if we have more gfx chip type on this HB. */
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002258 char *name;
2259 const struct agp_bridge_driver *driver;
2260 const struct agp_bridge_driver *gmch_driver;
2261} intel_agp_chipsets[] = {
Wang Zhenyu88889852007-06-14 10:01:04 +08002262 { PCI_DEVICE_ID_INTEL_82443LX_0, 0, 0, "440LX", &intel_generic_driver, NULL },
2263 { PCI_DEVICE_ID_INTEL_82443BX_0, 0, 0, "440BX", &intel_generic_driver, NULL },
2264 { PCI_DEVICE_ID_INTEL_82443GX_0, 0, 0, "440GX", &intel_generic_driver, NULL },
2265 { PCI_DEVICE_ID_INTEL_82810_MC1, PCI_DEVICE_ID_INTEL_82810_IG1, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002266 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002267 { PCI_DEVICE_ID_INTEL_82810_MC3, PCI_DEVICE_ID_INTEL_82810_IG3, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002268 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002269 { PCI_DEVICE_ID_INTEL_82810E_MC, PCI_DEVICE_ID_INTEL_82810E_IG, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002270 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002271 { PCI_DEVICE_ID_INTEL_82815_MC, PCI_DEVICE_ID_INTEL_82815_CGC, 0, "i815",
2272 &intel_815_driver, &intel_810_driver },
2273 { PCI_DEVICE_ID_INTEL_82820_HB, 0, 0, "i820", &intel_820_driver, NULL },
2274 { PCI_DEVICE_ID_INTEL_82820_UP_HB, 0, 0, "i820", &intel_820_driver, NULL },
2275 { PCI_DEVICE_ID_INTEL_82830_HB, PCI_DEVICE_ID_INTEL_82830_CGC, 0, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002276 &intel_830mp_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002277 { PCI_DEVICE_ID_INTEL_82840_HB, 0, 0, "i840", &intel_840_driver, NULL },
2278 { PCI_DEVICE_ID_INTEL_82845_HB, 0, 0, "845G", &intel_845_driver, NULL },
2279 { PCI_DEVICE_ID_INTEL_82845G_HB, PCI_DEVICE_ID_INTEL_82845G_IG, 0, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002280 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002281 { PCI_DEVICE_ID_INTEL_82850_HB, 0, 0, "i850", &intel_850_driver, NULL },
Stefan Husemann347486b2009-04-13 14:40:10 -07002282 { PCI_DEVICE_ID_INTEL_82854_HB, PCI_DEVICE_ID_INTEL_82854_IG, 0, "854",
2283 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002284 { PCI_DEVICE_ID_INTEL_82855PM_HB, 0, 0, "855PM", &intel_845_driver, NULL },
2285 { PCI_DEVICE_ID_INTEL_82855GM_HB, PCI_DEVICE_ID_INTEL_82855GM_IG, 0, "855GM",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002286 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002287 { PCI_DEVICE_ID_INTEL_82860_HB, 0, 0, "i860", &intel_860_driver, NULL },
2288 { PCI_DEVICE_ID_INTEL_82865_HB, PCI_DEVICE_ID_INTEL_82865_IG, 0, "865",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002289 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002290 { PCI_DEVICE_ID_INTEL_82875_HB, 0, 0, "i875", &intel_845_driver, NULL },
Carlos Martíne914a362008-01-24 10:34:09 +10002291 { PCI_DEVICE_ID_INTEL_E7221_HB, PCI_DEVICE_ID_INTEL_E7221_IG, 0, "E7221 (i915)",
2292 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002293 { PCI_DEVICE_ID_INTEL_82915G_HB, PCI_DEVICE_ID_INTEL_82915G_IG, 0, "915G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002294 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002295 { PCI_DEVICE_ID_INTEL_82915GM_HB, PCI_DEVICE_ID_INTEL_82915GM_IG, 0, "915GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002296 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002297 { PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, 0, "945G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002298 NULL, &intel_915_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002299 { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, 0, "945GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002300 NULL, &intel_915_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002301 { PCI_DEVICE_ID_INTEL_82945GME_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, 0, "945GME",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002302 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002303 { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002304 NULL, &intel_i965_driver },
Zhenyu Wang9119f852008-01-23 15:49:26 +10002305 { PCI_DEVICE_ID_INTEL_82G35_HB, PCI_DEVICE_ID_INTEL_82G35_IG, 0, "G35",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002306 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002307 { PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, 0, "965Q",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002308 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002309 { PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, 0, "965G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002310 NULL, &intel_i965_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002311 { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, 0, "965GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002312 NULL, &intel_i965_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002313 { PCI_DEVICE_ID_INTEL_82965GME_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, 0, "965GME/GLE",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002314 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002315 { PCI_DEVICE_ID_INTEL_7505_0, 0, 0, "E7505", &intel_7505_driver, NULL },
2316 { PCI_DEVICE_ID_INTEL_7205_0, 0, 0, "E7205", &intel_7505_driver, NULL },
2317 { PCI_DEVICE_ID_INTEL_G33_HB, PCI_DEVICE_ID_INTEL_G33_IG, 0, "G33",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002318 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002319 { PCI_DEVICE_ID_INTEL_Q35_HB, PCI_DEVICE_ID_INTEL_Q35_IG, 0, "Q35",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002320 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002321 { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002322 NULL, &intel_g33_driver },
Shaohua Li21778322009-02-23 15:19:16 +08002323 { PCI_DEVICE_ID_INTEL_IGDGM_HB, PCI_DEVICE_ID_INTEL_IGDGM_IG, 0, "IGD",
2324 NULL, &intel_g33_driver },
2325 { PCI_DEVICE_ID_INTEL_IGDG_HB, PCI_DEVICE_ID_INTEL_IGDG_IG, 0, "IGD",
2326 NULL, &intel_g33_driver },
Zhenyu Wang99d32bd2008-07-30 12:26:50 -07002327 { PCI_DEVICE_ID_INTEL_GM45_HB, PCI_DEVICE_ID_INTEL_GM45_IG, 0,
Eric Anholtb854b2a2008-12-22 18:56:27 -08002328 "Mobile Intel® GM45 Express", NULL, &intel_i965_driver },
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10002329 { PCI_DEVICE_ID_INTEL_IGD_E_HB, PCI_DEVICE_ID_INTEL_IGD_E_IG, 0,
2330 "Intel Integrated Graphics Device", NULL, &intel_i965_driver },
2331 { PCI_DEVICE_ID_INTEL_Q45_HB, PCI_DEVICE_ID_INTEL_Q45_IG, 0,
2332 "Q45/Q43", NULL, &intel_i965_driver },
2333 { PCI_DEVICE_ID_INTEL_G45_HB, PCI_DEVICE_ID_INTEL_G45_IG, 0,
2334 "G45/G43", NULL, &intel_i965_driver },
Zhenyu Wanga50ccc62008-11-17 14:39:00 +08002335 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 0,
2336 "G41", NULL, &intel_i965_driver },
Zhenyu Wang32cb0552009-06-05 15:38:36 +08002337 { PCI_DEVICE_ID_INTEL_IGDNG_D_HB, PCI_DEVICE_ID_INTEL_IGDNG_D_IG, 0,
2338 "IGDNG/D", NULL, &intel_i965_driver },
2339 { PCI_DEVICE_ID_INTEL_IGDNG_M_HB, PCI_DEVICE_ID_INTEL_IGDNG_M_IG, 0,
2340 "IGDNG/M", NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002341 { 0, 0, 0, NULL, NULL, NULL }
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002342};
2343
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344static int __devinit agp_intel_probe(struct pci_dev *pdev,
2345 const struct pci_device_id *ent)
2346{
2347 struct agp_bridge_data *bridge;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 u8 cap_ptr = 0;
2349 struct resource *r;
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002350 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351
2352 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
2353
2354 bridge = agp_alloc_bridge();
2355 if (!bridge)
2356 return -ENOMEM;
2357
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002358 for (i = 0; intel_agp_chipsets[i].name != NULL; i++) {
2359 /* In case that multiple models of gfx chip may
2360 stand on same host bridge type, this can be
2361 sure we detect the right IGD. */
Wang Zhenyu88889852007-06-14 10:01:04 +08002362 if (pdev->device == intel_agp_chipsets[i].chip_id) {
2363 if ((intel_agp_chipsets[i].gmch_chip_id != 0) &&
2364 find_gmch(intel_agp_chipsets[i].gmch_chip_id)) {
2365 bridge->driver =
2366 intel_agp_chipsets[i].gmch_driver;
2367 break;
2368 } else if (intel_agp_chipsets[i].multi_gmch_chip) {
2369 continue;
2370 } else {
2371 bridge->driver = intel_agp_chipsets[i].driver;
2372 break;
2373 }
2374 }
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002375 }
2376
2377 if (intel_agp_chipsets[i].name == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 if (cap_ptr)
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002379 dev_warn(&pdev->dev, "unsupported Intel chipset [%04x/%04x]\n",
2380 pdev->vendor, pdev->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 agp_put_bridge(bridge);
2382 return -ENODEV;
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002383 }
2384
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002385 if (bridge->driver == NULL) {
Wang Zhenyu47d46372007-06-21 13:43:18 +08002386 /* bridge has no AGP and no IGD detected */
2387 if (cap_ptr)
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002388 dev_warn(&pdev->dev, "can't find bridge device (chip_id: %04x)\n",
2389 intel_agp_chipsets[i].gmch_chip_id);
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002390 agp_put_bridge(bridge);
2391 return -ENODEV;
Dave Airlief011ae72008-01-25 11:23:04 +10002392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
2394 bridge->dev = pdev;
2395 bridge->capndx = cap_ptr;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002396 bridge->dev_private_data = &intel_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002398 dev_info(&pdev->dev, "Intel %s Chipset\n", intel_agp_chipsets[i].name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
2400 /*
2401 * The following fixes the case where the BIOS has "forgotten" to
2402 * provide an address range for the GART.
2403 * 20030610 - hamish@zot.org
2404 */
2405 r = &pdev->resource[0];
2406 if (!r->start && r->end) {
Dave Jones6a92a4e2006-02-28 00:54:25 -05002407 if (pci_assign_resource(pdev, 0)) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002408 dev_err(&pdev->dev, "can't assign resource 0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 agp_put_bridge(bridge);
2410 return -ENODEV;
2411 }
2412 }
2413
2414 /*
2415 * If the device has not been properly setup, the following will catch
2416 * the problem and should stop the system from crashing.
2417 * 20030610 - hamish@zot.org
2418 */
2419 if (pci_enable_device(pdev)) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002420 dev_err(&pdev->dev, "can't enable PCI device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 agp_put_bridge(bridge);
2422 return -ENODEV;
2423 }
2424
2425 /* Fill in the mode register */
2426 if (cap_ptr) {
2427 pci_read_config_dword(pdev,
2428 bridge->capndx+PCI_AGP_STATUS,
2429 &bridge->mode);
2430 }
2431
2432 pci_set_drvdata(pdev, bridge);
2433 return agp_add_bridge(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434}
2435
2436static void __devexit agp_intel_remove(struct pci_dev *pdev)
2437{
2438 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
2439
2440 agp_remove_bridge(bridge);
2441
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002442 if (intel_private.pcidev)
2443 pci_dev_put(intel_private.pcidev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
2445 agp_put_bridge(bridge);
2446}
2447
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002448#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449static int agp_intel_resume(struct pci_dev *pdev)
2450{
2451 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
Keith Packarda8c84df2008-07-31 15:48:07 +10002452 int ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453
2454 pci_restore_state(pdev);
2455
Wang Zhenyu4b953202007-01-17 11:07:54 +08002456 /* We should restore our graphics device's config space,
2457 * as host bridge (00:00) resumes before graphics device (02:00),
2458 * then our access to its pci space can work right.
2459 */
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002460 if (intel_private.pcidev)
2461 pci_restore_state(intel_private.pcidev);
Wang Zhenyu4b953202007-01-17 11:07:54 +08002462
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 if (bridge->driver == &intel_generic_driver)
2464 intel_configure();
2465 else if (bridge->driver == &intel_850_driver)
2466 intel_850_configure();
2467 else if (bridge->driver == &intel_845_driver)
2468 intel_845_configure();
2469 else if (bridge->driver == &intel_830mp_driver)
2470 intel_830mp_configure();
2471 else if (bridge->driver == &intel_915_driver)
2472 intel_i915_configure();
2473 else if (bridge->driver == &intel_830_driver)
2474 intel_i830_configure();
2475 else if (bridge->driver == &intel_810_driver)
2476 intel_i810_configure();
Dave Jones08da3f42006-09-10 21:09:26 -04002477 else if (bridge->driver == &intel_i965_driver)
2478 intel_i915_configure();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
Keith Packarda8c84df2008-07-31 15:48:07 +10002480 ret_val = agp_rebind_memory();
2481 if (ret_val != 0)
2482 return ret_val;
2483
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 return 0;
2485}
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002486#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
2488static struct pci_device_id agp_intel_pci_table[] = {
2489#define ID(x) \
2490 { \
2491 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
2492 .class_mask = ~0, \
2493 .vendor = PCI_VENDOR_ID_INTEL, \
2494 .device = x, \
2495 .subvendor = PCI_ANY_ID, \
2496 .subdevice = PCI_ANY_ID, \
2497 }
2498 ID(PCI_DEVICE_ID_INTEL_82443LX_0),
2499 ID(PCI_DEVICE_ID_INTEL_82443BX_0),
2500 ID(PCI_DEVICE_ID_INTEL_82443GX_0),
2501 ID(PCI_DEVICE_ID_INTEL_82810_MC1),
2502 ID(PCI_DEVICE_ID_INTEL_82810_MC3),
2503 ID(PCI_DEVICE_ID_INTEL_82810E_MC),
2504 ID(PCI_DEVICE_ID_INTEL_82815_MC),
2505 ID(PCI_DEVICE_ID_INTEL_82820_HB),
2506 ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
2507 ID(PCI_DEVICE_ID_INTEL_82830_HB),
2508 ID(PCI_DEVICE_ID_INTEL_82840_HB),
2509 ID(PCI_DEVICE_ID_INTEL_82845_HB),
2510 ID(PCI_DEVICE_ID_INTEL_82845G_HB),
2511 ID(PCI_DEVICE_ID_INTEL_82850_HB),
Stefan Husemann347486b2009-04-13 14:40:10 -07002512 ID(PCI_DEVICE_ID_INTEL_82854_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
2514 ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
2515 ID(PCI_DEVICE_ID_INTEL_82860_HB),
2516 ID(PCI_DEVICE_ID_INTEL_82865_HB),
2517 ID(PCI_DEVICE_ID_INTEL_82875_HB),
2518 ID(PCI_DEVICE_ID_INTEL_7505_0),
2519 ID(PCI_DEVICE_ID_INTEL_7205_0),
Carlos Martíne914a362008-01-24 10:34:09 +10002520 ID(PCI_DEVICE_ID_INTEL_E7221_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 ID(PCI_DEVICE_ID_INTEL_82915G_HB),
2522 ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
Alan Hourihaned0de98f2005-05-31 19:50:49 +01002523 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
Alan Hourihane3b0e8ea2006-01-19 14:08:40 +00002524 ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08002525 ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
Shaohua Li21778322009-02-23 15:19:16 +08002526 ID(PCI_DEVICE_ID_INTEL_IGDGM_HB),
2527 ID(PCI_DEVICE_ID_INTEL_IGDG_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04002528 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
Zhenyu Wang9119f852008-01-23 15:49:26 +10002529 ID(PCI_DEVICE_ID_INTEL_82G35_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04002530 ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
2531 ID(PCI_DEVICE_ID_INTEL_82965G_HB),
Wang Zhenyu4598af32007-04-09 08:51:36 +08002532 ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08002533 ID(PCI_DEVICE_ID_INTEL_82965GME_HB),
Wang Zhenyu874808c62007-06-06 11:16:25 +08002534 ID(PCI_DEVICE_ID_INTEL_G33_HB),
2535 ID(PCI_DEVICE_ID_INTEL_Q35_HB),
2536 ID(PCI_DEVICE_ID_INTEL_Q33_HB),
Zhenyu Wang99d32bd2008-07-30 12:26:50 -07002537 ID(PCI_DEVICE_ID_INTEL_GM45_HB),
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10002538 ID(PCI_DEVICE_ID_INTEL_IGD_E_HB),
2539 ID(PCI_DEVICE_ID_INTEL_Q45_HB),
2540 ID(PCI_DEVICE_ID_INTEL_G45_HB),
Zhenyu Wanga50ccc62008-11-17 14:39:00 +08002541 ID(PCI_DEVICE_ID_INTEL_G41_HB),
Zhenyu Wang32cb0552009-06-05 15:38:36 +08002542 ID(PCI_DEVICE_ID_INTEL_IGDNG_D_HB),
2543 ID(PCI_DEVICE_ID_INTEL_IGDNG_M_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 { }
2545};
2546
2547MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
2548
2549static struct pci_driver agp_intel_pci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 .name = "agpgart-intel",
2551 .id_table = agp_intel_pci_table,
2552 .probe = agp_intel_probe,
2553 .remove = __devexit_p(agp_intel_remove),
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002554#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 .resume = agp_intel_resume,
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002556#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557};
2558
2559static int __init agp_intel_init(void)
2560{
2561 if (agp_off)
2562 return -EINVAL;
2563 return pci_register_driver(&agp_intel_pci_driver);
2564}
2565
2566static void __exit agp_intel_cleanup(void)
2567{
2568 pci_unregister_driver(&agp_intel_pci_driver);
2569}
2570
2571module_init(agp_intel_init);
2572module_exit(agp_intel_cleanup);
2573
Dave Jonesf4432c52008-10-20 13:31:45 -04002574MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575MODULE_LICENSE("GPL and additional rights");