2 * Copyright 2013 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <subdev/gpio.h>
27 #include <subdev/bios.h>
28 #include <subdev/bios/pll.h>
29 #include <subdev/bios/init.h>
30 #include <subdev/bios/rammap.h>
31 #include <subdev/bios/timing.h>
32 #include <subdev/bios/M0205.h>
33 #include <subdev/bios/M0209.h>
35 #include <subdev/clock.h>
36 #include <subdev/clock/pll.h>
38 #include <subdev/timer.h>
40 #include <core/option.h>
49 struct nvbios_pll refpll;
50 struct nvbios_pll mempll;
52 struct ramfuc_reg r_gpioMV;
54 struct ramfuc_reg r_gpio2E;
56 struct ramfuc_reg r_gpiotrig;
58 struct ramfuc_reg r_0x132020;
59 struct ramfuc_reg r_0x132028;
60 struct ramfuc_reg r_0x132024;
61 struct ramfuc_reg r_0x132030;
62 struct ramfuc_reg r_0x132034;
63 struct ramfuc_reg r_0x132000;
64 struct ramfuc_reg r_0x132004;
65 struct ramfuc_reg r_0x132040;
67 struct ramfuc_reg r_0x10f248;
68 struct ramfuc_reg r_0x10f290;
69 struct ramfuc_reg r_0x10f294;
70 struct ramfuc_reg r_0x10f298;
71 struct ramfuc_reg r_0x10f29c;
72 struct ramfuc_reg r_0x10f2a0;
73 struct ramfuc_reg r_0x10f2a4;
74 struct ramfuc_reg r_0x10f2a8;
75 struct ramfuc_reg r_0x10f2ac;
76 struct ramfuc_reg r_0x10f2cc;
77 struct ramfuc_reg r_0x10f2e8;
78 struct ramfuc_reg r_0x10f250;
79 struct ramfuc_reg r_0x10f24c;
80 struct ramfuc_reg r_0x10fec4;
81 struct ramfuc_reg r_0x10fec8;
82 struct ramfuc_reg r_0x10f604;
83 struct ramfuc_reg r_0x10f614;
84 struct ramfuc_reg r_0x10f610;
85 struct ramfuc_reg r_0x100770;
86 struct ramfuc_reg r_0x100778;
87 struct ramfuc_reg r_0x10f224;
89 struct ramfuc_reg r_0x10f870;
90 struct ramfuc_reg r_0x10f698;
91 struct ramfuc_reg r_0x10f694;
92 struct ramfuc_reg r_0x10f6b8;
93 struct ramfuc_reg r_0x10f808;
94 struct ramfuc_reg r_0x10f670;
95 struct ramfuc_reg r_0x10f60c;
96 struct ramfuc_reg r_0x10f830;
97 struct ramfuc_reg r_0x1373ec;
98 struct ramfuc_reg r_0x10f800;
99 struct ramfuc_reg r_0x10f82c;
101 struct ramfuc_reg r_0x10f978;
102 struct ramfuc_reg r_0x10f910;
103 struct ramfuc_reg r_0x10f914;
105 struct ramfuc_reg r_mr[16]; /* MR0 - MR8, MR15 */
107 struct ramfuc_reg r_0x62c000;
109 struct ramfuc_reg r_0x10f200;
111 struct ramfuc_reg r_0x10f210;
112 struct ramfuc_reg r_0x10f310;
113 struct ramfuc_reg r_0x10f314;
114 struct ramfuc_reg r_0x10f318;
115 struct ramfuc_reg r_0x10f090;
116 struct ramfuc_reg r_0x10f69c;
117 struct ramfuc_reg r_0x10f824;
118 struct ramfuc_reg r_0x1373f0;
119 struct ramfuc_reg r_0x1373f4;
120 struct ramfuc_reg r_0x137320;
121 struct ramfuc_reg r_0x10f65c;
122 struct ramfuc_reg r_0x10f6bc;
123 struct ramfuc_reg r_0x100710;
124 struct ramfuc_reg r_0x100750;
128 struct nouveau_ram base;
129 struct nve0_ramfuc fuc;
131 struct list_head cfg;
136 struct nvbios_ramcfg diff;
143 /*******************************************************************************
145 ******************************************************************************/
147 nve0_ram_train(struct nve0_ramfuc *fuc, u32 mask, u32 data)
149 struct nve0_ram *ram = container_of(fuc, typeof(*ram), fuc);
150 u32 addr = 0x110974, i;
152 ram_mask(fuc, 0x10f910, mask, data);
153 ram_mask(fuc, 0x10f914, mask, data);
155 for (i = 0; (data & 0x80000000) && i < ram->parts; addr += 0x1000, i++) {
156 if (ram->pmask & (1 << i))
158 ram_wait(fuc, addr, 0x0000000f, 0x00000000, 500000);
163 r1373f4_init(struct nve0_ramfuc *fuc)
165 struct nve0_ram *ram = container_of(fuc, typeof(*ram), fuc);
166 const u32 mcoef = ((--ram->P2 << 28) | (ram->N2 << 8) | ram->M2);
167 const u32 rcoef = (( ram->P1 << 16) | (ram->N1 << 8) | ram->M1);
168 const u32 runk0 = ram->fN1 << 16;
169 const u32 runk1 = ram->fN1;
171 if (ram->from == 2) {
172 ram_mask(fuc, 0x1373f4, 0x00000000, 0x00001100);
173 ram_mask(fuc, 0x1373f4, 0x00000000, 0x00000010);
175 ram_mask(fuc, 0x1373f4, 0x00000000, 0x00010010);
178 ram_mask(fuc, 0x1373f4, 0x00000003, 0x00000000);
179 ram_mask(fuc, 0x1373f4, 0x00000010, 0x00000000);
181 /* (re)program refpll, if required */
182 if ((ram_rd32(fuc, 0x132024) & 0xffffffff) != rcoef ||
183 (ram_rd32(fuc, 0x132034) & 0x0000ffff) != runk1) {
184 ram_mask(fuc, 0x132000, 0x00000001, 0x00000000);
185 ram_mask(fuc, 0x132020, 0x00000001, 0x00000000);
186 ram_wr32(fuc, 0x137320, 0x00000000);
187 ram_mask(fuc, 0x132030, 0xffff0000, runk0);
188 ram_mask(fuc, 0x132034, 0x0000ffff, runk1);
189 ram_wr32(fuc, 0x132024, rcoef);
190 ram_mask(fuc, 0x132028, 0x00080000, 0x00080000);
191 ram_mask(fuc, 0x132020, 0x00000001, 0x00000001);
192 ram_wait(fuc, 0x137390, 0x00020000, 0x00020000, 64000);
193 ram_mask(fuc, 0x132028, 0x00080000, 0x00000000);
196 /* (re)program mempll, if required */
197 if (ram->mode == 2) {
198 ram_mask(fuc, 0x1373f4, 0x00010000, 0x00000000);
199 ram_mask(fuc, 0x132000, 0x80000000, 0x80000000);
200 ram_mask(fuc, 0x132000, 0x00000001, 0x00000000);
201 ram_mask(fuc, 0x132004, 0x103fffff, mcoef);
202 ram_mask(fuc, 0x132000, 0x00000001, 0x00000001);
203 ram_wait(fuc, 0x137390, 0x00000002, 0x00000002, 64000);
204 ram_mask(fuc, 0x1373f4, 0x00000000, 0x00001100);
206 ram_mask(fuc, 0x1373f4, 0x00000000, 0x00010100);
209 ram_mask(fuc, 0x1373f4, 0x00000000, 0x00000010);
213 r1373f4_fini(struct nve0_ramfuc *fuc)
215 struct nve0_ram *ram = container_of(fuc, typeof(*ram), fuc);
216 struct nouveau_ram_data *next = ram->base.next;
217 u8 v0 = next->bios.ramcfg_11_03_c0;
218 u8 v1 = next->bios.ramcfg_11_03_30;
221 tmp = ram_rd32(fuc, 0x1373ec) & ~0x00030000;
222 ram_wr32(fuc, 0x1373ec, tmp | (v1 << 16));
223 ram_mask(fuc, 0x1373f0, (~ram->mode & 3), 0x00000000);
224 if (ram->mode == 2) {
225 ram_mask(fuc, 0x1373f4, 0x00000003, 0x000000002);
226 ram_mask(fuc, 0x1373f4, 0x00001100, 0x000000000);
228 ram_mask(fuc, 0x1373f4, 0x00000003, 0x000000001);
229 ram_mask(fuc, 0x1373f4, 0x00010000, 0x000000000);
231 ram_mask(fuc, 0x10f800, 0x00000030, (v0 ^ v1) << 4);
235 nve0_ram_nuts(struct nve0_ram *ram, struct ramfuc_reg *reg,
236 u32 _mask, u32 _data, u32 _copy)
238 struct nve0_fb_priv *priv = (void *)nouveau_fb(ram);
239 struct ramfuc *fuc = &ram->fuc.base;
240 u32 addr = 0x110000 + (reg->addr[0] & 0xfff);
241 u32 mask = _mask | _copy;
242 u32 data = (_data & _mask) | (reg->data & _copy);
245 for (i = 0; i < 16; i++, addr += 0x1000) {
246 if (ram->pnuts & (1 << i)) {
247 u32 prev = nv_rd32(priv, addr);
248 u32 next = (prev & ~mask) | data;
249 nouveau_memx_wr32(fuc->memx, addr, next);
253 #define ram_nuts(s,r,m,d,c) \
254 nve0_ram_nuts((s), &(s)->fuc.r_##r, (m), (d), (c))
257 nve0_ram_calc_gddr5(struct nouveau_fb *pfb, u32 freq)
259 struct nve0_ram *ram = (void *)pfb->ram;
260 struct nve0_ramfuc *fuc = &ram->fuc;
261 struct nouveau_ram_data *next = ram->base.next;
262 int vc = !next->bios.ramcfg_11_02_08;
263 int mv = !next->bios.ramcfg_11_02_04;
266 ram_mask(fuc, 0x10f808, 0x40000000, 0x40000000);
267 ram_wr32(fuc, 0x62c000, 0x0f0f0000);
269 /* MR1: turn termination on early, for some reason.. */
270 if ((ram->base.mr[1] & 0x03c) != 0x030) {
271 ram_mask(fuc, mr[1], 0x03c, ram->base.mr[1] & 0x03c);
272 ram_nuts(ram, mr[1], 0x03c, ram->base.mr1_nuts & 0x03c, 0x000);
275 if (vc == 1 && ram_have(fuc, gpio2E)) {
276 u32 temp = ram_mask(fuc, gpio2E, 0x3000, fuc->r_func2E[1]);
277 if (temp != ram_rd32(fuc, gpio2E)) {
278 ram_wr32(fuc, gpiotrig, 1);
279 ram_nsec(fuc, 20000);
283 ram_mask(fuc, 0x10f200, 0x00000800, 0x00000000);
285 nve0_ram_train(fuc, 0x01020000, 0x000c0000);
287 ram_wr32(fuc, 0x10f210, 0x00000000); /* REFRESH_AUTO = 0 */
289 ram_wr32(fuc, 0x10f310, 0x00000001); /* REFRESH */
292 ram_mask(fuc, 0x10f200, 0x80000000, 0x80000000);
293 ram_wr32(fuc, 0x10f314, 0x00000001); /* PRECHARGE */
294 ram_mask(fuc, 0x10f200, 0x80000000, 0x00000000);
295 ram_wr32(fuc, 0x10f090, 0x00000061);
296 ram_wr32(fuc, 0x10f090, 0xc000007f);
299 ram_wr32(fuc, 0x10f698, 0x00000000);
300 ram_wr32(fuc, 0x10f69c, 0x00000000);
302 /*XXX: there does appear to be some kind of condition here, simply
303 * modifying these bits in the vbios from the default pl0
304 * entries shows no change. however, the data does appear to
305 * be correct and may be required for the transition back
309 if (ram_rd32(fuc, 0x10f978) & 0x00800000)
314 switch (next->bios.ramcfg_11_03_c0) {
315 case 3: data &= ~0x00000040; break;
316 case 2: data &= ~0x00000100; break;
317 case 1: data &= ~0x80000000; break;
318 case 0: data &= ~0x00000400; break;
321 switch (next->bios.ramcfg_11_03_30) {
322 case 3: data &= ~0x00000020; break;
323 case 2: data &= ~0x00000080; break;
324 case 1: data &= ~0x00080000; break;
325 case 0: data &= ~0x00000200; break;
329 if (next->bios.ramcfg_11_02_80)
331 if (next->bios.ramcfg_11_02_40)
333 if (next->bios.ramcfg_11_07_10)
335 if (next->bios.ramcfg_11_07_08)
339 if (ram_rd32(fuc, 0x10f978) & 0x00800000)
342 ram_mask(fuc, 0x10f824, mask, data);
344 ram_mask(fuc, 0x132040, 0x00010000, 0x00000000);
346 if (ram->from == 2 && ram->mode != 2) {
347 ram_mask(fuc, 0x10f808, 0x00080000, 0x00000000);
348 ram_mask(fuc, 0x10f200, 0x18008000, 0x00008000);
349 ram_mask(fuc, 0x10f800, 0x00000000, 0x00000004);
350 ram_mask(fuc, 0x10f830, 0x00008000, 0x01040010);
351 ram_mask(fuc, 0x10f830, 0x01000000, 0x00000000);
353 ram_mask(fuc, 0x1373f0, 0x00000002, 0x00000001);
355 ram_mask(fuc, 0x10f830, 0x00c00000, 0x00240001);
357 if (ram->from != 2 && ram->mode != 2) {
362 if (ram_have(fuc, gpioMV)) {
363 u32 temp = ram_mask(fuc, gpioMV, 0x3000, fuc->r_funcMV[mv]);
364 if (temp != ram_rd32(fuc, gpioMV)) {
365 ram_wr32(fuc, gpiotrig, 1);
366 ram_nsec(fuc, 64000);
370 if (next->bios.ramcfg_11_02_40 ||
371 next->bios.ramcfg_11_07_10) {
372 ram_mask(fuc, 0x132040, 0x00010000, 0x00010000);
373 ram_nsec(fuc, 20000);
376 if (ram->from != 2 && ram->mode == 2) {
377 if (0 /*XXX: Titan */)
378 ram_mask(fuc, 0x10f200, 0x18000000, 0x18000000);
379 ram_mask(fuc, 0x10f800, 0x00000004, 0x00000000);
380 ram_mask(fuc, 0x1373f0, 0x00000000, 0x00000002);
381 ram_mask(fuc, 0x10f830, 0x00800001, 0x00408010);
384 ram_mask(fuc, 0x10f808, 0x00000000, 0x00080000);
385 ram_mask(fuc, 0x10f200, 0x00808000, 0x00800000);
387 if (ram->from == 2 && ram->mode == 2) {
388 ram_mask(fuc, 0x10f800, 0x00000004, 0x00000000);
393 if (ram->mode != 2) /*XXX*/ {
394 if (next->bios.ramcfg_11_07_40)
395 ram_mask(fuc, 0x10f670, 0x80000000, 0x80000000);
398 ram_wr32(fuc, 0x10f65c, 0x00000011 * next->bios.rammap_11_11_0c);
399 ram_wr32(fuc, 0x10f6b8, 0x01010101 * next->bios.ramcfg_11_09);
400 ram_wr32(fuc, 0x10f6bc, 0x01010101 * next->bios.ramcfg_11_09);
402 if (!next->bios.ramcfg_11_07_08 && !next->bios.ramcfg_11_07_04) {
403 ram_wr32(fuc, 0x10f698, 0x01010101 * next->bios.ramcfg_11_04);
404 ram_wr32(fuc, 0x10f69c, 0x01010101 * next->bios.ramcfg_11_04);
406 if (!next->bios.ramcfg_11_07_08) {
407 ram_wr32(fuc, 0x10f698, 0x00000000);
408 ram_wr32(fuc, 0x10f69c, 0x00000000);
411 if (ram->mode != 2) {
412 u32 data = 0x01000100 * next->bios.ramcfg_11_04;
413 ram_nuke(fuc, 0x10f694);
414 ram_mask(fuc, 0x10f694, 0xff00ff00, data);
417 if (ram->mode == 2 && next->bios.ramcfg_11_08_10)
421 ram_mask(fuc, 0x10f60c, 0x00000080, data);
425 if (!next->bios.ramcfg_11_02_80)
427 if (!next->bios.ramcfg_11_02_40)
429 if (!next->bios.ramcfg_11_07_10)
431 if (!next->bios.ramcfg_11_07_08)
435 ram_mask(fuc, 0x10f824, mask, data);
437 if (next->bios.ramcfg_11_01_08)
441 ram_mask(fuc, 0x10f200, 0x00001000, data);
443 if (ram_rd32(fuc, 0x10f670) & 0x80000000) {
444 ram_nsec(fuc, 10000);
445 ram_mask(fuc, 0x10f670, 0x80000000, 0x00000000);
448 if (next->bios.ramcfg_11_08_01)
452 ram_mask(fuc, 0x10f82c, 0x00100000, data);
455 if (next->bios.ramcfg_11_08_08)
457 if (next->bios.ramcfg_11_08_04)
459 if (next->bios.ramcfg_11_08_02)
461 ram_mask(fuc, 0x10f830, 0x00007000, data);
464 ram_mask(fuc, 0x10f248, 0xffffffff, next->bios.timing[10]);
465 ram_mask(fuc, 0x10f290, 0xffffffff, next->bios.timing[0]);
466 ram_mask(fuc, 0x10f294, 0xffffffff, next->bios.timing[1]);
467 ram_mask(fuc, 0x10f298, 0xffffffff, next->bios.timing[2]);
468 ram_mask(fuc, 0x10f29c, 0xffffffff, next->bios.timing[3]);
469 ram_mask(fuc, 0x10f2a0, 0xffffffff, next->bios.timing[4]);
470 ram_mask(fuc, 0x10f2a4, 0xffffffff, next->bios.timing[5]);
471 ram_mask(fuc, 0x10f2a8, 0xffffffff, next->bios.timing[6]);
472 ram_mask(fuc, 0x10f2ac, 0xffffffff, next->bios.timing[7]);
473 ram_mask(fuc, 0x10f2cc, 0xffffffff, next->bios.timing[8]);
474 ram_mask(fuc, 0x10f2e8, 0xffffffff, next->bios.timing[9]);
476 data = mask = 0x00000000;
477 if (ram->diff.ramcfg_11_08_20) {
478 if (next->bios.ramcfg_11_08_20)
482 ram_mask(fuc, 0x10f200, mask, data);
484 data = mask = 0x00000000;
485 if (ram->diff.ramcfg_11_02_03) {
486 data |= next->bios.ramcfg_11_02_03 << 8;
489 if (ram->diff.ramcfg_11_01_10) {
490 if (next->bios.ramcfg_11_01_10)
494 ram_mask(fuc, 0x10f604, mask, data);
496 data = mask = 0x00000000;
497 if (ram->diff.timing_20_30_07) {
498 data |= next->bios.timing_20_30_07 << 28;
501 if (ram->diff.ramcfg_11_01_01) {
502 if (next->bios.ramcfg_11_01_01)
506 ram_mask(fuc, 0x10f614, mask, data);
508 data = mask = 0x00000000;
509 if (ram->diff.timing_20_30_07) {
510 data |= next->bios.timing_20_30_07 << 28;
513 if (ram->diff.ramcfg_11_01_02) {
514 if (next->bios.ramcfg_11_01_02)
518 ram_mask(fuc, 0x10f610, mask, data);
522 if (!next->bios.ramcfg_11_01_04)
524 if (!next->bios.ramcfg_11_07_80)
526 /*XXX: see note above about there probably being some condition
527 * for the 10f824 stuff that uses ramcfg 3...
529 if (next->bios.ramcfg_11_03_f0) {
530 if (next->bios.rammap_11_08_0c) {
531 if (!next->bios.ramcfg_11_07_80)
542 ram_mask(fuc, 0x10f808, mask, data);
544 ram_wr32(fuc, 0x10f870, 0x11111111 * next->bios.ramcfg_11_03_0f);
546 data = mask = 0x00000000;
547 if (ram->diff.ramcfg_11_02_03) {
548 data |= next->bios.ramcfg_11_02_03;
551 if (ram->diff.ramcfg_11_01_10) {
552 if (next->bios.ramcfg_11_01_10)
557 if ((ram_mask(fuc, 0x100770, mask, data) & mask & 4) != (data & 4)) {
558 ram_mask(fuc, 0x100750, 0x00000008, 0x00000008);
559 ram_wr32(fuc, 0x100710, 0x00000000);
560 ram_wait(fuc, 0x100710, 0x80000000, 0x80000000, 200000);
563 data = next->bios.timing_20_30_07 << 8;
564 if (next->bios.ramcfg_11_01_01)
566 ram_mask(fuc, 0x100778, 0x00000700, data);
568 ram_mask(fuc, 0x10f250, 0x000003f0, next->bios.timing_20_2c_003f << 4);
569 data = (next->bios.timing[10] & 0x7f000000) >> 24;
570 if (data < next->bios.timing_20_2c_1fc0)
571 data = next->bios.timing_20_2c_1fc0;
572 ram_mask(fuc, 0x10f24c, 0x7f000000, data << 24);
573 ram_mask(fuc, 0x10f224, 0x001f0000, next->bios.timing_20_30_f8 << 16);
575 ram_mask(fuc, 0x10fec4, 0x041e0f07, next->bios.timing_20_31_0800 << 26 |
576 next->bios.timing_20_31_0780 << 17 |
577 next->bios.timing_20_31_0078 << 8 |
578 next->bios.timing_20_31_0007);
579 ram_mask(fuc, 0x10fec8, 0x00000027, next->bios.timing_20_31_8000 << 5 |
580 next->bios.timing_20_31_7000);
582 ram_wr32(fuc, 0x10f090, 0x4000007e);
584 ram_wr32(fuc, 0x10f314, 0x00000001); /* PRECHARGE */
585 ram_wr32(fuc, 0x10f310, 0x00000001); /* REFRESH */
586 ram_wr32(fuc, 0x10f210, 0x80000000); /* REFRESH_AUTO = 1 */
588 if (next->bios.ramcfg_11_08_10 && (ram->mode == 2) /*XXX*/) {
589 u32 temp = ram_mask(fuc, 0x10f294, 0xff000000, 0x24000000);
590 nve0_ram_train(fuc, 0xbc0e0000, 0xa4010000); /*XXX*/
592 ram_wr32(fuc, 0x10f294, temp);
595 ram_mask(fuc, mr[3], 0xfff, ram->base.mr[3]);
596 ram_wr32(fuc, mr[0], ram->base.mr[0]);
597 ram_mask(fuc, mr[8], 0xfff, ram->base.mr[8]);
599 ram_mask(fuc, mr[1], 0xfff, ram->base.mr[1]);
600 ram_mask(fuc, mr[5], 0xfff, ram->base.mr[5] & ~0x004); /* LP3 later */
601 ram_mask(fuc, mr[6], 0xfff, ram->base.mr[6]);
602 ram_mask(fuc, mr[7], 0xfff, ram->base.mr[7]);
604 if (vc == 0 && ram_have(fuc, gpio2E)) {
605 u32 temp = ram_mask(fuc, gpio2E, 0x3000, fuc->r_func2E[0]);
606 if (temp != ram_rd32(fuc, gpio2E)) {
607 ram_wr32(fuc, gpiotrig, 1);
608 ram_nsec(fuc, 20000);
612 ram_mask(fuc, 0x10f200, 0x80000000, 0x80000000);
613 ram_wr32(fuc, 0x10f318, 0x00000001); /* NOP? */
614 ram_mask(fuc, 0x10f200, 0x80000000, 0x00000000);
616 ram_nuts(ram, 0x10f200, 0x18808800, 0x00000000, 0x18808800);
618 data = ram_rd32(fuc, 0x10f978);
621 if (!next->bios.ramcfg_11_07_08) {
622 if (!next->bios.ramcfg_11_07_04)
629 ram_wr32(fuc, 0x10f978, data);
631 if (ram->mode == 1) {
632 data = ram_rd32(fuc, 0x10f830) | 0x00000001;
633 ram_wr32(fuc, 0x10f830, data);
636 if (!next->bios.ramcfg_11_07_08) {
638 if ( next->bios.ramcfg_11_07_04)
640 if (!next->bios.rammap_11_08_10)
645 nve0_ram_train(fuc, 0xbc0f0000, data);
646 if (1) /* XXX: not always? */
649 if (ram->mode == 2) { /*XXX*/
650 ram_mask(fuc, 0x10f800, 0x00000004, 0x00000004);
654 if (ram_mask(fuc, mr[5], 0x004, ram->base.mr[5]) != ram->base.mr[5])
657 if (ram->mode != 2) {
658 ram_mask(fuc, 0x10f830, 0x01000000, 0x01000000);
659 ram_mask(fuc, 0x10f830, 0x01000000, 0x00000000);
662 if (next->bios.ramcfg_11_07_02)
663 nve0_ram_train(fuc, 0x80020000, 0x01000000);
665 ram_wr32(fuc, 0x62c000, 0x0f0f0f00);
667 if (next->bios.rammap_11_08_01)
671 ram_mask(fuc, 0x10f200, 0x00000800, data);
672 ram_nuts(ram, 0x10f200, 0x18808800, data, 0x18808800);
676 /*******************************************************************************
678 ******************************************************************************/
681 nve0_ram_calc_sddr3(struct nouveau_fb *pfb, u32 freq)
683 struct nve0_ram *ram = (void *)pfb->ram;
684 struct nve0_ramfuc *fuc = &ram->fuc;
685 const u32 rcoef = (( ram->P1 << 16) | (ram->N1 << 8) | ram->M1);
686 const u32 runk0 = ram->fN1 << 16;
687 const u32 runk1 = ram->fN1;
688 struct nouveau_ram_data *next = ram->base.next;
689 int vc = !next->bios.ramcfg_11_02_08;
690 int mv = !next->bios.ramcfg_11_02_04;
693 ram_mask(fuc, 0x10f808, 0x40000000, 0x40000000);
694 ram_wr32(fuc, 0x62c000, 0x0f0f0000);
696 if (vc == 1 && ram_have(fuc, gpio2E)) {
697 u32 temp = ram_mask(fuc, gpio2E, 0x3000, fuc->r_func2E[1]);
698 if (temp != ram_rd32(fuc, gpio2E)) {
699 ram_wr32(fuc, gpiotrig, 1);
700 ram_nsec(fuc, 20000);
704 ram_mask(fuc, 0x10f200, 0x00000800, 0x00000000);
705 if (next->bios.ramcfg_11_03_f0)
706 ram_mask(fuc, 0x10f808, 0x04000000, 0x04000000);
708 ram_wr32(fuc, 0x10f314, 0x00000001); /* PRECHARGE */
709 ram_wr32(fuc, 0x10f210, 0x00000000); /* REFRESH_AUTO = 0 */
710 ram_wr32(fuc, 0x10f310, 0x00000001); /* REFRESH */
711 ram_mask(fuc, 0x10f200, 0x80000000, 0x80000000);
712 ram_wr32(fuc, 0x10f310, 0x00000001); /* REFRESH */
713 ram_mask(fuc, 0x10f200, 0x80000000, 0x00000000);
716 ram_wr32(fuc, 0x10f090, 0x00000060);
717 ram_wr32(fuc, 0x10f090, 0xc000007e);
719 /*XXX: there does appear to be some kind of condition here, simply
720 * modifying these bits in the vbios from the default pl0
721 * entries shows no change. however, the data does appear to
722 * be correct and may be required for the transition back
730 switch (next->bios.ramcfg_11_03_c0) {
731 case 3: data &= ~0x00000040; break;
732 case 2: data &= ~0x00000100; break;
733 case 1: data &= ~0x80000000; break;
734 case 0: data &= ~0x00000400; break;
737 switch (next->bios.ramcfg_11_03_30) {
738 case 3: data &= ~0x00000020; break;
739 case 2: data &= ~0x00000080; break;
740 case 1: data &= ~0x00080000; break;
741 case 0: data &= ~0x00000200; break;
745 if (next->bios.ramcfg_11_02_80)
747 if (next->bios.ramcfg_11_02_40)
749 if (next->bios.ramcfg_11_07_10)
751 if (next->bios.ramcfg_11_07_08)
755 ram_mask(fuc, 0x10f824, mask, data);
757 ram_mask(fuc, 0x132040, 0x00010000, 0x00000000);
759 ram_mask(fuc, 0x1373f4, 0x00000000, 0x00010010);
760 data = ram_rd32(fuc, 0x1373ec) & ~0x00030000;
761 data |= next->bios.ramcfg_11_03_30 << 16;
762 ram_wr32(fuc, 0x1373ec, data);
763 ram_mask(fuc, 0x1373f4, 0x00000003, 0x00000000);
764 ram_mask(fuc, 0x1373f4, 0x00000010, 0x00000000);
766 /* (re)program refpll, if required */
767 if ((ram_rd32(fuc, 0x132024) & 0xffffffff) != rcoef ||
768 (ram_rd32(fuc, 0x132034) & 0x0000ffff) != runk1) {
769 ram_mask(fuc, 0x132000, 0x00000001, 0x00000000);
770 ram_mask(fuc, 0x132020, 0x00000001, 0x00000000);
771 ram_wr32(fuc, 0x137320, 0x00000000);
772 ram_mask(fuc, 0x132030, 0xffff0000, runk0);
773 ram_mask(fuc, 0x132034, 0x0000ffff, runk1);
774 ram_wr32(fuc, 0x132024, rcoef);
775 ram_mask(fuc, 0x132028, 0x00080000, 0x00080000);
776 ram_mask(fuc, 0x132020, 0x00000001, 0x00000001);
777 ram_wait(fuc, 0x137390, 0x00020000, 0x00020000, 64000);
778 ram_mask(fuc, 0x132028, 0x00080000, 0x00000000);
781 ram_mask(fuc, 0x1373f4, 0x00000010, 0x00000010);
782 ram_mask(fuc, 0x1373f4, 0x00000003, 0x00000001);
783 ram_mask(fuc, 0x1373f4, 0x00010000, 0x00000000);
785 if (ram_have(fuc, gpioMV)) {
786 u32 temp = ram_mask(fuc, gpioMV, 0x3000, fuc->r_funcMV[mv]);
787 if (temp != ram_rd32(fuc, gpioMV)) {
788 ram_wr32(fuc, gpiotrig, 1);
789 ram_nsec(fuc, 64000);
793 if (next->bios.ramcfg_11_02_40 ||
794 next->bios.ramcfg_11_07_10) {
795 ram_mask(fuc, 0x132040, 0x00010000, 0x00010000);
796 ram_nsec(fuc, 20000);
799 if (ram->mode != 2) /*XXX*/ {
800 if (next->bios.ramcfg_11_07_40)
801 ram_mask(fuc, 0x10f670, 0x80000000, 0x80000000);
804 ram_wr32(fuc, 0x10f65c, 0x00000011 * next->bios.rammap_11_11_0c);
805 ram_wr32(fuc, 0x10f6b8, 0x01010101 * next->bios.ramcfg_11_09);
806 ram_wr32(fuc, 0x10f6bc, 0x01010101 * next->bios.ramcfg_11_09);
810 if (!next->bios.ramcfg_11_02_80)
812 if (!next->bios.ramcfg_11_02_40)
814 if (!next->bios.ramcfg_11_07_10)
816 if (!next->bios.ramcfg_11_07_08)
820 ram_mask(fuc, 0x10f824, mask, data);
823 if (next->bios.ramcfg_11_08_01)
827 ram_mask(fuc, 0x10f82c, 0x00100000, data);
830 ram_mask(fuc, 0x10f248, 0xffffffff, next->bios.timing[10]);
831 ram_mask(fuc, 0x10f290, 0xffffffff, next->bios.timing[0]);
832 ram_mask(fuc, 0x10f294, 0xffffffff, next->bios.timing[1]);
833 ram_mask(fuc, 0x10f298, 0xffffffff, next->bios.timing[2]);
834 ram_mask(fuc, 0x10f29c, 0xffffffff, next->bios.timing[3]);
835 ram_mask(fuc, 0x10f2a0, 0xffffffff, next->bios.timing[4]);
836 ram_mask(fuc, 0x10f2a4, 0xffffffff, next->bios.timing[5]);
837 ram_mask(fuc, 0x10f2a8, 0xffffffff, next->bios.timing[6]);
838 ram_mask(fuc, 0x10f2ac, 0xffffffff, next->bios.timing[7]);
839 ram_mask(fuc, 0x10f2cc, 0xffffffff, next->bios.timing[8]);
840 ram_mask(fuc, 0x10f2e8, 0xffffffff, next->bios.timing[9]);
844 if (!next->bios.ramcfg_11_01_04)
846 if (!next->bios.ramcfg_11_07_80)
848 /*XXX: see note above about there probably being some condition
849 * for the 10f824 stuff that uses ramcfg 3...
851 if (next->bios.ramcfg_11_03_f0) {
852 if (next->bios.rammap_11_08_0c) {
853 if (!next->bios.ramcfg_11_07_80)
865 ram_mask(fuc, 0x10f808, mask, data);
867 ram_wr32(fuc, 0x10f870, 0x11111111 * next->bios.ramcfg_11_03_0f);
869 ram_mask(fuc, 0x10f250, 0x000003f0, next->bios.timing_20_2c_003f << 4);
871 data = (next->bios.timing[10] & 0x7f000000) >> 24;
872 if (data < next->bios.timing_20_2c_1fc0)
873 data = next->bios.timing_20_2c_1fc0;
874 ram_mask(fuc, 0x10f24c, 0x7f000000, data << 24);
876 ram_mask(fuc, 0x10f224, 0x001f0000, next->bios.timing_20_30_f8 << 16);
878 ram_wr32(fuc, 0x10f090, 0x4000007f);
881 ram_wr32(fuc, 0x10f314, 0x00000001); /* PRECHARGE */
882 ram_wr32(fuc, 0x10f310, 0x00000001); /* REFRESH */
883 ram_wr32(fuc, 0x10f210, 0x80000000); /* REFRESH_AUTO = 1 */
886 ram_nuke(fuc, mr[0]);
887 ram_mask(fuc, mr[0], 0x100, 0x100);
888 ram_mask(fuc, mr[0], 0x100, 0x000);
890 ram_mask(fuc, mr[2], 0xfff, ram->base.mr[2]);
891 ram_wr32(fuc, mr[0], ram->base.mr[0]);
894 ram_nuke(fuc, mr[0]);
895 ram_mask(fuc, mr[0], 0x100, 0x100);
896 ram_mask(fuc, mr[0], 0x100, 0x000);
898 if (vc == 0 && ram_have(fuc, gpio2E)) {
899 u32 temp = ram_mask(fuc, gpio2E, 0x3000, fuc->r_func2E[0]);
900 if (temp != ram_rd32(fuc, gpio2E)) {
901 ram_wr32(fuc, gpiotrig, 1);
902 ram_nsec(fuc, 20000);
906 if (ram->mode != 2) {
907 ram_mask(fuc, 0x10f830, 0x01000000, 0x01000000);
908 ram_mask(fuc, 0x10f830, 0x01000000, 0x00000000);
911 ram_mask(fuc, 0x10f200, 0x80000000, 0x80000000);
912 ram_wr32(fuc, 0x10f318, 0x00000001); /* NOP? */
913 ram_mask(fuc, 0x10f200, 0x80000000, 0x00000000);
916 ram_wr32(fuc, 0x62c000, 0x0f0f0f00);
918 if (next->bios.rammap_11_08_01)
922 ram_mask(fuc, 0x10f200, 0x00000800, data);
926 /*******************************************************************************
928 ******************************************************************************/
931 nve0_ram_calc_data(struct nouveau_fb *pfb, u32 khz,
932 struct nouveau_ram_data *data)
934 struct nve0_ram *ram = (void *)pfb->ram;
935 struct nouveau_ram_data *cfg;
936 u32 mhz = khz / 1000;
938 list_for_each_entry(cfg, &ram->cfg, head) {
939 if (mhz >= cfg->bios.rammap_min &&
940 mhz <= cfg->bios.rammap_max) {
947 nv_error(ram, "ramcfg data for %dMHz not found\n", mhz);
952 nve0_ram_calc_xits(struct nouveau_fb *pfb, struct nouveau_ram_data *next)
954 struct nve0_ram *ram = (void *)pfb->ram;
955 struct nve0_ramfuc *fuc = &ram->fuc;
959 ret = ram_init(fuc, pfb);
965 ram->mode = (next->freq > fuc->refpll.vco1.max_freq) ? 2 : 1;
966 ram->from = ram_rd32(fuc, 0x1373f4) & 0x0000000f;
968 /* XXX: this is *not* what nvidia do. on fermi nvidia generally
969 * select, based on some unknown condition, one of the two possible
970 * reference frequencies listed in the vbios table for mempll and
971 * program refpll to that frequency.
973 * so far, i've seen very weird values being chosen by nvidia on
974 * kepler boards, no idea how/why they're chosen.
978 refclk = fuc->mempll.refclk;
980 /* calculate refpll coefficients */
981 ret = nva3_pll_calc(nv_subdev(pfb), &fuc->refpll, refclk, &ram->N1,
982 &ram->fN1, &ram->M1, &ram->P1);
983 fuc->mempll.refclk = ret;
985 nv_error(pfb, "unable to calc refpll\n");
989 /* calculate mempll coefficients, if we're using it */
990 if (ram->mode == 2) {
991 /* post-divider doesn't work... the reg takes the values but
992 * appears to completely ignore it. there *is* a bit at
993 * bit 28 that appears to divide the clock by 2 if set.
995 fuc->mempll.min_p = 1;
996 fuc->mempll.max_p = 2;
998 ret = nva3_pll_calc(nv_subdev(pfb), &fuc->mempll, next->freq,
999 &ram->N2, NULL, &ram->M2, &ram->P2);
1001 nv_error(pfb, "unable to calc mempll\n");
1006 for (i = 0; i < ARRAY_SIZE(fuc->r_mr); i++) {
1007 if (ram_have(fuc, mr[i]))
1008 ram->base.mr[i] = ram_rd32(fuc, mr[i]);
1010 ram->base.freq = next->freq;
1012 switch (ram->base.type) {
1013 case NV_MEM_TYPE_DDR3:
1014 ret = nouveau_sddr3_calc(&ram->base);
1016 ret = nve0_ram_calc_sddr3(pfb, next->freq);
1018 case NV_MEM_TYPE_GDDR5:
1019 ret = nouveau_gddr5_calc(&ram->base, ram->pnuts != 0);
1021 ret = nve0_ram_calc_gddr5(pfb, next->freq);
1035 nve0_ram_calc(struct nouveau_fb *pfb, u32 freq)
1037 struct nouveau_clock *clk = nouveau_clock(pfb);
1038 struct nve0_ram *ram = (void *)pfb->ram;
1039 struct nouveau_ram_data *xits = &ram->base.xition;
1040 struct nouveau_ram_data *copy;
1043 if (ram->base.next == NULL) {
1044 ret = nve0_ram_calc_data(pfb, clk->read(clk, nv_clk_src_mem),
1049 ret = nve0_ram_calc_data(pfb, freq, &ram->base.target);
1053 if (ram->base.target.freq < ram->base.former.freq) {
1054 *xits = ram->base.target;
1055 copy = &ram->base.former;
1057 *xits = ram->base.former;
1058 copy = &ram->base.target;
1061 xits->bios.ramcfg_11_02_04 = copy->bios.ramcfg_11_02_04;
1062 xits->bios.ramcfg_11_02_03 = copy->bios.ramcfg_11_02_03;
1063 xits->bios.timing_20_30_07 = copy->bios.timing_20_30_07;
1065 ram->base.next = &ram->base.target;
1066 if (memcmp(xits, &ram->base.former, sizeof(xits->bios)))
1067 ram->base.next = &ram->base.xition;
1069 BUG_ON(ram->base.next != &ram->base.xition);
1070 ram->base.next = &ram->base.target;
1073 return nve0_ram_calc_xits(pfb, ram->base.next);
1077 nve0_ram_prog(struct nouveau_fb *pfb)
1079 struct nouveau_device *device = nv_device(pfb);
1080 struct nve0_ram *ram = (void *)pfb->ram;
1081 struct nve0_ramfuc *fuc = &ram->fuc;
1082 ram_exec(fuc, nouveau_boolopt(device->cfgopt, "NvMemExec", true));
1083 return (ram->base.next == &ram->base.xition);
1087 nve0_ram_tidy(struct nouveau_fb *pfb)
1089 struct nve0_ram *ram = (void *)pfb->ram;
1090 struct nve0_ramfuc *fuc = &ram->fuc;
1091 ram->base.next = NULL;
1092 ram_exec(fuc, false);
1095 struct nve0_ram_train {
1097 struct nvbios_M0209S remap;
1098 struct nvbios_M0209S type00;
1099 struct nvbios_M0209S type01;
1100 struct nvbios_M0209S type04;
1101 struct nvbios_M0209S type06;
1102 struct nvbios_M0209S type07;
1103 struct nvbios_M0209S type08;
1104 struct nvbios_M0209S type09;
1108 nve0_ram_train_type(struct nouveau_fb *pfb, int i, u8 ramcfg,
1109 struct nve0_ram_train *train)
1111 struct nouveau_bios *bios = nouveau_bios(pfb);
1112 struct nvbios_M0205E M0205E;
1113 struct nvbios_M0205S M0205S;
1114 struct nvbios_M0209E M0209E;
1115 struct nvbios_M0209S *remap = &train->remap;
1116 struct nvbios_M0209S *value;
1117 u8 ver, hdr, cnt, len;
1120 /* determine type of data for this index */
1121 if (!(data = nvbios_M0205Ep(bios, i, &ver, &hdr, &cnt, &len, &M0205E)))
1124 switch (M0205E.type) {
1125 case 0x00: value = &train->type00; break;
1126 case 0x01: value = &train->type01; break;
1127 case 0x04: value = &train->type04; break;
1128 case 0x06: value = &train->type06; break;
1129 case 0x07: value = &train->type07; break;
1130 case 0x08: value = &train->type08; break;
1131 case 0x09: value = &train->type09; break;
1136 /* training data index determined by ramcfg strap */
1137 if (!(data = nvbios_M0205Sp(bios, i, ramcfg, &ver, &hdr, &M0205S)))
1141 /* training data format information */
1142 if (!(data = nvbios_M0209Ep(bios, i, &ver, &hdr, &cnt, &len, &M0209E)))
1145 /* ... and the raw data */
1146 if (!(data = nvbios_M0209Sp(bios, i, 0, &ver, &hdr, value)))
1149 if (M0209E.v02_07 == 2) {
1150 /* of course! why wouldn't we have a pointer to another entry
1151 * in the same table, and use the first one as an array of
1154 if (!(data = nvbios_M0209Sp(bios, M0209E.v03, 0, &ver, &hdr,
1158 for (i = 0; i < ARRAY_SIZE(value->data); i++)
1159 value->data[i] = remap->data[value->data[i]];
1161 if (M0209E.v02_07 != 1)
1164 train->mask |= 1 << M0205E.type;
1169 nve0_ram_train_init_0(struct nouveau_fb *pfb, struct nve0_ram_train *train)
1173 if ((train->mask & 0x03d3) != 0x03d3) {
1174 nv_warn(pfb, "missing link training data\n");
1178 for (i = 0; i < 0x30; i++) {
1179 for (j = 0; j < 8; j += 4) {
1180 nv_wr32(pfb, 0x10f968 + j, 0x00000000 | (i << 8));
1181 nv_wr32(pfb, 0x10f920 + j, 0x00000000 |
1182 train->type08.data[i] << 4 |
1183 train->type06.data[i]);
1184 nv_wr32(pfb, 0x10f918 + j, train->type00.data[i]);
1185 nv_wr32(pfb, 0x10f920 + j, 0x00000100 |
1186 train->type09.data[i] << 4 |
1187 train->type07.data[i]);
1188 nv_wr32(pfb, 0x10f918 + j, train->type01.data[i]);
1192 for (j = 0; j < 8; j += 4) {
1193 for (i = 0; i < 0x100; i++) {
1194 nv_wr32(pfb, 0x10f968 + j, i);
1195 nv_wr32(pfb, 0x10f900 + j, train->type04.data[i]);
1203 nve0_ram_train_init(struct nouveau_fb *pfb)
1205 u8 ramcfg = nvbios_ramcfg_index(nv_subdev(pfb));
1206 struct nve0_ram_train *train;
1207 int ret = -ENOMEM, i;
1209 if ((train = kzalloc(sizeof(*train), GFP_KERNEL))) {
1210 for (i = 0; i < 0x100; i++) {
1211 ret = nve0_ram_train_type(pfb, i, ramcfg, train);
1212 if (ret && ret != -ENOENT)
1217 switch (pfb->ram->type) {
1218 case NV_MEM_TYPE_GDDR5:
1219 ret = nve0_ram_train_init_0(pfb, train);
1231 nve0_ram_init(struct nouveau_object *object)
1233 struct nouveau_fb *pfb = (void *)object->parent;
1234 struct nve0_ram *ram = (void *)object;
1235 struct nouveau_bios *bios = nouveau_bios(pfb);
1236 u8 ver, hdr, cnt, len, snr, ssz;
1240 ret = nouveau_ram_init(&ram->base);
1244 /* run a bunch of tables from rammap table. there's actually
1245 * individual pointers for each rammap entry too, but, nvidia
1246 * seem to just run the last two entries' scripts early on in
1247 * their init, and never again.. we'll just run 'em all once
1250 * i strongly suspect that each script is for a separate mode
1251 * (likely selected by 0x10f65c's lower bits?), and the
1252 * binary driver skips the one that's already been setup by
1255 data = nvbios_rammapTe(bios, &ver, &hdr, &cnt, &len, &snr, &ssz);
1256 if (!data || hdr < 0x15)
1259 cnt = nv_ro08(bios, data + 0x14); /* guess at count */
1260 data = nv_ro32(bios, data + 0x10); /* guess u32... */
1261 save = nv_rd32(pfb, 0x10f65c) & 0x000000f0;
1262 for (i = 0; i < cnt; i++, data += 4) {
1263 if (i != save >> 4) {
1264 nv_mask(pfb, 0x10f65c, 0x000000f0, i << 4);
1265 nvbios_exec(&(struct nvbios_init) {
1266 .subdev = nv_subdev(pfb),
1268 .offset = nv_ro32(bios, data),
1273 nv_mask(pfb, 0x10f65c, 0x000000f0, save);
1274 nv_mask(pfb, 0x10f584, 0x11000000, 0x00000000);
1275 nv_wr32(pfb, 0x10ecc0, 0xffffffff);
1276 nv_mask(pfb, 0x10f160, 0x00000010, 0x00000010);
1278 return nve0_ram_train_init(pfb);
1282 nve0_ram_ctor_data(struct nve0_ram *ram, u8 ramcfg, int i)
1284 struct nouveau_fb *pfb = (void *)nv_object(ram)->parent;
1285 struct nouveau_bios *bios = nouveau_bios(pfb);
1286 struct nouveau_ram_data *cfg;
1287 struct nvbios_ramcfg *d = &ram->diff;
1288 struct nvbios_ramcfg *p, *n;
1289 u8 ver, hdr, cnt, len;
1293 if (!(cfg = kmalloc(sizeof(*cfg), GFP_KERNEL)))
1295 p = &list_last_entry(&ram->cfg, typeof(*cfg), head)->bios;
1298 /* memory config data for a range of target frequencies */
1299 data = nvbios_rammapEp(bios, i, &ver, &hdr, &cnt, &len, &cfg->bios);
1300 if (ret = -ENOENT, !data)
1302 if (ret = -ENOSYS, ver != 0x11 || hdr < 0x12)
1305 /* ... and a portion specific to the attached memory */
1306 data = nvbios_rammapSp(bios, data, ver, hdr, cnt, len, ramcfg,
1307 &ver, &hdr, &cfg->bios);
1308 if (ret = -EINVAL, !data)
1310 if (ret = -ENOSYS, ver != 0x11 || hdr < 0x0a)
1313 /* lookup memory timings, if bios says they're present */
1314 if (cfg->bios.ramcfg_timing != 0xff) {
1315 data = nvbios_timingEp(bios, cfg->bios.ramcfg_timing,
1316 &ver, &hdr, &cnt, &len,
1318 if (ret = -EINVAL, !data)
1320 if (ret = -ENOSYS, ver != 0x20 || hdr < 0x33)
1324 list_add_tail(&cfg->head, &ram->cfg);
1325 if (ret = 0, i == 0)
1328 d->ramcfg_11_01_01 |= p->ramcfg_11_01_01 != n->ramcfg_11_01_01;
1329 d->ramcfg_11_01_02 |= p->ramcfg_11_01_02 != n->ramcfg_11_01_02;
1330 d->ramcfg_11_01_10 |= p->ramcfg_11_01_10 != n->ramcfg_11_01_10;
1331 d->ramcfg_11_02_03 |= p->ramcfg_11_02_03 != n->ramcfg_11_02_03;
1332 d->ramcfg_11_08_20 |= p->ramcfg_11_08_20 != n->ramcfg_11_08_20;
1333 d->timing_20_30_07 |= p->timing_20_30_07 != n->timing_20_30_07;
1341 nve0_ram_dtor(struct nouveau_object *object)
1343 struct nve0_ram *ram = (void *)object;
1344 struct nouveau_ram_data *cfg, *tmp;
1346 list_for_each_entry_safe(cfg, tmp, &ram->cfg, head) {
1350 nouveau_ram_destroy(&ram->base);
1354 nve0_ram_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
1355 struct nouveau_oclass *oclass, void *data, u32 size,
1356 struct nouveau_object **pobject)
1358 struct nouveau_fb *pfb = nouveau_fb(parent);
1359 struct nouveau_bios *bios = nouveau_bios(pfb);
1360 struct nouveau_gpio *gpio = nouveau_gpio(pfb);
1361 struct dcb_gpio_func func;
1362 struct nve0_ram *ram;
1364 u8 ramcfg = nvbios_ramcfg_index(nv_subdev(pfb));
1367 ret = nvc0_ram_create(parent, engine, oclass, 0x022554, &ram);
1368 *pobject = nv_object(ram);
1372 INIT_LIST_HEAD(&ram->cfg);
1374 switch (ram->base.type) {
1375 case NV_MEM_TYPE_DDR3:
1376 case NV_MEM_TYPE_GDDR5:
1377 ram->base.calc = nve0_ram_calc;
1378 ram->base.prog = nve0_ram_prog;
1379 ram->base.tidy = nve0_ram_tidy;
1382 nv_warn(pfb, "reclocking of this RAM type is unsupported\n");
1386 /* calculate a mask of differently configured memory partitions,
1387 * because, of course reclocking wasn't complicated enough
1388 * already without having to treat some of them differently to
1391 ram->parts = nv_rd32(pfb, 0x022438);
1392 ram->pmask = nv_rd32(pfb, 0x022554);
1394 for (i = 0, tmp = 0; i < ram->parts; i++) {
1395 if (!(ram->pmask & (1 << i))) {
1396 u32 cfg1 = nv_rd32(pfb, 0x110204 + (i * 0x1000));
1397 if (tmp && tmp != cfg1) {
1398 ram->pnuts |= (1 << i);
1405 /* parse bios data for all rammap table entries up-front, and
1406 * build information on whether certain fields differ between
1407 * any of the entries.
1409 * the binary driver appears to completely ignore some fields
1410 * when all entries contain the same value. at first, it was
1411 * hoped that these were mere optimisations and the bios init
1412 * tables had configured as per the values here, but there is
1413 * evidence now to suggest that this isn't the case and we do
1414 * need to treat this condition as a "don't touch" indicator.
1416 for (i = 0; !ret; i++) {
1417 ret = nve0_ram_ctor_data(ram, ramcfg, i);
1418 if (ret && ret != -ENOENT) {
1419 nv_error(pfb, "failed to parse ramcfg data\n");
1424 /* parse bios data for both pll's */
1425 ret = nvbios_pll_parse(bios, 0x0c, &ram->fuc.refpll);
1427 nv_error(pfb, "mclk refpll data not found\n");
1431 ret = nvbios_pll_parse(bios, 0x04, &ram->fuc.mempll);
1433 nv_error(pfb, "mclk pll data not found\n");
1437 /* lookup memory voltage gpios */
1438 ret = gpio->find(gpio, 0, 0x18, DCB_GPIO_UNUSED, &func);
1440 ram->fuc.r_gpioMV = ramfuc_reg(0x00d610 + (func.line * 0x04));
1441 ram->fuc.r_funcMV[0] = (func.log[0] ^ 2) << 12;
1442 ram->fuc.r_funcMV[1] = (func.log[1] ^ 2) << 12;
1445 ret = gpio->find(gpio, 0, 0x2e, DCB_GPIO_UNUSED, &func);
1447 ram->fuc.r_gpio2E = ramfuc_reg(0x00d610 + (func.line * 0x04));
1448 ram->fuc.r_func2E[0] = (func.log[0] ^ 2) << 12;
1449 ram->fuc.r_func2E[1] = (func.log[1] ^ 2) << 12;
1452 ram->fuc.r_gpiotrig = ramfuc_reg(0x00d604);
1454 ram->fuc.r_0x132020 = ramfuc_reg(0x132020);
1455 ram->fuc.r_0x132028 = ramfuc_reg(0x132028);
1456 ram->fuc.r_0x132024 = ramfuc_reg(0x132024);
1457 ram->fuc.r_0x132030 = ramfuc_reg(0x132030);
1458 ram->fuc.r_0x132034 = ramfuc_reg(0x132034);
1459 ram->fuc.r_0x132000 = ramfuc_reg(0x132000);
1460 ram->fuc.r_0x132004 = ramfuc_reg(0x132004);
1461 ram->fuc.r_0x132040 = ramfuc_reg(0x132040);
1463 ram->fuc.r_0x10f248 = ramfuc_reg(0x10f248);
1464 ram->fuc.r_0x10f290 = ramfuc_reg(0x10f290);
1465 ram->fuc.r_0x10f294 = ramfuc_reg(0x10f294);
1466 ram->fuc.r_0x10f298 = ramfuc_reg(0x10f298);
1467 ram->fuc.r_0x10f29c = ramfuc_reg(0x10f29c);
1468 ram->fuc.r_0x10f2a0 = ramfuc_reg(0x10f2a0);
1469 ram->fuc.r_0x10f2a4 = ramfuc_reg(0x10f2a4);
1470 ram->fuc.r_0x10f2a8 = ramfuc_reg(0x10f2a8);
1471 ram->fuc.r_0x10f2ac = ramfuc_reg(0x10f2ac);
1472 ram->fuc.r_0x10f2cc = ramfuc_reg(0x10f2cc);
1473 ram->fuc.r_0x10f2e8 = ramfuc_reg(0x10f2e8);
1474 ram->fuc.r_0x10f250 = ramfuc_reg(0x10f250);
1475 ram->fuc.r_0x10f24c = ramfuc_reg(0x10f24c);
1476 ram->fuc.r_0x10fec4 = ramfuc_reg(0x10fec4);
1477 ram->fuc.r_0x10fec8 = ramfuc_reg(0x10fec8);
1478 ram->fuc.r_0x10f604 = ramfuc_reg(0x10f604);
1479 ram->fuc.r_0x10f614 = ramfuc_reg(0x10f614);
1480 ram->fuc.r_0x10f610 = ramfuc_reg(0x10f610);
1481 ram->fuc.r_0x100770 = ramfuc_reg(0x100770);
1482 ram->fuc.r_0x100778 = ramfuc_reg(0x100778);
1483 ram->fuc.r_0x10f224 = ramfuc_reg(0x10f224);
1485 ram->fuc.r_0x10f870 = ramfuc_reg(0x10f870);
1486 ram->fuc.r_0x10f698 = ramfuc_reg(0x10f698);
1487 ram->fuc.r_0x10f694 = ramfuc_reg(0x10f694);
1488 ram->fuc.r_0x10f6b8 = ramfuc_reg(0x10f6b8);
1489 ram->fuc.r_0x10f808 = ramfuc_reg(0x10f808);
1490 ram->fuc.r_0x10f670 = ramfuc_reg(0x10f670);
1491 ram->fuc.r_0x10f60c = ramfuc_reg(0x10f60c);
1492 ram->fuc.r_0x10f830 = ramfuc_reg(0x10f830);
1493 ram->fuc.r_0x1373ec = ramfuc_reg(0x1373ec);
1494 ram->fuc.r_0x10f800 = ramfuc_reg(0x10f800);
1495 ram->fuc.r_0x10f82c = ramfuc_reg(0x10f82c);
1497 ram->fuc.r_0x10f978 = ramfuc_reg(0x10f978);
1498 ram->fuc.r_0x10f910 = ramfuc_reg(0x10f910);
1499 ram->fuc.r_0x10f914 = ramfuc_reg(0x10f914);
1501 switch (ram->base.type) {
1502 case NV_MEM_TYPE_GDDR5:
1503 ram->fuc.r_mr[0] = ramfuc_reg(0x10f300);
1504 ram->fuc.r_mr[1] = ramfuc_reg(0x10f330);
1505 ram->fuc.r_mr[2] = ramfuc_reg(0x10f334);
1506 ram->fuc.r_mr[3] = ramfuc_reg(0x10f338);
1507 ram->fuc.r_mr[4] = ramfuc_reg(0x10f33c);
1508 ram->fuc.r_mr[5] = ramfuc_reg(0x10f340);
1509 ram->fuc.r_mr[6] = ramfuc_reg(0x10f344);
1510 ram->fuc.r_mr[7] = ramfuc_reg(0x10f348);
1511 ram->fuc.r_mr[8] = ramfuc_reg(0x10f354);
1512 ram->fuc.r_mr[15] = ramfuc_reg(0x10f34c);
1514 case NV_MEM_TYPE_DDR3:
1515 ram->fuc.r_mr[0] = ramfuc_reg(0x10f300);
1516 ram->fuc.r_mr[2] = ramfuc_reg(0x10f320);
1522 ram->fuc.r_0x62c000 = ramfuc_reg(0x62c000);
1523 ram->fuc.r_0x10f200 = ramfuc_reg(0x10f200);
1524 ram->fuc.r_0x10f210 = ramfuc_reg(0x10f210);
1525 ram->fuc.r_0x10f310 = ramfuc_reg(0x10f310);
1526 ram->fuc.r_0x10f314 = ramfuc_reg(0x10f314);
1527 ram->fuc.r_0x10f318 = ramfuc_reg(0x10f318);
1528 ram->fuc.r_0x10f090 = ramfuc_reg(0x10f090);
1529 ram->fuc.r_0x10f69c = ramfuc_reg(0x10f69c);
1530 ram->fuc.r_0x10f824 = ramfuc_reg(0x10f824);
1531 ram->fuc.r_0x1373f0 = ramfuc_reg(0x1373f0);
1532 ram->fuc.r_0x1373f4 = ramfuc_reg(0x1373f4);
1533 ram->fuc.r_0x137320 = ramfuc_reg(0x137320);
1534 ram->fuc.r_0x10f65c = ramfuc_reg(0x10f65c);
1535 ram->fuc.r_0x10f6bc = ramfuc_reg(0x10f6bc);
1536 ram->fuc.r_0x100710 = ramfuc_reg(0x100710);
1537 ram->fuc.r_0x100750 = ramfuc_reg(0x100750);
1541 struct nouveau_oclass
1544 .ofuncs = &(struct nouveau_ofuncs) {
1545 .ctor = nve0_ram_ctor,
1546 .dtor = nve0_ram_dtor,
1547 .init = nve0_ram_init,
1548 .fini = _nouveau_ram_fini,