ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / char / agp / amd64-agp.c
1 /* 
2  * Copyright 2001-2003 SuSE Labs.
3  * Distributed under the GNU public license, v2.
4  * 
5  * This is a GART driver for the AMD Opteron/Athlon64 on-CPU northbridge.
6  * It also includes support for the AMD 8151 AGP bridge,
7  * although it doesn't actually do much, as all the real
8  * work is done in the northbridge(s).
9  */
10
11 #include <linux/config.h>
12 #include <linux/module.h>
13 #include <linux/pci.h>
14 #include <linux/init.h>
15 #include <linux/agp_backend.h>
16 #include "agp.h"
17
18 /* Will need to be increased if AMD64 ever goes >8-way. */
19 #define MAX_HAMMER_GARTS   8
20
21 /* PTE bits. */
22 #define GPTE_VALID      1
23 #define GPTE_COHERENT   2
24
25 /* Aperture control register bits. */
26 #define GARTEN          (1<<0)
27 #define DISGARTCPU      (1<<4)
28 #define DISGARTIO       (1<<5)
29
30 /* GART cache control register bits. */
31 #define INVGART         (1<<0)
32 #define GARTPTEERR      (1<<1)
33
34 /* K8 On-cpu GART registers */
35 #define AMD64_GARTAPERTURECTL   0x90
36 #define AMD64_GARTAPERTUREBASE  0x94
37 #define AMD64_GARTTABLEBASE     0x98
38 #define AMD64_GARTCACHECTL      0x9c
39 #define AMD64_GARTEN            (1<<0)
40
41 /* NVIDIA K8 registers */
42 #define NVIDIA_X86_64_0_APBASE          0x10
43 #define NVIDIA_X86_64_1_APBASE1         0x50
44 #define NVIDIA_X86_64_1_APLIMIT1        0x54
45 #define NVIDIA_X86_64_1_APSIZE          0xa8
46 #define NVIDIA_X86_64_1_APBASE2         0xd8
47 #define NVIDIA_X86_64_1_APLIMIT2        0xdc
48
49 static int nr_garts;
50 static struct pci_dev * hammers[MAX_HAMMER_GARTS];
51
52 static struct resource *aperture_resource;
53 static int __initdata agp_try_unsupported;
54
55 static int gart_iterator;
56 #define for_each_nb() for(gart_iterator=0;gart_iterator<nr_garts;gart_iterator++)
57
58 static void flush_amd64_tlb(struct pci_dev *dev)
59 {
60         u32 tmp;
61
62         pci_read_config_dword (dev, AMD64_GARTCACHECTL, &tmp);
63         tmp |= INVGART;
64         pci_write_config_dword (dev, AMD64_GARTCACHECTL, tmp);
65 }
66
67 static void amd64_tlbflush(struct agp_memory *temp)
68 {
69         for_each_nb()
70                 flush_amd64_tlb(hammers[gart_iterator]);
71 }
72
73 static int amd64_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
74 {
75         int i, j, num_entries;
76         long tmp;
77         u32 pte;
78
79         num_entries = agp_num_entries();
80
81         if (type != 0 || mem->type != 0)
82                 return -EINVAL;
83
84         /* Make sure we can fit the range in the gatt table. */
85         /* FIXME: could wrap */
86         if (((unsigned long)pg_start + mem->page_count) > num_entries)
87                 return -EINVAL;
88
89         j = pg_start;
90
91         /* gatt table should be empty. */
92         while (j < (pg_start + mem->page_count)) {
93                 if (!PGE_EMPTY(agp_bridge, agp_bridge->gatt_table[j]))
94                         return -EBUSY;
95                 j++;
96         }
97
98         if (mem->is_flushed == FALSE) {
99                 global_cache_flush();
100                 mem->is_flushed = TRUE;
101         }
102
103         for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
104                 tmp = agp_bridge->driver->mask_memory(mem->memory[i], mem->type);
105
106                 BUG_ON(tmp & 0xffffff0000000ffcULL);
107                 pte = (tmp & 0x000000ff00000000ULL) >> 28;
108                 pte |=(tmp & 0x00000000fffff000ULL);
109                 pte |= GPTE_VALID | GPTE_COHERENT;
110
111                 agp_bridge->gatt_table[j] = pte;
112         }
113         amd64_tlbflush(mem);
114         return 0;
115 }
116
117 /*
118  * This hack alters the order element according
119  * to the size of a long. It sucks. I totally disown this, even
120  * though it does appear to work for the most part.
121  */
122 static struct aper_size_info_32 amd64_aperture_sizes[7] =
123 {
124         {32,   8192,   3+(sizeof(long)/8), 0 },
125         {64,   16384,  4+(sizeof(long)/8), 1<<1 },
126         {128,  32768,  5+(sizeof(long)/8), 1<<2 },
127         {256,  65536,  6+(sizeof(long)/8), 1<<1 | 1<<2 },
128         {512,  131072, 7+(sizeof(long)/8), 1<<3 },
129         {1024, 262144, 8+(sizeof(long)/8), 1<<1 | 1<<3},
130         {2048, 524288, 9+(sizeof(long)/8), 1<<2 | 1<<3}
131 };
132
133
134 /*
135  * Get the current Aperture size from the x86-64.
136  * Note, that there may be multiple x86-64's, but we just return
137  * the value from the first one we find. The set_size functions
138  * keep the rest coherent anyway. Or at least should do.
139  */
140 static int amd64_fetch_size(void)
141 {
142         struct pci_dev *dev;
143         int i;
144         u32 temp;
145         struct aper_size_info_32 *values;
146
147         dev = hammers[0];
148         if (dev==NULL)
149                 return 0;
150
151         pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &temp);
152         temp = (temp & 0xe);
153         values = A_SIZE_32(amd64_aperture_sizes);
154
155         for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
156                 if (temp == values[i].size_value) {
157                         agp_bridge->previous_size =
158                             agp_bridge->current_size = (void *) (values + i);
159
160                         agp_bridge->aperture_size_idx = i;
161                         return values[i].size;
162                 }
163         }
164         return 0;
165 }
166
167 /*
168  * In a multiprocessor x86-64 system, this function gets
169  * called once for each CPU.
170  */
171 static u64 amd64_configure (struct pci_dev *hammer, u64 gatt_table)
172 {
173         u64 aperturebase;
174         u32 tmp;
175         u64 addr, aper_base;
176
177         /* Address to map to */
178         pci_read_config_dword (hammer, AMD64_GARTAPERTUREBASE, &tmp);
179         aperturebase = tmp << 25;
180         aper_base = (aperturebase & PCI_BASE_ADDRESS_MEM_MASK);
181
182         /* address of the mappings table */
183         addr = (u64) gatt_table;
184         addr >>= 12;
185         tmp = (u32) addr<<4;
186         tmp &= ~0xf;
187         pci_write_config_dword (hammer, AMD64_GARTTABLEBASE, tmp);
188
189         /* Enable GART translation for this hammer. */
190         pci_read_config_dword(hammer, AMD64_GARTAPERTURECTL, &tmp);
191         tmp |= GARTEN;
192         tmp &= ~(DISGARTCPU | DISGARTIO);
193         pci_write_config_dword(hammer, AMD64_GARTAPERTURECTL, tmp);
194
195         /* keep CPU's coherent. */
196         flush_amd64_tlb (hammer);
197         
198         return aper_base;
199 }
200
201
202 static struct aper_size_info_32 amd_8151_sizes[7] =
203 {
204         {2048, 524288, 9, 0x00000000 }, /* 0 0 0 0 0 0 */
205         {1024, 262144, 8, 0x00000400 }, /* 1 0 0 0 0 0 */
206         {512,  131072, 7, 0x00000600 }, /* 1 1 0 0 0 0 */
207         {256,  65536,  6, 0x00000700 }, /* 1 1 1 0 0 0 */
208         {128,  32768,  5, 0x00000720 }, /* 1 1 1 1 0 0 */
209         {64,   16384,  4, 0x00000730 }, /* 1 1 1 1 1 0 */
210         {32,   8192,   3, 0x00000738 }  /* 1 1 1 1 1 1 */
211 };
212
213 static int amd_8151_configure(void)
214 {
215         unsigned long gatt_bus = virt_to_phys(agp_bridge->gatt_table_real);
216
217         /* Configure AGP regs in each x86-64 host bridge. */
218         for_each_nb() {
219                 agp_bridge->gart_bus_addr =
220                                 amd64_configure(hammers[gart_iterator],gatt_bus);
221         }
222         return 0;
223 }
224
225
226 static void amd64_cleanup(void)
227 {
228         u32 tmp;
229
230         for_each_nb() {
231                 /* disable gart translation */
232                 pci_read_config_dword (hammers[gart_iterator], AMD64_GARTAPERTURECTL, &tmp);
233                 tmp &= ~AMD64_GARTEN;
234                 pci_write_config_dword (hammers[gart_iterator], AMD64_GARTAPERTURECTL, tmp);
235         }
236 }
237
238
239 struct agp_bridge_driver amd_8151_driver = {
240         .owner                  = THIS_MODULE,
241         .aperture_sizes         = amd_8151_sizes,
242         .size_type              = U32_APER_SIZE,
243         .num_aperture_sizes     = 7,
244         .configure              = amd_8151_configure,
245         .fetch_size             = amd64_fetch_size,
246         .cleanup                = amd64_cleanup,
247         .tlb_flush              = amd64_tlbflush,
248         .mask_memory            = agp_generic_mask_memory,
249         .masks                  = NULL,
250         .agp_enable             = agp_generic_enable,
251         .cache_flush            = global_cache_flush,
252         .create_gatt_table      = agp_generic_create_gatt_table,
253         .free_gatt_table        = agp_generic_free_gatt_table,
254         .insert_memory          = amd64_insert_memory,
255         .remove_memory          = agp_generic_remove_memory,
256         .alloc_by_type          = agp_generic_alloc_by_type,
257         .free_by_type           = agp_generic_free_by_type,
258         .agp_alloc_page         = agp_generic_alloc_page,
259         .agp_destroy_page       = agp_generic_destroy_page,
260 };
261
262 /* Some basic sanity checks for the aperture. */
263 static int __devinit aperture_valid(u64 aper, u32 size)
264
265         u32 pfn, c;
266         if (aper == 0) { 
267                 printk(KERN_ERR PFX "No aperture\n");
268                 return 0; 
269         }
270         if (size < 32*1024*1024) {
271                 printk(KERN_ERR PFX "Aperture too small (%d MB)\n", size>>20);
272                 return 0;
273         }
274         if (aper + size > 0xffffffff) { 
275                 printk(KERN_ERR PFX "Aperture out of bounds\n"); 
276                 return 0;
277         } 
278         pfn = aper >> PAGE_SHIFT;
279         for (c = 0; c < size/PAGE_SIZE; c++) { 
280                 if (!pfn_valid(pfn + c))
281                         break;
282                 if (!PageReserved(pfn_to_page(pfn + c))) { 
283                         printk(KERN_ERR PFX "Aperture pointing to RAM\n");
284                         return 0;
285                 }
286         }
287
288         /* Request the Aperture. This catches cases when someone else
289            already put a mapping in there - happens with some very broken BIOS 
290
291            Maybe better to use pci_assign_resource/pci_enable_device instead trusting
292            the bridges? */
293         if (!aperture_resource &&
294             !(aperture_resource = request_mem_region(aper, size, "aperture"))) {
295                 printk(KERN_ERR PFX "Aperture conflicts with PCI mapping.\n"); 
296                 return 0;
297         }
298         return 1;
299
300
301 /* 
302  * W*s centric BIOS sometimes only set up the aperture in the AGP
303  * bridge, not the northbridge. On AMD64 this is handled early 
304  * in aperture.c, but when GART_IOMMU is not enabled or we run
305  * on a 32bit kernel this needs to be redone. 
306  * Unfortunately it is impossible to fix the aperture here because it's too late
307  * to allocate that much memory. But at least error out cleanly instead of
308  * crashing.
309  */ 
310 static __devinit int fix_northbridge(struct pci_dev *nb, struct pci_dev *agp, 
311                                                                  u16 cap)
312 {
313         u32 aper_low, aper_hi;
314         u64 aper, nb_aper;
315         int order = 0;
316         u32 nb_order, nb_base;
317         u16 apsize;
318
319         pci_read_config_dword(nb, 0x90, &nb_order); 
320         nb_order = (nb_order >> 1) & 7;
321         pci_read_config_dword(nb, 0x94, &nb_base); 
322         nb_aper = nb_base << 25;        
323         if (aperture_valid(nb_aper, (32*1024*1024)<<nb_order)) { 
324                 return 0;
325         }
326
327         /* Northbridge seems to contain crap. Try the AGP bridge. */
328
329         pci_read_config_word(agp, cap+0x14, &apsize); 
330         if (apsize == 0xffff) 
331                 return -1; 
332
333         apsize &= 0xfff;
334         /* Some BIOS use weird encodings not in the AGPv3 table. */
335         if (apsize & 0xff) 
336                 apsize |= 0xf00; 
337         order = 7 - hweight16(apsize); 
338
339         pci_read_config_dword(agp, 0x10, &aper_low);
340         pci_read_config_dword(agp, 0x14, &aper_hi);
341         aper = (aper_low & ~((1<<22)-1)) | ((u64)aper_hi << 32); 
342         printk(KERN_INFO PFX "Aperture from AGP @ %Lx size %u MB\n", aper, 32 << order);
343         if (order < 0 || !aperture_valid(aper, (32*1024*1024)<<order))
344                 return -1; 
345         
346         pci_write_config_dword(nb, 0x90, order << 1); 
347         pci_write_config_dword(nb, 0x94, aper >> 25); 
348
349         return 0;
350
351
352 static __devinit int cache_nbs (struct pci_dev *pdev, u32 cap_ptr)
353 {
354         struct pci_dev *loop_dev = NULL;
355         int i = 0;
356
357         /* cache pci_devs of northbridges. */
358         while ((loop_dev = pci_find_device(PCI_VENDOR_ID_AMD, 0x1103, loop_dev)) 
359                         != NULL) {
360                 if (i == MAX_HAMMER_GARTS) { 
361                         printk(KERN_ERR PFX "Too many northbridges for AGP\n");
362                         return -1;
363                 }
364                 if (fix_northbridge(loop_dev, pdev, cap_ptr) < 0) { 
365                         printk(KERN_ERR PFX "No usable aperture found.\n");
366 #ifdef __x86_64__ 
367                         /* should port this to i386 */
368                         printk(KERN_ERR PFX "Consider rebooting with iommu=memaper=2 to get a good aperture.\n");
369 #endif 
370                         return -1;  
371                 }
372                 hammers[i++] = loop_dev;
373         }
374                 nr_garts = i;
375         return i == 0 ? -1 : 0;
376 }
377
378 /* Handle AMD 8151 quirks */
379 static void __devinit amd8151_init(struct pci_dev *pdev, struct agp_bridge_data *bridge)
380
381 {               
382         char *revstring;
383         u8 rev_id;
384
385         pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
386         switch (rev_id) {
387         case 0x01: revstring="A0"; break;
388         case 0x02: revstring="A1"; break;
389         case 0x11: revstring="B0"; break;
390         case 0x12: revstring="B1"; break;
391         case 0x13: revstring="B2"; break;
392         case 0x14: revstring="B3"; break;
393         default:   revstring="??"; break;
394         }
395
396         printk (KERN_INFO PFX "Detected AMD 8151 AGP Bridge rev %s\n", revstring);
397
398         /*
399          * Work around errata.
400          * Chips before B2 stepping incorrectly reporting v3.5
401          */
402         if (rev_id < 0x13) {
403                 printk (KERN_INFO PFX "Correcting AGP revision (reports 3.5, is really 3.0)\n");
404                 bridge->major_version = 3;
405                 bridge->minor_version = 0;
406         }
407 }
408
409 static struct aper_size_info_32 nforce3_sizes[5] =
410 {
411         {512,  131072, 7, 0x00000000 },
412         {256,  65536,  6, 0x00000008 },
413         {128,  32768,  5, 0x0000000C },
414         {64,   16384,  4, 0x0000000E },
415         {32,   8192,   3, 0x0000000F }
416 };
417
418 /* Handle shadow device of the Nvidia NForce3 */
419 /* CHECK-ME original 2.4 version set up some IORRs. Check if that is needed. */
420 static int __devinit nforce3_agp_init(struct pci_dev *pdev) 
421
422         u32 tmp, apbase, apbar, aplimit;
423         struct pci_dev *dev1; 
424         int i;
425         unsigned size = amd64_fetch_size(); 
426
427         printk(KERN_INFO PFX "Setting up Nforce3 AGP.\n");
428
429         dev1 = pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(11, 0));
430         if (dev1 == NULL) {
431                 printk(KERN_INFO PFX "agpgart: Detected an NVIDIA "
432                         "nForce3 chipset, but could not find "
433                         "the secondary device.\n");
434                 return -ENODEV;
435         }       
436
437         for (i = 0; i < ARRAY_SIZE(nforce3_sizes); i++) 
438                 if (nforce3_sizes[i].size == size)
439                         break; 
440
441         if (i == ARRAY_SIZE(nforce3_sizes)) {
442                 printk(KERN_INFO PFX "No NForce3 size found for %d\n", size); 
443                 return -ENODEV; 
444         }
445         
446         pci_read_config_dword(dev1, NVIDIA_X86_64_1_APSIZE, &tmp);
447         tmp &= ~(0xf);
448         tmp |= nforce3_sizes[i].size_value;
449         pci_write_config_dword(dev1, NVIDIA_X86_64_1_APSIZE, tmp);
450
451         /* shadow x86-64 registers into NVIDIA registers */
452         pci_read_config_dword (hammers[0], AMD64_GARTAPERTUREBASE, &apbase);
453
454         /* if x86-64 aperture base is beyond 4G, exit here */
455         if ( (apbase & 0x7fff) >> (32 - 25) )
456                  return -ENODEV;
457
458         apbase = (apbase & 0x7fff) << 25;
459
460         pci_read_config_dword(pdev, NVIDIA_X86_64_0_APBASE, &apbar);
461         apbar &= ~PCI_BASE_ADDRESS_MEM_MASK;
462         apbar |= apbase;
463         pci_write_config_dword(pdev, NVIDIA_X86_64_0_APBASE, apbar);
464
465         aplimit = apbase + (size * 1024 * 1024) - 1;
466         pci_write_config_dword(dev1, NVIDIA_X86_64_1_APBASE1, apbase);
467         pci_write_config_dword(dev1, NVIDIA_X86_64_1_APLIMIT1, aplimit);
468         pci_write_config_dword(dev1, NVIDIA_X86_64_1_APBASE2, apbase);
469         pci_write_config_dword(dev1, NVIDIA_X86_64_1_APLIMIT2, aplimit);
470
471         return 0;
472 }
473
474 static int __devinit agp_amd64_probe(struct pci_dev *pdev,
475                                      const struct pci_device_id *ent)
476 {
477         struct agp_bridge_data *bridge;
478         u8 cap_ptr;
479
480         cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
481         if (!cap_ptr)
482                 return -ENODEV;
483
484         /* Could check for AGPv3 here */
485
486         bridge = agp_alloc_bridge();
487         if (!bridge)
488                 return -ENOMEM;
489
490         if (pdev->vendor == PCI_VENDOR_ID_AMD &&
491             pdev->device == PCI_DEVICE_ID_AMD_8151_0) {
492                 amd8151_init(pdev, bridge);
493         } else {
494                 printk(KERN_INFO PFX "Detected AGP bridge %x\n",
495                         pdev->devfn);
496         }
497
498         bridge->driver = &amd_8151_driver;
499         bridge->dev = pdev;
500         bridge->capndx = cap_ptr;
501
502         /* Fill in the mode register */
503         pci_read_config_dword(pdev, bridge->capndx+PCI_AGP_STATUS, &bridge->mode);
504
505         if (cache_nbs(pdev, cap_ptr) == -1) {
506                 agp_put_bridge(bridge);
507                 return -ENODEV;
508         }
509
510         if (pdev->vendor == PCI_VENDOR_ID_NVIDIA) { 
511                 int ret = nforce3_agp_init(pdev);
512                 if (ret) { 
513                         agp_put_bridge(bridge); 
514                         return ret;
515                 }
516         }
517
518         pci_set_drvdata(pdev, bridge);
519         return agp_add_bridge(bridge);
520 }
521
522 static void __devexit agp_amd64_remove(struct pci_dev *pdev)
523 {
524         struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
525
526         release_mem_region(virt_to_phys(bridge->gatt_table_real), 
527                            amd64_aperture_sizes[bridge->aperture_size_idx].size); 
528         agp_remove_bridge(bridge);
529         agp_put_bridge(bridge);
530 }
531
532 static struct pci_device_id agp_amd64_pci_table[] = {
533         {
534         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
535         .class_mask     = ~0,
536         .vendor         = PCI_VENDOR_ID_AMD,
537         .device         = PCI_DEVICE_ID_AMD_8151_0,
538         .subvendor      = PCI_ANY_ID,
539         .subdevice      = PCI_ANY_ID,
540         },
541         /* VIA K8T800 */
542         {
543         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
544         .class_mask     = ~0,
545         .vendor         = PCI_VENDOR_ID_VIA,
546         .device         = PCI_DEVICE_ID_VIA_8385_0,
547         .subvendor      = PCI_ANY_ID,
548         .subdevice      = PCI_ANY_ID,
549         },
550         /* VIA K8M800 / K8N800 */
551         {
552         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
553         .class_mask     = ~0,
554         .vendor         = PCI_VENDOR_ID_VIA,
555         .device         = PCI_DEVICE_ID_VIA_8380_0,
556         .subvendor      = PCI_ANY_ID,
557         .subdevice      = PCI_ANY_ID,
558         },
559         {
560         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
561         .class_mask     = ~0,
562         .vendor         = PCI_VENDOR_ID_VIA,
563         .device         = PCI_DEVICE_ID_VIA_8380_0,
564         .subvendor      = PCI_ANY_ID,
565         .subdevice      = PCI_ANY_ID,
566         },
567         /* NForce3 */
568         {
569         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
570         .class_mask     = ~0,
571         .vendor         = PCI_VENDOR_ID_NVIDIA,
572         .device         = PCI_DEVICE_ID_NVIDIA_NFORCE3,
573         .subvendor      = PCI_ANY_ID,
574         .subdevice      = PCI_ANY_ID,
575         },
576         {
577         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
578         .class_mask     = ~0,
579         .vendor         = PCI_VENDOR_ID_NVIDIA,
580         .device         = PCI_DEVICE_ID_NVIDIA_NFORCE3S,
581         .subvendor      = PCI_ANY_ID,
582         .subdevice      = PCI_ANY_ID,
583         },
584         { }
585 };
586
587 MODULE_DEVICE_TABLE(pci, agp_amd64_pci_table);
588
589 static struct pci_driver agp_amd64_pci_driver = {
590         .name           = "agpgart-amd64",
591         .id_table       = agp_amd64_pci_table,
592         .probe          = agp_amd64_probe,
593         .remove         = agp_amd64_remove,
594 };
595
596
597 /* Not static due to IOMMU code calling it early. */
598 int __init agp_amd64_init(void)
599 {
600         int err = 0;
601         if (agp_off)
602                 return -EINVAL;
603         if (pci_module_init(&agp_amd64_pci_driver) > 0) { 
604                 struct pci_dev *dev;
605                 if (!agp_try_unsupported && !agp_try_unsupported_boot) { 
606                         printk(KERN_INFO PFX "No supported AGP bridge found.\n");
607 #ifdef MODULE                   
608                         printk(KERN_INFO PFX "You can try agp_try_unsupported=1\n");
609 #else
610                         printk(KERN_INFO PFX "You can boot with agp=try_unsupported\n");
611 #endif                  
612                         return -ENODEV;
613                 }
614
615                 /* First check that we have at least one AMD64 NB */
616                 if (!pci_find_device(PCI_VENDOR_ID_AMD, 0x1103, NULL))
617                         return -ENODEV;
618
619                 /* Look for any AGP bridge */
620                 dev = NULL;
621                 err = -ENODEV;
622                 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev))) {
623                         if (!pci_find_capability(dev, PCI_CAP_ID_AGP))
624                                 continue;
625                         /* Only one bridge supported right now */       
626                         if (agp_amd64_probe(dev, NULL) == 0) {
627                                 err = 0;
628                                 break;
629                         }       
630                 }               
631         }
632         return err;
633 }
634
635 static void __exit agp_amd64_cleanup(void)
636 {
637         if (aperture_resource)
638                 release_resource(aperture_resource);
639         pci_unregister_driver(&agp_amd64_pci_driver);
640 }
641
642 /* On AMD64 the PCI driver needs to initialize this driver early
643    for the IOMMU, so it has to be called via a backdoor. */
644 #ifndef CONFIG_GART_IOMMU
645 module_init(agp_amd64_init);
646 module_exit(agp_amd64_cleanup);
647 #endif
648
649 MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>, Andi Kleen");
650 MODULE_PARM(agp_try_unsupported, "1i");
651 MODULE_LICENSE("GPL and additional rights");