amd64-agp.c 20 KB

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