alpha-agp.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #include <linux/module.h>
  2. #include <linux/pci.h>
  3. #include <linux/init.h>
  4. #include <linux/agp_backend.h>
  5. #include <linux/mm.h>
  6. #include <linux/slab.h>
  7. #include <asm/machvec.h>
  8. #include <asm/agp_backend.h>
  9. #include "../../../arch/alpha/kernel/pci_impl.h"
  10. #include "agp.h"
  11. static int alpha_core_agp_vm_fault(struct vm_area_struct *vma,
  12. struct vm_fault *vmf)
  13. {
  14. alpha_agp_info *agp = agp_bridge->dev_private_data;
  15. dma_addr_t dma_addr;
  16. unsigned long pa;
  17. struct page *page;
  18. dma_addr = (unsigned long)vmf->virtual_address - vma->vm_start
  19. + agp->aperture.bus_base;
  20. pa = agp->ops->translate(agp, dma_addr);
  21. if (pa == (unsigned long)-EINVAL)
  22. return VM_FAULT_SIGBUS; /* no translation */
  23. /*
  24. * Get the page, inc the use count, and return it
  25. */
  26. page = virt_to_page(__va(pa));
  27. get_page(page);
  28. vmf->page = page;
  29. return 0;
  30. }
  31. static struct aper_size_info_fixed alpha_core_agp_sizes[] =
  32. {
  33. { 0, 0, 0 }, /* filled in by alpha_core_agp_setup */
  34. };
  35. static const struct vm_operations_struct alpha_core_agp_vm_ops = {
  36. .fault = alpha_core_agp_vm_fault,
  37. };
  38. static int alpha_core_agp_fetch_size(void)
  39. {
  40. return alpha_core_agp_sizes[0].size;
  41. }
  42. static int alpha_core_agp_configure(void)
  43. {
  44. alpha_agp_info *agp = agp_bridge->dev_private_data;
  45. agp_bridge->gart_bus_addr = agp->aperture.bus_base;
  46. return 0;
  47. }
  48. static void alpha_core_agp_cleanup(void)
  49. {
  50. alpha_agp_info *agp = agp_bridge->dev_private_data;
  51. agp->ops->cleanup(agp);
  52. }
  53. static void alpha_core_agp_tlbflush(struct agp_memory *mem)
  54. {
  55. alpha_agp_info *agp = agp_bridge->dev_private_data;
  56. alpha_mv.mv_pci_tbi(agp->hose, 0, -1);
  57. }
  58. static void alpha_core_agp_enable(struct agp_bridge_data *bridge, u32 mode)
  59. {
  60. alpha_agp_info *agp = bridge->dev_private_data;
  61. agp->mode.lw = agp_collect_device_status(bridge, mode,
  62. agp->capability.lw);
  63. agp->mode.bits.enable = 1;
  64. agp->ops->configure(agp);
  65. agp_device_command(agp->mode.lw, false);
  66. }
  67. static int alpha_core_agp_insert_memory(struct agp_memory *mem, off_t pg_start,
  68. int type)
  69. {
  70. alpha_agp_info *agp = agp_bridge->dev_private_data;
  71. int num_entries, status;
  72. void *temp;
  73. if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
  74. return -EINVAL;
  75. temp = agp_bridge->current_size;
  76. num_entries = A_SIZE_FIX(temp)->num_entries;
  77. if ((pg_start + mem->page_count) > num_entries)
  78. return -EINVAL;
  79. status = agp->ops->bind(agp, pg_start, mem);
  80. mb();
  81. alpha_core_agp_tlbflush(mem);
  82. return status;
  83. }
  84. static int alpha_core_agp_remove_memory(struct agp_memory *mem, off_t pg_start,
  85. int type)
  86. {
  87. alpha_agp_info *agp = agp_bridge->dev_private_data;
  88. int status;
  89. status = agp->ops->unbind(agp, pg_start, mem);
  90. alpha_core_agp_tlbflush(mem);
  91. return status;
  92. }
  93. static int alpha_core_agp_create_free_gatt_table(struct agp_bridge_data *a)
  94. {
  95. return 0;
  96. }
  97. struct agp_bridge_driver alpha_core_agp_driver = {
  98. .owner = THIS_MODULE,
  99. .aperture_sizes = alpha_core_agp_sizes,
  100. .num_aperture_sizes = 1,
  101. .size_type = FIXED_APER_SIZE,
  102. .cant_use_aperture = true,
  103. .masks = NULL,
  104. .fetch_size = alpha_core_agp_fetch_size,
  105. .configure = alpha_core_agp_configure,
  106. .agp_enable = alpha_core_agp_enable,
  107. .cleanup = alpha_core_agp_cleanup,
  108. .tlb_flush = alpha_core_agp_tlbflush,
  109. .mask_memory = agp_generic_mask_memory,
  110. .cache_flush = global_cache_flush,
  111. .create_gatt_table = alpha_core_agp_create_free_gatt_table,
  112. .free_gatt_table = alpha_core_agp_create_free_gatt_table,
  113. .insert_memory = alpha_core_agp_insert_memory,
  114. .remove_memory = alpha_core_agp_remove_memory,
  115. .alloc_by_type = agp_generic_alloc_by_type,
  116. .free_by_type = agp_generic_free_by_type,
  117. .agp_alloc_page = agp_generic_alloc_page,
  118. .agp_alloc_pages = agp_generic_alloc_pages,
  119. .agp_destroy_page = agp_generic_destroy_page,
  120. .agp_destroy_pages = agp_generic_destroy_pages,
  121. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  122. };
  123. struct agp_bridge_data *alpha_bridge;
  124. int __init
  125. alpha_core_agp_setup(void)
  126. {
  127. alpha_agp_info *agp = alpha_mv.agp_info();
  128. struct pci_dev *pdev; /* faked */
  129. struct aper_size_info_fixed *aper_size;
  130. if (!agp)
  131. return -ENODEV;
  132. if (agp->ops->setup(agp))
  133. return -ENODEV;
  134. /*
  135. * Build the aperture size descriptor
  136. */
  137. aper_size = alpha_core_agp_sizes;
  138. aper_size->size = agp->aperture.size / (1024 * 1024);
  139. aper_size->num_entries = agp->aperture.size / PAGE_SIZE;
  140. aper_size->page_order = __ffs(aper_size->num_entries / 1024);
  141. /*
  142. * Build a fake pci_dev struct
  143. */
  144. pdev = pci_alloc_dev(NULL);
  145. if (!pdev)
  146. return -ENOMEM;
  147. pdev->vendor = 0xffff;
  148. pdev->device = 0xffff;
  149. pdev->sysdata = agp->hose;
  150. alpha_bridge = agp_alloc_bridge();
  151. if (!alpha_bridge)
  152. goto fail;
  153. alpha_bridge->driver = &alpha_core_agp_driver;
  154. alpha_bridge->vm_ops = &alpha_core_agp_vm_ops;
  155. alpha_bridge->current_size = aper_size; /* only 1 size */
  156. alpha_bridge->dev_private_data = agp;
  157. alpha_bridge->dev = pdev;
  158. alpha_bridge->mode = agp->capability.lw;
  159. printk(KERN_INFO PFX "Detected AGP on hose %d\n", agp->hose->index);
  160. return agp_add_bridge(alpha_bridge);
  161. fail:
  162. kfree(pdev);
  163. return -ENOMEM;
  164. }
  165. static int __init agp_alpha_core_init(void)
  166. {
  167. if (agp_off)
  168. return -EINVAL;
  169. if (alpha_mv.agp_info)
  170. return alpha_core_agp_setup();
  171. return -ENODEV;
  172. }
  173. static void __exit agp_alpha_core_cleanup(void)
  174. {
  175. agp_remove_bridge(alpha_bridge);
  176. agp_put_bridge(alpha_bridge);
  177. }
  178. module_init(agp_alpha_core_init);
  179. module_exit(agp_alpha_core_cleanup);
  180. MODULE_AUTHOR("Jeff Wiedemeier <Jeff.Wiedemeier@hp.com>");
  181. MODULE_LICENSE("GPL and additional rights");