alpha-agp.c 5.3 KB

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