Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nva3.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/fb.h>
31 #include <subdev/vm.h>
32 
33 #include <engine/fifo.h>
34 #include <engine/copy.h>
35 
36 #include "fuc/nva3.fuc.h"
37 
40 };
41 
44 };
45 
46 /*******************************************************************************
47  * Copy object classes
48  ******************************************************************************/
49 
50 static struct nouveau_oclass
51 nva3_copy_sclass[] = {
52  { 0x85b5, &nouveau_object_ofuncs },
53  {}
54 };
55 
56 /*******************************************************************************
57  * PCOPY context
58  ******************************************************************************/
59 
60 static int
61 nva3_copy_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 nva3_copy_chan *priv;
67  int ret;
68 
69  ret = nouveau_copy_context_create(parent, engine, oclass, NULL, 256, 0,
70  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 nva3_copy_cclass = {
80  .handle = NV_ENGCTX(COPY0, 0xa3),
81  .ofuncs = &(struct nouveau_ofuncs) {
82  .ctor = nva3_copy_context_ctor,
88 
89  },
90 };
91 
92 /*******************************************************************************
93  * PCOPY engine/subdev functions
94  ******************************************************************************/
95 
96 static const struct nouveau_enum nva3_copy_isr_error_name[] = {
97  { 0x0001, "ILLEGAL_MTHD" },
98  { 0x0002, "INVALID_ENUM" },
99  { 0x0003, "INVALID_BITFIELD" },
100  {}
101 };
102 
103 static void
104 nva3_copy_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 nva3_copy_priv *priv = (void *)subdev;
110  u32 dispatch = nv_rd32(priv, 0x10401c);
111  u32 stat = nv_rd32(priv, 0x104008) & dispatch & ~(dispatch >> 16);
112  u64 inst = nv_rd32(priv, 0x104050) & 0x3fffffff;
113  u32 ssta = nv_rd32(priv, 0x104040) & 0x0000ffff;
114  u32 addr = nv_rd32(priv, 0x104040) >> 16;
115  u32 mthd = (addr & 0x07ff) << 2;
116  u32 subc = (addr & 0x3800) >> 11;
117  u32 data = nv_rd32(priv, 0x104044);
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(nva3_copy_isr_error_name, ssta);
126  printk("] ch %d [0x%010llx] subc %d mthd 0x%04x data 0x%08x\n",
127  chid, inst << 12, subc, mthd, data);
128  nv_wr32(priv, 0x104004, 0x00000040);
129  stat &= ~0x00000040;
130  }
131 
132  if (stat) {
133  nv_error(priv, "unhandled intr 0x%08x\n", stat);
134  nv_wr32(priv, 0x104004, stat);
135  }
136 
137  nv50_fb_trap(nouveau_fb(priv), 1);
138  nouveau_engctx_put(engctx);
139 }
140 
141 static int
142 nva3_copy_tlb_flush(struct nouveau_engine *engine)
143 {
144  nv50_vm_flush_engine(&engine->base, 0x0d);
145  return 0;
146 }
147 
148 static int
149 nva3_copy_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  bool enable = (nv_device(parent)->chipset != 0xaf);
154  struct nva3_copy_priv *priv;
155  int ret;
156 
157  ret = nouveau_copy_create(parent, engine, oclass, enable, 0, &priv);
158  *pobject = nv_object(priv);
159  if (ret)
160  return ret;
161 
162  nv_subdev(priv)->unit = 0x00802000;
163  nv_subdev(priv)->intr = nva3_copy_intr;
164  nv_engine(priv)->cclass = &nva3_copy_cclass;
165  nv_engine(priv)->sclass = nva3_copy_sclass;
166  nv_engine(priv)->tlb_flush = nva3_copy_tlb_flush;
167  return 0;
168 }
169 
170 static int
171 nva3_copy_init(struct nouveau_object *object)
172 {
173  struct nva3_copy_priv *priv = (void *)object;
174  int ret, i;
175 
176  ret = nouveau_copy_init(&priv->base);
177  if (ret)
178  return ret;
179 
180  /* disable all interrupts */
181  nv_wr32(priv, 0x104014, 0xffffffff);
182 
183  /* upload ucode */
184  nv_wr32(priv, 0x1041c0, 0x01000000);
185  for (i = 0; i < sizeof(nva3_pcopy_data) / 4; i++)
186  nv_wr32(priv, 0x1041c4, nva3_pcopy_data[i]);
187 
188  nv_wr32(priv, 0x104180, 0x01000000);
189  for (i = 0; i < sizeof(nva3_pcopy_code) / 4; i++) {
190  if ((i & 0x3f) == 0)
191  nv_wr32(priv, 0x104188, i >> 6);
192  nv_wr32(priv, 0x104184, nva3_pcopy_code[i]);
193  }
194 
195  /* start it running */
196  nv_wr32(priv, 0x10410c, 0x00000000);
197  nv_wr32(priv, 0x104104, 0x00000000); /* ENTRY */
198  nv_wr32(priv, 0x104100, 0x00000002); /* TRIGGER */
199  return 0;
200 }
201 
202 static int
203 nva3_copy_fini(struct nouveau_object *object, bool suspend)
204 {
205  struct nva3_copy_priv *priv = (void *)object;
206 
207  nv_mask(priv, 0x104048, 0x00000003, 0x00000000);
208  nv_wr32(priv, 0x104014, 0xffffffff);
209 
210  return nouveau_copy_fini(&priv->base, suspend);
211 }
212 
213 struct nouveau_oclass
215  .handle = NV_ENGINE(COPY0, 0xa3),
216  .ofuncs = &(struct nouveau_ofuncs) {
217  .ctor = nva3_copy_ctor,
218  .dtor = _nouveau_copy_dtor,
219  .init = nva3_copy_init,
220  .fini = nva3_copy_fini,
221  },
222 };