Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 254 lines (213 sloc) 7.338 kB
775f20e Add missing fuc and pcopy sources
Shinpei Kato authored
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 "nouveau_drv.h"
26 #include "pscnv_engine.h"
27 #include "pscnv_chan.h"
28 #include "nvc0_copy.h"
29 #include "nvc0_copy.fuc.h"
30 #include "nvc0_vm.h"
31
32 struct nvc0_copy_chan {
33 struct pscnv_bo *bo;
34 struct pscnv_mm_node *vm;
35 };
36
37 static int
38 nvc0_copy_chan_alloc(struct pscnv_engine *eng, struct pscnv_chan *ch)
39 {
40 struct drm_device *dev = eng->dev;
41 struct drm_nouveau_private *dev_priv = dev->dev_private;
42 struct nvc0_copy_engine *pcopy = NVC0_COPY(eng);
43 struct nvc0_copy_chan *coch = kzalloc(sizeof(*coch), GFP_KERNEL);
44 uint32_t cookie = pcopy->fuc;
45 int ret;
46
47 coch->bo = pscnv_mem_alloc(dev, 256, PSCNV_GEM_CONTIG, 0, cookie);
48 if (!coch->bo) {
49 ret = -ENOMEM;
50 goto fail_mem_alloc;
51 }
52
53 ret = dev_priv->vm->map_kernel(coch->bo);
54 if (ret) {
55 goto fail_map_kernel;
56 }
57
58 ret = pscnv_vspace_map(ch->vspace, coch->bo, 0x1000, (1ULL << 40) - 1, 0,
59 &coch->vm);
60 if (ret) {
61 goto fail_vspace_map;
62 }
63
64 nv_wv32(ch->bo, pcopy->ctx + 0, coch->vm->start);
65 nv_wv32(ch->bo, pcopy->ctx + 4, coch->vm->start >> 32);
66 dev_priv->vm->bar_flush(dev);
67
68 ch->engdata[PSCNV_ENGINE_COPY + pcopy->id] = coch;
69
70 return 0;
71
72 fail_vspace_map:
73 fail_map_kernel:
74 pscnv_mem_free(coch->bo);
75 fail_mem_alloc:
76 kfree(coch);
77
78 return ret;
79 }
80
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
81 static void
775f20e Add missing fuc and pcopy sources
Shinpei Kato authored
82 nvc0_copy_chan_kill(struct pscnv_engine *eng, struct pscnv_chan *ch)
83 {
84 /* FIXME */
85 }
86
87 static void
88 nvc0_copy_chan_free(struct pscnv_engine *eng, struct pscnv_chan *ch)
89 {
90 struct drm_device *dev = eng->dev;
91 struct nvc0_copy_engine *pcopy = NVC0_COPY(eng);
92 struct nvc0_copy_chan *coch = ch->engdata[PSCNV_ENGINE_COPY + pcopy->id];
93 uint32_t inst;
94
95 inst = (ch->bo->start >> 12);
96 inst |= 0x40000000;
97
98 /* disable fifo access */
99 nv_wr32(dev, pcopy->fuc + 0x048, 0x00000000);
100 /* mark channel as unloaded if it's currently active */
101 if (nv_rd32(dev, pcopy->fuc + 0x050) == inst)
102 nv_mask(dev, pcopy->fuc + 0x050, 0x40000000, 0x00000000);
103 /* mark next channel as invalid if it's about to be loaded */
104 if (nv_rd32(dev, pcopy->fuc + 0x054) == inst)
105 nv_mask(dev, pcopy->fuc + 0x054, 0x40000000, 0x00000000);
106 /* restore fifo access */
107 nv_wr32(dev, pcopy->fuc + 0x048, 0x00000003);
108
109 nv_wv32(ch->bo, pcopy->ctx + 0, 0x00000000);
110 nv_wv32(ch->bo, pcopy->ctx + 4, 0x00000000);
111
112 pscnv_vspace_unmap_node(coch->vm);
113 pscnv_mem_free(coch->bo);
114 kfree(coch);
115
116 ch->engdata[PSCNV_ENGINE_COPY + pcopy->id] = NULL;
117 }
118
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
119 static void
775f20e Add missing fuc and pcopy sources
Shinpei Kato authored
120 nvc0_copy_takedown(struct pscnv_engine *eng)
121 {
122 struct drm_device *dev = eng->dev;
123 struct nvc0_copy_engine *pcopy = NVC0_COPY(eng);
124
125 nv_mask(dev, pcopy->fuc + 0x048, 0x00000003, 0x00000000);
126
127 /* trigger fuc context unload */
128 nv_wait(dev, pcopy->fuc + 0x008, 0x0000000c, 0x00000000);
129 nv_mask(dev, pcopy->fuc + 0x054, 0x40000000, 0x00000000);
130 nv_wr32(dev, pcopy->fuc + 0x000, 0x00000008);
131 nv_wait(dev, pcopy->fuc + 0x008, 0x00000008, 0x00000000);
132
133 nv_wr32(dev, pcopy->fuc + 0x014, 0xffffffff);
134
135 nouveau_irq_unregister(dev, pcopy->irq);
136 kfree(pcopy);
137 }
138
139 struct pscnv_copy_enum {
140 int value;
141 const char *name;
142 };
143
144 struct pscnv_copy_enum nvc0_copy_isr_error_name[] = {
145 { 0x0001, "ILLEGAL_MTHD" },
146 { 0x0002, "INVALID_ENUM" },
147 { 0x0003, "INVALID_BITFIELD" },
148 {}
149 };
150
151 static void
152 nvc0_copy_isr(struct drm_device *dev, int engine)
153 {
154 uint64_t inst;
155 uint32_t disp, stat, chid, ssta, addr, mthd, subc, data;
156 struct drm_nouveau_private *dev_priv = dev->dev_private;
157 struct nvc0_copy_engine *pcopy = NVC0_COPY(dev_priv->engines[engine]);
158 #define PCOPY_ERROR(name) \
159 NV_ERROR(dev, "%s: st %08x ch %d sub %d mthd %04x data %08x %08x/%08llx\n",\
160 name, stat, chid, subc, mthd, data, ssta, inst);
161
162 disp = nv_rd32(dev, pcopy->fuc + 0x01c);
163 stat = nv_rd32(dev, pcopy->fuc + 0x008) & disp & ~(disp >> 16);
164 inst = (u64)(nv_rd32(dev, pcopy->fuc + 0x050) & 0x0fffffff) << 12;
165 chid = -1;
166 ssta = nv_rd32(dev, pcopy->fuc + 0x040) & 0x0000ffff;
167 addr = nv_rd32(dev, pcopy->fuc + 0x040) >> 16;
168 mthd = (addr & 0x07ff) << 2;
169 subc = (addr & 0x3800) >> 11;
170 data = nv_rd32(dev, pcopy->fuc + 0x044);
171
172 if (stat & 0x00000040) {
173 PCOPY_ERROR("PCOPY_DISPATCH");
174 nv_wr32(dev, pcopy->fuc + 0x004, 0x00000040);
175 stat &= ~0x00000040;
176 }
177
178 if (stat) {
179 NV_INFO(dev, "PCOPY: unhandled intr 0x%08x\n", stat);
180 nv_wr32(dev, pcopy->fuc + 0x004, stat);
181 }
182 }
183
184 static void
185 nvc0_copy_isr_0(struct drm_device *dev, int irq)
186 {
187 nvc0_copy_isr(dev, PSCNV_ENGINE_COPY0);
188 }
189
190 static void
191 nvc0_copy_isr_1(struct drm_device *dev, int irq)
192 {
193 nvc0_copy_isr(dev, PSCNV_ENGINE_COPY1);
194 }
195
196 int
197 nvc0_copy_init(struct drm_device *dev, int engine)
198 {
199 int i;
200 struct drm_nouveau_private *dev_priv = dev->dev_private;
201 struct nvc0_copy_engine *pcopy = kzalloc(sizeof(*pcopy), GFP_KERNEL);
202
203 if (!pcopy) {
204 NV_ERROR(dev, "PCOPY%d: Couldn't allocate engine!\n", engine);
205 return -ENOMEM;
206 }
207 NV_INFO(dev, "PCOPY%d: Initializing...\n", engine);
208
209 dev_priv->engines[PSCNV_ENGINE_COPY + engine] = &pcopy->base;
210 pcopy->base.dev = dev;
211 pcopy->base.takedown = nvc0_copy_takedown;
212 pcopy->base.chan_alloc = nvc0_copy_chan_alloc;
213 pcopy->base.chan_kill = nvc0_copy_chan_kill;
214 pcopy->base.chan_free = nvc0_copy_chan_free;
215 spin_lock_init(&pcopy->lock);
216
217 if (engine == 0) {
218 pcopy->irq = 5;
219 pcopy->pmc = 0x00000040;
220 pcopy->fuc = 0x104000;
221 pcopy->ctx = 0x0230;
222 nouveau_irq_register(dev, pcopy->irq, nvc0_copy_isr_0);
223 } else {
224 pcopy->irq = 6;
225 pcopy->pmc = 0x00000080;
226 pcopy->fuc = 0x105000;
227 pcopy->ctx = 0x0240;
228 nouveau_irq_register(dev, pcopy->irq, nvc0_copy_isr_1);
229 }
230 pcopy->id = engine;
231
232 nv_mask(dev, 0x000200, pcopy->pmc, 0x00000000);
233 nv_mask(dev, 0x000200, pcopy->pmc, pcopy->pmc);
234 nv_wr32(dev, pcopy->fuc + 0x014, 0xffffffff);
235
236 nv_wr32(dev, pcopy->fuc + 0x1c0, 0x01000000);
237 for (i = 0; i < sizeof(nvc0_pcopy_data) / 4; i++)
238 nv_wr32(dev, pcopy->fuc + 0x1c4, nvc0_pcopy_data[i]);
239
240 nv_wr32(dev, pcopy->fuc + 0x180, 0x01000000);
241 for (i = 0; i < sizeof(nvc0_pcopy_code) / 4; i++) {
242 if ((i & 0x3f) == 0)
243 nv_wr32(dev, pcopy->fuc + 0x188, i >> 6);
244 nv_wr32(dev, pcopy->fuc + 0x184, nvc0_pcopy_code[i]);
245 }
246
9208081 @mlankhorst nvc0: Fix copy fuc engine
mlankhorst authored
247 nv_wr32(dev, pcopy->fuc + 0x084, engine);
775f20e Add missing fuc and pcopy sources
Shinpei Kato authored
248 nv_wr32(dev, pcopy->fuc + 0x10c, 0x00000000);
249 nv_wr32(dev, pcopy->fuc + 0x104, 0x00000000); /* ENTRY */
250 nv_wr32(dev, pcopy->fuc + 0x100, 0x00000002); /* TRIGGER */
251
252 return 0;
253 }
Something went wrong with that request. Please try again.