drm/nvc0-/gr: generate grctx template at init time, not first context ctor
[deliverable/linux.git] / drivers / gpu / drm / nouveau / core / engine / copy / nva3.c
CommitLineData
7ff5441e
BS
1/*
2 * Copyright 2011 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 <linux/firmware.h>
26#include "drmP.h"
27#include "nouveau_drv.h"
28#include "nouveau_util.h"
02a841d4
BS
29#include <core/ramht.h>
30#include "fuc/nva3.fuc.h"
7ff5441e
BS
31
32struct nva3_copy_engine {
33 struct nouveau_exec_engine base;
34};
35
36static int
37nva3_copy_context_new(struct nouveau_channel *chan, int engine)
38{
39 struct drm_device *dev = chan->dev;
7ff5441e
BS
40 struct nouveau_gpuobj *ramin = chan->ramin;
41 struct nouveau_gpuobj *ctx = NULL;
42 int ret;
43
44 NV_DEBUG(dev, "ch%d\n", chan->id);
45
46 ret = nouveau_gpuobj_new(dev, chan, 256, 0, NVOBJ_FLAG_ZERO_ALLOC |
47 NVOBJ_FLAG_ZERO_FREE, &ctx);
48 if (ret)
49 return ret;
50
51 nv_wo32(ramin, 0xc0, 0x00190000);
3863c9bc
BS
52 nv_wo32(ramin, 0xc4, ctx->addr + ctx->size - 1);
53 nv_wo32(ramin, 0xc8, ctx->addr);
7ff5441e
BS
54 nv_wo32(ramin, 0xcc, 0x00000000);
55 nv_wo32(ramin, 0xd0, 0x00000000);
56 nv_wo32(ramin, 0xd4, 0x00000000);
3863c9bc 57 nvimem_flush(dev);
7ff5441e 58
3863c9bc 59 nvvm_engref(chan->vm, engine, 1);
7ff5441e
BS
60 chan->engctx[engine] = ctx;
61 return 0;
62}
63
64static int
65nva3_copy_object_new(struct nouveau_channel *chan, int engine,
66 u32 handle, u16 class)
67{
68 struct nouveau_gpuobj *ctx = chan->engctx[engine];
69
70 /* fuc engine doesn't need an object, our ramht code does.. */
71 ctx->engine = 3;
72 ctx->class = class;
73 return nouveau_ramht_insert(chan, handle, ctx);
74}
75
76static void
77nva3_copy_context_del(struct nouveau_channel *chan, int engine)
78{
79 struct nouveau_gpuobj *ctx = chan->engctx[engine];
5511d490 80 int i;
7ff5441e 81
5511d490
BS
82 for (i = 0xc0; i <= 0xd4; i += 4)
83 nv_wo32(chan->ramin, i, 0x00000000);
7ff5441e 84
3863c9bc 85 nvvm_engref(chan->vm, engine, -1);
5511d490 86 nouveau_gpuobj_ref(NULL, &ctx);
7ff5441e
BS
87 chan->engctx[engine] = ctx;
88}
89
90static void
91nva3_copy_tlb_flush(struct drm_device *dev, int engine)
92{
93 nv50_vm_flush_engine(dev, 0x0d);
94}
95
96static int
97nva3_copy_init(struct drm_device *dev, int engine)
98{
99 int i;
100
101 nv_mask(dev, 0x000200, 0x00002000, 0x00000000);
102 nv_mask(dev, 0x000200, 0x00002000, 0x00002000);
103 nv_wr32(dev, 0x104014, 0xffffffff); /* disable all interrupts */
104
105 /* upload ucode */
106 nv_wr32(dev, 0x1041c0, 0x01000000);
107 for (i = 0; i < sizeof(nva3_pcopy_data) / 4; i++)
108 nv_wr32(dev, 0x1041c4, nva3_pcopy_data[i]);
109
110 nv_wr32(dev, 0x104180, 0x01000000);
111 for (i = 0; i < sizeof(nva3_pcopy_code) / 4; i++) {
112 if ((i & 0x3f) == 0)
113 nv_wr32(dev, 0x104188, i >> 6);
114 nv_wr32(dev, 0x104184, nva3_pcopy_code[i]);
115 }
116
117 /* start it running */
118 nv_wr32(dev, 0x10410c, 0x00000000);
119 nv_wr32(dev, 0x104104, 0x00000000); /* ENTRY */
120 nv_wr32(dev, 0x104100, 0x00000002); /* TRIGGER */
121 return 0;
122}
123
124static int
6c320fef 125nva3_copy_fini(struct drm_device *dev, int engine, bool suspend)
7ff5441e
BS
126{
127 nv_mask(dev, 0x104048, 0x00000003, 0x00000000);
7ff5441e
BS
128 nv_wr32(dev, 0x104014, 0xffffffff);
129 return 0;
130}
131
132static struct nouveau_enum nva3_copy_isr_error_name[] = {
133 { 0x0001, "ILLEGAL_MTHD" },
134 { 0x0002, "INVALID_ENUM" },
135 { 0x0003, "INVALID_BITFIELD" },
136 {}
137};
138
139static void
140nva3_copy_isr(struct drm_device *dev)
141{
142 u32 dispatch = nv_rd32(dev, 0x10401c);
143 u32 stat = nv_rd32(dev, 0x104008) & dispatch & ~(dispatch >> 16);
144 u32 inst = nv_rd32(dev, 0x104050) & 0x3fffffff;
145 u32 ssta = nv_rd32(dev, 0x104040) & 0x0000ffff;
146 u32 addr = nv_rd32(dev, 0x104040) >> 16;
147 u32 mthd = (addr & 0x07ff) << 2;
148 u32 subc = (addr & 0x3800) >> 11;
149 u32 data = nv_rd32(dev, 0x104044);
150 int chid = nv50_graph_isr_chid(dev, inst);
151
152 if (stat & 0x00000040) {
153 NV_INFO(dev, "PCOPY: DISPATCH_ERROR [");
154 nouveau_enum_print(nva3_copy_isr_error_name, ssta);
155 printk("] ch %d [0x%08x] subc %d mthd 0x%04x data 0x%08x\n",
156 chid, inst, subc, mthd, data);
157 nv_wr32(dev, 0x104004, 0x00000040);
158 stat &= ~0x00000040;
159 }
160
161 if (stat) {
162 NV_INFO(dev, "PCOPY: unhandled intr 0x%08x\n", stat);
163 nv_wr32(dev, 0x104004, stat);
164 }
165 nv50_fb_vm_trap(dev, 1);
166}
167
168static void
169nva3_copy_destroy(struct drm_device *dev, int engine)
170{
171 struct nva3_copy_engine *pcopy = nv_engine(dev, engine);
172
173 nouveau_irq_unregister(dev, 22);
174
175 NVOBJ_ENGINE_DEL(dev, COPY0);
176 kfree(pcopy);
177}
178
179int
180nva3_copy_create(struct drm_device *dev)
181{
182 struct nva3_copy_engine *pcopy;
183
184 pcopy = kzalloc(sizeof(*pcopy), GFP_KERNEL);
185 if (!pcopy)
186 return -ENOMEM;
187
188 pcopy->base.destroy = nva3_copy_destroy;
189 pcopy->base.init = nva3_copy_init;
190 pcopy->base.fini = nva3_copy_fini;
191 pcopy->base.context_new = nva3_copy_context_new;
192 pcopy->base.context_del = nva3_copy_context_del;
193 pcopy->base.object_new = nva3_copy_object_new;
194 pcopy->base.tlb_flush = nva3_copy_tlb_flush;
195
196 nouveau_irq_register(dev, 22, nva3_copy_isr);
197
198 NVOBJ_ENGINE_ADD(dev, COPY0, &pcopy->base);
199 NVOBJ_CLASS(dev, 0x85b5, COPY0);
200 return 0;
201}
This page took 0.123663 seconds and 5 git commands to generate.