amd64-agp.c 20 KB

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