xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvkm/engine/mpeg/nv50.c (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs  * Copyright 2012 Red Hat Inc.
3c39f472eSBen Skeggs  *
4c39f472eSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs  * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs  *
11c39f472eSBen Skeggs  * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs  * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs  *
14c39f472eSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17c39f472eSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs  *
22c39f472eSBen Skeggs  * Authors: Ben Skeggs
23c39f472eSBen Skeggs  */
24218f978dSBen Skeggs #include "priv.h"
25c39f472eSBen Skeggs 
26218f978dSBen Skeggs #include <core/gpuobj.h>
274246b92cSBen Skeggs #include <core/object.h>
28c39f472eSBen Skeggs #include <subdev/timer.h>
29c39f472eSBen Skeggs 
30218f978dSBen Skeggs #include <nvif/class.h>
31c39f472eSBen Skeggs 
32c39f472eSBen Skeggs /*******************************************************************************
33c39f472eSBen Skeggs  * PMPEG context
34c39f472eSBen Skeggs  ******************************************************************************/
35c39f472eSBen Skeggs 
36218f978dSBen Skeggs static int
nv50_mpeg_cclass_bind(struct nvkm_object * object,struct nvkm_gpuobj * parent,int align,struct nvkm_gpuobj ** pgpuobj)37218f978dSBen Skeggs nv50_mpeg_cclass_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
38218f978dSBen Skeggs 		      int align, struct nvkm_gpuobj **pgpuobj)
39c39f472eSBen Skeggs {
40218f978dSBen Skeggs 	int ret = nvkm_gpuobj_new(object->engine->subdev.device, 128 * 4,
41218f978dSBen Skeggs 				  align, true, parent, pgpuobj);
42218f978dSBen Skeggs 	if (ret == 0) {
43218f978dSBen Skeggs 		nvkm_kmap(*pgpuobj);
44218f978dSBen Skeggs 		nvkm_wo32(*pgpuobj, 0x70, 0x00801ec1);
45218f978dSBen Skeggs 		nvkm_wo32(*pgpuobj, 0x7c, 0x0000037c);
46218f978dSBen Skeggs 		nvkm_done(*pgpuobj);
47218f978dSBen Skeggs 	}
48c39f472eSBen Skeggs 	return ret;
49c39f472eSBen Skeggs }
50c39f472eSBen Skeggs 
51218f978dSBen Skeggs const struct nvkm_object_func
52c39f472eSBen Skeggs nv50_mpeg_cclass = {
53218f978dSBen Skeggs 	.bind = nv50_mpeg_cclass_bind,
54c39f472eSBen Skeggs };
55c39f472eSBen Skeggs 
56c39f472eSBen Skeggs /*******************************************************************************
57c39f472eSBen Skeggs  * PMPEG engine/subdev functions
58c39f472eSBen Skeggs  ******************************************************************************/
59c39f472eSBen Skeggs 
60c39f472eSBen Skeggs void
nv50_mpeg_intr(struct nvkm_engine * mpeg)617624fc01SBen Skeggs nv50_mpeg_intr(struct nvkm_engine *mpeg)
62c39f472eSBen Skeggs {
637624fc01SBen Skeggs 	struct nvkm_subdev *subdev = &mpeg->subdev;
647624fc01SBen Skeggs 	struct nvkm_device *device = subdev->device;
65636e37aaSBen Skeggs 	u32 stat = nvkm_rd32(device, 0x00b100);
66636e37aaSBen Skeggs 	u32 type = nvkm_rd32(device, 0x00b230);
67636e37aaSBen Skeggs 	u32 mthd = nvkm_rd32(device, 0x00b234);
68636e37aaSBen Skeggs 	u32 data = nvkm_rd32(device, 0x00b238);
69c39f472eSBen Skeggs 	u32 show = stat;
70c39f472eSBen Skeggs 
71c39f472eSBen Skeggs 	if (stat & 0x01000000) {
72c39f472eSBen Skeggs 		/* happens on initial binding of the object */
73c39f472eSBen Skeggs 		if (type == 0x00000020 && mthd == 0x0000) {
74636e37aaSBen Skeggs 			nvkm_wr32(device, 0x00b308, 0x00000100);
75c39f472eSBen Skeggs 			show &= ~0x01000000;
76c39f472eSBen Skeggs 		}
77c39f472eSBen Skeggs 	}
78c39f472eSBen Skeggs 
79c39f472eSBen Skeggs 	if (show) {
80b835c09bSBen Skeggs 		nvkm_info(subdev, "%08x %08x %08x %08x\n",
81c39f472eSBen Skeggs 			  stat, type, mthd, data);
82c39f472eSBen Skeggs 	}
83c39f472eSBen Skeggs 
84636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b100, stat);
85636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b230, 0x00000001);
86c39f472eSBen Skeggs }
87c39f472eSBen Skeggs 
88c39f472eSBen Skeggs int
nv50_mpeg_init(struct nvkm_engine * mpeg)897624fc01SBen Skeggs nv50_mpeg_init(struct nvkm_engine *mpeg)
90c39f472eSBen Skeggs {
917624fc01SBen Skeggs 	struct nvkm_subdev *subdev = &mpeg->subdev;
92b835c09bSBen Skeggs 	struct nvkm_device *device = subdev->device;
93c39f472eSBen Skeggs 
94636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b32c, 0x00000000);
95636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b314, 0x00000100);
96636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b0e0, 0x0000001a);
97c39f472eSBen Skeggs 
98636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b220, 0x00000044);
99636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b300, 0x00801ec1);
100636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b390, 0x00000000);
101636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b394, 0x00000000);
102636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b398, 0x00000000);
103636e37aaSBen Skeggs 	nvkm_mask(device, 0x00b32c, 0x00000001, 0x00000001);
104c39f472eSBen Skeggs 
105636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b100, 0xffffffff);
106636e37aaSBen Skeggs 	nvkm_wr32(device, 0x00b140, 0xffffffff);
107c39f472eSBen Skeggs 
10837eabb03SBen Skeggs 	if (nvkm_msec(device, 2000,
10937eabb03SBen Skeggs 		if (!(nvkm_rd32(device, 0x00b200) & 0x00000001))
11037eabb03SBen Skeggs 			break;
11137eabb03SBen Skeggs 	) < 0) {
112b835c09bSBen Skeggs 		nvkm_error(subdev, "timeout %08x\n",
113b835c09bSBen Skeggs 			   nvkm_rd32(device, 0x00b200));
114c39f472eSBen Skeggs 		return -EBUSY;
115c39f472eSBen Skeggs 	}
116c39f472eSBen Skeggs 
117c39f472eSBen Skeggs 	return 0;
118c39f472eSBen Skeggs }
119c39f472eSBen Skeggs 
1207624fc01SBen Skeggs static const struct nvkm_engine_func
1217624fc01SBen Skeggs nv50_mpeg = {
122c39f472eSBen Skeggs 	.init = nv50_mpeg_init,
1237624fc01SBen Skeggs 	.intr = nv50_mpeg_intr,
1247624fc01SBen Skeggs 	.cclass = &nv50_mpeg_cclass,
1257624fc01SBen Skeggs 	.sclass = {
1267624fc01SBen Skeggs 		{ -1, -1, NV31_MPEG, &nv31_mpeg_object },
1277624fc01SBen Skeggs 		{}
1287624fc01SBen Skeggs 	}
129c39f472eSBen Skeggs };
1307624fc01SBen Skeggs 
1317624fc01SBen Skeggs int
nv50_mpeg_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_engine ** pmpeg)132*e5e95a76SBen Skeggs nv50_mpeg_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
133*e5e95a76SBen Skeggs 	      struct nvkm_engine **pmpeg)
1347624fc01SBen Skeggs {
135*e5e95a76SBen Skeggs 	return nvkm_engine_new_(&nv50_mpeg, device, type, inst, true, pmpeg);
1367624fc01SBen Skeggs }
137