blob: 780bb1d66f95f61189ff44892ec5701fab7064ae [file] [log] [blame]
Ben Skeggsbd2e5972010-10-19 20:06:01 +10001/*
2 * Copyright 2010 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"
26#include "nouveau_drv.h"
Ben Skeggsd7facf92010-11-03 10:06:43 +100027#include "nouveau_util.h"
28
29static void nv84_crypt_isr(struct drm_device *);
Ben Skeggsbd2e5972010-10-19 20:06:01 +100030
31int
32nv84_crypt_create_context(struct nouveau_channel *chan)
33{
34 struct drm_device *dev = chan->dev;
35 struct drm_nouveau_private *dev_priv = dev->dev_private;
36 struct nouveau_gpuobj *ramin = chan->ramin;
37 int ret;
38
39 NV_DEBUG(dev, "ch%d\n", chan->id);
40
Ben Skeggs3052be22010-10-20 11:46:38 +100041 ret = nouveau_gpuobj_new(dev, chan, 256, 0,
Ben Skeggsbd2e5972010-10-19 20:06:01 +100042 NVOBJ_FLAG_ZERO_ALLOC | NVOBJ_FLAG_ZERO_FREE,
43 &chan->crypt_ctx);
44 if (ret)
45 return ret;
46
47 nv_wo32(ramin, 0xa0, 0x00190000);
48 nv_wo32(ramin, 0xa4, chan->crypt_ctx->vinst + 0xff);
49 nv_wo32(ramin, 0xa8, chan->crypt_ctx->vinst);
50 nv_wo32(ramin, 0xac, 0);
51 nv_wo32(ramin, 0xb0, 0);
52 nv_wo32(ramin, 0xb4, 0);
53
54 dev_priv->engine.instmem.flush(dev);
55 return 0;
56}
57
58void
59nv84_crypt_destroy_context(struct nouveau_channel *chan)
60{
61 struct drm_device *dev = chan->dev;
62 u32 inst;
63
Ben Skeggs2cb3d3b2010-11-15 16:28:19 +100064 if (!chan->crypt_ctx)
Ben Skeggsbd2e5972010-10-19 20:06:01 +100065 return;
66
67 inst = (chan->ramin->vinst >> 12);
68 inst |= 0x80000000;
69
70 /* mark context as invalid if still on the hardware, not
71 * doing this causes issues the next time PCRYPT is used,
72 * unsurprisingly :)
73 */
74 nv_wr32(dev, 0x10200c, 0x00000000);
75 if (nv_rd32(dev, 0x102188) == inst)
76 nv_mask(dev, 0x102188, 0x80000000, 0x00000000);
77 if (nv_rd32(dev, 0x10218c) == inst)
78 nv_mask(dev, 0x10218c, 0x80000000, 0x00000000);
79 nv_wr32(dev, 0x10200c, 0x00000010);
80
81 nouveau_gpuobj_ref(NULL, &chan->crypt_ctx);
82}
83
84void
85nv84_crypt_tlb_flush(struct drm_device *dev)
86{
87 nv50_vm_flush(dev, 0x0a);
88}
89
90int
91nv84_crypt_init(struct drm_device *dev)
92{
93 struct drm_nouveau_private *dev_priv = dev->dev_private;
94 struct nouveau_crypt_engine *pcrypt = &dev_priv->engine.crypt;
95
96 if (!pcrypt->registered) {
97 NVOBJ_CLASS(dev, 0x74c1, CRYPT);
98 pcrypt->registered = true;
99 }
100
101 nv_mask(dev, 0x000200, 0x00004000, 0x00000000);
102 nv_mask(dev, 0x000200, 0x00004000, 0x00004000);
Ben Skeggsd7facf92010-11-03 10:06:43 +1000103
104 nouveau_irq_register(dev, 14, nv84_crypt_isr);
Ben Skeggsbd2e5972010-10-19 20:06:01 +1000105 nv_wr32(dev, 0x102130, 0xffffffff);
106 nv_wr32(dev, 0x102140, 0xffffffbf);
Ben Skeggsd7facf92010-11-03 10:06:43 +1000107
Ben Skeggsbd2e5972010-10-19 20:06:01 +1000108 nv_wr32(dev, 0x10200c, 0x00000010);
109 return 0;
110}
111
112void
113nv84_crypt_fini(struct drm_device *dev)
114{
115 nv_wr32(dev, 0x102140, 0x00000000);
Ben Skeggsd7facf92010-11-03 10:06:43 +1000116 nouveau_irq_unregister(dev, 14);
117}
118
119static void
120nv84_crypt_isr(struct drm_device *dev)
121{
122 u32 stat = nv_rd32(dev, 0x102130);
123 u32 mthd = nv_rd32(dev, 0x102190);
124 u32 data = nv_rd32(dev, 0x102194);
125 u32 inst = nv_rd32(dev, 0x102188) & 0x7fffffff;
126 int show = nouveau_ratelimit();
127
128 if (show) {
129 NV_INFO(dev, "PCRYPT_INTR: 0x%08x 0x%08x 0x%08x 0x%08x\n",
130 stat, mthd, data, inst);
131 }
132
133 nv_wr32(dev, 0x102130, stat);
134 nv_wr32(dev, 0x10200c, 0x10);
135
136 nv50_fb_vm_trap(dev, show, "PCRYPT");
Ben Skeggsbd2e5972010-10-19 20:06:01 +1000137}