2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include <core/enum.h>
27 #include <core/class.h>
28 #include <core/engctx.h>
30 #include <engine/copy.h>
32 #include "fuc/nvc0.fuc.h"
34 struct nvc0_copy_priv
{
35 struct nouveau_copy base
;
38 struct nvc0_copy_chan
{
39 struct nouveau_copy_chan base
;
42 /*******************************************************************************
44 ******************************************************************************/
46 static struct nouveau_oclass
47 nvc0_copy0_sclass
[] = {
48 { 0x90b5, &nouveau_object_ofuncs
},
52 static struct nouveau_oclass
53 nvc0_copy1_sclass
[] = {
54 { 0x90b8, &nouveau_object_ofuncs
},
58 /*******************************************************************************
60 ******************************************************************************/
63 nvc0_copy_context_ctor(struct nouveau_object
*parent
,
64 struct nouveau_object
*engine
,
65 struct nouveau_oclass
*oclass
, void *data
, u32 size
,
66 struct nouveau_object
**pobject
)
68 struct nvc0_copy_chan
*priv
;
71 ret
= nouveau_copy_context_create(parent
, engine
, oclass
, NULL
, 256,
72 256, NVOBJ_FLAG_ZERO_ALLOC
, &priv
);
73 *pobject
= nv_object(priv
);
80 static struct nouveau_ofuncs
81 nvc0_copy_context_ofuncs
= {
82 .ctor
= nvc0_copy_context_ctor
,
83 .dtor
= _nouveau_copy_context_dtor
,
84 .init
= _nouveau_copy_context_init
,
85 .fini
= _nouveau_copy_context_fini
,
86 .rd32
= _nouveau_copy_context_rd32
,
87 .wr32
= _nouveau_copy_context_wr32
,
90 static struct nouveau_oclass
92 .handle
= NV_ENGCTX(COPY0
, 0xc0),
93 .ofuncs
= &nvc0_copy_context_ofuncs
,
96 static struct nouveau_oclass
98 .handle
= NV_ENGCTX(COPY1
, 0xc0),
99 .ofuncs
= &nvc0_copy_context_ofuncs
,
102 /*******************************************************************************
103 * PCOPY engine/subdev functions
104 ******************************************************************************/
106 static struct nouveau_enum nvc0_copy_isr_error_name
[] = {
107 { 0x0001, "ILLEGAL_MTHD" },
108 { 0x0002, "INVALID_ENUM" },
109 { 0x0003, "INVALID_BITFIELD" },
114 nvc0_copy_intr(struct nouveau_subdev
*subdev
)
116 int idx
= nv_engidx(nv_object(subdev
)) - NVDEV_ENGINE_COPY0
;
117 struct nvc0_copy_priv
*priv
= (void *)subdev
;
118 u32 disp
= nv_rd32(priv
, 0x10401c + (idx
* 0x1000));
119 u32 intr
= nv_rd32(priv
, 0x104008 + (idx
* 0x1000));
120 u32 stat
= intr
& disp
& ~(disp
>> 16);
121 u64 inst
= nv_rd32(priv
, 0x104050 + (idx
* 0x1000)) & 0x0fffffff;
122 u32 ssta
= nv_rd32(priv
, 0x104040 + (idx
* 0x1000)) & 0x0000ffff;
123 u32 addr
= nv_rd32(priv
, 0x104040 + (idx
* 0x1000)) >> 16;
124 u32 mthd
= (addr
& 0x07ff) << 2;
125 u32 subc
= (addr
& 0x3800) >> 11;
126 u32 data
= nv_rd32(priv
, 0x104044 + (idx
* 0x1000));
128 if (stat
& 0x00000040) {
129 nv_error(priv
, "DISPATCH_ERROR [");
130 nouveau_enum_print(nvc0_copy_isr_error_name
, ssta
);
131 printk("] ch 0x%010llx subc %d mthd 0x%04x data 0x%08x\n",
132 (u64
)inst
<< 12, subc
, mthd
, data
);
133 nv_wr32(priv
, 0x104004 + (idx
* 0x1000), 0x00000040);
138 nv_error(priv
, "unhandled intr 0x%08x\n", stat
);
139 nv_wr32(priv
, 0x104004 + (idx
* 0x1000), stat
);
144 nvc0_copy0_ctor(struct nouveau_object
*parent
, struct nouveau_object
*engine
,
145 struct nouveau_oclass
*oclass
, void *data
, u32 size
,
146 struct nouveau_object
**pobject
)
148 struct nvc0_copy_priv
*priv
;
151 if (nv_rd32(parent
, 0x022500) & 0x00000100)
154 ret
= nouveau_copy_create(parent
, engine
, oclass
, true, 0, &priv
);
155 *pobject
= nv_object(priv
);
159 nv_subdev(priv
)->unit
= 0x00000040;
160 nv_subdev(priv
)->intr
= nvc0_copy_intr
;
161 nv_engine(priv
)->cclass
= &nvc0_copy0_cclass
;
162 nv_engine(priv
)->sclass
= nvc0_copy0_sclass
;
167 nvc0_copy1_ctor(struct nouveau_object
*parent
, struct nouveau_object
*engine
,
168 struct nouveau_oclass
*oclass
, void *data
, u32 size
,
169 struct nouveau_object
**pobject
)
171 struct nvc0_copy_priv
*priv
;
174 if (nv_rd32(parent
, 0x022500) & 0x00000200)
177 ret
= nouveau_copy_create(parent
, engine
, oclass
, true, 1, &priv
);
178 *pobject
= nv_object(priv
);
182 nv_subdev(priv
)->unit
= 0x00000080;
183 nv_subdev(priv
)->intr
= nvc0_copy_intr
;
184 nv_engine(priv
)->cclass
= &nvc0_copy1_cclass
;
185 nv_engine(priv
)->sclass
= nvc0_copy1_sclass
;
190 nvc0_copy_init(struct nouveau_object
*object
)
192 int idx
= nv_engidx(object
) - NVDEV_ENGINE_COPY0
;
193 struct nvc0_copy_priv
*priv
= (void *)object
;
196 ret
= nouveau_copy_init(&priv
->base
);
200 /* disable all interrupts */
201 nv_wr32(priv
, 0x104014 + (idx
* 0x1000), 0xffffffff);
204 nv_wr32(priv
, 0x1041c0 + (idx
* 0x1000), 0x01000000);
205 for (i
= 0; i
< sizeof(nvc0_pcopy_data
) / 4; i
++)
206 nv_wr32(priv
, 0x1041c4 + (idx
* 0x1000), nvc0_pcopy_data
[i
]);
208 nv_wr32(priv
, 0x104180 + (idx
* 0x1000), 0x01000000);
209 for (i
= 0; i
< sizeof(nvc0_pcopy_code
) / 4; i
++) {
211 nv_wr32(priv
, 0x104188 + (idx
* 0x1000), i
>> 6);
212 nv_wr32(priv
, 0x104184 + (idx
* 0x1000), nvc0_pcopy_code
[i
]);
215 /* start it running */
216 nv_wr32(priv
, 0x104084 + (idx
* 0x1000), idx
);
217 nv_wr32(priv
, 0x10410c + (idx
* 0x1000), 0x00000000);
218 nv_wr32(priv
, 0x104104 + (idx
* 0x1000), 0x00000000); /* ENTRY */
219 nv_wr32(priv
, 0x104100 + (idx
* 0x1000), 0x00000002); /* TRIGGER */
224 nvc0_copy_fini(struct nouveau_object
*object
, bool suspend
)
226 int idx
= nv_engidx(object
) - NVDEV_ENGINE_COPY0
;
227 struct nvc0_copy_priv
*priv
= (void *)object
;
229 nv_mask(priv
, 0x104048 + (idx
* 0x1000), 0x00000003, 0x00000000);
230 nv_wr32(priv
, 0x104014 + (idx
* 0x1000), 0xffffffff);
232 return nouveau_copy_fini(&priv
->base
, suspend
);
235 struct nouveau_oclass
236 nvc0_copy0_oclass
= {
237 .handle
= NV_ENGINE(COPY0
, 0xc0),
238 .ofuncs
= &(struct nouveau_ofuncs
) {
239 .ctor
= nvc0_copy0_ctor
,
240 .dtor
= _nouveau_copy_dtor
,
241 .init
= nvc0_copy_init
,
242 .fini
= nvc0_copy_fini
,
246 struct nouveau_oclass
247 nvc0_copy1_oclass
= {
248 .handle
= NV_ENGINE(COPY1
, 0xc0),
249 .ofuncs
= &(struct nouveau_ofuncs
) {
250 .ctor
= nvc0_copy1_ctor
,
251 .dtor
= _nouveau_copy_dtor
,
252 .init
= nvc0_copy_init
,
253 .fini
= nvc0_copy_fini
,