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/bios.h>
26 #include <subdev/bios/bit.h>
27 #include <subdev/bios/pll.h>
28 #include <subdev/bios/rammap.h>
29 #include <subdev/bios/timing.h>
31 #include <subdev/clock/nva3.h>
32 #include <subdev/clock/pll.h>
34 #include <core/option.h>
42 struct ramfuc_reg r_0x004000
;
43 struct ramfuc_reg r_0x004004
;
44 struct ramfuc_reg r_0x004018
;
45 struct ramfuc_reg r_0x004128
;
46 struct ramfuc_reg r_0x004168
;
47 struct ramfuc_reg r_0x100200
;
48 struct ramfuc_reg r_0x100210
;
49 struct ramfuc_reg r_0x100220
[9];
50 struct ramfuc_reg r_0x1002d0
;
51 struct ramfuc_reg r_0x1002d4
;
52 struct ramfuc_reg r_0x1002dc
;
53 struct ramfuc_reg r_0x10053c
;
54 struct ramfuc_reg r_0x1005a0
;
55 struct ramfuc_reg r_0x1005a4
;
56 struct ramfuc_reg r_0x100714
;
57 struct ramfuc_reg r_0x100718
;
58 struct ramfuc_reg r_0x10071c
;
59 struct ramfuc_reg r_0x100760
;
60 struct ramfuc_reg r_0x1007a0
;
61 struct ramfuc_reg r_0x1007e0
;
62 struct ramfuc_reg r_0x10f804
;
63 struct ramfuc_reg r_0x1110e0
;
64 struct ramfuc_reg r_0x111100
;
65 struct ramfuc_reg r_0x111104
;
66 struct ramfuc_reg r_0x611200
;
67 struct ramfuc_reg r_mr
[4];
71 struct nouveau_ram base
;
72 struct nva3_ramfuc fuc
;
76 nva3_ram_calc(struct nouveau_fb
*pfb
, u32 freq
)
78 struct nouveau_bios
*bios
= nouveau_bios(pfb
);
79 struct nva3_ram
*ram
= (void *)pfb
->ram
;
80 struct nva3_ramfuc
*fuc
= &ram
->fuc
;
81 struct nva3_clock_info mclk
;
88 } rammap
, ramcfg
, timing
;
89 u32 r004018
, r100760
, ctrl
;
90 u32 unk714
, unk718
, unk71c
;
93 /* lookup memory config data relevant to the target frequency */
94 rammap
.data
= nvbios_rammap_match(bios
, freq
/ 1000, &ver
, &rammap
.size
,
96 if (!rammap
.data
|| ver
!= 0x10 || rammap
.size
< 0x0e) {
97 nv_error(pfb
, "invalid/missing rammap entry\n");
101 /* locate specific data set for the attached memory */
102 if (bit_entry(bios
, 'M', &M
) || M
.version
!= 2 || M
.length
< 3) {
103 nv_error(pfb
, "invalid/missing memory table\n");
107 strap
= (nv_rd32(pfb
, 0x101000) & 0x0000003c) >> 2;
108 data
= nv_ro16(bios
, M
.offset
+ 1);
110 strap
= nv_ro08(bios
, data
+ strap
);
113 nv_error(pfb
, "invalid ramcfg strap\n");
117 ramcfg
.data
= rammap
.data
+ rammap
.size
+ (strap
* ramcfg
.size
);
118 if (!ramcfg
.data
|| ver
!= 0x10 || ramcfg
.size
< 0x0e) {
119 nv_error(pfb
, "invalid/missing ramcfg entry\n");
123 /* lookup memory timings, if bios says they're present */
124 strap
= nv_ro08(bios
, ramcfg
.data
+ 0x01);
126 timing
.data
= nvbios_timing_entry(bios
, strap
, &ver
,
128 if (!timing
.data
|| ver
!= 0x10 || timing
.size
< 0x19) {
129 nv_error(pfb
, "invalid/missing timing entry\n");
136 ret
= nva3_clock_info(nouveau_clock(pfb
), 0x12, 0x4000, freq
, &mclk
);
138 nv_error(pfb
, "failed mclk calculation\n");
142 ret
= ram_init(fuc
, pfb
);
146 /* XXX: where the fuck does 750MHz come from? */
147 if (freq
<= 750000) {
148 r004018
= 0x10000000;
149 r100760
= 0x22222222;
151 r004018
= 0x00000000;
152 r100760
= 0x00000000;
155 ctrl
= ram_rd32(fuc
, 0x004000);
156 if (ctrl
& 0x00000008) {
158 ram_mask(fuc
, 0x004128, 0x00000101, 0x00000101);
159 ram_wr32(fuc
, 0x004004, mclk
.pll
);
160 ram_wr32(fuc
, 0x004000, (ctrl
|= 0x00000001));
161 ram_wr32(fuc
, 0x004000, (ctrl
&= 0xffffffef));
162 ram_wait(fuc
, 0x004000, 0x00020000, 0x00020000, 64000);
163 ram_wr32(fuc
, 0x004000, (ctrl
|= 0x00000010));
164 ram_wr32(fuc
, 0x004018, 0x00005000 | r004018
);
165 ram_wr32(fuc
, 0x004000, (ctrl
|= 0x00000004));
168 u32 ssel
= 0x00000101;
172 ssel
|= 0x00080000; /* 324MHz, shouldn't matter... */
173 ram_mask(fuc
, 0x004168, 0x003f3141, ctrl
);
176 if ( (nv_ro08(bios
, ramcfg
.data
+ 0x02) & 0x10)) {
177 ram_mask(fuc
, 0x111104, 0x00000600, 0x00000000);
179 ram_mask(fuc
, 0x111100, 0x40000000, 0x40000000);
180 ram_mask(fuc
, 0x111104, 0x00000180, 0x00000000);
183 if (!(nv_ro08(bios
, rammap
.data
+ 0x04) & 0x02))
184 ram_mask(fuc
, 0x100200, 0x00000800, 0x00000000);
185 ram_wr32(fuc
, 0x611200, 0x00003300);
186 if (!(nv_ro08(bios
, ramcfg
.data
+ 0x02) & 0x10))
187 ram_wr32(fuc
, 0x111100, 0x4c020000); /*XXX*/
189 ram_wr32(fuc
, 0x1002d4, 0x00000001);
190 ram_wr32(fuc
, 0x1002d0, 0x00000001);
191 ram_wr32(fuc
, 0x1002d0, 0x00000001);
192 ram_wr32(fuc
, 0x100210, 0x00000000);
193 ram_wr32(fuc
, 0x1002dc, 0x00000001);
196 ctrl
= ram_rd32(fuc
, 0x004000);
197 if (!(ctrl
& 0x00000008) && mclk
.pll
) {
198 ram_wr32(fuc
, 0x004000, (ctrl
|= 0x00000008));
199 ram_mask(fuc
, 0x1110e0, 0x00088000, 0x00088000);
200 ram_wr32(fuc
, 0x004018, 0x00001000);
201 ram_wr32(fuc
, 0x004000, (ctrl
&= ~0x00000001));
202 ram_wr32(fuc
, 0x004004, mclk
.pll
);
203 ram_wr32(fuc
, 0x004000, (ctrl
|= 0x00000001));
205 ram_wr32(fuc
, 0x004018, 0x00005000 | r004018
);
209 ram_mask(fuc
, 0x004168, 0x003f3040, mclk
.clk
);
210 ram_wr32(fuc
, 0x004000, (ctrl
|= 0x00000008));
211 ram_mask(fuc
, 0x1110e0, 0x00088000, 0x00088000);
212 ram_wr32(fuc
, 0x004018, 0x0000d000 | r004018
);
215 if ( (nv_ro08(bios
, rammap
.data
+ 0x04) & 0x08)) {
216 u32 unk5a0
= (nv_ro16(bios
, ramcfg
.data
+ 0x05) << 8) |
217 nv_ro08(bios
, ramcfg
.data
+ 0x05);
218 u32 unk5a4
= (nv_ro16(bios
, ramcfg
.data
+ 0x07));
219 u32 unk804
= (nv_ro08(bios
, ramcfg
.data
+ 0x09) & 0xf0) << 16 |
220 (nv_ro08(bios
, ramcfg
.data
+ 0x03) & 0x0f) << 16 |
221 (nv_ro08(bios
, ramcfg
.data
+ 0x09) & 0x0f) |
223 ram_wr32(fuc
, 0x1005a0, unk5a0
);
224 ram_wr32(fuc
, 0x1005a4, unk5a4
);
225 ram_wr32(fuc
, 0x10f804, unk804
);
226 ram_mask(fuc
, 0x10053c, 0x00001000, 0x00000000);
228 ram_mask(fuc
, 0x10053c, 0x00001000, 0x00001000);
229 ram_mask(fuc
, 0x10f804, 0x80000000, 0x00000000);
230 ram_mask(fuc
, 0x100760, 0x22222222, r100760
);
231 ram_mask(fuc
, 0x1007a0, 0x22222222, r100760
);
232 ram_mask(fuc
, 0x1007e0, 0x22222222, r100760
);
236 ram_mask(fuc
, 0x1110e0, 0x00088000, 0x00011000);
237 ram_wr32(fuc
, 0x004000, (ctrl
&= ~0x00000008));
241 ram_wr32(fuc
, 0x1002dc, 0x00000000);
242 ram_wr32(fuc
, 0x1002d4, 0x00000001);
243 ram_wr32(fuc
, 0x100210, 0x80000000);
247 ram_mask(fuc
, mr
[2], 0x00000000, 0x00000000);
249 ram_nuke(fuc
, mr
[0]);
250 ram_mask(fuc
, mr
[0], 0x00000000, 0x00000000);
253 ram_mask(fuc
, 0x100220[3], 0x00000000, 0x00000000);
254 ram_mask(fuc
, 0x100220[1], 0x00000000, 0x00000000);
255 ram_mask(fuc
, 0x100220[6], 0x00000000, 0x00000000);
256 ram_mask(fuc
, 0x100220[7], 0x00000000, 0x00000000);
257 ram_mask(fuc
, 0x100220[2], 0x00000000, 0x00000000);
258 ram_mask(fuc
, 0x100220[4], 0x00000000, 0x00000000);
259 ram_mask(fuc
, 0x100220[5], 0x00000000, 0x00000000);
260 ram_mask(fuc
, 0x100220[0], 0x00000000, 0x00000000);
261 ram_mask(fuc
, 0x100220[8], 0x00000000, 0x00000000);
263 data
= (nv_ro08(bios
, ramcfg
.data
+ 0x02) & 0x08) ? 0x00000000 : 0x00001000;
264 ram_mask(fuc
, 0x100200, 0x00001000, data
);
266 unk714
= ram_rd32(fuc
, 0x100714) & ~0xf0000010;
267 unk718
= ram_rd32(fuc
, 0x100718) & ~0x00000100;
268 unk71c
= ram_rd32(fuc
, 0x10071c) & ~0x00000100;
269 if ( (nv_ro08(bios
, ramcfg
.data
+ 0x02) & 0x20))
270 unk714
|= 0xf0000000;
271 if (!(nv_ro08(bios
, ramcfg
.data
+ 0x02) & 0x04))
272 unk714
|= 0x00000010;
273 ram_wr32(fuc
, 0x100714, unk714
);
275 if (nv_ro08(bios
, ramcfg
.data
+ 0x02) & 0x01)
276 unk71c
|= 0x00000100;
277 ram_wr32(fuc
, 0x10071c, unk71c
);
279 if (nv_ro08(bios
, ramcfg
.data
+ 0x02) & 0x02)
280 unk718
|= 0x00000100;
281 ram_wr32(fuc
, 0x100718, unk718
);
283 if (nv_ro08(bios
, ramcfg
.data
+ 0x02) & 0x10)
284 ram_wr32(fuc
, 0x111100, 0x48000000); /*XXX*/
286 ram_mask(fuc
, mr
[0], 0x100, 0x100);
288 ram_mask(fuc
, mr
[0], 0x100, 0x000);
292 ram_nsec(fuc
, 12000);
294 ram_wr32(fuc
, 0x611200, 0x00003330);
295 if ( (nv_ro08(bios
, rammap
.data
+ 0x04) & 0x02))
296 ram_mask(fuc
, 0x100200, 0x00000800, 0x00000800);
297 if ( (nv_ro08(bios
, ramcfg
.data
+ 0x02) & 0x10)) {
298 ram_mask(fuc
, 0x111104, 0x00000180, 0x00000180);
299 ram_mask(fuc
, 0x111100, 0x40000000, 0x00000000);
301 ram_mask(fuc
, 0x111104, 0x00000600, 0x00000600);
305 ram_mask(fuc
, 0x004168, 0x00000001, 0x00000000);
306 ram_mask(fuc
, 0x004168, 0x00000100, 0x00000000);
308 ram_mask(fuc
, 0x004000, 0x00000001, 0x00000000);
309 ram_mask(fuc
, 0x004128, 0x00000001, 0x00000000);
310 ram_mask(fuc
, 0x004128, 0x00000100, 0x00000000);
317 nva3_ram_prog(struct nouveau_fb
*pfb
)
319 struct nouveau_device
*device
= nv_device(pfb
);
320 struct nva3_ram
*ram
= (void *)pfb
->ram
;
321 struct nva3_ramfuc
*fuc
= &ram
->fuc
;
322 ram_exec(fuc
, nouveau_boolopt(device
->cfgopt
, "NvMemExec", false));
327 nva3_ram_tidy(struct nouveau_fb
*pfb
)
329 struct nva3_ram
*ram
= (void *)pfb
->ram
;
330 struct nva3_ramfuc
*fuc
= &ram
->fuc
;
331 ram_exec(fuc
, false);
335 nva3_ram_init(struct nouveau_object
*object
)
337 struct nouveau_fb
*pfb
= (void *)object
->parent
;
338 struct nva3_ram
*ram
= (void *)object
;
341 ret
= nouveau_ram_init(&ram
->base
);
345 /* prepare for ddr link training, and load training patterns */
346 switch (ram
->base
.type
) {
347 case NV_MEM_TYPE_DDR3
: {
348 static const u32 pattern
[16] = {
349 0xaaaaaaaa, 0xcccccccc, 0xdddddddd, 0xeeeeeeee,
350 0x00000000, 0x11111111, 0x44444444, 0xdddddddd,
351 0x33333333, 0x55555555, 0x77777777, 0x66666666,
352 0x99999999, 0x88888888, 0xeeeeeeee, 0xbbbbbbbb,
355 nv_wr32(pfb
, 0x100538, 0x10001ff6); /*XXX*/
356 nv_wr32(pfb
, 0x1005a8, 0x0000ffff);
357 nv_mask(pfb
, 0x10f800, 0x00000001, 0x00000001);
358 for (i
= 0; i
< 0x30; i
++) {
359 nv_wr32(pfb
, 0x10f8c0, (i
<< 8) | i
);
360 nv_wr32(pfb
, 0x10f8e0, (i
<< 8) | i
);
361 nv_wr32(pfb
, 0x10f900, pattern
[i
% 16]);
362 nv_wr32(pfb
, 0x10f920, pattern
[i
% 16]);
374 nva3_ram_ctor(struct nouveau_object
*parent
, struct nouveau_object
*engine
,
375 struct nouveau_oclass
*oclass
, void *data
, u32 datasize
,
376 struct nouveau_object
**pobject
)
378 struct nva3_ram
*ram
;
381 ret
= nv50_ram_create(parent
, engine
, oclass
, &ram
);
382 *pobject
= nv_object(ram
);
386 switch (ram
->base
.type
) {
387 case NV_MEM_TYPE_DDR3
:
388 ram
->base
.calc
= nva3_ram_calc
;
389 ram
->base
.prog
= nva3_ram_prog
;
390 ram
->base
.tidy
= nva3_ram_tidy
;
393 nv_warn(ram
, "reclocking of this ram type unsupported\n");
397 ram
->fuc
.r_0x004000
= ramfuc_reg(0x004000);
398 ram
->fuc
.r_0x004004
= ramfuc_reg(0x004004);
399 ram
->fuc
.r_0x004018
= ramfuc_reg(0x004018);
400 ram
->fuc
.r_0x004128
= ramfuc_reg(0x004128);
401 ram
->fuc
.r_0x004168
= ramfuc_reg(0x004168);
402 ram
->fuc
.r_0x100200
= ramfuc_reg(0x100200);
403 ram
->fuc
.r_0x100210
= ramfuc_reg(0x100210);
404 for (i
= 0; i
< 9; i
++)
405 ram
->fuc
.r_0x100220
[i
] = ramfuc_reg(0x100220 + (i
* 4));
406 ram
->fuc
.r_0x1002d0
= ramfuc_reg(0x1002d0);
407 ram
->fuc
.r_0x1002d4
= ramfuc_reg(0x1002d4);
408 ram
->fuc
.r_0x1002dc
= ramfuc_reg(0x1002dc);
409 ram
->fuc
.r_0x10053c
= ramfuc_reg(0x10053c);
410 ram
->fuc
.r_0x1005a0
= ramfuc_reg(0x1005a0);
411 ram
->fuc
.r_0x1005a4
= ramfuc_reg(0x1005a4);
412 ram
->fuc
.r_0x100714
= ramfuc_reg(0x100714);
413 ram
->fuc
.r_0x100718
= ramfuc_reg(0x100718);
414 ram
->fuc
.r_0x10071c
= ramfuc_reg(0x10071c);
415 ram
->fuc
.r_0x100760
= ramfuc_reg(0x100760);
416 ram
->fuc
.r_0x1007a0
= ramfuc_reg(0x1007a0);
417 ram
->fuc
.r_0x1007e0
= ramfuc_reg(0x1007e0);
418 ram
->fuc
.r_0x10f804
= ramfuc_reg(0x10f804);
419 ram
->fuc
.r_0x1110e0
= ramfuc_reg(0x1110e0);
420 ram
->fuc
.r_0x111100
= ramfuc_reg(0x111100);
421 ram
->fuc
.r_0x111104
= ramfuc_reg(0x111104);
422 ram
->fuc
.r_0x611200
= ramfuc_reg(0x611200);
424 if (ram
->base
.ranks
> 1) {
425 ram
->fuc
.r_mr
[0] = ramfuc_reg2(0x1002c0, 0x1002c8);
426 ram
->fuc
.r_mr
[1] = ramfuc_reg2(0x1002c4, 0x1002cc);
427 ram
->fuc
.r_mr
[2] = ramfuc_reg2(0x1002e0, 0x1002e8);
428 ram
->fuc
.r_mr
[3] = ramfuc_reg2(0x1002e4, 0x1002ec);
430 ram
->fuc
.r_mr
[0] = ramfuc_reg(0x1002c0);
431 ram
->fuc
.r_mr
[1] = ramfuc_reg(0x1002c4);
432 ram
->fuc
.r_mr
[2] = ramfuc_reg(0x1002e0);
433 ram
->fuc
.r_mr
[3] = ramfuc_reg(0x1002e4);
439 struct nouveau_oclass
441 .ofuncs
= &(struct nouveau_ofuncs
) {
442 .ctor
= nva3_ram_ctor
,
443 .dtor
= _nouveau_ram_dtor
,
444 .init
= nva3_ram_init
,
445 .fini
= _nouveau_ram_fini
,
This page took 0.044374 seconds and 5 git commands to generate.