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.
23 #include <nvif/client.h>
25 #include <nvif/if000a.h>
28 nvif_mem_init_map(struct nvif_mmu
*mmu
, u8 type
, u64 size
, struct nvif_mem
*mem
)
30 int ret
= nvif_mem_init(mmu
, mmu
->mem
, NVIF_MEM_MAPPABLE
| type
, 0,
33 ret
= nvif_object_map(&mem
->object
, NULL
, 0);
41 nvif_mem_fini(struct nvif_mem
*mem
)
43 nvif_object_fini(&mem
->object
);
47 nvif_mem_init_type(struct nvif_mmu
*mmu
, s32 oclass
, int type
, u8 page
,
48 u64 size
, void *argv
, u32 argc
, struct nvif_mem
*mem
)
50 struct nvif_mem_v0
*args
;
54 mem
->object
.client
= NULL
;
58 if (sizeof(*args
) + argc
> sizeof(stack
)) {
59 if (!(args
= kmalloc(sizeof(*args
) + argc
, GFP_KERNEL
)))
68 memcpy(args
->data
, argv
, argc
);
70 ret
= nvif_object_init(&mmu
->object
, 0, oclass
, args
,
71 sizeof(*args
) + argc
, &mem
->object
);
73 mem
->type
= mmu
->type
[type
].type
;
74 mem
->page
= args
->page
;
75 mem
->addr
= args
->addr
;
76 mem
->size
= args
->size
;
79 if (args
!= (void *)stack
)
86 nvif_mem_init(struct nvif_mmu
*mmu
, s32 oclass
, u8 type
, u8 page
,
87 u64 size
, void *argv
, u32 argc
, struct nvif_mem
*mem
)
91 mem
->object
.client
= NULL
;
93 for (i
= 0; ret
&& i
< mmu
->type_nr
; i
++) {
94 if ((mmu
->type
[i
].type
& type
) == type
) {
95 ret
= nvif_mem_init_type(mmu
, oclass
, i
, page
, size
,