| 1 | /* $NetBSD: nouveau_engine_crypt_nv98.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_nv98.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 | |
| 36 | #include <subdev/timer.h> |
| 37 | #include <subdev/fb.h> |
| 38 | |
| 39 | #include <engine/falcon.h> |
| 40 | #include <engine/fifo.h> |
| 41 | #include <engine/crypt.h> |
| 42 | |
| 43 | #include "fuc/nv98.fuc.h" |
| 44 | |
| 45 | struct nv98_crypt_priv { |
| 46 | struct nouveau_falcon base; |
| 47 | }; |
| 48 | |
| 49 | /******************************************************************************* |
| 50 | * Crypt object classes |
| 51 | ******************************************************************************/ |
| 52 | |
| 53 | static struct nouveau_oclass |
| 54 | nv98_crypt_sclass[] = { |
| 55 | { 0x88b4, &nouveau_object_ofuncs }, |
| 56 | {}, |
| 57 | }; |
| 58 | |
| 59 | /******************************************************************************* |
| 60 | * PCRYPT context |
| 61 | ******************************************************************************/ |
| 62 | |
| 63 | static struct nouveau_oclass |
| 64 | nv98_crypt_cclass = { |
| 65 | .handle = NV_ENGCTX(CRYPT, 0x98), |
| 66 | .ofuncs = &(struct nouveau_ofuncs) { |
| 67 | .ctor = _nouveau_falcon_context_ctor, |
| 68 | .dtor = _nouveau_falcon_context_dtor, |
| 69 | .init = _nouveau_falcon_context_init, |
| 70 | .fini = _nouveau_falcon_context_fini, |
| 71 | .rd32 = _nouveau_falcon_context_rd32, |
| 72 | .wr32 = _nouveau_falcon_context_wr32, |
| 73 | }, |
| 74 | }; |
| 75 | |
| 76 | /******************************************************************************* |
| 77 | * PCRYPT engine/subdev functions |
| 78 | ******************************************************************************/ |
| 79 | |
| 80 | static const struct nouveau_enum nv98_crypt_isr_error_name[] = { |
| 81 | { 0x0000, "ILLEGAL_MTHD" }, |
| 82 | { 0x0001, "INVALID_BITFIELD" }, |
| 83 | { 0x0002, "INVALID_ENUM" }, |
| 84 | { 0x0003, "QUERY" }, |
| 85 | {} |
| 86 | }; |
| 87 | |
| 88 | static void |
| 89 | nv98_crypt_intr(struct nouveau_subdev *subdev) |
| 90 | { |
| 91 | struct nouveau_fifo *pfifo = nouveau_fifo(subdev); |
| 92 | struct nouveau_engine *engine = nv_engine(subdev); |
| 93 | struct nouveau_object *engctx; |
| 94 | struct nv98_crypt_priv *priv = (void *)subdev; |
| 95 | u32 disp = nv_rd32(priv, 0x08701c); |
| 96 | u32 stat = nv_rd32(priv, 0x087008) & disp & ~(disp >> 16); |
| 97 | u32 inst = nv_rd32(priv, 0x087050) & 0x3fffffff; |
| 98 | u32 ssta = nv_rd32(priv, 0x087040) & 0x0000ffff; |
| 99 | u32 addr = nv_rd32(priv, 0x087040) >> 16; |
| 100 | u32 mthd = (addr & 0x07ff) << 2; |
| 101 | u32 subc = (addr & 0x3800) >> 11; |
| 102 | u32 data = nv_rd32(priv, 0x087044); |
| 103 | int chid; |
| 104 | |
| 105 | engctx = nouveau_engctx_get(engine, inst); |
| 106 | chid = pfifo->chid(pfifo, engctx); |
| 107 | |
| 108 | if (stat & 0x00000040) { |
| 109 | nv_error(priv, "DISPATCH_ERROR [" ); |
| 110 | nouveau_enum_print(nv98_crypt_isr_error_name, ssta); |
| 111 | pr_cont("] ch %d [0x%010" PRIx64" %s] subc %d mthd 0x%04x data 0x%08x\n" , |
| 112 | chid, (u64)inst << 12, nouveau_client_name(engctx), |
| 113 | subc, mthd, data); |
| 114 | nv_wr32(priv, 0x087004, 0x00000040); |
| 115 | stat &= ~0x00000040; |
| 116 | } |
| 117 | |
| 118 | if (stat) { |
| 119 | nv_error(priv, "unhandled intr 0x%08x\n" , stat); |
| 120 | nv_wr32(priv, 0x087004, stat); |
| 121 | } |
| 122 | |
| 123 | nouveau_engctx_put(engctx); |
| 124 | } |
| 125 | |
| 126 | static int |
| 127 | nv98_crypt_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
| 128 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 129 | struct nouveau_object **pobject) |
| 130 | { |
| 131 | struct nv98_crypt_priv *priv; |
| 132 | int ret; |
| 133 | |
| 134 | ret = nouveau_falcon_create(parent, engine, oclass, 0x087000, true, |
| 135 | "PCRYPT" , "crypt" , &priv); |
| 136 | *pobject = nv_object(priv); |
| 137 | if (ret) |
| 138 | return ret; |
| 139 | |
| 140 | nv_subdev(priv)->unit = 0x00004000; |
| 141 | nv_subdev(priv)->intr = nv98_crypt_intr; |
| 142 | nv_engine(priv)->cclass = &nv98_crypt_cclass; |
| 143 | nv_engine(priv)->sclass = nv98_crypt_sclass; |
| 144 | nv_falcon(priv)->code.data = nv98_pcrypt_code; |
| 145 | nv_falcon(priv)->code.size = sizeof(nv98_pcrypt_code); |
| 146 | nv_falcon(priv)->data.data = nv98_pcrypt_data; |
| 147 | nv_falcon(priv)->data.size = sizeof(nv98_pcrypt_data); |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | struct nouveau_oclass |
| 152 | nv98_crypt_oclass = { |
| 153 | .handle = NV_ENGINE(CRYPT, 0x98), |
| 154 | .ofuncs = &(struct nouveau_ofuncs) { |
| 155 | .ctor = nv98_crypt_ctor, |
| 156 | .dtor = _nouveau_falcon_dtor, |
| 157 | .init = _nouveau_falcon_init, |
| 158 | .fini = _nouveau_falcon_fini, |
| 159 | .rd32 = _nouveau_falcon_rd32, |
| 160 | .wr32 = _nouveau_falcon_wr32, |
| 161 | }, |
| 162 | }; |
| 163 | |