1 #include <linux/pagemap.h>
2 #include <linux/slab.h>
4 #include "nouveau_drm.h"
5 #include "nouveau_ttm.h"
7 struct nouveau_sgdma_be
{
8 /* this has to be the first field so populate/unpopulated in
9 * nouve_bo.c works properly, otherwise have to move them here
11 struct ttm_dma_tt ttm
;
12 struct nvkm_mem
*node
;
16 nouveau_sgdma_destroy(struct ttm_tt
*ttm
)
18 struct nouveau_sgdma_be
*nvbe
= (struct nouveau_sgdma_be
*)ttm
;
21 ttm_dma_tt_fini(&nvbe
->ttm
);
27 nv04_sgdma_bind(struct ttm_tt
*ttm
, struct ttm_mem_reg
*mem
)
29 struct nouveau_sgdma_be
*nvbe
= (struct nouveau_sgdma_be
*)ttm
;
30 struct nvkm_mem
*node
= mem
->mm_node
;
37 node
->pages
= nvbe
->ttm
.dma_address
;
39 node
->size
= (mem
->num_pages
<< PAGE_SHIFT
) >> 12;
41 nvkm_vm_map(&node
->vma
[0], node
);
47 nv04_sgdma_unbind(struct ttm_tt
*ttm
)
49 struct nouveau_sgdma_be
*nvbe
= (struct nouveau_sgdma_be
*)ttm
;
50 nvkm_vm_unmap(&nvbe
->node
->vma
[0]);
54 static struct ttm_backend_func nv04_sgdma_backend
= {
55 .bind
= nv04_sgdma_bind
,
56 .unbind
= nv04_sgdma_unbind
,
57 .destroy
= nouveau_sgdma_destroy
61 nv50_sgdma_bind(struct ttm_tt
*ttm
, struct ttm_mem_reg
*mem
)
63 struct nouveau_sgdma_be
*nvbe
= (struct nouveau_sgdma_be
*)ttm
;
64 struct nvkm_mem
*node
= mem
->mm_node
;
66 /* noop: bound in move_notify() */
72 node
->pages
= nvbe
->ttm
.dma_address
;
74 node
->size
= (mem
->num_pages
<< PAGE_SHIFT
) >> 12;
79 nv50_sgdma_unbind(struct ttm_tt
*ttm
)
81 /* noop: unbound in move_notify() */
85 static struct ttm_backend_func nv50_sgdma_backend
= {
86 .bind
= nv50_sgdma_bind
,
87 .unbind
= nv50_sgdma_unbind
,
88 .destroy
= nouveau_sgdma_destroy
92 nouveau_sgdma_create_ttm(struct ttm_bo_device
*bdev
,
93 unsigned long size
, uint32_t page_flags
,
94 struct page
*dummy_read_page
)
96 struct nouveau_drm
*drm
= nouveau_bdev(bdev
);
97 struct nouveau_sgdma_be
*nvbe
;
99 nvbe
= kzalloc(sizeof(*nvbe
), GFP_KERNEL
);
103 if (drm
->device
.info
.family
< NV_DEVICE_INFO_V0_TESLA
)
104 nvbe
->ttm
.ttm
.func
= &nv04_sgdma_backend
;
106 nvbe
->ttm
.ttm
.func
= &nv50_sgdma_backend
;
108 if (ttm_dma_tt_init(&nvbe
->ttm
, bdev
, size
, page_flags
, dummy_read_page
))
110 * A failing ttm_dma_tt_init() will call ttm_tt_destroy()
111 * and thus our nouveau_sgdma_destroy() hook, so we don't need
115 return &nvbe
->ttm
.ttm
;