Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / gpu / drm / nouveau / nvif / mmu.c
blob15d0dcbf7ab41d5599b472a0122042cc825ec34e
1 /*
2 * Copyright 2017 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 #include <nvif/mmu.h>
24 #include <nvif/class.h>
25 #include <nvif/if0008.h>
27 void
28 nvif_mmu_fini(struct nvif_mmu *mmu)
30 kfree(mmu->kind);
31 kfree(mmu->type);
32 kfree(mmu->heap);
33 nvif_object_fini(&mmu->object);
36 int
37 nvif_mmu_init(struct nvif_object *parent, s32 oclass, struct nvif_mmu *mmu)
39 struct nvif_mmu_v0 args;
40 int ret, i;
42 args.version = 0;
43 mmu->heap = NULL;
44 mmu->type = NULL;
45 mmu->kind = NULL;
47 ret = nvif_object_init(parent, 0, oclass, &args, sizeof(args),
48 &mmu->object);
49 if (ret)
50 goto done;
52 mmu->dmabits = args.dmabits;
53 mmu->heap_nr = args.heap_nr;
54 mmu->type_nr = args.type_nr;
55 mmu->kind_nr = args.kind_nr;
57 mmu->heap = kmalloc(sizeof(*mmu->heap) * mmu->heap_nr, GFP_KERNEL);
58 mmu->type = kmalloc(sizeof(*mmu->type) * mmu->type_nr, GFP_KERNEL);
59 if (ret = -ENOMEM, !mmu->heap || !mmu->type)
60 goto done;
62 mmu->kind = kmalloc(sizeof(*mmu->kind) * mmu->kind_nr, GFP_KERNEL);
63 if (!mmu->kind && mmu->kind_nr)
64 goto done;
66 for (i = 0; i < mmu->heap_nr; i++) {
67 struct nvif_mmu_heap_v0 args = { .index = i };
69 ret = nvif_object_mthd(&mmu->object, NVIF_MMU_V0_HEAP,
70 &args, sizeof(args));
71 if (ret)
72 goto done;
74 mmu->heap[i].size = args.size;
77 for (i = 0; i < mmu->type_nr; i++) {
78 struct nvif_mmu_type_v0 args = { .index = i };
80 ret = nvif_object_mthd(&mmu->object, NVIF_MMU_V0_TYPE,
81 &args, sizeof(args));
82 if (ret)
83 goto done;
85 mmu->type[i].type = 0;
86 if (args.vram) mmu->type[i].type |= NVIF_MEM_VRAM;
87 if (args.host) mmu->type[i].type |= NVIF_MEM_HOST;
88 if (args.comp) mmu->type[i].type |= NVIF_MEM_COMP;
89 if (args.disp) mmu->type[i].type |= NVIF_MEM_DISP;
90 if (args.kind ) mmu->type[i].type |= NVIF_MEM_KIND;
91 if (args.mappable) mmu->type[i].type |= NVIF_MEM_MAPPABLE;
92 if (args.coherent) mmu->type[i].type |= NVIF_MEM_COHERENT;
93 if (args.uncached) mmu->type[i].type |= NVIF_MEM_UNCACHED;
94 mmu->type[i].heap = args.heap;
97 if (mmu->kind_nr) {
98 struct nvif_mmu_kind_v0 *kind;
99 u32 argc = sizeof(*kind) + sizeof(*kind->data) * mmu->kind_nr;
101 if (ret = -ENOMEM, !(kind = kmalloc(argc, GFP_KERNEL)))
102 goto done;
103 kind->version = 0;
104 kind->count = mmu->kind_nr;
106 ret = nvif_object_mthd(&mmu->object, NVIF_MMU_V0_KIND,
107 kind, argc);
108 if (ret == 0)
109 memcpy(mmu->kind, kind->data, kind->count);
110 kfree(kind);
113 done:
114 if (ret)
115 nvif_mmu_fini(mmu);
116 return ret;