amd64-agp.c 20 KB

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