nvc0.c 7.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 24
 *
 * 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
 */

25 26 27 28 29 30 31
#include <core/os.h>
#include <core/enum.h>
#include <core/class.h>
#include <core/engctx.h>

#include <engine/copy.h>

32
#include "fuc/nvc0.fuc.h"
33

34 35
struct nvc0_copy_priv {
	struct nouveau_copy base;
36 37
};

38
struct nvc0_copy_chan {
39
	struct nouveau_copy_chan base;
40 41
};

42 43 44
/*******************************************************************************
 * Copy object classes
 ******************************************************************************/
45

46 47 48 49 50
static struct nouveau_oclass
nvc0_copy0_sclass[] = {
	{ 0x90b5, &nouveau_object_ofuncs },
	{},
};
51

52 53 54 55 56
static struct nouveau_oclass
nvc0_copy1_sclass[] = {
	{ 0x90b8, &nouveau_object_ofuncs },
	{},
};
57

58 59 60
/*******************************************************************************
 * PCOPY context
 ******************************************************************************/
61 62

static int
63 64 65 66
nvc0_copy_context_ctor(struct nouveau_object *parent,
		       struct nouveau_object *engine,
		       struct nouveau_oclass *oclass, void *data, u32 size,
		       struct nouveau_object **pobject)
67
{
68 69
	struct nvc0_copy_chan *priv;
	int ret;
70

71 72 73 74 75
	ret = nouveau_copy_context_create(parent, engine, oclass, NULL, 256,
					  256, NVOBJ_FLAG_ZERO_ALLOC, &priv);
	*pobject = nv_object(priv);
	if (ret)
		return ret;
76 77 78 79

	return 0;
}

80 81 82 83 84 85 86 87 88
static struct nouveau_ofuncs
nvc0_copy_context_ofuncs = {
	.ctor = nvc0_copy_context_ctor,
	.dtor = _nouveau_copy_context_dtor,
	.init = _nouveau_copy_context_init,
	.fini = _nouveau_copy_context_fini,
	.rd32 = _nouveau_copy_context_rd32,
	.wr32 = _nouveau_copy_context_wr32,
};
89

90 91 92 93 94
static struct nouveau_oclass
nvc0_copy0_cclass = {
	.handle = NV_ENGCTX(COPY0, 0xc0),
	.ofuncs = &nvc0_copy_context_ofuncs,
};
95

96 97 98 99 100
static struct nouveau_oclass
nvc0_copy1_cclass = {
	.handle = NV_ENGCTX(COPY1, 0xc0),
	.ofuncs = &nvc0_copy_context_ofuncs,
};
101

102 103 104
/*******************************************************************************
 * PCOPY engine/subdev functions
 ******************************************************************************/
105 106 107 108 109 110 111 112 113

static struct nouveau_enum nvc0_copy_isr_error_name[] = {
	{ 0x0001, "ILLEGAL_MTHD" },
	{ 0x0002, "INVALID_ENUM" },
	{ 0x0003, "INVALID_BITFIELD" },
	{}
};

static void
114
nvc0_copy_intr(struct nouveau_subdev *subdev)
115
{
116 117 118 119 120 121 122 123
	int idx = nv_engidx(nv_object(subdev)) - NVDEV_ENGINE_COPY0;
	struct nvc0_copy_priv *priv = (void *)subdev;
	u32 disp = nv_rd32(priv, 0x10401c + (idx * 0x1000));
	u32 intr = nv_rd32(priv, 0x104008 + (idx * 0x1000));
	u32 stat = intr & disp & ~(disp >> 16);
	u64 inst = nv_rd32(priv, 0x104050 + (idx * 0x1000)) & 0x0fffffff;
	u32 ssta = nv_rd32(priv, 0x104040 + (idx * 0x1000)) & 0x0000ffff;
	u32 addr = nv_rd32(priv, 0x104040 + (idx * 0x1000)) >> 16;
124 125
	u32 mthd = (addr & 0x07ff) << 2;
	u32 subc = (addr & 0x3800) >> 11;
126
	u32 data = nv_rd32(priv, 0x104044 + (idx * 0x1000));
127 128

	if (stat & 0x00000040) {
129
		nv_error(priv, "DISPATCH_ERROR [");
130
		nouveau_enum_print(nvc0_copy_isr_error_name, ssta);
131 132 133
		printk("] ch 0x%010llx subc %d mthd 0x%04x data 0x%08x\n",
		       (u64)inst << 12, subc, mthd, data);
		nv_wr32(priv, 0x104004 + (idx * 0x1000), 0x00000040);
134 135 136 137
		stat &= ~0x00000040;
	}

	if (stat) {
138 139
		nv_error(priv, "unhandled intr 0x%08x\n", stat);
		nv_wr32(priv, 0x104004 + (idx * 0x1000), stat);
140 141 142
	}
}

143 144 145 146
static int
nvc0_copy0_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
		struct nouveau_oclass *oclass, void *data, u32 size,
		struct nouveau_object **pobject)
147
{
148 149
	struct nvc0_copy_priv *priv;
	int ret;
150

151 152 153 154 155 156 157 158 159 160 161 162 163
	if (nv_rd32(parent, 0x022500) & 0x00000100)
		return -ENODEV;

	ret = nouveau_copy_create(parent, engine, oclass, true, 0, &priv);
	*pobject = nv_object(priv);
	if (ret)
		return ret;

	nv_subdev(priv)->unit = 0x00000040;
	nv_subdev(priv)->intr = nvc0_copy_intr;
	nv_engine(priv)->cclass = &nvc0_copy0_cclass;
	nv_engine(priv)->sclass = nvc0_copy0_sclass;
	return 0;
164 165
}

166 167 168 169
static int
nvc0_copy1_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
		struct nouveau_oclass *oclass, void *data, u32 size,
		struct nouveau_object **pobject)
170
{
171 172
	struct nvc0_copy_priv *priv;
	int ret;
173

174 175
	if (nv_rd32(parent, 0x022500) & 0x00000200)
		return -ENODEV;
176

177 178 179 180 181 182 183 184 185 186
	ret = nouveau_copy_create(parent, engine, oclass, true, 1, &priv);
	*pobject = nv_object(priv);
	if (ret)
		return ret;

	nv_subdev(priv)->unit = 0x00000080;
	nv_subdev(priv)->intr = nvc0_copy_intr;
	nv_engine(priv)->cclass = &nvc0_copy1_cclass;
	nv_engine(priv)->sclass = nvc0_copy1_sclass;
	return 0;
187 188
}

189 190
static int
nvc0_copy_init(struct nouveau_object *object)
191
{
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
	int idx = nv_engidx(object) - NVDEV_ENGINE_COPY0;
	struct nvc0_copy_priv *priv = (void *)object;
	int ret, i;

	ret = nouveau_copy_init(&priv->base);
	if (ret)
		return ret;

	/* disable all interrupts */
	nv_wr32(priv, 0x104014 + (idx * 0x1000), 0xffffffff);

	/* upload ucode */
	nv_wr32(priv, 0x1041c0 + (idx * 0x1000), 0x01000000);
	for (i = 0; i < sizeof(nvc0_pcopy_data) / 4; i++)
		nv_wr32(priv, 0x1041c4 + (idx * 0x1000), nvc0_pcopy_data[i]);

	nv_wr32(priv, 0x104180 + (idx * 0x1000), 0x01000000);
	for (i = 0; i < sizeof(nvc0_pcopy_code) / 4; i++) {
		if ((i & 0x3f) == 0)
			nv_wr32(priv, 0x104188 + (idx * 0x1000), i >> 6);
		nv_wr32(priv, 0x104184 + (idx * 0x1000), nvc0_pcopy_code[i]);
213 214
	}

215 216 217 218 219
	/* start it running */
	nv_wr32(priv, 0x104084 + (idx * 0x1000), idx);
	nv_wr32(priv, 0x10410c + (idx * 0x1000), 0x00000000);
	nv_wr32(priv, 0x104104 + (idx * 0x1000), 0x00000000); /* ENTRY */
	nv_wr32(priv, 0x104100 + (idx * 0x1000), 0x00000002); /* TRIGGER */
220 221
	return 0;
}
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255

static int
nvc0_copy_fini(struct nouveau_object *object, bool suspend)
{
	int idx = nv_engidx(object) - NVDEV_ENGINE_COPY0;
	struct nvc0_copy_priv *priv = (void *)object;

	nv_mask(priv, 0x104048 + (idx * 0x1000), 0x00000003, 0x00000000);
	nv_wr32(priv, 0x104014 + (idx * 0x1000), 0xffffffff);

	return nouveau_copy_fini(&priv->base, suspend);
}

struct nouveau_oclass
nvc0_copy0_oclass = {
	.handle = NV_ENGINE(COPY0, 0xc0),
	.ofuncs = &(struct nouveau_ofuncs) {
		.ctor = nvc0_copy0_ctor,
		.dtor = _nouveau_copy_dtor,
		.init = nvc0_copy_init,
		.fini = nvc0_copy_fini,
	},
};

struct nouveau_oclass
nvc0_copy1_oclass = {
	.handle = NV_ENGINE(COPY1, 0xc0),
	.ofuncs = &(struct nouveau_ofuncs) {
		.ctor = nvc0_copy1_ctor,
		.dtor = _nouveau_copy_dtor,
		.init = nvc0_copy_init,
		.fini = nvc0_copy_fini,
	},
};