blob: 563f60d1ce6ee4afb0ccb06d5b516d1e7671f215 [file] [log] [blame]
Ben Skeggs8f27c542011-08-11 14:58:06 +10001/*
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 "drmP.h"
Ben Skeggsb3550962012-05-02 21:00:20 +100026
Ben Skeggs8f27c542011-08-11 14:58:06 +100027#include "nouveau_drv.h"
28#include "nouveau_util.h"
Ben Skeggs02a841d2012-07-04 23:44:54 +100029#include <subdev/vm.h>
30#include <core/ramht.h>
Ben Skeggs8f27c542011-08-11 14:58:06 +100031
Ben Skeggs02a841d2012-07-04 23:44:54 +100032#include "fuc/nv98.fuc.h"
Ben Skeggsb3550962012-05-02 21:00:20 +100033
34struct nv98_crypt_priv {
Ben Skeggs8f27c542011-08-11 14:58:06 +100035 struct nouveau_exec_engine base;
36};
37
Ben Skeggsb3550962012-05-02 21:00:20 +100038struct nv98_crypt_chan {
39 struct nouveau_gpuobj *mem;
40};
41
42static int
43nv98_crypt_context_new(struct nouveau_channel *chan, int engine)
44{
45 struct drm_device *dev = chan->dev;
46 struct drm_nouveau_private *dev_priv = dev->dev_private;
47 struct nv98_crypt_priv *priv = nv_engine(dev, engine);
48 struct nv98_crypt_chan *cctx;
49 int ret;
50
51 cctx = chan->engctx[engine] = kzalloc(sizeof(*cctx), GFP_KERNEL);
52 if (!cctx)
53 return -ENOMEM;
54
55 atomic_inc(&chan->vm->engref[engine]);
56
57 ret = nouveau_gpuobj_new(dev, chan, 256, 0, NVOBJ_FLAG_ZERO_ALLOC |
58 NVOBJ_FLAG_ZERO_FREE, &cctx->mem);
59 if (ret)
60 goto error;
61
62 nv_wo32(chan->ramin, 0xa0, 0x00190000);
63 nv_wo32(chan->ramin, 0xa4, cctx->mem->vinst + cctx->mem->size - 1);
64 nv_wo32(chan->ramin, 0xa8, cctx->mem->vinst);
65 nv_wo32(chan->ramin, 0xac, 0x00000000);
66 nv_wo32(chan->ramin, 0xb0, 0x00000000);
67 nv_wo32(chan->ramin, 0xb4, 0x00000000);
68 dev_priv->engine.instmem.flush(dev);
69
70error:
71 if (ret)
72 priv->base.context_del(chan, engine);
73 return ret;
74}
75
76static void
77nv98_crypt_context_del(struct nouveau_channel *chan, int engine)
78{
79 struct nv98_crypt_chan *cctx = chan->engctx[engine];
80 int i;
81
82 for (i = 0xa0; i < 0xb4; i += 4)
83 nv_wo32(chan->ramin, i, 0x00000000);
84
85 nouveau_gpuobj_ref(NULL, &cctx->mem);
86
87 atomic_dec(&chan->vm->engref[engine]);
88 chan->engctx[engine] = NULL;
89 kfree(cctx);
90}
91
92static int
93nv98_crypt_object_new(struct nouveau_channel *chan, int engine,
94 u32 handle, u16 class)
95{
96 struct nv98_crypt_chan *cctx = chan->engctx[engine];
97
98 /* fuc engine doesn't need an object, our ramht code does.. */
99 cctx->mem->engine = 5;
100 cctx->mem->class = class;
101 return nouveau_ramht_insert(chan, handle, cctx->mem);
102}
103
104static void
105nv98_crypt_tlb_flush(struct drm_device *dev, int engine)
106{
107 nv50_vm_flush_engine(dev, 0x0a);
108}
109
Ben Skeggs8f27c542011-08-11 14:58:06 +1000110static int
111nv98_crypt_fini(struct drm_device *dev, int engine, bool suspend)
112{
Ben Skeggs8f27c542011-08-11 14:58:06 +1000113 nv_mask(dev, 0x000200, 0x00004000, 0x00000000);
114 return 0;
115}
116
117static int
118nv98_crypt_init(struct drm_device *dev, int engine)
119{
Ben Skeggsb3550962012-05-02 21:00:20 +1000120 int i;
121
122 /* reset! */
Ben Skeggs8f27c542011-08-11 14:58:06 +1000123 nv_mask(dev, 0x000200, 0x00004000, 0x00000000);
124 nv_mask(dev, 0x000200, 0x00004000, 0x00004000);
Ben Skeggsb3550962012-05-02 21:00:20 +1000125
126 /* wait for exit interrupt to signal */
127 nv_wait(dev, 0x087008, 0x00000010, 0x00000010);
128 nv_wr32(dev, 0x087004, 0x00000010);
129
130 /* upload microcode code and data segments */
131 nv_wr32(dev, 0x087ff8, 0x00100000);
132 for (i = 0; i < ARRAY_SIZE(nv98_pcrypt_code); i++)
133 nv_wr32(dev, 0x087ff4, nv98_pcrypt_code[i]);
134
135 nv_wr32(dev, 0x087ff8, 0x00000000);
136 for (i = 0; i < ARRAY_SIZE(nv98_pcrypt_data); i++)
137 nv_wr32(dev, 0x087ff4, nv98_pcrypt_data[i]);
138
139 /* start it running */
140 nv_wr32(dev, 0x08710c, 0x00000000);
141 nv_wr32(dev, 0x087104, 0x00000000); /* ENTRY */
142 nv_wr32(dev, 0x087100, 0x00000002); /* TRIGGER */
Ben Skeggs8f27c542011-08-11 14:58:06 +1000143 return 0;
144}
145
Ben Skeggsb3550962012-05-02 21:00:20 +1000146static struct nouveau_enum nv98_crypt_isr_error_name[] = {
147 { 0x0000, "ILLEGAL_MTHD" },
148 { 0x0001, "INVALID_BITFIELD" },
149 { 0x0002, "INVALID_ENUM" },
150 { 0x0003, "QUERY" },
151 {}
152};
153
154static void
155nv98_crypt_isr(struct drm_device *dev)
156{
157 u32 disp = nv_rd32(dev, 0x08701c);
158 u32 stat = nv_rd32(dev, 0x087008) & disp & ~(disp >> 16);
159 u32 inst = nv_rd32(dev, 0x087050) & 0x3fffffff;
160 u32 ssta = nv_rd32(dev, 0x087040) & 0x0000ffff;
161 u32 addr = nv_rd32(dev, 0x087040) >> 16;
162 u32 mthd = (addr & 0x07ff) << 2;
163 u32 subc = (addr & 0x3800) >> 11;
164 u32 data = nv_rd32(dev, 0x087044);
165 int chid = nv50_graph_isr_chid(dev, inst);
166
167 if (stat & 0x00000040) {
168 NV_INFO(dev, "PCRYPT: DISPATCH_ERROR [");
169 nouveau_enum_print(nv98_crypt_isr_error_name, ssta);
170 printk("] ch %d [0x%08x] subc %d mthd 0x%04x data 0x%08x\n",
171 chid, inst, subc, mthd, data);
172 nv_wr32(dev, 0x087004, 0x00000040);
173 stat &= ~0x00000040;
174 }
175
176 if (stat) {
177 NV_INFO(dev, "PCRYPT: unhandled intr 0x%08x\n", stat);
178 nv_wr32(dev, 0x087004, stat);
179 }
180
181 nv50_fb_vm_trap(dev, 1);
182}
183
Ben Skeggs8f27c542011-08-11 14:58:06 +1000184static void
185nv98_crypt_destroy(struct drm_device *dev, int engine)
186{
Ben Skeggsb3550962012-05-02 21:00:20 +1000187 struct nv98_crypt_priv *priv = nv_engine(dev, engine);
Ben Skeggs8f27c542011-08-11 14:58:06 +1000188
Ben Skeggsb3550962012-05-02 21:00:20 +1000189 nouveau_irq_unregister(dev, 14);
Ben Skeggs8f27c542011-08-11 14:58:06 +1000190 NVOBJ_ENGINE_DEL(dev, CRYPT);
Ben Skeggsb3550962012-05-02 21:00:20 +1000191 kfree(priv);
Ben Skeggs8f27c542011-08-11 14:58:06 +1000192}
193
194int
195nv98_crypt_create(struct drm_device *dev)
196{
Ben Skeggsb3550962012-05-02 21:00:20 +1000197 struct nv98_crypt_priv *priv;
Ben Skeggs8f27c542011-08-11 14:58:06 +1000198
Ben Skeggsb3550962012-05-02 21:00:20 +1000199 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
200 if (!priv)
Ben Skeggs8f27c542011-08-11 14:58:06 +1000201 return -ENOMEM;
202
Ben Skeggsb3550962012-05-02 21:00:20 +1000203 priv->base.destroy = nv98_crypt_destroy;
204 priv->base.init = nv98_crypt_init;
205 priv->base.fini = nv98_crypt_fini;
206 priv->base.context_new = nv98_crypt_context_new;
207 priv->base.context_del = nv98_crypt_context_del;
208 priv->base.object_new = nv98_crypt_object_new;
209 priv->base.tlb_flush = nv98_crypt_tlb_flush;
Ben Skeggs8f27c542011-08-11 14:58:06 +1000210
Ben Skeggsb3550962012-05-02 21:00:20 +1000211 nouveau_irq_register(dev, 14, nv98_crypt_isr);
212
213 NVOBJ_ENGINE_ADD(dev, CRYPT, &priv->base);
214 NVOBJ_CLASS(dev, 0x88b4, CRYPT);
Ben Skeggs8f27c542011-08-11 14:58:06 +1000215 return 0;
216}