amd64-agp.c 20 KB

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