2 * Copyright 2012 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.
26 #include <core/enum.h>
27 #include <core/class.h>
28 #include <core/engctx.h>
29 #include <core/gpuobj.h>
31 #include <subdev/fb.h>
33 #include <engine/crypt.h>
35 struct nv84_crypt_priv
{
36 struct nouveau_crypt base
;
39 struct nv84_crypt_chan
{
40 struct nouveau_crypt_chan base
;
43 /*******************************************************************************
44 * Crypt object classes
45 ******************************************************************************/
48 nv84_crypt_object_ctor(struct nouveau_object
*parent
,
49 struct nouveau_object
*engine
,
50 struct nouveau_oclass
*oclass
, void *data
, u32 size
,
51 struct nouveau_object
**pobject
)
53 struct nouveau_gpuobj
*obj
;
56 ret
= nouveau_gpuobj_create(parent
, engine
, oclass
, 0, parent
,
58 *pobject
= nv_object(obj
);
62 nv_wo32(obj
, 0x00, nv_mclass(obj
));
63 nv_wo32(obj
, 0x04, 0x00000000);
64 nv_wo32(obj
, 0x08, 0x00000000);
65 nv_wo32(obj
, 0x0c, 0x00000000);
69 static struct nouveau_ofuncs
71 .ctor
= nv84_crypt_object_ctor
,
72 .dtor
= _nouveau_gpuobj_dtor
,
73 .init
= _nouveau_gpuobj_init
,
74 .fini
= _nouveau_gpuobj_fini
,
75 .rd32
= _nouveau_gpuobj_rd32
,
76 .wr32
= _nouveau_gpuobj_wr32
,
79 static struct nouveau_oclass
80 nv84_crypt_sclass
[] = {
81 { 0x74c1, &nv84_crypt_ofuncs
},
85 /*******************************************************************************
87 ******************************************************************************/
90 nv84_crypt_context_ctor(struct nouveau_object
*parent
,
91 struct nouveau_object
*engine
,
92 struct nouveau_oclass
*oclass
, void *data
, u32 size
,
93 struct nouveau_object
**pobject
)
95 struct nv84_crypt_chan
*priv
;
98 ret
= nouveau_crypt_context_create(parent
, engine
, oclass
, NULL
, 256,
99 0, NVOBJ_FLAG_ZERO_ALLOC
, &priv
);
100 *pobject
= nv_object(priv
);
107 static struct nouveau_oclass
108 nv84_crypt_cclass
= {
109 .handle
= NV_ENGCTX(CRYPT
, 0x84),
110 .ofuncs
= &(struct nouveau_ofuncs
) {
111 .ctor
= nv84_crypt_context_ctor
,
112 .dtor
= _nouveau_crypt_context_dtor
,
113 .init
= _nouveau_crypt_context_init
,
114 .fini
= _nouveau_crypt_context_fini
,
115 .rd32
= _nouveau_crypt_context_rd32
,
116 .wr32
= _nouveau_crypt_context_wr32
,
120 /*******************************************************************************
121 * PCRYPT engine/subdev functions
122 ******************************************************************************/
124 static struct nouveau_bitfield nv84_crypt_intr_mask
[] = {
125 { 0x00000001, "INVALID_STATE" },
126 { 0x00000002, "ILLEGAL_MTHD" },
127 { 0x00000004, "ILLEGAL_CLASS" },
128 { 0x00000080, "QUERY" },
129 { 0x00000100, "FAULT" },
134 nv84_crypt_intr(struct nouveau_subdev
*subdev
)
136 struct nv84_crypt_priv
*priv
= (void *)subdev
;
137 u32 stat
= nv_rd32(priv
, 0x102130);
138 u32 mthd
= nv_rd32(priv
, 0x102190);
139 u32 data
= nv_rd32(priv
, 0x102194);
140 u32 inst
= nv_rd32(priv
, 0x102188) & 0x7fffffff;
144 nouveau_bitfield_print(nv84_crypt_intr_mask
, stat
);
145 printk(" ch 0x%010llx mthd 0x%04x data 0x%08x\n",
146 (u64
)inst
<< 12, mthd
, data
);
149 nv_wr32(priv
, 0x102130, stat
);
150 nv_wr32(priv
, 0x10200c, 0x10);
152 nv50_fb_trap(nouveau_fb(priv
), 1);
156 nv84_crypt_tlb_flush(struct nouveau_engine
*engine
)
158 nv50_vm_flush_engine(&engine
->base
, 0x0a);
163 nv84_crypt_ctor(struct nouveau_object
*parent
, struct nouveau_object
*engine
,
164 struct nouveau_oclass
*oclass
, void *data
, u32 size
,
165 struct nouveau_object
**pobject
)
167 struct nv84_crypt_priv
*priv
;
170 ret
= nouveau_crypt_create(parent
, engine
, oclass
, &priv
);
171 *pobject
= nv_object(priv
);
175 nv_subdev(priv
)->unit
= 0x00004000;
176 nv_subdev(priv
)->intr
= nv84_crypt_intr
;
177 nv_engine(priv
)->cclass
= &nv84_crypt_cclass
;
178 nv_engine(priv
)->sclass
= nv84_crypt_sclass
;
179 nv_engine(priv
)->tlb_flush
= nv84_crypt_tlb_flush
;
184 nv84_crypt_init(struct nouveau_object
*object
)
186 struct nv84_crypt_priv
*priv
= (void *)object
;
189 ret
= nouveau_crypt_init(&priv
->base
);
193 nv_wr32(priv
, 0x102130, 0xffffffff);
194 nv_wr32(priv
, 0x102140, 0xffffffbf);
195 nv_wr32(priv
, 0x10200c, 0x00000010);
199 struct nouveau_oclass
200 nv84_crypt_oclass
= {
201 .handle
= NV_ENGINE(CRYPT
, 0x84),
202 .ofuncs
= &(struct nouveau_ofuncs
) {
203 .ctor
= nv84_crypt_ctor
,
204 .dtor
= _nouveau_crypt_dtor
,
205 .init
= nv84_crypt_init
,
206 .fini
= _nouveau_crypt_fini
,