| 1 | /* $NetBSD: nouveau_engine_crypt_nv84.c,v 1.2 2014/08/23 08:03:33 riastradh Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2012 Red Hat Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Ben Skeggs |
| 25 | */ |
| 26 | |
| 27 | #include <sys/cdefs.h> |
| 28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_engine_crypt_nv84.c,v 1.2 2014/08/23 08:03:33 riastradh Exp $" ); |
| 29 | |
| 30 | #include <core/client.h> |
| 31 | #include <core/os.h> |
| 32 | #include <core/enum.h> |
| 33 | #include <core/class.h> |
| 34 | #include <core/engctx.h> |
| 35 | #include <core/gpuobj.h> |
| 36 | |
| 37 | #include <subdev/fb.h> |
| 38 | |
| 39 | #include <engine/fifo.h> |
| 40 | #include <engine/crypt.h> |
| 41 | |
| 42 | struct nv84_crypt_priv { |
| 43 | struct nouveau_engine base; |
| 44 | }; |
| 45 | |
| 46 | /******************************************************************************* |
| 47 | * Crypt object classes |
| 48 | ******************************************************************************/ |
| 49 | |
| 50 | static int |
| 51 | nv84_crypt_object_ctor(struct nouveau_object *parent, |
| 52 | struct nouveau_object *engine, |
| 53 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 54 | struct nouveau_object **pobject) |
| 55 | { |
| 56 | struct nouveau_gpuobj *obj; |
| 57 | int ret; |
| 58 | |
| 59 | ret = nouveau_gpuobj_create(parent, engine, oclass, 0, parent, |
| 60 | 16, 16, 0, &obj); |
| 61 | *pobject = nv_object(obj); |
| 62 | if (ret) |
| 63 | return ret; |
| 64 | |
| 65 | nv_wo32(obj, 0x00, nv_mclass(obj)); |
| 66 | nv_wo32(obj, 0x04, 0x00000000); |
| 67 | nv_wo32(obj, 0x08, 0x00000000); |
| 68 | nv_wo32(obj, 0x0c, 0x00000000); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static struct nouveau_ofuncs |
| 73 | nv84_crypt_ofuncs = { |
| 74 | .ctor = nv84_crypt_object_ctor, |
| 75 | .dtor = _nouveau_gpuobj_dtor, |
| 76 | .init = _nouveau_gpuobj_init, |
| 77 | .fini = _nouveau_gpuobj_fini, |
| 78 | .rd32 = _nouveau_gpuobj_rd32, |
| 79 | .wr32 = _nouveau_gpuobj_wr32, |
| 80 | }; |
| 81 | |
| 82 | static struct nouveau_oclass |
| 83 | nv84_crypt_sclass[] = { |
| 84 | { 0x74c1, &nv84_crypt_ofuncs }, |
| 85 | {} |
| 86 | }; |
| 87 | |
| 88 | /******************************************************************************* |
| 89 | * PCRYPT context |
| 90 | ******************************************************************************/ |
| 91 | |
| 92 | static struct nouveau_oclass |
| 93 | nv84_crypt_cclass = { |
| 94 | .handle = NV_ENGCTX(CRYPT, 0x84), |
| 95 | .ofuncs = &(struct nouveau_ofuncs) { |
| 96 | .ctor = _nouveau_engctx_ctor, |
| 97 | .dtor = _nouveau_engctx_dtor, |
| 98 | .init = _nouveau_engctx_init, |
| 99 | .fini = _nouveau_engctx_fini, |
| 100 | .rd32 = _nouveau_engctx_rd32, |
| 101 | .wr32 = _nouveau_engctx_wr32, |
| 102 | }, |
| 103 | }; |
| 104 | |
| 105 | /******************************************************************************* |
| 106 | * PCRYPT engine/subdev functions |
| 107 | ******************************************************************************/ |
| 108 | |
| 109 | static const struct nouveau_bitfield nv84_crypt_intr_mask[] = { |
| 110 | { 0x00000001, "INVALID_STATE" }, |
| 111 | { 0x00000002, "ILLEGAL_MTHD" }, |
| 112 | { 0x00000004, "ILLEGAL_CLASS" }, |
| 113 | { 0x00000080, "QUERY" }, |
| 114 | { 0x00000100, "FAULT" }, |
| 115 | {} |
| 116 | }; |
| 117 | |
| 118 | static void |
| 119 | nv84_crypt_intr(struct nouveau_subdev *subdev) |
| 120 | { |
| 121 | struct nouveau_fifo *pfifo = nouveau_fifo(subdev); |
| 122 | struct nouveau_engine *engine = nv_engine(subdev); |
| 123 | struct nouveau_object *engctx; |
| 124 | struct nv84_crypt_priv *priv = (void *)subdev; |
| 125 | u32 stat = nv_rd32(priv, 0x102130); |
| 126 | u32 mthd = nv_rd32(priv, 0x102190); |
| 127 | u32 data = nv_rd32(priv, 0x102194); |
| 128 | u32 inst = nv_rd32(priv, 0x102188) & 0x7fffffff; |
| 129 | int chid; |
| 130 | |
| 131 | engctx = nouveau_engctx_get(engine, inst); |
| 132 | chid = pfifo->chid(pfifo, engctx); |
| 133 | |
| 134 | if (stat) { |
| 135 | nv_error(priv, "%s" , "" ); |
| 136 | nouveau_bitfield_print(nv84_crypt_intr_mask, stat); |
| 137 | pr_cont(" ch %d [0x%010" PRIx64" %s] mthd 0x%04x data 0x%08x\n" , |
| 138 | chid, (u64)inst << 12, nouveau_client_name(engctx), |
| 139 | mthd, data); |
| 140 | } |
| 141 | |
| 142 | nv_wr32(priv, 0x102130, stat); |
| 143 | nv_wr32(priv, 0x10200c, 0x10); |
| 144 | |
| 145 | nouveau_engctx_put(engctx); |
| 146 | } |
| 147 | |
| 148 | static int |
| 149 | nv84_crypt_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
| 150 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 151 | struct nouveau_object **pobject) |
| 152 | { |
| 153 | struct nv84_crypt_priv *priv; |
| 154 | int ret; |
| 155 | |
| 156 | ret = nouveau_engine_create(parent, engine, oclass, true, |
| 157 | "PCRYPT" , "crypt" , &priv); |
| 158 | *pobject = nv_object(priv); |
| 159 | if (ret) |
| 160 | return ret; |
| 161 | |
| 162 | nv_subdev(priv)->unit = 0x00004000; |
| 163 | nv_subdev(priv)->intr = nv84_crypt_intr; |
| 164 | nv_engine(priv)->cclass = &nv84_crypt_cclass; |
| 165 | nv_engine(priv)->sclass = nv84_crypt_sclass; |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static int |
| 170 | nv84_crypt_init(struct nouveau_object *object) |
| 171 | { |
| 172 | struct nv84_crypt_priv *priv = (void *)object; |
| 173 | int ret; |
| 174 | |
| 175 | ret = nouveau_engine_init(&priv->base); |
| 176 | if (ret) |
| 177 | return ret; |
| 178 | |
| 179 | nv_wr32(priv, 0x102130, 0xffffffff); |
| 180 | nv_wr32(priv, 0x102140, 0xffffffbf); |
| 181 | nv_wr32(priv, 0x10200c, 0x00000010); |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | struct nouveau_oclass |
| 186 | nv84_crypt_oclass = { |
| 187 | .handle = NV_ENGINE(CRYPT, 0x84), |
| 188 | .ofuncs = &(struct nouveau_ofuncs) { |
| 189 | .ctor = nv84_crypt_ctor, |
| 190 | .dtor = _nouveau_engine_dtor, |
| 191 | .init = nv84_crypt_init, |
| 192 | .fini = _nouveau_engine_fini, |
| 193 | }, |
| 194 | }; |
| 195 | |