Home | History | Annotate | Line # | Download | only in mpeg
      1 /*	$NetBSD: nouveau_nvkm_engine_mpeg_nv50.c,v 1.3 2021/12/18 23:45:36 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2012 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  * Authors: Ben Skeggs
     25  */
     26 #include <sys/cdefs.h>
     27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_mpeg_nv50.c,v 1.3 2021/12/18 23:45:36 riastradh Exp $");
     28 
     29 #include "priv.h"
     30 
     31 #include <core/gpuobj.h>
     32 #include <core/object.h>
     33 #include <subdev/timer.h>
     34 
     35 #include <nvif/class.h>
     36 
     37 /*******************************************************************************
     38  * PMPEG context
     39  ******************************************************************************/
     40 
     41 static int
     42 nv50_mpeg_cclass_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
     43 		      int align, struct nvkm_gpuobj **pgpuobj)
     44 {
     45 	int ret = nvkm_gpuobj_new(object->engine->subdev.device, 128 * 4,
     46 				  align, true, parent, pgpuobj);
     47 	if (ret == 0) {
     48 		nvkm_kmap(*pgpuobj);
     49 		nvkm_wo32(*pgpuobj, 0x70, 0x00801ec1);
     50 		nvkm_wo32(*pgpuobj, 0x7c, 0x0000037c);
     51 		nvkm_done(*pgpuobj);
     52 	}
     53 	return ret;
     54 }
     55 
     56 const struct nvkm_object_func
     57 nv50_mpeg_cclass = {
     58 	.bind = nv50_mpeg_cclass_bind,
     59 };
     60 
     61 /*******************************************************************************
     62  * PMPEG engine/subdev functions
     63  ******************************************************************************/
     64 
     65 void
     66 nv50_mpeg_intr(struct nvkm_engine *mpeg)
     67 {
     68 	struct nvkm_subdev *subdev = &mpeg->subdev;
     69 	struct nvkm_device *device = subdev->device;
     70 	u32 stat = nvkm_rd32(device, 0x00b100);
     71 	u32 type = nvkm_rd32(device, 0x00b230);
     72 	u32 mthd = nvkm_rd32(device, 0x00b234);
     73 	u32 data = nvkm_rd32(device, 0x00b238);
     74 	u32 show = stat;
     75 
     76 	if (stat & 0x01000000) {
     77 		/* happens on initial binding of the object */
     78 		if (type == 0x00000020 && mthd == 0x0000) {
     79 			nvkm_wr32(device, 0x00b308, 0x00000100);
     80 			show &= ~0x01000000;
     81 		}
     82 	}
     83 
     84 	if (show) {
     85 		nvkm_info(subdev, "%08x %08x %08x %08x\n",
     86 			  stat, type, mthd, data);
     87 	}
     88 
     89 	nvkm_wr32(device, 0x00b100, stat);
     90 	nvkm_wr32(device, 0x00b230, 0x00000001);
     91 }
     92 
     93 int
     94 nv50_mpeg_init(struct nvkm_engine *mpeg)
     95 {
     96 	struct nvkm_subdev *subdev = &mpeg->subdev;
     97 	struct nvkm_device *device = subdev->device;
     98 
     99 	nvkm_wr32(device, 0x00b32c, 0x00000000);
    100 	nvkm_wr32(device, 0x00b314, 0x00000100);
    101 	nvkm_wr32(device, 0x00b0e0, 0x0000001a);
    102 
    103 	nvkm_wr32(device, 0x00b220, 0x00000044);
    104 	nvkm_wr32(device, 0x00b300, 0x00801ec1);
    105 	nvkm_wr32(device, 0x00b390, 0x00000000);
    106 	nvkm_wr32(device, 0x00b394, 0x00000000);
    107 	nvkm_wr32(device, 0x00b398, 0x00000000);
    108 	nvkm_mask(device, 0x00b32c, 0x00000001, 0x00000001);
    109 
    110 	nvkm_wr32(device, 0x00b100, 0xffffffff);
    111 	nvkm_wr32(device, 0x00b140, 0xffffffff);
    112 
    113 	if (nvkm_msec(device, 2000,
    114 		if (!(nvkm_rd32(device, 0x00b200) & 0x00000001))
    115 			break;
    116 	) < 0) {
    117 		nvkm_error(subdev, "timeout %08x\n",
    118 			   nvkm_rd32(device, 0x00b200));
    119 		return -EBUSY;
    120 	}
    121 
    122 	return 0;
    123 }
    124 
    125 static const struct nvkm_engine_func
    126 nv50_mpeg = {
    127 	.init = nv50_mpeg_init,
    128 	.intr = nv50_mpeg_intr,
    129 	.cclass = &nv50_mpeg_cclass,
    130 	.sclass = {
    131 		{ -1, -1, NV31_MPEG, &nv31_mpeg_object },
    132 		{}
    133 	}
    134 };
    135 
    136 int
    137 nv50_mpeg_new(struct nvkm_device *device, int index, struct nvkm_engine **pmpeg)
    138 {
    139 	return nvkm_engine_new_(&nv50_mpeg, device, index, true, pmpeg);
    140 }
    141