patch-2_6_7-vs1_9_1_12
[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
292            trusting 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         char *revstring;
382         u8 rev_id;
383
384         pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
385         switch (rev_id) {
386         case 0x01: revstring="A0"; break;
387         case 0x02: revstring="A1"; break;
388         case 0x11: revstring="B0"; break;
389         case 0x12: revstring="B1"; break;
390         case 0x13: revstring="B2"; break;
391         case 0x14: revstring="B3"; break;
392         default:   revstring="??"; break;
393         }
394
395         printk (KERN_INFO PFX "Detected AMD 8151 AGP Bridge rev %s\n", revstring);
396
397         /*
398          * Work around errata.
399          * Chips before B2 stepping incorrectly reporting v3.5
400          */
401         if (rev_id < 0x13) {
402                 printk (KERN_INFO PFX "Correcting AGP revision (reports 3.5, is really 3.0)\n");
403                 bridge->major_version = 3;
404                 bridge->minor_version = 0;
405         }
406 }
407
408 static struct aper_size_info_32 nforce3_sizes[5] =
409 {
410         {512,  131072, 7, 0x00000000 },
411         {256,  65536,  6, 0x00000008 },
412         {128,  32768,  5, 0x0000000C },
413         {64,   16384,  4, 0x0000000E },
414         {32,   8192,   3, 0x0000000F }
415 };
416
417 /* Handle shadow device of the Nvidia NForce3 */
418 /* CHECK-ME original 2.4 version set up some IORRs. Check if that is needed. */
419 static int __devinit nforce3_agp_init(struct pci_dev *pdev)
420 {
421         u32 tmp, apbase, apbar, aplimit;
422         struct pci_dev *dev1;
423         int i;
424         unsigned size = amd64_fetch_size();
425
426         printk(KERN_INFO PFX "Setting up Nforce3 AGP.\n");
427
428         dev1 = pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(11, 0));
429         if (dev1 == NULL) {
430                 printk(KERN_INFO PFX "agpgart: Detected an NVIDIA "
431                         "nForce3 chipset, but could not find "
432                         "the secondary device.\n");
433                 return -ENODEV;
434         }
435
436         for (i = 0; i < ARRAY_SIZE(nforce3_sizes); i++)
437                 if (nforce3_sizes[i].size == size)
438                         break;
439
440         if (i == ARRAY_SIZE(nforce3_sizes)) {
441                 printk(KERN_INFO PFX "No NForce3 size found for %d\n", size);
442                 return -ENODEV;
443         }
444
445         pci_read_config_dword(dev1, NVIDIA_X86_64_1_APSIZE, &tmp);
446         tmp &= ~(0xf);
447         tmp |= nforce3_sizes[i].size_value;
448         pci_write_config_dword(dev1, NVIDIA_X86_64_1_APSIZE, tmp);
449
450         /* shadow x86-64 registers into NVIDIA registers */
451         pci_read_config_dword (hammers[0], AMD64_GARTAPERTUREBASE, &apbase);
452
453         /* if x86-64 aperture base is beyond 4G, exit here */
454         if ( (apbase & 0x7fff) >> (32 - 25) )
455                  return -ENODEV;
456
457         apbase = (apbase & 0x7fff) << 25;
458
459         pci_read_config_dword(pdev, NVIDIA_X86_64_0_APBASE, &apbar);
460         apbar &= ~PCI_BASE_ADDRESS_MEM_MASK;
461         apbar |= apbase;
462         pci_write_config_dword(pdev, NVIDIA_X86_64_0_APBASE, apbar);
463
464         aplimit = apbase + (size * 1024 * 1024) - 1;
465         pci_write_config_dword(dev1, NVIDIA_X86_64_1_APBASE1, apbase);
466         pci_write_config_dword(dev1, NVIDIA_X86_64_1_APLIMIT1, aplimit);
467         pci_write_config_dword(dev1, NVIDIA_X86_64_1_APBASE2, apbase);
468         pci_write_config_dword(dev1, NVIDIA_X86_64_1_APLIMIT2, aplimit);
469
470         return 0;
471 }
472
473 static int __devinit agp_amd64_probe(struct pci_dev *pdev,
474                                      const struct pci_device_id *ent)
475 {
476         struct agp_bridge_data *bridge;
477         u8 cap_ptr;
478
479         cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
480         if (!cap_ptr)
481                 return -ENODEV;
482
483         /* Could check for AGPv3 here */
484
485         bridge = agp_alloc_bridge();
486         if (!bridge)
487                 return -ENOMEM;
488
489         if (pdev->vendor == PCI_VENDOR_ID_AMD &&
490             pdev->device == PCI_DEVICE_ID_AMD_8151_0) {
491                 amd8151_init(pdev, bridge);
492         } else {
493                 printk(KERN_INFO PFX "Detected AGP bridge %x\n", pdev->devfn);
494         }
495
496         bridge->driver = &amd_8151_driver;
497         bridge->dev = pdev;
498         bridge->capndx = cap_ptr;
499
500         /* Fill in the mode register */
501         pci_read_config_dword(pdev, bridge->capndx+PCI_AGP_STATUS, &bridge->mode);
502
503         if (cache_nbs(pdev, cap_ptr) == -1) {
504                 agp_put_bridge(bridge);
505                 return -ENODEV;
506         }
507
508         if (pdev->vendor == PCI_VENDOR_ID_NVIDIA) {
509                 int ret = nforce3_agp_init(pdev);
510                 if (ret) {
511                         agp_put_bridge(bridge);
512                         return ret;
513                 }
514         }
515
516         pci_set_drvdata(pdev, bridge);
517         return agp_add_bridge(bridge);
518 }
519
520 static void __devexit agp_amd64_remove(struct pci_dev *pdev)
521 {
522         struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
523
524         release_mem_region(virt_to_phys(bridge->gatt_table_real),
525                            amd64_aperture_sizes[bridge->aperture_size_idx].size);
526         agp_remove_bridge(bridge);
527         agp_put_bridge(bridge);
528 }
529
530 static struct pci_device_id agp_amd64_pci_table[] = {
531         {
532         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
533         .class_mask     = ~0,
534         .vendor         = PCI_VENDOR_ID_AMD,
535         .device         = PCI_DEVICE_ID_AMD_8151_0,
536         .subvendor      = PCI_ANY_ID,
537         .subdevice      = PCI_ANY_ID,
538         },
539         /* VIA K8T800 */
540         {
541         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
542         .class_mask     = ~0,
543         .vendor         = PCI_VENDOR_ID_VIA,
544         .device         = PCI_DEVICE_ID_VIA_8385_0,
545         .subvendor      = PCI_ANY_ID,
546         .subdevice      = PCI_ANY_ID,
547         },
548         /* VIA K8M800 / K8N800 */
549         {
550         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
551         .class_mask     = ~0,
552         .vendor         = PCI_VENDOR_ID_VIA,
553         .device         = PCI_DEVICE_ID_VIA_8380_0,
554         .subvendor      = PCI_ANY_ID,
555         .subdevice      = PCI_ANY_ID,
556         },
557         {
558         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
559         .class_mask     = ~0,
560         .vendor         = PCI_VENDOR_ID_VIA,
561         .device         = PCI_DEVICE_ID_VIA_8380_0,
562         .subvendor      = PCI_ANY_ID,
563         .subdevice      = PCI_ANY_ID,
564         },
565         /* NForce3 */
566         {
567         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
568         .class_mask     = ~0,
569         .vendor         = PCI_VENDOR_ID_NVIDIA,
570         .device         = PCI_DEVICE_ID_NVIDIA_NFORCE3,
571         .subvendor      = PCI_ANY_ID,
572         .subdevice      = PCI_ANY_ID,
573         },
574         {
575         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
576         .class_mask     = ~0,
577         .vendor         = PCI_VENDOR_ID_NVIDIA,
578         .device         = PCI_DEVICE_ID_NVIDIA_NFORCE3S,
579         .subvendor      = PCI_ANY_ID,
580         .subdevice      = PCI_ANY_ID,
581         },
582         /* SIS 755 */
583         {
584         .class          = (PCI_CLASS_BRIDGE_HOST << 8),
585         .class_mask     = ~0,
586         .vendor         = PCI_VENDOR_ID_SI,
587         .device         = PCI_DEVICE_ID_SI_755,
588         .subvendor      = PCI_ANY_ID,
589         .subdevice      = PCI_ANY_ID,
590         },
591         { }
592 };
593
594 MODULE_DEVICE_TABLE(pci, agp_amd64_pci_table);
595
596 static struct pci_driver agp_amd64_pci_driver = {
597         .name           = "agpgart-amd64",
598         .id_table       = agp_amd64_pci_table,
599         .probe          = agp_amd64_probe,
600         .remove         = agp_amd64_remove,
601 };
602
603
604 /* Not static due to IOMMU code calling it early. */
605 int __init agp_amd64_init(void)
606 {
607         int err = 0;
608         if (agp_off)
609                 return -EINVAL;
610         if (pci_module_init(&agp_amd64_pci_driver) > 0) {
611                 struct pci_dev *dev;
612                 if (!agp_try_unsupported && !agp_try_unsupported_boot) {
613                         printk(KERN_INFO PFX "No supported AGP bridge found.\n");
614 #ifdef MODULE
615                         printk(KERN_INFO PFX "You can try agp_try_unsupported=1\n");
616 #else
617                         printk(KERN_INFO PFX "You can boot with agp=try_unsupported\n");
618 #endif
619                         return -ENODEV;
620                 }
621
622                 /* First check that we have at least one AMD64 NB */
623                 if (!pci_find_device(PCI_VENDOR_ID_AMD, 0x1103, NULL))
624                         return -ENODEV;
625
626                 /* Look for any AGP bridge */
627                 dev = NULL;
628                 err = -ENODEV;
629                 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev))) {
630                         if (!pci_find_capability(dev, PCI_CAP_ID_AGP))
631                                 continue;
632                         /* Only one bridge supported right now */
633                         if (agp_amd64_probe(dev, NULL) == 0) {
634                                 err = 0;
635                                 break;
636                         }
637                 }
638         }
639         return err;
640 }
641
642 static void __exit agp_amd64_cleanup(void)
643 {
644         if (aperture_resource)
645                 release_resource(aperture_resource);
646         pci_unregister_driver(&agp_amd64_pci_driver);
647 }
648
649 /* On AMD64 the PCI driver needs to initialize this driver early
650    for the IOMMU, so it has to be called via a backdoor. */
651 #ifndef CONFIG_GART_IOMMU
652 module_init(agp_amd64_init);
653 module_exit(agp_amd64_cleanup);
654 #endif
655
656 MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>, Andi Kleen");
657 MODULE_PARM(agp_try_unsupported, "1i");
658 MODULE_LICENSE("GPL and additional rights");