1 /*
2 * Copyright 2015 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24 #include <engine/ce.h>
25
26 #include <core/engctx.h>
27
28 struct gm204_ce_priv {
29 struct nvkm_engine base;
30 };
31
32 /*******************************************************************************
33 * Copy object classes
34 ******************************************************************************/
35
36 static struct nvkm_oclass
37 gm204_ce_sclass[] = {
38 { 0xb0b5, &nvkm_object_ofuncs },
39 {},
40 };
41
42 /*******************************************************************************
43 * PCE context
44 ******************************************************************************/
45
46 static struct nvkm_ofuncs
47 gm204_ce_context_ofuncs = {
48 .ctor = _nvkm_engctx_ctor,
49 .dtor = _nvkm_engctx_dtor,
50 .init = _nvkm_engctx_init,
51 .fini = _nvkm_engctx_fini,
52 .rd32 = _nvkm_engctx_rd32,
53 .wr32 = _nvkm_engctx_wr32,
54 };
55
56 static struct nvkm_oclass
57 gm204_ce_cclass = {
58 .handle = NV_ENGCTX(CE0, 0x24),
59 .ofuncs = &gm204_ce_context_ofuncs,
60 };
61
62 /*******************************************************************************
63 * PCE engine/subdev functions
64 ******************************************************************************/
65
66 static void
gm204_ce_intr(struct nvkm_subdev * subdev)67 gm204_ce_intr(struct nvkm_subdev *subdev)
68 {
69 const int ce = nv_subidx(subdev) - NVDEV_ENGINE_CE0;
70 struct gm204_ce_priv *priv = (void *)subdev;
71 u32 stat = nv_rd32(priv, 0x104908 + (ce * 0x1000));
72
73 if (stat) {
74 nv_warn(priv, "unhandled intr 0x%08x\n", stat);
75 nv_wr32(priv, 0x104908 + (ce * 0x1000), stat);
76 }
77 }
78
79 static int
gm204_ce0_ctor(struct nvkm_object * parent,struct nvkm_object * engine,struct nvkm_oclass * oclass,void * data,u32 size,struct nvkm_object ** pobject)80 gm204_ce0_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
81 struct nvkm_oclass *oclass, void *data, u32 size,
82 struct nvkm_object **pobject)
83 {
84 struct gm204_ce_priv *priv;
85 int ret;
86
87 ret = nvkm_engine_create(parent, engine, oclass, true,
88 "PCE0", "ce0", &priv);
89 *pobject = nv_object(priv);
90 if (ret)
91 return ret;
92
93 nv_subdev(priv)->unit = 0x00000040;
94 nv_subdev(priv)->intr = gm204_ce_intr;
95 nv_engine(priv)->cclass = &gm204_ce_cclass;
96 nv_engine(priv)->sclass = gm204_ce_sclass;
97 return 0;
98 }
99
100 static int
gm204_ce1_ctor(struct nvkm_object * parent,struct nvkm_object * engine,struct nvkm_oclass * oclass,void * data,u32 size,struct nvkm_object ** pobject)101 gm204_ce1_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
102 struct nvkm_oclass *oclass, void *data, u32 size,
103 struct nvkm_object **pobject)
104 {
105 struct gm204_ce_priv *priv;
106 int ret;
107
108 ret = nvkm_engine_create(parent, engine, oclass, true,
109 "PCE1", "ce1", &priv);
110 *pobject = nv_object(priv);
111 if (ret)
112 return ret;
113
114 nv_subdev(priv)->unit = 0x00000080;
115 nv_subdev(priv)->intr = gm204_ce_intr;
116 nv_engine(priv)->cclass = &gm204_ce_cclass;
117 nv_engine(priv)->sclass = gm204_ce_sclass;
118 return 0;
119 }
120
121 static int
gm204_ce2_ctor(struct nvkm_object * parent,struct nvkm_object * engine,struct nvkm_oclass * oclass,void * data,u32 size,struct nvkm_object ** pobject)122 gm204_ce2_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
123 struct nvkm_oclass *oclass, void *data, u32 size,
124 struct nvkm_object **pobject)
125 {
126 struct gm204_ce_priv *priv;
127 int ret;
128
129 ret = nvkm_engine_create(parent, engine, oclass, true,
130 "PCE2", "ce2", &priv);
131 *pobject = nv_object(priv);
132 if (ret)
133 return ret;
134
135 nv_subdev(priv)->unit = 0x00200000;
136 nv_subdev(priv)->intr = gm204_ce_intr;
137 nv_engine(priv)->cclass = &gm204_ce_cclass;
138 nv_engine(priv)->sclass = gm204_ce_sclass;
139 return 0;
140 }
141
142 struct nvkm_oclass
143 gm204_ce0_oclass = {
144 .handle = NV_ENGINE(CE0, 0x24),
145 .ofuncs = &(struct nvkm_ofuncs) {
146 .ctor = gm204_ce0_ctor,
147 .dtor = _nvkm_engine_dtor,
148 .init = _nvkm_engine_init,
149 .fini = _nvkm_engine_fini,
150 },
151 };
152
153 struct nvkm_oclass
154 gm204_ce1_oclass = {
155 .handle = NV_ENGINE(CE1, 0x24),
156 .ofuncs = &(struct nvkm_ofuncs) {
157 .ctor = gm204_ce1_ctor,
158 .dtor = _nvkm_engine_dtor,
159 .init = _nvkm_engine_init,
160 .fini = _nvkm_engine_fini,
161 },
162 };
163
164 struct nvkm_oclass
165 gm204_ce2_oclass = {
166 .handle = NV_ENGINE(CE2, 0x24),
167 .ofuncs = &(struct nvkm_ofuncs) {
168 .ctor = gm204_ce2_ctor,
169 .dtor = _nvkm_engine_dtor,
170 .init = _nvkm_engine_init,
171 .fini = _nvkm_engine_fini,
172 },
173 };
174