1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <core/object.h>
26#include <core/class.h>
27
28#include <subdev/fb.h>
29#include <engine/dmaobj.h>
30
31static int
32nouveau_dmaobj_ctor(struct nouveau_object *parent,
33 struct nouveau_object *engine,
34 struct nouveau_oclass *oclass, void *data, u32 size,
35 struct nouveau_object **pobject)
36{
37 struct nouveau_dmaeng *dmaeng = (void *)engine;
38 struct nouveau_dmaobj *dmaobj;
39 struct nouveau_gpuobj *gpuobj;
40 struct nv_dma_class *args = data;
41 int ret;
42
43 if (size < sizeof(*args))
44 return -EINVAL;
45
46 ret = nouveau_object_create(parent, engine, oclass, 0, &dmaobj);
47 *pobject = nv_object(dmaobj);
48 if (ret)
49 return ret;
50
51 switch (args->flags & NV_DMA_TARGET_MASK) {
52 case NV_DMA_TARGET_VM:
53 dmaobj->target = NV_MEM_TARGET_VM;
54 break;
55 case NV_DMA_TARGET_VRAM:
56 dmaobj->target = NV_MEM_TARGET_VRAM;
57 break;
58 case NV_DMA_TARGET_PCI:
59 dmaobj->target = NV_MEM_TARGET_PCI;
60 break;
61 case NV_DMA_TARGET_PCI_US:
62 case NV_DMA_TARGET_AGP:
63 dmaobj->target = NV_MEM_TARGET_PCI_NOSNOOP;
64 break;
65 default:
66 return -EINVAL;
67 }
68
69 switch (args->flags & NV_DMA_ACCESS_MASK) {
70 case NV_DMA_ACCESS_VM:
71 dmaobj->access = NV_MEM_ACCESS_VM;
72 break;
73 case NV_DMA_ACCESS_RD:
74 dmaobj->access = NV_MEM_ACCESS_RO;
75 break;
76 case NV_DMA_ACCESS_WR:
77 dmaobj->access = NV_MEM_ACCESS_WO;
78 break;
79 case NV_DMA_ACCESS_RDWR:
80 dmaobj->access = NV_MEM_ACCESS_RW;
81 break;
82 default:
83 return -EINVAL;
84 }
85
86 dmaobj->start = args->start;
87 dmaobj->limit = args->limit;
88 dmaobj->conf0 = args->conf0;
89
90 switch (nv_mclass(parent)) {
91 case NV_DEVICE_CLASS:
92
93 break;
94 default:
95 ret = dmaeng->bind(dmaeng, *pobject, dmaobj, &gpuobj);
96 if (ret == 0) {
97 nouveau_object_ref(NULL, pobject);
98 *pobject = nv_object(gpuobj);
99 }
100 break;
101 }
102
103 return ret;
104}
105
106static struct nouveau_ofuncs
107nouveau_dmaobj_ofuncs = {
108 .ctor = nouveau_dmaobj_ctor,
109 .dtor = nouveau_object_destroy,
110 .init = nouveau_object_init,
111 .fini = nouveau_object_fini,
112};
113
114struct nouveau_oclass
115nouveau_dmaobj_sclass[] = {
116 { NV_DMA_FROM_MEMORY_CLASS, &nouveau_dmaobj_ofuncs },
117 { NV_DMA_TO_MEMORY_CLASS, &nouveau_dmaobj_ofuncs },
118 { NV_DMA_IN_MEMORY_CLASS, &nouveau_dmaobj_ofuncs },
119 {}
120};
121