Home | History | Annotate | Line # | Download | only in mmu
      1 /*	$NetBSD: nouveau_nvkm_subdev_mmu_vmmgv100.c,v 1.2 2021/12/18 23:45:41 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2018 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_vmmgv100.c,v 1.2 2021/12/18 23:45:41 riastradh Exp $");
     26 
     27 #include "vmm.h"
     28 
     29 #include <subdev/fb.h>
     30 #include <subdev/ltc.h>
     31 
     32 #include <nvif/ifc00d.h>
     33 #include <nvif/unpack.h>
     34 
     35 int
     36 gv100_vmm_join(struct nvkm_vmm *vmm, struct nvkm_memory *inst)
     37 {
     38 	u64 data[2], mask;
     39 	int ret = gp100_vmm_join(vmm, inst), i;
     40 	if (ret)
     41 		return ret;
     42 
     43 	nvkm_kmap(inst);
     44 	data[0] = nvkm_ro32(inst, 0x200);
     45 	data[1] = nvkm_ro32(inst, 0x204);
     46 	mask = BIT_ULL(0);
     47 
     48 	nvkm_wo32(inst, 0x21c, 0x00000000);
     49 
     50 	for (i = 0; i < 64; i++) {
     51 		if (mask & BIT_ULL(i)) {
     52 			nvkm_wo32(inst, 0x2a4 + (i * 0x10), data[1]);
     53 			nvkm_wo32(inst, 0x2a0 + (i * 0x10), data[0]);
     54 		} else {
     55 			nvkm_wo32(inst, 0x2a4 + (i * 0x10), 0x00000001);
     56 			nvkm_wo32(inst, 0x2a0 + (i * 0x10), 0x00000001);
     57 		}
     58 		nvkm_wo32(inst, 0x2a8 + (i * 0x10), 0x00000000);
     59 	}
     60 
     61 	nvkm_wo32(inst, 0x298, lower_32_bits(mask));
     62 	nvkm_wo32(inst, 0x29c, upper_32_bits(mask));
     63 	nvkm_done(inst);
     64 	return 0;
     65 }
     66 
     67 static const struct nvkm_vmm_func
     68 gv100_vmm = {
     69 	.join = gv100_vmm_join,
     70 	.part = gf100_vmm_part,
     71 	.aper = gf100_vmm_aper,
     72 	.valid = gp100_vmm_valid,
     73 	.flush = gp100_vmm_flush,
     74 	.mthd = gp100_vmm_mthd,
     75 	.invalidate_pdb = gp100_vmm_invalidate_pdb,
     76 	.page = {
     77 		{ 47, &gp100_vmm_desc_16[4], NVKM_VMM_PAGE_Sxxx },
     78 		{ 38, &gp100_vmm_desc_16[3], NVKM_VMM_PAGE_Sxxx },
     79 		{ 29, &gp100_vmm_desc_16[2], NVKM_VMM_PAGE_Sxxx },
     80 		{ 21, &gp100_vmm_desc_16[1], NVKM_VMM_PAGE_SVxC },
     81 		{ 16, &gp100_vmm_desc_16[0], NVKM_VMM_PAGE_SVxC },
     82 		{ 12, &gp100_vmm_desc_12[0], NVKM_VMM_PAGE_SVHx },
     83 		{}
     84 	}
     85 };
     86 
     87 int
     88 gv100_vmm_new(struct nvkm_mmu *mmu, bool managed, u64 addr, u64 size,
     89 	      void *argv, u32 argc, struct lock_class_key *key,
     90 	      const char *name, struct nvkm_vmm **pvmm)
     91 {
     92 	return gp100_vmm_new_(&gv100_vmm, mmu, managed, addr, size,
     93 			      argv, argc, key, name, pvmm);
     94 }
     95