This source file includes following definitions.
- nvif_mmu_fini
- nvif_mmu_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include <nvif/mmu.h>
23
24 #include <nvif/class.h>
25 #include <nvif/if0008.h>
26
27 void
28 nvif_mmu_fini(struct nvif_mmu *mmu)
29 {
30 kfree(mmu->kind);
31 kfree(mmu->type);
32 kfree(mmu->heap);
33 nvif_object_fini(&mmu->object);
34 }
35
36 int
37 nvif_mmu_init(struct nvif_object *parent, s32 oclass, struct nvif_mmu *mmu)
38 {
39 static const struct nvif_mclass mems[] = {
40 { NVIF_CLASS_MEM_GF100, -1 },
41 { NVIF_CLASS_MEM_NV50 , -1 },
42 { NVIF_CLASS_MEM_NV04 , -1 },
43 {}
44 };
45 struct nvif_mmu_v0 args;
46 int ret, i;
47
48 args.version = 0;
49 mmu->heap = NULL;
50 mmu->type = NULL;
51 mmu->kind = NULL;
52
53 ret = nvif_object_init(parent, 0, oclass, &args, sizeof(args),
54 &mmu->object);
55 if (ret)
56 goto done;
57
58 mmu->dmabits = args.dmabits;
59 mmu->heap_nr = args.heap_nr;
60 mmu->type_nr = args.type_nr;
61 mmu->kind_nr = args.kind_nr;
62
63 ret = nvif_mclass(&mmu->object, mems);
64 if (ret < 0)
65 goto done;
66 mmu->mem = mems[ret].oclass;
67
68 mmu->heap = kmalloc_array(mmu->heap_nr, sizeof(*mmu->heap),
69 GFP_KERNEL);
70 mmu->type = kmalloc_array(mmu->type_nr, sizeof(*mmu->type),
71 GFP_KERNEL);
72 if (ret = -ENOMEM, !mmu->heap || !mmu->type)
73 goto done;
74
75 mmu->kind = kmalloc_array(mmu->kind_nr, sizeof(*mmu->kind),
76 GFP_KERNEL);
77 if (!mmu->kind && mmu->kind_nr)
78 goto done;
79
80 for (i = 0; i < mmu->heap_nr; i++) {
81 struct nvif_mmu_heap_v0 args = { .index = i };
82
83 ret = nvif_object_mthd(&mmu->object, NVIF_MMU_V0_HEAP,
84 &args, sizeof(args));
85 if (ret)
86 goto done;
87
88 mmu->heap[i].size = args.size;
89 }
90
91 for (i = 0; i < mmu->type_nr; i++) {
92 struct nvif_mmu_type_v0 args = { .index = i };
93
94 ret = nvif_object_mthd(&mmu->object, NVIF_MMU_V0_TYPE,
95 &args, sizeof(args));
96 if (ret)
97 goto done;
98
99 mmu->type[i].type = 0;
100 if (args.vram) mmu->type[i].type |= NVIF_MEM_VRAM;
101 if (args.host) mmu->type[i].type |= NVIF_MEM_HOST;
102 if (args.comp) mmu->type[i].type |= NVIF_MEM_COMP;
103 if (args.disp) mmu->type[i].type |= NVIF_MEM_DISP;
104 if (args.kind ) mmu->type[i].type |= NVIF_MEM_KIND;
105 if (args.mappable) mmu->type[i].type |= NVIF_MEM_MAPPABLE;
106 if (args.coherent) mmu->type[i].type |= NVIF_MEM_COHERENT;
107 if (args.uncached) mmu->type[i].type |= NVIF_MEM_UNCACHED;
108 mmu->type[i].heap = args.heap;
109 }
110
111 if (mmu->kind_nr) {
112 struct nvif_mmu_kind_v0 *kind;
113 size_t argc = struct_size(kind, data, mmu->kind_nr);
114
115 if (ret = -ENOMEM, !(kind = kmalloc(argc, GFP_KERNEL)))
116 goto done;
117 kind->version = 0;
118 kind->count = mmu->kind_nr;
119
120 ret = nvif_object_mthd(&mmu->object, NVIF_MMU_V0_KIND,
121 kind, argc);
122 if (ret == 0)
123 memcpy(mmu->kind, kind->data, kind->count);
124 kfree(kind);
125 }
126
127 done:
128 if (ret)
129 nvif_mmu_fini(mmu);
130 return ret;
131 }