dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nvif / mem.c
blobb6ebb3b5867325d5c45fef05f0ae585d8b894c88
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/mem.h>
23 #include <nvif/client.h>
25 #include <nvif/if000a.h>
27 int
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,
31 size, NULL, 0, mem);
32 if (ret == 0) {
33 ret = nvif_object_map(&mem->object, NULL, 0);
34 if (ret)
35 nvif_mem_fini(mem);
37 return ret;
40 void
41 nvif_mem_fini(struct nvif_mem *mem)
43 nvif_object_fini(&mem->object);
46 int
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;
51 u8 stack[128];
52 int ret;
54 mem->object.client = NULL;
55 if (type < 0)
56 return -EINVAL;
58 if (sizeof(*args) + argc > sizeof(stack)) {
59 if (!(args = kmalloc(sizeof(*args) + argc, GFP_KERNEL)))
60 return -ENOMEM;
61 } else {
62 args = (void *)stack;
64 args->version = 0;
65 args->type = type;
66 args->page = page;
67 args->size = size;
68 memcpy(args->data, argv, argc);
70 ret = nvif_object_init(&mmu->object, 0, oclass, args,
71 sizeof(*args) + argc, &mem->object);
72 if (ret == 0) {
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)
80 kfree(args);
81 return ret;
85 int
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)
89 int ret = -EINVAL, i;
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,
96 argv, argc, mem);
100 return ret;