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.
24 #include <nvif/class.h>
25 #include <nvif/if0008.h>
28 nvif_mmu_fini(struct nvif_mmu
*mmu
)
33 nvif_object_fini(&mmu
->object
);
37 nvif_mmu_init(struct nvif_object
*parent
, s32 oclass
, struct nvif_mmu
*mmu
)
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 },
45 struct nvif_mmu_v0 args
;
53 ret
= nvif_object_init(parent
, 0, oclass
, &args
, sizeof(args
),
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
;
63 ret
= nvif_mclass(&mmu
->object
, mems
);
66 mmu
->mem
= mems
[ret
].oclass
;
68 mmu
->heap
= kmalloc_array(mmu
->heap_nr
, sizeof(*mmu
->heap
),
70 mmu
->type
= kmalloc_array(mmu
->type_nr
, sizeof(*mmu
->type
),
72 if (ret
= -ENOMEM
, !mmu
->heap
|| !mmu
->type
)
75 mmu
->kind
= kmalloc_array(mmu
->kind_nr
, sizeof(*mmu
->kind
),
77 if (!mmu
->kind
&& mmu
->kind_nr
)
80 for (i
= 0; i
< mmu
->heap_nr
; i
++) {
81 struct nvif_mmu_heap_v0 args
= { .index
= i
};
83 ret
= nvif_object_mthd(&mmu
->object
, NVIF_MMU_V0_HEAP
,
88 mmu
->heap
[i
].size
= args
.size
;
91 for (i
= 0; i
< mmu
->type_nr
; i
++) {
92 struct nvif_mmu_type_v0 args
= { .index
= i
};
94 ret
= nvif_object_mthd(&mmu
->object
, NVIF_MMU_V0_TYPE
,
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
;
112 struct nvif_mmu_kind_v0
*kind
;
113 u32 argc
= sizeof(*kind
) + sizeof(*kind
->data
) * mmu
->kind_nr
;
115 if (ret
= -ENOMEM
, !(kind
= kmalloc(argc
, GFP_KERNEL
)))
118 kind
->count
= mmu
->kind_nr
;
120 ret
= nvif_object_mthd(&mmu
->object
, NVIF_MMU_V0_KIND
,
123 memcpy(mmu
->kind
, kind
->data
, kind
->count
);