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/fb.h>
0026 
0027 #include <nvif/if000b.h>
0028 #include <nvif/unpack.h>
0029 
0030 int
0031 nv04_mem_map(struct nvkm_mmu *mmu, struct nvkm_memory *memory, void *argv,
0032          u32 argc, u64 *paddr, u64 *psize, struct nvkm_vma **pvma)
0033 {
0034     union {
0035         struct nv04_mem_map_vn vn;
0036     } *args = argv;
0037     struct nvkm_device *device = mmu->subdev.device;
0038     const u64 addr = nvkm_memory_addr(memory);
0039     int ret = -ENOSYS;
0040 
0041     if ((ret = nvif_unvers(ret, &argv, &argc, args->vn)))
0042         return ret;
0043 
0044     *paddr = device->func->resource_addr(device, 1) + addr;
0045     *psize = nvkm_memory_size(memory);
0046     *pvma = ERR_PTR(-ENODEV);
0047     return 0;
0048 }
0049 
0050 int
0051 nv04_mem_new(struct nvkm_mmu *mmu, int type, u8 page, u64 size,
0052          void *argv, u32 argc, struct nvkm_memory **pmemory)
0053 {
0054     union {
0055         struct nv04_mem_vn vn;
0056     } *args = argv;
0057     int ret = -ENOSYS;
0058 
0059     if ((ret = nvif_unvers(ret, &argv, &argc, args->vn)))
0060         return ret;
0061 
0062     if (mmu->type[type].type & NVKM_MEM_MAPPABLE)
0063         type = NVKM_RAM_MM_NORMAL;
0064     else
0065         type = NVKM_RAM_MM_NOMAP;
0066 
0067     return nvkm_ram_get(mmu->subdev.device, type, 0x01, page,
0068                 size, true, false, pmemory);
0069 }