nouveau_sgdma.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include <linux/pagemap.h>
  2. #include <linux/slab.h>
  3. #include "nouveau_drm.h"
  4. #include "nouveau_ttm.h"
  5. struct nouveau_sgdma_be {
  6. /* this has to be the first field so populate/unpopulated in
  7. * nouve_bo.c works properly, otherwise have to move them here
  8. */
  9. struct ttm_dma_tt ttm;
  10. struct drm_device *dev;
  11. struct nouveau_mem *node;
  12. };
  13. static void
  14. nouveau_sgdma_destroy(struct ttm_tt *ttm)
  15. {
  16. struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
  17. if (ttm) {
  18. ttm_dma_tt_fini(&nvbe->ttm);
  19. kfree(nvbe);
  20. }
  21. }
  22. static int
  23. nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
  24. {
  25. struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
  26. struct nouveau_mem *node = mem->mm_node;
  27. if (ttm->sg) {
  28. node->sg = ttm->sg;
  29. node->pages = NULL;
  30. } else {
  31. node->sg = NULL;
  32. node->pages = nvbe->ttm.dma_address;
  33. }
  34. node->size = (mem->num_pages << PAGE_SHIFT) >> 12;
  35. nouveau_vm_map(&node->vma[0], node);
  36. nvbe->node = node;
  37. return 0;
  38. }
  39. static int
  40. nv04_sgdma_unbind(struct ttm_tt *ttm)
  41. {
  42. struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
  43. nouveau_vm_unmap(&nvbe->node->vma[0]);
  44. return 0;
  45. }
  46. static struct ttm_backend_func nv04_sgdma_backend = {
  47. .bind = nv04_sgdma_bind,
  48. .unbind = nv04_sgdma_unbind,
  49. .destroy = nouveau_sgdma_destroy
  50. };
  51. static int
  52. nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
  53. {
  54. struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
  55. struct nouveau_mem *node = mem->mm_node;
  56. /* noop: bound in move_notify() */
  57. if (ttm->sg) {
  58. node->sg = ttm->sg;
  59. node->pages = NULL;
  60. } else {
  61. node->sg = NULL;
  62. node->pages = nvbe->ttm.dma_address;
  63. }
  64. node->size = (mem->num_pages << PAGE_SHIFT) >> 12;
  65. return 0;
  66. }
  67. static int
  68. nv50_sgdma_unbind(struct ttm_tt *ttm)
  69. {
  70. /* noop: unbound in move_notify() */
  71. return 0;
  72. }
  73. static struct ttm_backend_func nv50_sgdma_backend = {
  74. .bind = nv50_sgdma_bind,
  75. .unbind = nv50_sgdma_unbind,
  76. .destroy = nouveau_sgdma_destroy
  77. };
  78. struct ttm_tt *
  79. nouveau_sgdma_create_ttm(struct ttm_bo_device *bdev,
  80. unsigned long size, uint32_t page_flags,
  81. struct page *dummy_read_page)
  82. {
  83. struct nouveau_drm *drm = nouveau_bdev(bdev);
  84. struct nouveau_sgdma_be *nvbe;
  85. nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
  86. if (!nvbe)
  87. return NULL;
  88. nvbe->dev = drm->dev;
  89. if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA)
  90. nvbe->ttm.ttm.func = &nv04_sgdma_backend;
  91. else
  92. nvbe->ttm.ttm.func = &nv50_sgdma_backend;
  93. if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page))
  94. return NULL;
  95. return &nvbe->ttm.ttm;
  96. }