ramgk104.c 46.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright 2013 Red Hat Inc.
 *
 * 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
#define gk104_ram(p) container_of((p), struct gk104_ram, base)
#include "ram.h"
26
#include "ramfuc.h"
27

28
#include <core/option.h>
29 30
#include <subdev/bios.h>
#include <subdev/bios/init.h>
31 32
#include <subdev/bios/M0205.h>
#include <subdev/bios/M0209.h>
33 34 35
#include <subdev/bios/pll.h>
#include <subdev/bios/rammap.h>
#include <subdev/bios/timing.h>
36 37
#include <subdev/clk.h>
#include <subdev/clk/pll.h>
38
#include <subdev/gpio.h>
39

40
struct gk104_ramfuc {
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
	struct ramfuc base;

	struct nvbios_pll refpll;
	struct nvbios_pll mempll;

	struct ramfuc_reg r_gpioMV;
	u32 r_funcMV[2];
	struct ramfuc_reg r_gpio2E;
	u32 r_func2E[2];
	struct ramfuc_reg r_gpiotrig;

	struct ramfuc_reg r_0x132020;
	struct ramfuc_reg r_0x132028;
	struct ramfuc_reg r_0x132024;
	struct ramfuc_reg r_0x132030;
	struct ramfuc_reg r_0x132034;
	struct ramfuc_reg r_0x132000;
	struct ramfuc_reg r_0x132004;
	struct ramfuc_reg r_0x132040;

	struct ramfuc_reg r_0x10f248;
	struct ramfuc_reg r_0x10f290;
	struct ramfuc_reg r_0x10f294;
	struct ramfuc_reg r_0x10f298;
	struct ramfuc_reg r_0x10f29c;
	struct ramfuc_reg r_0x10f2a0;
	struct ramfuc_reg r_0x10f2a4;
	struct ramfuc_reg r_0x10f2a8;
	struct ramfuc_reg r_0x10f2ac;
	struct ramfuc_reg r_0x10f2cc;
	struct ramfuc_reg r_0x10f2e8;
	struct ramfuc_reg r_0x10f250;
	struct ramfuc_reg r_0x10f24c;
	struct ramfuc_reg r_0x10fec4;
	struct ramfuc_reg r_0x10fec8;
	struct ramfuc_reg r_0x10f604;
	struct ramfuc_reg r_0x10f614;
	struct ramfuc_reg r_0x10f610;
	struct ramfuc_reg r_0x100770;
	struct ramfuc_reg r_0x100778;
	struct ramfuc_reg r_0x10f224;

	struct ramfuc_reg r_0x10f870;
	struct ramfuc_reg r_0x10f698;
	struct ramfuc_reg r_0x10f694;
	struct ramfuc_reg r_0x10f6b8;
	struct ramfuc_reg r_0x10f808;
	struct ramfuc_reg r_0x10f670;
	struct ramfuc_reg r_0x10f60c;
	struct ramfuc_reg r_0x10f830;
	struct ramfuc_reg r_0x1373ec;
	struct ramfuc_reg r_0x10f800;
	struct ramfuc_reg r_0x10f82c;

	struct ramfuc_reg r_0x10f978;
	struct ramfuc_reg r_0x10f910;
	struct ramfuc_reg r_0x10f914;

	struct ramfuc_reg r_mr[16]; /* MR0 - MR8, MR15 */

	struct ramfuc_reg r_0x62c000;
102

103
	struct ramfuc_reg r_0x10f200;
104

105 106 107 108 109 110 111 112 113 114 115 116 117
	struct ramfuc_reg r_0x10f210;
	struct ramfuc_reg r_0x10f310;
	struct ramfuc_reg r_0x10f314;
	struct ramfuc_reg r_0x10f318;
	struct ramfuc_reg r_0x10f090;
	struct ramfuc_reg r_0x10f69c;
	struct ramfuc_reg r_0x10f824;
	struct ramfuc_reg r_0x1373f0;
	struct ramfuc_reg r_0x1373f4;
	struct ramfuc_reg r_0x137320;
	struct ramfuc_reg r_0x10f65c;
	struct ramfuc_reg r_0x10f6bc;
	struct ramfuc_reg r_0x100710;
B
Ben Skeggs 已提交
118
	struct ramfuc_reg r_0x100750;
119 120
};

121 122 123
struct gk104_ram {
	struct nvkm_ram base;
	struct gk104_ramfuc fuc;
124

125
	struct list_head cfg;
126 127 128 129
	u32 parts;
	u32 pmask;
	u32 pnuts;

130
	struct nvbios_ramcfg diff;
131 132 133 134 135 136 137 138 139 140
	int from;
	int mode;
	int N1, fN1, M1, P1;
	int N2, M2, P2;
};

/*******************************************************************************
 * GDDR5
 ******************************************************************************/
static void
141
gk104_ram_train(struct gk104_ramfuc *fuc, u32 mask, u32 data)
142
{
143
	struct gk104_ram *ram = container_of(fuc, typeof(*ram), fuc);
144
	u32 addr = 0x110974, i;
145

146 147
	ram_mask(fuc, 0x10f910, mask, data);
	ram_mask(fuc, 0x10f914, mask, data);
148

149
	for (i = 0; (data & 0x80000000) && i < ram->parts; addr += 0x1000, i++) {
150
		if (ram->pmask & (1 << i))
151
			continue;
152 153 154 155 156
		ram_wait(fuc, addr, 0x0000000f, 0x00000000, 500000);
	}
}

static void
157
r1373f4_init(struct gk104_ramfuc *fuc)
158
{
159
	struct gk104_ram *ram = container_of(fuc, typeof(*ram), fuc);
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
	const u32 mcoef = ((--ram->P2 << 28) | (ram->N2 << 8) | ram->M2);
	const u32 rcoef = ((  ram->P1 << 16) | (ram->N1 << 8) | ram->M1);
	const u32 runk0 = ram->fN1 << 16;
	const u32 runk1 = ram->fN1;

	if (ram->from == 2) {
		ram_mask(fuc, 0x1373f4, 0x00000000, 0x00001100);
		ram_mask(fuc, 0x1373f4, 0x00000000, 0x00000010);
	} else {
		ram_mask(fuc, 0x1373f4, 0x00000000, 0x00010010);
	}

	ram_mask(fuc, 0x1373f4, 0x00000003, 0x00000000);
	ram_mask(fuc, 0x1373f4, 0x00000010, 0x00000000);

	/* (re)program refpll, if required */
	if ((ram_rd32(fuc, 0x132024) & 0xffffffff) != rcoef ||
	    (ram_rd32(fuc, 0x132034) & 0x0000ffff) != runk1) {
		ram_mask(fuc, 0x132000, 0x00000001, 0x00000000);
		ram_mask(fuc, 0x132020, 0x00000001, 0x00000000);
		ram_wr32(fuc, 0x137320, 0x00000000);
		ram_mask(fuc, 0x132030, 0xffff0000, runk0);
		ram_mask(fuc, 0x132034, 0x0000ffff, runk1);
		ram_wr32(fuc, 0x132024, rcoef);
		ram_mask(fuc, 0x132028, 0x00080000, 0x00080000);
		ram_mask(fuc, 0x132020, 0x00000001, 0x00000001);
		ram_wait(fuc, 0x137390, 0x00020000, 0x00020000, 64000);
		ram_mask(fuc, 0x132028, 0x00080000, 0x00000000);
	}

	/* (re)program mempll, if required */
	if (ram->mode == 2) {
		ram_mask(fuc, 0x1373f4, 0x00010000, 0x00000000);
B
Ben Skeggs 已提交
193
		ram_mask(fuc, 0x132000, 0x80000000, 0x80000000);
194 195 196 197 198 199 200 201 202 203 204 205 206
		ram_mask(fuc, 0x132000, 0x00000001, 0x00000000);
		ram_mask(fuc, 0x132004, 0x103fffff, mcoef);
		ram_mask(fuc, 0x132000, 0x00000001, 0x00000001);
		ram_wait(fuc, 0x137390, 0x00000002, 0x00000002, 64000);
		ram_mask(fuc, 0x1373f4, 0x00000000, 0x00001100);
	} else {
		ram_mask(fuc, 0x1373f4, 0x00000000, 0x00010100);
	}

	ram_mask(fuc, 0x1373f4, 0x00000000, 0x00000010);
}

static void
207
r1373f4_fini(struct gk104_ramfuc *fuc)
208
{
209 210
	struct gk104_ram *ram = container_of(fuc, typeof(*ram), fuc);
	struct nvkm_ram_data *next = ram->base.next;
211 212
	u8 v0 = next->bios.ramcfg_11_03_c0;
	u8 v1 = next->bios.ramcfg_11_03_30;
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
	u32 tmp;

	tmp = ram_rd32(fuc, 0x1373ec) & ~0x00030000;
	ram_wr32(fuc, 0x1373ec, tmp | (v1 << 16));
	ram_mask(fuc, 0x1373f0, (~ram->mode & 3), 0x00000000);
	if (ram->mode == 2) {
		ram_mask(fuc, 0x1373f4, 0x00000003, 0x000000002);
		ram_mask(fuc, 0x1373f4, 0x00001100, 0x000000000);
	} else {
		ram_mask(fuc, 0x1373f4, 0x00000003, 0x000000001);
		ram_mask(fuc, 0x1373f4, 0x00010000, 0x000000000);
	}
	ram_mask(fuc, 0x10f800, 0x00000030, (v0 ^ v1) << 4);
}

228
static void
229 230
gk104_ram_nuts(struct gk104_ram *ram, struct ramfuc_reg *reg,
	       u32 _mask, u32 _data, u32 _copy)
231
{
232
	struct nvkm_fb *fb = ram->base.fb;
233
	struct ramfuc *fuc = &ram->fuc.base;
234
	struct nvkm_device *device = fb->subdev.device;
235
	u32 addr = 0x110000 + (reg->addr & 0xfff);
236 237 238 239 240 241
	u32 mask = _mask | _copy;
	u32 data = (_data & _mask) | (reg->data & _copy);
	u32 i;

	for (i = 0; i < 16; i++, addr += 0x1000) {
		if (ram->pnuts & (1 << i)) {
242
			u32 prev = nvkm_rd32(device, addr);
243
			u32 next = (prev & ~mask) | data;
244
			nvkm_memx_wr32(fuc->memx, addr, next);
245 246 247 248
		}
	}
}
#define ram_nuts(s,r,m,d,c)                                                    \
249
	gk104_ram_nuts((s), &(s)->fuc.r_##r, (m), (d), (c))
250

251
static int
252
gk104_ram_calc_gddr5(struct gk104_ram *ram, u32 freq)
253
{
254 255
	struct gk104_ramfuc *fuc = &ram->fuc;
	struct nvkm_ram_data *next = ram->base.next;
256 257
	int vc = !next->bios.ramcfg_11_02_08;
	int mv = !next->bios.ramcfg_11_02_04;
258
	u32 mask, data;
259 260

	ram_mask(fuc, 0x10f808, 0x40000000, 0x40000000);
261
	ram_block(fuc);
262 263 264
	ram_wr32(fuc, 0x62c000, 0x0f0f0000);

	/* MR1: turn termination on early, for some reason.. */
265
	if ((ram->base.mr[1] & 0x03c) != 0x030) {
266
		ram_mask(fuc, mr[1], 0x03c, ram->base.mr[1] & 0x03c);
267 268
		ram_nuts(ram, mr[1], 0x03c, ram->base.mr1_nuts & 0x03c, 0x000);
	}
269 270 271 272 273 274 275 276 277 278 279

	if (vc == 1 && ram_have(fuc, gpio2E)) {
		u32 temp  = ram_mask(fuc, gpio2E, 0x3000, fuc->r_func2E[1]);
		if (temp != ram_rd32(fuc, gpio2E)) {
			ram_wr32(fuc, gpiotrig, 1);
			ram_nsec(fuc, 20000);
		}
	}

	ram_mask(fuc, 0x10f200, 0x00000800, 0x00000000);

280
	gk104_ram_train(fuc, 0x01020000, 0x000c0000);
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308

	ram_wr32(fuc, 0x10f210, 0x00000000); /* REFRESH_AUTO = 0 */
	ram_nsec(fuc, 1000);
	ram_wr32(fuc, 0x10f310, 0x00000001); /* REFRESH */
	ram_nsec(fuc, 1000);

	ram_mask(fuc, 0x10f200, 0x80000000, 0x80000000);
	ram_wr32(fuc, 0x10f314, 0x00000001); /* PRECHARGE */
	ram_mask(fuc, 0x10f200, 0x80000000, 0x00000000);
	ram_wr32(fuc, 0x10f090, 0x00000061);
	ram_wr32(fuc, 0x10f090, 0xc000007f);
	ram_nsec(fuc, 1000);

	ram_wr32(fuc, 0x10f698, 0x00000000);
	ram_wr32(fuc, 0x10f69c, 0x00000000);

	/*XXX: there does appear to be some kind of condition here, simply
	 *     modifying these bits in the vbios from the default pl0
	 *     entries shows no change.  however, the data does appear to
	 *     be correct and may be required for the transition back
	 */
	mask = 0x800f07e0;
	data = 0x00030000;
	if (ram_rd32(fuc, 0x10f978) & 0x00800000)
		data |= 0x00040000;

	if (1) {
		data |= 0x800807e0;
309 310 311 312 313
		switch (next->bios.ramcfg_11_03_c0) {
		case 3: data &= ~0x00000040; break;
		case 2: data &= ~0x00000100; break;
		case 1: data &= ~0x80000000; break;
		case 0: data &= ~0x00000400; break;
314 315
		}

316 317 318 319 320
		switch (next->bios.ramcfg_11_03_30) {
		case 3: data &= ~0x00000020; break;
		case 2: data &= ~0x00000080; break;
		case 1: data &= ~0x00080000; break;
		case 0: data &= ~0x00000200; break;
321 322 323
		}
	}

324
	if (next->bios.ramcfg_11_02_80)
325
		mask |= 0x03000000;
326
	if (next->bios.ramcfg_11_02_40)
327
		mask |= 0x00002000;
328
	if (next->bios.ramcfg_11_07_10)
329
		mask |= 0x00004000;
330
	if (next->bios.ramcfg_11_07_08)
331 332 333 334 335 336 337 338 339 340 341 342
		mask |= 0x00000003;
	else {
		mask |= 0x34000000;
		if (ram_rd32(fuc, 0x10f978) & 0x00800000)
			mask |= 0x40000000;
	}
	ram_mask(fuc, 0x10f824, mask, data);

	ram_mask(fuc, 0x132040, 0x00010000, 0x00000000);

	if (ram->from == 2 && ram->mode != 2) {
		ram_mask(fuc, 0x10f808, 0x00080000, 0x00000000);
343
		ram_mask(fuc, 0x10f200, 0x18008000, 0x00008000);
344 345 346 347 348
		ram_mask(fuc, 0x10f800, 0x00000000, 0x00000004);
		ram_mask(fuc, 0x10f830, 0x00008000, 0x01040010);
		ram_mask(fuc, 0x10f830, 0x01000000, 0x00000000);
		r1373f4_init(fuc);
		ram_mask(fuc, 0x1373f0, 0x00000002, 0x00000001);
349
		r1373f4_fini(fuc);
350 351 352 353
		ram_mask(fuc, 0x10f830, 0x00c00000, 0x00240001);
	} else
	if (ram->from != 2 && ram->mode != 2) {
		r1373f4_init(fuc);
354
		r1373f4_fini(fuc);
355 356 357 358 359 360 361 362 363 364
	}

	if (ram_have(fuc, gpioMV)) {
		u32 temp  = ram_mask(fuc, gpioMV, 0x3000, fuc->r_funcMV[mv]);
		if (temp != ram_rd32(fuc, gpioMV)) {
			ram_wr32(fuc, gpiotrig, 1);
			ram_nsec(fuc, 64000);
		}
	}

365 366
	if (next->bios.ramcfg_11_02_40 ||
	    next->bios.ramcfg_11_07_10) {
367 368 369 370 371
		ram_mask(fuc, 0x132040, 0x00010000, 0x00010000);
		ram_nsec(fuc, 20000);
	}

	if (ram->from != 2 && ram->mode == 2) {
372 373
		if (0 /*XXX: Titan */)
			ram_mask(fuc, 0x10f200, 0x18000000, 0x18000000);
374 375 376 377
		ram_mask(fuc, 0x10f800, 0x00000004, 0x00000000);
		ram_mask(fuc, 0x1373f0, 0x00000000, 0x00000002);
		ram_mask(fuc, 0x10f830, 0x00800001, 0x00408010);
		r1373f4_init(fuc);
378
		r1373f4_fini(fuc);
379 380 381 382 383 384
		ram_mask(fuc, 0x10f808, 0x00000000, 0x00080000);
		ram_mask(fuc, 0x10f200, 0x00808000, 0x00800000);
	} else
	if (ram->from == 2 && ram->mode == 2) {
		ram_mask(fuc, 0x10f800, 0x00000004, 0x00000000);
		r1373f4_init(fuc);
385
		r1373f4_fini(fuc);
386 387 388
	}

	if (ram->mode != 2) /*XXX*/ {
389
		if (next->bios.ramcfg_11_07_40)
390 391 392
			ram_mask(fuc, 0x10f670, 0x80000000, 0x80000000);
	}

393 394 395
	ram_wr32(fuc, 0x10f65c, 0x00000011 * next->bios.rammap_11_11_0c);
	ram_wr32(fuc, 0x10f6b8, 0x01010101 * next->bios.ramcfg_11_09);
	ram_wr32(fuc, 0x10f6bc, 0x01010101 * next->bios.ramcfg_11_09);
396

B
Ben Skeggs 已提交
397
	if (!next->bios.ramcfg_11_07_08 && !next->bios.ramcfg_11_07_04) {
398 399
		ram_wr32(fuc, 0x10f698, 0x01010101 * next->bios.ramcfg_11_04);
		ram_wr32(fuc, 0x10f69c, 0x01010101 * next->bios.ramcfg_11_04);
B
Ben Skeggs 已提交
400 401 402 403
	} else
	if (!next->bios.ramcfg_11_07_08) {
		ram_wr32(fuc, 0x10f698, 0x00000000);
		ram_wr32(fuc, 0x10f69c, 0x00000000);
404 405 406
	}

	if (ram->mode != 2) {
407 408 409
		u32 data = 0x01000100 * next->bios.ramcfg_11_04;
		ram_nuke(fuc, 0x10f694);
		ram_mask(fuc, 0x10f694, 0xff00ff00, data);
410 411
	}

412
	if (ram->mode == 2 && next->bios.ramcfg_11_08_10)
413 414 415 416 417 418 419
		data = 0x00000080;
	else
		data = 0x00000000;
	ram_mask(fuc, 0x10f60c, 0x00000080, data);

	mask = 0x00070000;
	data = 0x00000000;
420
	if (!next->bios.ramcfg_11_02_80)
421
		data |= 0x03000000;
422
	if (!next->bios.ramcfg_11_02_40)
423
		data |= 0x00002000;
424
	if (!next->bios.ramcfg_11_07_10)
425
		data |= 0x00004000;
426
	if (!next->bios.ramcfg_11_07_08)
427 428 429 430 431
		data |= 0x00000003;
	else
		data |= 0x74000000;
	ram_mask(fuc, 0x10f824, mask, data);

432
	if (next->bios.ramcfg_11_01_08)
433 434 435 436 437 438 439 440 441 442
		data = 0x00000000;
	else
		data = 0x00001000;
	ram_mask(fuc, 0x10f200, 0x00001000, data);

	if (ram_rd32(fuc, 0x10f670) & 0x80000000) {
		ram_nsec(fuc, 10000);
		ram_mask(fuc, 0x10f670, 0x80000000, 0x00000000);
	}

443
	if (next->bios.ramcfg_11_08_01)
444 445 446 447 448 449
		data = 0x00100000;
	else
		data = 0x00000000;
	ram_mask(fuc, 0x10f82c, 0x00100000, data);

	data = 0x00000000;
450
	if (next->bios.ramcfg_11_08_08)
451
		data |= 0x00002000;
452
	if (next->bios.ramcfg_11_08_04)
453
		data |= 0x00001000;
454
	if (next->bios.ramcfg_11_08_02)
455 456 457 458
		data |= 0x00004000;
	ram_mask(fuc, 0x10f830, 0x00007000, data);

	/* PFB timing */
459 460 461 462 463 464 465 466 467 468 469
	ram_mask(fuc, 0x10f248, 0xffffffff, next->bios.timing[10]);
	ram_mask(fuc, 0x10f290, 0xffffffff, next->bios.timing[0]);
	ram_mask(fuc, 0x10f294, 0xffffffff, next->bios.timing[1]);
	ram_mask(fuc, 0x10f298, 0xffffffff, next->bios.timing[2]);
	ram_mask(fuc, 0x10f29c, 0xffffffff, next->bios.timing[3]);
	ram_mask(fuc, 0x10f2a0, 0xffffffff, next->bios.timing[4]);
	ram_mask(fuc, 0x10f2a4, 0xffffffff, next->bios.timing[5]);
	ram_mask(fuc, 0x10f2a8, 0xffffffff, next->bios.timing[6]);
	ram_mask(fuc, 0x10f2ac, 0xffffffff, next->bios.timing[7]);
	ram_mask(fuc, 0x10f2cc, 0xffffffff, next->bios.timing[8]);
	ram_mask(fuc, 0x10f2e8, 0xffffffff, next->bios.timing[9]);
470

471
	data = mask = 0x00000000;
472
	if (ram->diff.ramcfg_11_08_20) {
473 474 475 476 477 478
		if (next->bios.ramcfg_11_08_20)
			data |= 0x01000000;
		mask |= 0x01000000;
	}
	ram_mask(fuc, 0x10f200, mask, data);

479
	data = mask = 0x00000000;
480
	if (ram->diff.ramcfg_11_02_03) {
481
		data |= next->bios.ramcfg_11_02_03 << 8;
482 483
		mask |= 0x00000300;
	}
484
	if (ram->diff.ramcfg_11_01_10) {
485
		if (next->bios.ramcfg_11_01_10)
486
			data |= 0x70000000;
487 488 489
		mask |= 0x70000000;
	}
	ram_mask(fuc, 0x10f604, mask, data);
490

491
	data = mask = 0x00000000;
492
	if (ram->diff.timing_20_30_07) {
493
		data |= next->bios.timing_20_30_07 << 28;
494 495
		mask |= 0x70000000;
	}
496
	if (ram->diff.ramcfg_11_01_01) {
497
		if (next->bios.ramcfg_11_01_01)
498
			data |= 0x00000100;
499 500 501
		mask |= 0x00000100;
	}
	ram_mask(fuc, 0x10f614, mask, data);
502

503
	data = mask = 0x00000000;
504
	if (ram->diff.timing_20_30_07) {
505
		data |= next->bios.timing_20_30_07 << 28;
506 507
		mask |= 0x70000000;
	}
508
	if (ram->diff.ramcfg_11_01_02) {
509
		if (next->bios.ramcfg_11_01_02)
510
			data |= 0x00000100;
511
		mask |= 0x00000100;
512
	}
513
	ram_mask(fuc, 0x10f610, mask, data);
514 515 516

	mask = 0x33f00000;
	data = 0x00000000;
517
	if (!next->bios.ramcfg_11_01_04)
518
		data |= 0x20200000;
519
	if (!next->bios.ramcfg_11_07_80)
520 521 522 523
		data |= 0x12800000;
	/*XXX: see note above about there probably being some condition
	 *     for the 10f824 stuff that uses ramcfg 3...
	 */
524
	if (next->bios.ramcfg_11_03_f0) {
525
		if (next->bios.rammap_11_08_0c) {
526
			if (!next->bios.ramcfg_11_07_80)
527 528 529 530 531 532 533 534 535 536 537 538
				mask |= 0x00000020;
			else
				data |= 0x00000020;
			mask |= 0x00000004;
		}
	} else {
		mask |= 0x40000020;
		data |= 0x00000004;
	}

	ram_mask(fuc, 0x10f808, mask, data);

539
	ram_wr32(fuc, 0x10f870, 0x11111111 * next->bios.ramcfg_11_03_0f);
540

541
	data = mask = 0x00000000;
542
	if (ram->diff.ramcfg_11_02_03) {
543
		data |= next->bios.ramcfg_11_02_03;
544 545
		mask |= 0x00000003;
	}
546
	if (ram->diff.ramcfg_11_01_10) {
547
		if (next->bios.ramcfg_11_01_10)
548 549 550 551 552 553
			data |= 0x00000004;
		mask |= 0x00000004;
	}

	if ((ram_mask(fuc, 0x100770, mask, data) & mask & 4) != (data & 4)) {
		ram_mask(fuc, 0x100750, 0x00000008, 0x00000008);
554 555 556 557
		ram_wr32(fuc, 0x100710, 0x00000000);
		ram_wait(fuc, 0x100710, 0x80000000, 0x80000000, 200000);
	}

558
	data = next->bios.timing_20_30_07 << 8;
559
	if (next->bios.ramcfg_11_01_01)
560 561 562
		data |= 0x80000000;
	ram_mask(fuc, 0x100778, 0x00000700, data);

563
	ram_mask(fuc, 0x10f250, 0x000003f0, next->bios.timing_20_2c_003f << 4);
564 565 566 567
	data = (next->bios.timing[10] & 0x7f000000) >> 24;
	if (data < next->bios.timing_20_2c_1fc0)
		data = next->bios.timing_20_2c_1fc0;
	ram_mask(fuc, 0x10f24c, 0x7f000000, data << 24);
568
	ram_mask(fuc, 0x10f224, 0x001f0000, next->bios.timing_20_30_f8 << 16);
569

570 571 572 573 574 575
	ram_mask(fuc, 0x10fec4, 0x041e0f07, next->bios.timing_20_31_0800 << 26 |
					    next->bios.timing_20_31_0780 << 17 |
					    next->bios.timing_20_31_0078 << 8 |
					    next->bios.timing_20_31_0007);
	ram_mask(fuc, 0x10fec8, 0x00000027, next->bios.timing_20_31_8000 << 5 |
					    next->bios.timing_20_31_7000);
576 577

	ram_wr32(fuc, 0x10f090, 0x4000007e);
578
	ram_nsec(fuc, 2000);
579 580 581 582
	ram_wr32(fuc, 0x10f314, 0x00000001); /* PRECHARGE */
	ram_wr32(fuc, 0x10f310, 0x00000001); /* REFRESH */
	ram_wr32(fuc, 0x10f210, 0x80000000); /* REFRESH_AUTO = 1 */

583
	if (next->bios.ramcfg_11_08_10 && (ram->mode == 2) /*XXX*/) {
584
		u32 temp = ram_mask(fuc, 0x10f294, 0xff000000, 0x24000000);
585
		gk104_ram_train(fuc, 0xbc0e0000, 0xa4010000); /*XXX*/
586 587 588 589 590 591 592 593 594
		ram_nsec(fuc, 1000);
		ram_wr32(fuc, 0x10f294, temp);
	}

	ram_mask(fuc, mr[3], 0xfff, ram->base.mr[3]);
	ram_wr32(fuc, mr[0], ram->base.mr[0]);
	ram_mask(fuc, mr[8], 0xfff, ram->base.mr[8]);
	ram_nsec(fuc, 1000);
	ram_mask(fuc, mr[1], 0xfff, ram->base.mr[1]);
595
	ram_mask(fuc, mr[5], 0xfff, ram->base.mr[5] & ~0x004); /* LP3 later */
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
	ram_mask(fuc, mr[6], 0xfff, ram->base.mr[6]);
	ram_mask(fuc, mr[7], 0xfff, ram->base.mr[7]);

	if (vc == 0 && ram_have(fuc, gpio2E)) {
		u32 temp  = ram_mask(fuc, gpio2E, 0x3000, fuc->r_func2E[0]);
		if (temp != ram_rd32(fuc, gpio2E)) {
			ram_wr32(fuc, gpiotrig, 1);
			ram_nsec(fuc, 20000);
		}
	}

	ram_mask(fuc, 0x10f200, 0x80000000, 0x80000000);
	ram_wr32(fuc, 0x10f318, 0x00000001); /* NOP? */
	ram_mask(fuc, 0x10f200, 0x80000000, 0x00000000);
	ram_nsec(fuc, 1000);
611
	ram_nuts(ram, 0x10f200, 0x18808800, 0x00000000, 0x18808800);
612 613 614 615

	data  = ram_rd32(fuc, 0x10f978);
	data &= ~0x00046144;
	data |=  0x0000000b;
616 617
	if (!next->bios.ramcfg_11_07_08) {
		if (!next->bios.ramcfg_11_07_04)
618 619 620 621 622 623 624 625 626 627 628 629 630
			data |= 0x0000200c;
		else
			data |= 0x00000000;
	} else {
		data |= 0x00040044;
	}
	ram_wr32(fuc, 0x10f978, data);

	if (ram->mode == 1) {
		data = ram_rd32(fuc, 0x10f830) | 0x00000001;
		ram_wr32(fuc, 0x10f830, data);
	}

631
	if (!next->bios.ramcfg_11_07_08) {
632
		data = 0x88020000;
633
		if ( next->bios.ramcfg_11_07_04)
634
			data |= 0x10000000;
635
		if (!next->bios.rammap_11_08_10)
636 637 638 639
			data |= 0x00080000;
	} else {
		data = 0xa40e0000;
	}
640
	gk104_ram_train(fuc, 0xbc0f0000, data);
641 642
	if (1) /* XXX: not always? */
		ram_nsec(fuc, 1000);
643 644 645 646 647

	if (ram->mode == 2) { /*XXX*/
		ram_mask(fuc, 0x10f800, 0x00000004, 0x00000004);
	}

648 649 650
	/* LP3 */
	if (ram_mask(fuc, mr[5], 0x004, ram->base.mr[5]) != ram->base.mr[5])
		ram_nsec(fuc, 1000);
651 652 653 654 655 656

	if (ram->mode != 2) {
		ram_mask(fuc, 0x10f830, 0x01000000, 0x01000000);
		ram_mask(fuc, 0x10f830, 0x01000000, 0x00000000);
	}

657
	if (next->bios.ramcfg_11_07_02)
658
		gk104_ram_train(fuc, 0x80020000, 0x01000000);
659

660
	ram_unblock(fuc);
661 662
	ram_wr32(fuc, 0x62c000, 0x0f0f0f00);

663
	if (next->bios.rammap_11_08_01)
664 665 666 667
		data = 0x00000800;
	else
		data = 0x00000000;
	ram_mask(fuc, 0x10f200, 0x00000800, data);
668
	ram_nuts(ram, 0x10f200, 0x18808800, data, 0x18808800);
669 670 671 672 673 674 675 676
	return 0;
}

/*******************************************************************************
 * DDR3
 ******************************************************************************/

static int
677
gk104_ram_calc_sddr3(struct gk104_ram *ram, u32 freq)
678
{
679
	struct gk104_ramfuc *fuc = &ram->fuc;
680 681 682
	const u32 rcoef = ((  ram->P1 << 16) | (ram->N1 << 8) | ram->M1);
	const u32 runk0 = ram->fN1 << 16;
	const u32 runk1 = ram->fN1;
683
	struct nvkm_ram_data *next = ram->base.next;
684 685
	int vc = !next->bios.ramcfg_11_02_08;
	int mv = !next->bios.ramcfg_11_02_04;
686 687 688
	u32 mask, data;

	ram_mask(fuc, 0x10f808, 0x40000000, 0x40000000);
689
	ram_block(fuc);
690 691 692 693 694 695 696 697 698 699 700
	ram_wr32(fuc, 0x62c000, 0x0f0f0000);

	if (vc == 1 && ram_have(fuc, gpio2E)) {
		u32 temp  = ram_mask(fuc, gpio2E, 0x3000, fuc->r_func2E[1]);
		if (temp != ram_rd32(fuc, gpio2E)) {
			ram_wr32(fuc, gpiotrig, 1);
			ram_nsec(fuc, 20000);
		}
	}

	ram_mask(fuc, 0x10f200, 0x00000800, 0x00000000);
701
	if (next->bios.ramcfg_11_03_f0)
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
		ram_mask(fuc, 0x10f808, 0x04000000, 0x04000000);

	ram_wr32(fuc, 0x10f314, 0x00000001); /* PRECHARGE */
	ram_wr32(fuc, 0x10f210, 0x00000000); /* REFRESH_AUTO = 0 */
	ram_wr32(fuc, 0x10f310, 0x00000001); /* REFRESH */
	ram_mask(fuc, 0x10f200, 0x80000000, 0x80000000);
	ram_wr32(fuc, 0x10f310, 0x00000001); /* REFRESH */
	ram_mask(fuc, 0x10f200, 0x80000000, 0x00000000);
	ram_nsec(fuc, 1000);

	ram_wr32(fuc, 0x10f090, 0x00000060);
	ram_wr32(fuc, 0x10f090, 0xc000007e);

	/*XXX: there does appear to be some kind of condition here, simply
	 *     modifying these bits in the vbios from the default pl0
	 *     entries shows no change.  however, the data does appear to
	 *     be correct and may be required for the transition back
	 */
	mask = 0x00010000;
	data = 0x00010000;

	if (1) {
		mask |= 0x800807e0;
		data |= 0x800807e0;
726 727 728 729 730
		switch (next->bios.ramcfg_11_03_c0) {
		case 3: data &= ~0x00000040; break;
		case 2: data &= ~0x00000100; break;
		case 1: data &= ~0x80000000; break;
		case 0: data &= ~0x00000400; break;
731 732
		}

733 734 735 736 737
		switch (next->bios.ramcfg_11_03_30) {
		case 3: data &= ~0x00000020; break;
		case 2: data &= ~0x00000080; break;
		case 1: data &= ~0x00080000; break;
		case 0: data &= ~0x00000200; break;
738 739 740
		}
	}

741
	if (next->bios.ramcfg_11_02_80)
742
		mask |= 0x03000000;
743
	if (next->bios.ramcfg_11_02_40)
744
		mask |= 0x00002000;
745
	if (next->bios.ramcfg_11_07_10)
746
		mask |= 0x00004000;
747
	if (next->bios.ramcfg_11_07_08)
748 749 750 751 752 753 754 755 756
		mask |= 0x00000003;
	else
		mask |= 0x14000000;
	ram_mask(fuc, 0x10f824, mask, data);

	ram_mask(fuc, 0x132040, 0x00010000, 0x00000000);

	ram_mask(fuc, 0x1373f4, 0x00000000, 0x00010010);
	data  = ram_rd32(fuc, 0x1373ec) & ~0x00030000;
757
	data |= next->bios.ramcfg_11_03_30 << 16;
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
	ram_wr32(fuc, 0x1373ec, data);
	ram_mask(fuc, 0x1373f4, 0x00000003, 0x00000000);
	ram_mask(fuc, 0x1373f4, 0x00000010, 0x00000000);

	/* (re)program refpll, if required */
	if ((ram_rd32(fuc, 0x132024) & 0xffffffff) != rcoef ||
	    (ram_rd32(fuc, 0x132034) & 0x0000ffff) != runk1) {
		ram_mask(fuc, 0x132000, 0x00000001, 0x00000000);
		ram_mask(fuc, 0x132020, 0x00000001, 0x00000000);
		ram_wr32(fuc, 0x137320, 0x00000000);
		ram_mask(fuc, 0x132030, 0xffff0000, runk0);
		ram_mask(fuc, 0x132034, 0x0000ffff, runk1);
		ram_wr32(fuc, 0x132024, rcoef);
		ram_mask(fuc, 0x132028, 0x00080000, 0x00080000);
		ram_mask(fuc, 0x132020, 0x00000001, 0x00000001);
		ram_wait(fuc, 0x137390, 0x00020000, 0x00020000, 64000);
		ram_mask(fuc, 0x132028, 0x00080000, 0x00000000);
	}

	ram_mask(fuc, 0x1373f4, 0x00000010, 0x00000010);
	ram_mask(fuc, 0x1373f4, 0x00000003, 0x00000001);
	ram_mask(fuc, 0x1373f4, 0x00010000, 0x00000000);

	if (ram_have(fuc, gpioMV)) {
		u32 temp  = ram_mask(fuc, gpioMV, 0x3000, fuc->r_funcMV[mv]);
		if (temp != ram_rd32(fuc, gpioMV)) {
			ram_wr32(fuc, gpiotrig, 1);
			ram_nsec(fuc, 64000);
		}
	}

789 790
	if (next->bios.ramcfg_11_02_40 ||
	    next->bios.ramcfg_11_07_10) {
791 792 793 794 795
		ram_mask(fuc, 0x132040, 0x00010000, 0x00010000);
		ram_nsec(fuc, 20000);
	}

	if (ram->mode != 2) /*XXX*/ {
796
		if (next->bios.ramcfg_11_07_40)
797 798 799
			ram_mask(fuc, 0x10f670, 0x80000000, 0x80000000);
	}

800 801 802
	ram_wr32(fuc, 0x10f65c, 0x00000011 * next->bios.rammap_11_11_0c);
	ram_wr32(fuc, 0x10f6b8, 0x01010101 * next->bios.ramcfg_11_09);
	ram_wr32(fuc, 0x10f6bc, 0x01010101 * next->bios.ramcfg_11_09);
803 804 805

	mask = 0x00010000;
	data = 0x00000000;
806
	if (!next->bios.ramcfg_11_02_80)
807
		data |= 0x03000000;
808
	if (!next->bios.ramcfg_11_02_40)
809
		data |= 0x00002000;
810
	if (!next->bios.ramcfg_11_07_10)
811
		data |= 0x00004000;
812
	if (!next->bios.ramcfg_11_07_08)
813 814 815 816 817 818
		data |= 0x00000003;
	else
		data |= 0x14000000;
	ram_mask(fuc, 0x10f824, mask, data);
	ram_nsec(fuc, 1000);

819
	if (next->bios.ramcfg_11_08_01)
820 821 822 823 824 825
		data = 0x00100000;
	else
		data = 0x00000000;
	ram_mask(fuc, 0x10f82c, 0x00100000, data);

	/* PFB timing */
826 827 828 829 830 831 832 833 834 835 836
	ram_mask(fuc, 0x10f248, 0xffffffff, next->bios.timing[10]);
	ram_mask(fuc, 0x10f290, 0xffffffff, next->bios.timing[0]);
	ram_mask(fuc, 0x10f294, 0xffffffff, next->bios.timing[1]);
	ram_mask(fuc, 0x10f298, 0xffffffff, next->bios.timing[2]);
	ram_mask(fuc, 0x10f29c, 0xffffffff, next->bios.timing[3]);
	ram_mask(fuc, 0x10f2a0, 0xffffffff, next->bios.timing[4]);
	ram_mask(fuc, 0x10f2a4, 0xffffffff, next->bios.timing[5]);
	ram_mask(fuc, 0x10f2a8, 0xffffffff, next->bios.timing[6]);
	ram_mask(fuc, 0x10f2ac, 0xffffffff, next->bios.timing[7]);
	ram_mask(fuc, 0x10f2cc, 0xffffffff, next->bios.timing[8]);
	ram_mask(fuc, 0x10f2e8, 0xffffffff, next->bios.timing[9]);
837 838 839

	mask = 0x33f00000;
	data = 0x00000000;
840
	if (!next->bios.ramcfg_11_01_04)
841
		data |= 0x20200000;
842
	if (!next->bios.ramcfg_11_07_80)
843 844 845 846
		data |= 0x12800000;
	/*XXX: see note above about there probably being some condition
	 *     for the 10f824 stuff that uses ramcfg 3...
	 */
847
	if (next->bios.ramcfg_11_03_f0) {
848
		if (next->bios.rammap_11_08_0c) {
849
			if (!next->bios.ramcfg_11_07_80)
850 851 852 853 854 855 856 857 858 859 860 861 862
				mask |= 0x00000020;
			else
				data |= 0x00000020;
			mask |= 0x08000004;
		}
		data |= 0x04000000;
	} else {
		mask |= 0x44000020;
		data |= 0x08000004;
	}

	ram_mask(fuc, 0x10f808, mask, data);

863
	ram_wr32(fuc, 0x10f870, 0x11111111 * next->bios.ramcfg_11_03_0f);
864

865
	ram_mask(fuc, 0x10f250, 0x000003f0, next->bios.timing_20_2c_003f << 4);
866

867
	data = (next->bios.timing[10] & 0x7f000000) >> 24;
868
	if (data < next->bios.timing_20_2c_1fc0)
869
		data = next->bios.timing_20_2c_1fc0;
870 871
	ram_mask(fuc, 0x10f24c, 0x7f000000, data << 24);

872
	ram_mask(fuc, 0x10f224, 0x001f0000, next->bios.timing_20_30_f8 << 16);
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911

	ram_wr32(fuc, 0x10f090, 0x4000007f);
	ram_nsec(fuc, 1000);

	ram_wr32(fuc, 0x10f314, 0x00000001); /* PRECHARGE */
	ram_wr32(fuc, 0x10f310, 0x00000001); /* REFRESH */
	ram_wr32(fuc, 0x10f210, 0x80000000); /* REFRESH_AUTO = 1 */
	ram_nsec(fuc, 1000);

	ram_nuke(fuc, mr[0]);
	ram_mask(fuc, mr[0], 0x100, 0x100);
	ram_mask(fuc, mr[0], 0x100, 0x000);

	ram_mask(fuc, mr[2], 0xfff, ram->base.mr[2]);
	ram_wr32(fuc, mr[0], ram->base.mr[0]);
	ram_nsec(fuc, 1000);

	ram_nuke(fuc, mr[0]);
	ram_mask(fuc, mr[0], 0x100, 0x100);
	ram_mask(fuc, mr[0], 0x100, 0x000);

	if (vc == 0 && ram_have(fuc, gpio2E)) {
		u32 temp  = ram_mask(fuc, gpio2E, 0x3000, fuc->r_func2E[0]);
		if (temp != ram_rd32(fuc, gpio2E)) {
			ram_wr32(fuc, gpiotrig, 1);
			ram_nsec(fuc, 20000);
		}
	}

	if (ram->mode != 2) {
		ram_mask(fuc, 0x10f830, 0x01000000, 0x01000000);
		ram_mask(fuc, 0x10f830, 0x01000000, 0x00000000);
	}

	ram_mask(fuc, 0x10f200, 0x80000000, 0x80000000);
	ram_wr32(fuc, 0x10f318, 0x00000001); /* NOP? */
	ram_mask(fuc, 0x10f200, 0x80000000, 0x00000000);
	ram_nsec(fuc, 1000);

912
	ram_unblock(fuc);
913 914
	ram_wr32(fuc, 0x62c000, 0x0f0f0f00);

915
	if (next->bios.rammap_11_08_01)
916 917 918 919 920 921 922 923 924 925 926 927
		data = 0x00000800;
	else
		data = 0x00000000;
	ram_mask(fuc, 0x10f200, 0x00000800, data);
	return 0;
}

/*******************************************************************************
 * main hooks
 ******************************************************************************/

static int
928
gk104_ram_calc_data(struct gk104_ram *ram, u32 khz, struct nvkm_ram_data *data)
929
{
930
	struct nvkm_subdev *subdev = &ram->base.fb->subdev;
931
	struct nvkm_ram_data *cfg;
932 933 934 935 936 937 938 939
	u32 mhz = khz / 1000;

	list_for_each_entry(cfg, &ram->cfg, head) {
		if (mhz >= cfg->bios.rammap_min &&
		    mhz <= cfg->bios.rammap_max) {
			*data = *cfg;
			data->freq = khz;
			return 0;
940 941 942
		}
	}

943
	nvkm_error(subdev, "ramcfg data for %dMHz not found\n", mhz);
944
	return -EINVAL;
945 946 947
}

static int
948
gk104_ram_calc_xits(struct gk104_ram *ram, struct nvkm_ram_data *next)
949
{
950
	struct gk104_ramfuc *fuc = &ram->fuc;
951
	struct nvkm_subdev *subdev = &ram->base.fb->subdev;
952 953
	int refclk, i;
	int ret;
954

955
	ret = ram_init(fuc, ram->base.fb);
956 957 958
	if (ret)
		return ret;

959
	ram->mode = (next->freq > fuc->refpll.vco1.max_freq) ? 2 : 1;
960 961 962 963 964 965 966 967 968 969
	ram->from = ram_rd32(fuc, 0x1373f4) & 0x0000000f;

	/* XXX: this is *not* what nvidia do.  on fermi nvidia generally
	 * select, based on some unknown condition, one of the two possible
	 * reference frequencies listed in the vbios table for mempll and
	 * program refpll to that frequency.
	 *
	 * so far, i've seen very weird values being chosen by nvidia on
	 * kepler boards, no idea how/why they're chosen.
	 */
970
	refclk = next->freq;
971 972 973 974
	if (ram->mode == 2)
		refclk = fuc->mempll.refclk;

	/* calculate refpll coefficients */
975
	ret = gt215_pll_calc(subdev, &fuc->refpll, refclk, &ram->N1,
976
			     &ram->fN1, &ram->M1, &ram->P1);
977 978
	fuc->mempll.refclk = ret;
	if (ret <= 0) {
979
		nvkm_error(subdev, "unable to calc refpll\n");
980 981 982 983 984 985 986 987 988 989 990 991
		return -EINVAL;
	}

	/* calculate mempll coefficients, if we're using it */
	if (ram->mode == 2) {
		/* post-divider doesn't work... the reg takes the values but
		 * appears to completely ignore it.  there *is* a bit at
		 * bit 28 that appears to divide the clock by 2 if set.
		 */
		fuc->mempll.min_p = 1;
		fuc->mempll.max_p = 2;

992
		ret = gt215_pll_calc(subdev, &fuc->mempll, next->freq,
993
				     &ram->N2, NULL, &ram->M2, &ram->P2);
994
		if (ret <= 0) {
995
			nvkm_error(subdev, "unable to calc mempll\n");
996 997 998 999 1000 1001 1002 1003
			return -EINVAL;
		}
	}

	for (i = 0; i < ARRAY_SIZE(fuc->r_mr); i++) {
		if (ram_have(fuc, mr[i]))
			ram->base.mr[i] = ram_rd32(fuc, mr[i]);
	}
1004
	ram->base.freq = next->freq;
1005 1006

	switch (ram->base.type) {
1007
	case NVKM_RAM_TYPE_DDR3:
1008
		ret = nvkm_sddr3_calc(&ram->base);
1009
		if (ret == 0)
1010
			ret = gk104_ram_calc_sddr3(ram, next->freq);
1011
		break;
1012
	case NVKM_RAM_TYPE_GDDR5:
1013
		ret = nvkm_gddr5_calc(&ram->base, ram->pnuts != 0);
1014
		if (ret == 0)
1015
			ret = gk104_ram_calc_gddr5(ram, next->freq);
1016 1017 1018 1019 1020 1021 1022 1023 1024
		break;
	default:
		ret = -ENOSYS;
		break;
	}

	return ret;
}

1025
static int
1026
gk104_ram_calc(struct nvkm_ram *base, u32 freq)
1027
{
1028 1029
	struct gk104_ram *ram = gk104_ram(base);
	struct nvkm_clk *clk = ram->base.fb->subdev.device->clk;
1030 1031
	struct nvkm_ram_data *xits = &ram->base.xition;
	struct nvkm_ram_data *copy;
1032 1033 1034
	int ret;

	if (ram->base.next == NULL) {
1035
		ret = gk104_ram_calc_data(ram, clk->read(clk, nv_clk_src_mem),
1036
					  &ram->base.former);
1037 1038 1039
		if (ret)
			return ret;

1040
		ret = gk104_ram_calc_data(ram, freq, &ram->base.target);
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
		if (ret)
			return ret;

		if (ram->base.target.freq < ram->base.former.freq) {
			*xits = ram->base.target;
			copy = &ram->base.former;
		} else {
			*xits = ram->base.former;
			copy = &ram->base.target;
		}

		xits->bios.ramcfg_11_02_04 = copy->bios.ramcfg_11_02_04;
		xits->bios.ramcfg_11_02_03 = copy->bios.ramcfg_11_02_03;
		xits->bios.timing_20_30_07 = copy->bios.timing_20_30_07;

		ram->base.next = &ram->base.target;
		if (memcmp(xits, &ram->base.former, sizeof(xits->bios)))
			ram->base.next = &ram->base.xition;
	} else {
		BUG_ON(ram->base.next != &ram->base.xition);
		ram->base.next = &ram->base.target;
	}

1064
	return gk104_ram_calc_xits(ram, ram->base.next);
1065 1066
}

1067
static void
1068
gk104_ram_prog_0(struct gk104_ram *ram, u32 freq)
1069
{
1070
	struct nvkm_device *device = ram->base.fb->subdev.device;
1071
	struct nvkm_ram_data *cfg;
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
	u32 mhz = freq / 1000;
	u32 mask, data;

	list_for_each_entry(cfg, &ram->cfg, head) {
		if (mhz >= cfg->bios.rammap_min &&
		    mhz <= cfg->bios.rammap_max)
			break;
	}

	if (&cfg->head == &ram->cfg)
		return;

	if (mask = 0, data = 0, ram->diff.rammap_11_0a_03fe) {
		data |= cfg->bios.rammap_11_0a_03fe << 12;
		mask |= 0x001ff000;
	}
	if (ram->diff.rammap_11_09_01ff) {
		data |= cfg->bios.rammap_11_09_01ff;
		mask |= 0x000001ff;
	}
1092
	nvkm_mask(device, 0x10f468, mask, data);
1093 1094 1095 1096 1097

	if (mask = 0, data = 0, ram->diff.rammap_11_0a_0400) {
		data |= cfg->bios.rammap_11_0a_0400;
		mask |= 0x00000001;
	}
1098
	nvkm_mask(device, 0x10f420, mask, data);
1099 1100 1101 1102 1103

	if (mask = 0, data = 0, ram->diff.rammap_11_0a_0800) {
		data |= cfg->bios.rammap_11_0a_0800;
		mask |= 0x00000001;
	}
1104
	nvkm_mask(device, 0x10f430, mask, data);
1105 1106 1107 1108 1109

	if (mask = 0, data = 0, ram->diff.rammap_11_0b_01f0) {
		data |= cfg->bios.rammap_11_0b_01f0;
		mask |= 0x0000001f;
	}
1110
	nvkm_mask(device, 0x10f400, mask, data);
1111 1112 1113 1114 1115

	if (mask = 0, data = 0, ram->diff.rammap_11_0b_0200) {
		data |= cfg->bios.rammap_11_0b_0200 << 9;
		mask |= 0x00000200;
	}
1116
	nvkm_mask(device, 0x10f410, mask, data);
1117 1118 1119 1120 1121 1122 1123 1124 1125

	if (mask = 0, data = 0, ram->diff.rammap_11_0d) {
		data |= cfg->bios.rammap_11_0d << 16;
		mask |= 0x00ff0000;
	}
	if (ram->diff.rammap_11_0f) {
		data |= cfg->bios.rammap_11_0f << 8;
		mask |= 0x0000ff00;
	}
1126
	nvkm_mask(device, 0x10f440, mask, data);
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139

	if (mask = 0, data = 0, ram->diff.rammap_11_0e) {
		data |= cfg->bios.rammap_11_0e << 8;
		mask |= 0x0000ff00;
	}
	if (ram->diff.rammap_11_0b_0800) {
		data |= cfg->bios.rammap_11_0b_0800 << 7;
		mask |= 0x00000080;
	}
	if (ram->diff.rammap_11_0b_0400) {
		data |= cfg->bios.rammap_11_0b_0400 << 5;
		mask |= 0x00000020;
	}
1140
	nvkm_mask(device, 0x10f444, mask, data);
1141 1142
}

1143
static int
1144
gk104_ram_prog(struct nvkm_ram *base)
1145
{
1146
	struct gk104_ram *ram = gk104_ram(base);
1147
	struct gk104_ramfuc *fuc = &ram->fuc;
1148
	struct nvkm_device *device = ram->base.fb->subdev.device;
1149
	struct nvkm_ram_data *next = ram->base.next;
1150

1151
	if (!nvkm_boolopt(device->cfgopt, "NvMemExec", true)) {
1152 1153 1154 1155
		ram_exec(fuc, false);
		return (ram->base.next == &ram->base.xition);
	}

1156
	gk104_ram_prog_0(ram, 1000);
1157
	ram_exec(fuc, true);
1158
	gk104_ram_prog_0(ram, next->freq);
1159

1160
	return (ram->base.next == &ram->base.xition);
1161 1162 1163
}

static void
1164
gk104_ram_tidy(struct nvkm_ram *base)
1165
{
1166
	struct gk104_ram *ram = gk104_ram(base);
1167
	ram->base.next = NULL;
1168
	ram_exec(&ram->fuc, false);
1169 1170
}

1171
struct gk104_ram_train {
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
	u16 mask;
	struct nvbios_M0209S remap;
	struct nvbios_M0209S type00;
	struct nvbios_M0209S type01;
	struct nvbios_M0209S type04;
	struct nvbios_M0209S type06;
	struct nvbios_M0209S type07;
	struct nvbios_M0209S type08;
	struct nvbios_M0209S type09;
};

static int
1184
gk104_ram_train_type(struct nvkm_ram *ram, int i, u8 ramcfg,
1185
		     struct gk104_ram_train *train)
1186
{
1187
	struct nvkm_bios *bios = ram->fb->subdev.device->bios;
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
	struct nvbios_M0205E M0205E;
	struct nvbios_M0205S M0205S;
	struct nvbios_M0209E M0209E;
	struct nvbios_M0209S *remap = &train->remap;
	struct nvbios_M0209S *value;
	u8  ver, hdr, cnt, len;
	u32 data;

	/* determine type of data for this index */
	if (!(data = nvbios_M0205Ep(bios, i, &ver, &hdr, &cnt, &len, &M0205E)))
		return -ENOENT;

	switch (M0205E.type) {
	case 0x00: value = &train->type00; break;
	case 0x01: value = &train->type01; break;
	case 0x04: value = &train->type04; break;
	case 0x06: value = &train->type06; break;
	case 0x07: value = &train->type07; break;
	case 0x08: value = &train->type08; break;
	case 0x09: value = &train->type09; break;
	default:
		return 0;
	}

	/* training data index determined by ramcfg strap */
	if (!(data = nvbios_M0205Sp(bios, i, ramcfg, &ver, &hdr, &M0205S)))
		return -EINVAL;
	i = M0205S.data;

	/* training data format information */
	if (!(data = nvbios_M0209Ep(bios, i, &ver, &hdr, &cnt, &len, &M0209E)))
		return -EINVAL;

	/* ... and the raw data */
	if (!(data = nvbios_M0209Sp(bios, i, 0, &ver, &hdr, value)))
		return -EINVAL;

	if (M0209E.v02_07 == 2) {
		/* of course! why wouldn't we have a pointer to another entry
		 * in the same table, and use the first one as an array of
		 * remap indices...
		 */
		if (!(data = nvbios_M0209Sp(bios, M0209E.v03, 0, &ver, &hdr,
					    remap)))
			return -EINVAL;

		for (i = 0; i < ARRAY_SIZE(value->data); i++)
			value->data[i] = remap->data[value->data[i]];
	} else
	if (M0209E.v02_07 != 1)
		return -EINVAL;

	train->mask |= 1 << M0205E.type;
	return 0;
}

static int
1245
gk104_ram_train_init_0(struct nvkm_ram *ram, struct gk104_ram_train *train)
1246
{
1247
	struct nvkm_subdev *subdev = &ram->fb->subdev;
1248
	struct nvkm_device *device = subdev->device;
1249 1250 1251
	int i, j;

	if ((train->mask & 0x03d3) != 0x03d3) {
1252
		nvkm_warn(subdev, "missing link training data\n");
1253 1254 1255 1256 1257
		return -EINVAL;
	}

	for (i = 0; i < 0x30; i++) {
		for (j = 0; j < 8; j += 4) {
1258 1259
			nvkm_wr32(device, 0x10f968 + j, 0x00000000 | (i << 8));
			nvkm_wr32(device, 0x10f920 + j, 0x00000000 |
1260 1261
						   train->type08.data[i] << 4 |
						   train->type06.data[i]);
1262 1263
			nvkm_wr32(device, 0x10f918 + j, train->type00.data[i]);
			nvkm_wr32(device, 0x10f920 + j, 0x00000100 |
1264 1265
						   train->type09.data[i] << 4 |
						   train->type07.data[i]);
1266
			nvkm_wr32(device, 0x10f918 + j, train->type01.data[i]);
1267 1268 1269 1270 1271
		}
	}

	for (j = 0; j < 8; j += 4) {
		for (i = 0; i < 0x100; i++) {
1272 1273
			nvkm_wr32(device, 0x10f968 + j, i);
			nvkm_wr32(device, 0x10f900 + j, train->type04.data[i]);
1274 1275 1276 1277 1278 1279 1280
		}
	}

	return 0;
}

static int
1281
gk104_ram_train_init(struct nvkm_ram *ram)
1282
{
1283
	u8 ramcfg = nvbios_ramcfg_index(&ram->fb->subdev);
1284
	struct gk104_ram_train *train;
B
Ben Skeggs 已提交
1285
	int ret, i;
1286

B
Ben Skeggs 已提交
1287 1288 1289 1290
	if (!(train = kzalloc(sizeof(*train), GFP_KERNEL)))
		return -ENOMEM;

	for (i = 0; i < 0x100; i++) {
1291
		ret = gk104_ram_train_type(ram, i, ramcfg, train);
B
Ben Skeggs 已提交
1292 1293
		if (ret && ret != -ENOENT)
			break;
1294 1295
	}

1296 1297 1298
	switch (ram->type) {
	case NVKM_RAM_TYPE_GDDR5:
		ret = gk104_ram_train_init_0(ram, train);
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
		break;
	default:
		ret = 0;
		break;
	}

	kfree(train);
	return ret;
}

1309
int
1310
gk104_ram_init(struct nvkm_ram *ram)
1311
{
1312 1313
	struct nvkm_subdev *subdev = &ram->fb->subdev;
	struct nvkm_device *device = subdev->device;
1314
	struct nvkm_bios *bios = device->bios;
1315 1316
	u8  ver, hdr, cnt, len, snr, ssz;
	u32 data, save;
1317
	int i;
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329

	/* run a bunch of tables from rammap table.  there's actually
	 * individual pointers for each rammap entry too, but, nvidia
	 * seem to just run the last two entries' scripts early on in
	 * their init, and never again.. we'll just run 'em all once
	 * for now.
	 *
	 * i strongly suspect that each script is for a separate mode
	 * (likely selected by 0x10f65c's lower bits?), and the
	 * binary driver skips the one that's already been setup by
	 * the init tables.
	 */
1330
	data = nvbios_rammapTe(bios, &ver, &hdr, &cnt, &len, &snr, &ssz);
1331 1332 1333
	if (!data || hdr < 0x15)
		return -EINVAL;

1334 1335
	cnt  = nvbios_rd08(bios, data + 0x14); /* guess at count */
	data = nvbios_rd32(bios, data + 0x10); /* guess u32... */
1336
	save = nvkm_rd32(device, 0x10f65c) & 0x000000f0;
1337 1338
	for (i = 0; i < cnt; i++, data += 4) {
		if (i != save >> 4) {
1339
			nvkm_mask(device, 0x10f65c, 0x000000f0, i << 4);
1340
			nvbios_exec(&(struct nvbios_init) {
1341
					.subdev = subdev,
1342
					.bios = bios,
1343
					.offset = nvbios_rd32(bios, data),
1344 1345 1346
					.execute = 1,
				    });
		}
1347
	}
1348 1349 1350 1351
	nvkm_mask(device, 0x10f65c, 0x000000f0, save);
	nvkm_mask(device, 0x10f584, 0x11000000, 0x00000000);
	nvkm_wr32(device, 0x10ecc0, 0xffffffff);
	nvkm_mask(device, 0x10f160, 0x00000010, 0x00000010);
1352

1353
	return gk104_ram_train_init(ram);
1354 1355
}

1356
static int
1357
gk104_ram_ctor_data(struct gk104_ram *ram, u8 ramcfg, int i)
1358
{
1359
	struct nvkm_bios *bios = ram->base.fb->subdev.device->bios;
1360
	struct nvkm_ram_data *cfg;
1361 1362
	struct nvbios_ramcfg *d = &ram->diff;
	struct nvbios_ramcfg *p, *n;
1363 1364 1365 1366 1367 1368
	u8  ver, hdr, cnt, len;
	u32 data;
	int ret;

	if (!(cfg = kmalloc(sizeof(*cfg), GFP_KERNEL)))
		return -ENOMEM;
1369 1370
	p = &list_last_entry(&ram->cfg, typeof(*cfg), head)->bios;
	n = &cfg->bios;
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398

	/* memory config data for a range of target frequencies */
	data = nvbios_rammapEp(bios, i, &ver, &hdr, &cnt, &len, &cfg->bios);
	if (ret = -ENOENT, !data)
		goto done;
	if (ret = -ENOSYS, ver != 0x11 || hdr < 0x12)
		goto done;

	/* ... and a portion specific to the attached memory */
	data = nvbios_rammapSp(bios, data, ver, hdr, cnt, len, ramcfg,
			       &ver, &hdr, &cfg->bios);
	if (ret = -EINVAL, !data)
		goto done;
	if (ret = -ENOSYS, ver != 0x11 || hdr < 0x0a)
		goto done;

	/* lookup memory timings, if bios says they're present */
	if (cfg->bios.ramcfg_timing != 0xff) {
		data = nvbios_timingEp(bios, cfg->bios.ramcfg_timing,
				       &ver, &hdr, &cnt, &len,
				       &cfg->bios);
		if (ret = -EINVAL, !data)
			goto done;
		if (ret = -ENOSYS, ver != 0x20 || hdr < 0x33)
			goto done;
	}

	list_add_tail(&cfg->head, &ram->cfg);
1399 1400 1401
	if (ret = 0, i == 0)
		goto done;

1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
	d->rammap_11_0a_03fe |= p->rammap_11_0a_03fe != n->rammap_11_0a_03fe;
	d->rammap_11_09_01ff |= p->rammap_11_09_01ff != n->rammap_11_09_01ff;
	d->rammap_11_0a_0400 |= p->rammap_11_0a_0400 != n->rammap_11_0a_0400;
	d->rammap_11_0a_0800 |= p->rammap_11_0a_0800 != n->rammap_11_0a_0800;
	d->rammap_11_0b_01f0 |= p->rammap_11_0b_01f0 != n->rammap_11_0b_01f0;
	d->rammap_11_0b_0200 |= p->rammap_11_0b_0200 != n->rammap_11_0b_0200;
	d->rammap_11_0d |= p->rammap_11_0d != n->rammap_11_0d;
	d->rammap_11_0f |= p->rammap_11_0f != n->rammap_11_0f;
	d->rammap_11_0e |= p->rammap_11_0e != n->rammap_11_0e;
	d->rammap_11_0b_0800 |= p->rammap_11_0b_0800 != n->rammap_11_0b_0800;
	d->rammap_11_0b_0400 |= p->rammap_11_0b_0400 != n->rammap_11_0b_0400;
1413 1414 1415 1416 1417 1418
	d->ramcfg_11_01_01 |= p->ramcfg_11_01_01 != n->ramcfg_11_01_01;
	d->ramcfg_11_01_02 |= p->ramcfg_11_01_02 != n->ramcfg_11_01_02;
	d->ramcfg_11_01_10 |= p->ramcfg_11_01_10 != n->ramcfg_11_01_10;
	d->ramcfg_11_02_03 |= p->ramcfg_11_02_03 != n->ramcfg_11_02_03;
	d->ramcfg_11_08_20 |= p->ramcfg_11_08_20 != n->ramcfg_11_08_20;
	d->timing_20_30_07 |= p->timing_20_30_07 != n->timing_20_30_07;
1419 1420 1421 1422 1423 1424
done:
	if (ret)
		kfree(cfg);
	return ret;
}

1425 1426
static void *
gk104_ram_dtor(struct nvkm_ram *base)
1427
{
1428
	struct gk104_ram *ram = gk104_ram(base);
1429
	struct nvkm_ram_data *cfg, *tmp;
1430 1431 1432 1433 1434

	list_for_each_entry_safe(cfg, tmp, &ram->cfg, head) {
		kfree(cfg);
	}

1435
	return ram;
1436 1437
}

1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
static const struct nvkm_ram_func
gk104_ram_func = {
	.dtor = gk104_ram_dtor,
	.init = gk104_ram_init,
	.get = gf100_ram_get,
	.put = gf100_ram_put,
	.calc = gk104_ram_calc,
	.prog = gk104_ram_prog,
	.tidy = gk104_ram_tidy,
};

int
gk104_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram)
1451
{
1452 1453
	struct nvkm_subdev *subdev = &fb->subdev;
	struct nvkm_device *device = subdev->device;
1454 1455
	struct nvkm_bios *bios = device->bios;
	struct nvkm_gpio *gpio = device->gpio;
1456
	struct dcb_gpio_func func;
1457
	struct gk104_ram *ram;
1458
	int ret, i;
B
Ben Skeggs 已提交
1459
	u8  ramcfg = nvbios_ramcfg_index(nv_subdev(fb));
1460
	u32 tmp;
1461

1462 1463 1464 1465 1466
	if (!(ram = kzalloc(sizeof(*ram), GFP_KERNEL)))
		return -ENOMEM;
	*pram = &ram->base;

	ret = gf100_ram_ctor(&gk104_ram_func, fb, 0x022554, &ram->base);
1467 1468 1469
	if (ret)
		return ret;

1470 1471
	INIT_LIST_HEAD(&ram->cfg);

1472 1473 1474 1475 1476
	/* calculate a mask of differently configured memory partitions,
	 * because, of course reclocking wasn't complicated enough
	 * already without having to treat some of them differently to
	 * the others....
	 */
1477 1478
	ram->parts = nvkm_rd32(device, 0x022438);
	ram->pmask = nvkm_rd32(device, 0x022554);
1479 1480 1481
	ram->pnuts = 0;
	for (i = 0, tmp = 0; i < ram->parts; i++) {
		if (!(ram->pmask & (1 << i))) {
1482
			u32 cfg1 = nvkm_rd32(device, 0x110204 + (i * 0x1000));
1483 1484 1485 1486 1487 1488 1489 1490
			if (tmp && tmp != cfg1) {
				ram->pnuts |= (1 << i);
				continue;
			}
			tmp = cfg1;
		}
	}

1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
	/* parse bios data for all rammap table entries up-front, and
	 * build information on whether certain fields differ between
	 * any of the entries.
	 *
	 * the binary driver appears to completely ignore some fields
	 * when all entries contain the same value.  at first, it was
	 * hoped that these were mere optimisations and the bios init
	 * tables had configured as per the values here, but there is
	 * evidence now to suggest that this isn't the case and we do
	 * need to treat this condition as a "don't touch" indicator.
	 */
1502
	for (i = 0; !ret; i++) {
1503
		ret = gk104_ram_ctor_data(ram, ramcfg, i);
1504
		if (ret && ret != -ENOENT) {
1505
			nvkm_error(subdev, "failed to parse ramcfg data\n");
1506 1507 1508 1509 1510
			return ret;
		}
	}

	/* parse bios data for both pll's */
1511 1512
	ret = nvbios_pll_parse(bios, 0x0c, &ram->fuc.refpll);
	if (ret) {
1513
		nvkm_error(subdev, "mclk refpll data not found\n");
1514 1515 1516 1517 1518
		return ret;
	}

	ret = nvbios_pll_parse(bios, 0x04, &ram->fuc.mempll);
	if (ret) {
1519
		nvkm_error(subdev, "mclk pll data not found\n");
1520 1521 1522
		return ret;
	}

1523
	/* lookup memory voltage gpios */
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
	ret = gpio->find(gpio, 0, 0x18, DCB_GPIO_UNUSED, &func);
	if (ret == 0) {
		ram->fuc.r_gpioMV = ramfuc_reg(0x00d610 + (func.line * 0x04));
		ram->fuc.r_funcMV[0] = (func.log[0] ^ 2) << 12;
		ram->fuc.r_funcMV[1] = (func.log[1] ^ 2) << 12;
	}

	ret = gpio->find(gpio, 0, 0x2e, DCB_GPIO_UNUSED, &func);
	if (ret == 0) {
		ram->fuc.r_gpio2E = ramfuc_reg(0x00d610 + (func.line * 0x04));
		ram->fuc.r_func2E[0] = (func.log[0] ^ 2) << 12;
		ram->fuc.r_func2E[1] = (func.log[1] ^ 2) << 12;
	}

	ram->fuc.r_gpiotrig = ramfuc_reg(0x00d604);

	ram->fuc.r_0x132020 = ramfuc_reg(0x132020);
	ram->fuc.r_0x132028 = ramfuc_reg(0x132028);
	ram->fuc.r_0x132024 = ramfuc_reg(0x132024);
	ram->fuc.r_0x132030 = ramfuc_reg(0x132030);
	ram->fuc.r_0x132034 = ramfuc_reg(0x132034);
	ram->fuc.r_0x132000 = ramfuc_reg(0x132000);
	ram->fuc.r_0x132004 = ramfuc_reg(0x132004);
	ram->fuc.r_0x132040 = ramfuc_reg(0x132040);

	ram->fuc.r_0x10f248 = ramfuc_reg(0x10f248);
	ram->fuc.r_0x10f290 = ramfuc_reg(0x10f290);
	ram->fuc.r_0x10f294 = ramfuc_reg(0x10f294);
	ram->fuc.r_0x10f298 = ramfuc_reg(0x10f298);
	ram->fuc.r_0x10f29c = ramfuc_reg(0x10f29c);
	ram->fuc.r_0x10f2a0 = ramfuc_reg(0x10f2a0);
	ram->fuc.r_0x10f2a4 = ramfuc_reg(0x10f2a4);
	ram->fuc.r_0x10f2a8 = ramfuc_reg(0x10f2a8);
	ram->fuc.r_0x10f2ac = ramfuc_reg(0x10f2ac);
	ram->fuc.r_0x10f2cc = ramfuc_reg(0x10f2cc);
	ram->fuc.r_0x10f2e8 = ramfuc_reg(0x10f2e8);
	ram->fuc.r_0x10f250 = ramfuc_reg(0x10f250);
	ram->fuc.r_0x10f24c = ramfuc_reg(0x10f24c);
	ram->fuc.r_0x10fec4 = ramfuc_reg(0x10fec4);
	ram->fuc.r_0x10fec8 = ramfuc_reg(0x10fec8);
	ram->fuc.r_0x10f604 = ramfuc_reg(0x10f604);
	ram->fuc.r_0x10f614 = ramfuc_reg(0x10f614);
	ram->fuc.r_0x10f610 = ramfuc_reg(0x10f610);
	ram->fuc.r_0x100770 = ramfuc_reg(0x100770);
	ram->fuc.r_0x100778 = ramfuc_reg(0x100778);
	ram->fuc.r_0x10f224 = ramfuc_reg(0x10f224);

	ram->fuc.r_0x10f870 = ramfuc_reg(0x10f870);
	ram->fuc.r_0x10f698 = ramfuc_reg(0x10f698);
	ram->fuc.r_0x10f694 = ramfuc_reg(0x10f694);
	ram->fuc.r_0x10f6b8 = ramfuc_reg(0x10f6b8);
	ram->fuc.r_0x10f808 = ramfuc_reg(0x10f808);
	ram->fuc.r_0x10f670 = ramfuc_reg(0x10f670);
	ram->fuc.r_0x10f60c = ramfuc_reg(0x10f60c);
	ram->fuc.r_0x10f830 = ramfuc_reg(0x10f830);
	ram->fuc.r_0x1373ec = ramfuc_reg(0x1373ec);
	ram->fuc.r_0x10f800 = ramfuc_reg(0x10f800);
	ram->fuc.r_0x10f82c = ramfuc_reg(0x10f82c);

	ram->fuc.r_0x10f978 = ramfuc_reg(0x10f978);
	ram->fuc.r_0x10f910 = ramfuc_reg(0x10f910);
	ram->fuc.r_0x10f914 = ramfuc_reg(0x10f914);

	switch (ram->base.type) {
1588
	case NVKM_RAM_TYPE_GDDR5:
1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
		ram->fuc.r_mr[0] = ramfuc_reg(0x10f300);
		ram->fuc.r_mr[1] = ramfuc_reg(0x10f330);
		ram->fuc.r_mr[2] = ramfuc_reg(0x10f334);
		ram->fuc.r_mr[3] = ramfuc_reg(0x10f338);
		ram->fuc.r_mr[4] = ramfuc_reg(0x10f33c);
		ram->fuc.r_mr[5] = ramfuc_reg(0x10f340);
		ram->fuc.r_mr[6] = ramfuc_reg(0x10f344);
		ram->fuc.r_mr[7] = ramfuc_reg(0x10f348);
		ram->fuc.r_mr[8] = ramfuc_reg(0x10f354);
		ram->fuc.r_mr[15] = ramfuc_reg(0x10f34c);
		break;
1600
	case NVKM_RAM_TYPE_DDR3:
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
		ram->fuc.r_mr[0] = ramfuc_reg(0x10f300);
		ram->fuc.r_mr[2] = ramfuc_reg(0x10f320);
		break;
	default:
		break;
	}

	ram->fuc.r_0x62c000 = ramfuc_reg(0x62c000);
	ram->fuc.r_0x10f200 = ramfuc_reg(0x10f200);
	ram->fuc.r_0x10f210 = ramfuc_reg(0x10f210);
	ram->fuc.r_0x10f310 = ramfuc_reg(0x10f310);
	ram->fuc.r_0x10f314 = ramfuc_reg(0x10f314);
	ram->fuc.r_0x10f318 = ramfuc_reg(0x10f318);
	ram->fuc.r_0x10f090 = ramfuc_reg(0x10f090);
	ram->fuc.r_0x10f69c = ramfuc_reg(0x10f69c);
	ram->fuc.r_0x10f824 = ramfuc_reg(0x10f824);
	ram->fuc.r_0x1373f0 = ramfuc_reg(0x1373f0);
	ram->fuc.r_0x1373f4 = ramfuc_reg(0x1373f4);
	ram->fuc.r_0x137320 = ramfuc_reg(0x137320);
	ram->fuc.r_0x10f65c = ramfuc_reg(0x10f65c);
	ram->fuc.r_0x10f6bc = ramfuc_reg(0x10f6bc);
	ram->fuc.r_0x100710 = ramfuc_reg(0x100710);
B
Ben Skeggs 已提交
1623
	ram->fuc.r_0x100750 = ramfuc_reg(0x100750);
1624 1625
	return 0;
}