drm/nouveau: port all engines to new engine module format
[deliverable/linux.git] / drivers / gpu / drm / nouveau / core / engine / crypt / nv84.c
1 /*
2 * Copyright 2012 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
25 #include <core/os.h>
26 #include <core/enum.h>
27 #include <core/class.h>
28 #include <core/engctx.h>
29 #include <core/gpuobj.h>
30
31 #include <subdev/fb.h>
32
33 #include <engine/crypt.h>
34
35 struct nv84_crypt_priv {
36 struct nouveau_crypt base;
37 };
38
39 struct nv84_crypt_chan {
40 struct nouveau_crypt_chan base;
41 };
42
43 /*******************************************************************************
44 * Crypt object classes
45 ******************************************************************************/
46
47 static int
48 nv84_crypt_object_ctor(struct nouveau_object *parent,
49 struct nouveau_object *engine,
50 struct nouveau_oclass *oclass, void *data, u32 size,
51 struct nouveau_object **pobject)
52 {
53 struct nouveau_gpuobj *obj;
54 int ret;
55
56 ret = nouveau_gpuobj_create(parent, engine, oclass, 0, parent,
57 16, 16, 0, &obj);
58 *pobject = nv_object(obj);
59 if (ret)
60 return ret;
61
62 nv_wo32(obj, 0x00, nv_mclass(obj));
63 nv_wo32(obj, 0x04, 0x00000000);
64 nv_wo32(obj, 0x08, 0x00000000);
65 nv_wo32(obj, 0x0c, 0x00000000);
66 return 0;
67 }
68
69 static struct nouveau_ofuncs
70 nv84_crypt_ofuncs = {
71 .ctor = nv84_crypt_object_ctor,
72 .dtor = _nouveau_gpuobj_dtor,
73 .init = _nouveau_gpuobj_init,
74 .fini = _nouveau_gpuobj_fini,
75 .rd32 = _nouveau_gpuobj_rd32,
76 .wr32 = _nouveau_gpuobj_wr32,
77 };
78
79 static struct nouveau_oclass
80 nv84_crypt_sclass[] = {
81 { 0x74c1, &nv84_crypt_ofuncs },
82 {}
83 };
84
85 /*******************************************************************************
86 * PCRYPT context
87 ******************************************************************************/
88
89 static int
90 nv84_crypt_context_ctor(struct nouveau_object *parent,
91 struct nouveau_object *engine,
92 struct nouveau_oclass *oclass, void *data, u32 size,
93 struct nouveau_object **pobject)
94 {
95 struct nv84_crypt_chan *priv;
96 int ret;
97
98 ret = nouveau_crypt_context_create(parent, engine, oclass, NULL, 256,
99 0, NVOBJ_FLAG_ZERO_ALLOC, &priv);
100 *pobject = nv_object(priv);
101 if (ret)
102 return ret;
103
104 return 0;
105 }
106
107 static struct nouveau_oclass
108 nv84_crypt_cclass = {
109 .handle = NV_ENGCTX(CRYPT, 0x84),
110 .ofuncs = &(struct nouveau_ofuncs) {
111 .ctor = nv84_crypt_context_ctor,
112 .dtor = _nouveau_crypt_context_dtor,
113 .init = _nouveau_crypt_context_init,
114 .fini = _nouveau_crypt_context_fini,
115 .rd32 = _nouveau_crypt_context_rd32,
116 .wr32 = _nouveau_crypt_context_wr32,
117 },
118 };
119
120 /*******************************************************************************
121 * PCRYPT engine/subdev functions
122 ******************************************************************************/
123
124 static struct nouveau_bitfield nv84_crypt_intr_mask[] = {
125 { 0x00000001, "INVALID_STATE" },
126 { 0x00000002, "ILLEGAL_MTHD" },
127 { 0x00000004, "ILLEGAL_CLASS" },
128 { 0x00000080, "QUERY" },
129 { 0x00000100, "FAULT" },
130 {}
131 };
132
133 static void
134 nv84_crypt_intr(struct nouveau_subdev *subdev)
135 {
136 struct nv84_crypt_priv *priv = (void *)subdev;
137 u32 stat = nv_rd32(priv, 0x102130);
138 u32 mthd = nv_rd32(priv, 0x102190);
139 u32 data = nv_rd32(priv, 0x102194);
140 u32 inst = nv_rd32(priv, 0x102188) & 0x7fffffff;
141
142 if (stat) {
143 nv_error(priv, "");
144 nouveau_bitfield_print(nv84_crypt_intr_mask, stat);
145 printk(" ch 0x%010llx mthd 0x%04x data 0x%08x\n",
146 (u64)inst << 12, mthd, data);
147 }
148
149 nv_wr32(priv, 0x102130, stat);
150 nv_wr32(priv, 0x10200c, 0x10);
151
152 nv50_fb_trap(nouveau_fb(priv), 1);
153 }
154
155 static int
156 nv84_crypt_tlb_flush(struct nouveau_engine *engine)
157 {
158 nv50_vm_flush_engine(&engine->base, 0x0a);
159 return 0;
160 }
161
162 static int
163 nv84_crypt_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
164 struct nouveau_oclass *oclass, void *data, u32 size,
165 struct nouveau_object **pobject)
166 {
167 struct nv84_crypt_priv *priv;
168 int ret;
169
170 ret = nouveau_crypt_create(parent, engine, oclass, &priv);
171 *pobject = nv_object(priv);
172 if (ret)
173 return ret;
174
175 nv_subdev(priv)->unit = 0x00004000;
176 nv_subdev(priv)->intr = nv84_crypt_intr;
177 nv_engine(priv)->cclass = &nv84_crypt_cclass;
178 nv_engine(priv)->sclass = nv84_crypt_sclass;
179 nv_engine(priv)->tlb_flush = nv84_crypt_tlb_flush;
180 return 0;
181 }
182
183 static int
184 nv84_crypt_init(struct nouveau_object *object)
185 {
186 struct nv84_crypt_priv *priv = (void *)object;
187 int ret;
188
189 ret = nouveau_crypt_init(&priv->base);
190 if (ret)
191 return ret;
192
193 nv_wr32(priv, 0x102130, 0xffffffff);
194 nv_wr32(priv, 0x102140, 0xffffffbf);
195 nv_wr32(priv, 0x10200c, 0x00000010);
196 return 0;
197 }
198
199 struct nouveau_oclass
200 nv84_crypt_oclass = {
201 .handle = NV_ENGINE(CRYPT, 0x84),
202 .ofuncs = &(struct nouveau_ofuncs) {
203 .ctor = nv84_crypt_ctor,
204 .dtor = _nouveau_crypt_dtor,
205 .init = nv84_crypt_init,
206 .fini = _nouveau_crypt_fini,
207 },
208 };
This page took 0.035471 seconds and 5 git commands to generate.