amd64-agp.c 20 KB

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