11 #include <linux/module.h>
12 #include <linux/pci.h>
23 #define NVIDIA_X86_64_0_APBASE 0x10
24 #define NVIDIA_X86_64_1_APBASE1 0x50
25 #define NVIDIA_X86_64_1_APLIMIT1 0x54
26 #define NVIDIA_X86_64_1_APSIZE 0xa8
27 #define NVIDIA_X86_64_1_APBASE2 0xd8
28 #define NVIDIA_X86_64_1_APLIMIT2 0xdc
31 #define ULI_X86_64_BASE_ADDR 0x10
32 #define ULI_X86_64_HTT_FEA_REG 0x50
33 #define ULI_X86_64_ENU_SCR_REG 0x54
35 static struct resource *aperture_resource;
36 static bool __initdata agp_try_unsupported = 1;
37 static int agp_bridges_found;
54 if (type != mem->
type)
56 mask_type = bridge->
driver->agp_type_to_mask_type(bridge, type);
63 if (((
unsigned long)pg_start + mem->
page_count) > num_entries)
80 for (i = 0, j = pg_start; i < mem->
page_count; i++, j++) {
85 BUG_ON(tmp & 0xffffff0000000ffcULL);
86 pte = (tmp & 0x000000ff00000000ULL) >> 28;
87 pte |=(tmp & 0x00000000fffff000ULL);
104 {32, 8192, 3+(
sizeof(
long)/8), 0 },
105 {64, 16384, 4+(
sizeof(
long)/8), 1<<1 },
106 {128, 32768, 5+(
sizeof(
long)/8), 1<<2 },
107 {256, 65536, 6+(
sizeof(
long)/8), 1<<1 | 1<<2 },
108 {512, 131072, 7+(
sizeof(
long)/8), 1<<3 },
109 {1024, 262144, 8+(
sizeof(
long)/8), 1<<1 | 1<<3},
110 {2048, 524288, 9+(
sizeof(
long)/8), 1<<2 | 1<<3}
120 static int amd64_fetch_size(
void)
133 values =
A_SIZE_32(amd64_aperture_sizes);
135 for (i = 0; i <
agp_bridge->driver->num_aperture_sizes; i++) {
138 agp_bridge->current_size = (
void *) (values + i);
141 return values[
i].
size;
151 static u64 amd64_configure(
struct pci_dev *hammer,
u64 gatt_table)
159 aperturebase = tmp << 25;
162 enable_gart_translation(hammer, gatt_table);
170 {2048, 524288, 9, 0x00000000 },
171 {1024, 262144, 8, 0x00000400 },
172 {512, 131072, 7, 0x00000600 },
173 {256, 65536, 6, 0x00000700 },
174 {128, 32768, 5, 0x00000720 },
175 {64, 16384, 4, 0x00000730 },
176 {32, 8192, 3, 0x00000738 }
179 static int amd_8151_configure(
void)
197 static void amd64_cleanup(
void)
217 .aperture_sizes = amd_8151_sizes,
219 .num_aperture_sizes = 7,
220 .needs_scratch_page =
true,
221 .configure = amd_8151_configure,
222 .fetch_size = amd64_fetch_size,
223 .cleanup = amd64_cleanup,
224 .tlb_flush = amd64_tlbflush,
231 .insert_memory = amd64_insert_memory,
245 if (!aperture_valid(aper, size, 32*1024*1024))
253 if (!aperture_resource &&
273 u32 aper_low, aper_hi;
276 u32 nb_order, nb_base;
280 nb_order = (nb_order >> 1) & 7;
282 nb_aper = nb_base << 25;
286 pci_read_config_word(agp, cap+0x14, &apsize);
287 if (apsize == 0xffff) {
288 if (agp_aperture_valid(nb_aper, (32*1024*1024)<<nb_order))
299 pci_read_config_dword(agp, 0x10, &aper_low);
300 pci_read_config_dword(agp, 0x14, &aper_hi);
301 aper = (aper_low & ~((1<<22)-1)) | ((
u64)aper_hi << 32);
307 if (order >=0 && aper + (32ULL<<(20 + order)) > 0x100000000ULL) {
308 dev_info(&agp->
dev,
"aperture size %u MB is not right, using settings from NB\n",
313 if (nb_order >= order) {
314 if (agp_aperture_valid(nb_aper, (32*1024*1024)<<nb_order))
318 dev_info(&agp->
dev,
"aperture from AGP @ %Lx size %u MB\n",
320 if (order < 0 || !agp_aperture_valid(aper, (32*1024*1024)<<order))
323 gart_set_size_and_enable(nb, order);
342 if (fix_northbridge(dev, pdev, cap_ptr) < 0) {
343 dev_err(&dev->
dev,
"no usable aperture found\n");
346 dev_err(&dev->
dev,
"consider rebooting with iommu=memaper=2 to get a good aperture\n");
360 case 0x01: revstring=
"A0";
break;
361 case 0x02: revstring=
"A1";
break;
362 case 0x11: revstring=
"B0";
break;
363 case 0x12: revstring=
"B1";
break;
364 case 0x13: revstring=
"B2";
break;
365 case 0x14: revstring=
"B3";
break;
366 default: revstring=
"??";
break;
369 dev_info(&pdev->
dev,
"AMD 8151 AGP Bridge rev %s\n", revstring);
376 dev_info(&pdev->
dev,
"correcting AGP revision (reports 3.5, is really 3.0)\n");
395 u32 httfea,baseaddr,enuscr;
398 unsigned size = amd64_fetch_size();
403 dev_info(&pdev->
dev,
"can't find ULi secondary device\n");
408 if (uli_sizes[i].size == size)
412 dev_info(&pdev->
dev,
"no ULi size found for %d\n", size);
422 if ((httfea & 0x7fff) >> (32 - 25)) {
427 httfea = (httfea& 0x7fff) << 25;
434 enuscr= httfea+ (size * 1024 * 1024) - 1;
446 {512, 131072, 7, 0x00000000 },
447 {256, 65536, 6, 0x00000008 },
448 {128, 32768, 5, 0x0000000C },
449 {64, 16384, 4, 0x0000000E },
450 {32, 8192, 3, 0x0000000F }
455 static int nforce3_agp_init(
struct pci_dev *pdev)
457 u32 tmp, apbase, apbar, aplimit;
460 unsigned size = amd64_fetch_size();
466 dev_info(&pdev->
dev,
"can't find Nforce3 secondary device\n");
470 for (i = 0; i <
ARRAY_SIZE(nforce3_sizes); i++)
471 if (nforce3_sizes[i].size == size)
475 dev_info(&pdev->
dev,
"no NForce3 size found for %d\n", size);
490 if ( (apbase & 0x7fff) >> (32 - 25) ) {
496 apbase = (apbase & 0x7fff) << 25;
503 aplimit = apbase + (size * 1024 * 1024) - 1;
524 if (agp_bridges_found)
539 amd8151_init(pdev, bridge);
545 bridge->
driver = &amd_8151_driver;
552 if (cache_nbs(pdev, cap_ptr) == -1) {
558 int ret = nforce3_agp_init(pdev);
566 int ret = uli_agp_init(pdev);
573 pci_set_drvdata(pdev, bridge);
604 static int agp_amd64_resume(
struct pci_dev *pdev)
610 nforce3_agp_init(pdev);
612 return amd_8151_configure();
744 static struct pci_driver agp_amd64_pci_driver = {
745 .name =
"agpgart-amd64",
746 .id_table = agp_amd64_pci_table,
747 .probe = agp_amd64_probe,
748 .remove = agp_amd64_remove,
750 .suspend = agp_amd64_suspend,
751 .resume = agp_amd64_resume,
764 err = pci_register_driver(&agp_amd64_pci_driver);
768 if (agp_bridges_found == 0) {
787 agp_amd64_pci_driver.
id_table = agp_amd64_pci_promisc_table;
789 if (err == 0 && agp_bridges_found == 0) {
797 static int __init agp_amd64_mod_init(
void)
801 return agp_bridges_found ? 0 : -
ENODEV;
806 static void __exit agp_amd64_cleanup(
void)
812 if (aperture_resource)