sgi-agp.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2003-2005 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. /*
  9. * SGI TIOCA AGPGART routines.
  10. *
  11. */
  12. #include <linux/acpi.h>
  13. #include <linux/module.h>
  14. #include <linux/pci.h>
  15. #include <linux/init.h>
  16. #include <linux/agp_backend.h>
  17. #include <asm/sn/addrs.h>
  18. #include <asm/sn/io.h>
  19. #include <asm/sn/pcidev.h>
  20. #include <asm/sn/pcibus_provider_defs.h>
  21. #include <asm/sn/tioca_provider.h>
  22. #include "agp.h"
  23. extern int agp_memory_reserved;
  24. extern uint32_t tioca_gart_found;
  25. extern struct list_head tioca_list;
  26. static struct agp_bridge_data **sgi_tioca_agp_bridges;
  27. /*
  28. * The aperature size and related information is set up at TIOCA init time.
  29. * Values for this table will be extracted and filled in at
  30. * sgi_tioca_fetch_size() time.
  31. */
  32. static struct aper_size_info_fixed sgi_tioca_sizes[] = {
  33. {0, 0, 0},
  34. };
  35. static void *sgi_tioca_alloc_page(struct agp_bridge_data *bridge)
  36. {
  37. struct page *page;
  38. int nid;
  39. struct tioca_kernel *info =
  40. (struct tioca_kernel *)bridge->dev_private_data;
  41. nid = info->ca_closest_node;
  42. page = alloc_pages_node(nid, GFP_KERNEL, 0);
  43. if (page == NULL) {
  44. return 0;
  45. }
  46. get_page(page);
  47. SetPageLocked(page);
  48. atomic_inc(&agp_bridge->current_memory_agp);
  49. return page_address(page);
  50. }
  51. /*
  52. * Flush GART tlb's. Cannot selectively flush based on memory so the mem
  53. * arg is ignored.
  54. */
  55. static void sgi_tioca_tlbflush(struct agp_memory *mem)
  56. {
  57. tioca_tlbflush(mem->bridge->dev_private_data);
  58. }
  59. /*
  60. * Given an address of a host physical page, turn it into a valid gart
  61. * entry.
  62. */
  63. static unsigned long
  64. sgi_tioca_mask_memory(struct agp_bridge_data *bridge,
  65. unsigned long addr, int type)
  66. {
  67. return tioca_physpage_to_gart(addr);
  68. }
  69. static void sgi_tioca_agp_enable(struct agp_bridge_data *bridge, u32 mode)
  70. {
  71. tioca_fastwrite_enable(bridge->dev_private_data);
  72. }
  73. /*
  74. * sgi_tioca_configure() doesn't have anything to do since the base CA driver
  75. * has alreay set up the GART.
  76. */
  77. static int sgi_tioca_configure(void)
  78. {
  79. return 0;
  80. }
  81. /*
  82. * Determine gfx aperature size. This has already been determined by the
  83. * CA driver init, so just need to set agp_bridge values accordingly.
  84. */
  85. static int sgi_tioca_fetch_size(void)
  86. {
  87. struct tioca_kernel *info =
  88. (struct tioca_kernel *)agp_bridge->dev_private_data;
  89. sgi_tioca_sizes[0].size = info->ca_gfxap_size / MB(1);
  90. sgi_tioca_sizes[0].num_entries = info->ca_gfxgart_entries;
  91. return sgi_tioca_sizes[0].size;
  92. }
  93. static int sgi_tioca_create_gatt_table(struct agp_bridge_data *bridge)
  94. {
  95. struct tioca_kernel *info =
  96. (struct tioca_kernel *)bridge->dev_private_data;
  97. bridge->gatt_table_real = (u32 *) info->ca_gfxgart;
  98. bridge->gatt_table = bridge->gatt_table_real;
  99. bridge->gatt_bus_addr = info->ca_gfxgart_base;
  100. return 0;
  101. }
  102. static int sgi_tioca_free_gatt_table(struct agp_bridge_data *bridge)
  103. {
  104. return 0;
  105. }
  106. static int sgi_tioca_insert_memory(struct agp_memory *mem, off_t pg_start,
  107. int type)
  108. {
  109. int num_entries;
  110. size_t i;
  111. off_t j;
  112. void *temp;
  113. struct agp_bridge_data *bridge;
  114. u64 *table;
  115. bridge = mem->bridge;
  116. if (!bridge)
  117. return -EINVAL;
  118. table = (u64 *)bridge->gatt_table;
  119. temp = bridge->current_size;
  120. switch (bridge->driver->size_type) {
  121. case U8_APER_SIZE:
  122. num_entries = A_SIZE_8(temp)->num_entries;
  123. break;
  124. case U16_APER_SIZE:
  125. num_entries = A_SIZE_16(temp)->num_entries;
  126. break;
  127. case U32_APER_SIZE:
  128. num_entries = A_SIZE_32(temp)->num_entries;
  129. break;
  130. case FIXED_APER_SIZE:
  131. num_entries = A_SIZE_FIX(temp)->num_entries;
  132. break;
  133. case LVL2_APER_SIZE:
  134. return -EINVAL;
  135. break;
  136. default:
  137. num_entries = 0;
  138. break;
  139. }
  140. num_entries -= agp_memory_reserved / PAGE_SIZE;
  141. if (num_entries < 0)
  142. num_entries = 0;
  143. if (type != 0 || mem->type != 0) {
  144. return -EINVAL;
  145. }
  146. if ((pg_start + mem->page_count) > num_entries)
  147. return -EINVAL;
  148. j = pg_start;
  149. while (j < (pg_start + mem->page_count)) {
  150. if (table[j])
  151. return -EBUSY;
  152. j++;
  153. }
  154. if (mem->is_flushed == FALSE) {
  155. bridge->driver->cache_flush();
  156. mem->is_flushed = TRUE;
  157. }
  158. for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
  159. table[j] =
  160. bridge->driver->mask_memory(bridge, mem->memory[i],
  161. mem->type);
  162. }
  163. bridge->driver->tlb_flush(mem);
  164. return 0;
  165. }
  166. static int sgi_tioca_remove_memory(struct agp_memory *mem, off_t pg_start,
  167. int type)
  168. {
  169. size_t i;
  170. struct agp_bridge_data *bridge;
  171. u64 *table;
  172. bridge = mem->bridge;
  173. if (!bridge)
  174. return -EINVAL;
  175. if (type != 0 || mem->type != 0) {
  176. return -EINVAL;
  177. }
  178. table = (u64 *)bridge->gatt_table;
  179. for (i = pg_start; i < (mem->page_count + pg_start); i++) {
  180. table[i] = 0;
  181. }
  182. bridge->driver->tlb_flush(mem);
  183. return 0;
  184. }
  185. static void sgi_tioca_cache_flush(void)
  186. {
  187. }
  188. /*
  189. * Cleanup. Nothing to do as the CA driver owns the GART.
  190. */
  191. static void sgi_tioca_cleanup(void)
  192. {
  193. }
  194. static struct agp_bridge_data *sgi_tioca_find_bridge(struct pci_dev *pdev)
  195. {
  196. struct agp_bridge_data *bridge;
  197. list_for_each_entry(bridge, &agp_bridges, list) {
  198. if (bridge->dev->bus == pdev->bus)
  199. break;
  200. }
  201. return bridge;
  202. }
  203. struct agp_bridge_driver sgi_tioca_driver = {
  204. .owner = THIS_MODULE,
  205. .size_type = U16_APER_SIZE,
  206. .configure = sgi_tioca_configure,
  207. .fetch_size = sgi_tioca_fetch_size,
  208. .cleanup = sgi_tioca_cleanup,
  209. .tlb_flush = sgi_tioca_tlbflush,
  210. .mask_memory = sgi_tioca_mask_memory,
  211. .agp_enable = sgi_tioca_agp_enable,
  212. .cache_flush = sgi_tioca_cache_flush,
  213. .create_gatt_table = sgi_tioca_create_gatt_table,
  214. .free_gatt_table = sgi_tioca_free_gatt_table,
  215. .insert_memory = sgi_tioca_insert_memory,
  216. .remove_memory = sgi_tioca_remove_memory,
  217. .alloc_by_type = agp_generic_alloc_by_type,
  218. .free_by_type = agp_generic_free_by_type,
  219. .agp_alloc_page = sgi_tioca_alloc_page,
  220. .agp_destroy_page = agp_generic_destroy_page,
  221. .cant_use_aperture = 1,
  222. .needs_scratch_page = 0,
  223. .num_aperture_sizes = 1,
  224. };
  225. static int __devinit agp_sgi_init(void)
  226. {
  227. unsigned int j;
  228. struct tioca_kernel *info;
  229. struct pci_dev *pdev = NULL;
  230. if (tioca_gart_found)
  231. printk(KERN_INFO PFX "SGI TIO CA GART driver initialized.\n");
  232. else
  233. return 0;
  234. sgi_tioca_agp_bridges =
  235. (struct agp_bridge_data **)kmalloc(tioca_gart_found *
  236. sizeof(struct agp_bridge_data *),
  237. GFP_KERNEL);
  238. j = 0;
  239. list_for_each_entry(info, &tioca_list, ca_list) {
  240. struct list_head *tmp;
  241. if (list_empty(info->ca_devices))
  242. continue;
  243. list_for_each(tmp, info->ca_devices) {
  244. u8 cap_ptr;
  245. pdev = pci_dev_b(tmp);
  246. if (pdev->class != (PCI_CLASS_DISPLAY_VGA << 8))
  247. continue;
  248. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  249. if (!cap_ptr)
  250. continue;
  251. }
  252. sgi_tioca_agp_bridges[j] = agp_alloc_bridge();
  253. printk(KERN_INFO PFX "bridge %d = 0x%p\n", j,
  254. sgi_tioca_agp_bridges[j]);
  255. if (sgi_tioca_agp_bridges[j]) {
  256. sgi_tioca_agp_bridges[j]->dev = pdev;
  257. sgi_tioca_agp_bridges[j]->dev_private_data = info;
  258. sgi_tioca_agp_bridges[j]->driver = &sgi_tioca_driver;
  259. sgi_tioca_agp_bridges[j]->gart_bus_addr =
  260. info->ca_gfxap_base;
  261. sgi_tioca_agp_bridges[j]->mode = (0x7D << 24) | /* 126 requests */
  262. (0x1 << 9) | /* SBA supported */
  263. (0x1 << 5) | /* 64-bit addresses supported */
  264. (0x1 << 4) | /* FW supported */
  265. (0x1 << 3) | /* AGP 3.0 mode */
  266. 0x2; /* 8x transfer only */
  267. sgi_tioca_agp_bridges[j]->current_size =
  268. sgi_tioca_agp_bridges[j]->previous_size =
  269. (void *)&sgi_tioca_sizes[0];
  270. agp_add_bridge(sgi_tioca_agp_bridges[j]);
  271. }
  272. j++;
  273. }
  274. agp_find_bridge = &sgi_tioca_find_bridge;
  275. return 0;
  276. }
  277. static void __devexit agp_sgi_cleanup(void)
  278. {
  279. if (sgi_tioca_agp_bridges)
  280. kfree(sgi_tioca_agp_bridges);
  281. sgi_tioca_agp_bridges=NULL;
  282. }
  283. module_init(agp_sgi_init);
  284. module_exit(agp_sgi_cleanup);
  285. MODULE_LICENSE("GPL and additional rights");