Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nv98.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 
30 #include <subdev/timer.h>
31 #include <subdev/fb.h>
32 
33 #include <engine/fifo.h>
34 #include <engine/crypt.h>
35 
36 #include "fuc/nv98.fuc.h"
37 
40 };
41 
44 };
45 
46 /*******************************************************************************
47  * Crypt object classes
48  ******************************************************************************/
49 
50 static struct nouveau_oclass
51 nv98_crypt_sclass[] = {
52  { 0x88b4, &nouveau_object_ofuncs },
53  {},
54 };
55 
56 /*******************************************************************************
57  * PCRYPT context
58  ******************************************************************************/
59 
60 static int
61 nv98_crypt_context_ctor(struct nouveau_object *parent,
62  struct nouveau_object *engine,
63  struct nouveau_oclass *oclass, void *data, u32 size,
64  struct nouveau_object **pobject)
65 {
66  struct nv98_crypt_chan *priv;
67  int ret;
68 
69  ret = nouveau_crypt_context_create(parent, engine, oclass, NULL, 256,
70  256, NVOBJ_FLAG_ZERO_ALLOC, &priv);
71  *pobject = nv_object(priv);
72  if (ret)
73  return ret;
74 
75  return 0;
76 }
77 
78 static struct nouveau_oclass
79 nv98_crypt_cclass = {
80  .handle = NV_ENGCTX(CRYPT, 0x98),
81  .ofuncs = &(struct nouveau_ofuncs) {
82  .ctor = nv98_crypt_context_ctor,
88  },
89 };
90 
91 /*******************************************************************************
92  * PCRYPT engine/subdev functions
93  ******************************************************************************/
94 
95 static const struct nouveau_enum nv98_crypt_isr_error_name[] = {
96  { 0x0000, "ILLEGAL_MTHD" },
97  { 0x0001, "INVALID_BITFIELD" },
98  { 0x0002, "INVALID_ENUM" },
99  { 0x0003, "QUERY" },
100  {}
101 };
102 
103 static void
104 nv98_crypt_intr(struct nouveau_subdev *subdev)
105 {
106  struct nouveau_fifo *pfifo = nouveau_fifo(subdev);
107  struct nouveau_engine *engine = nv_engine(subdev);
108  struct nouveau_object *engctx;
109  struct nv98_crypt_priv *priv = (void *)subdev;
110  u32 disp = nv_rd32(priv, 0x08701c);
111  u32 stat = nv_rd32(priv, 0x087008) & disp & ~(disp >> 16);
112  u32 inst = nv_rd32(priv, 0x087050) & 0x3fffffff;
113  u32 ssta = nv_rd32(priv, 0x087040) & 0x0000ffff;
114  u32 addr = nv_rd32(priv, 0x087040) >> 16;
115  u32 mthd = (addr & 0x07ff) << 2;
116  u32 subc = (addr & 0x3800) >> 11;
117  u32 data = nv_rd32(priv, 0x087044);
118  int chid;
119 
120  engctx = nouveau_engctx_get(engine, inst);
121  chid = pfifo->chid(pfifo, engctx);
122 
123  if (stat & 0x00000040) {
124  nv_error(priv, "DISPATCH_ERROR [");
125  nouveau_enum_print(nv98_crypt_isr_error_name, ssta);
126  printk("] ch %d [0x%010llx] subc %d mthd 0x%04x data 0x%08x\n",
127  chid, (u64)inst << 12, subc, mthd, data);
128  nv_wr32(priv, 0x087004, 0x00000040);
129  stat &= ~0x00000040;
130  }
131 
132  if (stat) {
133  nv_error(priv, "unhandled intr 0x%08x\n", stat);
134  nv_wr32(priv, 0x087004, stat);
135  }
136 
137  nv50_fb_trap(nouveau_fb(priv), 1);
138  nouveau_engctx_put(engctx);
139 }
140 
141 static int
142 nv98_crypt_tlb_flush(struct nouveau_engine *engine)
143 {
144  nv50_vm_flush_engine(&engine->base, 0x0a);
145  return 0;
146 }
147 
148 static int
149 nv98_crypt_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
150  struct nouveau_oclass *oclass, void *data, u32 size,
151  struct nouveau_object **pobject)
152 {
153  struct nv98_crypt_priv *priv;
154  int ret;
155 
156  ret = nouveau_crypt_create(parent, engine, oclass, &priv);
157  *pobject = nv_object(priv);
158  if (ret)
159  return ret;
160 
161  nv_subdev(priv)->unit = 0x00004000;
162  nv_subdev(priv)->intr = nv98_crypt_intr;
163  nv_engine(priv)->cclass = &nv98_crypt_cclass;
164  nv_engine(priv)->sclass = nv98_crypt_sclass;
165  nv_engine(priv)->tlb_flush = nv98_crypt_tlb_flush;
166  return 0;
167 }
168 
169 static int
170 nv98_crypt_init(struct nouveau_object *object)
171 {
172  struct nv98_crypt_priv *priv = (void *)object;
173  int ret, i;
174 
175  ret = nouveau_crypt_init(&priv->base);
176  if (ret)
177  return ret;
178 
179  /* wait for exit interrupt to signal */
180  nv_wait(priv, 0x087008, 0x00000010, 0x00000010);
181  nv_wr32(priv, 0x087004, 0x00000010);
182 
183  /* upload microcode code and data segments */
184  nv_wr32(priv, 0x087ff8, 0x00100000);
185  for (i = 0; i < ARRAY_SIZE(nv98_pcrypt_code); i++)
186  nv_wr32(priv, 0x087ff4, nv98_pcrypt_code[i]);
187 
188  nv_wr32(priv, 0x087ff8, 0x00000000);
189  for (i = 0; i < ARRAY_SIZE(nv98_pcrypt_data); i++)
190  nv_wr32(priv, 0x087ff4, nv98_pcrypt_data[i]);
191 
192  /* start it running */
193  nv_wr32(priv, 0x08710c, 0x00000000);
194  nv_wr32(priv, 0x087104, 0x00000000); /* ENTRY */
195  nv_wr32(priv, 0x087100, 0x00000002); /* TRIGGER */
196  return 0;
197 }
198 
199 struct nouveau_oclass
201  .handle = NV_ENGINE(CRYPT, 0x98),
202  .ofuncs = &(struct nouveau_ofuncs) {
203  .ctor = nv98_crypt_ctor,
204  .dtor = _nouveau_crypt_dtor,
205  .init = nv98_crypt_init,
206  .fini = _nouveau_crypt_fini,
207  },
208 };