blob: 034644eeedf25f9e5b17043782512b0cdbe7ccf7 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09007#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/init.h>
Ahmed S. Darwish1eaf1222007-02-06 18:08:28 +02009#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/pagemap.h>
11#include <linux/agp_backend.h>
Borislav Petkov48a719c2010-01-22 16:01:04 +010012#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "agp.h"
Daniel Vetterff7cdd62010-04-14 00:29:51 +020014#include "intel-agp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Daniel Vetterf51b7662010-04-14 00:29:52 +020016#include "intel-gtt.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Zhenyu Wang1f7a6e32010-02-23 14:05:24 +080018int intel_agp_enabled;
19EXPORT_SYMBOL(intel_agp_enabled);
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021static int intel_fetch_size(void)
22{
23 int i;
24 u16 temp;
25 struct aper_size_info_16 *values;
26
27 pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
28 values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
29
30 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
31 if (temp == values[i].size_value) {
32 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
33 agp_bridge->aperture_size_idx = i;
34 return values[i].size;
35 }
36 }
37
38 return 0;
39}
40
41static int __intel_8xx_fetch_size(u8 temp)
42{
43 int i;
44 struct aper_size_info_8 *values;
45
46 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
47
48 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
49 if (temp == values[i].size_value) {
50 agp_bridge->previous_size =
51 agp_bridge->current_size = (void *) (values + i);
52 agp_bridge->aperture_size_idx = i;
53 return values[i].size;
54 }
55 }
56 return 0;
57}
58
59static int intel_8xx_fetch_size(void)
60{
61 u8 temp;
62
63 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
64 return __intel_8xx_fetch_size(temp);
65}
66
67static int intel_815_fetch_size(void)
68{
69 u8 temp;
70
71 /* Intel 815 chipsets have a _weird_ APSIZE register with only
72 * one non-reserved bit, so mask the others out ... */
73 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
74 temp &= (1 << 3);
75
76 return __intel_8xx_fetch_size(temp);
77}
78
79static void intel_tlbflush(struct agp_memory *mem)
80{
81 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
82 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
83}
84
85
86static void intel_8xx_tlbflush(struct agp_memory *mem)
87{
88 u32 temp;
89 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
90 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
91 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
92 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
93}
94
95
96static void intel_cleanup(void)
97{
98 u16 temp;
99 struct aper_size_info_16 *previous_size;
100
101 previous_size = A_SIZE_16(agp_bridge->previous_size);
102 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
103 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
104 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
105}
106
107
108static void intel_8xx_cleanup(void)
109{
110 u16 temp;
111 struct aper_size_info_8 *previous_size;
112
113 previous_size = A_SIZE_8(agp_bridge->previous_size);
114 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
115 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
116 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
117}
118
119
120static int intel_configure(void)
121{
122 u32 temp;
123 u16 temp2;
124 struct aper_size_info_16 *current_size;
125
126 current_size = A_SIZE_16(agp_bridge->current_size);
127
128 /* aperture size */
129 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
130
131 /* address to map to */
132 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
133 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
134
135 /* attbase - aperture base */
136 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
137
138 /* agpctrl */
139 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
140
141 /* paccfg/nbxcfg */
142 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
143 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
144 (temp2 & ~(1 << 10)) | (1 << 9));
145 /* clear any possible error conditions */
146 pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
147 return 0;
148}
149
150static int intel_815_configure(void)
151{
152 u32 temp, addr;
153 u8 temp2;
154 struct aper_size_info_8 *current_size;
155
156 /* attbase - aperture base */
157 /* the Intel 815 chipset spec. says that bits 29-31 in the
158 * ATTBASE register are reserved -> try not to write them */
159 if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700160 dev_emerg(&agp_bridge->dev->dev, "gatt bus addr too high");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return -EINVAL;
162 }
163
164 current_size = A_SIZE_8(agp_bridge->current_size);
165
166 /* aperture size */
167 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
168 current_size->size_value);
169
170 /* address to map to */
171 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
172 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
173
174 pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
175 addr &= INTEL_815_ATTBASE_MASK;
176 addr |= agp_bridge->gatt_bus_addr;
177 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
178
179 /* agpctrl */
180 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
181
182 /* apcont */
183 pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
184 pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
185
186 /* clear any possible error conditions */
187 /* Oddness : this chipset seems to have no ERRSTS register ! */
188 return 0;
189}
190
191static void intel_820_tlbflush(struct agp_memory *mem)
192{
193 return;
194}
195
196static void intel_820_cleanup(void)
197{
198 u8 temp;
199 struct aper_size_info_8 *previous_size;
200
201 previous_size = A_SIZE_8(agp_bridge->previous_size);
202 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
203 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
204 temp & ~(1 << 1));
205 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
206 previous_size->size_value);
207}
208
209
210static int intel_820_configure(void)
211{
212 u32 temp;
213 u8 temp2;
214 struct aper_size_info_8 *current_size;
215
216 current_size = A_SIZE_8(agp_bridge->current_size);
217
218 /* aperture size */
219 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
220
221 /* address to map to */
222 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
223 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
224
225 /* attbase - aperture base */
226 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
227
228 /* agpctrl */
229 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
230
231 /* global enable aperture access */
232 /* This flag is not accessed through MCHCFG register as in */
233 /* i850 chipset. */
234 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
235 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
236 /* clear any possible AGP-related error conditions */
237 pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
238 return 0;
239}
240
241static int intel_840_configure(void)
242{
243 u32 temp;
244 u16 temp2;
245 struct aper_size_info_8 *current_size;
246
247 current_size = A_SIZE_8(agp_bridge->current_size);
248
249 /* aperture size */
250 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
251
252 /* address to map to */
253 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
254 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
255
256 /* attbase - aperture base */
257 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
258
259 /* agpctrl */
260 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
261
262 /* mcgcfg */
263 pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
264 pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
265 /* clear any possible error conditions */
266 pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
267 return 0;
268}
269
270static int intel_845_configure(void)
271{
272 u32 temp;
273 u8 temp2;
274 struct aper_size_info_8 *current_size;
275
276 current_size = A_SIZE_8(agp_bridge->current_size);
277
278 /* aperture size */
279 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
280
Matthew Garrettb0825482005-07-29 14:03:39 -0700281 if (agp_bridge->apbase_config != 0) {
282 pci_write_config_dword(agp_bridge->dev, AGP_APBASE,
283 agp_bridge->apbase_config);
284 } else {
285 /* address to map to */
286 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
287 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
288 agp_bridge->apbase_config = temp;
289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 /* attbase - aperture base */
292 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
293
294 /* agpctrl */
295 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
296
297 /* agpm */
298 pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
299 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
300 /* clear any possible error conditions */
301 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
302 return 0;
303}
304
305static int intel_850_configure(void)
306{
307 u32 temp;
308 u16 temp2;
309 struct aper_size_info_8 *current_size;
310
311 current_size = A_SIZE_8(agp_bridge->current_size);
312
313 /* aperture size */
314 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
315
316 /* address to map to */
317 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
318 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
319
320 /* attbase - aperture base */
321 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
322
323 /* agpctrl */
324 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
325
326 /* mcgcfg */
327 pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
328 pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
329 /* clear any possible AGP-related error conditions */
330 pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
331 return 0;
332}
333
334static int intel_860_configure(void)
335{
336 u32 temp;
337 u16 temp2;
338 struct aper_size_info_8 *current_size;
339
340 current_size = A_SIZE_8(agp_bridge->current_size);
341
342 /* aperture size */
343 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
344
345 /* address to map to */
346 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
347 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
348
349 /* attbase - aperture base */
350 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
351
352 /* agpctrl */
353 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
354
355 /* mcgcfg */
356 pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
357 pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
358 /* clear any possible AGP-related error conditions */
359 pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
360 return 0;
361}
362
363static int intel_830mp_configure(void)
364{
365 u32 temp;
366 u16 temp2;
367 struct aper_size_info_8 *current_size;
368
369 current_size = A_SIZE_8(agp_bridge->current_size);
370
371 /* aperture size */
372 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
373
374 /* address to map to */
375 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
376 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
377
378 /* attbase - aperture base */
379 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
380
381 /* agpctrl */
382 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
383
384 /* gmch */
385 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
386 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
387 /* clear any possible AGP-related error conditions */
388 pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
389 return 0;
390}
391
392static int intel_7505_configure(void)
393{
394 u32 temp;
395 u16 temp2;
396 struct aper_size_info_8 *current_size;
397
398 current_size = A_SIZE_8(agp_bridge->current_size);
399
400 /* aperture size */
401 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
402
403 /* address to map to */
404 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
405 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
406
407 /* attbase - aperture base */
408 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
409
410 /* agpctrl */
411 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
412
413 /* mchcfg */
414 pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
415 pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
416
417 return 0;
418}
419
420/* Setup function */
Dave Jonese5524f32007-02-22 18:41:28 -0500421static const struct gatt_mask intel_generic_masks[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
423 {.mask = 0x00000017, .type = 0}
424};
425
Dave Jonese5524f32007-02-22 18:41:28 -0500426static const struct aper_size_info_8 intel_815_sizes[2] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
428 {64, 16384, 4, 0},
429 {32, 8192, 3, 8},
430};
431
Dave Jonese5524f32007-02-22 18:41:28 -0500432static const struct aper_size_info_8 intel_8xx_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
434 {256, 65536, 6, 0},
435 {128, 32768, 5, 32},
436 {64, 16384, 4, 48},
437 {32, 8192, 3, 56},
438 {16, 4096, 2, 60},
439 {8, 2048, 1, 62},
440 {4, 1024, 0, 63}
441};
442
Dave Jonese5524f32007-02-22 18:41:28 -0500443static const struct aper_size_info_16 intel_generic_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 {256, 65536, 6, 0},
446 {128, 32768, 5, 32},
447 {64, 16384, 4, 48},
448 {32, 8192, 3, 56},
449 {16, 4096, 2, 60},
450 {8, 2048, 1, 62},
451 {4, 1024, 0, 63}
452};
453
Dave Jonese5524f32007-02-22 18:41:28 -0500454static const struct aper_size_info_8 intel_830mp_sizes[4] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 {256, 65536, 6, 0},
457 {128, 32768, 5, 32},
458 {64, 16384, 4, 48},
459 {32, 8192, 3, 56}
460};
461
Dave Jonese5524f32007-02-22 18:41:28 -0500462static const struct agp_bridge_driver intel_generic_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 .owner = THIS_MODULE,
464 .aperture_sizes = intel_generic_sizes,
465 .size_type = U16_APER_SIZE,
466 .num_aperture_sizes = 7,
467 .configure = intel_configure,
468 .fetch_size = intel_fetch_size,
469 .cleanup = intel_cleanup,
470 .tlb_flush = intel_tlbflush,
471 .mask_memory = agp_generic_mask_memory,
472 .masks = intel_generic_masks,
473 .agp_enable = agp_generic_enable,
474 .cache_flush = global_cache_flush,
475 .create_gatt_table = agp_generic_create_gatt_table,
476 .free_gatt_table = agp_generic_free_gatt_table,
477 .insert_memory = agp_generic_insert_memory,
478 .remove_memory = agp_generic_remove_memory,
479 .alloc_by_type = agp_generic_alloc_by_type,
480 .free_by_type = agp_generic_free_by_type,
481 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +0800482 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +0800484 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100485 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486};
487
Dave Jonese5524f32007-02-22 18:41:28 -0500488static const struct agp_bridge_driver intel_815_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 .owner = THIS_MODULE,
490 .aperture_sizes = intel_815_sizes,
491 .size_type = U8_APER_SIZE,
492 .num_aperture_sizes = 2,
493 .configure = intel_815_configure,
494 .fetch_size = intel_815_fetch_size,
495 .cleanup = intel_8xx_cleanup,
496 .tlb_flush = intel_8xx_tlbflush,
497 .mask_memory = agp_generic_mask_memory,
498 .masks = intel_generic_masks,
499 .agp_enable = agp_generic_enable,
500 .cache_flush = global_cache_flush,
501 .create_gatt_table = agp_generic_create_gatt_table,
502 .free_gatt_table = agp_generic_free_gatt_table,
503 .insert_memory = agp_generic_insert_memory,
504 .remove_memory = agp_generic_remove_memory,
505 .alloc_by_type = agp_generic_alloc_by_type,
506 .free_by_type = agp_generic_free_by_type,
507 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +0800508 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +0800510 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +1000511 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512};
513
Dave Jonese5524f32007-02-22 18:41:28 -0500514static const struct agp_bridge_driver intel_820_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 .owner = THIS_MODULE,
516 .aperture_sizes = intel_8xx_sizes,
517 .size_type = U8_APER_SIZE,
518 .num_aperture_sizes = 7,
519 .configure = intel_820_configure,
520 .fetch_size = intel_8xx_fetch_size,
521 .cleanup = intel_820_cleanup,
522 .tlb_flush = intel_820_tlbflush,
523 .mask_memory = agp_generic_mask_memory,
524 .masks = intel_generic_masks,
525 .agp_enable = agp_generic_enable,
526 .cache_flush = global_cache_flush,
527 .create_gatt_table = agp_generic_create_gatt_table,
528 .free_gatt_table = agp_generic_free_gatt_table,
529 .insert_memory = agp_generic_insert_memory,
530 .remove_memory = agp_generic_remove_memory,
531 .alloc_by_type = agp_generic_alloc_by_type,
532 .free_by_type = agp_generic_free_by_type,
533 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +0800534 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +0800536 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100537 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538};
539
Dave Jonese5524f32007-02-22 18:41:28 -0500540static const struct agp_bridge_driver intel_830mp_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 .owner = THIS_MODULE,
542 .aperture_sizes = intel_830mp_sizes,
543 .size_type = U8_APER_SIZE,
544 .num_aperture_sizes = 4,
545 .configure = intel_830mp_configure,
546 .fetch_size = intel_8xx_fetch_size,
547 .cleanup = intel_8xx_cleanup,
548 .tlb_flush = intel_8xx_tlbflush,
549 .mask_memory = agp_generic_mask_memory,
550 .masks = intel_generic_masks,
551 .agp_enable = agp_generic_enable,
552 .cache_flush = global_cache_flush,
553 .create_gatt_table = agp_generic_create_gatt_table,
554 .free_gatt_table = agp_generic_free_gatt_table,
555 .insert_memory = agp_generic_insert_memory,
556 .remove_memory = agp_generic_remove_memory,
557 .alloc_by_type = agp_generic_alloc_by_type,
558 .free_by_type = agp_generic_free_by_type,
559 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +0800560 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +0800562 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100563 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564};
565
Dave Jonese5524f32007-02-22 18:41:28 -0500566static const struct agp_bridge_driver intel_840_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 .owner = THIS_MODULE,
568 .aperture_sizes = intel_8xx_sizes,
569 .size_type = U8_APER_SIZE,
570 .num_aperture_sizes = 7,
571 .configure = intel_840_configure,
572 .fetch_size = intel_8xx_fetch_size,
573 .cleanup = intel_8xx_cleanup,
574 .tlb_flush = intel_8xx_tlbflush,
575 .mask_memory = agp_generic_mask_memory,
576 .masks = intel_generic_masks,
577 .agp_enable = agp_generic_enable,
578 .cache_flush = global_cache_flush,
579 .create_gatt_table = agp_generic_create_gatt_table,
580 .free_gatt_table = agp_generic_free_gatt_table,
581 .insert_memory = agp_generic_insert_memory,
582 .remove_memory = agp_generic_remove_memory,
583 .alloc_by_type = agp_generic_alloc_by_type,
584 .free_by_type = agp_generic_free_by_type,
585 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +0800586 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +0800588 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100589 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590};
591
Dave Jonese5524f32007-02-22 18:41:28 -0500592static const struct agp_bridge_driver intel_845_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 .owner = THIS_MODULE,
594 .aperture_sizes = intel_8xx_sizes,
595 .size_type = U8_APER_SIZE,
596 .num_aperture_sizes = 7,
597 .configure = intel_845_configure,
598 .fetch_size = intel_8xx_fetch_size,
599 .cleanup = intel_8xx_cleanup,
600 .tlb_flush = intel_8xx_tlbflush,
601 .mask_memory = agp_generic_mask_memory,
602 .masks = intel_generic_masks,
603 .agp_enable = agp_generic_enable,
604 .cache_flush = global_cache_flush,
605 .create_gatt_table = agp_generic_create_gatt_table,
606 .free_gatt_table = agp_generic_free_gatt_table,
607 .insert_memory = agp_generic_insert_memory,
608 .remove_memory = agp_generic_remove_memory,
609 .alloc_by_type = agp_generic_alloc_by_type,
610 .free_by_type = agp_generic_free_by_type,
611 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +0800612 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +0800614 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100615 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616};
617
Dave Jonese5524f32007-02-22 18:41:28 -0500618static const struct agp_bridge_driver intel_850_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 .owner = THIS_MODULE,
620 .aperture_sizes = intel_8xx_sizes,
621 .size_type = U8_APER_SIZE,
622 .num_aperture_sizes = 7,
623 .configure = intel_850_configure,
624 .fetch_size = intel_8xx_fetch_size,
625 .cleanup = intel_8xx_cleanup,
626 .tlb_flush = intel_8xx_tlbflush,
627 .mask_memory = agp_generic_mask_memory,
628 .masks = intel_generic_masks,
629 .agp_enable = agp_generic_enable,
630 .cache_flush = global_cache_flush,
631 .create_gatt_table = agp_generic_create_gatt_table,
632 .free_gatt_table = agp_generic_free_gatt_table,
633 .insert_memory = agp_generic_insert_memory,
634 .remove_memory = agp_generic_remove_memory,
635 .alloc_by_type = agp_generic_alloc_by_type,
636 .free_by_type = agp_generic_free_by_type,
637 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +0800638 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +0800640 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100641 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642};
643
Dave Jonese5524f32007-02-22 18:41:28 -0500644static const struct agp_bridge_driver intel_860_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 .owner = THIS_MODULE,
646 .aperture_sizes = intel_8xx_sizes,
647 .size_type = U8_APER_SIZE,
648 .num_aperture_sizes = 7,
649 .configure = intel_860_configure,
650 .fetch_size = intel_8xx_fetch_size,
651 .cleanup = intel_8xx_cleanup,
652 .tlb_flush = intel_8xx_tlbflush,
653 .mask_memory = agp_generic_mask_memory,
654 .masks = intel_generic_masks,
655 .agp_enable = agp_generic_enable,
656 .cache_flush = global_cache_flush,
657 .create_gatt_table = agp_generic_create_gatt_table,
658 .free_gatt_table = agp_generic_free_gatt_table,
659 .insert_memory = agp_generic_insert_memory,
660 .remove_memory = agp_generic_remove_memory,
661 .alloc_by_type = agp_generic_alloc_by_type,
662 .free_by_type = agp_generic_free_by_type,
663 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +0800664 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +0800666 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100667 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668};
669
Dave Jonese5524f32007-02-22 18:41:28 -0500670static const struct agp_bridge_driver intel_7505_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 .owner = THIS_MODULE,
672 .aperture_sizes = intel_8xx_sizes,
673 .size_type = U8_APER_SIZE,
674 .num_aperture_sizes = 7,
675 .configure = intel_7505_configure,
676 .fetch_size = intel_8xx_fetch_size,
677 .cleanup = intel_8xx_cleanup,
678 .tlb_flush = intel_8xx_tlbflush,
679 .mask_memory = agp_generic_mask_memory,
680 .masks = intel_generic_masks,
681 .agp_enable = agp_generic_enable,
682 .cache_flush = global_cache_flush,
683 .create_gatt_table = agp_generic_create_gatt_table,
684 .free_gatt_table = agp_generic_free_gatt_table,
685 .insert_memory = agp_generic_insert_memory,
686 .remove_memory = agp_generic_remove_memory,
687 .alloc_by_type = agp_generic_alloc_by_type,
688 .free_by_type = agp_generic_free_by_type,
689 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +0800690 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +0800692 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100693 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694};
695
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800696static int find_gmch(u16 device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697{
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800698 struct pci_dev *gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800700 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
701 if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) {
702 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL,
Dave Airlief011ae72008-01-25 11:23:04 +1000703 device, gmch_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 }
705
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800706 if (!gmch_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 return 0;
708
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800709 intel_private.pcidev = gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 return 1;
711}
712
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800713/* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of
714 * driver and gmch_driver must be non-null, and find_gmch will determine
715 * which one should be used if a gmch_chip_id is present.
716 */
717static const struct intel_driver_description {
718 unsigned int chip_id;
719 unsigned int gmch_chip_id;
720 char *name;
721 const struct agp_bridge_driver *driver;
722 const struct agp_bridge_driver *gmch_driver;
723} intel_agp_chipsets[] = {
Daniel Vetter059efc62010-04-14 00:29:54 +0200724 { PCI_DEVICE_ID_INTEL_82443LX_0, 0, "440LX", &intel_generic_driver, NULL },
725 { PCI_DEVICE_ID_INTEL_82443BX_0, 0, "440BX", &intel_generic_driver, NULL },
726 { PCI_DEVICE_ID_INTEL_82443GX_0, 0, "440GX", &intel_generic_driver, NULL },
727 { PCI_DEVICE_ID_INTEL_82810_MC1, PCI_DEVICE_ID_INTEL_82810_IG1, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800728 NULL, &intel_810_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200729 { PCI_DEVICE_ID_INTEL_82810_MC3, PCI_DEVICE_ID_INTEL_82810_IG3, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800730 NULL, &intel_810_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200731 { PCI_DEVICE_ID_INTEL_82810E_MC, PCI_DEVICE_ID_INTEL_82810E_IG, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800732 NULL, &intel_810_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200733 { PCI_DEVICE_ID_INTEL_82815_MC, PCI_DEVICE_ID_INTEL_82815_CGC, "i815",
Wang Zhenyu88889852007-06-14 10:01:04 +0800734 &intel_815_driver, &intel_810_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200735 { PCI_DEVICE_ID_INTEL_82820_HB, 0, "i820", &intel_820_driver, NULL },
736 { PCI_DEVICE_ID_INTEL_82820_UP_HB, 0, "i820", &intel_820_driver, NULL },
737 { PCI_DEVICE_ID_INTEL_82830_HB, PCI_DEVICE_ID_INTEL_82830_CGC, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800738 &intel_830mp_driver, &intel_830_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200739 { PCI_DEVICE_ID_INTEL_82840_HB, 0, "i840", &intel_840_driver, NULL },
740 { PCI_DEVICE_ID_INTEL_82845_HB, 0, "845G", &intel_845_driver, NULL },
741 { PCI_DEVICE_ID_INTEL_82845G_HB, PCI_DEVICE_ID_INTEL_82845G_IG, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800742 &intel_845_driver, &intel_830_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200743 { PCI_DEVICE_ID_INTEL_82850_HB, 0, "i850", &intel_850_driver, NULL },
744 { PCI_DEVICE_ID_INTEL_82854_HB, PCI_DEVICE_ID_INTEL_82854_IG, "854",
Stefan Husemann347486b2009-04-13 14:40:10 -0700745 &intel_845_driver, &intel_830_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200746 { PCI_DEVICE_ID_INTEL_82855PM_HB, 0, "855PM", &intel_845_driver, NULL },
747 { PCI_DEVICE_ID_INTEL_82855GM_HB, PCI_DEVICE_ID_INTEL_82855GM_IG, "855GM",
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800748 &intel_845_driver, &intel_830_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200749 { PCI_DEVICE_ID_INTEL_82860_HB, 0, "i860", &intel_860_driver, NULL },
750 { PCI_DEVICE_ID_INTEL_82865_HB, PCI_DEVICE_ID_INTEL_82865_IG, "865",
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800751 &intel_845_driver, &intel_830_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200752 { PCI_DEVICE_ID_INTEL_82875_HB, 0, "i875", &intel_845_driver, NULL },
753 { PCI_DEVICE_ID_INTEL_E7221_HB, PCI_DEVICE_ID_INTEL_E7221_IG, "E7221 (i915)",
Carlos Martíne914a362008-01-24 10:34:09 +1000754 NULL, &intel_915_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200755 { PCI_DEVICE_ID_INTEL_82915G_HB, PCI_DEVICE_ID_INTEL_82915G_IG, "915G",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800756 NULL, &intel_915_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200757 { PCI_DEVICE_ID_INTEL_82915GM_HB, PCI_DEVICE_ID_INTEL_82915GM_IG, "915GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800758 NULL, &intel_915_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200759 { PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, "945G",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800760 NULL, &intel_915_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200761 { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, "945GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800762 NULL, &intel_915_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200763 { PCI_DEVICE_ID_INTEL_82945GME_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, "945GME",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800764 NULL, &intel_915_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200765 { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, "946GZ",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800766 NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200767 { PCI_DEVICE_ID_INTEL_82G35_HB, PCI_DEVICE_ID_INTEL_82G35_IG, "G35",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800768 NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200769 { PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, "965Q",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800770 NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200771 { PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, "965G",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800772 NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200773 { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, "965GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800774 NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200775 { PCI_DEVICE_ID_INTEL_82965GME_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, "965GME/GLE",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800776 NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200777 { PCI_DEVICE_ID_INTEL_7505_0, 0, "E7505", &intel_7505_driver, NULL },
778 { PCI_DEVICE_ID_INTEL_7205_0, 0, "E7205", &intel_7505_driver, NULL },
779 { PCI_DEVICE_ID_INTEL_G33_HB, PCI_DEVICE_ID_INTEL_G33_IG, "G33",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800780 NULL, &intel_g33_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200781 { PCI_DEVICE_ID_INTEL_Q35_HB, PCI_DEVICE_ID_INTEL_Q35_IG, "Q35",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800782 NULL, &intel_g33_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200783 { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, "Q33",
Wang Zhenyu47d46372007-06-21 13:43:18 +0800784 NULL, &intel_g33_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200785 { PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB, PCI_DEVICE_ID_INTEL_PINEVIEW_M_IG, "GMA3150",
Shaohua Li21778322009-02-23 15:19:16 +0800786 NULL, &intel_g33_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200787 { PCI_DEVICE_ID_INTEL_PINEVIEW_HB, PCI_DEVICE_ID_INTEL_PINEVIEW_IG, "GMA3150",
Shaohua Li21778322009-02-23 15:19:16 +0800788 NULL, &intel_g33_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200789 { PCI_DEVICE_ID_INTEL_GM45_HB, PCI_DEVICE_ID_INTEL_GM45_IG,
Adam Jackson107f5172009-12-03 17:14:41 -0500790 "GM45", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200791 { PCI_DEVICE_ID_INTEL_EAGLELAKE_HB, PCI_DEVICE_ID_INTEL_EAGLELAKE_IG,
Adam Jackson107f5172009-12-03 17:14:41 -0500792 "Eaglelake", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200793 { PCI_DEVICE_ID_INTEL_Q45_HB, PCI_DEVICE_ID_INTEL_Q45_IG,
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000794 "Q45/Q43", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200795 { PCI_DEVICE_ID_INTEL_G45_HB, PCI_DEVICE_ID_INTEL_G45_IG,
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000796 "G45/G43", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200797 { PCI_DEVICE_ID_INTEL_B43_HB, PCI_DEVICE_ID_INTEL_B43_IG,
Fabian Henze38d8a952009-09-08 00:59:58 +0800798 "B43", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200799 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG,
Zhenyu Wanga50ccc62008-11-17 14:39:00 +0800800 "G41", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200801 { PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG,
Zhenyu Wangaf86d4b2010-02-10 10:39:33 +0800802 "HD Graphics", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200803 { PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG,
Zhenyu Wangaf86d4b2010-02-10 10:39:33 +0800804 "HD Graphics", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200805 { PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG,
Zhenyu Wangaf86d4b2010-02-10 10:39:33 +0800806 "HD Graphics", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200807 { PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG,
Zhenyu Wangaf86d4b2010-02-10 10:39:33 +0800808 "HD Graphics", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200809 { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB, PCI_DEVICE_ID_INTEL_SANDYBRIDGE_IG,
Eric Anholt1089e302009-10-22 16:10:52 -0700810 "Sandybridge", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200811 { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB, PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_IG,
Eric Anholt954bce52010-01-07 16:21:46 -0800812 "Sandybridge", NULL, &intel_i965_driver },
Daniel Vetter059efc62010-04-14 00:29:54 +0200813 { 0, 0, NULL, NULL, NULL }
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800814};
815
Daniel Vetter22dd82a2010-04-14 00:29:55 +0200816static int __devinit intel_gmch_probe(struct pci_dev *pdev,
817 struct agp_bridge_data *bridge)
818{
819 int i;
820 bridge->driver = NULL;
821
822 for (i = 0; intel_agp_chipsets[i].name != NULL; i++) {
823 if ((intel_agp_chipsets[i].gmch_chip_id != 0) &&
824 find_gmch(intel_agp_chipsets[i].gmch_chip_id)) {
825 bridge->driver =
826 intel_agp_chipsets[i].gmch_driver;
827 break;
828 }
829 }
830
831 if (!bridge->driver)
832 return 0;
833
834 bridge->dev_private_data = &intel_private;
835 bridge->dev = pdev;
836
837 dev_info(&pdev->dev, "Intel %s Chipset\n", intel_agp_chipsets[i].name);
838
839 if (bridge->driver->mask_memory == intel_i965_mask_memory) {
840 if (pci_set_dma_mask(intel_private.pcidev, DMA_BIT_MASK(36)))
841 dev_err(&intel_private.pcidev->dev,
842 "set gfx device dma mask 36bit failed!\n");
843 else
844 pci_set_consistent_dma_mask(intel_private.pcidev,
845 DMA_BIT_MASK(36));
846 }
847
848 return 1;
849}
850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851static int __devinit agp_intel_probe(struct pci_dev *pdev,
852 const struct pci_device_id *ent)
853{
854 struct agp_bridge_data *bridge;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 u8 cap_ptr = 0;
856 struct resource *r;
Zhenyu Wang1f7a6e32010-02-23 14:05:24 +0800857 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
859 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
860
861 bridge = agp_alloc_bridge();
862 if (!bridge)
863 return -ENOMEM;
864
Daniel Vetter22dd82a2010-04-14 00:29:55 +0200865 bridge->capndx = cap_ptr;
866
867 if (intel_gmch_probe(pdev, bridge))
868 goto found_gmch;
869
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800870 for (i = 0; intel_agp_chipsets[i].name != NULL; i++) {
871 /* In case that multiple models of gfx chip may
872 stand on same host bridge type, this can be
873 sure we detect the right IGD. */
Wang Zhenyu88889852007-06-14 10:01:04 +0800874 if (pdev->device == intel_agp_chipsets[i].chip_id) {
Daniel Vetter22dd82a2010-04-14 00:29:55 +0200875 bridge->driver = intel_agp_chipsets[i].driver;
876 break;
Wang Zhenyu88889852007-06-14 10:01:04 +0800877 }
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800878 }
879
880 if (intel_agp_chipsets[i].name == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 if (cap_ptr)
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700882 dev_warn(&pdev->dev, "unsupported Intel chipset [%04x/%04x]\n",
883 pdev->vendor, pdev->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 agp_put_bridge(bridge);
885 return -ENODEV;
Wang Zhenyu9614ece2007-05-30 09:45:58 +0800886 }
887
Dave Airlie10fd8832010-04-20 16:34:20 +1000888 if (!bridge->driver) {
889 if (cap_ptr)
890 dev_warn(&pdev->dev, "can't find bridge device (chip_id: %04x)\n",
891 intel_agp_chipsets[i].gmch_chip_id);
892 agp_put_bridge(bridge);
893 return -ENODEV;
894 }
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 bridge->dev = pdev;
Daniel Vetter22dd82a2010-04-14 00:29:55 +0200897 bridge->dev_private_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700899 dev_info(&pdev->dev, "Intel %s Chipset\n", intel_agp_chipsets[i].name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901 /*
902 * The following fixes the case where the BIOS has "forgotten" to
903 * provide an address range for the GART.
904 * 20030610 - hamish@zot.org
905 */
906 r = &pdev->resource[0];
907 if (!r->start && r->end) {
Dave Jones6a92a4e2006-02-28 00:54:25 -0500908 if (pci_assign_resource(pdev, 0)) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700909 dev_err(&pdev->dev, "can't assign resource 0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 agp_put_bridge(bridge);
911 return -ENODEV;
912 }
913 }
914
915 /*
916 * If the device has not been properly setup, the following will catch
917 * the problem and should stop the system from crashing.
918 * 20030610 - hamish@zot.org
919 */
920 if (pci_enable_device(pdev)) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700921 dev_err(&pdev->dev, "can't enable PCI device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 agp_put_bridge(bridge);
923 return -ENODEV;
924 }
925
926 /* Fill in the mode register */
927 if (cap_ptr) {
928 pci_read_config_dword(pdev,
929 bridge->capndx+PCI_AGP_STATUS,
930 &bridge->mode);
931 }
932
Daniel Vetter22dd82a2010-04-14 00:29:55 +0200933found_gmch:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 pci_set_drvdata(pdev, bridge);
Zhenyu Wang1f7a6e32010-02-23 14:05:24 +0800935 err = agp_add_bridge(bridge);
936 if (!err)
937 intel_agp_enabled = 1;
938 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939}
940
941static void __devexit agp_intel_remove(struct pci_dev *pdev)
942{
943 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
944
945 agp_remove_bridge(bridge);
946
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800947 if (intel_private.pcidev)
948 pci_dev_put(intel_private.pcidev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 agp_put_bridge(bridge);
951}
952
Alexey Dobriyan85be7d62006-08-12 02:02:02 +0400953#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954static int agp_intel_resume(struct pci_dev *pdev)
955{
956 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
Keith Packarda8c84df2008-07-31 15:48:07 +1000957 int ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Daniel Vettere5a04d52010-04-14 00:29:53 +0200959 bridge->driver->configure();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Keith Packarda8c84df2008-07-31 15:48:07 +1000961 ret_val = agp_rebind_memory();
962 if (ret_val != 0)
963 return ret_val;
964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 return 0;
966}
Alexey Dobriyan85be7d62006-08-12 02:02:02 +0400967#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
969static struct pci_device_id agp_intel_pci_table[] = {
970#define ID(x) \
971 { \
972 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
973 .class_mask = ~0, \
974 .vendor = PCI_VENDOR_ID_INTEL, \
975 .device = x, \
976 .subvendor = PCI_ANY_ID, \
977 .subdevice = PCI_ANY_ID, \
978 }
979 ID(PCI_DEVICE_ID_INTEL_82443LX_0),
980 ID(PCI_DEVICE_ID_INTEL_82443BX_0),
981 ID(PCI_DEVICE_ID_INTEL_82443GX_0),
982 ID(PCI_DEVICE_ID_INTEL_82810_MC1),
983 ID(PCI_DEVICE_ID_INTEL_82810_MC3),
984 ID(PCI_DEVICE_ID_INTEL_82810E_MC),
985 ID(PCI_DEVICE_ID_INTEL_82815_MC),
986 ID(PCI_DEVICE_ID_INTEL_82820_HB),
987 ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
988 ID(PCI_DEVICE_ID_INTEL_82830_HB),
989 ID(PCI_DEVICE_ID_INTEL_82840_HB),
990 ID(PCI_DEVICE_ID_INTEL_82845_HB),
991 ID(PCI_DEVICE_ID_INTEL_82845G_HB),
992 ID(PCI_DEVICE_ID_INTEL_82850_HB),
Stefan Husemann347486b2009-04-13 14:40:10 -0700993 ID(PCI_DEVICE_ID_INTEL_82854_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
995 ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
996 ID(PCI_DEVICE_ID_INTEL_82860_HB),
997 ID(PCI_DEVICE_ID_INTEL_82865_HB),
998 ID(PCI_DEVICE_ID_INTEL_82875_HB),
999 ID(PCI_DEVICE_ID_INTEL_7505_0),
1000 ID(PCI_DEVICE_ID_INTEL_7205_0),
Carlos Martíne914a362008-01-24 10:34:09 +10001001 ID(PCI_DEVICE_ID_INTEL_E7221_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 ID(PCI_DEVICE_ID_INTEL_82915G_HB),
1003 ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
Alan Hourihaned0de98f2005-05-31 19:50:49 +01001004 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
Alan Hourihane3b0e8ea2006-01-19 14:08:40 +00001005 ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08001006 ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
Adam Jackson107f5172009-12-03 17:14:41 -05001007 ID(PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB),
1008 ID(PCI_DEVICE_ID_INTEL_PINEVIEW_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04001009 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
Zhenyu Wang9119f852008-01-23 15:49:26 +10001010 ID(PCI_DEVICE_ID_INTEL_82G35_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04001011 ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
1012 ID(PCI_DEVICE_ID_INTEL_82965G_HB),
Wang Zhenyu4598af32007-04-09 08:51:36 +08001013 ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08001014 ID(PCI_DEVICE_ID_INTEL_82965GME_HB),
Wang Zhenyu874808c62007-06-06 11:16:25 +08001015 ID(PCI_DEVICE_ID_INTEL_G33_HB),
1016 ID(PCI_DEVICE_ID_INTEL_Q35_HB),
1017 ID(PCI_DEVICE_ID_INTEL_Q33_HB),
Zhenyu Wang99d32bd2008-07-30 12:26:50 -07001018 ID(PCI_DEVICE_ID_INTEL_GM45_HB),
Adam Jackson107f5172009-12-03 17:14:41 -05001019 ID(PCI_DEVICE_ID_INTEL_EAGLELAKE_HB),
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001020 ID(PCI_DEVICE_ID_INTEL_Q45_HB),
1021 ID(PCI_DEVICE_ID_INTEL_G45_HB),
Zhenyu Wanga50ccc62008-11-17 14:39:00 +08001022 ID(PCI_DEVICE_ID_INTEL_G41_HB),
Fabian Henze38d8a952009-09-08 00:59:58 +08001023 ID(PCI_DEVICE_ID_INTEL_B43_HB),
Adam Jackson107f5172009-12-03 17:14:41 -05001024 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB),
1025 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB),
1026 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB),
Dave Airlie3ff99162009-12-08 14:03:47 +10001027 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB),
Eric Anholt1089e302009-10-22 16:10:52 -07001028 ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB),
Eric Anholt954bce52010-01-07 16:21:46 -08001029 ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 { }
1031};
1032
1033MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
1034
1035static struct pci_driver agp_intel_pci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 .name = "agpgart-intel",
1037 .id_table = agp_intel_pci_table,
1038 .probe = agp_intel_probe,
1039 .remove = __devexit_p(agp_intel_remove),
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04001040#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 .resume = agp_intel_resume,
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04001042#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043};
1044
1045static int __init agp_intel_init(void)
1046{
1047 if (agp_off)
1048 return -EINVAL;
1049 return pci_register_driver(&agp_intel_pci_driver);
1050}
1051
1052static void __exit agp_intel_cleanup(void)
1053{
1054 pci_unregister_driver(&agp_intel_pci_driver);
1055}
1056
1057module_init(agp_intel_init);
1058module_exit(agp_intel_cleanup);
1059
Dave Jonesf4432c52008-10-20 13:31:45 -04001060MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061MODULE_LICENSE("GPL and additional rights");