1 /* 2 * Copyright 2012 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 #include <engine/cipher.h> 25 #include <engine/fifo.h> 26 27 #include <core/client.h> 28 #include <core/engctx.h> 29 #include <core/enum.h> 30 31 /******************************************************************************* 32 * Crypt object classes 33 ******************************************************************************/ 34 35 static int 36 g84_cipher_object_ctor(struct nvkm_object *parent, 37 struct nvkm_object *engine, 38 struct nvkm_oclass *oclass, void *data, u32 size, 39 struct nvkm_object **pobject) 40 { 41 struct nvkm_gpuobj *obj; 42 int ret; 43 44 ret = nvkm_gpuobj_create(parent, engine, oclass, 0, parent, 45 16, 16, 0, &obj); 46 *pobject = nv_object(obj); 47 if (ret) 48 return ret; 49 50 nv_wo32(obj, 0x00, nv_mclass(obj)); 51 nv_wo32(obj, 0x04, 0x00000000); 52 nv_wo32(obj, 0x08, 0x00000000); 53 nv_wo32(obj, 0x0c, 0x00000000); 54 return 0; 55 } 56 57 static struct nvkm_ofuncs 58 g84_cipher_ofuncs = { 59 .ctor = g84_cipher_object_ctor, 60 .dtor = _nvkm_gpuobj_dtor, 61 .init = _nvkm_gpuobj_init, 62 .fini = _nvkm_gpuobj_fini, 63 .rd32 = _nvkm_gpuobj_rd32, 64 .wr32 = _nvkm_gpuobj_wr32, 65 }; 66 67 static struct nvkm_oclass 68 g84_cipher_sclass[] = { 69 { 0x74c1, &g84_cipher_ofuncs }, 70 {} 71 }; 72 73 /******************************************************************************* 74 * PCIPHER context 75 ******************************************************************************/ 76 77 static struct nvkm_oclass 78 g84_cipher_cclass = { 79 .handle = NV_ENGCTX(CIPHER, 0x84), 80 .ofuncs = &(struct nvkm_ofuncs) { 81 .ctor = _nvkm_engctx_ctor, 82 .dtor = _nvkm_engctx_dtor, 83 .init = _nvkm_engctx_init, 84 .fini = _nvkm_engctx_fini, 85 .rd32 = _nvkm_engctx_rd32, 86 .wr32 = _nvkm_engctx_wr32, 87 }, 88 }; 89 90 /******************************************************************************* 91 * PCIPHER engine/subdev functions 92 ******************************************************************************/ 93 94 static const struct nvkm_bitfield 95 g84_cipher_intr_mask[] = { 96 { 0x00000001, "INVALID_STATE" }, 97 { 0x00000002, "ILLEGAL_MTHD" }, 98 { 0x00000004, "ILLEGAL_CLASS" }, 99 { 0x00000080, "QUERY" }, 100 { 0x00000100, "FAULT" }, 101 {} 102 }; 103 104 static void 105 g84_cipher_intr(struct nvkm_subdev *subdev) 106 { 107 struct nvkm_fifo *fifo = nvkm_fifo(subdev); 108 struct nvkm_engine *engine = nv_engine(subdev); 109 struct nvkm_object *engctx; 110 struct nvkm_engine *cipher = (void *)subdev; 111 u32 stat = nv_rd32(cipher, 0x102130); 112 u32 mthd = nv_rd32(cipher, 0x102190); 113 u32 data = nv_rd32(cipher, 0x102194); 114 u32 inst = nv_rd32(cipher, 0x102188) & 0x7fffffff; 115 int chid; 116 117 engctx = nvkm_engctx_get(engine, inst); 118 chid = fifo->chid(fifo, engctx); 119 120 if (stat) { 121 nv_error(cipher, "%s", ""); 122 nvkm_bitfield_print(g84_cipher_intr_mask, stat); 123 pr_cont(" ch %d [0x%010llx %s] mthd 0x%04x data 0x%08x\n", 124 chid, (u64)inst << 12, nvkm_client_name(engctx), 125 mthd, data); 126 } 127 128 nv_wr32(cipher, 0x102130, stat); 129 nv_wr32(cipher, 0x10200c, 0x10); 130 131 nvkm_engctx_put(engctx); 132 } 133 134 static int 135 g84_cipher_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 136 struct nvkm_oclass *oclass, void *data, u32 size, 137 struct nvkm_object **pobject) 138 { 139 struct nvkm_engine *cipher; 140 int ret; 141 142 ret = nvkm_engine_create(parent, engine, oclass, true, 143 "PCIPHER", "cipher", &cipher); 144 *pobject = nv_object(cipher); 145 if (ret) 146 return ret; 147 148 nv_subdev(cipher)->unit = 0x00004000; 149 nv_subdev(cipher)->intr = g84_cipher_intr; 150 nv_engine(cipher)->cclass = &g84_cipher_cclass; 151 nv_engine(cipher)->sclass = g84_cipher_sclass; 152 return 0; 153 } 154 155 static int 156 g84_cipher_init(struct nvkm_object *object) 157 { 158 struct nvkm_engine *cipher = (void *)object; 159 int ret; 160 161 ret = nvkm_engine_init(cipher); 162 if (ret) 163 return ret; 164 165 nv_wr32(cipher, 0x102130, 0xffffffff); 166 nv_wr32(cipher, 0x102140, 0xffffffbf); 167 nv_wr32(cipher, 0x10200c, 0x00000010); 168 return 0; 169 } 170 171 struct nvkm_oclass 172 g84_cipher_oclass = { 173 .handle = NV_ENGINE(CIPHER, 0x84), 174 .ofuncs = &(struct nvkm_ofuncs) { 175 .ctor = g84_cipher_ctor, 176 .dtor = _nvkm_engine_dtor, 177 .init = g84_cipher_init, 178 .fini = _nvkm_engine_fini, 179 }, 180 }; 181