g84.c 5.1 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
	nv_wo32(obj, 0x00, nv_mclass(obj));
	nv_wo32(obj, 0x04, 0x00000000);
	nv_wo32(obj, 0x08, 0x00000000);
	nv_wo32(obj, 0x0c, 0x00000000);
54 55 56
	return 0;
}

57 58 59 60 61 62 63 64
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,
65 66
};

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

/*******************************************************************************
74
 * PCIPHER context
75
 ******************************************************************************/
76

77 78
static struct nvkm_oclass
g84_cipher_cclass = {
79
	.handle = NV_ENGCTX(CIPHER, 0x84),
80 81 82 83 84 85 86
	.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,
87 88 89 90
	},
};

/*******************************************************************************
91
 * PCIPHER engine/subdev functions
92
 ******************************************************************************/
93

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

104
static void
105
g84_cipher_intr(struct nvkm_subdev *subdev)
106
{
B
Ben Skeggs 已提交
107
	struct nvkm_fifo *fifo = nvkm_fifo(subdev);
108 109
	struct nvkm_engine *engine = nv_engine(subdev);
	struct nvkm_object *engctx;
110
	struct nvkm_engine *cipher = (void *)subdev;
111 112 113 114 115
	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;
116
	char msg[128];
117 118
	int chid;

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

	if (stat) {
123 124 125 126 127
		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);
128 129
	}

130 131
	nvkm_wr32(device, 0x102130, stat);
	nvkm_wr32(device, 0x10200c, 0x10);
132

133
	nvkm_engctx_put(engctx);
134 135 136
}

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

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

150 151 152 153
	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;
154 155 156
	return 0;
}

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

164
	ret = nvkm_engine_init(cipher);
165 166
	if (ret)
		return ret;
167

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

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