2 * Copyright 2011 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.
25 #include <linux/firmware.h>
27 #include "nouveau_drv.h"
28 #include "nouveau_util.h"
29 #include "nouveau_vm.h"
30 #include "nouveau_ramht.h"
31 #include "nva3_copy.fuc.h"
33 struct nva3_copy_engine
{
34 struct nouveau_exec_engine base
;
38 nva3_copy_context_new(struct nouveau_channel
*chan
, int engine
)
40 struct drm_device
*dev
= chan
->dev
;
41 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
42 struct nouveau_gpuobj
*ramin
= chan
->ramin
;
43 struct nouveau_gpuobj
*ctx
= NULL
;
46 NV_DEBUG(dev
, "ch%d\n", chan
->id
);
48 ret
= nouveau_gpuobj_new(dev
, chan
, 256, 0, NVOBJ_FLAG_ZERO_ALLOC
|
49 NVOBJ_FLAG_ZERO_FREE
, &ctx
);
53 nv_wo32(ramin
, 0xc0, 0x00190000);
54 nv_wo32(ramin
, 0xc4, ctx
->vinst
+ ctx
->size
- 1);
55 nv_wo32(ramin
, 0xc8, ctx
->vinst
);
56 nv_wo32(ramin
, 0xcc, 0x00000000);
57 nv_wo32(ramin
, 0xd0, 0x00000000);
58 nv_wo32(ramin
, 0xd4, 0x00000000);
59 dev_priv
->engine
.instmem
.flush(dev
);
61 atomic_inc(&chan
->vm
->engref
[engine
]);
62 chan
->engctx
[engine
] = ctx
;
67 nva3_copy_object_new(struct nouveau_channel
*chan
, int engine
,
68 u32 handle
, u16
class)
70 struct nouveau_gpuobj
*ctx
= chan
->engctx
[engine
];
72 /* fuc engine doesn't need an object, our ramht code does.. */
75 return nouveau_ramht_insert(chan
, handle
, ctx
);
79 nva3_copy_context_del(struct nouveau_channel
*chan
, int engine
)
81 struct nouveau_gpuobj
*ctx
= chan
->engctx
[engine
];
84 for (i
= 0xc0; i
<= 0xd4; i
+= 4)
85 nv_wo32(chan
->ramin
, i
, 0x00000000);
87 atomic_dec(&chan
->vm
->engref
[engine
]);
88 nouveau_gpuobj_ref(NULL
, &ctx
);
89 chan
->engctx
[engine
] = ctx
;
93 nva3_copy_tlb_flush(struct drm_device
*dev
, int engine
)
95 nv50_vm_flush_engine(dev
, 0x0d);
99 nva3_copy_init(struct drm_device
*dev
, int engine
)
103 nv_mask(dev
, 0x000200, 0x00002000, 0x00000000);
104 nv_mask(dev
, 0x000200, 0x00002000, 0x00002000);
105 nv_wr32(dev
, 0x104014, 0xffffffff); /* disable all interrupts */
108 nv_wr32(dev
, 0x1041c0, 0x01000000);
109 for (i
= 0; i
< sizeof(nva3_pcopy_data
) / 4; i
++)
110 nv_wr32(dev
, 0x1041c4, nva3_pcopy_data
[i
]);
112 nv_wr32(dev
, 0x104180, 0x01000000);
113 for (i
= 0; i
< sizeof(nva3_pcopy_code
) / 4; i
++) {
115 nv_wr32(dev
, 0x104188, i
>> 6);
116 nv_wr32(dev
, 0x104184, nva3_pcopy_code
[i
]);
119 /* start it running */
120 nv_wr32(dev
, 0x10410c, 0x00000000);
121 nv_wr32(dev
, 0x104104, 0x00000000); /* ENTRY */
122 nv_wr32(dev
, 0x104100, 0x00000002); /* TRIGGER */
127 nva3_copy_fini(struct drm_device
*dev
, int engine
, bool suspend
)
129 nv_mask(dev
, 0x104048, 0x00000003, 0x00000000);
130 nv_wr32(dev
, 0x104014, 0xffffffff);
134 static struct nouveau_enum nva3_copy_isr_error_name
[] = {
135 { 0x0001, "ILLEGAL_MTHD" },
136 { 0x0002, "INVALID_ENUM" },
137 { 0x0003, "INVALID_BITFIELD" },
142 nva3_copy_isr(struct drm_device
*dev
)
144 u32 dispatch
= nv_rd32(dev
, 0x10401c);
145 u32 stat
= nv_rd32(dev
, 0x104008) & dispatch
& ~(dispatch
>> 16);
146 u32 inst
= nv_rd32(dev
, 0x104050) & 0x3fffffff;
147 u32 ssta
= nv_rd32(dev
, 0x104040) & 0x0000ffff;
148 u32 addr
= nv_rd32(dev
, 0x104040) >> 16;
149 u32 mthd
= (addr
& 0x07ff) << 2;
150 u32 subc
= (addr
& 0x3800) >> 11;
151 u32 data
= nv_rd32(dev
, 0x104044);
152 int chid
= nv50_graph_isr_chid(dev
, inst
);
154 if (stat
& 0x00000040) {
155 NV_INFO(dev
, "PCOPY: DISPATCH_ERROR [");
156 nouveau_enum_print(nva3_copy_isr_error_name
, ssta
);
157 printk("] ch %d [0x%08x] subc %d mthd 0x%04x data 0x%08x\n",
158 chid
, inst
, subc
, mthd
, data
);
159 nv_wr32(dev
, 0x104004, 0x00000040);
164 NV_INFO(dev
, "PCOPY: unhandled intr 0x%08x\n", stat
);
165 nv_wr32(dev
, 0x104004, stat
);
167 nv50_fb_vm_trap(dev
, 1);
171 nva3_copy_destroy(struct drm_device
*dev
, int engine
)
173 struct nva3_copy_engine
*pcopy
= nv_engine(dev
, engine
);
175 nouveau_irq_unregister(dev
, 22);
177 NVOBJ_ENGINE_DEL(dev
, COPY0
);
182 nva3_copy_create(struct drm_device
*dev
)
184 struct nva3_copy_engine
*pcopy
;
186 pcopy
= kzalloc(sizeof(*pcopy
), GFP_KERNEL
);
190 pcopy
->base
.destroy
= nva3_copy_destroy
;
191 pcopy
->base
.init
= nva3_copy_init
;
192 pcopy
->base
.fini
= nva3_copy_fini
;
193 pcopy
->base
.context_new
= nva3_copy_context_new
;
194 pcopy
->base
.context_del
= nva3_copy_context_del
;
195 pcopy
->base
.object_new
= nva3_copy_object_new
;
196 pcopy
->base
.tlb_flush
= nva3_copy_tlb_flush
;
198 nouveau_irq_register(dev
, 22, nva3_copy_isr
);
200 NVOBJ_ENGINE_ADD(dev
, COPY0
, &pcopy
->base
);
201 NVOBJ_CLASS(dev
, 0x85b5, COPY0
);