g84.c 5.2 KB
Newer Older
1
/*
2
 * Copyright 2012 Red Hat Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Ben Skeggs
 */
24 25
#include <engine/cipher.h>
#include <engine/fifo.h>
26

27
#include <core/client.h>
28
#include <core/engctx.h>
29
#include <core/enum.h>
30 31 32 33 34

/*******************************************************************************
 * Crypt object classes
 ******************************************************************************/

35
static int
36 37 38 39
g84_cipher_object_ctor(struct nvkm_object *parent,
		       struct nvkm_object *engine,
		       struct nvkm_oclass *oclass, void *data, u32 size,
		       struct nvkm_object **pobject)
40
{
41
	struct nvkm_gpuobj *obj;
42 43
	int ret;

44 45
	ret = nvkm_gpuobj_create(parent, engine, oclass, 0, parent,
				 16, 16, 0, &obj);
46
	*pobject = nv_object(obj);
47 48 49
	if (ret)
		return ret;

50 51 52 53 54 55
	nvkm_kmap(obj);
	nvkm_wo32(obj, 0x00, nv_mclass(obj));
	nvkm_wo32(obj, 0x04, 0x00000000);
	nvkm_wo32(obj, 0x08, 0x00000000);
	nvkm_wo32(obj, 0x0c, 0x00000000);
	nvkm_done(obj);
56 57 58
	return 0;
}

59 60 61 62 63 64 65 66
static struct nvkm_ofuncs
g84_cipher_ofuncs = {
	.ctor = g84_cipher_object_ctor,
	.dtor = _nvkm_gpuobj_dtor,
	.init = _nvkm_gpuobj_init,
	.fini = _nvkm_gpuobj_fini,
	.rd32 = _nvkm_gpuobj_rd32,
	.wr32 = _nvkm_gpuobj_wr32,
67 68
};

69 70 71
static struct nvkm_oclass
g84_cipher_sclass[] = {
	{ 0x74c1, &g84_cipher_ofuncs },
72 73 74 75
	{}
};

/*******************************************************************************
76
 * PCIPHER context
77
 ******************************************************************************/
78

79 80
static struct nvkm_oclass
g84_cipher_cclass = {
81
	.handle = NV_ENGCTX(CIPHER, 0x84),
82 83 84 85 86 87 88
	.ofuncs = &(struct nvkm_ofuncs) {
		.ctor = _nvkm_engctx_ctor,
		.dtor = _nvkm_engctx_dtor,
		.init = _nvkm_engctx_init,
		.fini = _nvkm_engctx_fini,
		.rd32 = _nvkm_engctx_rd32,
		.wr32 = _nvkm_engctx_wr32,
89 90 91 92
	},
};

/*******************************************************************************
93
 * PCIPHER engine/subdev functions
94
 ******************************************************************************/
95

96 97
static const struct nvkm_bitfield
g84_cipher_intr_mask[] = {
M
Marcin Slusarz 已提交
98 99 100 101 102 103 104 105
	{ 0x00000001, "INVALID_STATE" },
	{ 0x00000002, "ILLEGAL_MTHD" },
	{ 0x00000004, "ILLEGAL_CLASS" },
	{ 0x00000080, "QUERY" },
	{ 0x00000100, "FAULT" },
	{}
};

106
static void
107
g84_cipher_intr(struct nvkm_subdev *subdev)
108
{
B
Ben Skeggs 已提交
109
	struct nvkm_fifo *fifo = nvkm_fifo(subdev);
110 111
	struct nvkm_engine *engine = nv_engine(subdev);
	struct nvkm_object *engctx;
112
	struct nvkm_engine *cipher = (void *)subdev;
113 114 115 116 117
	struct nvkm_device *device = cipher->subdev.device;
	u32 stat = nvkm_rd32(device, 0x102130);
	u32 mthd = nvkm_rd32(device, 0x102190);
	u32 data = nvkm_rd32(device, 0x102194);
	u32 inst = nvkm_rd32(device, 0x102188) & 0x7fffffff;
118
	char msg[128];
119 120
	int chid;

121
	engctx = nvkm_engctx_get(engine, inst);
B
Ben Skeggs 已提交
122
	chid   = fifo->chid(fifo, engctx);
123 124

	if (stat) {
125 126 127 128 129
		nvkm_snprintbf(msg, sizeof(msg), g84_cipher_intr_mask, stat);
		nvkm_error(subdev,  "%08x [%s] ch %d [%010llx %s] "
				    "mthd %04x data %08x\n",
			   stat, msg, chid, (u64)inst << 12,
			   nvkm_client_name(engctx), mthd, data);
130 131
	}

132 133
	nvkm_wr32(device, 0x102130, stat);
	nvkm_wr32(device, 0x10200c, 0x10);
134

135
	nvkm_engctx_put(engctx);
136 137 138
}

static int
139 140 141
g84_cipher_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
		struct nvkm_oclass *oclass, void *data, u32 size,
		struct nvkm_object **pobject)
142
{
143
	struct nvkm_engine *cipher;
144
	int ret;
145

146
	ret = nvkm_engine_create(parent, engine, oclass, true,
147 148
				 "PCIPHER", "cipher", &cipher);
	*pobject = nv_object(cipher);
149 150
	if (ret)
		return ret;
151

152 153 154 155
	nv_subdev(cipher)->unit = 0x00004000;
	nv_subdev(cipher)->intr = g84_cipher_intr;
	nv_engine(cipher)->cclass = &g84_cipher_cclass;
	nv_engine(cipher)->sclass = g84_cipher_sclass;
156 157 158
	return 0;
}

159
static int
160
g84_cipher_init(struct nvkm_object *object)
161
{
162
	struct nvkm_engine *cipher = (void *)object;
163
	struct nvkm_device *device = cipher->subdev.device;
164
	int ret;
165

166
	ret = nvkm_engine_init(cipher);
167 168
	if (ret)
		return ret;
169

170 171 172
	nvkm_wr32(device, 0x102130, 0xffffffff);
	nvkm_wr32(device, 0x102140, 0xffffffbf);
	nvkm_wr32(device, 0x10200c, 0x00000010);
173
	return 0;
174
}
175

176 177
struct nvkm_oclass
g84_cipher_oclass = {
178
	.handle = NV_ENGINE(CIPHER, 0x84),
179 180 181 182 183
	.ofuncs = &(struct nvkm_ofuncs) {
		.ctor = g84_cipher_ctor,
		.dtor = _nvkm_engine_dtor,
		.init = g84_cipher_init,
		.fini = _nvkm_engine_fini,
184 185
	},
};