Home | History | Annotate | Line # | Download | only in mmu
      1 /*	$NetBSD: nouveau_nvkm_subdev_mmu_memnv04.c,v 1.3 2021/12/19 10:51:58 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2017 Red Hat Inc.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be included in
     14  * all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  * OTHER DEALINGS IN THE SOFTWARE.
     23  */
     24 #include <sys/cdefs.h>
     25 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_mmu_memnv04.c,v 1.3 2021/12/19 10:51:58 riastradh Exp $");
     26 
     27 #include "mem.h"
     28 
     29 #include <core/memory.h>
     30 #include <subdev/fb.h>
     31 
     32 #include <nvif/if000b.h>
     33 #include <nvif/unpack.h>
     34 
     35 int
     36 #ifdef __NetBSD__
     37 nv04_mem_map(struct nvkm_mmu *mmu, struct nvkm_memory *memory, void *argv,
     38 	     u32 argc, bus_space_tag_t *ptag, u64 *paddr, u64 *psize, struct nvkm_vma **pvma)
     39 #else
     40 nv04_mem_map(struct nvkm_mmu *mmu, struct nvkm_memory *memory, void *argv,
     41 	     u32 argc, u64 *paddr, u64 *psize, struct nvkm_vma **pvma)
     42 #endif
     43 {
     44 	union {
     45 		struct nv04_mem_map_vn vn;
     46 	} *args = argv;
     47 	struct nvkm_device *device = mmu->subdev.device;
     48 	const u64 addr = nvkm_memory_addr(memory);
     49 	int ret = -ENOSYS;
     50 
     51 	if ((ret = nvif_unvers(ret, &argv, &argc, args->vn)))
     52 		return ret;
     53 
     54 #ifdef __NetBSD__
     55 	*ptag = device->func->resource_tag(device, 1);
     56 #endif
     57 	*paddr = device->func->resource_addr(device, 1) + addr;
     58 	*psize = nvkm_memory_size(memory);
     59 	*pvma = ERR_PTR(-ENODEV);
     60 	return 0;
     61 }
     62 
     63 int
     64 nv04_mem_new(struct nvkm_mmu *mmu, int type, u8 page, u64 size,
     65 	     void *argv, u32 argc, struct nvkm_memory **pmemory)
     66 {
     67 	union {
     68 		struct nv04_mem_vn vn;
     69 	} *args = argv;
     70 	int ret = -ENOSYS;
     71 
     72 	if ((ret = nvif_unvers(ret, &argv, &argc, args->vn)))
     73 		return ret;
     74 
     75 	if (mmu->type[type].type & NVKM_MEM_MAPPABLE)
     76 		type = NVKM_RAM_MM_NORMAL;
     77 	else
     78 		type = NVKM_RAM_MM_NOMAP;
     79 
     80 	return nvkm_ram_get(mmu->subdev.device, type, 0x01, page,
     81 			    size, true, false, pmemory);
     82 }
     83