amd64-agp.c 20 KB

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