Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nvc0.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 <engine/fifo.h>
31 #include <engine/copy.h>
32 
33 #include "fuc/nvc0.fuc.h"
34 
37 };
38 
41 };
42 
43 /*******************************************************************************
44  * Copy object classes
45  ******************************************************************************/
46 
47 static struct nouveau_oclass
48 nvc0_copy0_sclass[] = {
49  { 0x90b5, &nouveau_object_ofuncs },
50  {},
51 };
52 
53 static struct nouveau_oclass
54 nvc0_copy1_sclass[] = {
55  { 0x90b8, &nouveau_object_ofuncs },
56  {},
57 };
58 
59 /*******************************************************************************
60  * PCOPY context
61  ******************************************************************************/
62 
63 static int
64 nvc0_copy_context_ctor(struct nouveau_object *parent,
65  struct nouveau_object *engine,
66  struct nouveau_oclass *oclass, void *data, u32 size,
67  struct nouveau_object **pobject)
68 {
69  struct nvc0_copy_chan *priv;
70  int ret;
71 
72  ret = nouveau_copy_context_create(parent, engine, oclass, NULL, 256,
73  256, NVOBJ_FLAG_ZERO_ALLOC, &priv);
74  *pobject = nv_object(priv);
75  if (ret)
76  return ret;
77 
78  return 0;
79 }
80 
81 static struct nouveau_ofuncs
82 nvc0_copy_context_ofuncs = {
83  .ctor = nvc0_copy_context_ctor,
89 };
90 
91 static struct nouveau_oclass
92 nvc0_copy0_cclass = {
93  .handle = NV_ENGCTX(COPY0, 0xc0),
94  .ofuncs = &nvc0_copy_context_ofuncs,
95 };
96 
97 static struct nouveau_oclass
98 nvc0_copy1_cclass = {
99  .handle = NV_ENGCTX(COPY1, 0xc0),
100  .ofuncs = &nvc0_copy_context_ofuncs,
101 };
102 
103 /*******************************************************************************
104  * PCOPY engine/subdev functions
105  ******************************************************************************/
106 
107 static const struct nouveau_enum nvc0_copy_isr_error_name[] = {
108  { 0x0001, "ILLEGAL_MTHD" },
109  { 0x0002, "INVALID_ENUM" },
110  { 0x0003, "INVALID_BITFIELD" },
111  {}
112 };
113 
114 static void
115 nvc0_copy_intr(struct nouveau_subdev *subdev)
116 {
117  struct nouveau_fifo *pfifo = nouveau_fifo(subdev);
118  struct nouveau_engine *engine = nv_engine(subdev);
119  struct nouveau_object *engctx;
120  int idx = nv_engidx(nv_object(subdev)) - NVDEV_ENGINE_COPY0;
121  struct nvc0_copy_priv *priv = (void *)subdev;
122  u32 disp = nv_rd32(priv, 0x10401c + (idx * 0x1000));
123  u32 intr = nv_rd32(priv, 0x104008 + (idx * 0x1000));
124  u32 stat = intr & disp & ~(disp >> 16);
125  u64 inst = nv_rd32(priv, 0x104050 + (idx * 0x1000)) & 0x0fffffff;
126  u32 ssta = nv_rd32(priv, 0x104040 + (idx * 0x1000)) & 0x0000ffff;
127  u32 addr = nv_rd32(priv, 0x104040 + (idx * 0x1000)) >> 16;
128  u32 mthd = (addr & 0x07ff) << 2;
129  u32 subc = (addr & 0x3800) >> 11;
130  u32 data = nv_rd32(priv, 0x104044 + (idx * 0x1000));
131  int chid;
132 
133  engctx = nouveau_engctx_get(engine, inst);
134  chid = pfifo->chid(pfifo, engctx);
135 
136  if (stat & 0x00000040) {
137  nv_error(priv, "DISPATCH_ERROR [");
138  nouveau_enum_print(nvc0_copy_isr_error_name, ssta);
139  printk("] ch %d [0x%010llx] subc %d mthd 0x%04x data 0x%08x\n",
140  chid, (u64)inst << 12, subc, mthd, data);
141  nv_wr32(priv, 0x104004 + (idx * 0x1000), 0x00000040);
142  stat &= ~0x00000040;
143  }
144 
145  if (stat) {
146  nv_error(priv, "unhandled intr 0x%08x\n", stat);
147  nv_wr32(priv, 0x104004 + (idx * 0x1000), stat);
148  }
149 
150  nouveau_engctx_put(engctx);
151 }
152 
153 static int
154 nvc0_copy0_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
155  struct nouveau_oclass *oclass, void *data, u32 size,
156  struct nouveau_object **pobject)
157 {
158  struct nvc0_copy_priv *priv;
159  int ret;
160 
161  if (nv_rd32(parent, 0x022500) & 0x00000100)
162  return -ENODEV;
163 
164  ret = nouveau_copy_create(parent, engine, oclass, true, 0, &priv);
165  *pobject = nv_object(priv);
166  if (ret)
167  return ret;
168 
169  nv_subdev(priv)->unit = 0x00000040;
170  nv_subdev(priv)->intr = nvc0_copy_intr;
171  nv_engine(priv)->cclass = &nvc0_copy0_cclass;
172  nv_engine(priv)->sclass = nvc0_copy0_sclass;
173  return 0;
174 }
175 
176 static int
177 nvc0_copy1_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
178  struct nouveau_oclass *oclass, void *data, u32 size,
179  struct nouveau_object **pobject)
180 {
181  struct nvc0_copy_priv *priv;
182  int ret;
183 
184  if (nv_rd32(parent, 0x022500) & 0x00000200)
185  return -ENODEV;
186 
187  ret = nouveau_copy_create(parent, engine, oclass, true, 1, &priv);
188  *pobject = nv_object(priv);
189  if (ret)
190  return ret;
191 
192  nv_subdev(priv)->unit = 0x00000080;
193  nv_subdev(priv)->intr = nvc0_copy_intr;
194  nv_engine(priv)->cclass = &nvc0_copy1_cclass;
195  nv_engine(priv)->sclass = nvc0_copy1_sclass;
196  return 0;
197 }
198 
199 static int
200 nvc0_copy_init(struct nouveau_object *object)
201 {
202  int idx = nv_engidx(object) - NVDEV_ENGINE_COPY0;
203  struct nvc0_copy_priv *priv = (void *)object;
204  int ret, i;
205 
206  ret = nouveau_copy_init(&priv->base);
207  if (ret)
208  return ret;
209 
210  /* disable all interrupts */
211  nv_wr32(priv, 0x104014 + (idx * 0x1000), 0xffffffff);
212 
213  /* upload ucode */
214  nv_wr32(priv, 0x1041c0 + (idx * 0x1000), 0x01000000);
215  for (i = 0; i < sizeof(nvc0_pcopy_data) / 4; i++)
216  nv_wr32(priv, 0x1041c4 + (idx * 0x1000), nvc0_pcopy_data[i]);
217 
218  nv_wr32(priv, 0x104180 + (idx * 0x1000), 0x01000000);
219  for (i = 0; i < sizeof(nvc0_pcopy_code) / 4; i++) {
220  if ((i & 0x3f) == 0)
221  nv_wr32(priv, 0x104188 + (idx * 0x1000), i >> 6);
222  nv_wr32(priv, 0x104184 + (idx * 0x1000), nvc0_pcopy_code[i]);
223  }
224 
225  /* start it running */
226  nv_wr32(priv, 0x104084 + (idx * 0x1000), idx);
227  nv_wr32(priv, 0x10410c + (idx * 0x1000), 0x00000000);
228  nv_wr32(priv, 0x104104 + (idx * 0x1000), 0x00000000); /* ENTRY */
229  nv_wr32(priv, 0x104100 + (idx * 0x1000), 0x00000002); /* TRIGGER */
230  return 0;
231 }
232 
233 static int
234 nvc0_copy_fini(struct nouveau_object *object, bool suspend)
235 {
236  int idx = nv_engidx(object) - NVDEV_ENGINE_COPY0;
237  struct nvc0_copy_priv *priv = (void *)object;
238 
239  nv_mask(priv, 0x104048 + (idx * 0x1000), 0x00000003, 0x00000000);
240  nv_wr32(priv, 0x104014 + (idx * 0x1000), 0xffffffff);
241 
242  return nouveau_copy_fini(&priv->base, suspend);
243 }
244 
245 struct nouveau_oclass
247  .handle = NV_ENGINE(COPY0, 0xc0),
248  .ofuncs = &(struct nouveau_ofuncs) {
249  .ctor = nvc0_copy0_ctor,
250  .dtor = _nouveau_copy_dtor,
251  .init = nvc0_copy_init,
252  .fini = nvc0_copy_fini,
253  },
254 };
255 
256 struct nouveau_oclass
258  .handle = NV_ENGINE(COPY1, 0xc0),
259  .ofuncs = &(struct nouveau_ofuncs) {
260  .ctor = nvc0_copy1_ctor,
261  .dtor = _nouveau_copy_dtor,
262  .init = nvc0_copy_init,
263  .fini = nvc0_copy_fini,
264  },
265 };