Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2017 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  */
0022 #include "ummu.h"
0023 #include "umem.h"
0024 #include "uvmm.h"
0025 
0026 #include <core/client.h>
0027 
0028 #include <nvif/if0008.h>
0029 #include <nvif/unpack.h>
0030 
0031 static int
0032 nvkm_ummu_sclass(struct nvkm_object *object, int index,
0033          struct nvkm_oclass *oclass)
0034 {
0035     struct nvkm_mmu *mmu = nvkm_ummu(object)->mmu;
0036 
0037     if (mmu->func->mem.user.oclass) {
0038         if (index-- == 0) {
0039             oclass->base = mmu->func->mem.user;
0040             oclass->ctor = nvkm_umem_new;
0041             return 0;
0042         }
0043     }
0044 
0045     if (mmu->func->vmm.user.oclass) {
0046         if (index-- == 0) {
0047             oclass->base = mmu->func->vmm.user;
0048             oclass->ctor = nvkm_uvmm_new;
0049             return 0;
0050         }
0051     }
0052 
0053     return -EINVAL;
0054 }
0055 
0056 static int
0057 nvkm_ummu_heap(struct nvkm_ummu *ummu, void *argv, u32 argc)
0058 {
0059     struct nvkm_mmu *mmu = ummu->mmu;
0060     union {
0061         struct nvif_mmu_heap_v0 v0;
0062     } *args = argv;
0063     int ret = -ENOSYS;
0064     u8 index;
0065 
0066     if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
0067         if ((index = args->v0.index) >= mmu->heap_nr)
0068             return -EINVAL;
0069         args->v0.size = mmu->heap[index].size;
0070     } else
0071         return ret;
0072 
0073     return 0;
0074 }
0075 
0076 static int
0077 nvkm_ummu_type(struct nvkm_ummu *ummu, void *argv, u32 argc)
0078 {
0079     struct nvkm_mmu *mmu = ummu->mmu;
0080     union {
0081         struct nvif_mmu_type_v0 v0;
0082     } *args = argv;
0083     int ret = -ENOSYS;
0084     u8 type, index;
0085 
0086     if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
0087         if ((index = args->v0.index) >= mmu->type_nr)
0088             return -EINVAL;
0089         type = mmu->type[index].type;
0090         args->v0.heap = mmu->type[index].heap;
0091         args->v0.vram = !!(type & NVKM_MEM_VRAM);
0092         args->v0.host = !!(type & NVKM_MEM_HOST);
0093         args->v0.comp = !!(type & NVKM_MEM_COMP);
0094         args->v0.disp = !!(type & NVKM_MEM_DISP);
0095         args->v0.kind = !!(type & NVKM_MEM_KIND);
0096         args->v0.mappable = !!(type & NVKM_MEM_MAPPABLE);
0097         args->v0.coherent = !!(type & NVKM_MEM_COHERENT);
0098         args->v0.uncached = !!(type & NVKM_MEM_UNCACHED);
0099     } else
0100         return ret;
0101 
0102     return 0;
0103 }
0104 
0105 static int
0106 nvkm_ummu_kind(struct nvkm_ummu *ummu, void *argv, u32 argc)
0107 {
0108     struct nvkm_mmu *mmu = ummu->mmu;
0109     union {
0110         struct nvif_mmu_kind_v0 v0;
0111     } *args = argv;
0112     const u8 *kind = NULL;
0113     int ret = -ENOSYS, count = 0;
0114     u8 kind_inv = 0;
0115 
0116     if (mmu->func->kind)
0117         kind = mmu->func->kind(mmu, &count, &kind_inv);
0118 
0119     if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, true))) {
0120         if (argc != args->v0.count * sizeof(*args->v0.data))
0121             return -EINVAL;
0122         if (args->v0.count > count)
0123             return -EINVAL;
0124         args->v0.kind_inv = kind_inv;
0125         memcpy(args->v0.data, kind, args->v0.count);
0126     } else
0127         return ret;
0128 
0129     return 0;
0130 }
0131 
0132 static int
0133 nvkm_ummu_mthd(struct nvkm_object *object, u32 mthd, void *argv, u32 argc)
0134 {
0135     struct nvkm_ummu *ummu = nvkm_ummu(object);
0136     switch (mthd) {
0137     case NVIF_MMU_V0_HEAP: return nvkm_ummu_heap(ummu, argv, argc);
0138     case NVIF_MMU_V0_TYPE: return nvkm_ummu_type(ummu, argv, argc);
0139     case NVIF_MMU_V0_KIND: return nvkm_ummu_kind(ummu, argv, argc);
0140     default:
0141         break;
0142     }
0143     return -EINVAL;
0144 }
0145 
0146 static const struct nvkm_object_func
0147 nvkm_ummu = {
0148     .mthd = nvkm_ummu_mthd,
0149     .sclass = nvkm_ummu_sclass,
0150 };
0151 
0152 int
0153 nvkm_ummu_new(struct nvkm_device *device, const struct nvkm_oclass *oclass,
0154           void *argv, u32 argc, struct nvkm_object **pobject)
0155 {
0156     union {
0157         struct nvif_mmu_v0 v0;
0158     } *args = argv;
0159     struct nvkm_mmu *mmu = device->mmu;
0160     struct nvkm_ummu *ummu;
0161     int ret = -ENOSYS, kinds = 0;
0162     u8 unused = 0;
0163 
0164     if (mmu->func->kind)
0165         mmu->func->kind(mmu, &kinds, &unused);
0166 
0167     if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
0168         args->v0.dmabits = mmu->dma_bits;
0169         args->v0.heap_nr = mmu->heap_nr;
0170         args->v0.type_nr = mmu->type_nr;
0171         args->v0.kind_nr = kinds;
0172     } else
0173         return ret;
0174 
0175     if (!(ummu = kzalloc(sizeof(*ummu), GFP_KERNEL)))
0176         return -ENOMEM;
0177     nvkm_object_ctor(&nvkm_ummu, oclass, &ummu->object);
0178     ummu->mmu = mmu;
0179     *pobject = &ummu->object;
0180     return 0;
0181 }