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 nvkm_kmap(obj); 51 nvkm_wo32(obj, 0x00, nv_mclass(obj)); 52 nvkm_wo32(obj, 0x04, 0x00000000); 53 nvkm_wo32(obj, 0x08, 0x00000000); 54 nvkm_wo32(obj, 0x0c, 0x00000000); 55 nvkm_done(obj); 56 return 0; 57 } 58 59 static struct nvkm_ofuncs 60 g84_cipher_ofuncs = { 61 .ctor = g84_cipher_object_ctor, 62 .dtor = _nvkm_gpuobj_dtor, 63 .init = _nvkm_gpuobj_init, 64 .fini = _nvkm_gpuobj_fini, 65 .rd32 = _nvkm_gpuobj_rd32, 66 .wr32 = _nvkm_gpuobj_wr32, 67 }; 68 69 static struct nvkm_oclass 70 g84_cipher_sclass[] = { 71 { 0x74c1, &g84_cipher_ofuncs }, 72 {} 73 }; 74 75 /******************************************************************************* 76 * PCIPHER context 77 ******************************************************************************/ 78 79 static struct nvkm_oclass 80 g84_cipher_cclass = { 81 .handle = NV_ENGCTX(CIPHER, 0x84), 82 .ofuncs = &(struct nvkm_ofuncs) { 83 .ctor = _nvkm_engctx_ctor, 84 .dtor = _nvkm_engctx_dtor, 85 .init = _nvkm_engctx_init, 86 .fini = _nvkm_engctx_fini, 87 .rd32 = _nvkm_engctx_rd32, 88 .wr32 = _nvkm_engctx_wr32, 89 }, 90 }; 91 92 /******************************************************************************* 93 * PCIPHER engine/subdev functions 94 ******************************************************************************/ 95 96 static const struct nvkm_bitfield 97 g84_cipher_intr_mask[] = { 98 { 0x00000001, "INVALID_STATE" }, 99 { 0x00000002, "ILLEGAL_MTHD" }, 100 { 0x00000004, "ILLEGAL_CLASS" }, 101 { 0x00000080, "QUERY" }, 102 { 0x00000100, "FAULT" }, 103 {} 104 }; 105 106 static void 107 g84_cipher_intr(struct nvkm_subdev *subdev) 108 { 109 struct nvkm_engine *cipher = (void *)subdev; 110 struct nvkm_device *device = cipher->subdev.device; 111 struct nvkm_fifo *fifo = device->fifo; 112 struct nvkm_fifo_chan *chan; 113 u32 stat = nvkm_rd32(device, 0x102130); 114 u32 mthd = nvkm_rd32(device, 0x102190); 115 u32 data = nvkm_rd32(device, 0x102194); 116 u32 inst = nvkm_rd32(device, 0x102188) & 0x7fffffff; 117 unsigned long flags; 118 char msg[128]; 119 120 chan = nvkm_fifo_chan_inst(fifo, (u64)inst << 12, &flags); 121 if (stat) { 122 nvkm_snprintbf(msg, sizeof(msg), g84_cipher_intr_mask, stat); 123 nvkm_error(subdev, "%08x [%s] ch %d [%010llx %s] " 124 "mthd %04x data %08x\n", stat, msg, 125 chan ? chan->chid : -1, (u64)inst << 12, 126 chan ? chan->object.client->name : "unknown", 127 mthd, data); 128 } 129 nvkm_fifo_chan_put(fifo, flags, &chan); 130 131 nvkm_wr32(device, 0x102130, stat); 132 nvkm_wr32(device, 0x10200c, 0x10); 133 } 134 135 static int 136 g84_cipher_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 137 struct nvkm_oclass *oclass, void *data, u32 size, 138 struct nvkm_object **pobject) 139 { 140 struct nvkm_engine *cipher; 141 int ret; 142 143 ret = nvkm_engine_create(parent, engine, oclass, true, 144 "PCIPHER", "cipher", &cipher); 145 *pobject = nv_object(cipher); 146 if (ret) 147 return ret; 148 149 nv_subdev(cipher)->unit = 0x00004000; 150 nv_subdev(cipher)->intr = g84_cipher_intr; 151 nv_engine(cipher)->cclass = &g84_cipher_cclass; 152 nv_engine(cipher)->sclass = g84_cipher_sclass; 153 return 0; 154 } 155 156 static int 157 g84_cipher_init(struct nvkm_object *object) 158 { 159 struct nvkm_engine *cipher = (void *)object; 160 struct nvkm_device *device = cipher->subdev.device; 161 int ret; 162 163 ret = nvkm_engine_init_old(cipher); 164 if (ret) 165 return ret; 166 167 nvkm_wr32(device, 0x102130, 0xffffffff); 168 nvkm_wr32(device, 0x102140, 0xffffffbf); 169 nvkm_wr32(device, 0x10200c, 0x00000010); 170 return 0; 171 } 172 173 struct nvkm_oclass 174 g84_cipher_oclass = { 175 .handle = NV_ENGINE(CIPHER, 0x84), 176 .ofuncs = &(struct nvkm_ofuncs) { 177 .ctor = g84_cipher_ctor, 178 .dtor = _nvkm_engine_dtor, 179 .init = g84_cipher_init, 180 .fini = _nvkm_engine_fini, 181 }, 182 }; 183