Home | History | Annotate | Line # | Download | only in dma
      1 /*	$NetBSD: nouveau_nvkm_engine_dma_usergv100.c,v 1.2 2021/12/18 23:45:35 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_engine_dma_usergv100.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $");
     26 
     27 #define gv100_dmaobj(p) container_of((p), struct gv100_dmaobj, base)
     28 #include "user.h"
     29 
     30 #include <core/client.h>
     31 #include <core/gpuobj.h>
     32 #include <subdev/fb.h>
     33 
     34 #include <nvif/cl0002.h>
     35 #include <nvif/unpack.h>
     36 
     37 struct gv100_dmaobj {
     38 	struct nvkm_dmaobj base;
     39 	u32 flags0;
     40 };
     41 
     42 static int
     43 gv100_dmaobj_bind(struct nvkm_dmaobj *base, struct nvkm_gpuobj *parent,
     44 		  int align, struct nvkm_gpuobj **pgpuobj)
     45 {
     46 	struct gv100_dmaobj *dmaobj = gv100_dmaobj(base);
     47 	struct nvkm_device *device = dmaobj->base.dma->engine.subdev.device;
     48 	u64 start = dmaobj->base.start >> 8;
     49 	u64 limit = dmaobj->base.limit >> 8;
     50 	int ret;
     51 
     52 	ret = nvkm_gpuobj_new(device, 24, align, false, parent, pgpuobj);
     53 	if (ret == 0) {
     54 		nvkm_kmap(*pgpuobj);
     55 		nvkm_wo32(*pgpuobj, 0x00, dmaobj->flags0);
     56 		nvkm_wo32(*pgpuobj, 0x04, lower_32_bits(start));
     57 		nvkm_wo32(*pgpuobj, 0x08, upper_32_bits(start));
     58 		nvkm_wo32(*pgpuobj, 0x0c, lower_32_bits(limit));
     59 		nvkm_wo32(*pgpuobj, 0x10, upper_32_bits(limit));
     60 		nvkm_done(*pgpuobj);
     61 	}
     62 
     63 	return ret;
     64 }
     65 
     66 static const struct nvkm_dmaobj_func
     67 gv100_dmaobj_func = {
     68 	.bind = gv100_dmaobj_bind,
     69 };
     70 
     71 int
     72 gv100_dmaobj_new(struct nvkm_dma *dma, const struct nvkm_oclass *oclass,
     73 		 void *data, u32 size, struct nvkm_dmaobj **pdmaobj)
     74 {
     75 	union {
     76 		struct gf119_dma_v0 v0;
     77 	} *args;
     78 	struct nvkm_object *parent = oclass->parent;
     79 	struct gv100_dmaobj *dmaobj;
     80 	u32 kind, page;
     81 	int ret;
     82 
     83 	if (!(dmaobj = kzalloc(sizeof(*dmaobj), GFP_KERNEL)))
     84 		return -ENOMEM;
     85 	*pdmaobj = &dmaobj->base;
     86 
     87 	ret = nvkm_dmaobj_ctor(&gv100_dmaobj_func, dma, oclass,
     88 			       &data, &size, &dmaobj->base);
     89 	if (ret)
     90 		return ret;
     91 
     92 	ret  = -ENOSYS;
     93 	args = data;
     94 
     95 	nvif_ioctl(parent, "create gv100 dma size %d\n", size);
     96 	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
     97 		nvif_ioctl(parent,
     98 			   "create gv100 dma vers %d page %d kind %02x\n",
     99 			   args->v0.version, args->v0.page, args->v0.kind);
    100 		kind = args->v0.kind != 0;
    101 		page = args->v0.page != 0;
    102 	} else
    103 	if (size == 0) {
    104 		kind = 0;
    105 		page = GF119_DMA_V0_PAGE_SP;
    106 	} else
    107 		return ret;
    108 
    109 	if (kind)
    110 		dmaobj->flags0 |= 0x00100000;
    111 	if (page)
    112 		dmaobj->flags0 |= 0x00000040;
    113 	dmaobj->flags0 |= 0x00000004; /* rw */
    114 
    115 	switch (dmaobj->base.target) {
    116 	case NV_MEM_TARGET_VRAM       : dmaobj->flags0 |= 0x00000001; break;
    117 	case NV_MEM_TARGET_PCI        : dmaobj->flags0 |= 0x00000002; break;
    118 	case NV_MEM_TARGET_PCI_NOSNOOP: dmaobj->flags0 |= 0x00000003; break;
    119 	default:
    120 		return -EINVAL;
    121 	}
    122 
    123 	return 0;
    124 }
    125