amd64-agp.c 20 KB

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