Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/nouveau/drm/pm: remove everything except the hwmon interfaces to THERM

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>

+70 -4838
+1 -3
drivers/gpu/drm/nouveau/Makefile
··· 270 270 nouveau-y += nv50_display.o 271 271 272 272 # drm/pm 273 - nouveau-y += nouveau_pm.o nouveau_volt.o nouveau_perf.o 274 - nouveau-y += nv04_pm.o nv40_pm.o nv50_pm.o nva3_pm.o nvc0_pm.o 275 - nouveau-y += nouveau_mem.o 273 + nouveau-y += nouveau_hwmon.o 276 274 277 275 # other random bits 278 276 nouveau-$(CONFIG_COMPAT) += nouveau_ioc32.o
+3 -6
drivers/gpu/drm/nouveau/nouveau_drm.c
··· 46 46 #include "nouveau_gem.h" 47 47 #include "nouveau_agp.h" 48 48 #include "nouveau_vga.h" 49 - #include "nouveau_pm.h" 49 + #include "nouveau_hwmon.h" 50 50 #include "nouveau_acpi.h" 51 51 #include "nouveau_bios.h" 52 52 #include "nouveau_ioctl.h" ··· 384 384 goto fail_dispinit; 385 385 } 386 386 387 - nouveau_pm_init(dev); 388 - 387 + nouveau_hwmon_init(dev); 389 388 nouveau_accel_init(drm); 390 389 nouveau_fbcon_init(dev); 391 390 ··· 420 421 pm_runtime_get_sync(dev->dev); 421 422 nouveau_fbcon_fini(dev); 422 423 nouveau_accel_fini(drm); 423 - 424 - nouveau_pm_fini(dev); 424 + nouveau_hwmon_fini(dev); 425 425 426 426 if (dev->mode_config.num_crtc) 427 427 nouveau_display_fini(dev); ··· 560 562 } 561 563 562 564 nouveau_run_vbios_init(dev); 563 - nouveau_pm_resume(dev); 564 565 565 566 if (dev->mode_config.num_crtc) { 566 567 NV_INFO(drm, "resuming display...\n");
+1 -1
drivers/gpu/drm/nouveau/nouveau_drm.h
··· 129 129 struct backlight_device *backlight; 130 130 131 131 /* power management */ 132 - struct nouveau_pm *pm; 132 + struct nouveau_hwmon *hwmon; 133 133 134 134 /* display power reference */ 135 135 bool have_disp_power_ref;
+43
drivers/gpu/drm/nouveau/nouveau_hwmon.h
··· 1 + /* 2 + * Copyright 2010 Red Hat Inc. 3 + * 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: 10 + * 11 + * The above copyright notice and this permission notice shall be included in 12 + * all copies or substantial portions of the Software. 13 + * 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. 21 + * 22 + * Authors: Ben Skeggs 23 + */ 24 + 25 + #ifndef __NOUVEAU_PM_H__ 26 + #define __NOUVEAU_PM_H__ 27 + 28 + struct nouveau_hwmon { 29 + struct drm_device *dev; 30 + struct device *hwmon; 31 + }; 32 + 33 + static inline struct nouveau_hwmon * 34 + nouveau_hwmon(struct drm_device *dev) 35 + { 36 + return nouveau_drm(dev)->hwmon; 37 + } 38 + 39 + /* nouveau_hwmon.c */ 40 + int nouveau_hwmon_init(struct drm_device *dev); 41 + void nouveau_hwmon_fini(struct drm_device *dev); 42 + 43 + #endif
-115
drivers/gpu/drm/nouveau/nouveau_hwsq.h
··· 1 - /* 2 - * Copyright 2010 Red Hat Inc. 3 - * 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: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 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. 21 - * 22 - * Authors: Ben Skeggs 23 - */ 24 - 25 - #ifndef __NOUVEAU_HWSQ_H__ 26 - #define __NOUVEAU_HWSQ_H__ 27 - 28 - struct hwsq_ucode { 29 - u8 data[0x200]; 30 - union { 31 - u8 *u08; 32 - u16 *u16; 33 - u32 *u32; 34 - } ptr; 35 - u16 len; 36 - 37 - u32 reg; 38 - u32 val; 39 - }; 40 - 41 - static inline void 42 - hwsq_init(struct hwsq_ucode *hwsq) 43 - { 44 - hwsq->ptr.u08 = hwsq->data; 45 - hwsq->reg = 0xffffffff; 46 - hwsq->val = 0xffffffff; 47 - } 48 - 49 - static inline void 50 - hwsq_fini(struct hwsq_ucode *hwsq) 51 - { 52 - do { 53 - *hwsq->ptr.u08++ = 0x7f; 54 - hwsq->len = hwsq->ptr.u08 - hwsq->data; 55 - } while (hwsq->len & 3); 56 - hwsq->ptr.u08 = hwsq->data; 57 - } 58 - 59 - static inline void 60 - hwsq_usec(struct hwsq_ucode *hwsq, u8 usec) 61 - { 62 - u32 shift = 0; 63 - while (usec & ~3) { 64 - usec >>= 2; 65 - shift++; 66 - } 67 - 68 - *hwsq->ptr.u08++ = (shift << 2) | usec; 69 - } 70 - 71 - static inline void 72 - hwsq_setf(struct hwsq_ucode *hwsq, u8 flag, int val) 73 - { 74 - flag += 0x80; 75 - if (val >= 0) 76 - flag += 0x20; 77 - if (val >= 1) 78 - flag += 0x20; 79 - *hwsq->ptr.u08++ = flag; 80 - } 81 - 82 - static inline void 83 - hwsq_op5f(struct hwsq_ucode *hwsq, u8 v0, u8 v1) 84 - { 85 - *hwsq->ptr.u08++ = 0x5f; 86 - *hwsq->ptr.u08++ = v0; 87 - *hwsq->ptr.u08++ = v1; 88 - } 89 - 90 - static inline void 91 - hwsq_wr32(struct hwsq_ucode *hwsq, u32 reg, u32 val) 92 - { 93 - if (val != hwsq->val) { 94 - if ((val & 0xffff0000) == (hwsq->val & 0xffff0000)) { 95 - *hwsq->ptr.u08++ = 0x42; 96 - *hwsq->ptr.u16++ = (val & 0x0000ffff); 97 - } else { 98 - *hwsq->ptr.u08++ = 0xe2; 99 - *hwsq->ptr.u32++ = val; 100 - } 101 - 102 - hwsq->val = val; 103 - } 104 - 105 - if ((reg & 0xffff0000) == (hwsq->reg & 0xffff0000)) { 106 - *hwsq->ptr.u08++ = 0x40; 107 - *hwsq->ptr.u16++ = (reg & 0x0000ffff); 108 - } else { 109 - *hwsq->ptr.u08++ = 0xe0; 110 - *hwsq->ptr.u32++ = reg; 111 - } 112 - hwsq->reg = reg; 113 - } 114 - 115 - #endif
-647
drivers/gpu/drm/nouveau/nouveau_mem.c
··· 1 - /* 2 - * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 3 - * Copyright 2005 Stephane Marchesin 4 - * 5 - * The Weather Channel (TM) funded Tungsten Graphics to develop the 6 - * initial release of the Radeon 8500 driver under the XFree86 license. 7 - * This notice must be preserved. 8 - * 9 - * Permission is hereby granted, free of charge, to any person obtaining a 10 - * copy of this software and associated documentation files (the "Software"), 11 - * to deal in the Software without restriction, including without limitation 12 - * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 - * and/or sell copies of the Software, and to permit persons to whom the 14 - * Software is furnished to do so, subject to the following conditions: 15 - * 16 - * The above copyright notice and this permission notice (including the next 17 - * paragraph) shall be included in all copies or substantial portions of the 18 - * Software. 19 - * 20 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 - * THE AUTHORS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 25 - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 - * DEALINGS IN THE SOFTWARE. 27 - * 28 - * Authors: 29 - * Ben Skeggs <bskeggs@redhat.com> 30 - * Roy Spliet <r.spliet@student.tudelft.nl> 31 - */ 32 - 33 - #include "nouveau_drm.h" 34 - #include "nouveau_pm.h" 35 - 36 - #include <subdev/fb.h> 37 - 38 - static int 39 - nv40_mem_timing_calc(struct drm_device *dev, u32 freq, 40 - struct nouveau_pm_tbl_entry *e, u8 len, 41 - struct nouveau_pm_memtiming *boot, 42 - struct nouveau_pm_memtiming *t) 43 - { 44 - struct nouveau_drm *drm = nouveau_drm(dev); 45 - 46 - t->reg[0] = (e->tRP << 24 | e->tRAS << 16 | e->tRFC << 8 | e->tRC); 47 - 48 - /* XXX: I don't trust the -1's and +1's... they must come 49 - * from somewhere! */ 50 - t->reg[1] = (e->tWR + 2 + (t->tCWL - 1)) << 24 | 51 - 1 << 16 | 52 - (e->tWTR + 2 + (t->tCWL - 1)) << 8 | 53 - (e->tCL + 2 - (t->tCWL - 1)); 54 - 55 - t->reg[2] = 0x20200000 | 56 - ((t->tCWL - 1) << 24 | 57 - e->tRRD << 16 | 58 - e->tRCDWR << 8 | 59 - e->tRCDRD); 60 - 61 - NV_DEBUG(drm, "Entry %d: 220: %08x %08x %08x\n", t->id, 62 - t->reg[0], t->reg[1], t->reg[2]); 63 - return 0; 64 - } 65 - 66 - static int 67 - nv50_mem_timing_calc(struct drm_device *dev, u32 freq, 68 - struct nouveau_pm_tbl_entry *e, u8 len, 69 - struct nouveau_pm_memtiming *boot, 70 - struct nouveau_pm_memtiming *t) 71 - { 72 - struct nouveau_device *device = nouveau_dev(dev); 73 - struct nouveau_fb *pfb = nouveau_fb(device); 74 - struct nouveau_drm *drm = nouveau_drm(dev); 75 - struct bit_entry P; 76 - uint8_t unk18 = 1, unk20 = 0, unk21 = 0, tmp7_3; 77 - 78 - if (bit_table(dev, 'P', &P)) 79 - return -EINVAL; 80 - 81 - switch (min(len, (u8) 22)) { 82 - case 22: 83 - unk21 = e->tUNK_21; 84 - case 21: 85 - unk20 = e->tUNK_20; 86 - case 20: 87 - if (e->tCWL > 0) 88 - t->tCWL = e->tCWL; 89 - case 19: 90 - unk18 = e->tUNK_18; 91 - break; 92 - } 93 - 94 - t->reg[0] = (e->tRP << 24 | e->tRAS << 16 | e->tRFC << 8 | e->tRC); 95 - 96 - t->reg[1] = (e->tWR + 2 + (t->tCWL - 1)) << 24 | 97 - max(unk18, (u8) 1) << 16 | 98 - (e->tWTR + 2 + (t->tCWL - 1)) << 8; 99 - 100 - t->reg[2] = ((t->tCWL - 1) << 24 | 101 - e->tRRD << 16 | 102 - e->tRCDWR << 8 | 103 - e->tRCDRD); 104 - 105 - t->reg[4] = e->tUNK_13 << 8 | e->tUNK_13; 106 - 107 - t->reg[5] = (e->tRFC << 24 | max(e->tRCDRD, e->tRCDWR) << 16 | e->tRP); 108 - 109 - t->reg[8] = boot->reg[8] & 0xffffff00; 110 - 111 - if (P.version == 1) { 112 - t->reg[1] |= (e->tCL + 2 - (t->tCWL - 1)); 113 - 114 - t->reg[3] = (0x14 + e->tCL) << 24 | 115 - 0x16 << 16 | 116 - (e->tCL - 1) << 8 | 117 - (e->tCL - 1); 118 - 119 - t->reg[4] |= boot->reg[4] & 0xffff0000; 120 - 121 - t->reg[6] = (0x33 - t->tCWL) << 16 | 122 - t->tCWL << 8 | 123 - (0x2e + e->tCL - t->tCWL); 124 - 125 - t->reg[7] = 0x4000202 | (e->tCL - 1) << 16; 126 - 127 - /* XXX: P.version == 1 only has DDR2 and GDDR3? */ 128 - if (pfb->ram->type == NV_MEM_TYPE_DDR2) { 129 - t->reg[5] |= (e->tCL + 3) << 8; 130 - t->reg[6] |= (t->tCWL - 2) << 8; 131 - t->reg[8] |= (e->tCL - 4); 132 - } else { 133 - t->reg[5] |= (e->tCL + 2) << 8; 134 - t->reg[6] |= t->tCWL << 8; 135 - t->reg[8] |= (e->tCL - 2); 136 - } 137 - } else { 138 - t->reg[1] |= (5 + e->tCL - (t->tCWL)); 139 - 140 - /* XXX: 0xb? 0x30? */ 141 - t->reg[3] = (0x30 + e->tCL) << 24 | 142 - (boot->reg[3] & 0x00ff0000)| 143 - (0xb + e->tCL) << 8 | 144 - (e->tCL - 1); 145 - 146 - t->reg[4] |= (unk20 << 24 | unk21 << 16); 147 - 148 - /* XXX: +6? */ 149 - t->reg[5] |= (t->tCWL + 6) << 8; 150 - 151 - t->reg[6] = (0x5a + e->tCL) << 16 | 152 - (6 - e->tCL + t->tCWL) << 8 | 153 - (0x50 + e->tCL - t->tCWL); 154 - 155 - tmp7_3 = (boot->reg[7] & 0xff000000) >> 24; 156 - t->reg[7] = (tmp7_3 << 24) | 157 - ((tmp7_3 - 6 + e->tCL) << 16) | 158 - 0x202; 159 - } 160 - 161 - NV_DEBUG(drm, "Entry %d: 220: %08x %08x %08x %08x\n", t->id, 162 - t->reg[0], t->reg[1], t->reg[2], t->reg[3]); 163 - NV_DEBUG(drm, " 230: %08x %08x %08x %08x\n", 164 - t->reg[4], t->reg[5], t->reg[6], t->reg[7]); 165 - NV_DEBUG(drm, " 240: %08x\n", t->reg[8]); 166 - return 0; 167 - } 168 - 169 - static int 170 - nvc0_mem_timing_calc(struct drm_device *dev, u32 freq, 171 - struct nouveau_pm_tbl_entry *e, u8 len, 172 - struct nouveau_pm_memtiming *boot, 173 - struct nouveau_pm_memtiming *t) 174 - { 175 - struct nouveau_drm *drm = nouveau_drm(dev); 176 - 177 - if (e->tCWL > 0) 178 - t->tCWL = e->tCWL; 179 - 180 - t->reg[0] = (e->tRP << 24 | (e->tRAS & 0x7f) << 17 | 181 - e->tRFC << 8 | e->tRC); 182 - 183 - t->reg[1] = (boot->reg[1] & 0xff000000) | 184 - (e->tRCDWR & 0x0f) << 20 | 185 - (e->tRCDRD & 0x0f) << 14 | 186 - (t->tCWL << 7) | 187 - (e->tCL & 0x0f); 188 - 189 - t->reg[2] = (boot->reg[2] & 0xff0000ff) | 190 - e->tWR << 16 | e->tWTR << 8; 191 - 192 - t->reg[3] = (e->tUNK_20 & 0x1f) << 9 | 193 - (e->tUNK_21 & 0xf) << 5 | 194 - (e->tUNK_13 & 0x1f); 195 - 196 - t->reg[4] = (boot->reg[4] & 0xfff00fff) | 197 - (e->tRRD&0x1f) << 15; 198 - 199 - NV_DEBUG(drm, "Entry %d: 290: %08x %08x %08x %08x\n", t->id, 200 - t->reg[0], t->reg[1], t->reg[2], t->reg[3]); 201 - NV_DEBUG(drm, " 2a0: %08x\n", t->reg[4]); 202 - return 0; 203 - } 204 - 205 - /** 206 - * MR generation methods 207 - */ 208 - 209 - static int 210 - nouveau_mem_ddr2_mr(struct drm_device *dev, u32 freq, 211 - struct nouveau_pm_tbl_entry *e, u8 len, 212 - struct nouveau_pm_memtiming *boot, 213 - struct nouveau_pm_memtiming *t) 214 - { 215 - struct nouveau_drm *drm = nouveau_drm(dev); 216 - 217 - t->drive_strength = 0; 218 - if (len < 15) { 219 - t->odt = boot->odt; 220 - } else { 221 - t->odt = e->RAM_FT1 & 0x07; 222 - } 223 - 224 - if (e->tCL >= NV_MEM_CL_DDR2_MAX) { 225 - NV_WARN(drm, "(%u) Invalid tCL: %u", t->id, e->tCL); 226 - return -ERANGE; 227 - } 228 - 229 - if (e->tWR >= NV_MEM_WR_DDR2_MAX) { 230 - NV_WARN(drm, "(%u) Invalid tWR: %u", t->id, e->tWR); 231 - return -ERANGE; 232 - } 233 - 234 - if (t->odt > 3) { 235 - NV_WARN(drm, "(%u) Invalid odt value, assuming disabled: %x", 236 - t->id, t->odt); 237 - t->odt = 0; 238 - } 239 - 240 - t->mr[0] = (boot->mr[0] & 0x100f) | 241 - (e->tCL) << 4 | 242 - (e->tWR - 1) << 9; 243 - t->mr[1] = (boot->mr[1] & 0x101fbb) | 244 - (t->odt & 0x1) << 2 | 245 - (t->odt & 0x2) << 5; 246 - 247 - NV_DEBUG(drm, "(%u) MR: %08x", t->id, t->mr[0]); 248 - return 0; 249 - } 250 - 251 - static const uint8_t nv_mem_wr_lut_ddr3[NV_MEM_WR_DDR3_MAX] = { 252 - 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 0, 0}; 253 - 254 - static int 255 - nouveau_mem_ddr3_mr(struct drm_device *dev, u32 freq, 256 - struct nouveau_pm_tbl_entry *e, u8 len, 257 - struct nouveau_pm_memtiming *boot, 258 - struct nouveau_pm_memtiming *t) 259 - { 260 - struct nouveau_drm *drm = nouveau_drm(dev); 261 - u8 cl = e->tCL - 4; 262 - 263 - t->drive_strength = 0; 264 - if (len < 15) { 265 - t->odt = boot->odt; 266 - } else { 267 - t->odt = e->RAM_FT1 & 0x07; 268 - } 269 - 270 - if (e->tCL >= NV_MEM_CL_DDR3_MAX || e->tCL < 4) { 271 - NV_WARN(drm, "(%u) Invalid tCL: %u", t->id, e->tCL); 272 - return -ERANGE; 273 - } 274 - 275 - if (e->tWR >= NV_MEM_WR_DDR3_MAX || e->tWR < 4) { 276 - NV_WARN(drm, "(%u) Invalid tWR: %u", t->id, e->tWR); 277 - return -ERANGE; 278 - } 279 - 280 - if (e->tCWL < 5) { 281 - NV_WARN(drm, "(%u) Invalid tCWL: %u", t->id, e->tCWL); 282 - return -ERANGE; 283 - } 284 - 285 - t->mr[0] = (boot->mr[0] & 0x180b) | 286 - /* CAS */ 287 - (cl & 0x7) << 4 | 288 - (cl & 0x8) >> 1 | 289 - (nv_mem_wr_lut_ddr3[e->tWR]) << 9; 290 - t->mr[1] = (boot->mr[1] & 0x101dbb) | 291 - (t->odt & 0x1) << 2 | 292 - (t->odt & 0x2) << 5 | 293 - (t->odt & 0x4) << 7; 294 - t->mr[2] = (boot->mr[2] & 0x20ffb7) | (e->tCWL - 5) << 3; 295 - 296 - NV_DEBUG(drm, "(%u) MR: %08x %08x", t->id, t->mr[0], t->mr[2]); 297 - return 0; 298 - } 299 - 300 - static const uint8_t nv_mem_cl_lut_gddr3[NV_MEM_CL_GDDR3_MAX] = { 301 - 0, 0, 0, 0, 4, 5, 6, 7, 0, 1, 2, 3, 8, 9, 10, 11}; 302 - static const uint8_t nv_mem_wr_lut_gddr3[NV_MEM_WR_GDDR3_MAX] = { 303 - 0, 0, 0, 0, 0, 2, 3, 8, 9, 10, 11, 0, 0, 1, 1, 0, 3}; 304 - 305 - static int 306 - nouveau_mem_gddr3_mr(struct drm_device *dev, u32 freq, 307 - struct nouveau_pm_tbl_entry *e, u8 len, 308 - struct nouveau_pm_memtiming *boot, 309 - struct nouveau_pm_memtiming *t) 310 - { 311 - struct nouveau_drm *drm = nouveau_drm(dev); 312 - 313 - if (len < 15) { 314 - t->drive_strength = boot->drive_strength; 315 - t->odt = boot->odt; 316 - } else { 317 - t->drive_strength = (e->RAM_FT1 & 0x30) >> 4; 318 - t->odt = e->RAM_FT1 & 0x07; 319 - } 320 - 321 - if (e->tCL >= NV_MEM_CL_GDDR3_MAX) { 322 - NV_WARN(drm, "(%u) Invalid tCL: %u", t->id, e->tCL); 323 - return -ERANGE; 324 - } 325 - 326 - if (e->tWR >= NV_MEM_WR_GDDR3_MAX) { 327 - NV_WARN(drm, "(%u) Invalid tWR: %u", t->id, e->tWR); 328 - return -ERANGE; 329 - } 330 - 331 - if (t->odt > 3) { 332 - NV_WARN(drm, "(%u) Invalid odt value, assuming autocal: %x", 333 - t->id, t->odt); 334 - t->odt = 0; 335 - } 336 - 337 - t->mr[0] = (boot->mr[0] & 0xe0b) | 338 - /* CAS */ 339 - ((nv_mem_cl_lut_gddr3[e->tCL] & 0x7) << 4) | 340 - ((nv_mem_cl_lut_gddr3[e->tCL] & 0x8) >> 2); 341 - t->mr[1] = (boot->mr[1] & 0x100f40) | t->drive_strength | 342 - (t->odt << 2) | 343 - (nv_mem_wr_lut_gddr3[e->tWR] & 0xf) << 4; 344 - t->mr[2] = boot->mr[2]; 345 - 346 - NV_DEBUG(drm, "(%u) MR: %08x %08x %08x", t->id, 347 - t->mr[0], t->mr[1], t->mr[2]); 348 - return 0; 349 - } 350 - 351 - static int 352 - nouveau_mem_gddr5_mr(struct drm_device *dev, u32 freq, 353 - struct nouveau_pm_tbl_entry *e, u8 len, 354 - struct nouveau_pm_memtiming *boot, 355 - struct nouveau_pm_memtiming *t) 356 - { 357 - struct nouveau_drm *drm = nouveau_drm(dev); 358 - 359 - if (len < 15) { 360 - t->drive_strength = boot->drive_strength; 361 - t->odt = boot->odt; 362 - } else { 363 - t->drive_strength = (e->RAM_FT1 & 0x30) >> 4; 364 - t->odt = e->RAM_FT1 & 0x03; 365 - } 366 - 367 - if (e->tCL >= NV_MEM_CL_GDDR5_MAX) { 368 - NV_WARN(drm, "(%u) Invalid tCL: %u", t->id, e->tCL); 369 - return -ERANGE; 370 - } 371 - 372 - if (e->tWR >= NV_MEM_WR_GDDR5_MAX) { 373 - NV_WARN(drm, "(%u) Invalid tWR: %u", t->id, e->tWR); 374 - return -ERANGE; 375 - } 376 - 377 - if (t->odt > 3) { 378 - NV_WARN(drm, "(%u) Invalid odt value, assuming autocal: %x", 379 - t->id, t->odt); 380 - t->odt = 0; 381 - } 382 - 383 - t->mr[0] = (boot->mr[0] & 0x007) | 384 - ((e->tCL - 5) << 3) | 385 - ((e->tWR - 4) << 8); 386 - t->mr[1] = (boot->mr[1] & 0x1007f0) | 387 - t->drive_strength | 388 - (t->odt << 2); 389 - 390 - NV_DEBUG(drm, "(%u) MR: %08x %08x", t->id, t->mr[0], t->mr[1]); 391 - return 0; 392 - } 393 - 394 - int 395 - nouveau_mem_timing_calc(struct drm_device *dev, u32 freq, 396 - struct nouveau_pm_memtiming *t) 397 - { 398 - struct nouveau_device *device = nouveau_dev(dev); 399 - struct nouveau_fb *pfb = nouveau_fb(device); 400 - struct nouveau_pm *pm = nouveau_pm(dev); 401 - struct nouveau_pm_memtiming *boot = &pm->boot.timing; 402 - struct nouveau_pm_tbl_entry *e; 403 - u8 ver, len, *ptr, *ramcfg; 404 - int ret; 405 - 406 - ptr = nouveau_perf_timing(dev, freq, &ver, &len); 407 - if (!ptr || ptr[0] == 0x00) { 408 - *t = *boot; 409 - return 0; 410 - } 411 - e = (struct nouveau_pm_tbl_entry *)ptr; 412 - 413 - t->tCWL = boot->tCWL; 414 - 415 - switch (device->card_type) { 416 - case NV_40: 417 - ret = nv40_mem_timing_calc(dev, freq, e, len, boot, t); 418 - break; 419 - case NV_50: 420 - ret = nv50_mem_timing_calc(dev, freq, e, len, boot, t); 421 - break; 422 - case NV_C0: 423 - case NV_D0: 424 - ret = nvc0_mem_timing_calc(dev, freq, e, len, boot, t); 425 - break; 426 - default: 427 - ret = -ENODEV; 428 - break; 429 - } 430 - 431 - switch (pfb->ram->type * !ret) { 432 - case NV_MEM_TYPE_GDDR3: 433 - ret = nouveau_mem_gddr3_mr(dev, freq, e, len, boot, t); 434 - break; 435 - case NV_MEM_TYPE_GDDR5: 436 - ret = nouveau_mem_gddr5_mr(dev, freq, e, len, boot, t); 437 - break; 438 - case NV_MEM_TYPE_DDR2: 439 - ret = nouveau_mem_ddr2_mr(dev, freq, e, len, boot, t); 440 - break; 441 - case NV_MEM_TYPE_DDR3: 442 - ret = nouveau_mem_ddr3_mr(dev, freq, e, len, boot, t); 443 - break; 444 - default: 445 - ret = -EINVAL; 446 - break; 447 - } 448 - 449 - ramcfg = nouveau_perf_ramcfg(dev, freq, &ver, &len); 450 - if (ramcfg) { 451 - int dll_off; 452 - 453 - if (ver == 0x00) 454 - dll_off = !!(ramcfg[3] & 0x04); 455 - else 456 - dll_off = !!(ramcfg[2] & 0x40); 457 - 458 - switch (pfb->ram->type) { 459 - case NV_MEM_TYPE_GDDR3: 460 - t->mr[1] &= ~0x00000040; 461 - t->mr[1] |= 0x00000040 * dll_off; 462 - break; 463 - default: 464 - t->mr[1] &= ~0x00000001; 465 - t->mr[1] |= 0x00000001 * dll_off; 466 - break; 467 - } 468 - } 469 - 470 - return ret; 471 - } 472 - 473 - void 474 - nouveau_mem_timing_read(struct drm_device *dev, struct nouveau_pm_memtiming *t) 475 - { 476 - struct nouveau_device *device = nouveau_dev(dev); 477 - struct nouveau_fb *pfb = nouveau_fb(device); 478 - u32 timing_base, timing_regs, mr_base; 479 - int i; 480 - 481 - if (device->card_type >= 0xC0) { 482 - timing_base = 0x10f290; 483 - mr_base = 0x10f300; 484 - } else { 485 - timing_base = 0x100220; 486 - mr_base = 0x1002c0; 487 - } 488 - 489 - t->id = -1; 490 - 491 - switch (device->card_type) { 492 - case NV_50: 493 - timing_regs = 9; 494 - break; 495 - case NV_C0: 496 - case NV_D0: 497 - timing_regs = 5; 498 - break; 499 - case NV_30: 500 - case NV_40: 501 - timing_regs = 3; 502 - break; 503 - default: 504 - timing_regs = 0; 505 - return; 506 - } 507 - for(i = 0; i < timing_regs; i++) 508 - t->reg[i] = nv_rd32(device, timing_base + (0x04 * i)); 509 - 510 - t->tCWL = 0; 511 - if (device->card_type < NV_C0) { 512 - t->tCWL = ((nv_rd32(device, 0x100228) & 0x0f000000) >> 24) + 1; 513 - } else if (device->card_type <= NV_D0) { 514 - t->tCWL = ((nv_rd32(device, 0x10f294) & 0x00000f80) >> 7); 515 - } 516 - 517 - t->mr[0] = nv_rd32(device, mr_base); 518 - t->mr[1] = nv_rd32(device, mr_base + 0x04); 519 - t->mr[2] = nv_rd32(device, mr_base + 0x20); 520 - t->mr[3] = nv_rd32(device, mr_base + 0x24); 521 - 522 - t->odt = 0; 523 - t->drive_strength = 0; 524 - 525 - switch (pfb->ram->type) { 526 - case NV_MEM_TYPE_DDR3: 527 - t->odt |= (t->mr[1] & 0x200) >> 7; 528 - case NV_MEM_TYPE_DDR2: 529 - t->odt |= (t->mr[1] & 0x04) >> 2 | 530 - (t->mr[1] & 0x40) >> 5; 531 - break; 532 - case NV_MEM_TYPE_GDDR3: 533 - case NV_MEM_TYPE_GDDR5: 534 - t->drive_strength = t->mr[1] & 0x03; 535 - t->odt = (t->mr[1] & 0x0c) >> 2; 536 - break; 537 - default: 538 - break; 539 - } 540 - } 541 - 542 - int 543 - nouveau_mem_exec(struct nouveau_mem_exec_func *exec, 544 - struct nouveau_pm_level *perflvl) 545 - { 546 - struct nouveau_drm *drm = nouveau_drm(exec->dev); 547 - struct nouveau_device *device = nouveau_dev(exec->dev); 548 - struct nouveau_fb *pfb = nouveau_fb(device); 549 - struct nouveau_pm_memtiming *info = &perflvl->timing; 550 - u32 tMRD = 1000, tCKSRE = 0, tCKSRX = 0, tXS = 0, tDLLK = 0; 551 - u32 mr[3] = { info->mr[0], info->mr[1], info->mr[2] }; 552 - u32 mr1_dlloff; 553 - 554 - switch (pfb->ram->type) { 555 - case NV_MEM_TYPE_DDR2: 556 - tDLLK = 2000; 557 - mr1_dlloff = 0x00000001; 558 - break; 559 - case NV_MEM_TYPE_DDR3: 560 - tDLLK = 12000; 561 - tCKSRE = 2000; 562 - tXS = 1000; 563 - mr1_dlloff = 0x00000001; 564 - break; 565 - case NV_MEM_TYPE_GDDR3: 566 - tDLLK = 40000; 567 - mr1_dlloff = 0x00000040; 568 - break; 569 - default: 570 - NV_ERROR(drm, "cannot reclock unsupported memtype\n"); 571 - return -ENODEV; 572 - } 573 - 574 - /* fetch current MRs */ 575 - switch (pfb->ram->type) { 576 - case NV_MEM_TYPE_GDDR3: 577 - case NV_MEM_TYPE_DDR3: 578 - mr[2] = exec->mrg(exec, 2); 579 - default: 580 - mr[1] = exec->mrg(exec, 1); 581 - mr[0] = exec->mrg(exec, 0); 582 - break; 583 - } 584 - 585 - /* DLL 'on' -> DLL 'off' mode, disable before entering self-refresh */ 586 - if (!(mr[1] & mr1_dlloff) && (info->mr[1] & mr1_dlloff)) { 587 - exec->precharge(exec); 588 - exec->mrs (exec, 1, mr[1] | mr1_dlloff); 589 - exec->wait(exec, tMRD); 590 - } 591 - 592 - /* enter self-refresh mode */ 593 - exec->precharge(exec); 594 - exec->refresh(exec); 595 - exec->refresh(exec); 596 - exec->refresh_auto(exec, false); 597 - exec->refresh_self(exec, true); 598 - exec->wait(exec, tCKSRE); 599 - 600 - /* modify input clock frequency */ 601 - exec->clock_set(exec); 602 - 603 - /* exit self-refresh mode */ 604 - exec->wait(exec, tCKSRX); 605 - exec->precharge(exec); 606 - exec->refresh_self(exec, false); 607 - exec->refresh_auto(exec, true); 608 - exec->wait(exec, tXS); 609 - exec->wait(exec, tXS); 610 - 611 - /* update MRs */ 612 - if (mr[2] != info->mr[2]) { 613 - exec->mrs (exec, 2, info->mr[2]); 614 - exec->wait(exec, tMRD); 615 - } 616 - 617 - if (mr[1] != info->mr[1]) { 618 - /* need to keep DLL off until later, at least on GDDR3 */ 619 - exec->mrs (exec, 1, info->mr[1] | (mr[1] & mr1_dlloff)); 620 - exec->wait(exec, tMRD); 621 - } 622 - 623 - if (mr[0] != info->mr[0]) { 624 - exec->mrs (exec, 0, info->mr[0]); 625 - exec->wait(exec, tMRD); 626 - } 627 - 628 - /* update PFB timing registers */ 629 - exec->timing_set(exec); 630 - 631 - /* DLL (enable + ) reset */ 632 - if (!(info->mr[1] & mr1_dlloff)) { 633 - if (mr[1] & mr1_dlloff) { 634 - exec->mrs (exec, 1, info->mr[1]); 635 - exec->wait(exec, tMRD); 636 - } 637 - exec->mrs (exec, 0, info->mr[0] | 0x00000100); 638 - exec->wait(exec, tMRD); 639 - exec->mrs (exec, 0, info->mr[0] | 0x00000000); 640 - exec->wait(exec, tMRD); 641 - exec->wait(exec, tDLLK); 642 - if (pfb->ram->type == NV_MEM_TYPE_GDDR3) 643 - exec->precharge(exec); 644 - } 645 - 646 - return 0; 647 - }
-416
drivers/gpu/drm/nouveau/nouveau_perf.c
··· 1 - /* 2 - * Copyright 2010 Red Hat Inc. 3 - * 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: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 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. 21 - * 22 - * Authors: Ben Skeggs 23 - */ 24 - 25 - #include <drm/drmP.h> 26 - 27 - #include "nouveau_drm.h" 28 - #include "nouveau_reg.h" 29 - #include "nouveau_pm.h" 30 - 31 - static u8 * 32 - nouveau_perf_table(struct drm_device *dev, u8 *ver) 33 - { 34 - struct nouveau_drm *drm = nouveau_drm(dev); 35 - struct nvbios *bios = &drm->vbios; 36 - struct bit_entry P; 37 - 38 - if (!bit_table(dev, 'P', &P) && P.version && P.version <= 2) { 39 - u8 *perf = ROMPTR(dev, P.data[0]); 40 - if (perf) { 41 - *ver = perf[0]; 42 - return perf; 43 - } 44 - } 45 - 46 - if (bios->type == NVBIOS_BMP) { 47 - if (bios->data[bios->offset + 6] >= 0x25) { 48 - u8 *perf = ROMPTR(dev, bios->data[bios->offset + 0x94]); 49 - if (perf) { 50 - *ver = perf[1]; 51 - return perf; 52 - } 53 - } 54 - } 55 - 56 - return NULL; 57 - } 58 - 59 - static u8 * 60 - nouveau_perf_entry(struct drm_device *dev, int idx, 61 - u8 *ver, u8 *hdr, u8 *cnt, u8 *len) 62 - { 63 - u8 *perf = nouveau_perf_table(dev, ver); 64 - if (perf) { 65 - if (*ver >= 0x12 && *ver < 0x20 && idx < perf[2]) { 66 - *hdr = perf[3]; 67 - *cnt = 0; 68 - *len = 0; 69 - return perf + perf[0] + idx * perf[3]; 70 - } else 71 - if (*ver >= 0x20 && *ver < 0x40 && idx < perf[2]) { 72 - *hdr = perf[3]; 73 - *cnt = perf[4]; 74 - *len = perf[5]; 75 - return perf + perf[1] + idx * (*hdr + (*cnt * *len)); 76 - } else 77 - if (*ver >= 0x40 && *ver < 0x41 && idx < perf[5]) { 78 - *hdr = perf[2]; 79 - *cnt = perf[4]; 80 - *len = perf[3]; 81 - return perf + perf[1] + idx * (*hdr + (*cnt * *len)); 82 - } 83 - } 84 - return NULL; 85 - } 86 - 87 - u8 * 88 - nouveau_perf_rammap(struct drm_device *dev, u32 freq, 89 - u8 *ver, u8 *hdr, u8 *cnt, u8 *len) 90 - { 91 - struct nouveau_drm *drm = nouveau_drm(dev); 92 - struct bit_entry P; 93 - u8 *perf, i = 0; 94 - 95 - if (!bit_table(dev, 'P', &P) && P.version == 2) { 96 - u8 *rammap = ROMPTR(dev, P.data[4]); 97 - if (rammap) { 98 - u8 *ramcfg = rammap + rammap[1]; 99 - 100 - *ver = rammap[0]; 101 - *hdr = rammap[2]; 102 - *cnt = rammap[4]; 103 - *len = rammap[3]; 104 - 105 - freq /= 1000; 106 - for (i = 0; i < rammap[5]; i++) { 107 - if (freq >= ROM16(ramcfg[0]) && 108 - freq <= ROM16(ramcfg[2])) 109 - return ramcfg; 110 - 111 - ramcfg += *hdr + (*cnt * *len); 112 - } 113 - } 114 - 115 - return NULL; 116 - } 117 - 118 - if (nv_device(drm->device)->chipset == 0x49 || 119 - nv_device(drm->device)->chipset == 0x4b) 120 - freq /= 2; 121 - 122 - while ((perf = nouveau_perf_entry(dev, i++, ver, hdr, cnt, len))) { 123 - if (*ver >= 0x20 && *ver < 0x25) { 124 - if (perf[0] != 0xff && freq <= ROM16(perf[11]) * 1000) 125 - break; 126 - } else 127 - if (*ver >= 0x25 && *ver < 0x40) { 128 - if (perf[0] != 0xff && freq <= ROM16(perf[12]) * 1000) 129 - break; 130 - } 131 - } 132 - 133 - if (perf) { 134 - u8 *ramcfg = perf + *hdr; 135 - *ver = 0x00; 136 - *hdr = 0; 137 - return ramcfg; 138 - } 139 - 140 - return NULL; 141 - } 142 - 143 - u8 * 144 - nouveau_perf_ramcfg(struct drm_device *dev, u32 freq, u8 *ver, u8 *len) 145 - { 146 - struct nouveau_device *device = nouveau_dev(dev); 147 - struct nouveau_drm *drm = nouveau_drm(dev); 148 - struct nvbios *bios = &drm->vbios; 149 - u8 strap, hdr, cnt; 150 - u8 *rammap; 151 - 152 - strap = (nv_rd32(device, 0x101000) & 0x0000003c) >> 2; 153 - if (bios->ram_restrict_tbl_ptr) 154 - strap = bios->data[bios->ram_restrict_tbl_ptr + strap]; 155 - 156 - rammap = nouveau_perf_rammap(dev, freq, ver, &hdr, &cnt, len); 157 - if (rammap && strap < cnt) 158 - return rammap + hdr + (strap * *len); 159 - 160 - return NULL; 161 - } 162 - 163 - u8 * 164 - nouveau_perf_timing(struct drm_device *dev, u32 freq, u8 *ver, u8 *len) 165 - { 166 - struct nouveau_drm *drm = nouveau_drm(dev); 167 - struct nvbios *bios = &drm->vbios; 168 - struct bit_entry P; 169 - u8 *perf, *timing = NULL; 170 - u8 i = 0, hdr, cnt; 171 - 172 - if (bios->type == NVBIOS_BMP) { 173 - while ((perf = nouveau_perf_entry(dev, i++, ver, &hdr, &cnt, 174 - len)) && *ver == 0x15) { 175 - if (freq <= ROM32(perf[5]) * 20) { 176 - *ver = 0x00; 177 - *len = 14; 178 - return perf + 41; 179 - } 180 - } 181 - return NULL; 182 - } 183 - 184 - if (!bit_table(dev, 'P', &P)) { 185 - if (P.version == 1) 186 - timing = ROMPTR(dev, P.data[4]); 187 - else 188 - if (P.version == 2) 189 - timing = ROMPTR(dev, P.data[8]); 190 - } 191 - 192 - if (timing && timing[0] == 0x10) { 193 - u8 *ramcfg = nouveau_perf_ramcfg(dev, freq, ver, len); 194 - if (ramcfg && ramcfg[1] < timing[2]) { 195 - *ver = timing[0]; 196 - *len = timing[3]; 197 - return timing + timing[1] + (ramcfg[1] * timing[3]); 198 - } 199 - } 200 - 201 - return NULL; 202 - } 203 - 204 - static void 205 - legacy_perf_init(struct drm_device *dev) 206 - { 207 - struct nouveau_device *device = nouveau_dev(dev); 208 - struct nouveau_drm *drm = nouveau_drm(dev); 209 - struct nvbios *bios = &drm->vbios; 210 - struct nouveau_pm *pm = nouveau_pm(dev); 211 - char *perf, *entry, *bmp = &bios->data[bios->offset]; 212 - int headerlen, use_straps; 213 - 214 - if (bmp[5] < 0x5 || bmp[6] < 0x14) { 215 - NV_DEBUG(drm, "BMP version too old for perf\n"); 216 - return; 217 - } 218 - 219 - perf = ROMPTR(dev, bmp[0x73]); 220 - if (!perf) { 221 - NV_DEBUG(drm, "No memclock table pointer found.\n"); 222 - return; 223 - } 224 - 225 - switch (perf[0]) { 226 - case 0x12: 227 - case 0x14: 228 - case 0x18: 229 - use_straps = 0; 230 - headerlen = 1; 231 - break; 232 - case 0x01: 233 - use_straps = perf[1] & 1; 234 - headerlen = (use_straps ? 8 : 2); 235 - break; 236 - default: 237 - NV_WARN(drm, "Unknown memclock table version %x.\n", perf[0]); 238 - return; 239 - } 240 - 241 - entry = perf + headerlen; 242 - if (use_straps) 243 - entry += (nv_rd32(device, NV_PEXTDEV_BOOT_0) & 0x3c) >> 1; 244 - 245 - sprintf(pm->perflvl[0].name, "performance_level_0"); 246 - pm->perflvl[0].memory = ROM16(entry[0]) * 20; 247 - pm->nr_perflvl = 1; 248 - } 249 - 250 - static void 251 - nouveau_perf_voltage(struct drm_device *dev, struct nouveau_pm_level *perflvl) 252 - { 253 - struct nouveau_drm *drm = nouveau_drm(dev); 254 - struct bit_entry P; 255 - u8 *vmap; 256 - int id; 257 - 258 - id = perflvl->volt_min; 259 - perflvl->volt_min = 0; 260 - 261 - /* boards using voltage table version <0x40 store the voltage 262 - * level directly in the perflvl entry as a multiple of 10mV 263 - */ 264 - if (drm->pm->voltage.version < 0x40) { 265 - perflvl->volt_min = id * 10000; 266 - perflvl->volt_max = perflvl->volt_min; 267 - return; 268 - } 269 - 270 - /* on newer ones, the perflvl stores an index into yet another 271 - * vbios table containing a min/max voltage value for the perflvl 272 - */ 273 - if (bit_table(dev, 'P', &P) || P.version != 2 || P.length < 34) { 274 - NV_DEBUG(drm, "where's our volt map table ptr? %d %d\n", 275 - P.version, P.length); 276 - return; 277 - } 278 - 279 - vmap = ROMPTR(dev, P.data[32]); 280 - if (!vmap) { 281 - NV_DEBUG(drm, "volt map table pointer invalid\n"); 282 - return; 283 - } 284 - 285 - if (id < vmap[3]) { 286 - vmap += vmap[1] + (vmap[2] * id); 287 - perflvl->volt_min = ROM32(vmap[0]); 288 - perflvl->volt_max = ROM32(vmap[4]); 289 - } 290 - } 291 - 292 - void 293 - nouveau_perf_init(struct drm_device *dev) 294 - { 295 - struct nouveau_drm *drm = nouveau_drm(dev); 296 - struct nouveau_pm *pm = nouveau_pm(dev); 297 - struct nvbios *bios = &drm->vbios; 298 - u8 *perf, ver, hdr, cnt, len; 299 - int ret, vid, i = -1; 300 - 301 - if (bios->type == NVBIOS_BMP && bios->data[bios->offset + 6] < 0x25) { 302 - legacy_perf_init(dev); 303 - return; 304 - } 305 - 306 - perf = nouveau_perf_table(dev, &ver); 307 - 308 - while ((perf = nouveau_perf_entry(dev, ++i, &ver, &hdr, &cnt, &len))) { 309 - struct nouveau_pm_level *perflvl = &pm->perflvl[pm->nr_perflvl]; 310 - 311 - if (perf[0] == 0xff) 312 - continue; 313 - 314 - switch (ver) { 315 - case 0x12: 316 - case 0x13: 317 - case 0x15: 318 - perflvl->fanspeed = perf[55]; 319 - if (hdr > 56) 320 - perflvl->volt_min = perf[56]; 321 - perflvl->core = ROM32(perf[1]) * 10; 322 - perflvl->memory = ROM32(perf[5]) * 20; 323 - break; 324 - case 0x21: 325 - case 0x23: 326 - case 0x24: 327 - perflvl->fanspeed = perf[4]; 328 - perflvl->volt_min = perf[5]; 329 - perflvl->shader = ROM16(perf[6]) * 1000; 330 - perflvl->core = perflvl->shader; 331 - perflvl->core += (signed char)perf[8] * 1000; 332 - if (nv_device(drm->device)->chipset == 0x49 || 333 - nv_device(drm->device)->chipset == 0x4b) 334 - perflvl->memory = ROM16(perf[11]) * 1000; 335 - else 336 - perflvl->memory = ROM16(perf[11]) * 2000; 337 - break; 338 - case 0x25: 339 - perflvl->fanspeed = perf[4]; 340 - perflvl->volt_min = perf[5]; 341 - perflvl->core = ROM16(perf[6]) * 1000; 342 - perflvl->shader = ROM16(perf[10]) * 1000; 343 - perflvl->memory = ROM16(perf[12]) * 1000; 344 - break; 345 - case 0x30: 346 - perflvl->memscript = ROM16(perf[2]); 347 - case 0x35: 348 - perflvl->fanspeed = perf[6]; 349 - perflvl->volt_min = perf[7]; 350 - perflvl->core = ROM16(perf[8]) * 1000; 351 - perflvl->shader = ROM16(perf[10]) * 1000; 352 - perflvl->memory = ROM16(perf[12]) * 1000; 353 - perflvl->vdec = ROM16(perf[16]) * 1000; 354 - perflvl->dom6 = ROM16(perf[20]) * 1000; 355 - break; 356 - case 0x40: 357 - #define subent(n) ((ROM16(perf[hdr + (n) * len]) & 0xfff) * 1000) 358 - perflvl->fanspeed = 0; /*XXX*/ 359 - perflvl->volt_min = perf[2]; 360 - if (nv_device(drm->device)->card_type == NV_50) { 361 - perflvl->core = subent(0); 362 - perflvl->shader = subent(1); 363 - perflvl->memory = subent(2); 364 - perflvl->vdec = subent(3); 365 - perflvl->unka0 = subent(4); 366 - } else { 367 - perflvl->hub06 = subent(0); 368 - perflvl->hub01 = subent(1); 369 - perflvl->copy = subent(2); 370 - perflvl->shader = subent(3); 371 - perflvl->rop = subent(4); 372 - perflvl->memory = subent(5); 373 - perflvl->vdec = subent(6); 374 - perflvl->daemon = subent(10); 375 - perflvl->hub07 = subent(11); 376 - perflvl->core = perflvl->shader / 2; 377 - } 378 - break; 379 - } 380 - 381 - /* make sure vid is valid */ 382 - nouveau_perf_voltage(dev, perflvl); 383 - if (pm->voltage.supported && perflvl->volt_min) { 384 - vid = nouveau_volt_vid_lookup(dev, perflvl->volt_min); 385 - if (vid < 0) { 386 - NV_DEBUG(drm, "perflvl %d, bad vid\n", i); 387 - continue; 388 - } 389 - } 390 - 391 - /* get the corresponding memory timings */ 392 - ret = nouveau_mem_timing_calc(dev, perflvl->memory, 393 - &perflvl->timing); 394 - if (ret) { 395 - NV_DEBUG(drm, "perflvl %d, bad timing: %d\n", i, ret); 396 - continue; 397 - } 398 - 399 - snprintf(perflvl->name, sizeof(perflvl->name), 400 - "performance_level_%d", i); 401 - perflvl->id = i; 402 - 403 - snprintf(perflvl->profile.name, sizeof(perflvl->profile.name), 404 - "%d", perflvl->id); 405 - perflvl->profile.func = &nouveau_pm_static_profile_func; 406 - list_add_tail(&perflvl->profile.head, &pm->profiles); 407 - 408 - 409 - pm->nr_perflvl++; 410 - } 411 - } 412 - 413 - void 414 - nouveau_perf_fini(struct drm_device *dev) 415 - { 416 - }
+22 -540
drivers/gpu/drm/nouveau/nouveau_pm.c drivers/gpu/drm/nouveau/nouveau_hwmon.c
··· 32 32 #include <drm/drmP.h> 33 33 34 34 #include "nouveau_drm.h" 35 - #include "nouveau_pm.h" 35 + #include "nouveau_hwmon.h" 36 36 37 37 #include <subdev/gpio.h> 38 38 #include <subdev/timer.h> 39 39 #include <subdev/therm.h> 40 - 41 - MODULE_PARM_DESC(perflvl, "Performance level (default: boot)"); 42 - static char *nouveau_perflvl; 43 - module_param_named(perflvl, nouveau_perflvl, charp, 0400); 44 - 45 - MODULE_PARM_DESC(perflvl_wr, "Allow perflvl changes (warning: dangerous!)"); 46 - static int nouveau_perflvl_wr; 47 - module_param_named(perflvl_wr, nouveau_perflvl_wr, int, 0400); 48 - 49 - static int 50 - nouveau_pm_perflvl_aux(struct drm_device *dev, struct nouveau_pm_level *perflvl, 51 - struct nouveau_pm_level *a, struct nouveau_pm_level *b) 52 - { 53 - struct nouveau_drm *drm = nouveau_drm(dev); 54 - struct nouveau_pm *pm = nouveau_pm(dev); 55 - struct nouveau_therm *therm = nouveau_therm(drm->device); 56 - int ret; 57 - 58 - /*XXX: not on all boards, we should control based on temperature 59 - * on recent boards.. or maybe on some other factor we don't 60 - * know about? 61 - */ 62 - if (therm && therm->fan_set && 63 - a->fanspeed && b->fanspeed && b->fanspeed > a->fanspeed) { 64 - ret = therm->fan_set(therm, perflvl->fanspeed); 65 - if (ret && ret != -ENODEV) { 66 - NV_ERROR(drm, "fanspeed set failed: %d\n", ret); 67 - } 68 - } 69 - 70 - if (pm->voltage.supported && pm->voltage_set) { 71 - if (perflvl->volt_min && b->volt_min > a->volt_min) { 72 - ret = pm->voltage_set(dev, perflvl->volt_min); 73 - if (ret) { 74 - NV_ERROR(drm, "voltage set failed: %d\n", ret); 75 - return ret; 76 - } 77 - } 78 - } 79 - 80 - return 0; 81 - } 82 - 83 - static int 84 - nouveau_pm_perflvl_set(struct drm_device *dev, struct nouveau_pm_level *perflvl) 85 - { 86 - struct nouveau_pm *pm = nouveau_pm(dev); 87 - void *state; 88 - int ret; 89 - 90 - if (perflvl == pm->cur) 91 - return 0; 92 - 93 - ret = nouveau_pm_perflvl_aux(dev, perflvl, pm->cur, perflvl); 94 - if (ret) 95 - return ret; 96 - 97 - state = pm->clocks_pre(dev, perflvl); 98 - if (IS_ERR(state)) { 99 - ret = PTR_ERR(state); 100 - goto error; 101 - } 102 - ret = pm->clocks_set(dev, state); 103 - if (ret) 104 - goto error; 105 - 106 - ret = nouveau_pm_perflvl_aux(dev, perflvl, perflvl, pm->cur); 107 - if (ret) 108 - return ret; 109 - 110 - pm->cur = perflvl; 111 - return 0; 112 - 113 - error: 114 - /* restore the fan speed and voltage before leaving */ 115 - nouveau_pm_perflvl_aux(dev, perflvl, perflvl, pm->cur); 116 - return ret; 117 - } 118 - 119 - void 120 - nouveau_pm_trigger(struct drm_device *dev) 121 - { 122 - struct nouveau_drm *drm = nouveau_drm(dev); 123 - struct nouveau_timer *ptimer = nouveau_timer(drm->device); 124 - struct nouveau_pm *pm = nouveau_pm(dev); 125 - struct nouveau_pm_profile *profile = NULL; 126 - struct nouveau_pm_level *perflvl = NULL; 127 - int ret; 128 - 129 - /* select power profile based on current power source */ 130 - if (power_supply_is_system_supplied()) 131 - profile = pm->profile_ac; 132 - else 133 - profile = pm->profile_dc; 134 - 135 - if (profile != pm->profile) { 136 - pm->profile->func->fini(pm->profile); 137 - pm->profile = profile; 138 - pm->profile->func->init(pm->profile); 139 - } 140 - 141 - /* select performance level based on profile */ 142 - perflvl = profile->func->select(profile); 143 - 144 - /* change perflvl, if necessary */ 145 - if (perflvl != pm->cur) { 146 - u64 time0 = ptimer->read(ptimer); 147 - 148 - NV_INFO(drm, "setting performance level: %d", perflvl->id); 149 - ret = nouveau_pm_perflvl_set(dev, perflvl); 150 - if (ret) 151 - NV_INFO(drm, "> reclocking failed: %d\n\n", ret); 152 - 153 - NV_INFO(drm, "> reclocking took %lluns\n\n", 154 - ptimer->read(ptimer) - time0); 155 - } 156 - } 157 - 158 - static struct nouveau_pm_profile * 159 - profile_find(struct drm_device *dev, const char *string) 160 - { 161 - struct nouveau_pm *pm = nouveau_pm(dev); 162 - struct nouveau_pm_profile *profile; 163 - 164 - list_for_each_entry(profile, &pm->profiles, head) { 165 - if (!strncmp(profile->name, string, sizeof(profile->name))) 166 - return profile; 167 - } 168 - 169 - return NULL; 170 - } 171 - 172 - static int 173 - nouveau_pm_profile_set(struct drm_device *dev, const char *profile) 174 - { 175 - struct nouveau_pm *pm = nouveau_pm(dev); 176 - struct nouveau_pm_profile *ac = NULL, *dc = NULL; 177 - char string[16], *cur = string, *ptr; 178 - 179 - /* safety precaution, for now */ 180 - if (nouveau_perflvl_wr != 7777) 181 - return -EPERM; 182 - 183 - strncpy(string, profile, sizeof(string)); 184 - string[sizeof(string) - 1] = 0; 185 - if ((ptr = strchr(string, '\n'))) 186 - *ptr = '\0'; 187 - 188 - ptr = strsep(&cur, ","); 189 - if (ptr) 190 - ac = profile_find(dev, ptr); 191 - 192 - ptr = strsep(&cur, ","); 193 - if (ptr) 194 - dc = profile_find(dev, ptr); 195 - else 196 - dc = ac; 197 - 198 - if (ac == NULL || dc == NULL) 199 - return -EINVAL; 200 - 201 - pm->profile_ac = ac; 202 - pm->profile_dc = dc; 203 - nouveau_pm_trigger(dev); 204 - return 0; 205 - } 206 - 207 - static void 208 - nouveau_pm_static_dummy(struct nouveau_pm_profile *profile) 209 - { 210 - } 211 - 212 - static struct nouveau_pm_level * 213 - nouveau_pm_static_select(struct nouveau_pm_profile *profile) 214 - { 215 - return container_of(profile, struct nouveau_pm_level, profile); 216 - } 217 - 218 - const struct nouveau_pm_profile_func nouveau_pm_static_profile_func = { 219 - .destroy = nouveau_pm_static_dummy, 220 - .init = nouveau_pm_static_dummy, 221 - .fini = nouveau_pm_static_dummy, 222 - .select = nouveau_pm_static_select, 223 - }; 224 - 225 - static int 226 - nouveau_pm_perflvl_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) 227 - { 228 - struct nouveau_drm *drm = nouveau_drm(dev); 229 - struct nouveau_pm *pm = nouveau_pm(dev); 230 - struct nouveau_therm *therm = nouveau_therm(drm->device); 231 - int ret; 232 - 233 - memset(perflvl, 0, sizeof(*perflvl)); 234 - 235 - if (pm->clocks_get) { 236 - ret = pm->clocks_get(dev, perflvl); 237 - if (ret) 238 - return ret; 239 - } 240 - 241 - if (pm->voltage.supported && pm->voltage_get) { 242 - ret = pm->voltage_get(dev); 243 - if (ret > 0) { 244 - perflvl->volt_min = ret; 245 - perflvl->volt_max = ret; 246 - } 247 - } 248 - 249 - if (therm && therm->fan_get) { 250 - ret = therm->fan_get(therm); 251 - if (ret >= 0) 252 - perflvl->fanspeed = ret; 253 - } 254 - 255 - nouveau_mem_timing_read(dev, &perflvl->timing); 256 - return 0; 257 - } 258 - 259 - static void 260 - nouveau_pm_perflvl_info(struct nouveau_pm_level *perflvl, char *ptr, int len) 261 - { 262 - char c[16], s[16], v[32], f[16], m[16]; 263 - 264 - c[0] = '\0'; 265 - if (perflvl->core) 266 - snprintf(c, sizeof(c), " core %dMHz", perflvl->core / 1000); 267 - 268 - s[0] = '\0'; 269 - if (perflvl->shader) 270 - snprintf(s, sizeof(s), " shader %dMHz", perflvl->shader / 1000); 271 - 272 - m[0] = '\0'; 273 - if (perflvl->memory) 274 - snprintf(m, sizeof(m), " memory %dMHz", perflvl->memory / 1000); 275 - 276 - v[0] = '\0'; 277 - if (perflvl->volt_min && perflvl->volt_min != perflvl->volt_max) { 278 - snprintf(v, sizeof(v), " voltage %dmV-%dmV", 279 - perflvl->volt_min / 1000, perflvl->volt_max / 1000); 280 - } else 281 - if (perflvl->volt_min) { 282 - snprintf(v, sizeof(v), " voltage %dmV", 283 - perflvl->volt_min / 1000); 284 - } 285 - 286 - f[0] = '\0'; 287 - if (perflvl->fanspeed) 288 - snprintf(f, sizeof(f), " fanspeed %d%%", perflvl->fanspeed); 289 - 290 - snprintf(ptr, len, "%s%s%s%s%s\n", c, s, m, v, f); 291 - } 292 - 293 - static ssize_t 294 - nouveau_pm_get_perflvl_info(struct device *d, 295 - struct device_attribute *a, char *buf) 296 - { 297 - struct nouveau_pm_level *perflvl = 298 - container_of(a, struct nouveau_pm_level, dev_attr); 299 - char *ptr = buf; 300 - int len = PAGE_SIZE; 301 - 302 - snprintf(ptr, len, "%d:", perflvl->id); 303 - ptr += strlen(buf); 304 - len -= strlen(buf); 305 - 306 - nouveau_pm_perflvl_info(perflvl, ptr, len); 307 - return strlen(buf); 308 - } 309 - 310 - static ssize_t 311 - nouveau_pm_get_perflvl(struct device *d, struct device_attribute *a, char *buf) 312 - { 313 - struct drm_device *dev = pci_get_drvdata(to_pci_dev(d)); 314 - struct nouveau_pm *pm = nouveau_pm(dev); 315 - struct nouveau_pm_level cur; 316 - int len = PAGE_SIZE, ret; 317 - char *ptr = buf; 318 - 319 - snprintf(ptr, len, "profile: %s, %s\nc:", 320 - pm->profile_ac->name, pm->profile_dc->name); 321 - ptr += strlen(buf); 322 - len -= strlen(buf); 323 - 324 - ret = nouveau_pm_perflvl_get(dev, &cur); 325 - if (ret == 0) 326 - nouveau_pm_perflvl_info(&cur, ptr, len); 327 - return strlen(buf); 328 - } 329 - 330 - static ssize_t 331 - nouveau_pm_set_perflvl(struct device *d, struct device_attribute *a, 332 - const char *buf, size_t count) 333 - { 334 - struct drm_device *dev = pci_get_drvdata(to_pci_dev(d)); 335 - int ret; 336 - 337 - ret = nouveau_pm_profile_set(dev, buf); 338 - if (ret) 339 - return ret; 340 - return strlen(buf); 341 - } 342 - 343 - static DEVICE_ATTR(performance_level, S_IRUGO | S_IWUSR, 344 - nouveau_pm_get_perflvl, nouveau_pm_set_perflvl); 345 - 346 - static int 347 - nouveau_sysfs_init(struct drm_device *dev) 348 - { 349 - struct nouveau_drm *drm = nouveau_drm(dev); 350 - struct nouveau_pm *pm = nouveau_pm(dev); 351 - struct device *d = &dev->pdev->dev; 352 - int ret, i; 353 - 354 - ret = device_create_file(d, &dev_attr_performance_level); 355 - if (ret) 356 - return ret; 357 - 358 - for (i = 0; i < pm->nr_perflvl; i++) { 359 - struct nouveau_pm_level *perflvl = &pm->perflvl[i]; 360 - 361 - perflvl->dev_attr.attr.name = perflvl->name; 362 - perflvl->dev_attr.attr.mode = S_IRUGO; 363 - perflvl->dev_attr.show = nouveau_pm_get_perflvl_info; 364 - perflvl->dev_attr.store = NULL; 365 - sysfs_attr_init(&perflvl->dev_attr.attr); 366 - 367 - ret = device_create_file(d, &perflvl->dev_attr); 368 - if (ret) { 369 - NV_ERROR(drm, "failed pervlvl %d sysfs: %d\n", 370 - perflvl->id, i); 371 - perflvl->dev_attr.attr.name = NULL; 372 - nouveau_pm_fini(dev); 373 - return ret; 374 - } 375 - } 376 - 377 - return 0; 378 - } 379 - 380 - static void 381 - nouveau_sysfs_fini(struct drm_device *dev) 382 - { 383 - struct nouveau_pm *pm = nouveau_pm(dev); 384 - struct device *d = &dev->pdev->dev; 385 - int i; 386 - 387 - device_remove_file(d, &dev_attr_performance_level); 388 - for (i = 0; i < pm->nr_perflvl; i++) { 389 - struct nouveau_pm_level *pl = &pm->perflvl[i]; 390 - 391 - if (!pl->dev_attr.attr.name) 392 - break; 393 - 394 - device_remove_file(d, &pl->dev_attr); 395 - } 396 - } 397 40 398 41 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) 399 42 static ssize_t ··· 421 778 int ret = -ENODEV; 422 779 long value; 423 780 424 - if (nouveau_perflvl_wr != 7777) 425 - return -EPERM; 426 - 427 781 if (kstrtol(buf, 10, &value) == -EINVAL) 428 782 return -EINVAL; 429 783 ··· 559 919 }; 560 920 #endif 561 921 562 - static int 922 + int 563 923 nouveau_hwmon_init(struct drm_device *dev) 564 924 { 565 - struct nouveau_pm *pm = nouveau_pm(dev); 566 - 567 925 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) 568 926 struct nouveau_drm *drm = nouveau_drm(dev); 569 927 struct nouveau_therm *therm = nouveau_therm(drm->device); 928 + struct nouveau_hwmon *hwmon; 570 929 struct device *hwmon_dev; 571 930 int ret = 0; 931 + 932 + hwmon = drm->hwmon = kzalloc(sizeof(*hwmon), GFP_KERNEL); 933 + if (!hwmon) 934 + return -ENOMEM; 935 + hwmon->dev = dev; 572 936 573 937 if (!therm || !therm->temp_get || !therm->attr_get || !therm->attr_set) 574 938 return -ENODEV; ··· 620 976 goto error; 621 977 } 622 978 623 - pm->hwmon = hwmon_dev; 979 + hwmon->hwmon = hwmon_dev; 624 980 625 981 return 0; 626 982 627 983 error: 628 984 NV_ERROR(drm, "Unable to create some hwmon sysfs files: %d\n", ret); 629 985 hwmon_device_unregister(hwmon_dev); 630 - pm->hwmon = NULL; 986 + hwmon->hwmon = NULL; 631 987 return ret; 632 988 #else 633 - pm->hwmon = NULL; 989 + hwmon->hwmon = NULL; 634 990 return 0; 635 991 #endif 636 992 } 637 993 638 - static void 994 + void 639 995 nouveau_hwmon_fini(struct drm_device *dev) 640 996 { 641 997 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) 642 - struct nouveau_pm *pm = nouveau_pm(dev); 998 + struct nouveau_hwmon *hwmon = nouveau_hwmon(dev); 643 999 644 - if (pm->hwmon) { 645 - sysfs_remove_group(&pm->hwmon->kobj, &hwmon_default_attrgroup); 646 - sysfs_remove_group(&pm->hwmon->kobj, &hwmon_temp_attrgroup); 647 - sysfs_remove_group(&pm->hwmon->kobj, &hwmon_pwm_fan_attrgroup); 648 - sysfs_remove_group(&pm->hwmon->kobj, &hwmon_fan_rpm_attrgroup); 1000 + if (hwmon->hwmon) { 1001 + sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_default_attrgroup); 1002 + sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_temp_attrgroup); 1003 + sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_pwm_fan_attrgroup); 1004 + sysfs_remove_group(&hwmon->hwmon->kobj, &hwmon_fan_rpm_attrgroup); 649 1005 650 - hwmon_device_unregister(pm->hwmon); 1006 + hwmon_device_unregister(hwmon->hwmon); 651 1007 } 1008 + 1009 + nouveau_drm(dev)->hwmon = NULL; 1010 + kfree(hwmon); 652 1011 #endif 653 - } 654 - 655 - #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY) 656 - static int 657 - nouveau_pm_acpi_event(struct notifier_block *nb, unsigned long val, void *data) 658 - { 659 - struct nouveau_pm *pm = container_of(nb, struct nouveau_pm, acpi_nb); 660 - struct nouveau_drm *drm = nouveau_drm(pm->dev); 661 - struct acpi_bus_event *entry = (struct acpi_bus_event *)data; 662 - 663 - if (strcmp(entry->device_class, "ac_adapter") == 0) { 664 - bool ac = power_supply_is_system_supplied(); 665 - 666 - NV_DEBUG(drm, "power supply changed: %s\n", ac ? "AC" : "DC"); 667 - nouveau_pm_trigger(pm->dev); 668 - } 669 - 670 - return NOTIFY_OK; 671 - } 672 - #endif 673 - 674 - int 675 - nouveau_pm_init(struct drm_device *dev) 676 - { 677 - struct nouveau_device *device = nouveau_dev(dev); 678 - struct nouveau_drm *drm = nouveau_drm(dev); 679 - struct nouveau_pm *pm; 680 - char info[256]; 681 - int ret, i; 682 - 683 - pm = drm->pm = kzalloc(sizeof(*pm), GFP_KERNEL); 684 - if (!pm) 685 - return -ENOMEM; 686 - 687 - pm->dev = dev; 688 - 689 - if (device->card_type < NV_40) { 690 - pm->clocks_get = nv04_pm_clocks_get; 691 - pm->clocks_pre = nv04_pm_clocks_pre; 692 - pm->clocks_set = nv04_pm_clocks_set; 693 - if (nouveau_gpio(drm->device)) { 694 - pm->voltage_get = nouveau_voltage_gpio_get; 695 - pm->voltage_set = nouveau_voltage_gpio_set; 696 - } 697 - } else 698 - if (device->card_type < NV_50) { 699 - pm->clocks_get = nv40_pm_clocks_get; 700 - pm->clocks_pre = nv40_pm_clocks_pre; 701 - pm->clocks_set = nv40_pm_clocks_set; 702 - pm->voltage_get = nouveau_voltage_gpio_get; 703 - pm->voltage_set = nouveau_voltage_gpio_set; 704 - } else 705 - if (device->card_type < NV_C0) { 706 - if (device->chipset < 0xa3 || 707 - device->chipset == 0xaa || 708 - device->chipset == 0xac) { 709 - pm->clocks_get = nv50_pm_clocks_get; 710 - pm->clocks_pre = nv50_pm_clocks_pre; 711 - pm->clocks_set = nv50_pm_clocks_set; 712 - } else { 713 - pm->clocks_get = nva3_pm_clocks_get; 714 - pm->clocks_pre = nva3_pm_clocks_pre; 715 - pm->clocks_set = nva3_pm_clocks_set; 716 - } 717 - pm->voltage_get = nouveau_voltage_gpio_get; 718 - pm->voltage_set = nouveau_voltage_gpio_set; 719 - } else 720 - if (device->card_type < NV_E0) { 721 - pm->clocks_get = nvc0_pm_clocks_get; 722 - pm->clocks_pre = nvc0_pm_clocks_pre; 723 - pm->clocks_set = nvc0_pm_clocks_set; 724 - pm->voltage_get = nouveau_voltage_gpio_get; 725 - pm->voltage_set = nouveau_voltage_gpio_set; 726 - } 727 - 728 - 729 - /* parse aux tables from vbios */ 730 - nouveau_volt_init(dev); 731 - 732 - INIT_LIST_HEAD(&pm->profiles); 733 - 734 - /* determine current ("boot") performance level */ 735 - ret = nouveau_pm_perflvl_get(dev, &pm->boot); 736 - if (ret) { 737 - NV_ERROR(drm, "failed to determine boot perflvl\n"); 738 - return ret; 739 - } 740 - 741 - strncpy(pm->boot.name, "boot", 4); 742 - strncpy(pm->boot.profile.name, "boot", 4); 743 - pm->boot.profile.func = &nouveau_pm_static_profile_func; 744 - 745 - list_add(&pm->boot.profile.head, &pm->profiles); 746 - 747 - pm->profile_ac = &pm->boot.profile; 748 - pm->profile_dc = &pm->boot.profile; 749 - pm->profile = &pm->boot.profile; 750 - pm->cur = &pm->boot; 751 - 752 - /* add performance levels from vbios */ 753 - nouveau_perf_init(dev); 754 - 755 - /* display available performance levels */ 756 - NV_INFO(drm, "%d available performance level(s)\n", pm->nr_perflvl); 757 - for (i = 0; i < pm->nr_perflvl; i++) { 758 - nouveau_pm_perflvl_info(&pm->perflvl[i], info, sizeof(info)); 759 - NV_INFO(drm, "%d:%s", pm->perflvl[i].id, info); 760 - } 761 - 762 - nouveau_pm_perflvl_info(&pm->boot, info, sizeof(info)); 763 - NV_INFO(drm, "c:%s", info); 764 - 765 - /* switch performance levels now if requested */ 766 - if (nouveau_perflvl != NULL) 767 - nouveau_pm_profile_set(dev, nouveau_perflvl); 768 - 769 - nouveau_sysfs_init(dev); 770 - nouveau_hwmon_init(dev); 771 - #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY) 772 - pm->acpi_nb.notifier_call = nouveau_pm_acpi_event; 773 - register_acpi_notifier(&pm->acpi_nb); 774 - #endif 775 - 776 - return 0; 777 - } 778 - 779 - void 780 - nouveau_pm_fini(struct drm_device *dev) 781 - { 782 - struct nouveau_pm *pm = nouveau_pm(dev); 783 - struct nouveau_pm_profile *profile, *tmp; 784 - 785 - list_for_each_entry_safe(profile, tmp, &pm->profiles, head) { 786 - list_del(&profile->head); 787 - profile->func->destroy(profile); 788 - } 789 - 790 - if (pm->cur != &pm->boot) 791 - nouveau_pm_perflvl_set(dev, &pm->boot); 792 - 793 - nouveau_perf_fini(dev); 794 - nouveau_volt_fini(dev); 795 - 796 - #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY) 797 - unregister_acpi_notifier(&pm->acpi_nb); 798 - #endif 799 - nouveau_hwmon_fini(dev); 800 - nouveau_sysfs_fini(dev); 801 - 802 - nouveau_drm(dev)->pm = NULL; 803 - kfree(pm); 804 - } 805 - 806 - void 807 - nouveau_pm_resume(struct drm_device *dev) 808 - { 809 - struct nouveau_pm *pm = nouveau_pm(dev); 810 - struct nouveau_pm_level *perflvl; 811 - 812 - if (!pm->cur || pm->cur == &pm->boot) 813 - return; 814 - 815 - perflvl = pm->cur; 816 - pm->cur = &pm->boot; 817 - nouveau_pm_perflvl_set(dev, perflvl); 818 1012 }
-283
drivers/gpu/drm/nouveau/nouveau_pm.h
··· 1 - /* 2 - * Copyright 2010 Red Hat Inc. 3 - * 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: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 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. 21 - * 22 - * Authors: Ben Skeggs 23 - */ 24 - 25 - #ifndef __NOUVEAU_PM_H__ 26 - #define __NOUVEAU_PM_H__ 27 - 28 - #include <subdev/bios/pll.h> 29 - #include <subdev/clock.h> 30 - 31 - struct nouveau_pm_voltage_level { 32 - u32 voltage; /* microvolts */ 33 - u8 vid; 34 - }; 35 - 36 - struct nouveau_pm_voltage { 37 - bool supported; 38 - u8 version; 39 - u8 vid_mask; 40 - 41 - struct nouveau_pm_voltage_level *level; 42 - int nr_level; 43 - }; 44 - 45 - /* Exclusive upper limits */ 46 - #define NV_MEM_CL_DDR2_MAX 8 47 - #define NV_MEM_WR_DDR2_MAX 9 48 - #define NV_MEM_CL_DDR3_MAX 17 49 - #define NV_MEM_WR_DDR3_MAX 17 50 - #define NV_MEM_CL_GDDR3_MAX 16 51 - #define NV_MEM_WR_GDDR3_MAX 18 52 - #define NV_MEM_CL_GDDR5_MAX 21 53 - #define NV_MEM_WR_GDDR5_MAX 20 54 - 55 - struct nouveau_pm_memtiming { 56 - int id; 57 - 58 - u32 reg[9]; 59 - u32 mr[4]; 60 - 61 - u8 tCWL; 62 - 63 - u8 odt; 64 - u8 drive_strength; 65 - }; 66 - 67 - struct nouveau_pm_tbl_header { 68 - u8 version; 69 - u8 header_len; 70 - u8 entry_cnt; 71 - u8 entry_len; 72 - }; 73 - 74 - struct nouveau_pm_tbl_entry { 75 - u8 tWR; 76 - u8 tWTR; 77 - u8 tCL; 78 - u8 tRC; 79 - u8 empty_4; 80 - u8 tRFC; /* Byte 5 */ 81 - u8 empty_6; 82 - u8 tRAS; /* Byte 7 */ 83 - u8 empty_8; 84 - u8 tRP; /* Byte 9 */ 85 - u8 tRCDRD; 86 - u8 tRCDWR; 87 - u8 tRRD; 88 - u8 tUNK_13; 89 - u8 RAM_FT1; /* 14, a bitmask of random RAM features */ 90 - u8 empty_15; 91 - u8 tUNK_16; 92 - u8 empty_17; 93 - u8 tUNK_18; 94 - u8 tCWL; 95 - u8 tUNK_20, tUNK_21; 96 - }; 97 - 98 - struct nouveau_pm_profile; 99 - struct nouveau_pm_profile_func { 100 - void (*destroy)(struct nouveau_pm_profile *); 101 - void (*init)(struct nouveau_pm_profile *); 102 - void (*fini)(struct nouveau_pm_profile *); 103 - struct nouveau_pm_level *(*select)(struct nouveau_pm_profile *); 104 - }; 105 - 106 - struct nouveau_pm_profile { 107 - const struct nouveau_pm_profile_func *func; 108 - struct list_head head; 109 - char name[8]; 110 - }; 111 - 112 - #define NOUVEAU_PM_MAX_LEVEL 8 113 - struct nouveau_pm_level { 114 - struct nouveau_pm_profile profile; 115 - struct device_attribute dev_attr; 116 - char name[32]; 117 - int id; 118 - 119 - struct nouveau_pm_memtiming timing; 120 - u32 memory; 121 - u16 memscript; 122 - 123 - u32 core; 124 - u32 shader; 125 - u32 rop; 126 - u32 copy; 127 - u32 daemon; 128 - u32 vdec; 129 - u32 dom6; 130 - u32 unka0; /* nva3:nvc0 */ 131 - u32 hub01; /* nvc0- */ 132 - u32 hub06; /* nvc0- */ 133 - u32 hub07; /* nvc0- */ 134 - 135 - u32 volt_min; /* microvolts */ 136 - u32 volt_max; 137 - u8 fanspeed; 138 - }; 139 - 140 - struct nouveau_pm_temp_sensor_constants { 141 - u16 offset_constant; 142 - s16 offset_mult; 143 - s16 offset_div; 144 - s16 slope_mult; 145 - s16 slope_div; 146 - }; 147 - 148 - struct nouveau_pm_threshold_temp { 149 - s16 critical; 150 - s16 down_clock; 151 - }; 152 - 153 - struct nouveau_pm { 154 - struct drm_device *dev; 155 - 156 - struct nouveau_pm_voltage voltage; 157 - struct nouveau_pm_level perflvl[NOUVEAU_PM_MAX_LEVEL]; 158 - int nr_perflvl; 159 - struct nouveau_pm_temp_sensor_constants sensor_constants; 160 - struct nouveau_pm_threshold_temp threshold_temp; 161 - 162 - struct nouveau_pm_profile *profile_ac; 163 - struct nouveau_pm_profile *profile_dc; 164 - struct nouveau_pm_profile *profile; 165 - struct list_head profiles; 166 - 167 - struct nouveau_pm_level boot; 168 - struct nouveau_pm_level *cur; 169 - 170 - struct device *hwmon; 171 - struct notifier_block acpi_nb; 172 - 173 - int (*clocks_get)(struct drm_device *, struct nouveau_pm_level *); 174 - void *(*clocks_pre)(struct drm_device *, struct nouveau_pm_level *); 175 - int (*clocks_set)(struct drm_device *, void *); 176 - 177 - int (*voltage_get)(struct drm_device *); 178 - int (*voltage_set)(struct drm_device *, int voltage); 179 - }; 180 - 181 - static inline struct nouveau_pm * 182 - nouveau_pm(struct drm_device *dev) 183 - { 184 - return nouveau_drm(dev)->pm; 185 - } 186 - 187 - struct nouveau_mem_exec_func { 188 - struct drm_device *dev; 189 - void (*precharge)(struct nouveau_mem_exec_func *); 190 - void (*refresh)(struct nouveau_mem_exec_func *); 191 - void (*refresh_auto)(struct nouveau_mem_exec_func *, bool); 192 - void (*refresh_self)(struct nouveau_mem_exec_func *, bool); 193 - void (*wait)(struct nouveau_mem_exec_func *, u32 nsec); 194 - u32 (*mrg)(struct nouveau_mem_exec_func *, int mr); 195 - void (*mrs)(struct nouveau_mem_exec_func *, int mr, u32 data); 196 - void (*clock_set)(struct nouveau_mem_exec_func *); 197 - void (*timing_set)(struct nouveau_mem_exec_func *); 198 - void *priv; 199 - }; 200 - 201 - /* nouveau_mem.c */ 202 - int nouveau_mem_exec(struct nouveau_mem_exec_func *, 203 - struct nouveau_pm_level *); 204 - 205 - /* nouveau_pm.c */ 206 - int nouveau_pm_init(struct drm_device *dev); 207 - void nouveau_pm_fini(struct drm_device *dev); 208 - void nouveau_pm_resume(struct drm_device *dev); 209 - extern const struct nouveau_pm_profile_func nouveau_pm_static_profile_func; 210 - void nouveau_pm_trigger(struct drm_device *dev); 211 - 212 - /* nouveau_volt.c */ 213 - void nouveau_volt_init(struct drm_device *); 214 - void nouveau_volt_fini(struct drm_device *); 215 - int nouveau_volt_vid_lookup(struct drm_device *, int voltage); 216 - int nouveau_volt_lvl_lookup(struct drm_device *, int vid); 217 - int nouveau_voltage_gpio_get(struct drm_device *); 218 - int nouveau_voltage_gpio_set(struct drm_device *, int voltage); 219 - 220 - /* nouveau_perf.c */ 221 - void nouveau_perf_init(struct drm_device *); 222 - void nouveau_perf_fini(struct drm_device *); 223 - u8 *nouveau_perf_rammap(struct drm_device *, u32 freq, u8 *ver, 224 - u8 *hdr, u8 *cnt, u8 *len); 225 - u8 *nouveau_perf_ramcfg(struct drm_device *, u32 freq, u8 *ver, u8 *len); 226 - u8 *nouveau_perf_timing(struct drm_device *, u32 freq, u8 *ver, u8 *len); 227 - 228 - /* nouveau_mem.c */ 229 - void nouveau_mem_timing_init(struct drm_device *); 230 - void nouveau_mem_timing_fini(struct drm_device *); 231 - 232 - /* nv04_pm.c */ 233 - int nv04_pm_clocks_get(struct drm_device *, struct nouveau_pm_level *); 234 - void *nv04_pm_clocks_pre(struct drm_device *, struct nouveau_pm_level *); 235 - int nv04_pm_clocks_set(struct drm_device *, void *); 236 - 237 - /* nv40_pm.c */ 238 - int nv40_pm_clocks_get(struct drm_device *, struct nouveau_pm_level *); 239 - void *nv40_pm_clocks_pre(struct drm_device *, struct nouveau_pm_level *); 240 - int nv40_pm_clocks_set(struct drm_device *, void *); 241 - int nv40_pm_pwm_get(struct drm_device *, int, u32 *, u32 *); 242 - int nv40_pm_pwm_set(struct drm_device *, int, u32, u32); 243 - 244 - /* nv50_pm.c */ 245 - int nv50_pm_clocks_get(struct drm_device *, struct nouveau_pm_level *); 246 - void *nv50_pm_clocks_pre(struct drm_device *, struct nouveau_pm_level *); 247 - int nv50_pm_clocks_set(struct drm_device *, void *); 248 - int nv50_pm_pwm_get(struct drm_device *, int, u32 *, u32 *); 249 - int nv50_pm_pwm_set(struct drm_device *, int, u32, u32); 250 - 251 - /* nva3_pm.c */ 252 - int nva3_pm_clocks_get(struct drm_device *, struct nouveau_pm_level *); 253 - void *nva3_pm_clocks_pre(struct drm_device *, struct nouveau_pm_level *); 254 - int nva3_pm_clocks_set(struct drm_device *, void *); 255 - 256 - /* nvc0_pm.c */ 257 - int nvc0_pm_clocks_get(struct drm_device *, struct nouveau_pm_level *); 258 - void *nvc0_pm_clocks_pre(struct drm_device *, struct nouveau_pm_level *); 259 - int nvc0_pm_clocks_set(struct drm_device *, void *); 260 - 261 - /* nouveau_mem.c */ 262 - int nouveau_mem_timing_calc(struct drm_device *, u32 freq, 263 - struct nouveau_pm_memtiming *); 264 - void nouveau_mem_timing_read(struct drm_device *, 265 - struct nouveau_pm_memtiming *); 266 - 267 - static inline int 268 - nva3_calc_pll(struct drm_device *dev, struct nvbios_pll *pll, u32 freq, 269 - int *N, int *fN, int *M, int *P) 270 - { 271 - struct nouveau_device *device = nouveau_dev(dev); 272 - struct nouveau_clock *clk = nouveau_clock(device); 273 - struct nouveau_pll_vals pv; 274 - int ret; 275 - 276 - ret = clk->pll_calc(clk, pll, freq, &pv); 277 - *N = pv.N1; 278 - *M = pv.M1; 279 - *P = pv.log2P; 280 - return ret; 281 - } 282 - 283 - #endif
-250
drivers/gpu/drm/nouveau/nouveau_volt.c
··· 1 - /* 2 - * Copyright 2010 Red Hat Inc. 3 - * 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: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 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. 21 - * 22 - * Authors: Ben Skeggs 23 - */ 24 - 25 - #include <drm/drmP.h> 26 - 27 - #include "nouveau_drm.h" 28 - #include "nouveau_pm.h" 29 - 30 - #include <subdev/bios/gpio.h> 31 - #include <subdev/gpio.h> 32 - 33 - static const enum dcb_gpio_func_name vidtag[] = { 0x04, 0x05, 0x06, 0x1a, 0x73 }; 34 - static int nr_vidtag = sizeof(vidtag) / sizeof(vidtag[0]); 35 - 36 - int 37 - nouveau_voltage_gpio_get(struct drm_device *dev) 38 - { 39 - struct nouveau_pm_voltage *volt = &nouveau_pm(dev)->voltage; 40 - struct nouveau_device *device = nouveau_dev(dev); 41 - struct nouveau_gpio *gpio = nouveau_gpio(device); 42 - u8 vid = 0; 43 - int i; 44 - 45 - for (i = 0; i < nr_vidtag; i++) { 46 - if (!(volt->vid_mask & (1 << i))) 47 - continue; 48 - 49 - vid |= gpio->get(gpio, 0, vidtag[i], 0xff) << i; 50 - } 51 - 52 - return nouveau_volt_lvl_lookup(dev, vid); 53 - } 54 - 55 - int 56 - nouveau_voltage_gpio_set(struct drm_device *dev, int voltage) 57 - { 58 - struct nouveau_device *device = nouveau_dev(dev); 59 - struct nouveau_gpio *gpio = nouveau_gpio(device); 60 - struct nouveau_pm_voltage *volt = &nouveau_pm(dev)->voltage; 61 - int vid, i; 62 - 63 - vid = nouveau_volt_vid_lookup(dev, voltage); 64 - if (vid < 0) 65 - return vid; 66 - 67 - for (i = 0; i < nr_vidtag; i++) { 68 - if (!(volt->vid_mask & (1 << i))) 69 - continue; 70 - 71 - gpio->set(gpio, 0, vidtag[i], 0xff, !!(vid & (1 << i))); 72 - } 73 - 74 - return 0; 75 - } 76 - 77 - int 78 - nouveau_volt_vid_lookup(struct drm_device *dev, int voltage) 79 - { 80 - struct nouveau_pm_voltage *volt = &nouveau_pm(dev)->voltage; 81 - int i; 82 - 83 - for (i = 0; i < volt->nr_level; i++) { 84 - if (volt->level[i].voltage == voltage) 85 - return volt->level[i].vid; 86 - } 87 - 88 - return -ENOENT; 89 - } 90 - 91 - int 92 - nouveau_volt_lvl_lookup(struct drm_device *dev, int vid) 93 - { 94 - struct nouveau_pm_voltage *volt = &nouveau_pm(dev)->voltage; 95 - int i; 96 - 97 - for (i = 0; i < volt->nr_level; i++) { 98 - if (volt->level[i].vid == vid) 99 - return volt->level[i].voltage; 100 - } 101 - 102 - return -ENOENT; 103 - } 104 - 105 - void 106 - nouveau_volt_init(struct drm_device *dev) 107 - { 108 - struct nouveau_drm *drm = nouveau_drm(dev); 109 - struct nouveau_gpio *gpio = nouveau_gpio(drm->device); 110 - struct nouveau_pm *pm = nouveau_pm(dev); 111 - struct nouveau_pm_voltage *voltage = &pm->voltage; 112 - struct nvbios *bios = &drm->vbios; 113 - struct dcb_gpio_func func; 114 - struct bit_entry P; 115 - u8 *volt = NULL, *entry; 116 - int i, headerlen, recordlen, entries, vidmask, vidshift; 117 - 118 - if (bios->type == NVBIOS_BIT) { 119 - if (bit_table(dev, 'P', &P)) 120 - return; 121 - 122 - if (P.version == 1) 123 - volt = ROMPTR(dev, P.data[16]); 124 - else 125 - if (P.version == 2) 126 - volt = ROMPTR(dev, P.data[12]); 127 - else { 128 - NV_WARN(drm, "unknown volt for BIT P %d\n", P.version); 129 - } 130 - } else { 131 - if (bios->data[bios->offset + 6] < 0x27) { 132 - NV_DEBUG(drm, "BMP version too old for voltage\n"); 133 - return; 134 - } 135 - 136 - volt = ROMPTR(dev, bios->data[bios->offset + 0x98]); 137 - } 138 - 139 - if (!volt) { 140 - NV_DEBUG(drm, "voltage table pointer invalid\n"); 141 - return; 142 - } 143 - 144 - switch (volt[0]) { 145 - case 0x10: 146 - case 0x11: 147 - case 0x12: 148 - headerlen = 5; 149 - recordlen = volt[1]; 150 - entries = volt[2]; 151 - vidshift = 0; 152 - vidmask = volt[4]; 153 - break; 154 - case 0x20: 155 - headerlen = volt[1]; 156 - recordlen = volt[3]; 157 - entries = volt[2]; 158 - vidshift = 0; /* could be vidshift like 0x30? */ 159 - vidmask = volt[5]; 160 - break; 161 - case 0x30: 162 - headerlen = volt[1]; 163 - recordlen = volt[2]; 164 - entries = volt[3]; 165 - vidmask = volt[4]; 166 - /* no longer certain what volt[5] is, if it's related to 167 - * the vid shift then it's definitely not a function of 168 - * how many bits are set. 169 - * 170 - * after looking at a number of nva3+ vbios images, they 171 - * all seem likely to have a static shift of 2.. lets 172 - * go with that for now until proven otherwise. 173 - */ 174 - vidshift = 2; 175 - break; 176 - case 0x40: 177 - headerlen = volt[1]; 178 - recordlen = volt[2]; 179 - entries = volt[3]; /* not a clue what the entries are for.. */ 180 - vidmask = volt[11]; /* guess.. */ 181 - vidshift = 0; 182 - break; 183 - default: 184 - NV_WARN(drm, "voltage table 0x%02x unknown\n", volt[0]); 185 - return; 186 - } 187 - 188 - /* validate vid mask */ 189 - voltage->vid_mask = vidmask; 190 - if (!voltage->vid_mask) 191 - return; 192 - 193 - i = 0; 194 - while (vidmask) { 195 - if (i > nr_vidtag) { 196 - NV_DEBUG(drm, "vid bit %d unknown\n", i); 197 - return; 198 - } 199 - 200 - if (gpio && gpio->find(gpio, 0, vidtag[i], 0xff, &func)) { 201 - NV_DEBUG(drm, "vid bit %d has no gpio tag\n", i); 202 - return; 203 - } 204 - 205 - vidmask >>= 1; 206 - i++; 207 - } 208 - 209 - /* parse vbios entries into common format */ 210 - voltage->version = volt[0]; 211 - if (voltage->version < 0x40) { 212 - voltage->nr_level = entries; 213 - voltage->level = 214 - kcalloc(entries, sizeof(*voltage->level), GFP_KERNEL); 215 - if (!voltage->level) 216 - return; 217 - 218 - entry = volt + headerlen; 219 - for (i = 0; i < entries; i++, entry += recordlen) { 220 - voltage->level[i].voltage = entry[0] * 10000; 221 - voltage->level[i].vid = entry[1] >> vidshift; 222 - } 223 - } else { 224 - u32 volt_uv = ROM32(volt[4]); 225 - s16 step_uv = ROM16(volt[8]); 226 - u8 vid; 227 - 228 - voltage->nr_level = voltage->vid_mask + 1; 229 - voltage->level = kcalloc(voltage->nr_level, 230 - sizeof(*voltage->level), GFP_KERNEL); 231 - if (!voltage->level) 232 - return; 233 - 234 - for (vid = 0; vid <= voltage->vid_mask; vid++) { 235 - voltage->level[vid].voltage = volt_uv; 236 - voltage->level[vid].vid = vid; 237 - volt_uv += step_uv; 238 - } 239 - } 240 - 241 - voltage->supported = true; 242 - } 243 - 244 - void 245 - nouveau_volt_fini(struct drm_device *dev) 246 - { 247 - struct nouveau_pm_voltage *volt = &nouveau_pm(dev)->voltage; 248 - 249 - kfree(volt->level); 250 - }
-146
drivers/gpu/drm/nouveau/nv04_pm.c
··· 1 - /* 2 - * Copyright 2010 Red Hat Inc. 3 - * 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: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 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. 21 - * 22 - * Authors: Ben Skeggs 23 - */ 24 - 25 - #include <drm/drmP.h> 26 - #include "nouveau_drm.h" 27 - #include "nouveau_reg.h" 28 - #include "dispnv04/hw.h" 29 - #include "nouveau_pm.h" 30 - 31 - #include <subdev/bios/pll.h> 32 - #include <subdev/clock.h> 33 - #include <subdev/timer.h> 34 - 35 - int 36 - nv04_pm_clocks_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) 37 - { 38 - int ret; 39 - 40 - ret = nouveau_hw_get_clock(dev, PLL_CORE); 41 - if (ret < 0) 42 - return ret; 43 - perflvl->core = ret; 44 - 45 - ret = nouveau_hw_get_clock(dev, PLL_MEMORY); 46 - if (ret < 0) 47 - return ret; 48 - perflvl->memory = ret; 49 - 50 - return 0; 51 - } 52 - 53 - struct nv04_pm_clock { 54 - struct nvbios_pll pll; 55 - struct nouveau_pll_vals calc; 56 - }; 57 - 58 - struct nv04_pm_state { 59 - struct nv04_pm_clock core; 60 - struct nv04_pm_clock memory; 61 - }; 62 - 63 - static int 64 - calc_pll(struct drm_device *dev, u32 id, int khz, struct nv04_pm_clock *clk) 65 - { 66 - struct nouveau_device *device = nouveau_dev(dev); 67 - struct nouveau_bios *bios = nouveau_bios(device); 68 - struct nouveau_clock *pclk = nouveau_clock(device); 69 - int ret; 70 - 71 - ret = nvbios_pll_parse(bios, id, &clk->pll); 72 - if (ret) 73 - return ret; 74 - 75 - ret = pclk->pll_calc(pclk, &clk->pll, khz, &clk->calc); 76 - if (!ret) 77 - return -EINVAL; 78 - 79 - return 0; 80 - } 81 - 82 - void * 83 - nv04_pm_clocks_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl) 84 - { 85 - struct nv04_pm_state *info; 86 - int ret; 87 - 88 - info = kzalloc(sizeof(*info), GFP_KERNEL); 89 - if (!info) 90 - return ERR_PTR(-ENOMEM); 91 - 92 - ret = calc_pll(dev, PLL_CORE, perflvl->core, &info->core); 93 - if (ret) 94 - goto error; 95 - 96 - if (perflvl->memory) { 97 - ret = calc_pll(dev, PLL_MEMORY, perflvl->memory, &info->memory); 98 - if (ret) 99 - goto error; 100 - } 101 - 102 - return info; 103 - error: 104 - kfree(info); 105 - return ERR_PTR(ret); 106 - } 107 - 108 - static void 109 - prog_pll(struct drm_device *dev, struct nv04_pm_clock *clk) 110 - { 111 - struct nouveau_device *device = nouveau_dev(dev); 112 - struct nouveau_clock *pclk = nouveau_clock(device); 113 - u32 reg = clk->pll.reg; 114 - 115 - /* thank the insane nouveau_hw_setpll() interface for this */ 116 - if (device->card_type >= NV_40) 117 - reg += 4; 118 - 119 - pclk->pll_prog(pclk, reg, &clk->calc); 120 - } 121 - 122 - int 123 - nv04_pm_clocks_set(struct drm_device *dev, void *pre_state) 124 - { 125 - struct nouveau_device *device = nouveau_dev(dev); 126 - struct nouveau_timer *ptimer = nouveau_timer(device); 127 - struct nv04_pm_state *state = pre_state; 128 - 129 - prog_pll(dev, &state->core); 130 - 131 - if (state->memory.pll.reg) { 132 - prog_pll(dev, &state->memory); 133 - if (device->card_type < NV_30) { 134 - if (device->card_type == NV_20) 135 - nv_mask(device, 0x1002c4, 0, 1 << 20); 136 - 137 - /* Reset the DLLs */ 138 - nv_mask(device, 0x1002c0, 0, 1 << 8); 139 - } 140 - } 141 - 142 - nv_ofuncs(ptimer)->init(nv_object(ptimer)); 143 - 144 - kfree(state); 145 - return 0; 146 - }
-353
drivers/gpu/drm/nouveau/nv40_pm.c
··· 1 - /* 2 - * Copyright 2011 Red Hat Inc. 3 - * 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: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 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. 21 - * 22 - * Authors: Ben Skeggs 23 - */ 24 - 25 - #include <drm/drmP.h> 26 - #include "nouveau_drm.h" 27 - #include "nouveau_bios.h" 28 - #include "nouveau_pm.h" 29 - #include "dispnv04/hw.h" 30 - 31 - #include <subdev/bios/pll.h> 32 - #include <subdev/clock.h> 33 - #include <subdev/timer.h> 34 - 35 - #include <engine/fifo.h> 36 - 37 - #define min2(a,b) ((a) < (b) ? (a) : (b)) 38 - 39 - static u32 40 - read_pll_1(struct drm_device *dev, u32 reg) 41 - { 42 - struct nouveau_device *device = nouveau_dev(dev); 43 - u32 ctrl = nv_rd32(device, reg + 0x00); 44 - int P = (ctrl & 0x00070000) >> 16; 45 - int N = (ctrl & 0x0000ff00) >> 8; 46 - int M = (ctrl & 0x000000ff) >> 0; 47 - u32 ref = 27000, clk = 0; 48 - 49 - if (ctrl & 0x80000000) 50 - clk = ref * N / M; 51 - 52 - return clk >> P; 53 - } 54 - 55 - static u32 56 - read_pll_2(struct drm_device *dev, u32 reg) 57 - { 58 - struct nouveau_device *device = nouveau_dev(dev); 59 - u32 ctrl = nv_rd32(device, reg + 0x00); 60 - u32 coef = nv_rd32(device, reg + 0x04); 61 - int N2 = (coef & 0xff000000) >> 24; 62 - int M2 = (coef & 0x00ff0000) >> 16; 63 - int N1 = (coef & 0x0000ff00) >> 8; 64 - int M1 = (coef & 0x000000ff) >> 0; 65 - int P = (ctrl & 0x00070000) >> 16; 66 - u32 ref = 27000, clk = 0; 67 - 68 - if ((ctrl & 0x80000000) && M1) { 69 - clk = ref * N1 / M1; 70 - if ((ctrl & 0x40000100) == 0x40000000) { 71 - if (M2) 72 - clk = clk * N2 / M2; 73 - else 74 - clk = 0; 75 - } 76 - } 77 - 78 - return clk >> P; 79 - } 80 - 81 - static u32 82 - read_clk(struct drm_device *dev, u32 src) 83 - { 84 - switch (src) { 85 - case 3: 86 - return read_pll_2(dev, 0x004000); 87 - case 2: 88 - return read_pll_1(dev, 0x004008); 89 - default: 90 - break; 91 - } 92 - 93 - return 0; 94 - } 95 - 96 - int 97 - nv40_pm_clocks_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) 98 - { 99 - struct nouveau_device *device = nouveau_dev(dev); 100 - u32 ctrl = nv_rd32(device, 0x00c040); 101 - 102 - perflvl->core = read_clk(dev, (ctrl & 0x00000003) >> 0); 103 - perflvl->shader = read_clk(dev, (ctrl & 0x00000030) >> 4); 104 - perflvl->memory = read_pll_2(dev, 0x4020); 105 - return 0; 106 - } 107 - 108 - struct nv40_pm_state { 109 - u32 ctrl; 110 - u32 npll_ctrl; 111 - u32 npll_coef; 112 - u32 spll; 113 - u32 mpll_ctrl; 114 - u32 mpll_coef; 115 - }; 116 - 117 - static int 118 - nv40_calc_pll(struct drm_device *dev, u32 reg, struct nvbios_pll *pll, 119 - u32 clk, int *N1, int *M1, int *N2, int *M2, int *log2P) 120 - { 121 - struct nouveau_device *device = nouveau_dev(dev); 122 - struct nouveau_bios *bios = nouveau_bios(device); 123 - struct nouveau_clock *pclk = nouveau_clock(device); 124 - struct nouveau_pll_vals coef; 125 - int ret; 126 - 127 - ret = nvbios_pll_parse(bios, reg, pll); 128 - if (ret) 129 - return ret; 130 - 131 - if (clk < pll->vco1.max_freq) 132 - pll->vco2.max_freq = 0; 133 - 134 - ret = pclk->pll_calc(pclk, pll, clk, &coef); 135 - if (ret == 0) 136 - return -ERANGE; 137 - 138 - *N1 = coef.N1; 139 - *M1 = coef.M1; 140 - if (N2 && M2) { 141 - if (pll->vco2.max_freq) { 142 - *N2 = coef.N2; 143 - *M2 = coef.M2; 144 - } else { 145 - *N2 = 1; 146 - *M2 = 1; 147 - } 148 - } 149 - *log2P = coef.log2P; 150 - return 0; 151 - } 152 - 153 - void * 154 - nv40_pm_clocks_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl) 155 - { 156 - struct nv40_pm_state *info; 157 - struct nvbios_pll pll; 158 - int N1, N2, M1, M2, log2P; 159 - int ret; 160 - 161 - info = kmalloc(sizeof(*info), GFP_KERNEL); 162 - if (!info) 163 - return ERR_PTR(-ENOMEM); 164 - 165 - /* core/geometric clock */ 166 - ret = nv40_calc_pll(dev, 0x004000, &pll, perflvl->core, 167 - &N1, &M1, &N2, &M2, &log2P); 168 - if (ret < 0) 169 - goto out; 170 - 171 - if (N2 == M2) { 172 - info->npll_ctrl = 0x80000100 | (log2P << 16); 173 - info->npll_coef = (N1 << 8) | M1; 174 - } else { 175 - info->npll_ctrl = 0xc0000000 | (log2P << 16); 176 - info->npll_coef = (N2 << 24) | (M2 << 16) | (N1 << 8) | M1; 177 - } 178 - 179 - /* use the second PLL for shader/rop clock, if it differs from core */ 180 - if (perflvl->shader && perflvl->shader != perflvl->core) { 181 - ret = nv40_calc_pll(dev, 0x004008, &pll, perflvl->shader, 182 - &N1, &M1, NULL, NULL, &log2P); 183 - if (ret < 0) 184 - goto out; 185 - 186 - info->spll = 0xc0000000 | (log2P << 16) | (N1 << 8) | M1; 187 - info->ctrl = 0x00000223; 188 - } else { 189 - info->spll = 0x00000000; 190 - info->ctrl = 0x00000333; 191 - } 192 - 193 - /* memory clock */ 194 - if (!perflvl->memory) { 195 - info->mpll_ctrl = 0x00000000; 196 - goto out; 197 - } 198 - 199 - ret = nv40_calc_pll(dev, 0x004020, &pll, perflvl->memory, 200 - &N1, &M1, &N2, &M2, &log2P); 201 - if (ret < 0) 202 - goto out; 203 - 204 - info->mpll_ctrl = 0x80000000 | (log2P << 16); 205 - info->mpll_ctrl |= min2(pll.bias_p + log2P, pll.max_p) << 20; 206 - if (N2 == M2) { 207 - info->mpll_ctrl |= 0x00000100; 208 - info->mpll_coef = (N1 << 8) | M1; 209 - } else { 210 - info->mpll_ctrl |= 0x40000000; 211 - info->mpll_coef = (N2 << 24) | (M2 << 16) | (N1 << 8) | M1; 212 - } 213 - 214 - out: 215 - if (ret < 0) { 216 - kfree(info); 217 - info = ERR_PTR(ret); 218 - } 219 - return info; 220 - } 221 - 222 - static bool 223 - nv40_pm_gr_idle(void *data) 224 - { 225 - struct drm_device *dev = data; 226 - struct nouveau_device *device = nouveau_dev(dev); 227 - 228 - if ((nv_rd32(device, 0x400760) & 0x000000f0) >> 4 != 229 - (nv_rd32(device, 0x400760) & 0x0000000f)) 230 - return false; 231 - 232 - if (nv_rd32(device, 0x400700)) 233 - return false; 234 - 235 - return true; 236 - } 237 - 238 - int 239 - nv40_pm_clocks_set(struct drm_device *dev, void *pre_state) 240 - { 241 - struct nouveau_device *device = nouveau_dev(dev); 242 - struct nouveau_fifo *pfifo = nouveau_fifo(device); 243 - struct nouveau_drm *drm = nouveau_drm(dev); 244 - struct nv40_pm_state *info = pre_state; 245 - unsigned long flags; 246 - struct bit_entry M; 247 - u32 crtc_mask = 0; 248 - u8 sr1[2]; 249 - int i, ret = -EAGAIN; 250 - 251 - /* determine which CRTCs are active, fetch VGA_SR1 for each */ 252 - for (i = 0; i < 2; i++) { 253 - u32 vbl = nv_rd32(device, 0x600808 + (i * 0x2000)); 254 - u32 cnt = 0; 255 - do { 256 - if (vbl != nv_rd32(device, 0x600808 + (i * 0x2000))) { 257 - nv_wr08(device, 0x0c03c4 + (i * 0x2000), 0x01); 258 - sr1[i] = nv_rd08(device, 0x0c03c5 + (i * 0x2000)); 259 - if (!(sr1[i] & 0x20)) 260 - crtc_mask |= (1 << i); 261 - break; 262 - } 263 - udelay(1); 264 - } while (cnt++ < 32); 265 - } 266 - 267 - /* halt and idle engines */ 268 - pfifo->pause(pfifo, &flags); 269 - 270 - if (!nv_wait_cb(device, nv40_pm_gr_idle, dev)) 271 - goto resume; 272 - 273 - ret = 0; 274 - 275 - /* set engine clocks */ 276 - nv_mask(device, 0x00c040, 0x00000333, 0x00000000); 277 - nv_wr32(device, 0x004004, info->npll_coef); 278 - nv_mask(device, 0x004000, 0xc0070100, info->npll_ctrl); 279 - nv_mask(device, 0x004008, 0xc007ffff, info->spll); 280 - mdelay(5); 281 - nv_mask(device, 0x00c040, 0x00000333, info->ctrl); 282 - 283 - if (!info->mpll_ctrl) 284 - goto resume; 285 - 286 - /* wait for vblank start on active crtcs, disable memory access */ 287 - for (i = 0; i < 2; i++) { 288 - if (!(crtc_mask & (1 << i))) 289 - continue; 290 - nv_wait(device, 0x600808 + (i * 0x2000), 0x00010000, 0x00000000); 291 - nv_wait(device, 0x600808 + (i * 0x2000), 0x00010000, 0x00010000); 292 - nv_wr08(device, 0x0c03c4 + (i * 0x2000), 0x01); 293 - nv_wr08(device, 0x0c03c5 + (i * 0x2000), sr1[i] | 0x20); 294 - } 295 - 296 - /* prepare ram for reclocking */ 297 - nv_wr32(device, 0x1002d4, 0x00000001); /* precharge */ 298 - nv_wr32(device, 0x1002d0, 0x00000001); /* refresh */ 299 - nv_wr32(device, 0x1002d0, 0x00000001); /* refresh */ 300 - nv_mask(device, 0x100210, 0x80000000, 0x00000000); /* no auto refresh */ 301 - nv_wr32(device, 0x1002dc, 0x00000001); /* enable self-refresh */ 302 - 303 - /* change the PLL of each memory partition */ 304 - nv_mask(device, 0x00c040, 0x0000c000, 0x00000000); 305 - switch (nv_device(drm->device)->chipset) { 306 - case 0x40: 307 - case 0x45: 308 - case 0x41: 309 - case 0x42: 310 - case 0x47: 311 - nv_mask(device, 0x004044, 0xc0771100, info->mpll_ctrl); 312 - nv_mask(device, 0x00402c, 0xc0771100, info->mpll_ctrl); 313 - nv_wr32(device, 0x004048, info->mpll_coef); 314 - nv_wr32(device, 0x004030, info->mpll_coef); 315 - case 0x43: 316 - case 0x49: 317 - case 0x4b: 318 - nv_mask(device, 0x004038, 0xc0771100, info->mpll_ctrl); 319 - nv_wr32(device, 0x00403c, info->mpll_coef); 320 - default: 321 - nv_mask(device, 0x004020, 0xc0771100, info->mpll_ctrl); 322 - nv_wr32(device, 0x004024, info->mpll_coef); 323 - break; 324 - } 325 - udelay(100); 326 - nv_mask(device, 0x00c040, 0x0000c000, 0x0000c000); 327 - 328 - /* re-enable normal operation of memory controller */ 329 - nv_wr32(device, 0x1002dc, 0x00000000); 330 - nv_mask(device, 0x100210, 0x80000000, 0x80000000); 331 - udelay(100); 332 - 333 - /* execute memory reset script from vbios */ 334 - if (!bit_table(dev, 'M', &M)) 335 - nouveau_bios_run_init_table(dev, ROM16(M.data[0]), NULL, 0); 336 - 337 - /* make sure we're in vblank (hopefully the same one as before), and 338 - * then re-enable crtc memory access 339 - */ 340 - for (i = 0; i < 2; i++) { 341 - if (!(crtc_mask & (1 << i))) 342 - continue; 343 - nv_wait(device, 0x600808 + (i * 0x2000), 0x00010000, 0x00010000); 344 - nv_wr08(device, 0x0c03c4 + (i * 0x2000), 0x01); 345 - nv_wr08(device, 0x0c03c5 + (i * 0x2000), sr1[i]); 346 - } 347 - 348 - /* resume engines */ 349 - resume: 350 - pfifo->start(pfifo, &flags); 351 - kfree(info); 352 - return ret; 353 - }
-855
drivers/gpu/drm/nouveau/nv50_pm.c
··· 1 - /* 2 - * Copyright 2010 Red Hat Inc. 3 - * 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: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 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. 21 - * 22 - * Authors: Ben Skeggs 23 - */ 24 - 25 - #include <drm/drmP.h> 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" 31 - 32 - #include "nv50_display.h" 33 - 34 - #include <subdev/bios/pll.h> 35 - #include <subdev/clock.h> 36 - #include <subdev/timer.h> 37 - #include <subdev/fb.h> 38 - 39 - enum clk_src { 40 - clk_src_crystal, 41 - clk_src_href, 42 - clk_src_hclk, 43 - clk_src_hclkm3, 44 - clk_src_hclkm3d2, 45 - clk_src_host, 46 - clk_src_nvclk, 47 - clk_src_sclk, 48 - clk_src_mclk, 49 - clk_src_vdec, 50 - clk_src_dom6 51 - }; 52 - 53 - static u32 read_clk(struct drm_device *, enum clk_src); 54 - 55 - static u32 56 - read_div(struct drm_device *dev) 57 - { 58 - struct nouveau_device *device = nouveau_dev(dev); 59 - struct nouveau_drm *drm = nouveau_drm(dev); 60 - 61 - switch (nv_device(drm->device)->chipset) { 62 - case 0x50: /* it exists, but only has bit 31, not the dividers.. */ 63 - case 0x84: 64 - case 0x86: 65 - case 0x98: 66 - case 0xa0: 67 - return nv_rd32(device, 0x004700); 68 - case 0x92: 69 - case 0x94: 70 - case 0x96: 71 - return nv_rd32(device, 0x004800); 72 - default: 73 - return 0x00000000; 74 - } 75 - } 76 - 77 - static u32 78 - read_pll_src(struct drm_device *dev, u32 base) 79 - { 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); 84 - int P, N, M, id; 85 - 86 - switch (nv_device(drm->device)->chipset) { 87 - case 0x50: 88 - case 0xa0: 89 - switch (base) { 90 - case 0x4020: 91 - case 0x4028: id = !!(rsel & 0x00000004); break; 92 - case 0x4008: id = !!(rsel & 0x00000008); break; 93 - case 0x4030: id = 0; break; 94 - default: 95 - NV_ERROR(drm, "ref: bad pll 0x%06x\n", base); 96 - return 0; 97 - } 98 - 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; 104 - break; 105 - case 0x84: 106 - case 0x86: 107 - case 0x92: 108 - coef = nv_rd32(device, 0x00e81c); 109 - P = (coef & 0x00070000) >> 16; 110 - N = (coef & 0x0000ff00) >> 8; 111 - M = (coef & 0x000000ff) >> 0; 112 - break; 113 - case 0x94: 114 - case 0x96: 115 - case 0x98: 116 - rsel = nv_rd32(device, 0x00c050); 117 - switch (base) { 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; 122 - default: 123 - NV_ERROR(drm, "ref: bad pll 0x%06x\n", base); 124 - return 0; 125 - } 126 - 127 - switch (rsel) { 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; 132 - } 133 - 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; 139 - break; 140 - default: 141 - BUG_ON(1); 142 - } 143 - 144 - if (M) 145 - return (ref * N / M) >> P; 146 - return 0; 147 - } 148 - 149 - static u32 150 - read_pll_ref(struct drm_device *dev, u32 base) 151 - { 152 - struct nouveau_device *device = nouveau_dev(dev); 153 - struct nouveau_drm *drm = nouveau_drm(dev); 154 - u32 src, mast = nv_rd32(device, 0x00c040); 155 - 156 - switch (base) { 157 - case 0x004028: 158 - src = !!(mast & 0x00200000); 159 - break; 160 - case 0x004020: 161 - src = !!(mast & 0x00400000); 162 - break; 163 - case 0x004008: 164 - src = !!(mast & 0x00010000); 165 - break; 166 - case 0x004030: 167 - src = !!(mast & 0x02000000); 168 - break; 169 - case 0x00e810: 170 - return read_clk(dev, clk_src_crystal); 171 - default: 172 - NV_ERROR(drm, "bad pll 0x%06x\n", base); 173 - return 0; 174 - } 175 - 176 - if (src) 177 - return read_clk(dev, clk_src_href); 178 - return read_pll_src(dev, base); 179 - } 180 - 181 - static u32 182 - read_pll(struct drm_device *dev, u32 base) 183 - { 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); 190 - u32 clk = 0; 191 - int N1, N2, M1, M2; 192 - 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); 197 - } 198 - 199 - N2 = (coef & 0xff000000) >> 24; 200 - M2 = (coef & 0x00ff0000) >> 16; 201 - N1 = (coef & 0x0000ff00) >> 8; 202 - M1 = (coef & 0x000000ff); 203 - if ((ctrl & 0x80000000) && M1) { 204 - clk = ref * N1 / M1; 205 - if ((ctrl & 0x40000100) == 0x40000000) { 206 - if (M2) 207 - clk = clk * N2 / M2; 208 - else 209 - clk = 0; 210 - } 211 - } 212 - 213 - return clk; 214 - } 215 - 216 - static u32 217 - read_clk(struct drm_device *dev, enum clk_src src) 218 - { 219 - struct nouveau_device *device = nouveau_dev(dev); 220 - struct nouveau_drm *drm = nouveau_drm(dev); 221 - u32 mast = nv_rd32(device, 0x00c040); 222 - u32 P = 0; 223 - 224 - switch (src) { 225 - case clk_src_crystal: 226 - return device->crystal; 227 - case clk_src_href: 228 - return 100000; /* PCIE reference clock */ 229 - case clk_src_hclk: 230 - return read_clk(dev, clk_src_href) * 27778 / 10000; 231 - case clk_src_hclkm3: 232 - return read_clk(dev, clk_src_hclk) * 3; 233 - case clk_src_hclkm3d2: 234 - return read_clk(dev, clk_src_hclk) * 3 / 2; 235 - case clk_src_host: 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); 241 - } 242 - break; 243 - case clk_src_nvclk: 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; 251 - } 252 - break; 253 - case clk_src_sclk: 254 - P = (nv_rd32(device, 0x004020) & 0x00070000) >> 16; 255 - switch (mast & 0x00000030) { 256 - case 0x00000000: 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; 263 - } 264 - break; 265 - case clk_src_mclk: 266 - P = (nv_rd32(device, 0x004008) & 0x00070000) >> 16; 267 - if (nv_rd32(device, 0x004008) & 0x00000200) { 268 - switch (mast & 0x0000c000) { 269 - case 0x00000000: 270 - return read_clk(dev, clk_src_crystal) >> P; 271 - case 0x00008000: 272 - case 0x0000c000: 273 - return read_clk(dev, clk_src_href) >> P; 274 - } 275 - } else { 276 - return read_pll(dev, 0x004008) >> P; 277 - } 278 - break; 279 - case clk_src_vdec: 280 - P = (read_div(dev) & 0x00000700) >> 8; 281 - switch (nv_device(drm->device)->chipset) { 282 - case 0x84: 283 - case 0x86: 284 - case 0x92: 285 - case 0x94: 286 - case 0x96: 287 - case 0xa0: 288 - switch (mast & 0x00000c00) { 289 - case 0x00000000: 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; 293 - case 0x00000400: 294 - return 0; 295 - case 0x00000800: 296 - if (mast & 0x01000000) 297 - return read_pll(dev, 0x004028) >> P; 298 - return read_pll(dev, 0x004030) >> P; 299 - case 0x00000c00: 300 - return read_clk(dev, clk_src_nvclk) >> P; 301 - } 302 - break; 303 - case 0x98: 304 - switch (mast & 0x00000c00) { 305 - case 0x00000000: 306 - return read_clk(dev, clk_src_nvclk) >> P; 307 - case 0x00000400: 308 - return 0; 309 - case 0x00000800: 310 - return read_clk(dev, clk_src_hclkm3d2) >> P; 311 - case 0x00000c00: 312 - return read_clk(dev, clk_src_mclk) >> P; 313 - } 314 - break; 315 - } 316 - break; 317 - case clk_src_dom6: 318 - switch (nv_device(drm->device)->chipset) { 319 - case 0x50: 320 - case 0xa0: 321 - return read_pll(dev, 0x00e810) >> 2; 322 - case 0x84: 323 - case 0x86: 324 - case 0x92: 325 - case 0x94: 326 - case 0x96: 327 - case 0x98: 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); 333 - case 0x0c000000: 334 - return read_clk(dev, clk_src_hclkm3) >> P; 335 - } 336 - break; 337 - default: 338 - break; 339 - } 340 - default: 341 - break; 342 - } 343 - 344 - NV_DEBUG(drm, "unknown clock source %d 0x%08x\n", src, mast); 345 - return 0; 346 - } 347 - 348 - int 349 - nv50_pm_clocks_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) 350 - { 351 - struct nouveau_drm *drm = nouveau_drm(dev); 352 - if (nv_device(drm->device)->chipset == 0xaa || 353 - nv_device(drm->device)->chipset == 0xac) 354 - return 0; 355 - 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); 362 - } 363 - 364 - return 0; 365 - } 366 - 367 - struct nv50_pm_state { 368 - struct nouveau_pm_level *perflvl; 369 - struct hwsq_ucode eclk_hwsq; 370 - struct hwsq_ucode mclk_hwsq; 371 - u32 mscript; 372 - u32 mmast; 373 - u32 mctrl; 374 - u32 mcoef; 375 - }; 376 - 377 - static u32 378 - calc_pll(struct drm_device *dev, u32 reg, struct nvbios_pll *pll, 379 - u32 clk, int *N1, int *M1, int *log2P) 380 - { 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; 385 - int ret; 386 - 387 - ret = nvbios_pll_parse(bios, reg, pll); 388 - if (ret) 389 - return 0; 390 - 391 - pll->vco2.max_freq = 0; 392 - pll->refclk = read_pll_ref(dev, reg); 393 - if (!pll->refclk) 394 - return 0; 395 - 396 - ret = pclk->pll_calc(pclk, pll, clk, &coef); 397 - if (ret == 0) 398 - return 0; 399 - 400 - *N1 = coef.N1; 401 - *M1 = coef.M1; 402 - *log2P = coef.log2P; 403 - return ret; 404 - } 405 - 406 - static inline u32 407 - calc_div(u32 src, u32 target, int *div) 408 - { 409 - u32 clk0 = src, clk1 = src; 410 - for (*div = 0; *div <= 7; (*div)++) { 411 - if (clk0 <= target) { 412 - clk1 = clk0 << (*div ? 1 : 0); 413 - break; 414 - } 415 - clk0 >>= 1; 416 - } 417 - 418 - if (target - clk0 <= clk1 - target) 419 - return clk0; 420 - (*div)--; 421 - return clk1; 422 - } 423 - 424 - static inline u32 425 - clk_same(u32 a, u32 b) 426 - { 427 - return ((a / 1000) == (b / 1000)); 428 - } 429 - 430 - static void 431 - mclk_precharge(struct nouveau_mem_exec_func *exec) 432 - { 433 - struct nv50_pm_state *info = exec->priv; 434 - struct hwsq_ucode *hwsq = &info->mclk_hwsq; 435 - 436 - hwsq_wr32(hwsq, 0x1002d4, 0x00000001); 437 - } 438 - 439 - static void 440 - mclk_refresh(struct nouveau_mem_exec_func *exec) 441 - { 442 - struct nv50_pm_state *info = exec->priv; 443 - struct hwsq_ucode *hwsq = &info->mclk_hwsq; 444 - 445 - hwsq_wr32(hwsq, 0x1002d0, 0x00000001); 446 - } 447 - 448 - static void 449 - mclk_refresh_auto(struct nouveau_mem_exec_func *exec, bool enable) 450 - { 451 - struct nv50_pm_state *info = exec->priv; 452 - struct hwsq_ucode *hwsq = &info->mclk_hwsq; 453 - 454 - hwsq_wr32(hwsq, 0x100210, enable ? 0x80000000 : 0x00000000); 455 - } 456 - 457 - static void 458 - mclk_refresh_self(struct nouveau_mem_exec_func *exec, bool enable) 459 - { 460 - struct nv50_pm_state *info = exec->priv; 461 - struct hwsq_ucode *hwsq = &info->mclk_hwsq; 462 - 463 - hwsq_wr32(hwsq, 0x1002dc, enable ? 0x00000001 : 0x00000000); 464 - } 465 - 466 - static void 467 - mclk_wait(struct nouveau_mem_exec_func *exec, u32 nsec) 468 - { 469 - struct nv50_pm_state *info = exec->priv; 470 - struct hwsq_ucode *hwsq = &info->mclk_hwsq; 471 - 472 - if (nsec > 1000) 473 - hwsq_usec(hwsq, (nsec + 500) / 1000); 474 - } 475 - 476 - static u32 477 - mclk_mrg(struct nouveau_mem_exec_func *exec, int mr) 478 - { 479 - struct nouveau_device *device = nouveau_dev(exec->dev); 480 - if (mr <= 1) 481 - return nv_rd32(device, 0x1002c0 + ((mr - 0) * 4)); 482 - if (mr <= 3) 483 - return nv_rd32(device, 0x1002e0 + ((mr - 2) * 4)); 484 - return 0; 485 - } 486 - 487 - static void 488 - mclk_mrs(struct nouveau_mem_exec_func *exec, int mr, u32 data) 489 - { 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; 494 - 495 - if (mr <= 1) { 496 - if (pfb->ram->ranks > 1) 497 - hwsq_wr32(hwsq, 0x1002c8 + ((mr - 0) * 4), data); 498 - hwsq_wr32(hwsq, 0x1002c0 + ((mr - 0) * 4), data); 499 - } else 500 - if (mr <= 3) { 501 - if (pfb->ram->ranks > 1) 502 - hwsq_wr32(hwsq, 0x1002e8 + ((mr - 2) * 4), data); 503 - hwsq_wr32(hwsq, 0x1002e0 + ((mr - 2) * 4), data); 504 - } 505 - } 506 - 507 - static void 508 - mclk_clock_set(struct nouveau_mem_exec_func *exec) 509 - { 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); 514 - 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 */ 518 - 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); 524 - } 525 - 526 - static void 527 - mclk_timing_set(struct nouveau_mem_exec_func *exec) 528 - { 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; 533 - int i; 534 - 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]); 540 - } 541 - } 542 - 543 - static int 544 - calc_mclk(struct drm_device *dev, struct nouveau_pm_level *perflvl, 545 - struct nv50_pm_state *info) 546 - { 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 = { 551 - .dev = dev, 552 - .precharge = mclk_precharge, 553 - .refresh = mclk_refresh, 554 - .refresh_auto = mclk_refresh_auto, 555 - .refresh_self = mclk_refresh_self, 556 - .wait = mclk_wait, 557 - .mrg = mclk_mrg, 558 - .mrs = mclk_mrs, 559 - .clock_set = mclk_clock_set, 560 - .timing_set = mclk_timing_set, 561 - .priv = info 562 - }; 563 - struct hwsq_ucode *hwsq = &info->mclk_hwsq; 564 - struct nvbios_pll pll; 565 - int N, M, P; 566 - int ret; 567 - 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); 573 - } else { 574 - ret = calc_pll(dev, 0x4008, &pll, perflvl->memory, &N, &M, &P); 575 - if (ret == 0) 576 - return -EINVAL; 577 - 578 - info->mctrl |= 0x80000000 | (P << 22) | (P << 16); 579 - info->mctrl |= pll.bias_p << 19; 580 - info->mcoef = (N << 8) | M; 581 - } 582 - 583 - /* build the ucode which will reclock the memory for us */ 584 - hwsq_init(hwsq); 585 - if (crtc_mask) { 586 - hwsq_op5f(hwsq, crtc_mask, 0x00); /* wait for scanout */ 587 - hwsq_op5f(hwsq, crtc_mask, 0x01); /* wait for vblank */ 588 - } 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 */ 593 - 594 - ret = nouveau_mem_exec(&exec, perflvl); 595 - if (ret) 596 - return ret; 597 - 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 */ 602 - hwsq_fini(hwsq); 603 - return 0; 604 - } 605 - 606 - void * 607 - nv50_pm_clocks_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl) 608 - { 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; 616 - int N, M, P1, P2; 617 - 618 - if (nv_device(drm->device)->chipset == 0xaa || 619 - nv_device(drm->device)->chipset == 0xac) 620 - return ERR_PTR(-ENODEV); 621 - 622 - info = kmalloc(sizeof(*info), GFP_KERNEL); 623 - if (!info) 624 - return ERR_PTR(-ENOMEM); 625 - info->perflvl = perflvl; 626 - 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); 632 - if (ret) 633 - goto error; 634 - info->mscript = perflvl->memscript; 635 - } 636 - 637 - divs = read_div(dev); 638 - mast = info->mmast; 639 - 640 - /* start building HWSQ script for engine reclocking */ 641 - hwsq = &info->eclk_hwsq; 642 - hwsq_init(hwsq); 643 - hwsq_setf(hwsq, 0x10, 0); /* disable bus access */ 644 - hwsq_op5f(hwsq, 0x00, 0x01); /* wait for access disabled? */ 645 - 646 - /* vdec/dom6: switch to "safe" clocks temporarily */ 647 - if (perflvl->vdec) { 648 - mast &= ~0x00000c00; 649 - divs &= ~0x00000700; 650 - } 651 - 652 - if (perflvl->dom6) { 653 - mast &= ~0x0c000000; 654 - divs &= ~0x00000007; 655 - } 656 - 657 - hwsq_wr32(hwsq, 0x00c040, mast); 658 - 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 661 - * tied to xpll... 662 - */ 663 - if (perflvl->vdec) { 664 - /* see how close we can get using nvclk as a source */ 665 - clk = calc_div(perflvl->core, perflvl->vdec, &P1); 666 - 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); 670 - else 671 - out = read_clk(dev, clk_src_hclkm3d2); 672 - out = calc_div(out, perflvl->vdec, &P2); 673 - 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) 678 - mast |= 0x00000c00; 679 - divs |= P1 << 8; 680 - } else { 681 - mast |= 0x00000800; 682 - divs |= P2 << 8; 683 - } 684 - } 685 - 686 - /* dom6: nfi what this is, but we're limited to various combinations 687 - * of the host clock frequency 688 - */ 689 - if (perflvl->dom6) { 690 - if (clk_same(perflvl->dom6, read_clk(dev, clk_src_href))) { 691 - mast |= 0x00000000; 692 - } else 693 - if (clk_same(perflvl->dom6, read_clk(dev, clk_src_hclk))) { 694 - mast |= 0x08000000; 695 - } else { 696 - clk = read_clk(dev, clk_src_hclk) * 3; 697 - clk = calc_div(clk, perflvl->dom6, &P1); 698 - 699 - mast |= 0x0c000000; 700 - divs |= P1; 701 - } 702 - } 703 - 704 - /* vdec/dom6: complete switch to new clocks */ 705 - switch (nv_device(drm->device)->chipset) { 706 - case 0x92: 707 - case 0x94: 708 - case 0x96: 709 - hwsq_wr32(hwsq, 0x004800, divs); 710 - break; 711 - default: 712 - hwsq_wr32(hwsq, 0x004700, divs); 713 - break; 714 - } 715 - 716 - hwsq_wr32(hwsq, 0x00c040, mast); 717 - 718 - /* core/shader: make sure sclk/nvclk are disconnected from their 719 - * PLLs (nvclk to dom6, sclk to hclk) 720 - */ 721 - if (nv_device(drm->device)->chipset < 0x92) 722 - mast = (mast & ~0x001000b0) | 0x00100080; 723 - else 724 - mast = (mast & ~0x000000b3) | 0x00000081; 725 - 726 - hwsq_wr32(hwsq, 0x00c040, mast); 727 - 728 - /* core: for the moment at least, always use nvpll */ 729 - clk = calc_pll(dev, 0x4028, &pll, perflvl->core, &N, &M, &P1); 730 - if (clk == 0) 731 - goto error; 732 - 733 - ctrl = nv_rd32(device, 0x004028) & ~0xc03f0100; 734 - mast &= ~0x00100000; 735 - mast |= 3; 736 - 737 - hwsq_wr32(hwsq, 0x004028, 0x80000000 | (P1 << 19) | (P1 << 16) | ctrl); 738 - hwsq_wr32(hwsq, 0x00402c, (N << 8) | M); 739 - 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 744 - * corners 745 - */ 746 - ctrl = nv_rd32(device, 0x004020) & ~0xc03f0100; 747 - 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); 751 - } else { 752 - clk = calc_pll(dev, 0x4020, &pll, perflvl->shader, &N, &M, &P1); 753 - if (clk == 0) 754 - goto error; 755 - ctrl |= 0x80000000; 756 - 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); 760 - } 761 - 762 - hwsq_setf(hwsq, 0x10, 1); /* enable bus access */ 763 - hwsq_op5f(hwsq, 0x00, 0x00); /* wait for access enabled? */ 764 - hwsq_fini(hwsq); 765 - 766 - return info; 767 - error: 768 - kfree(info); 769 - return ERR_PTR(ret); 770 - } 771 - 772 - static int 773 - prog_hwsq(struct drm_device *dev, struct hwsq_ucode *hwsq) 774 - { 775 - struct nouveau_device *device = nouveau_dev(dev); 776 - struct nouveau_drm *drm = nouveau_drm(dev); 777 - u32 hwsq_data, hwsq_kick; 778 - int i; 779 - 780 - if (nv_device(drm->device)->chipset < 0x94) { 781 - hwsq_data = 0x001400; 782 - hwsq_kick = 0x00000003; 783 - } else { 784 - hwsq_data = 0x080000; 785 - hwsq_kick = 0x00000001; 786 - } 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); 795 - 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))); 804 - } 805 - 806 - return -EIO; 807 - } 808 - 809 - return 0; 810 - } 811 - 812 - int 813 - nv50_pm_clocks_set(struct drm_device *dev, void *data) 814 - { 815 - struct nouveau_device *device = nouveau_dev(dev); 816 - struct nv50_pm_state *info = data; 817 - struct bit_entry M; 818 - int ret = -EBUSY; 819 - 820 - /* halt and idle execution engines */ 821 - nv_mask(device, 0x002504, 0x00000001, 0x00000001); 822 - if (!nv_wait(device, 0x002504, 0x00000010, 0x00000010)) 823 - goto resume; 824 - if (!nv_wait(device, 0x00251c, 0x0000003f, 0x0000003f)) 825 - goto resume; 826 - 827 - /* program memory clock, if necessary - must come before engine clock 828 - * reprogramming due to how we construct the hwsq scripts in pre() 829 - */ 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) { 834 - if (M.length >= 6) 835 - nouveau_bios_init_exec(dev, ROM16(M.data[5])); 836 - if (M.length >= 8) 837 - nouveau_bios_init_exec(dev, ROM16(M.data[7])); 838 - if (M.length >= 10) 839 - nouveau_bios_init_exec(dev, ROM16(M.data[9])); 840 - nouveau_bios_init_exec(dev, info->mscript); 841 - } 842 - 843 - ret = prog_hwsq(dev, &info->mclk_hwsq); 844 - if (ret) 845 - goto resume; 846 - } 847 - 848 - /* program engine clocks */ 849 - ret = prog_hwsq(dev, &info->eclk_hwsq); 850 - 851 - resume: 852 - nv_mask(device, 0x002504, 0x00000001, 0x00000000); 853 - kfree(info); 854 - return ret; 855 - }
-624
drivers/gpu/drm/nouveau/nva3_pm.c
··· 1 - /* 2 - * Copyright 2010 Red Hat Inc. 3 - * 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: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 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. 21 - * 22 - * Authors: Ben Skeggs 23 - */ 24 - 25 - #include <drm/drmP.h> 26 - #include "nouveau_drm.h" 27 - #include "nouveau_bios.h" 28 - #include "nouveau_pm.h" 29 - 30 - #include <subdev/bios/pll.h> 31 - #include <subdev/bios.h> 32 - #include <subdev/clock.h> 33 - #include <subdev/timer.h> 34 - #include <subdev/fb.h> 35 - 36 - static u32 read_clk(struct drm_device *, int, bool); 37 - static u32 read_pll(struct drm_device *, int, u32); 38 - 39 - static u32 40 - read_vco(struct drm_device *dev, int clk) 41 - { 42 - struct nouveau_device *device = nouveau_dev(dev); 43 - u32 sctl = nv_rd32(device, 0x4120 + (clk * 4)); 44 - if ((sctl & 0x00000030) != 0x00000030) 45 - return read_pll(dev, 0x41, 0x00e820); 46 - return read_pll(dev, 0x42, 0x00e8a0); 47 - } 48 - 49 - static u32 50 - read_clk(struct drm_device *dev, int clk, bool ignore_en) 51 - { 52 - struct nouveau_device *device = nouveau_dev(dev); 53 - struct nouveau_drm *drm = nouveau_drm(dev); 54 - u32 sctl, sdiv, sclk; 55 - 56 - /* refclk for the 0xe8xx plls is a fixed frequency */ 57 - if (clk >= 0x40) { 58 - if (nv_device(drm->device)->chipset == 0xaf) { 59 - /* no joke.. seriously.. sigh.. */ 60 - return nv_rd32(device, 0x00471c) * 1000; 61 - } 62 - 63 - return device->crystal; 64 - } 65 - 66 - sctl = nv_rd32(device, 0x4120 + (clk * 4)); 67 - if (!ignore_en && !(sctl & 0x00000100)) 68 - return 0; 69 - 70 - switch (sctl & 0x00003000) { 71 - case 0x00000000: 72 - return device->crystal; 73 - case 0x00002000: 74 - if (sctl & 0x00000040) 75 - return 108000; 76 - return 100000; 77 - case 0x00003000: 78 - sclk = read_vco(dev, clk); 79 - sdiv = ((sctl & 0x003f0000) >> 16) + 2; 80 - return (sclk * 2) / sdiv; 81 - default: 82 - return 0; 83 - } 84 - } 85 - 86 - static u32 87 - read_pll(struct drm_device *dev, int clk, u32 pll) 88 - { 89 - struct nouveau_device *device = nouveau_dev(dev); 90 - u32 ctrl = nv_rd32(device, pll + 0); 91 - u32 sclk = 0, P = 1, N = 1, M = 1; 92 - 93 - if (!(ctrl & 0x00000008)) { 94 - if (ctrl & 0x00000001) { 95 - u32 coef = nv_rd32(device, pll + 4); 96 - M = (coef & 0x000000ff) >> 0; 97 - N = (coef & 0x0000ff00) >> 8; 98 - P = (coef & 0x003f0000) >> 16; 99 - 100 - /* no post-divider on these.. */ 101 - if ((pll & 0x00ff00) == 0x00e800) 102 - P = 1; 103 - 104 - sclk = read_clk(dev, 0x00 + clk, false); 105 - } 106 - } else { 107 - sclk = read_clk(dev, 0x10 + clk, false); 108 - } 109 - 110 - if (M * P) 111 - return sclk * N / (M * P); 112 - return 0; 113 - } 114 - 115 - struct creg { 116 - u32 clk; 117 - u32 pll; 118 - }; 119 - 120 - static int 121 - calc_clk(struct drm_device *dev, int clk, u32 pll, u32 khz, struct creg *reg) 122 - { 123 - struct nouveau_drm *drm = nouveau_drm(dev); 124 - struct nouveau_device *device = nouveau_dev(dev); 125 - struct nouveau_bios *bios = nouveau_bios(device); 126 - struct nvbios_pll limits; 127 - u32 oclk, sclk, sdiv; 128 - int P, N, M, diff; 129 - int ret; 130 - 131 - reg->pll = 0; 132 - reg->clk = 0; 133 - if (!khz) { 134 - NV_DEBUG(drm, "no clock for 0x%04x/0x%02x\n", pll, clk); 135 - return 0; 136 - } 137 - 138 - switch (khz) { 139 - case 27000: 140 - reg->clk = 0x00000100; 141 - return khz; 142 - case 100000: 143 - reg->clk = 0x00002100; 144 - return khz; 145 - case 108000: 146 - reg->clk = 0x00002140; 147 - return khz; 148 - default: 149 - sclk = read_vco(dev, clk); 150 - sdiv = min((sclk * 2) / (khz - 2999), (u32)65); 151 - /* if the clock has a PLL attached, and we can get a within 152 - * [-2, 3) MHz of a divider, we'll disable the PLL and use 153 - * the divider instead. 154 - * 155 - * divider can go as low as 2, limited here because NVIDIA 156 - * and the VBIOS on my NVA8 seem to prefer using the PLL 157 - * for 810MHz - is there a good reason? 158 - */ 159 - if (sdiv > 4) { 160 - oclk = (sclk * 2) / sdiv; 161 - diff = khz - oclk; 162 - if (!pll || (diff >= -2000 && diff < 3000)) { 163 - reg->clk = (((sdiv - 2) << 16) | 0x00003100); 164 - return oclk; 165 - } 166 - } 167 - 168 - if (!pll) { 169 - NV_ERROR(drm, "bad freq %02x: %d %d\n", clk, khz, sclk); 170 - return -ERANGE; 171 - } 172 - 173 - break; 174 - } 175 - 176 - ret = nvbios_pll_parse(bios, pll, &limits); 177 - if (ret) 178 - return ret; 179 - 180 - limits.refclk = read_clk(dev, clk - 0x10, true); 181 - if (!limits.refclk) 182 - return -EINVAL; 183 - 184 - ret = nva3_calc_pll(dev, &limits, khz, &N, NULL, &M, &P); 185 - if (ret >= 0) { 186 - reg->clk = nv_rd32(device, 0x4120 + (clk * 4)); 187 - reg->pll = (P << 16) | (N << 8) | M; 188 - } 189 - 190 - return ret; 191 - } 192 - 193 - static void 194 - prog_pll(struct drm_device *dev, int clk, u32 pll, struct creg *reg) 195 - { 196 - struct nouveau_device *device = nouveau_dev(dev); 197 - struct nouveau_drm *drm = nouveau_drm(dev); 198 - const u32 src0 = 0x004120 + (clk * 4); 199 - const u32 src1 = 0x004160 + (clk * 4); 200 - const u32 ctrl = pll + 0; 201 - const u32 coef = pll + 4; 202 - 203 - if (!reg->clk && !reg->pll) { 204 - NV_DEBUG(drm, "no clock for %02x\n", clk); 205 - return; 206 - } 207 - 208 - if (reg->pll) { 209 - nv_mask(device, src0, 0x00000101, 0x00000101); 210 - nv_wr32(device, coef, reg->pll); 211 - nv_mask(device, ctrl, 0x00000015, 0x00000015); 212 - nv_mask(device, ctrl, 0x00000010, 0x00000000); 213 - nv_wait(device, ctrl, 0x00020000, 0x00020000); 214 - nv_mask(device, ctrl, 0x00000010, 0x00000010); 215 - nv_mask(device, ctrl, 0x00000008, 0x00000000); 216 - nv_mask(device, src1, 0x00000100, 0x00000000); 217 - nv_mask(device, src1, 0x00000001, 0x00000000); 218 - } else { 219 - nv_mask(device, src1, 0x003f3141, 0x00000101 | reg->clk); 220 - nv_mask(device, ctrl, 0x00000018, 0x00000018); 221 - udelay(20); 222 - nv_mask(device, ctrl, 0x00000001, 0x00000000); 223 - nv_mask(device, src0, 0x00000100, 0x00000000); 224 - nv_mask(device, src0, 0x00000001, 0x00000000); 225 - } 226 - } 227 - 228 - static void 229 - prog_clk(struct drm_device *dev, int clk, struct creg *reg) 230 - { 231 - struct nouveau_device *device = nouveau_dev(dev); 232 - struct nouveau_drm *drm = nouveau_drm(dev); 233 - 234 - if (!reg->clk) { 235 - NV_DEBUG(drm, "no clock for %02x\n", clk); 236 - return; 237 - } 238 - 239 - nv_mask(device, 0x004120 + (clk * 4), 0x003f3141, 0x00000101 | reg->clk); 240 - } 241 - 242 - int 243 - nva3_pm_clocks_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) 244 - { 245 - perflvl->core = read_pll(dev, 0x00, 0x4200); 246 - perflvl->shader = read_pll(dev, 0x01, 0x4220); 247 - perflvl->memory = read_pll(dev, 0x02, 0x4000); 248 - perflvl->unka0 = read_clk(dev, 0x20, false); 249 - perflvl->vdec = read_clk(dev, 0x21, false); 250 - perflvl->daemon = read_clk(dev, 0x25, false); 251 - perflvl->copy = perflvl->core; 252 - return 0; 253 - } 254 - 255 - struct nva3_pm_state { 256 - struct nouveau_pm_level *perflvl; 257 - 258 - struct creg nclk; 259 - struct creg sclk; 260 - struct creg vdec; 261 - struct creg unka0; 262 - 263 - struct creg mclk; 264 - u8 *rammap; 265 - u8 rammap_ver; 266 - u8 rammap_len; 267 - u8 *ramcfg; 268 - u8 ramcfg_len; 269 - u32 r004018; 270 - u32 r100760; 271 - }; 272 - 273 - void * 274 - nva3_pm_clocks_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl) 275 - { 276 - struct nva3_pm_state *info; 277 - u8 ramcfg_cnt; 278 - int ret; 279 - 280 - info = kzalloc(sizeof(*info), GFP_KERNEL); 281 - if (!info) 282 - return ERR_PTR(-ENOMEM); 283 - 284 - ret = calc_clk(dev, 0x10, 0x4200, perflvl->core, &info->nclk); 285 - if (ret < 0) 286 - goto out; 287 - 288 - ret = calc_clk(dev, 0x11, 0x4220, perflvl->shader, &info->sclk); 289 - if (ret < 0) 290 - goto out; 291 - 292 - ret = calc_clk(dev, 0x12, 0x4000, perflvl->memory, &info->mclk); 293 - if (ret < 0) 294 - goto out; 295 - 296 - ret = calc_clk(dev, 0x20, 0x0000, perflvl->unka0, &info->unka0); 297 - if (ret < 0) 298 - goto out; 299 - 300 - ret = calc_clk(dev, 0x21, 0x0000, perflvl->vdec, &info->vdec); 301 - if (ret < 0) 302 - goto out; 303 - 304 - info->rammap = nouveau_perf_rammap(dev, perflvl->memory, 305 - &info->rammap_ver, 306 - &info->rammap_len, 307 - &ramcfg_cnt, &info->ramcfg_len); 308 - if (info->rammap_ver != 0x10 || info->rammap_len < 5) 309 - info->rammap = NULL; 310 - 311 - info->ramcfg = nouveau_perf_ramcfg(dev, perflvl->memory, 312 - &info->rammap_ver, 313 - &info->ramcfg_len); 314 - if (info->rammap_ver != 0x10) 315 - info->ramcfg = NULL; 316 - 317 - info->perflvl = perflvl; 318 - out: 319 - if (ret < 0) { 320 - kfree(info); 321 - info = ERR_PTR(ret); 322 - } 323 - return info; 324 - } 325 - 326 - static bool 327 - nva3_pm_grcp_idle(void *data) 328 - { 329 - struct drm_device *dev = data; 330 - struct nouveau_device *device = nouveau_dev(dev); 331 - 332 - if (!(nv_rd32(device, 0x400304) & 0x00000001)) 333 - return true; 334 - if (nv_rd32(device, 0x400308) == 0x0050001c) 335 - return true; 336 - return false; 337 - } 338 - 339 - static void 340 - mclk_precharge(struct nouveau_mem_exec_func *exec) 341 - { 342 - struct nouveau_device *device = nouveau_dev(exec->dev); 343 - nv_wr32(device, 0x1002d4, 0x00000001); 344 - } 345 - 346 - static void 347 - mclk_refresh(struct nouveau_mem_exec_func *exec) 348 - { 349 - struct nouveau_device *device = nouveau_dev(exec->dev); 350 - nv_wr32(device, 0x1002d0, 0x00000001); 351 - } 352 - 353 - static void 354 - mclk_refresh_auto(struct nouveau_mem_exec_func *exec, bool enable) 355 - { 356 - struct nouveau_device *device = nouveau_dev(exec->dev); 357 - nv_wr32(device, 0x100210, enable ? 0x80000000 : 0x00000000); 358 - } 359 - 360 - static void 361 - mclk_refresh_self(struct nouveau_mem_exec_func *exec, bool enable) 362 - { 363 - struct nouveau_device *device = nouveau_dev(exec->dev); 364 - nv_wr32(device, 0x1002dc, enable ? 0x00000001 : 0x00000000); 365 - } 366 - 367 - static void 368 - mclk_wait(struct nouveau_mem_exec_func *exec, u32 nsec) 369 - { 370 - struct nouveau_device *device = nouveau_dev(exec->dev); 371 - volatile u32 post = nv_rd32(device, 0); (void)post; 372 - udelay((nsec + 500) / 1000); 373 - } 374 - 375 - static u32 376 - mclk_mrg(struct nouveau_mem_exec_func *exec, int mr) 377 - { 378 - struct nouveau_device *device = nouveau_dev(exec->dev); 379 - if (mr <= 1) 380 - return nv_rd32(device, 0x1002c0 + ((mr - 0) * 4)); 381 - if (mr <= 3) 382 - return nv_rd32(device, 0x1002e0 + ((mr - 2) * 4)); 383 - return 0; 384 - } 385 - 386 - static void 387 - mclk_mrs(struct nouveau_mem_exec_func *exec, int mr, u32 data) 388 - { 389 - struct nouveau_device *device = nouveau_dev(exec->dev); 390 - struct nouveau_fb *pfb = nouveau_fb(device); 391 - if (mr <= 1) { 392 - if (pfb->ram->ranks > 1) 393 - nv_wr32(device, 0x1002c8 + ((mr - 0) * 4), data); 394 - nv_wr32(device, 0x1002c0 + ((mr - 0) * 4), data); 395 - } else 396 - if (mr <= 3) { 397 - if (pfb->ram->ranks > 1) 398 - nv_wr32(device, 0x1002e8 + ((mr - 2) * 4), data); 399 - nv_wr32(device, 0x1002e0 + ((mr - 2) * 4), data); 400 - } 401 - } 402 - 403 - static void 404 - mclk_clock_set(struct nouveau_mem_exec_func *exec) 405 - { 406 - struct nouveau_device *device = nouveau_dev(exec->dev); 407 - struct nva3_pm_state *info = exec->priv; 408 - u32 ctrl; 409 - 410 - ctrl = nv_rd32(device, 0x004000); 411 - if (!(ctrl & 0x00000008) && info->mclk.pll) { 412 - nv_wr32(device, 0x004000, (ctrl |= 0x00000008)); 413 - nv_mask(device, 0x1110e0, 0x00088000, 0x00088000); 414 - nv_wr32(device, 0x004018, 0x00001000); 415 - nv_wr32(device, 0x004000, (ctrl &= ~0x00000001)); 416 - nv_wr32(device, 0x004004, info->mclk.pll); 417 - nv_wr32(device, 0x004000, (ctrl |= 0x00000001)); 418 - udelay(64); 419 - nv_wr32(device, 0x004018, 0x00005000 | info->r004018); 420 - udelay(20); 421 - } else 422 - if (!info->mclk.pll) { 423 - nv_mask(device, 0x004168, 0x003f3040, info->mclk.clk); 424 - nv_wr32(device, 0x004000, (ctrl |= 0x00000008)); 425 - nv_mask(device, 0x1110e0, 0x00088000, 0x00088000); 426 - nv_wr32(device, 0x004018, 0x0000d000 | info->r004018); 427 - } 428 - 429 - if (info->rammap) { 430 - if (info->ramcfg && (info->rammap[4] & 0x08)) { 431 - u32 unk5a0 = (ROM16(info->ramcfg[5]) << 8) | 432 - info->ramcfg[5]; 433 - u32 unk5a4 = ROM16(info->ramcfg[7]); 434 - u32 unk804 = (info->ramcfg[9] & 0xf0) << 16 | 435 - (info->ramcfg[3] & 0x0f) << 16 | 436 - (info->ramcfg[9] & 0x0f) | 437 - 0x80000000; 438 - nv_wr32(device, 0x1005a0, unk5a0); 439 - nv_wr32(device, 0x1005a4, unk5a4); 440 - nv_wr32(device, 0x10f804, unk804); 441 - nv_mask(device, 0x10053c, 0x00001000, 0x00000000); 442 - } else { 443 - nv_mask(device, 0x10053c, 0x00001000, 0x00001000); 444 - nv_mask(device, 0x10f804, 0x80000000, 0x00000000); 445 - nv_mask(device, 0x100760, 0x22222222, info->r100760); 446 - nv_mask(device, 0x1007a0, 0x22222222, info->r100760); 447 - nv_mask(device, 0x1007e0, 0x22222222, info->r100760); 448 - } 449 - } 450 - 451 - if (info->mclk.pll) { 452 - nv_mask(device, 0x1110e0, 0x00088000, 0x00011000); 453 - nv_wr32(device, 0x004000, (ctrl &= ~0x00000008)); 454 - } 455 - } 456 - 457 - static void 458 - mclk_timing_set(struct nouveau_mem_exec_func *exec) 459 - { 460 - struct nouveau_device *device = nouveau_dev(exec->dev); 461 - struct nva3_pm_state *info = exec->priv; 462 - struct nouveau_pm_level *perflvl = info->perflvl; 463 - int i; 464 - 465 - for (i = 0; i < 9; i++) 466 - nv_wr32(device, 0x100220 + (i * 4), perflvl->timing.reg[i]); 467 - 468 - if (info->ramcfg) { 469 - u32 data = (info->ramcfg[2] & 0x08) ? 0x00000000 : 0x00001000; 470 - nv_mask(device, 0x100200, 0x00001000, data); 471 - } 472 - 473 - if (info->ramcfg) { 474 - u32 unk714 = nv_rd32(device, 0x100714) & ~0xf0000010; 475 - u32 unk718 = nv_rd32(device, 0x100718) & ~0x00000100; 476 - u32 unk71c = nv_rd32(device, 0x10071c) & ~0x00000100; 477 - if ( (info->ramcfg[2] & 0x20)) 478 - unk714 |= 0xf0000000; 479 - if (!(info->ramcfg[2] & 0x04)) 480 - unk714 |= 0x00000010; 481 - nv_wr32(device, 0x100714, unk714); 482 - 483 - if (info->ramcfg[2] & 0x01) 484 - unk71c |= 0x00000100; 485 - nv_wr32(device, 0x10071c, unk71c); 486 - 487 - if (info->ramcfg[2] & 0x02) 488 - unk718 |= 0x00000100; 489 - nv_wr32(device, 0x100718, unk718); 490 - 491 - if (info->ramcfg[2] & 0x10) 492 - nv_wr32(device, 0x111100, 0x48000000); /*XXX*/ 493 - } 494 - } 495 - 496 - static void 497 - prog_mem(struct drm_device *dev, struct nva3_pm_state *info) 498 - { 499 - struct nouveau_device *device = nouveau_dev(dev); 500 - struct nouveau_mem_exec_func exec = { 501 - .dev = dev, 502 - .precharge = mclk_precharge, 503 - .refresh = mclk_refresh, 504 - .refresh_auto = mclk_refresh_auto, 505 - .refresh_self = mclk_refresh_self, 506 - .wait = mclk_wait, 507 - .mrg = mclk_mrg, 508 - .mrs = mclk_mrs, 509 - .clock_set = mclk_clock_set, 510 - .timing_set = mclk_timing_set, 511 - .priv = info 512 - }; 513 - u32 ctrl; 514 - 515 - /* XXX: where the fuck does 750MHz come from? */ 516 - if (info->perflvl->memory <= 750000) { 517 - info->r004018 = 0x10000000; 518 - info->r100760 = 0x22222222; 519 - } 520 - 521 - ctrl = nv_rd32(device, 0x004000); 522 - if (ctrl & 0x00000008) { 523 - if (info->mclk.pll) { 524 - nv_mask(device, 0x004128, 0x00000101, 0x00000101); 525 - nv_wr32(device, 0x004004, info->mclk.pll); 526 - nv_wr32(device, 0x004000, (ctrl |= 0x00000001)); 527 - nv_wr32(device, 0x004000, (ctrl &= 0xffffffef)); 528 - nv_wait(device, 0x004000, 0x00020000, 0x00020000); 529 - nv_wr32(device, 0x004000, (ctrl |= 0x00000010)); 530 - nv_wr32(device, 0x004018, 0x00005000 | info->r004018); 531 - nv_wr32(device, 0x004000, (ctrl |= 0x00000004)); 532 - } 533 - } else { 534 - u32 ssel = 0x00000101; 535 - if (info->mclk.clk) 536 - ssel |= info->mclk.clk; 537 - else 538 - ssel |= 0x00080000; /* 324MHz, shouldn't matter... */ 539 - nv_mask(device, 0x004168, 0x003f3141, ctrl); 540 - } 541 - 542 - if (info->ramcfg) { 543 - if (info->ramcfg[2] & 0x10) { 544 - nv_mask(device, 0x111104, 0x00000600, 0x00000000); 545 - } else { 546 - nv_mask(device, 0x111100, 0x40000000, 0x40000000); 547 - nv_mask(device, 0x111104, 0x00000180, 0x00000000); 548 - } 549 - } 550 - if (info->rammap && !(info->rammap[4] & 0x02)) 551 - nv_mask(device, 0x100200, 0x00000800, 0x00000000); 552 - nv_wr32(device, 0x611200, 0x00003300); 553 - if (!(info->ramcfg[2] & 0x10)) 554 - nv_wr32(device, 0x111100, 0x4c020000); /*XXX*/ 555 - 556 - nouveau_mem_exec(&exec, info->perflvl); 557 - 558 - nv_wr32(device, 0x611200, 0x00003330); 559 - if (info->rammap && (info->rammap[4] & 0x02)) 560 - nv_mask(device, 0x100200, 0x00000800, 0x00000800); 561 - if (info->ramcfg) { 562 - if (info->ramcfg[2] & 0x10) { 563 - nv_mask(device, 0x111104, 0x00000180, 0x00000180); 564 - nv_mask(device, 0x111100, 0x40000000, 0x00000000); 565 - } else { 566 - nv_mask(device, 0x111104, 0x00000600, 0x00000600); 567 - } 568 - } 569 - 570 - if (info->mclk.pll) { 571 - nv_mask(device, 0x004168, 0x00000001, 0x00000000); 572 - nv_mask(device, 0x004168, 0x00000100, 0x00000000); 573 - } else { 574 - nv_mask(device, 0x004000, 0x00000001, 0x00000000); 575 - nv_mask(device, 0x004128, 0x00000001, 0x00000000); 576 - nv_mask(device, 0x004128, 0x00000100, 0x00000000); 577 - } 578 - } 579 - 580 - int 581 - nva3_pm_clocks_set(struct drm_device *dev, void *pre_state) 582 - { 583 - struct nouveau_device *device = nouveau_dev(dev); 584 - struct nouveau_drm *drm = nouveau_drm(dev); 585 - struct nva3_pm_state *info = pre_state; 586 - int ret = -EAGAIN; 587 - 588 - /* prevent any new grctx switches from starting */ 589 - nv_wr32(device, 0x400324, 0x00000000); 590 - nv_wr32(device, 0x400328, 0x0050001c); /* wait flag 0x1c */ 591 - /* wait for any pending grctx switches to complete */ 592 - if (!nv_wait_cb(device, nva3_pm_grcp_idle, dev)) { 593 - NV_ERROR(drm, "pm: ctxprog didn't go idle\n"); 594 - goto cleanup; 595 - } 596 - /* freeze PFIFO */ 597 - nv_mask(device, 0x002504, 0x00000001, 0x00000001); 598 - if (!nv_wait(device, 0x002504, 0x00000010, 0x00000010)) { 599 - NV_ERROR(drm, "pm: fifo didn't go idle\n"); 600 - goto cleanup; 601 - } 602 - 603 - prog_pll(dev, 0x00, 0x004200, &info->nclk); 604 - prog_pll(dev, 0x01, 0x004220, &info->sclk); 605 - prog_clk(dev, 0x20, &info->unka0); 606 - prog_clk(dev, 0x21, &info->vdec); 607 - 608 - if (info->mclk.clk || info->mclk.pll) 609 - prog_mem(dev, info); 610 - 611 - ret = 0; 612 - 613 - cleanup: 614 - /* unfreeze PFIFO */ 615 - nv_mask(device, 0x002504, 0x00000001, 0x00000000); 616 - /* restore ctxprog to normal */ 617 - nv_wr32(device, 0x400324, 0x00000000); 618 - nv_wr32(device, 0x400328, 0x0070009c); /* set flag 0x1c */ 619 - /* unblock it if necessary */ 620 - if (nv_rd32(device, 0x400308) == 0x0050001c) 621 - nv_mask(device, 0x400824, 0x10000000, 0x10000000); 622 - kfree(info); 623 - return ret; 624 - }
-599
drivers/gpu/drm/nouveau/nvc0_pm.c
··· 1 - /* 2 - * Copyright 2011 Red Hat Inc. 3 - * 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: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 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. 21 - * 22 - * Authors: Ben Skeggs 23 - */ 24 - 25 - #include "nouveau_drm.h" 26 - #include "nouveau_bios.h" 27 - #include "nouveau_pm.h" 28 - 29 - #include <subdev/bios/pll.h> 30 - #include <subdev/bios.h> 31 - #include <subdev/clock.h> 32 - #include <subdev/timer.h> 33 - #include <subdev/fb.h> 34 - 35 - static u32 read_div(struct drm_device *, int, u32, u32); 36 - static u32 read_pll(struct drm_device *, u32); 37 - 38 - static u32 39 - read_vco(struct drm_device *dev, u32 dsrc) 40 - { 41 - struct nouveau_device *device = nouveau_dev(dev); 42 - u32 ssrc = nv_rd32(device, dsrc); 43 - if (!(ssrc & 0x00000100)) 44 - return read_pll(dev, 0x00e800); 45 - return read_pll(dev, 0x00e820); 46 - } 47 - 48 - static u32 49 - read_pll(struct drm_device *dev, u32 pll) 50 - { 51 - struct nouveau_device *device = nouveau_dev(dev); 52 - u32 ctrl = nv_rd32(device, pll + 0); 53 - u32 coef = nv_rd32(device, pll + 4); 54 - u32 P = (coef & 0x003f0000) >> 16; 55 - u32 N = (coef & 0x0000ff00) >> 8; 56 - u32 M = (coef & 0x000000ff) >> 0; 57 - u32 sclk, doff; 58 - 59 - if (!(ctrl & 0x00000001)) 60 - return 0; 61 - 62 - switch (pll & 0xfff000) { 63 - case 0x00e000: 64 - sclk = 27000; 65 - P = 1; 66 - break; 67 - case 0x137000: 68 - doff = (pll - 0x137000) / 0x20; 69 - sclk = read_div(dev, doff, 0x137120, 0x137140); 70 - break; 71 - case 0x132000: 72 - switch (pll) { 73 - case 0x132000: 74 - sclk = read_pll(dev, 0x132020); 75 - break; 76 - case 0x132020: 77 - sclk = read_div(dev, 0, 0x137320, 0x137330); 78 - break; 79 - default: 80 - return 0; 81 - } 82 - break; 83 - default: 84 - return 0; 85 - } 86 - 87 - return sclk * N / M / P; 88 - } 89 - 90 - static u32 91 - read_div(struct drm_device *dev, int doff, u32 dsrc, u32 dctl) 92 - { 93 - struct nouveau_device *device = nouveau_dev(dev); 94 - u32 ssrc = nv_rd32(device, dsrc + (doff * 4)); 95 - u32 sctl = nv_rd32(device, dctl + (doff * 4)); 96 - 97 - switch (ssrc & 0x00000003) { 98 - case 0: 99 - if ((ssrc & 0x00030000) != 0x00030000) 100 - return 27000; 101 - return 108000; 102 - case 2: 103 - return 100000; 104 - case 3: 105 - if (sctl & 0x80000000) { 106 - u32 sclk = read_vco(dev, dsrc + (doff * 4)); 107 - u32 sdiv = (sctl & 0x0000003f) + 2; 108 - return (sclk * 2) / sdiv; 109 - } 110 - 111 - return read_vco(dev, dsrc + (doff * 4)); 112 - default: 113 - return 0; 114 - } 115 - } 116 - 117 - static u32 118 - read_mem(struct drm_device *dev) 119 - { 120 - struct nouveau_device *device = nouveau_dev(dev); 121 - u32 ssel = nv_rd32(device, 0x1373f0); 122 - if (ssel & 0x00000001) 123 - return read_div(dev, 0, 0x137300, 0x137310); 124 - return read_pll(dev, 0x132000); 125 - } 126 - 127 - static u32 128 - read_clk(struct drm_device *dev, int clk) 129 - { 130 - struct nouveau_device *device = nouveau_dev(dev); 131 - u32 sctl = nv_rd32(device, 0x137250 + (clk * 4)); 132 - u32 ssel = nv_rd32(device, 0x137100); 133 - u32 sclk, sdiv; 134 - 135 - if (ssel & (1 << clk)) { 136 - if (clk < 7) 137 - sclk = read_pll(dev, 0x137000 + (clk * 0x20)); 138 - else 139 - sclk = read_pll(dev, 0x1370e0); 140 - sdiv = ((sctl & 0x00003f00) >> 8) + 2; 141 - } else { 142 - sclk = read_div(dev, clk, 0x137160, 0x1371d0); 143 - sdiv = ((sctl & 0x0000003f) >> 0) + 2; 144 - } 145 - 146 - if (sctl & 0x80000000) 147 - return (sclk * 2) / sdiv; 148 - return sclk; 149 - } 150 - 151 - int 152 - nvc0_pm_clocks_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) 153 - { 154 - perflvl->shader = read_clk(dev, 0x00); 155 - perflvl->core = perflvl->shader / 2; 156 - perflvl->memory = read_mem(dev); 157 - perflvl->rop = read_clk(dev, 0x01); 158 - perflvl->hub07 = read_clk(dev, 0x02); 159 - perflvl->hub06 = read_clk(dev, 0x07); 160 - perflvl->hub01 = read_clk(dev, 0x08); 161 - perflvl->copy = read_clk(dev, 0x09); 162 - perflvl->daemon = read_clk(dev, 0x0c); 163 - perflvl->vdec = read_clk(dev, 0x0e); 164 - return 0; 165 - } 166 - 167 - struct nvc0_pm_clock { 168 - u32 freq; 169 - u32 ssel; 170 - u32 mdiv; 171 - u32 dsrc; 172 - u32 ddiv; 173 - u32 coef; 174 - }; 175 - 176 - struct nvc0_pm_state { 177 - struct nouveau_pm_level *perflvl; 178 - struct nvc0_pm_clock eng[16]; 179 - struct nvc0_pm_clock mem; 180 - }; 181 - 182 - static u32 183 - calc_div(struct drm_device *dev, int clk, u32 ref, u32 freq, u32 *ddiv) 184 - { 185 - u32 div = min((ref * 2) / freq, (u32)65); 186 - if (div < 2) 187 - div = 2; 188 - 189 - *ddiv = div - 2; 190 - return (ref * 2) / div; 191 - } 192 - 193 - static u32 194 - calc_src(struct drm_device *dev, int clk, u32 freq, u32 *dsrc, u32 *ddiv) 195 - { 196 - u32 sclk; 197 - 198 - /* use one of the fixed frequencies if possible */ 199 - *ddiv = 0x00000000; 200 - switch (freq) { 201 - case 27000: 202 - case 108000: 203 - *dsrc = 0x00000000; 204 - if (freq == 108000) 205 - *dsrc |= 0x00030000; 206 - return freq; 207 - case 100000: 208 - *dsrc = 0x00000002; 209 - return freq; 210 - default: 211 - *dsrc = 0x00000003; 212 - break; 213 - } 214 - 215 - /* otherwise, calculate the closest divider */ 216 - sclk = read_vco(dev, clk); 217 - if (clk < 7) 218 - sclk = calc_div(dev, clk, sclk, freq, ddiv); 219 - return sclk; 220 - } 221 - 222 - static u32 223 - calc_pll(struct drm_device *dev, int clk, u32 freq, u32 *coef) 224 - { 225 - struct nouveau_device *device = nouveau_dev(dev); 226 - struct nouveau_bios *bios = nouveau_bios(device); 227 - struct nvbios_pll limits; 228 - int N, M, P, ret; 229 - 230 - ret = nvbios_pll_parse(bios, 0x137000 + (clk * 0x20), &limits); 231 - if (ret) 232 - return 0; 233 - 234 - limits.refclk = read_div(dev, clk, 0x137120, 0x137140); 235 - if (!limits.refclk) 236 - return 0; 237 - 238 - ret = nva3_calc_pll(dev, &limits, freq, &N, NULL, &M, &P); 239 - if (ret <= 0) 240 - return 0; 241 - 242 - *coef = (P << 16) | (N << 8) | M; 243 - return ret; 244 - } 245 - 246 - /* A (likely rather simplified and incomplete) view of the clock tree 247 - * 248 - * Key: 249 - * 250 - * S: source select 251 - * D: divider 252 - * P: pll 253 - * F: switch 254 - * 255 - * Engine clocks: 256 - * 257 - * 137250(D) ---- 137100(F0) ---- 137160(S)/1371d0(D) ------------------- ref 258 - * (F1) ---- 1370X0(P) ---- 137120(S)/137140(D) ---- ref 259 - * 260 - * Not all registers exist for all clocks. For example: clocks >= 8 don't 261 - * have their own PLL (all tied to clock 7's PLL when in PLL mode), nor do 262 - * they have the divider at 1371d0, though the source selection at 137160 263 - * still exists. You must use the divider at 137250 for these instead. 264 - * 265 - * Memory clock: 266 - * 267 - * TBD, read_mem() above is likely very wrong... 268 - * 269 - */ 270 - 271 - static int 272 - calc_clk(struct drm_device *dev, int clk, struct nvc0_pm_clock *info, u32 freq) 273 - { 274 - u32 src0, div0, div1D, div1P = 0; 275 - u32 clk0, clk1 = 0; 276 - 277 - /* invalid clock domain */ 278 - if (!freq) 279 - return 0; 280 - 281 - /* first possible path, using only dividers */ 282 - clk0 = calc_src(dev, clk, freq, &src0, &div0); 283 - clk0 = calc_div(dev, clk, clk0, freq, &div1D); 284 - 285 - /* see if we can get any closer using PLLs */ 286 - if (clk0 != freq && (0x00004387 & (1 << clk))) { 287 - if (clk < 7) 288 - clk1 = calc_pll(dev, clk, freq, &info->coef); 289 - else 290 - clk1 = read_pll(dev, 0x1370e0); 291 - clk1 = calc_div(dev, clk, clk1, freq, &div1P); 292 - } 293 - 294 - /* select the method which gets closest to target freq */ 295 - if (abs((int)freq - clk0) <= abs((int)freq - clk1)) { 296 - info->dsrc = src0; 297 - if (div0) { 298 - info->ddiv |= 0x80000000; 299 - info->ddiv |= div0 << 8; 300 - info->ddiv |= div0; 301 - } 302 - if (div1D) { 303 - info->mdiv |= 0x80000000; 304 - info->mdiv |= div1D; 305 - } 306 - info->ssel = 0; 307 - info->freq = clk0; 308 - } else { 309 - if (div1P) { 310 - info->mdiv |= 0x80000000; 311 - info->mdiv |= div1P << 8; 312 - } 313 - info->ssel = (1 << clk); 314 - info->freq = clk1; 315 - } 316 - 317 - return 0; 318 - } 319 - 320 - static int 321 - calc_mem(struct drm_device *dev, struct nvc0_pm_clock *info, u32 freq) 322 - { 323 - struct nouveau_device *device = nouveau_dev(dev); 324 - struct nouveau_bios *bios = nouveau_bios(device); 325 - struct nvbios_pll pll; 326 - int N, M, P, ret; 327 - u32 ctrl; 328 - 329 - /* mclk pll input freq comes from another pll, make sure it's on */ 330 - ctrl = nv_rd32(device, 0x132020); 331 - if (!(ctrl & 0x00000001)) { 332 - /* if not, program it to 567MHz. nfi where this value comes 333 - * from - it looks like it's in the pll limits table for 334 - * 132000 but the binary driver ignores all my attempts to 335 - * change this value. 336 - */ 337 - nv_wr32(device, 0x137320, 0x00000103); 338 - nv_wr32(device, 0x137330, 0x81200606); 339 - nv_wait(device, 0x132020, 0x00010000, 0x00010000); 340 - nv_wr32(device, 0x132024, 0x0001150f); 341 - nv_mask(device, 0x132020, 0x00000001, 0x00000001); 342 - nv_wait(device, 0x137390, 0x00020000, 0x00020000); 343 - nv_mask(device, 0x132020, 0x00000004, 0x00000004); 344 - } 345 - 346 - /* for the moment, until the clock tree is better understood, use 347 - * pll mode for all clock frequencies 348 - */ 349 - ret = nvbios_pll_parse(bios, 0x132000, &pll); 350 - if (ret == 0) { 351 - pll.refclk = read_pll(dev, 0x132020); 352 - if (pll.refclk) { 353 - ret = nva3_calc_pll(dev, &pll, freq, &N, NULL, &M, &P); 354 - if (ret > 0) { 355 - info->coef = (P << 16) | (N << 8) | M; 356 - return 0; 357 - } 358 - } 359 - } 360 - 361 - return -EINVAL; 362 - } 363 - 364 - void * 365 - nvc0_pm_clocks_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl) 366 - { 367 - struct nouveau_device *device = nouveau_dev(dev); 368 - struct nvc0_pm_state *info; 369 - int ret; 370 - 371 - info = kzalloc(sizeof(*info), GFP_KERNEL); 372 - if (!info) 373 - return ERR_PTR(-ENOMEM); 374 - 375 - /* NFI why this is still in the performance table, the ROPCs appear 376 - * to get their clock from clock 2 ("hub07", actually hub05 on this 377 - * chip, but, anyway...) as well. nvatiming confirms hub05 and ROP 378 - * are always the same freq with the binary driver even when the 379 - * performance table says they should differ. 380 - */ 381 - if (device->chipset == 0xd9) 382 - perflvl->rop = 0; 383 - 384 - if ((ret = calc_clk(dev, 0x00, &info->eng[0x00], perflvl->shader)) || 385 - (ret = calc_clk(dev, 0x01, &info->eng[0x01], perflvl->rop)) || 386 - (ret = calc_clk(dev, 0x02, &info->eng[0x02], perflvl->hub07)) || 387 - (ret = calc_clk(dev, 0x07, &info->eng[0x07], perflvl->hub06)) || 388 - (ret = calc_clk(dev, 0x08, &info->eng[0x08], perflvl->hub01)) || 389 - (ret = calc_clk(dev, 0x09, &info->eng[0x09], perflvl->copy)) || 390 - (ret = calc_clk(dev, 0x0c, &info->eng[0x0c], perflvl->daemon)) || 391 - (ret = calc_clk(dev, 0x0e, &info->eng[0x0e], perflvl->vdec))) { 392 - kfree(info); 393 - return ERR_PTR(ret); 394 - } 395 - 396 - if (perflvl->memory) { 397 - ret = calc_mem(dev, &info->mem, perflvl->memory); 398 - if (ret) { 399 - kfree(info); 400 - return ERR_PTR(ret); 401 - } 402 - } 403 - 404 - info->perflvl = perflvl; 405 - return info; 406 - } 407 - 408 - static void 409 - prog_clk(struct drm_device *dev, int clk, struct nvc0_pm_clock *info) 410 - { 411 - struct nouveau_device *device = nouveau_dev(dev); 412 - 413 - /* program dividers at 137160/1371d0 first */ 414 - if (clk < 7 && !info->ssel) { 415 - nv_mask(device, 0x1371d0 + (clk * 0x04), 0x80003f3f, info->ddiv); 416 - nv_wr32(device, 0x137160 + (clk * 0x04), info->dsrc); 417 - } 418 - 419 - /* switch clock to non-pll mode */ 420 - nv_mask(device, 0x137100, (1 << clk), 0x00000000); 421 - nv_wait(device, 0x137100, (1 << clk), 0x00000000); 422 - 423 - /* reprogram pll */ 424 - if (clk < 7) { 425 - /* make sure it's disabled first... */ 426 - u32 base = 0x137000 + (clk * 0x20); 427 - u32 ctrl = nv_rd32(device, base + 0x00); 428 - if (ctrl & 0x00000001) { 429 - nv_mask(device, base + 0x00, 0x00000004, 0x00000000); 430 - nv_mask(device, base + 0x00, 0x00000001, 0x00000000); 431 - } 432 - /* program it to new values, if necessary */ 433 - if (info->ssel) { 434 - nv_wr32(device, base + 0x04, info->coef); 435 - nv_mask(device, base + 0x00, 0x00000001, 0x00000001); 436 - nv_wait(device, base + 0x00, 0x00020000, 0x00020000); 437 - nv_mask(device, base + 0x00, 0x00020004, 0x00000004); 438 - } 439 - } 440 - 441 - /* select pll/non-pll mode, and program final clock divider */ 442 - nv_mask(device, 0x137100, (1 << clk), info->ssel); 443 - nv_wait(device, 0x137100, (1 << clk), info->ssel); 444 - nv_mask(device, 0x137250 + (clk * 0x04), 0x00003f3f, info->mdiv); 445 - } 446 - 447 - static void 448 - mclk_precharge(struct nouveau_mem_exec_func *exec) 449 - { 450 - } 451 - 452 - static void 453 - mclk_refresh(struct nouveau_mem_exec_func *exec) 454 - { 455 - } 456 - 457 - static void 458 - mclk_refresh_auto(struct nouveau_mem_exec_func *exec, bool enable) 459 - { 460 - struct nouveau_device *device = nouveau_dev(exec->dev); 461 - nv_wr32(device, 0x10f210, enable ? 0x80000000 : 0x00000000); 462 - } 463 - 464 - static void 465 - mclk_refresh_self(struct nouveau_mem_exec_func *exec, bool enable) 466 - { 467 - } 468 - 469 - static void 470 - mclk_wait(struct nouveau_mem_exec_func *exec, u32 nsec) 471 - { 472 - udelay((nsec + 500) / 1000); 473 - } 474 - 475 - static u32 476 - mclk_mrg(struct nouveau_mem_exec_func *exec, int mr) 477 - { 478 - struct nouveau_device *device = nouveau_dev(exec->dev); 479 - struct nouveau_fb *pfb = nouveau_fb(device); 480 - if (pfb->ram->type != NV_MEM_TYPE_GDDR5) { 481 - if (mr <= 1) 482 - return nv_rd32(device, 0x10f300 + ((mr - 0) * 4)); 483 - return nv_rd32(device, 0x10f320 + ((mr - 2) * 4)); 484 - } else { 485 - if (mr == 0) 486 - return nv_rd32(device, 0x10f300 + (mr * 4)); 487 - else 488 - if (mr <= 7) 489 - return nv_rd32(device, 0x10f32c + (mr * 4)); 490 - return nv_rd32(device, 0x10f34c); 491 - } 492 - } 493 - 494 - static void 495 - mclk_mrs(struct nouveau_mem_exec_func *exec, int mr, u32 data) 496 - { 497 - struct nouveau_device *device = nouveau_dev(exec->dev); 498 - struct nouveau_fb *pfb = nouveau_fb(device); 499 - if (pfb->ram->type != NV_MEM_TYPE_GDDR5) { 500 - if (mr <= 1) { 501 - nv_wr32(device, 0x10f300 + ((mr - 0) * 4), data); 502 - if (pfb->ram->ranks > 1) 503 - nv_wr32(device, 0x10f308 + ((mr - 0) * 4), data); 504 - } else 505 - if (mr <= 3) { 506 - nv_wr32(device, 0x10f320 + ((mr - 2) * 4), data); 507 - if (pfb->ram->ranks > 1) 508 - nv_wr32(device, 0x10f328 + ((mr - 2) * 4), data); 509 - } 510 - } else { 511 - if (mr == 0) nv_wr32(device, 0x10f300 + (mr * 4), data); 512 - else if (mr <= 7) nv_wr32(device, 0x10f32c + (mr * 4), data); 513 - else if (mr == 15) nv_wr32(device, 0x10f34c, data); 514 - } 515 - } 516 - 517 - static void 518 - mclk_clock_set(struct nouveau_mem_exec_func *exec) 519 - { 520 - struct nouveau_device *device = nouveau_dev(exec->dev); 521 - struct nvc0_pm_state *info = exec->priv; 522 - u32 ctrl = nv_rd32(device, 0x132000); 523 - 524 - nv_wr32(device, 0x137360, 0x00000001); 525 - nv_wr32(device, 0x137370, 0x00000000); 526 - nv_wr32(device, 0x137380, 0x00000000); 527 - if (ctrl & 0x00000001) 528 - nv_wr32(device, 0x132000, (ctrl &= ~0x00000001)); 529 - 530 - nv_wr32(device, 0x132004, info->mem.coef); 531 - nv_wr32(device, 0x132000, (ctrl |= 0x00000001)); 532 - nv_wait(device, 0x137390, 0x00000002, 0x00000002); 533 - nv_wr32(device, 0x132018, 0x00005000); 534 - 535 - nv_wr32(device, 0x137370, 0x00000001); 536 - nv_wr32(device, 0x137380, 0x00000001); 537 - nv_wr32(device, 0x137360, 0x00000000); 538 - } 539 - 540 - static void 541 - mclk_timing_set(struct nouveau_mem_exec_func *exec) 542 - { 543 - struct nouveau_device *device = nouveau_dev(exec->dev); 544 - struct nvc0_pm_state *info = exec->priv; 545 - struct nouveau_pm_level *perflvl = info->perflvl; 546 - int i; 547 - 548 - for (i = 0; i < 5; i++) 549 - nv_wr32(device, 0x10f290 + (i * 4), perflvl->timing.reg[i]); 550 - } 551 - 552 - static void 553 - prog_mem(struct drm_device *dev, struct nvc0_pm_state *info) 554 - { 555 - struct nouveau_device *device = nouveau_dev(dev); 556 - struct nouveau_mem_exec_func exec = { 557 - .dev = dev, 558 - .precharge = mclk_precharge, 559 - .refresh = mclk_refresh, 560 - .refresh_auto = mclk_refresh_auto, 561 - .refresh_self = mclk_refresh_self, 562 - .wait = mclk_wait, 563 - .mrg = mclk_mrg, 564 - .mrs = mclk_mrs, 565 - .clock_set = mclk_clock_set, 566 - .timing_set = mclk_timing_set, 567 - .priv = info 568 - }; 569 - 570 - if (device->chipset < 0xd0) 571 - nv_wr32(device, 0x611200, 0x00003300); 572 - else 573 - nv_wr32(device, 0x62c000, 0x03030000); 574 - 575 - nouveau_mem_exec(&exec, info->perflvl); 576 - 577 - if (device->chipset < 0xd0) 578 - nv_wr32(device, 0x611200, 0x00003330); 579 - else 580 - nv_wr32(device, 0x62c000, 0x03030300); 581 - } 582 - int 583 - nvc0_pm_clocks_set(struct drm_device *dev, void *data) 584 - { 585 - struct nvc0_pm_state *info = data; 586 - int i; 587 - 588 - if (info->mem.coef) 589 - prog_mem(dev, info); 590 - 591 - for (i = 0; i < 16; i++) { 592 - if (!info->eng[i].freq) 593 - continue; 594 - prog_clk(dev, i, &info->eng[i]); 595 - } 596 - 597 - kfree(info); 598 - return 0; 599 - }