Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nv84.c
Go to the documentation of this file.
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/fifo.h>
34 #include <engine/crypt.h>
35 
38 };
39 
42 };
43 
44 /*******************************************************************************
45  * Crypt object classes
46  ******************************************************************************/
47 
48 static int
49 nv84_crypt_object_ctor(struct nouveau_object *parent,
50  struct nouveau_object *engine,
51  struct nouveau_oclass *oclass, void *data, u32 size,
52  struct nouveau_object **pobject)
53 {
54  struct nouveau_gpuobj *obj;
55  int ret;
56 
57  ret = nouveau_gpuobj_create(parent, engine, oclass, 0, parent,
58  16, 16, 0, &obj);
59  *pobject = nv_object(obj);
60  if (ret)
61  return ret;
62 
63  nv_wo32(obj, 0x00, nv_mclass(obj));
64  nv_wo32(obj, 0x04, 0x00000000);
65  nv_wo32(obj, 0x08, 0x00000000);
66  nv_wo32(obj, 0x0c, 0x00000000);
67  return 0;
68 }
69 
70 static struct nouveau_ofuncs
71 nv84_crypt_ofuncs = {
72  .ctor = nv84_crypt_object_ctor,
73  .dtor = _nouveau_gpuobj_dtor,
74  .init = _nouveau_gpuobj_init,
75  .fini = _nouveau_gpuobj_fini,
76  .rd32 = _nouveau_gpuobj_rd32,
77  .wr32 = _nouveau_gpuobj_wr32,
78 };
79 
80 static struct nouveau_oclass
81 nv84_crypt_sclass[] = {
82  { 0x74c1, &nv84_crypt_ofuncs },
83  {}
84 };
85 
86 /*******************************************************************************
87  * PCRYPT context
88  ******************************************************************************/
89 
90 static int
91 nv84_crypt_context_ctor(struct nouveau_object *parent,
92  struct nouveau_object *engine,
93  struct nouveau_oclass *oclass, void *data, u32 size,
94  struct nouveau_object **pobject)
95 {
96  struct nv84_crypt_chan *priv;
97  int ret;
98 
99  ret = nouveau_crypt_context_create(parent, engine, oclass, NULL, 256,
100  0, NVOBJ_FLAG_ZERO_ALLOC, &priv);
101  *pobject = nv_object(priv);
102  if (ret)
103  return ret;
104 
105  return 0;
106 }
107 
108 static struct nouveau_oclass
109 nv84_crypt_cclass = {
110  .handle = NV_ENGCTX(CRYPT, 0x84),
111  .ofuncs = &(struct nouveau_ofuncs) {
112  .ctor = nv84_crypt_context_ctor,
118  },
119 };
120 
121 /*******************************************************************************
122  * PCRYPT engine/subdev functions
123  ******************************************************************************/
124 
125 static const struct nouveau_bitfield nv84_crypt_intr_mask[] = {
126  { 0x00000001, "INVALID_STATE" },
127  { 0x00000002, "ILLEGAL_MTHD" },
128  { 0x00000004, "ILLEGAL_CLASS" },
129  { 0x00000080, "QUERY" },
130  { 0x00000100, "FAULT" },
131  {}
132 };
133 
134 static void
135 nv84_crypt_intr(struct nouveau_subdev *subdev)
136 {
137  struct nouveau_fifo *pfifo = nouveau_fifo(subdev);
138  struct nouveau_engine *engine = nv_engine(subdev);
139  struct nouveau_object *engctx;
140  struct nv84_crypt_priv *priv = (void *)subdev;
141  u32 stat = nv_rd32(priv, 0x102130);
142  u32 mthd = nv_rd32(priv, 0x102190);
143  u32 data = nv_rd32(priv, 0x102194);
144  u32 inst = nv_rd32(priv, 0x102188) & 0x7fffffff;
145  int chid;
146 
147  engctx = nouveau_engctx_get(engine, inst);
148  chid = pfifo->chid(pfifo, engctx);
149 
150  if (stat) {
151  nv_error(priv, "");
152  nouveau_bitfield_print(nv84_crypt_intr_mask, stat);
153  printk(" ch %d [0x%010llx] mthd 0x%04x data 0x%08x\n",
154  chid, (u64)inst << 12, mthd, data);
155  }
156 
157  nv_wr32(priv, 0x102130, stat);
158  nv_wr32(priv, 0x10200c, 0x10);
159 
160  nv50_fb_trap(nouveau_fb(priv), 1);
161  nouveau_engctx_put(engctx);
162 }
163 
164 static int
165 nv84_crypt_tlb_flush(struct nouveau_engine *engine)
166 {
167  nv50_vm_flush_engine(&engine->base, 0x0a);
168  return 0;
169 }
170 
171 static int
172 nv84_crypt_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
173  struct nouveau_oclass *oclass, void *data, u32 size,
174  struct nouveau_object **pobject)
175 {
176  struct nv84_crypt_priv *priv;
177  int ret;
178 
179  ret = nouveau_crypt_create(parent, engine, oclass, &priv);
180  *pobject = nv_object(priv);
181  if (ret)
182  return ret;
183 
184  nv_subdev(priv)->unit = 0x00004000;
185  nv_subdev(priv)->intr = nv84_crypt_intr;
186  nv_engine(priv)->cclass = &nv84_crypt_cclass;
187  nv_engine(priv)->sclass = nv84_crypt_sclass;
188  nv_engine(priv)->tlb_flush = nv84_crypt_tlb_flush;
189  return 0;
190 }
191 
192 static int
193 nv84_crypt_init(struct nouveau_object *object)
194 {
195  struct nv84_crypt_priv *priv = (void *)object;
196  int ret;
197 
198  ret = nouveau_crypt_init(&priv->base);
199  if (ret)
200  return ret;
201 
202  nv_wr32(priv, 0x102130, 0xffffffff);
203  nv_wr32(priv, 0x102140, 0xffffffbf);
204  nv_wr32(priv, 0x10200c, 0x00000010);
205  return 0;
206 }
207 
208 struct nouveau_oclass
210  .handle = NV_ENGINE(CRYPT, 0x84),
211  .ofuncs = &(struct nouveau_ofuncs) {
212  .ctor = nv84_crypt_ctor,
213  .dtor = _nouveau_crypt_dtor,
214  .init = nv84_crypt_init,
215  .fini = _nouveau_crypt_fini,
216  },
217 };