i460-agp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * For documentation on the i460 AGP interface, see Chapter 7 (AGP Subsystem) of
  3. * the "Intel 460GTX Chipset Software Developer's Manual":
  4. * http://www.intel.com/design/archives/itanium/downloads/248704.htm
  5. */
  6. /*
  7. * 460GX support by Chris Ahna <christopher.j.ahna@intel.com>
  8. * Clean up & simplification by David Mosberger-Tang <davidm@hpl.hp.com>
  9. */
  10. #include <linux/module.h>
  11. #include <linux/pci.h>
  12. #include <linux/init.h>
  13. #include <linux/string.h>
  14. #include <linux/slab.h>
  15. #include <linux/agp_backend.h>
  16. #include <linux/log2.h>
  17. #include "agp.h"
  18. #define INTEL_I460_BAPBASE 0x98
  19. #define INTEL_I460_GXBCTL 0xa0
  20. #define INTEL_I460_AGPSIZ 0xa2
  21. #define INTEL_I460_ATTBASE 0xfe200000
  22. #define INTEL_I460_GATT_VALID (1UL << 24)
  23. #define INTEL_I460_GATT_COHERENT (1UL << 25)
  24. /*
  25. * The i460 can operate with large (4MB) pages, but there is no sane way to support this
  26. * within the current kernel/DRM environment, so we disable the relevant code for now.
  27. * See also comments in ia64_alloc_page()...
  28. */
  29. #define I460_LARGE_IO_PAGES 0
  30. #if I460_LARGE_IO_PAGES
  31. # define I460_IO_PAGE_SHIFT i460.io_page_shift
  32. #else
  33. # define I460_IO_PAGE_SHIFT 12
  34. #endif
  35. #define I460_IOPAGES_PER_KPAGE (PAGE_SIZE >> I460_IO_PAGE_SHIFT)
  36. #define I460_KPAGES_PER_IOPAGE (1 << (I460_IO_PAGE_SHIFT - PAGE_SHIFT))
  37. #define I460_SRAM_IO_DISABLE (1 << 4)
  38. #define I460_BAPBASE_ENABLE (1 << 3)
  39. #define I460_AGPSIZ_MASK 0x7
  40. #define I460_4M_PS (1 << 1)
  41. /* Control bits for Out-Of-GART coherency and Burst Write Combining */
  42. #define I460_GXBCTL_OOG (1UL << 0)
  43. #define I460_GXBCTL_BWC (1UL << 2)
  44. /*
  45. * gatt_table entries are 32-bits wide on the i460; the generic code ought to declare the
  46. * gatt_table and gatt_table_real pointers a "void *"...
  47. */
  48. #define RD_GATT(index) readl((u32 *) i460.gatt + (index))
  49. #define WR_GATT(index, val) writel((val), (u32 *) i460.gatt + (index))
  50. /*
  51. * The 460 spec says we have to read the last location written to make sure that all
  52. * writes have taken effect
  53. */
  54. #define WR_FLUSH_GATT(index) RD_GATT(index)
  55. static unsigned long i460_mask_memory (struct agp_bridge_data *bridge,
  56. dma_addr_t addr, int type);
  57. static struct {
  58. void *gatt; /* ioremap'd GATT area */
  59. /* i460 supports multiple GART page sizes, so GART pageshift is dynamic: */
  60. u8 io_page_shift;
  61. /* BIOS configures chipset to one of 2 possible apbase values: */
  62. u8 dynamic_apbase;
  63. /* structure for tracking partial use of 4MB GART pages: */
  64. struct lp_desc {
  65. unsigned long *alloced_map; /* bitmap of kernel-pages in use */
  66. int refcount; /* number of kernel pages using the large page */
  67. u64 paddr; /* physical address of large page */
  68. struct page *page; /* page pointer */
  69. } *lp_desc;
  70. } i460;
  71. static const struct aper_size_info_8 i460_sizes[3] =
  72. {
  73. /*
  74. * The 32GB aperture is only available with a 4M GART page size. Due to the
  75. * dynamic GART page size, we can't figure out page_order or num_entries until
  76. * runtime.
  77. */
  78. {32768, 0, 0, 4},
  79. {1024, 0, 0, 2},
  80. {256, 0, 0, 1}
  81. };
  82. static struct gatt_mask i460_masks[] =
  83. {
  84. {
  85. .mask = INTEL_I460_GATT_VALID | INTEL_I460_GATT_COHERENT,
  86. .type = 0
  87. }
  88. };
  89. static int i460_fetch_size (void)
  90. {
  91. int i;
  92. u8 temp;
  93. struct aper_size_info_8 *values;
  94. /* Determine the GART page size */
  95. pci_read_config_byte(agp_bridge->dev, INTEL_I460_GXBCTL, &temp);
  96. i460.io_page_shift = (temp & I460_4M_PS) ? 22 : 12;
  97. pr_debug("i460_fetch_size: io_page_shift=%d\n", i460.io_page_shift);
  98. if (i460.io_page_shift != I460_IO_PAGE_SHIFT) {
  99. printk(KERN_ERR PFX
  100. "I/O (GART) page-size %luKB doesn't match expected "
  101. "size %luKB\n",
  102. 1UL << (i460.io_page_shift - 10),
  103. 1UL << (I460_IO_PAGE_SHIFT));
  104. return 0;
  105. }
  106. values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
  107. pci_read_config_byte(agp_bridge->dev, INTEL_I460_AGPSIZ, &temp);
  108. /* Exit now if the IO drivers for the GART SRAMS are turned off */
  109. if (temp & I460_SRAM_IO_DISABLE) {
  110. printk(KERN_ERR PFX "GART SRAMS disabled on 460GX chipset\n");
  111. printk(KERN_ERR PFX "AGPGART operation not possible\n");
  112. return 0;
  113. }
  114. /* Make sure we don't try to create an 2 ^ 23 entry GATT */
  115. if ((i460.io_page_shift == 0) && ((temp & I460_AGPSIZ_MASK) == 4)) {
  116. printk(KERN_ERR PFX "We can't have a 32GB aperture with 4KB GART pages\n");
  117. return 0;
  118. }
  119. /* Determine the proper APBASE register */
  120. if (temp & I460_BAPBASE_ENABLE)
  121. i460.dynamic_apbase = INTEL_I460_BAPBASE;
  122. else
  123. i460.dynamic_apbase = AGP_APBASE;
  124. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
  125. /*
  126. * Dynamically calculate the proper num_entries and page_order values for
  127. * the define aperture sizes. Take care not to shift off the end of
  128. * values[i].size.
  129. */
  130. values[i].num_entries = (values[i].size << 8) >> (I460_IO_PAGE_SHIFT - 12);
  131. values[i].page_order = ilog2((sizeof(u32)*values[i].num_entries) >> PAGE_SHIFT);
  132. }
  133. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
  134. /* Neglect control bits when matching up size_value */
  135. if ((temp & I460_AGPSIZ_MASK) == values[i].size_value) {
  136. agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
  137. agp_bridge->aperture_size_idx = i;
  138. return values[i].size;
  139. }
  140. }
  141. return 0;
  142. }
  143. /* There isn't anything to do here since 460 has no GART TLB. */
  144. static void i460_tlb_flush (struct agp_memory *mem)
  145. {
  146. return;
  147. }
  148. /*
  149. * This utility function is needed to prevent corruption of the control bits
  150. * which are stored along with the aperture size in 460's AGPSIZ register
  151. */
  152. static void i460_write_agpsiz (u8 size_value)
  153. {
  154. u8 temp;
  155. pci_read_config_byte(agp_bridge->dev, INTEL_I460_AGPSIZ, &temp);
  156. pci_write_config_byte(agp_bridge->dev, INTEL_I460_AGPSIZ,
  157. ((temp & ~I460_AGPSIZ_MASK) | size_value));
  158. }
  159. static void i460_cleanup (void)
  160. {
  161. struct aper_size_info_8 *previous_size;
  162. previous_size = A_SIZE_8(agp_bridge->previous_size);
  163. i460_write_agpsiz(previous_size->size_value);
  164. if (I460_IO_PAGE_SHIFT > PAGE_SHIFT)
  165. kfree(i460.lp_desc);
  166. }
  167. static int i460_configure (void)
  168. {
  169. union {
  170. u32 small[2];
  171. u64 large;
  172. } temp;
  173. size_t size;
  174. u8 scratch;
  175. struct aper_size_info_8 *current_size;
  176. temp.large = 0;
  177. current_size = A_SIZE_8(agp_bridge->current_size);
  178. i460_write_agpsiz(current_size->size_value);
  179. /*
  180. * Do the necessary rigmarole to read all eight bytes of APBASE.
  181. * This has to be done since the AGP aperture can be above 4GB on
  182. * 460 based systems.
  183. */
  184. pci_read_config_dword(agp_bridge->dev, i460.dynamic_apbase, &(temp.small[0]));
  185. pci_read_config_dword(agp_bridge->dev, i460.dynamic_apbase + 4, &(temp.small[1]));
  186. /* Clear BAR control bits */
  187. agp_bridge->gart_bus_addr = temp.large & ~((1UL << 3) - 1);
  188. pci_read_config_byte(agp_bridge->dev, INTEL_I460_GXBCTL, &scratch);
  189. pci_write_config_byte(agp_bridge->dev, INTEL_I460_GXBCTL,
  190. (scratch & 0x02) | I460_GXBCTL_OOG | I460_GXBCTL_BWC);
  191. /*
  192. * Initialize partial allocation trackers if a GART page is bigger than a kernel
  193. * page.
  194. */
  195. if (I460_IO_PAGE_SHIFT > PAGE_SHIFT) {
  196. size = current_size->num_entries * sizeof(i460.lp_desc[0]);
  197. i460.lp_desc = kzalloc(size, GFP_KERNEL);
  198. if (!i460.lp_desc)
  199. return -ENOMEM;
  200. }
  201. return 0;
  202. }
  203. static int i460_create_gatt_table (struct agp_bridge_data *bridge)
  204. {
  205. int page_order, num_entries, i;
  206. void *temp;
  207. /*
  208. * Load up the fixed address of the GART SRAMS which hold our GATT table.
  209. */
  210. temp = agp_bridge->current_size;
  211. page_order = A_SIZE_8(temp)->page_order;
  212. num_entries = A_SIZE_8(temp)->num_entries;
  213. i460.gatt = ioremap(INTEL_I460_ATTBASE, PAGE_SIZE << page_order);
  214. if (!i460.gatt) {
  215. printk(KERN_ERR PFX "ioremap failed\n");
  216. return -ENOMEM;
  217. }
  218. /* These are no good, the should be removed from the agp_bridge strucure... */
  219. agp_bridge->gatt_table_real = NULL;
  220. agp_bridge->gatt_table = NULL;
  221. agp_bridge->gatt_bus_addr = 0;
  222. for (i = 0; i < num_entries; ++i)
  223. WR_GATT(i, 0);
  224. WR_FLUSH_GATT(i - 1);
  225. return 0;
  226. }
  227. static int i460_free_gatt_table (struct agp_bridge_data *bridge)
  228. {
  229. int num_entries, i;
  230. void *temp;
  231. temp = agp_bridge->current_size;
  232. num_entries = A_SIZE_8(temp)->num_entries;
  233. for (i = 0; i < num_entries; ++i)
  234. WR_GATT(i, 0);
  235. WR_FLUSH_GATT(num_entries - 1);
  236. iounmap(i460.gatt);
  237. return 0;
  238. }
  239. /*
  240. * The following functions are called when the I/O (GART) page size is smaller than
  241. * PAGE_SIZE.
  242. */
  243. static int i460_insert_memory_small_io_page (struct agp_memory *mem,
  244. off_t pg_start, int type)
  245. {
  246. unsigned long paddr, io_pg_start, io_page_size;
  247. int i, j, k, num_entries;
  248. void *temp;
  249. pr_debug("i460_insert_memory_small_io_page(mem=%p, pg_start=%ld, type=%d, paddr0=0x%lx)\n",
  250. mem, pg_start, type, page_to_phys(mem->pages[0]));
  251. if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
  252. return -EINVAL;
  253. io_pg_start = I460_IOPAGES_PER_KPAGE * pg_start;
  254. temp = agp_bridge->current_size;
  255. num_entries = A_SIZE_8(temp)->num_entries;
  256. if ((io_pg_start + I460_IOPAGES_PER_KPAGE * mem->page_count) > num_entries) {
  257. printk(KERN_ERR PFX "Looks like we're out of AGP memory\n");
  258. return -EINVAL;
  259. }
  260. j = io_pg_start;
  261. while (j < (io_pg_start + I460_IOPAGES_PER_KPAGE * mem->page_count)) {
  262. if (!PGE_EMPTY(agp_bridge, RD_GATT(j))) {
  263. pr_debug("i460_insert_memory_small_io_page: GATT[%d]=0x%x is busy\n",
  264. j, RD_GATT(j));
  265. return -EBUSY;
  266. }
  267. j++;
  268. }
  269. io_page_size = 1UL << I460_IO_PAGE_SHIFT;
  270. for (i = 0, j = io_pg_start; i < mem->page_count; i++) {
  271. paddr = page_to_phys(mem->pages[i]);
  272. for (k = 0; k < I460_IOPAGES_PER_KPAGE; k++, j++, paddr += io_page_size)
  273. WR_GATT(j, i460_mask_memory(agp_bridge, paddr, mem->type));
  274. }
  275. WR_FLUSH_GATT(j - 1);
  276. return 0;
  277. }
  278. static int i460_remove_memory_small_io_page(struct agp_memory *mem,
  279. off_t pg_start, int type)
  280. {
  281. int i;
  282. pr_debug("i460_remove_memory_small_io_page(mem=%p, pg_start=%ld, type=%d)\n",
  283. mem, pg_start, type);
  284. pg_start = I460_IOPAGES_PER_KPAGE * pg_start;
  285. for (i = pg_start; i < (pg_start + I460_IOPAGES_PER_KPAGE * mem->page_count); i++)
  286. WR_GATT(i, 0);
  287. WR_FLUSH_GATT(i - 1);
  288. return 0;
  289. }
  290. #if I460_LARGE_IO_PAGES
  291. /*
  292. * These functions are called when the I/O (GART) page size exceeds PAGE_SIZE.
  293. *
  294. * This situation is interesting since AGP memory allocations that are smaller than a
  295. * single GART page are possible. The i460.lp_desc array tracks partial allocation of the
  296. * large GART pages to work around this issue.
  297. *
  298. * i460.lp_desc[pg_num].refcount tracks the number of kernel pages in use within GART page
  299. * pg_num. i460.lp_desc[pg_num].paddr is the physical address of the large page and
  300. * i460.lp_desc[pg_num].alloced_map is a bitmap of kernel pages that are in use (allocated).
  301. */
  302. static int i460_alloc_large_page (struct lp_desc *lp)
  303. {
  304. unsigned long order = I460_IO_PAGE_SHIFT - PAGE_SHIFT;
  305. size_t map_size;
  306. lp->page = alloc_pages(GFP_KERNEL, order);
  307. if (!lp->page) {
  308. printk(KERN_ERR PFX "Couldn't alloc 4M GART page...\n");
  309. return -ENOMEM;
  310. }
  311. map_size = ((I460_KPAGES_PER_IOPAGE + BITS_PER_LONG - 1) & -BITS_PER_LONG)/8;
  312. lp->alloced_map = kzalloc(map_size, GFP_KERNEL);
  313. if (!lp->alloced_map) {
  314. __free_pages(lp->page, order);
  315. printk(KERN_ERR PFX "Out of memory, we're in trouble...\n");
  316. return -ENOMEM;
  317. }
  318. lp->paddr = page_to_phys(lp->page);
  319. lp->refcount = 0;
  320. atomic_add(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp);
  321. return 0;
  322. }
  323. static void i460_free_large_page (struct lp_desc *lp)
  324. {
  325. kfree(lp->alloced_map);
  326. lp->alloced_map = NULL;
  327. __free_pages(lp->page, I460_IO_PAGE_SHIFT - PAGE_SHIFT);
  328. atomic_sub(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp);
  329. }
  330. static int i460_insert_memory_large_io_page (struct agp_memory *mem,
  331. off_t pg_start, int type)
  332. {
  333. int i, start_offset, end_offset, idx, pg, num_entries;
  334. struct lp_desc *start, *end, *lp;
  335. void *temp;
  336. if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
  337. return -EINVAL;
  338. temp = agp_bridge->current_size;
  339. num_entries = A_SIZE_8(temp)->num_entries;
  340. /* Figure out what pg_start means in terms of our large GART pages */
  341. start = &i460.lp_desc[pg_start / I460_KPAGES_PER_IOPAGE];
  342. end = &i460.lp_desc[(pg_start + mem->page_count - 1) / I460_KPAGES_PER_IOPAGE];
  343. start_offset = pg_start % I460_KPAGES_PER_IOPAGE;
  344. end_offset = (pg_start + mem->page_count - 1) % I460_KPAGES_PER_IOPAGE;
  345. if (end > i460.lp_desc + num_entries) {
  346. printk(KERN_ERR PFX "Looks like we're out of AGP memory\n");
  347. return -EINVAL;
  348. }
  349. /* Check if the requested region of the aperture is free */
  350. for (lp = start; lp <= end; ++lp) {
  351. if (!lp->alloced_map)
  352. continue; /* OK, the entire large page is available... */
  353. for (idx = ((lp == start) ? start_offset : 0);
  354. idx < ((lp == end) ? (end_offset + 1) : I460_KPAGES_PER_IOPAGE);
  355. idx++)
  356. {
  357. if (test_bit(idx, lp->alloced_map))
  358. return -EBUSY;
  359. }
  360. }
  361. for (lp = start, i = 0; lp <= end; ++lp) {
  362. if (!lp->alloced_map) {
  363. /* Allocate new GART pages... */
  364. if (i460_alloc_large_page(lp) < 0)
  365. return -ENOMEM;
  366. pg = lp - i460.lp_desc;
  367. WR_GATT(pg, i460_mask_memory(agp_bridge,
  368. lp->paddr, 0));
  369. WR_FLUSH_GATT(pg);
  370. }
  371. for (idx = ((lp == start) ? start_offset : 0);
  372. idx < ((lp == end) ? (end_offset + 1) : I460_KPAGES_PER_IOPAGE);
  373. idx++, i++)
  374. {
  375. mem->pages[i] = lp->page;
  376. __set_bit(idx, lp->alloced_map);
  377. ++lp->refcount;
  378. }
  379. }
  380. return 0;
  381. }
  382. static int i460_remove_memory_large_io_page (struct agp_memory *mem,
  383. off_t pg_start, int type)
  384. {
  385. int i, pg, start_offset, end_offset, idx, num_entries;
  386. struct lp_desc *start, *end, *lp;
  387. void *temp;
  388. temp = agp_bridge->current_size;
  389. num_entries = A_SIZE_8(temp)->num_entries;
  390. /* Figure out what pg_start means in terms of our large GART pages */
  391. start = &i460.lp_desc[pg_start / I460_KPAGES_PER_IOPAGE];
  392. end = &i460.lp_desc[(pg_start + mem->page_count - 1) / I460_KPAGES_PER_IOPAGE];
  393. start_offset = pg_start % I460_KPAGES_PER_IOPAGE;
  394. end_offset = (pg_start + mem->page_count - 1) % I460_KPAGES_PER_IOPAGE;
  395. for (i = 0, lp = start; lp <= end; ++lp) {
  396. for (idx = ((lp == start) ? start_offset : 0);
  397. idx < ((lp == end) ? (end_offset + 1) : I460_KPAGES_PER_IOPAGE);
  398. idx++, i++)
  399. {
  400. mem->pages[i] = NULL;
  401. __clear_bit(idx, lp->alloced_map);
  402. --lp->refcount;
  403. }
  404. /* Free GART pages if they are unused */
  405. if (lp->refcount == 0) {
  406. pg = lp - i460.lp_desc;
  407. WR_GATT(pg, 0);
  408. WR_FLUSH_GATT(pg);
  409. i460_free_large_page(lp);
  410. }
  411. }
  412. return 0;
  413. }
  414. /* Wrapper routines to call the approriate {small_io_page,large_io_page} function */
  415. static int i460_insert_memory (struct agp_memory *mem,
  416. off_t pg_start, int type)
  417. {
  418. if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT)
  419. return i460_insert_memory_small_io_page(mem, pg_start, type);
  420. else
  421. return i460_insert_memory_large_io_page(mem, pg_start, type);
  422. }
  423. static int i460_remove_memory (struct agp_memory *mem,
  424. off_t pg_start, int type)
  425. {
  426. if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT)
  427. return i460_remove_memory_small_io_page(mem, pg_start, type);
  428. else
  429. return i460_remove_memory_large_io_page(mem, pg_start, type);
  430. }
  431. /*
  432. * If the I/O (GART) page size is bigger than the kernel page size, we don't want to
  433. * allocate memory until we know where it is to be bound in the aperture (a
  434. * multi-kernel-page alloc might fit inside of an already allocated GART page).
  435. *
  436. * Let's just hope nobody counts on the allocated AGP memory being there before bind time
  437. * (I don't think current drivers do)...
  438. */
  439. static struct page *i460_alloc_page (struct agp_bridge_data *bridge)
  440. {
  441. void *page;
  442. if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT) {
  443. page = agp_generic_alloc_page(agp_bridge);
  444. } else
  445. /* Returning NULL would cause problems */
  446. /* AK: really dubious code. */
  447. page = (void *)~0UL;
  448. return page;
  449. }
  450. static void i460_destroy_page (struct page *page, int flags)
  451. {
  452. if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT) {
  453. agp_generic_destroy_page(page, flags);
  454. }
  455. }
  456. #endif /* I460_LARGE_IO_PAGES */
  457. static unsigned long i460_mask_memory (struct agp_bridge_data *bridge,
  458. dma_addr_t addr, int type)
  459. {
  460. /* Make sure the returned address is a valid GATT entry */
  461. return bridge->driver->masks[0].mask
  462. | (((addr & ~((1 << I460_IO_PAGE_SHIFT) - 1)) & 0xfffff000) >> 12);
  463. }
  464. const struct agp_bridge_driver intel_i460_driver = {
  465. .owner = THIS_MODULE,
  466. .aperture_sizes = i460_sizes,
  467. .size_type = U8_APER_SIZE,
  468. .num_aperture_sizes = 3,
  469. .configure = i460_configure,
  470. .fetch_size = i460_fetch_size,
  471. .cleanup = i460_cleanup,
  472. .tlb_flush = i460_tlb_flush,
  473. .mask_memory = i460_mask_memory,
  474. .masks = i460_masks,
  475. .agp_enable = agp_generic_enable,
  476. .cache_flush = global_cache_flush,
  477. .create_gatt_table = i460_create_gatt_table,
  478. .free_gatt_table = i460_free_gatt_table,
  479. #if I460_LARGE_IO_PAGES
  480. .insert_memory = i460_insert_memory,
  481. .remove_memory = i460_remove_memory,
  482. .agp_alloc_page = i460_alloc_page,
  483. .agp_destroy_page = i460_destroy_page,
  484. #else
  485. .insert_memory = i460_insert_memory_small_io_page,
  486. .remove_memory = i460_remove_memory_small_io_page,
  487. .agp_alloc_page = agp_generic_alloc_page,
  488. .agp_alloc_pages = agp_generic_alloc_pages,
  489. .agp_destroy_page = agp_generic_destroy_page,
  490. .agp_destroy_pages = agp_generic_destroy_pages,
  491. #endif
  492. .alloc_by_type = agp_generic_alloc_by_type,
  493. .free_by_type = agp_generic_free_by_type,
  494. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  495. .cant_use_aperture = true,
  496. };
  497. static int agp_intel_i460_probe(struct pci_dev *pdev,
  498. const struct pci_device_id *ent)
  499. {
  500. struct agp_bridge_data *bridge;
  501. u8 cap_ptr;
  502. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  503. if (!cap_ptr)
  504. return -ENODEV;
  505. bridge = agp_alloc_bridge();
  506. if (!bridge)
  507. return -ENOMEM;
  508. bridge->driver = &intel_i460_driver;
  509. bridge->dev = pdev;
  510. bridge->capndx = cap_ptr;
  511. printk(KERN_INFO PFX "Detected Intel 460GX chipset\n");
  512. pci_set_drvdata(pdev, bridge);
  513. return agp_add_bridge(bridge);
  514. }
  515. static void agp_intel_i460_remove(struct pci_dev *pdev)
  516. {
  517. struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
  518. agp_remove_bridge(bridge);
  519. agp_put_bridge(bridge);
  520. }
  521. static struct pci_device_id agp_intel_i460_pci_table[] = {
  522. {
  523. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  524. .class_mask = ~0,
  525. .vendor = PCI_VENDOR_ID_INTEL,
  526. .device = PCI_DEVICE_ID_INTEL_84460GX,
  527. .subvendor = PCI_ANY_ID,
  528. .subdevice = PCI_ANY_ID,
  529. },
  530. { }
  531. };
  532. MODULE_DEVICE_TABLE(pci, agp_intel_i460_pci_table);
  533. static struct pci_driver agp_intel_i460_pci_driver = {
  534. .name = "agpgart-intel-i460",
  535. .id_table = agp_intel_i460_pci_table,
  536. .probe = agp_intel_i460_probe,
  537. .remove = agp_intel_i460_remove,
  538. };
  539. static int __init agp_intel_i460_init(void)
  540. {
  541. if (agp_off)
  542. return -EINVAL;
  543. return pci_register_driver(&agp_intel_i460_pci_driver);
  544. }
  545. static void __exit agp_intel_i460_cleanup(void)
  546. {
  547. pci_unregister_driver(&agp_intel_i460_pci_driver);
  548. }
  549. module_init(agp_intel_i460_init);
  550. module_exit(agp_intel_i460_cleanup);
  551. MODULE_AUTHOR("Chris Ahna <Christopher.J.Ahna@intel.com>");
  552. MODULE_LICENSE("GPL and additional rights");