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_ctor_map(struct nvif_mmu
*mmu
, const char *name
, u8 type
, u64 size
,
31 int ret
= nvif_mem_ctor(mmu
, name
, mmu
->mem
, NVIF_MEM_MAPPABLE
| type
,
32 0, size
, NULL
, 0, mem
);
34 ret
= nvif_object_map(&mem
->object
, NULL
, 0);
42 nvif_mem_dtor(struct nvif_mem
*mem
)
44 nvif_object_dtor(&mem
->object
);
48 nvif_mem_ctor_type(struct nvif_mmu
*mmu
, const char *name
, s32 oclass
,
49 int type
, u8 page
, u64 size
, void *argv
, u32 argc
,
52 struct nvif_mem_v0
*args
;
56 mem
->object
.client
= NULL
;
60 if (sizeof(*args
) + argc
> sizeof(stack
)) {
61 if (!(args
= kmalloc(sizeof(*args
) + argc
, GFP_KERNEL
)))
70 memcpy(args
->data
, argv
, argc
);
72 ret
= nvif_object_ctor(&mmu
->object
, name
? name
: "nvifMem", 0, oclass
,
73 args
, sizeof(*args
) + argc
, &mem
->object
);
75 mem
->type
= mmu
->type
[type
].type
;
76 mem
->page
= args
->page
;
77 mem
->addr
= args
->addr
;
78 mem
->size
= args
->size
;
81 if (args
!= (void *)stack
)
88 nvif_mem_ctor(struct nvif_mmu
*mmu
, const char *name
, s32 oclass
, u8 type
,
89 u8 page
, u64 size
, void *argv
, u32 argc
, struct nvif_mem
*mem
)
93 mem
->object
.client
= NULL
;
95 for (i
= 0; ret
&& i
< mmu
->type_nr
; i
++) {
96 if ((mmu
->type
[i
].type
& type
) == type
) {
97 ret
= nvif_mem_ctor_type(mmu
, name
, oclass
, i
, page
,
98 size
, argv
, argc
, mem
);