gk20a.c 8.5 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/timer.h>
26

27
#include <nvif/class.h>
28

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

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

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

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

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

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

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

70 71 72 73 74
	*ppack = pack;

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

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

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

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

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

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

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

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

119 120 121 122 123
	*ppack = pack;

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

126
int
127 128
gk20a_gr_av_to_method(struct gf100_gr *gr, const char *fw_name,
		      struct gf100_gr_pack **ppack)
129
{
130
	struct gf100_gr_fuc fuc;
131 132 133 134
	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;
135 136 137 138 139 140 141 142 143 144
	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));
145 146 147

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

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

	for (i = 0; i < nent; i++) {
		struct gf100_gr_init *ent = &init[i];
157
		struct gk20a_fw_av *av = &((struct gk20a_fw_av *)fuc.data)[i];
158 159 160 161 162 163 164 165 166
		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);
167 168
				ret = -ENOSPC;
				goto end;
169 170 171 172 173 174 175 176 177
			}
		}

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

178 179 180 181 182
	*ppack = pack;

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

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

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

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

	return 0;
}

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

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

	/* Clear SCC RAM */
229
	nvkm_wr32(device, 0x40802c, 0x1);
230

B
Ben Skeggs 已提交
231
	gf100_gr_mmio(gr, gr->fuc_sw_nonctx);
232

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

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

	/* MMU debug buffer */
242 243
	nvkm_wr32(device, 0x100cc8, nvkm_memory_addr(gr->unk4188b4) >> 8);
	nvkm_wr32(device, 0x100ccc, nvkm_memory_addr(gr->unk4188b8) >> 8);
244

245 246
	if (gr->func->init_gpc_mmu)
		gr->func->init_gpc_mmu(gr);
247 248

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

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

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

263 264 265 266
	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 已提交
267 268

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

276
	nvkm_wr32(device, GPC_BCAST(0x3fd4), magicgpc918);
277 278

	/* Enable FIFO access */
279
	nvkm_wr32(device, 0x400500, 0x00010001);
280 281

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

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

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

292 293
	if (gr->func->set_hww_esr_report_mask)
		gr->func->set_hww_esr_report_mask(gr);
294 295

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

	/* Reset and enable all exceptions */
300 301 302 303 304 305
	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);
306

B
Ben Skeggs 已提交
307
	gf100_gr_zbc_init(gr);
308

B
Ben Skeggs 已提交
309
	return gf100_gr_init_ctxctl(gr);
310 311
}

312 313 314 315
static const struct gf100_gr_func
gk20a_gr = {
	.init = gk20a_gr_init,
	.set_hww_esr_report_mask = gk20a_gr_set_hww_esr_report_mask,
316
	.rops = gf100_gr_rops,
317 318 319 320 321 322 323 324 325 326 327
	.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 },
		{}
	}
};

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

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

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

342 343 344 345 346 347
	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;

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

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

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

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

364 365 366

	return 0;
}