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 "mem.h"
0023 
0024 #include <core/memory.h>
0025 #include <subdev/bar.h>
0026 #include <subdev/fb.h>
0027 
0028 #include <nvif/class.h>
0029 #include <nvif/if900b.h>
0030 #include <nvif/if900d.h>
0031 #include <nvif/unpack.h>
0032 
0033 int
0034 gf100_mem_map(struct nvkm_mmu *mmu, struct nvkm_memory *memory, void *argv,
0035           u32 argc, u64 *paddr, u64 *psize, struct nvkm_vma **pvma)
0036 {
0037     struct gf100_vmm_map_v0 uvmm = {};
0038     union {
0039         struct gf100_mem_map_vn vn;
0040         struct gf100_mem_map_v0 v0;
0041     } *args = argv;
0042     struct nvkm_device *device = mmu->subdev.device;
0043     struct nvkm_vmm *bar = nvkm_bar_bar1_vmm(device);
0044     int ret = -ENOSYS;
0045 
0046     if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
0047         uvmm.ro   = args->v0.ro;
0048         uvmm.kind = args->v0.kind;
0049     } else
0050     if (!(ret = nvif_unvers(ret, &argv, &argc, args->vn))) {
0051     } else
0052         return ret;
0053 
0054     ret = nvkm_vmm_get(bar, nvkm_memory_page(memory),
0055                 nvkm_memory_size(memory), pvma);
0056     if (ret)
0057         return ret;
0058 
0059     ret = nvkm_memory_map(memory, 0, bar, *pvma, &uvmm, sizeof(uvmm));
0060     if (ret)
0061         return ret;
0062 
0063     *paddr = device->func->resource_addr(device, 1) + (*pvma)->addr;
0064     *psize = (*pvma)->size;
0065     return 0;
0066 }
0067 
0068 int
0069 gf100_mem_new(struct nvkm_mmu *mmu, int type, u8 page, u64 size,
0070           void *argv, u32 argc, struct nvkm_memory **pmemory)
0071 {
0072     union {
0073         struct gf100_mem_vn vn;
0074         struct gf100_mem_v0 v0;
0075     } *args = argv;
0076     int ret = -ENOSYS;
0077     bool contig;
0078 
0079     if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
0080         contig = args->v0.contig;
0081     } else
0082     if (!(ret = nvif_unvers(ret, &argv, &argc, args->vn))) {
0083         contig = false;
0084     } else
0085         return ret;
0086 
0087     if (mmu->type[type].type & (NVKM_MEM_DISP | NVKM_MEM_COMP))
0088         type = NVKM_RAM_MM_NORMAL;
0089     else
0090         type = NVKM_RAM_MM_MIXED;
0091 
0092     return nvkm_ram_get(mmu->subdev.device, type, 0x01, page,
0093                 size, contig, false, pmemory);
0094 }