2 * Copyright 2010 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.
26 #include "nouveau_drm.h"
27 #include "nouveau_bios.h"
28 #include "dispnv04/hw.h"
29 #include "nouveau_pm.h"
30 #include "nouveau_hwsq.h"
32 #include "nv50_display.h"
34 #include <subdev/bios/pll.h>
35 #include <subdev/clock.h>
36 #include <subdev/timer.h>
37 #include <subdev/fb.h>
53 static u32
read_clk(struct drm_device
*, enum clk_src
);
56 read_div(struct drm_device
*dev
)
58 struct nouveau_device
*device
= nouveau_dev(dev
);
59 struct nouveau_drm
*drm
= nouveau_drm(dev
);
61 switch (nv_device(drm
->device
)->chipset
) {
62 case 0x50: /* it exists, but only has bit 31, not the dividers.. */
67 return nv_rd32(device
, 0x004700);
71 return nv_rd32(device
, 0x004800);
78 read_pll_src(struct drm_device
*dev
, u32 base
)
80 struct nouveau_device
*device
= nouveau_dev(dev
);
81 struct nouveau_drm
*drm
= nouveau_drm(dev
);
82 u32 coef
, ref
= read_clk(dev
, clk_src_crystal
);
83 u32 rsel
= nv_rd32(device
, 0x00e18c);
86 switch (nv_device(drm
->device
)->chipset
) {
91 case 0x4028: id
= !!(rsel
& 0x00000004); break;
92 case 0x4008: id
= !!(rsel
& 0x00000008); break;
93 case 0x4030: id
= 0; break;
95 NV_ERROR(drm
, "ref: bad pll 0x%06x\n", base
);
99 coef
= nv_rd32(device
, 0x00e81c + (id
* 0x0c));
100 ref
*= (coef
& 0x01000000) ? 2 : 4;
101 P
= (coef
& 0x00070000) >> 16;
102 N
= ((coef
& 0x0000ff00) >> 8) + 1;
103 M
= ((coef
& 0x000000ff) >> 0) + 1;
108 coef
= nv_rd32(device
, 0x00e81c);
109 P
= (coef
& 0x00070000) >> 16;
110 N
= (coef
& 0x0000ff00) >> 8;
111 M
= (coef
& 0x000000ff) >> 0;
116 rsel
= nv_rd32(device
, 0x00c050);
118 case 0x4020: rsel
= (rsel
& 0x00000003) >> 0; break;
119 case 0x4008: rsel
= (rsel
& 0x0000000c) >> 2; break;
120 case 0x4028: rsel
= (rsel
& 0x00001800) >> 11; break;
121 case 0x4030: rsel
= 3; break;
123 NV_ERROR(drm
, "ref: bad pll 0x%06x\n", base
);
128 case 0: id
= 1; break;
129 case 1: return read_clk(dev
, clk_src_crystal
);
130 case 2: return read_clk(dev
, clk_src_href
);
131 case 3: id
= 0; break;
134 coef
= nv_rd32(device
, 0x00e81c + (id
* 0x28));
135 P
= (nv_rd32(device
, 0x00e824 + (id
* 0x28)) >> 16) & 7;
136 P
+= (coef
& 0x00070000) >> 16;
137 N
= (coef
& 0x0000ff00) >> 8;
138 M
= (coef
& 0x000000ff) >> 0;
145 return (ref
* N
/ M
) >> P
;
150 read_pll_ref(struct drm_device
*dev
, u32 base
)
152 struct nouveau_device
*device
= nouveau_dev(dev
);
153 struct nouveau_drm
*drm
= nouveau_drm(dev
);
154 u32 src
, mast
= nv_rd32(device
, 0x00c040);
158 src
= !!(mast
& 0x00200000);
161 src
= !!(mast
& 0x00400000);
164 src
= !!(mast
& 0x00010000);
167 src
= !!(mast
& 0x02000000);
170 return read_clk(dev
, clk_src_crystal
);
172 NV_ERROR(drm
, "bad pll 0x%06x\n", base
);
177 return read_clk(dev
, clk_src_href
);
178 return read_pll_src(dev
, base
);
182 read_pll(struct drm_device
*dev
, u32 base
)
184 struct nouveau_device
*device
= nouveau_dev(dev
);
185 struct nouveau_drm
*drm
= nouveau_drm(dev
);
186 u32 mast
= nv_rd32(device
, 0x00c040);
187 u32 ctrl
= nv_rd32(device
, base
+ 0);
188 u32 coef
= nv_rd32(device
, base
+ 4);
189 u32 ref
= read_pll_ref(dev
, base
);
193 if (base
== 0x004028 && (mast
& 0x00100000)) {
194 /* wtf, appears to only disable post-divider on nva0 */
195 if (nv_device(drm
->device
)->chipset
!= 0xa0)
196 return read_clk(dev
, clk_src_dom6
);
199 N2
= (coef
& 0xff000000) >> 24;
200 M2
= (coef
& 0x00ff0000) >> 16;
201 N1
= (coef
& 0x0000ff00) >> 8;
202 M1
= (coef
& 0x000000ff);
203 if ((ctrl
& 0x80000000) && M1
) {
205 if ((ctrl
& 0x40000100) == 0x40000000) {
217 read_clk(struct drm_device
*dev
, enum clk_src src
)
219 struct nouveau_device
*device
= nouveau_dev(dev
);
220 struct nouveau_drm
*drm
= nouveau_drm(dev
);
221 u32 mast
= nv_rd32(device
, 0x00c040);
225 case clk_src_crystal
:
226 return device
->crystal
;
228 return 100000; /* PCIE reference clock */
230 return read_clk(dev
, clk_src_href
) * 27778 / 10000;
232 return read_clk(dev
, clk_src_hclk
) * 3;
233 case clk_src_hclkm3d2
:
234 return read_clk(dev
, clk_src_hclk
) * 3 / 2;
236 switch (mast
& 0x30000000) {
237 case 0x00000000: return read_clk(dev
, clk_src_href
);
238 case 0x10000000: break;
239 case 0x20000000: /* !0x50 */
240 case 0x30000000: return read_clk(dev
, clk_src_hclk
);
244 if (!(mast
& 0x00100000))
245 P
= (nv_rd32(device
, 0x004028) & 0x00070000) >> 16;
246 switch (mast
& 0x00000003) {
247 case 0x00000000: return read_clk(dev
, clk_src_crystal
) >> P
;
248 case 0x00000001: return read_clk(dev
, clk_src_dom6
);
249 case 0x00000002: return read_pll(dev
, 0x004020) >> P
;
250 case 0x00000003: return read_pll(dev
, 0x004028) >> P
;
254 P
= (nv_rd32(device
, 0x004020) & 0x00070000) >> 16;
255 switch (mast
& 0x00000030) {
257 if (mast
& 0x00000080)
258 return read_clk(dev
, clk_src_host
) >> P
;
259 return read_clk(dev
, clk_src_crystal
) >> P
;
260 case 0x00000010: break;
261 case 0x00000020: return read_pll(dev
, 0x004028) >> P
;
262 case 0x00000030: return read_pll(dev
, 0x004020) >> P
;
266 P
= (nv_rd32(device
, 0x004008) & 0x00070000) >> 16;
267 if (nv_rd32(device
, 0x004008) & 0x00000200) {
268 switch (mast
& 0x0000c000) {
270 return read_clk(dev
, clk_src_crystal
) >> P
;
273 return read_clk(dev
, clk_src_href
) >> P
;
276 return read_pll(dev
, 0x004008) >> P
;
280 P
= (read_div(dev
) & 0x00000700) >> 8;
281 switch (nv_device(drm
->device
)->chipset
) {
288 switch (mast
& 0x00000c00) {
290 if (nv_device(drm
->device
)->chipset
== 0xa0) /* wtf?? */
291 return read_clk(dev
, clk_src_nvclk
) >> P
;
292 return read_clk(dev
, clk_src_crystal
) >> P
;
296 if (mast
& 0x01000000)
297 return read_pll(dev
, 0x004028) >> P
;
298 return read_pll(dev
, 0x004030) >> P
;
300 return read_clk(dev
, clk_src_nvclk
) >> P
;
304 switch (mast
& 0x00000c00) {
306 return read_clk(dev
, clk_src_nvclk
) >> P
;
310 return read_clk(dev
, clk_src_hclkm3d2
) >> P
;
312 return read_clk(dev
, clk_src_mclk
) >> P
;
318 switch (nv_device(drm
->device
)->chipset
) {
321 return read_pll(dev
, 0x00e810) >> 2;
328 P
= (read_div(dev
) & 0x00000007) >> 0;
329 switch (mast
& 0x0c000000) {
330 case 0x00000000: return read_clk(dev
, clk_src_href
);
331 case 0x04000000: break;
332 case 0x08000000: return read_clk(dev
, clk_src_hclk
);
334 return read_clk(dev
, clk_src_hclkm3
) >> P
;
344 NV_DEBUG(drm
, "unknown clock source %d 0x%08x\n", src
, mast
);
349 nv50_pm_clocks_get(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
351 struct nouveau_drm
*drm
= nouveau_drm(dev
);
352 if (nv_device(drm
->device
)->chipset
== 0xaa ||
353 nv_device(drm
->device
)->chipset
== 0xac)
356 perflvl
->core
= read_clk(dev
, clk_src_nvclk
);
357 perflvl
->shader
= read_clk(dev
, clk_src_sclk
);
358 perflvl
->memory
= read_clk(dev
, clk_src_mclk
);
359 if (nv_device(drm
->device
)->chipset
!= 0x50) {
360 perflvl
->vdec
= read_clk(dev
, clk_src_vdec
);
361 perflvl
->dom6
= read_clk(dev
, clk_src_dom6
);
367 struct nv50_pm_state
{
368 struct nouveau_pm_level
*perflvl
;
369 struct hwsq_ucode eclk_hwsq
;
370 struct hwsq_ucode mclk_hwsq
;
378 calc_pll(struct drm_device
*dev
, u32 reg
, struct nvbios_pll
*pll
,
379 u32 clk
, int *N1
, int *M1
, int *log2P
)
381 struct nouveau_device
*device
= nouveau_dev(dev
);
382 struct nouveau_bios
*bios
= nouveau_bios(device
);
383 struct nouveau_clock
*pclk
= nouveau_clock(device
);
384 struct nouveau_pll_vals coef
;
387 ret
= nvbios_pll_parse(bios
, reg
, pll
);
391 pll
->vco2
.max_freq
= 0;
392 pll
->refclk
= read_pll_ref(dev
, reg
);
396 ret
= pclk
->pll_calc(pclk
, pll
, clk
, &coef
);
407 calc_div(u32 src
, u32 target
, int *div
)
409 u32 clk0
= src
, clk1
= src
;
410 for (*div
= 0; *div
<= 7; (*div
)++) {
411 if (clk0
<= target
) {
412 clk1
= clk0
<< (*div
? 1 : 0);
418 if (target
- clk0
<= clk1
- target
)
425 clk_same(u32 a
, u32 b
)
427 return ((a
/ 1000) == (b
/ 1000));
431 mclk_precharge(struct nouveau_mem_exec_func
*exec
)
433 struct nv50_pm_state
*info
= exec
->priv
;
434 struct hwsq_ucode
*hwsq
= &info
->mclk_hwsq
;
436 hwsq_wr32(hwsq
, 0x1002d4, 0x00000001);
440 mclk_refresh(struct nouveau_mem_exec_func
*exec
)
442 struct nv50_pm_state
*info
= exec
->priv
;
443 struct hwsq_ucode
*hwsq
= &info
->mclk_hwsq
;
445 hwsq_wr32(hwsq
, 0x1002d0, 0x00000001);
449 mclk_refresh_auto(struct nouveau_mem_exec_func
*exec
, bool enable
)
451 struct nv50_pm_state
*info
= exec
->priv
;
452 struct hwsq_ucode
*hwsq
= &info
->mclk_hwsq
;
454 hwsq_wr32(hwsq
, 0x100210, enable
? 0x80000000 : 0x00000000);
458 mclk_refresh_self(struct nouveau_mem_exec_func
*exec
, bool enable
)
460 struct nv50_pm_state
*info
= exec
->priv
;
461 struct hwsq_ucode
*hwsq
= &info
->mclk_hwsq
;
463 hwsq_wr32(hwsq
, 0x1002dc, enable
? 0x00000001 : 0x00000000);
467 mclk_wait(struct nouveau_mem_exec_func
*exec
, u32 nsec
)
469 struct nv50_pm_state
*info
= exec
->priv
;
470 struct hwsq_ucode
*hwsq
= &info
->mclk_hwsq
;
473 hwsq_usec(hwsq
, (nsec
+ 500) / 1000);
477 mclk_mrg(struct nouveau_mem_exec_func
*exec
, int mr
)
479 struct nouveau_device
*device
= nouveau_dev(exec
->dev
);
481 return nv_rd32(device
, 0x1002c0 + ((mr
- 0) * 4));
483 return nv_rd32(device
, 0x1002e0 + ((mr
- 2) * 4));
488 mclk_mrs(struct nouveau_mem_exec_func
*exec
, int mr
, u32 data
)
490 struct nouveau_device
*device
= nouveau_dev(exec
->dev
);
491 struct nouveau_fb
*pfb
= nouveau_fb(device
);
492 struct nv50_pm_state
*info
= exec
->priv
;
493 struct hwsq_ucode
*hwsq
= &info
->mclk_hwsq
;
496 if (pfb
->ram
->ranks
> 1)
497 hwsq_wr32(hwsq
, 0x1002c8 + ((mr
- 0) * 4), data
);
498 hwsq_wr32(hwsq
, 0x1002c0 + ((mr
- 0) * 4), data
);
501 if (pfb
->ram
->ranks
> 1)
502 hwsq_wr32(hwsq
, 0x1002e8 + ((mr
- 2) * 4), data
);
503 hwsq_wr32(hwsq
, 0x1002e0 + ((mr
- 2) * 4), data
);
508 mclk_clock_set(struct nouveau_mem_exec_func
*exec
)
510 struct nouveau_device
*device
= nouveau_dev(exec
->dev
);
511 struct nv50_pm_state
*info
= exec
->priv
;
512 struct hwsq_ucode
*hwsq
= &info
->mclk_hwsq
;
513 u32 ctrl
= nv_rd32(device
, 0x004008);
515 info
->mmast
= nv_rd32(device
, 0x00c040);
516 info
->mmast
&= ~0xc0000000; /* get MCLK_2 from HREF */
517 info
->mmast
|= 0x0000c000; /* use MCLK_2 as MPLL_BYPASS clock */
519 hwsq_wr32(hwsq
, 0xc040, info
->mmast
);
520 hwsq_wr32(hwsq
, 0x4008, ctrl
| 0x00000200); /* bypass MPLL */
521 if (info
->mctrl
& 0x80000000)
522 hwsq_wr32(hwsq
, 0x400c, info
->mcoef
);
523 hwsq_wr32(hwsq
, 0x4008, info
->mctrl
);
527 mclk_timing_set(struct nouveau_mem_exec_func
*exec
)
529 struct nouveau_device
*device
= nouveau_dev(exec
->dev
);
530 struct nv50_pm_state
*info
= exec
->priv
;
531 struct nouveau_pm_level
*perflvl
= info
->perflvl
;
532 struct hwsq_ucode
*hwsq
= &info
->mclk_hwsq
;
535 for (i
= 0; i
< 9; i
++) {
536 u32 reg
= 0x100220 + (i
* 4);
537 u32 val
= nv_rd32(device
, reg
);
538 if (val
!= perflvl
->timing
.reg
[i
])
539 hwsq_wr32(hwsq
, reg
, perflvl
->timing
.reg
[i
]);
544 calc_mclk(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
,
545 struct nv50_pm_state
*info
)
547 struct nouveau_drm
*drm
= nouveau_drm(dev
);
548 struct nouveau_device
*device
= nouveau_dev(dev
);
549 u32 crtc_mask
= 0; /*XXX: nv50_display_active_crtcs(dev); */
550 struct nouveau_mem_exec_func exec
= {
552 .precharge
= mclk_precharge
,
553 .refresh
= mclk_refresh
,
554 .refresh_auto
= mclk_refresh_auto
,
555 .refresh_self
= mclk_refresh_self
,
559 .clock_set
= mclk_clock_set
,
560 .timing_set
= mclk_timing_set
,
563 struct hwsq_ucode
*hwsq
= &info
->mclk_hwsq
;
564 struct nvbios_pll pll
;
568 /* use pcie refclock if possible, otherwise use mpll */
569 info
->mctrl
= nv_rd32(device
, 0x004008);
570 info
->mctrl
&= ~0x81ff0200;
571 if (clk_same(perflvl
->memory
, read_clk(dev
, clk_src_href
))) {
572 info
->mctrl
|= 0x00000200 | (pll
.bias_p
<< 19);
574 ret
= calc_pll(dev
, 0x4008, &pll
, perflvl
->memory
, &N
, &M
, &P
);
578 info
->mctrl
|= 0x80000000 | (P
<< 22) | (P
<< 16);
579 info
->mctrl
|= pll
.bias_p
<< 19;
580 info
->mcoef
= (N
<< 8) | M
;
583 /* build the ucode which will reclock the memory for us */
586 hwsq_op5f(hwsq
, crtc_mask
, 0x00); /* wait for scanout */
587 hwsq_op5f(hwsq
, crtc_mask
, 0x01); /* wait for vblank */
589 if (nv_device(drm
->device
)->chipset
>= 0x92)
590 hwsq_wr32(hwsq
, 0x611200, 0x00003300); /* disable scanout */
591 hwsq_setf(hwsq
, 0x10, 0); /* disable bus access */
592 hwsq_op5f(hwsq
, 0x00, 0x01); /* no idea :s */
594 ret
= nouveau_mem_exec(&exec
, perflvl
);
598 hwsq_setf(hwsq
, 0x10, 1); /* enable bus access */
599 hwsq_op5f(hwsq
, 0x00, 0x00); /* no idea, reverse of 0x00, 0x01? */
600 if (nv_device(drm
->device
)->chipset
>= 0x92)
601 hwsq_wr32(hwsq
, 0x611200, 0x00003330); /* enable scanout */
607 nv50_pm_clocks_pre(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
609 struct nouveau_device
*device
= nouveau_dev(dev
);
610 struct nouveau_drm
*drm
= nouveau_drm(dev
);
611 struct nv50_pm_state
*info
;
612 struct hwsq_ucode
*hwsq
;
613 struct nvbios_pll pll
;
614 u32 out
, mast
, divs
, ctrl
;
615 int clk
, ret
= -EINVAL
;
618 if (nv_device(drm
->device
)->chipset
== 0xaa ||
619 nv_device(drm
->device
)->chipset
== 0xac)
620 return ERR_PTR(-ENODEV
);
622 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
624 return ERR_PTR(-ENOMEM
);
625 info
->perflvl
= perflvl
;
627 /* memory: build hwsq ucode which we'll use to reclock memory.
628 * use pcie refclock if possible, otherwise use mpll */
629 info
->mclk_hwsq
.len
= 0;
630 if (perflvl
->memory
) {
631 ret
= calc_mclk(dev
, perflvl
, info
);
634 info
->mscript
= perflvl
->memscript
;
637 divs
= read_div(dev
);
640 /* start building HWSQ script for engine reclocking */
641 hwsq
= &info
->eclk_hwsq
;
643 hwsq_setf(hwsq
, 0x10, 0); /* disable bus access */
644 hwsq_op5f(hwsq
, 0x00, 0x01); /* wait for access disabled? */
646 /* vdec/dom6: switch to "safe" clocks temporarily */
657 hwsq_wr32(hwsq
, 0x00c040, mast
);
659 /* vdec: avoid modifying xpll until we know exactly how the other
660 * clock domains work, i suspect at least some of them can also be
664 /* see how close we can get using nvclk as a source */
665 clk
= calc_div(perflvl
->core
, perflvl
->vdec
, &P1
);
667 /* see how close we can get using xpll/hclk as a source */
668 if (nv_device(drm
->device
)->chipset
!= 0x98)
669 out
= read_pll(dev
, 0x004030);
671 out
= read_clk(dev
, clk_src_hclkm3d2
);
672 out
= calc_div(out
, perflvl
->vdec
, &P2
);
674 /* select whichever gets us closest */
675 if (abs((int)perflvl
->vdec
- clk
) <=
676 abs((int)perflvl
->vdec
- out
)) {
677 if (nv_device(drm
->device
)->chipset
!= 0x98)
686 /* dom6: nfi what this is, but we're limited to various combinations
687 * of the host clock frequency
690 if (clk_same(perflvl
->dom6
, read_clk(dev
, clk_src_href
))) {
693 if (clk_same(perflvl
->dom6
, read_clk(dev
, clk_src_hclk
))) {
696 clk
= read_clk(dev
, clk_src_hclk
) * 3;
697 clk
= calc_div(clk
, perflvl
->dom6
, &P1
);
704 /* vdec/dom6: complete switch to new clocks */
705 switch (nv_device(drm
->device
)->chipset
) {
709 hwsq_wr32(hwsq
, 0x004800, divs
);
712 hwsq_wr32(hwsq
, 0x004700, divs
);
716 hwsq_wr32(hwsq
, 0x00c040, mast
);
718 /* core/shader: make sure sclk/nvclk are disconnected from their
719 * PLLs (nvclk to dom6, sclk to hclk)
721 if (nv_device(drm
->device
)->chipset
< 0x92)
722 mast
= (mast
& ~0x001000b0) | 0x00100080;
724 mast
= (mast
& ~0x000000b3) | 0x00000081;
726 hwsq_wr32(hwsq
, 0x00c040, mast
);
728 /* core: for the moment at least, always use nvpll */
729 clk
= calc_pll(dev
, 0x4028, &pll
, perflvl
->core
, &N
, &M
, &P1
);
733 ctrl
= nv_rd32(device
, 0x004028) & ~0xc03f0100;
737 hwsq_wr32(hwsq
, 0x004028, 0x80000000 | (P1
<< 19) | (P1
<< 16) | ctrl
);
738 hwsq_wr32(hwsq
, 0x00402c, (N
<< 8) | M
);
740 /* shader: tie to nvclk if possible, otherwise use spll. have to be
741 * very careful that the shader clock is at least twice the core, or
742 * some chipsets will be very unhappy. i expect most or all of these
743 * cases will be handled by tying to nvclk, but it's possible there's
746 ctrl
= nv_rd32(device
, 0x004020) & ~0xc03f0100;
748 if (P1
-- && perflvl
->shader
== (perflvl
->core
<< 1)) {
749 hwsq_wr32(hwsq
, 0x004020, (P1
<< 19) | (P1
<< 16) | ctrl
);
750 hwsq_wr32(hwsq
, 0x00c040, 0x00000020 | mast
);
752 clk
= calc_pll(dev
, 0x4020, &pll
, perflvl
->shader
, &N
, &M
, &P1
);
757 hwsq_wr32(hwsq
, 0x004020, (P1
<< 19) | (P1
<< 16) | ctrl
);
758 hwsq_wr32(hwsq
, 0x004024, (N
<< 8) | M
);
759 hwsq_wr32(hwsq
, 0x00c040, 0x00000030 | mast
);
762 hwsq_setf(hwsq
, 0x10, 1); /* enable bus access */
763 hwsq_op5f(hwsq
, 0x00, 0x00); /* wait for access enabled? */
773 prog_hwsq(struct drm_device
*dev
, struct hwsq_ucode
*hwsq
)
775 struct nouveau_device
*device
= nouveau_dev(dev
);
776 struct nouveau_drm
*drm
= nouveau_drm(dev
);
777 u32 hwsq_data
, hwsq_kick
;
780 if (nv_device(drm
->device
)->chipset
< 0x94) {
781 hwsq_data
= 0x001400;
782 hwsq_kick
= 0x00000003;
784 hwsq_data
= 0x080000;
785 hwsq_kick
= 0x00000001;
787 /* upload hwsq ucode */
788 nv_mask(device
, 0x001098, 0x00000008, 0x00000000);
789 nv_wr32(device
, 0x001304, 0x00000000);
790 if (nv_device(drm
->device
)->chipset
>= 0x92)
791 nv_wr32(device
, 0x001318, 0x00000000);
792 for (i
= 0; i
< hwsq
->len
/ 4; i
++)
793 nv_wr32(device
, hwsq_data
+ (i
* 4), hwsq
->ptr
.u32
[i
]);
794 nv_mask(device
, 0x001098, 0x00000018, 0x00000018);
796 /* launch, and wait for completion */
797 nv_wr32(device
, 0x00130c, hwsq_kick
);
798 if (!nv_wait(device
, 0x001308, 0x00000100, 0x00000000)) {
799 NV_ERROR(drm
, "hwsq ucode exec timed out\n");
800 NV_ERROR(drm
, "0x001308: 0x%08x\n", nv_rd32(device
, 0x001308));
801 for (i
= 0; i
< hwsq
->len
/ 4; i
++) {
802 NV_ERROR(drm
, "0x%06x: 0x%08x\n", 0x1400 + (i
* 4),
803 nv_rd32(device
, 0x001400 + (i
* 4)));
813 nv50_pm_clocks_set(struct drm_device
*dev
, void *data
)
815 struct nouveau_device
*device
= nouveau_dev(dev
);
816 struct nv50_pm_state
*info
= data
;
820 /* halt and idle execution engines */
821 nv_mask(device
, 0x002504, 0x00000001, 0x00000001);
822 if (!nv_wait(device
, 0x002504, 0x00000010, 0x00000010))
824 if (!nv_wait(device
, 0x00251c, 0x0000003f, 0x0000003f))
827 /* program memory clock, if necessary - must come before engine clock
828 * reprogramming due to how we construct the hwsq scripts in pre()
830 #define nouveau_bios_init_exec(a,b) nouveau_bios_run_init_table((a), (b), NULL, 0)
831 if (info
->mclk_hwsq
.len
) {
832 /* execute some scripts that do ??? from the vbios.. */
833 if (!bit_table(dev
, 'M', &M
) && M
.version
== 1) {
835 nouveau_bios_init_exec(dev
, ROM16(M
.data
[5]));
837 nouveau_bios_init_exec(dev
, ROM16(M
.data
[7]));
839 nouveau_bios_init_exec(dev
, ROM16(M
.data
[9]));
840 nouveau_bios_init_exec(dev
, info
->mscript
);
843 ret
= prog_hwsq(dev
, &info
->mclk_hwsq
);
848 /* program engine clocks */
849 ret
= prog_hwsq(dev
, &info
->eclk_hwsq
);
852 nv_mask(device
, 0x002504, 0x00000001, 0x00000000);