amd64-agp.c 20 KB

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