gk20a.c 8.6 KB
Newer Older
1
/*
2
 * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * 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 AUTHORS OR COPYRIGHT HOLDERS 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.
 */
22
#include "gf100.h"
23
#include "ctxgf100.h"
24

25
#include <subdev/fb.h>
26
#include <subdev/timer.h>
27

28
#include <nvif/class.h>
29

30 31 32 33 34 35
struct gk20a_fw_av
{
	u32 addr;
	u32 data;
};

36
int
37 38
gk20a_gr_av_to_init(struct gf100_gr *gr, const char *fw_name,
		    struct gf100_gr_pack **ppack)
39
{
40
	struct gf100_gr_fuc fuc;
41 42
	struct gf100_gr_init *init;
	struct gf100_gr_pack *pack;
43 44
	int nent;
	int ret;
45 46
	int i;

47 48 49 50 51
	ret = gf100_gr_ctor_fw(gr, fw_name, &fuc);
	if (ret)
		return ret;

	nent = (fuc.size / sizeof(struct gk20a_fw_av));
52
	pack = vzalloc((sizeof(*pack) * 2) + (sizeof(*init) * (nent + 1)));
53 54 55 56
	if (!pack) {
		ret = -ENOMEM;
		goto end;
	}
57 58 59 60 61 62

	init = (void *)(pack + 2);
	pack[0].init = init;

	for (i = 0; i < nent; i++) {
		struct gf100_gr_init *ent = &init[i];
63
		struct gk20a_fw_av *av = &((struct gk20a_fw_av *)fuc.data)[i];
64 65 66 67 68 69 70

		ent->addr = av->addr;
		ent->data = av->data;
		ent->count = 1;
		ent->pitch = 1;
	}

71 72 73 74 75
	*ppack = pack;

end:
	gf100_gr_dtor_fw(&fuc);
	return ret;
76 77 78 79 80 81 82 83 84
}

struct gk20a_fw_aiv
{
	u32 addr;
	u32 index;
	u32 data;
};

85
int
86 87
gk20a_gr_aiv_to_init(struct gf100_gr *gr, const char *fw_name,
		     struct gf100_gr_pack **ppack)
88
{
89
	struct gf100_gr_fuc fuc;
90 91
	struct gf100_gr_init *init;
	struct gf100_gr_pack *pack;
92 93
	int nent;
	int ret;
94 95
	int i;

96 97 98 99 100
	ret = gf100_gr_ctor_fw(gr, fw_name, &fuc);
	if (ret)
		return ret;

	nent = (fuc.size / sizeof(struct gk20a_fw_aiv));
101
	pack = vzalloc((sizeof(*pack) * 2) + (sizeof(*init) * (nent + 1)));
102 103 104 105
	if (!pack) {
		ret = -ENOMEM;
		goto end;
	}
106 107 108 109 110 111

	init = (void *)(pack + 2);
	pack[0].init = init;

	for (i = 0; i < nent; i++) {
		struct gf100_gr_init *ent = &init[i];
112
		struct gk20a_fw_aiv *av = &((struct gk20a_fw_aiv *)fuc.data)[i];
113 114 115 116 117 118 119

		ent->addr = av->addr;
		ent->data = av->data;
		ent->count = 1;
		ent->pitch = 1;
	}

120 121 122 123 124
	*ppack = pack;

end:
	gf100_gr_dtor_fw(&fuc);
	return ret;
125 126
}

127
int
128 129
gk20a_gr_av_to_method(struct gf100_gr *gr, const char *fw_name,
		      struct gf100_gr_pack **ppack)
130
{
131
	struct gf100_gr_fuc fuc;
132 133 134 135
	struct gf100_gr_init *init;
	struct gf100_gr_pack *pack;
	/* We don't suppose we will initialize more than 16 classes here... */
	static const unsigned int max_classes = 16;
136 137 138 139 140 141 142 143 144 145
	u32 classidx = 0, prevclass = 0;
	int nent;
	int ret;
	int i;

	ret = gf100_gr_ctor_fw(gr, fw_name, &fuc);
	if (ret)
		return ret;

	nent = (fuc.size / sizeof(struct gk20a_fw_av));
146 147 148

	pack = vzalloc((sizeof(*pack) * max_classes) +
		       (sizeof(*init) * (nent + 1)));
149 150 151 152
	if (!pack) {
		ret = -ENOMEM;
		goto end;
	}
153 154 155 156 157

	init = (void *)(pack + max_classes);

	for (i = 0; i < nent; i++) {
		struct gf100_gr_init *ent = &init[i];
158
		struct gk20a_fw_av *av = &((struct gk20a_fw_av *)fuc.data)[i];
159 160 161 162 163 164 165 166 167
		u32 class = av->addr & 0xffff;
		u32 addr = (av->addr & 0xffff0000) >> 14;

		if (prevclass != class) {
			pack[classidx].init = ent;
			pack[classidx].type = class;
			prevclass = class;
			if (++classidx >= max_classes) {
				vfree(pack);
168 169
				ret = -ENOSPC;
				goto end;
170 171 172 173 174 175 176 177 178
			}
		}

		ent->addr = addr;
		ent->data = av->data;
		ent->count = 1;
		ent->pitch = 1;
	}

179 180 181 182 183
	*ppack = pack;

end:
	gf100_gr_dtor_fw(&fuc);
	return ret;
184 185 186
}

static int
B
Ben Skeggs 已提交
187
gk20a_gr_wait_mem_scrubbing(struct gf100_gr *gr)
188
{
189 190
	struct nvkm_subdev *subdev = &gr->base.engine.subdev;
	struct nvkm_device *device = subdev->device;
191 192 193 194 195

	if (nvkm_msec(device, 2000,
		if (!(nvkm_rd32(device, 0x40910c) & 0x00000006))
			break;
	) < 0) {
196
		nvkm_error(subdev, "FECS mem scrubbing timeout\n");
197 198 199
		return -ETIMEDOUT;
	}

200 201 202 203
	if (nvkm_msec(device, 2000,
		if (!(nvkm_rd32(device, 0x41a10c) & 0x00000006))
			break;
	) < 0) {
204
		nvkm_error(subdev, "GPCCS mem scrubbing timeout\n");
205 206 207 208 209 210 211
		return -ETIMEDOUT;
	}

	return 0;
}

static void
B
Ben Skeggs 已提交
212
gk20a_gr_set_hww_esr_report_mask(struct gf100_gr *gr)
213
{
214 215 216
	struct nvkm_device *device = gr->base.engine.subdev.device;
	nvkm_wr32(device, 0x419e44, 0x1ffffe);
	nvkm_wr32(device, 0x419e4c, 0x7f);
217 218
}

219
int
220
gk20a_gr_init(struct gf100_gr *gr)
221
{
222
	struct nvkm_device *device = gr->base.engine.subdev.device;
223
	struct nvkm_fb *fb = device->fb;
B
Ben Skeggs 已提交
224
	const u32 magicgpc918 = DIV_ROUND_UP(0x00800000, gr->tpc_total);
225 226 227 228 229 230
	u32 data[TPC_MAX / 8] = {};
	u8  tpcnr[GPC_MAX];
	int gpc, tpc;
	int ret, i;

	/* Clear SCC RAM */
231
	nvkm_wr32(device, 0x40802c, 0x1);
232

B
Ben Skeggs 已提交
233
	gf100_gr_mmio(gr, gr->fuc_sw_nonctx);
234

B
Ben Skeggs 已提交
235
	ret = gk20a_gr_wait_mem_scrubbing(gr);
236 237 238
	if (ret)
		return ret;

B
Ben Skeggs 已提交
239
	ret = gf100_gr_wait_idle(gr);
240 241 242 243
	if (ret)
		return ret;

	/* MMU debug buffer */
244 245
	nvkm_wr32(device, 0x100cc8, nvkm_memory_addr(fb->mmu_wr) >> 8);
	nvkm_wr32(device, 0x100ccc, nvkm_memory_addr(fb->mmu_rd) >> 8);
246

247 248
	if (gr->func->init_gpc_mmu)
		gr->func->init_gpc_mmu(gr);
249 250

	/* Set the PE as stream master */
251
	nvkm_mask(device, 0x503018, 0x1, 0x1);
252 253 254

	/* Zcull init */
	memset(data, 0x00, sizeof(data));
B
Ben Skeggs 已提交
255 256
	memcpy(tpcnr, gr->tpc_nr, sizeof(gr->tpc_nr));
	for (i = 0, gpc = -1; i < gr->tpc_total; i++) {
257
		do {
B
Ben Skeggs 已提交
258
			gpc = (gpc + 1) % gr->gpc_nr;
259
		} while (!tpcnr[gpc]);
B
Ben Skeggs 已提交
260
		tpc = gr->tpc_nr[gpc] - tpcnr[gpc]--;
261 262 263 264

		data[i / 8] |= tpc << ((i % 8) * 4);
	}

265 266 267 268
	nvkm_wr32(device, GPC_BCAST(0x0980), data[0]);
	nvkm_wr32(device, GPC_BCAST(0x0984), data[1]);
	nvkm_wr32(device, GPC_BCAST(0x0988), data[2]);
	nvkm_wr32(device, GPC_BCAST(0x098c), data[3]);
B
Ben Skeggs 已提交
269 270

	for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
271
		nvkm_wr32(device, GPC_UNIT(gpc, 0x0914),
272
			  gr->screen_tile_row_offset << 8 | gr->tpc_nr[gpc]);
273 274 275
		nvkm_wr32(device, GPC_UNIT(gpc, 0x0910), 0x00040000 |
			  gr->tpc_total);
		nvkm_wr32(device, GPC_UNIT(gpc, 0x0918), magicgpc918);
276 277
	}

278
	nvkm_wr32(device, GPC_BCAST(0x3fd4), magicgpc918);
279 280

	/* Enable FIFO access */
281
	nvkm_wr32(device, 0x400500, 0x00010001);
282 283

	/* Enable interrupts */
284 285
	nvkm_wr32(device, 0x400100, 0xffffffff);
	nvkm_wr32(device, 0x40013c, 0xffffffff);
286 287

	/* Enable FECS error interrupts */
288
	nvkm_wr32(device, 0x409c24, 0x000f0000);
289 290

	/* Enable hardware warning exceptions */
291 292
	nvkm_wr32(device, 0x404000, 0xc0000000);
	nvkm_wr32(device, 0x404600, 0xc0000000);
293

294 295
	if (gr->func->set_hww_esr_report_mask)
		gr->func->set_hww_esr_report_mask(gr);
296 297

	/* Enable TPC exceptions per GPC */
298 299
	nvkm_wr32(device, 0x419d0c, 0x2);
	nvkm_wr32(device, 0x41ac94, (((1 << gr->tpc_total) - 1) & 0xff) << 16);
300 301

	/* Reset and enable all exceptions */
302 303 304 305 306 307
	nvkm_wr32(device, 0x400108, 0xffffffff);
	nvkm_wr32(device, 0x400138, 0xffffffff);
	nvkm_wr32(device, 0x400118, 0xffffffff);
	nvkm_wr32(device, 0x400130, 0xffffffff);
	nvkm_wr32(device, 0x40011c, 0xffffffff);
	nvkm_wr32(device, 0x400134, 0xffffffff);
308

B
Ben Skeggs 已提交
309
	gf100_gr_zbc_init(gr);
310

B
Ben Skeggs 已提交
311
	return gf100_gr_init_ctxctl(gr);
312 313
}

314 315 316 317
static const struct gf100_gr_func
gk20a_gr = {
	.init = gk20a_gr_init,
	.set_hww_esr_report_mask = gk20a_gr_set_hww_esr_report_mask,
318
	.rops = gf100_gr_rops,
319 320 321 322 323 324 325 326 327 328 329
	.ppc_nr = 1,
	.grctx = &gk20a_grctx,
	.sclass = {
		{ -1, -1, FERMI_TWOD_A },
		{ -1, -1, KEPLER_INLINE_TO_MEMORY_A },
		{ -1, -1, KEPLER_C, &gf100_fermi },
		{ -1, -1, KEPLER_COMPUTE_A },
		{}
	}
};

330
int
331
gk20a_gr_new(struct nvkm_device *device, int index, struct nvkm_gr **pgr)
332 333 334 335 336 337 338 339
{
	struct gf100_gr *gr;
	int ret;

	if (!(gr = kzalloc(sizeof(*gr), GFP_KERNEL)))
		return -ENOMEM;
	*pgr = &gr->base;

340
	ret = gf100_gr_ctor(&gk20a_gr, device, index, gr);
341 342 343
	if (ret)
		return ret;

344 345 346 347 348 349
	if (gf100_gr_ctor_fw(gr, "fecs_inst", &gr->fuc409c) ||
	    gf100_gr_ctor_fw(gr, "fecs_data", &gr->fuc409d) ||
	    gf100_gr_ctor_fw(gr, "gpccs_inst", &gr->fuc41ac) ||
	    gf100_gr_ctor_fw(gr, "gpccs_data", &gr->fuc41ad))
		return -ENODEV;

350
	ret = gk20a_gr_av_to_init(gr, "sw_nonctx", &gr->fuc_sw_nonctx);
351 352 353
	if (ret)
		return ret;

354
	ret = gk20a_gr_aiv_to_init(gr, "sw_ctx", &gr->fuc_sw_ctx);
355 356 357
	if (ret)
		return ret;

358
	ret = gk20a_gr_av_to_init(gr, "sw_bundle_init", &gr->fuc_bundle);
359 360 361
	if (ret)
		return ret;

362
	ret = gk20a_gr_av_to_method(gr, "sw_method_init", &gr->fuc_method);
363 364
	if (ret)
		return ret;
365

366 367 368

	return 0;
}