Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | #include <linux/pagemap.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 2 | #include <linux/slab.h> |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 3 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 4 | #include <subdev/fb.h> |
| 5 | |
| 6 | #include "nouveau_drm.h" |
| 7 | #include "nouveau_ttm.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 8 | |
| 9 | struct nouveau_sgdma_be { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 10 | /* this has to be the first field so populate/unpopulated in |
| 11 | * nouve_bo.c works properly, otherwise have to move them here |
| 12 | */ |
| 13 | struct ttm_dma_tt ttm; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 14 | struct drm_device *dev; |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 15 | struct nouveau_mem *node; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 16 | }; |
| 17 | |
Ben Skeggs | efa58db | 2011-01-10 16:24:00 +1000 | [diff] [blame] | 18 | static void |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 19 | nouveau_sgdma_destroy(struct ttm_tt *ttm) |
Ben Skeggs | efa58db | 2011-01-10 16:24:00 +1000 | [diff] [blame] | 20 | { |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 21 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
Ben Skeggs | efa58db | 2011-01-10 16:24:00 +1000 | [diff] [blame] | 22 | |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 23 | if (ttm) { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 24 | ttm_dma_tt_fini(&nvbe->ttm); |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 25 | kfree(nvbe); |
Ben Skeggs | efa58db | 2011-01-10 16:24:00 +1000 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 29 | static int |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 30 | nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 31 | { |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 32 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 33 | struct nouveau_mem *node = mem->mm_node; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 34 | |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 35 | if (ttm->sg) { |
Ben Skeggs | 2e2cfbe | 2013-11-15 11:56:49 +1000 | [diff] [blame] | 36 | node->sg = ttm->sg; |
| 37 | node->pages = NULL; |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 38 | } else { |
Ben Skeggs | 2e2cfbe | 2013-11-15 11:56:49 +1000 | [diff] [blame] | 39 | node->sg = NULL; |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 40 | node->pages = nvbe->ttm.dma_address; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 41 | } |
Ben Skeggs | 2e2cfbe | 2013-11-15 11:56:49 +1000 | [diff] [blame] | 42 | node->size = (mem->num_pages << PAGE_SHIFT) >> 12; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 43 | |
Ben Skeggs | 2e2cfbe | 2013-11-15 11:56:49 +1000 | [diff] [blame] | 44 | nouveau_vm_map(&node->vma[0], node); |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 45 | nvbe->node = node; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 50 | nv04_sgdma_unbind(struct ttm_tt *ttm) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 51 | { |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 52 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 53 | nouveau_vm_unmap(&nvbe->node->vma[0]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
Ben Skeggs | efa58db | 2011-01-10 16:24:00 +1000 | [diff] [blame] | 57 | static struct ttm_backend_func nv04_sgdma_backend = { |
Ben Skeggs | efa58db | 2011-01-10 16:24:00 +1000 | [diff] [blame] | 58 | .bind = nv04_sgdma_bind, |
| 59 | .unbind = nv04_sgdma_unbind, |
| 60 | .destroy = nouveau_sgdma_destroy |
| 61 | }; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 62 | |
Ben Skeggs | b571fe2 | 2010-11-16 10:13:05 +1000 | [diff] [blame] | 63 | static int |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 64 | nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem) |
Ben Skeggs | b571fe2 | 2010-11-16 10:13:05 +1000 | [diff] [blame] | 65 | { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 66 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 67 | struct nouveau_mem *node = mem->mm_node; |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 68 | |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 69 | /* noop: bound in move_notify() */ |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 70 | if (ttm->sg) { |
Ben Skeggs | 2e2cfbe | 2013-11-15 11:56:49 +1000 | [diff] [blame] | 71 | node->sg = ttm->sg; |
| 72 | node->pages = NULL; |
| 73 | } else { |
| 74 | node->sg = NULL; |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 75 | node->pages = nvbe->ttm.dma_address; |
Ben Skeggs | 2e2cfbe | 2013-11-15 11:56:49 +1000 | [diff] [blame] | 76 | } |
| 77 | node->size = (mem->num_pages << PAGE_SHIFT) >> 12; |
Ben Skeggs | b571fe2 | 2010-11-16 10:13:05 +1000 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 82 | nv50_sgdma_unbind(struct ttm_tt *ttm) |
Ben Skeggs | b571fe2 | 2010-11-16 10:13:05 +1000 | [diff] [blame] | 83 | { |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 84 | /* noop: unbound in move_notify() */ |
Ben Skeggs | b571fe2 | 2010-11-16 10:13:05 +1000 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
Ben Skeggs | b571fe2 | 2010-11-16 10:13:05 +1000 | [diff] [blame] | 88 | static struct ttm_backend_func nv50_sgdma_backend = { |
Ben Skeggs | b571fe2 | 2010-11-16 10:13:05 +1000 | [diff] [blame] | 89 | .bind = nv50_sgdma_bind, |
| 90 | .unbind = nv50_sgdma_unbind, |
| 91 | .destroy = nouveau_sgdma_destroy |
| 92 | }; |
| 93 | |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 94 | struct ttm_tt * |
| 95 | nouveau_sgdma_create_ttm(struct ttm_bo_device *bdev, |
| 96 | unsigned long size, uint32_t page_flags, |
| 97 | struct page *dummy_read_page) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 98 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 99 | struct nouveau_drm *drm = nouveau_bdev(bdev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 100 | struct nouveau_sgdma_be *nvbe; |
| 101 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 102 | nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL); |
| 103 | if (!nvbe) |
| 104 | return NULL; |
| 105 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 106 | nvbe->dev = drm->dev; |
| 107 | if (nv_device(drm->device)->card_type < NV_50) |
| 108 | nvbe->ttm.ttm.func = &nv04_sgdma_backend; |
| 109 | else |
| 110 | nvbe->ttm.ttm.func = &nv50_sgdma_backend; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 111 | |
Ben Skeggs | 7a59cc3 | 2013-09-17 14:13:32 +1000 | [diff] [blame] | 112 | if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page)) |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 113 | return NULL; |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 114 | return &nvbe->ttm.ttm; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 115 | } |