Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Maarten Maathuis. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include "drmP.h" |
| 28 | #include "drm_mode.h" |
| 29 | #include "drm_crtc_helper.h" |
| 30 | |
| 31 | #define NOUVEAU_DMA_DEBUG (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO) |
| 32 | #include "nouveau_reg.h" |
| 33 | #include "nouveau_drv.h" |
| 34 | #include "nouveau_hw.h" |
| 35 | #include "nouveau_encoder.h" |
| 36 | #include "nouveau_crtc.h" |
| 37 | #include "nouveau_fb.h" |
| 38 | #include "nouveau_connector.h" |
| 39 | #include "nv50_display.h" |
| 40 | |
Ben Skeggs | 549cd87 | 2011-10-06 11:51:45 +1000 | [diff] [blame] | 41 | static int |
| 42 | nv50_crtc_wait_complete(struct drm_crtc *crtc) |
| 43 | { |
| 44 | struct drm_device *dev = crtc->dev; |
| 45 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 46 | struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer; |
| 47 | struct nv50_display *disp = nv50_display(dev); |
| 48 | struct nouveau_channel *evo = disp->master; |
| 49 | u64 start; |
| 50 | int ret; |
| 51 | |
| 52 | ret = RING_SPACE(evo, 6); |
| 53 | if (ret) |
| 54 | return ret; |
| 55 | BEGIN_RING(evo, 0, 0x0084, 1); |
| 56 | OUT_RING (evo, 0x80000000); |
| 57 | BEGIN_RING(evo, 0, 0x0080, 1); |
| 58 | OUT_RING (evo, 0); |
| 59 | BEGIN_RING(evo, 0, 0x0084, 1); |
| 60 | OUT_RING (evo, 0x00000000); |
| 61 | |
| 62 | nv_wo32(disp->ntfy, 0x000, 0x00000000); |
| 63 | FIRE_RING (evo); |
| 64 | |
| 65 | start = ptimer->read(dev); |
| 66 | do { |
| 67 | if (nv_ro32(disp->ntfy, 0x000)) |
| 68 | return 0; |
| 69 | } while (ptimer->read(dev) - start < 2000000000ULL); |
| 70 | |
| 71 | return -EBUSY; |
| 72 | } |
| 73 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 74 | static void |
| 75 | nv50_crtc_lut_load(struct drm_crtc *crtc) |
| 76 | { |
| 77 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 78 | void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo); |
| 79 | int i; |
| 80 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 81 | NV_DEBUG_KMS(crtc->dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 82 | |
| 83 | for (i = 0; i < 256; i++) { |
| 84 | writew(nv_crtc->lut.r[i] >> 2, lut + 8*i + 0); |
| 85 | writew(nv_crtc->lut.g[i] >> 2, lut + 8*i + 2); |
| 86 | writew(nv_crtc->lut.b[i] >> 2, lut + 8*i + 4); |
| 87 | } |
| 88 | |
| 89 | if (nv_crtc->lut.depth == 30) { |
| 90 | writew(nv_crtc->lut.r[i - 1] >> 2, lut + 8*i + 0); |
| 91 | writew(nv_crtc->lut.g[i - 1] >> 2, lut + 8*i + 2); |
| 92 | writew(nv_crtc->lut.b[i - 1] >> 2, lut + 8*i + 4); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | int |
| 97 | nv50_crtc_blank(struct nouveau_crtc *nv_crtc, bool blanked) |
| 98 | { |
| 99 | struct drm_device *dev = nv_crtc->base.dev; |
| 100 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 101 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 102 | int index = nv_crtc->index, ret; |
| 103 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 104 | NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); |
| 105 | NV_DEBUG_KMS(dev, "%s\n", blanked ? "blanked" : "unblanked"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 106 | |
| 107 | if (blanked) { |
| 108 | nv_crtc->cursor.hide(nv_crtc, false); |
| 109 | |
| 110 | ret = RING_SPACE(evo, dev_priv->chipset != 0x50 ? 7 : 5); |
| 111 | if (ret) { |
| 112 | NV_ERROR(dev, "no space while blanking crtc\n"); |
| 113 | return ret; |
| 114 | } |
| 115 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(index, CLUT_MODE), 2); |
| 116 | OUT_RING(evo, NV50_EVO_CRTC_CLUT_MODE_BLANK); |
| 117 | OUT_RING(evo, 0); |
| 118 | if (dev_priv->chipset != 0x50) { |
| 119 | BEGIN_RING(evo, 0, NV84_EVO_CRTC(index, CLUT_DMA), 1); |
| 120 | OUT_RING(evo, NV84_EVO_CRTC_CLUT_DMA_HANDLE_NONE); |
| 121 | } |
| 122 | |
| 123 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(index, FB_DMA), 1); |
| 124 | OUT_RING(evo, NV50_EVO_CRTC_FB_DMA_HANDLE_NONE); |
| 125 | } else { |
| 126 | if (nv_crtc->cursor.visible) |
| 127 | nv_crtc->cursor.show(nv_crtc, false); |
| 128 | else |
| 129 | nv_crtc->cursor.hide(nv_crtc, false); |
| 130 | |
| 131 | ret = RING_SPACE(evo, dev_priv->chipset != 0x50 ? 10 : 8); |
| 132 | if (ret) { |
| 133 | NV_ERROR(dev, "no space while unblanking crtc\n"); |
| 134 | return ret; |
| 135 | } |
| 136 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(index, CLUT_MODE), 2); |
| 137 | OUT_RING(evo, nv_crtc->lut.depth == 8 ? |
| 138 | NV50_EVO_CRTC_CLUT_MODE_OFF : |
| 139 | NV50_EVO_CRTC_CLUT_MODE_ON); |
Ben Skeggs | 180cc30 | 2011-06-07 11:24:14 +1000 | [diff] [blame] | 140 | OUT_RING(evo, nv_crtc->lut.nvbo->bo.offset >> 8); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 141 | if (dev_priv->chipset != 0x50) { |
| 142 | BEGIN_RING(evo, 0, NV84_EVO_CRTC(index, CLUT_DMA), 1); |
| 143 | OUT_RING(evo, NvEvoVRAM); |
| 144 | } |
| 145 | |
| 146 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(index, FB_OFFSET), 2); |
| 147 | OUT_RING(evo, nv_crtc->fb.offset >> 8); |
| 148 | OUT_RING(evo, 0); |
| 149 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(index, FB_DMA), 1); |
| 150 | if (dev_priv->chipset != 0x50) |
Ben Skeggs | 6d86951 | 2010-12-08 11:19:30 +1000 | [diff] [blame] | 151 | if (nv_crtc->fb.tile_flags == 0x7a00 || |
| 152 | nv_crtc->fb.tile_flags == 0xfe00) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 153 | OUT_RING(evo, NvEvoFB32); |
| 154 | else |
| 155 | if (nv_crtc->fb.tile_flags == 0x7000) |
| 156 | OUT_RING(evo, NvEvoFB16); |
| 157 | else |
Ben Skeggs | 6d86951 | 2010-12-08 11:19:30 +1000 | [diff] [blame] | 158 | OUT_RING(evo, NvEvoVRAM_LP); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 159 | else |
Ben Skeggs | 6d86951 | 2010-12-08 11:19:30 +1000 | [diff] [blame] | 160 | OUT_RING(evo, NvEvoVRAM_LP); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | nv_crtc->fb.blanked = blanked; |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int |
| 168 | nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool on, bool update) |
| 169 | { |
| 170 | struct drm_device *dev = nv_crtc->base.dev; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 171 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 172 | int ret; |
| 173 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 174 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 175 | |
| 176 | ret = RING_SPACE(evo, 2 + (update ? 2 : 0)); |
| 177 | if (ret) { |
| 178 | NV_ERROR(dev, "no space while setting dither\n"); |
| 179 | return ret; |
| 180 | } |
| 181 | |
| 182 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, DITHER_CTRL), 1); |
| 183 | if (on) |
| 184 | OUT_RING(evo, NV50_EVO_CRTC_DITHER_CTRL_ON); |
| 185 | else |
| 186 | OUT_RING(evo, NV50_EVO_CRTC_DITHER_CTRL_OFF); |
| 187 | |
| 188 | if (update) { |
| 189 | BEGIN_RING(evo, 0, NV50_EVO_UPDATE, 1); |
| 190 | OUT_RING(evo, 0); |
| 191 | FIRE_RING(evo); |
| 192 | } |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | struct nouveau_connector * |
| 198 | nouveau_crtc_connector_get(struct nouveau_crtc *nv_crtc) |
| 199 | { |
| 200 | struct drm_device *dev = nv_crtc->base.dev; |
| 201 | struct drm_connector *connector; |
| 202 | struct drm_crtc *crtc = to_drm_crtc(nv_crtc); |
| 203 | |
| 204 | /* The safest approach is to find an encoder with the right crtc, that |
| 205 | * is also linked to a connector. */ |
| 206 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 207 | if (connector->encoder) |
| 208 | if (connector->encoder->crtc == crtc) |
| 209 | return nouveau_connector(connector); |
| 210 | } |
| 211 | |
| 212 | return NULL; |
| 213 | } |
| 214 | |
| 215 | static int |
| 216 | nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, int scaling_mode, bool update) |
| 217 | { |
| 218 | struct nouveau_connector *nv_connector = |
| 219 | nouveau_crtc_connector_get(nv_crtc); |
Ben Skeggs | 549cd87 | 2011-10-06 11:51:45 +1000 | [diff] [blame] | 220 | struct drm_crtc *crtc = &nv_crtc->base; |
| 221 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 222 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 223 | struct drm_display_mode *native_mode = NULL; |
Ben Skeggs | 549cd87 | 2011-10-06 11:51:45 +1000 | [diff] [blame] | 224 | struct drm_display_mode *mode = &crtc->mode; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 225 | uint32_t outX, outY, horiz, vert; |
| 226 | int ret; |
| 227 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 228 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 229 | |
| 230 | switch (scaling_mode) { |
| 231 | case DRM_MODE_SCALE_NONE: |
| 232 | break; |
| 233 | default: |
| 234 | if (!nv_connector || !nv_connector->native_mode) { |
| 235 | NV_ERROR(dev, "No native mode, forcing panel scaling\n"); |
| 236 | scaling_mode = DRM_MODE_SCALE_NONE; |
| 237 | } else { |
| 238 | native_mode = nv_connector->native_mode; |
| 239 | } |
| 240 | break; |
| 241 | } |
| 242 | |
| 243 | switch (scaling_mode) { |
| 244 | case DRM_MODE_SCALE_ASPECT: |
| 245 | horiz = (native_mode->hdisplay << 19) / mode->hdisplay; |
| 246 | vert = (native_mode->vdisplay << 19) / mode->vdisplay; |
| 247 | |
| 248 | if (vert > horiz) { |
| 249 | outX = (mode->hdisplay * horiz) >> 19; |
| 250 | outY = (mode->vdisplay * horiz) >> 19; |
| 251 | } else { |
| 252 | outX = (mode->hdisplay * vert) >> 19; |
| 253 | outY = (mode->vdisplay * vert) >> 19; |
| 254 | } |
| 255 | break; |
| 256 | case DRM_MODE_SCALE_FULLSCREEN: |
| 257 | outX = native_mode->hdisplay; |
| 258 | outY = native_mode->vdisplay; |
| 259 | break; |
| 260 | case DRM_MODE_SCALE_CENTER: |
| 261 | case DRM_MODE_SCALE_NONE: |
| 262 | default: |
| 263 | outX = mode->hdisplay; |
| 264 | outY = mode->vdisplay; |
| 265 | break; |
| 266 | } |
| 267 | |
Ben Skeggs | 549cd87 | 2011-10-06 11:51:45 +1000 | [diff] [blame] | 268 | ret = RING_SPACE(evo, 5); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 269 | if (ret) |
| 270 | return ret; |
| 271 | |
| 272 | /* Got a better name for SCALER_ACTIVE? */ |
| 273 | /* One day i've got to really figure out why this is needed. */ |
| 274 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, SCALE_CTRL), 1); |
| 275 | if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) || |
| 276 | (mode->flags & DRM_MODE_FLAG_INTERLACE) || |
| 277 | mode->hdisplay != outX || mode->vdisplay != outY) { |
| 278 | OUT_RING(evo, NV50_EVO_CRTC_SCALE_CTRL_ACTIVE); |
| 279 | } else { |
| 280 | OUT_RING(evo, NV50_EVO_CRTC_SCALE_CTRL_INACTIVE); |
| 281 | } |
| 282 | |
| 283 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, SCALE_RES1), 2); |
| 284 | OUT_RING(evo, outY << 16 | outX); |
| 285 | OUT_RING(evo, outY << 16 | outX); |
| 286 | |
| 287 | if (update) { |
Ben Skeggs | 549cd87 | 2011-10-06 11:51:45 +1000 | [diff] [blame] | 288 | nv50_display_flip_stop(crtc); |
| 289 | nv50_crtc_wait_complete(crtc); |
| 290 | nv50_display_flip_next(crtc, crtc->fb, NULL); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | int |
| 297 | nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk) |
| 298 | { |
Ben Skeggs | 1ac7b52 | 2010-08-04 22:08:03 +1000 | [diff] [blame] | 299 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 300 | struct pll_lims pll; |
Ben Skeggs | 5b32165 | 2010-09-24 09:17:02 +1000 | [diff] [blame] | 301 | uint32_t reg1, reg2; |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 302 | int ret, N1, M1, N2, M2, P; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 303 | |
Ben Skeggs | 5b32165 | 2010-09-24 09:17:02 +1000 | [diff] [blame] | 304 | ret = get_pll_limits(dev, PLL_VPLL0 + head, &pll); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 305 | if (ret) |
| 306 | return ret; |
| 307 | |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 308 | if (pll.vco2.maxfreq) { |
| 309 | ret = nv50_calc_pll(dev, &pll, pclk, &N1, &M1, &N2, &M2, &P); |
| 310 | if (ret <= 0) |
| 311 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 312 | |
Ben Skeggs | 17b96cc | 2010-04-23 03:53:42 +1000 | [diff] [blame] | 313 | NV_DEBUG(dev, "pclk %d out %d NM1 %d %d NM2 %d %d P %d\n", |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 314 | pclk, ret, N1, M1, N2, M2, P); |
Ben Skeggs | 17b96cc | 2010-04-23 03:53:42 +1000 | [diff] [blame] | 315 | |
Ben Skeggs | 5b32165 | 2010-09-24 09:17:02 +1000 | [diff] [blame] | 316 | reg1 = nv_rd32(dev, pll.reg + 4) & 0xff00ff00; |
| 317 | reg2 = nv_rd32(dev, pll.reg + 8) & 0x8000ff00; |
| 318 | nv_wr32(dev, pll.reg + 0, 0x10000611); |
| 319 | nv_wr32(dev, pll.reg + 4, reg1 | (M1 << 16) | N1); |
| 320 | nv_wr32(dev, pll.reg + 8, reg2 | (P << 28) | (M2 << 16) | N2); |
Ben Skeggs | 1ac7b52 | 2010-08-04 22:08:03 +1000 | [diff] [blame] | 321 | } else |
| 322 | if (dev_priv->chipset < NV_C0) { |
Ben Skeggs | 52eba8d | 2011-04-28 02:34:21 +1000 | [diff] [blame] | 323 | ret = nva3_calc_pll(dev, &pll, pclk, &N1, &N2, &M1, &P); |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 324 | if (ret <= 0) |
| 325 | return 0; |
Ben Skeggs | 17b96cc | 2010-04-23 03:53:42 +1000 | [diff] [blame] | 326 | |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 327 | NV_DEBUG(dev, "pclk %d out %d N %d fN 0x%04x M %d P %d\n", |
| 328 | pclk, ret, N1, N2, M1, P); |
| 329 | |
Ben Skeggs | 5b32165 | 2010-09-24 09:17:02 +1000 | [diff] [blame] | 330 | reg1 = nv_rd32(dev, pll.reg + 4) & 0xffc00000; |
| 331 | nv_wr32(dev, pll.reg + 0, 0x50000610); |
| 332 | nv_wr32(dev, pll.reg + 4, reg1 | (P << 16) | (M1 << 8) | N1); |
| 333 | nv_wr32(dev, pll.reg + 8, N2); |
Ben Skeggs | 1ac7b52 | 2010-08-04 22:08:03 +1000 | [diff] [blame] | 334 | } else { |
Ben Skeggs | 52eba8d | 2011-04-28 02:34:21 +1000 | [diff] [blame] | 335 | ret = nva3_calc_pll(dev, &pll, pclk, &N1, &N2, &M1, &P); |
Ben Skeggs | 1ac7b52 | 2010-08-04 22:08:03 +1000 | [diff] [blame] | 336 | if (ret <= 0) |
| 337 | return 0; |
| 338 | |
| 339 | NV_DEBUG(dev, "pclk %d out %d N %d fN 0x%04x M %d P %d\n", |
| 340 | pclk, ret, N1, N2, M1, P); |
| 341 | |
Ben Skeggs | 5b32165 | 2010-09-24 09:17:02 +1000 | [diff] [blame] | 342 | nv_mask(dev, pll.reg + 0x0c, 0x00000000, 0x00000100); |
| 343 | nv_wr32(dev, pll.reg + 0x04, (P << 16) | (N1 << 8) | M1); |
| 344 | nv_wr32(dev, pll.reg + 0x10, N2 << 16); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | static void |
| 351 | nv50_crtc_destroy(struct drm_crtc *crtc) |
| 352 | { |
Marcin Slusarz | dd19e44 | 2010-01-30 15:41:00 +0100 | [diff] [blame] | 353 | struct drm_device *dev; |
| 354 | struct nouveau_crtc *nv_crtc; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 355 | |
| 356 | if (!crtc) |
| 357 | return; |
| 358 | |
Marcin Slusarz | dd19e44 | 2010-01-30 15:41:00 +0100 | [diff] [blame] | 359 | dev = crtc->dev; |
| 360 | nv_crtc = nouveau_crtc(crtc); |
| 361 | |
| 362 | NV_DEBUG_KMS(dev, "\n"); |
| 363 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 364 | drm_crtc_cleanup(&nv_crtc->base); |
| 365 | |
Ben Skeggs | 9d59e8a | 2010-08-27 13:04:41 +1000 | [diff] [blame] | 366 | nouveau_bo_unmap(nv_crtc->lut.nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 367 | nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo); |
Ben Skeggs | 9d59e8a | 2010-08-27 13:04:41 +1000 | [diff] [blame] | 368 | nouveau_bo_unmap(nv_crtc->cursor.nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 369 | nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo); |
| 370 | kfree(nv_crtc->mode); |
| 371 | kfree(nv_crtc); |
| 372 | } |
| 373 | |
| 374 | int |
| 375 | nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, |
| 376 | uint32_t buffer_handle, uint32_t width, uint32_t height) |
| 377 | { |
| 378 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 379 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 380 | struct nouveau_bo *cursor = NULL; |
| 381 | struct drm_gem_object *gem; |
| 382 | int ret = 0, i; |
| 383 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 384 | if (!buffer_handle) { |
| 385 | nv_crtc->cursor.hide(nv_crtc, true); |
| 386 | return 0; |
| 387 | } |
| 388 | |
Marcin Slusarz | b4fa9d0 | 2011-05-01 23:49:04 +0200 | [diff] [blame] | 389 | if (width != 64 || height != 64) |
| 390 | return -EINVAL; |
| 391 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 392 | gem = drm_gem_object_lookup(dev, file_priv, buffer_handle); |
| 393 | if (!gem) |
Chris Wilson | bf79cb9 | 2010-08-04 14:19:46 +0100 | [diff] [blame] | 394 | return -ENOENT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 395 | cursor = nouveau_gem_object(gem); |
| 396 | |
| 397 | ret = nouveau_bo_map(cursor); |
| 398 | if (ret) |
| 399 | goto out; |
| 400 | |
| 401 | /* The simple will do for now. */ |
| 402 | for (i = 0; i < 64 * 64; i++) |
| 403 | nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, nouveau_bo_rd32(cursor, i)); |
| 404 | |
| 405 | nouveau_bo_unmap(cursor); |
| 406 | |
Ben Skeggs | 180cc30 | 2011-06-07 11:24:14 +1000 | [diff] [blame] | 407 | nv_crtc->cursor.set_offset(nv_crtc, nv_crtc->cursor.nvbo->bo.offset); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 408 | nv_crtc->cursor.show(nv_crtc, true); |
| 409 | |
| 410 | out: |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 411 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 412 | return ret; |
| 413 | } |
| 414 | |
| 415 | int |
| 416 | nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 417 | { |
| 418 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 419 | |
| 420 | nv_crtc->cursor.set_pos(nv_crtc, x, y); |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | static void |
| 425 | nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 426 | uint32_t start, uint32_t size) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 427 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 428 | int end = (start + size > 256) ? 256 : start + size, i; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 429 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 430 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 431 | for (i = start; i < end; i++) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 432 | nv_crtc->lut.r[i] = r[i]; |
| 433 | nv_crtc->lut.g[i] = g[i]; |
| 434 | nv_crtc->lut.b[i] = b[i]; |
| 435 | } |
| 436 | |
| 437 | /* We need to know the depth before we upload, but it's possible to |
| 438 | * get called before a framebuffer is bound. If this is the case, |
| 439 | * mark the lut values as dirty by setting depth==0, and it'll be |
| 440 | * uploaded on the first mode_set_base() |
| 441 | */ |
| 442 | if (!nv_crtc->base.fb) { |
| 443 | nv_crtc->lut.depth = 0; |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | nv50_crtc_lut_load(crtc); |
| 448 | } |
| 449 | |
| 450 | static void |
| 451 | nv50_crtc_save(struct drm_crtc *crtc) |
| 452 | { |
| 453 | NV_ERROR(crtc->dev, "!!\n"); |
| 454 | } |
| 455 | |
| 456 | static void |
| 457 | nv50_crtc_restore(struct drm_crtc *crtc) |
| 458 | { |
| 459 | NV_ERROR(crtc->dev, "!!\n"); |
| 460 | } |
| 461 | |
| 462 | static const struct drm_crtc_funcs nv50_crtc_funcs = { |
| 463 | .save = nv50_crtc_save, |
| 464 | .restore = nv50_crtc_restore, |
| 465 | .cursor_set = nv50_crtc_cursor_set, |
| 466 | .cursor_move = nv50_crtc_cursor_move, |
| 467 | .gamma_set = nv50_crtc_gamma_set, |
| 468 | .set_config = drm_crtc_helper_set_config, |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 469 | .page_flip = nouveau_crtc_page_flip, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 470 | .destroy = nv50_crtc_destroy, |
| 471 | }; |
| 472 | |
| 473 | static void |
| 474 | nv50_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 475 | { |
| 476 | } |
| 477 | |
| 478 | static void |
| 479 | nv50_crtc_prepare(struct drm_crtc *crtc) |
| 480 | { |
| 481 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 482 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 483 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 484 | NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 485 | |
Ben Skeggs | 1d3fac0 | 2011-02-07 14:18:37 +1000 | [diff] [blame] | 486 | nv50_display_flip_stop(crtc); |
Francisco Jerez | 1c180fa | 2010-10-25 03:30:34 +0200 | [diff] [blame] | 487 | drm_vblank_pre_modeset(dev, nv_crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 488 | nv50_crtc_blank(nv_crtc, true); |
| 489 | } |
| 490 | |
| 491 | static void |
| 492 | nv50_crtc_commit(struct drm_crtc *crtc) |
| 493 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 494 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 495 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 496 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 497 | NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 498 | |
| 499 | nv50_crtc_blank(nv_crtc, false); |
Francisco Jerez | 1c180fa | 2010-10-25 03:30:34 +0200 | [diff] [blame] | 500 | drm_vblank_post_modeset(dev, nv_crtc->index); |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 501 | nv50_crtc_wait_complete(crtc); |
Ben Skeggs | 1d3fac0 | 2011-02-07 14:18:37 +1000 | [diff] [blame] | 502 | nv50_display_flip_next(crtc, crtc->fb, NULL); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static bool |
| 506 | nv50_crtc_mode_fixup(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 507 | struct drm_display_mode *adjusted_mode) |
| 508 | { |
| 509 | return true; |
| 510 | } |
| 511 | |
| 512 | static int |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 513 | nv50_crtc_do_mode_set_base(struct drm_crtc *crtc, |
| 514 | struct drm_framebuffer *passed_fb, |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 515 | int x, int y, bool atomic) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 516 | { |
| 517 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 518 | struct drm_device *dev = nv_crtc->base.dev; |
| 519 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 520 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Emil Velikov | ffbc559 | 2011-08-21 22:48:12 +0100 | [diff] [blame] | 521 | struct drm_framebuffer *drm_fb; |
| 522 | struct nouveau_framebuffer *fb; |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 523 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 524 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 525 | NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 526 | |
Emil Velikov | ffbc559 | 2011-08-21 22:48:12 +0100 | [diff] [blame] | 527 | /* no fb bound */ |
| 528 | if (!atomic && !crtc->fb) { |
| 529 | NV_DEBUG_KMS(dev, "No FB bound\n"); |
| 530 | return 0; |
| 531 | } |
| 532 | |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 533 | /* If atomic, we want to switch to the fb we were passed, so |
| 534 | * now we update pointers to do that. (We don't pin; just |
| 535 | * assume we're already pinned and update the base address.) |
| 536 | */ |
| 537 | if (atomic) { |
| 538 | drm_fb = passed_fb; |
| 539 | fb = nouveau_framebuffer(passed_fb); |
Emil Velikov | f9ec8f6 | 2011-03-19 23:31:53 +0000 | [diff] [blame] | 540 | } else { |
Emil Velikov | ffbc559 | 2011-08-21 22:48:12 +0100 | [diff] [blame] | 541 | drm_fb = crtc->fb; |
| 542 | fb = nouveau_framebuffer(crtc->fb); |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 543 | /* If not atomic, we can go ahead and pin, and unpin the |
| 544 | * old fb we were passed. |
| 545 | */ |
| 546 | ret = nouveau_bo_pin(fb->nvbo, TTM_PL_FLAG_VRAM); |
| 547 | if (ret) |
| 548 | return ret; |
| 549 | |
| 550 | if (passed_fb) { |
| 551 | struct nouveau_framebuffer *ofb = nouveau_framebuffer(passed_fb); |
| 552 | nouveau_bo_unpin(ofb->nvbo); |
| 553 | } |
| 554 | } |
| 555 | |
Ben Skeggs | 180cc30 | 2011-06-07 11:24:14 +1000 | [diff] [blame] | 556 | nv_crtc->fb.offset = fb->nvbo->bo.offset; |
Francisco Jerez | f13b326 | 2010-10-10 06:01:08 +0200 | [diff] [blame] | 557 | nv_crtc->fb.tile_flags = nouveau_bo_tile_layout(fb->nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 558 | nv_crtc->fb.cpp = drm_fb->bits_per_pixel / 8; |
| 559 | if (!nv_crtc->fb.blanked && dev_priv->chipset != 0x50) { |
| 560 | ret = RING_SPACE(evo, 2); |
| 561 | if (ret) |
| 562 | return ret; |
| 563 | |
| 564 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, FB_DMA), 1); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 565 | OUT_RING (evo, fb->r_dma); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | ret = RING_SPACE(evo, 12); |
| 569 | if (ret) |
| 570 | return ret; |
| 571 | |
| 572 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, FB_OFFSET), 5); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 573 | OUT_RING (evo, nv_crtc->fb.offset >> 8); |
| 574 | OUT_RING (evo, 0); |
| 575 | OUT_RING (evo, (drm_fb->height << 16) | drm_fb->width); |
| 576 | OUT_RING (evo, fb->r_pitch); |
| 577 | OUT_RING (evo, fb->r_format); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 578 | |
| 579 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CLUT_MODE), 1); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 580 | OUT_RING (evo, fb->base.depth == 8 ? |
| 581 | NV50_EVO_CRTC_CLUT_MODE_OFF : NV50_EVO_CRTC_CLUT_MODE_ON); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 582 | |
| 583 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, COLOR_CTRL), 1); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 584 | OUT_RING (evo, NV50_EVO_CRTC_COLOR_CTRL_COLOR); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 585 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, FB_POS), 1); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 586 | OUT_RING (evo, (y << 16) | x); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 587 | |
| 588 | if (nv_crtc->lut.depth != fb->base.depth) { |
| 589 | nv_crtc->lut.depth = fb->base.depth; |
| 590 | nv50_crtc_lut_load(crtc); |
| 591 | } |
| 592 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | static int |
| 597 | nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 598 | struct drm_display_mode *adjusted_mode, int x, int y, |
| 599 | struct drm_framebuffer *old_fb) |
| 600 | { |
| 601 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 602 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 603 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 604 | struct nouveau_connector *nv_connector = NULL; |
| 605 | uint32_t hsync_dur, vsync_dur, hsync_start_to_end, vsync_start_to_end; |
| 606 | uint32_t hunk1, vunk1, vunk2a, vunk2b; |
| 607 | int ret; |
| 608 | |
| 609 | /* Find the connector attached to this CRTC */ |
| 610 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
| 611 | |
| 612 | *nv_crtc->mode = *adjusted_mode; |
| 613 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 614 | NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 615 | |
| 616 | hsync_dur = adjusted_mode->hsync_end - adjusted_mode->hsync_start; |
| 617 | vsync_dur = adjusted_mode->vsync_end - adjusted_mode->vsync_start; |
| 618 | hsync_start_to_end = adjusted_mode->htotal - adjusted_mode->hsync_start; |
| 619 | vsync_start_to_end = adjusted_mode->vtotal - adjusted_mode->vsync_start; |
| 620 | /* I can't give this a proper name, anyone else can? */ |
| 621 | hunk1 = adjusted_mode->htotal - |
| 622 | adjusted_mode->hsync_start + adjusted_mode->hdisplay; |
| 623 | vunk1 = adjusted_mode->vtotal - |
| 624 | adjusted_mode->vsync_start + adjusted_mode->vdisplay; |
| 625 | /* Another strange value, this time only for interlaced adjusted_modes. */ |
| 626 | vunk2a = 2 * adjusted_mode->vtotal - |
| 627 | adjusted_mode->vsync_start + adjusted_mode->vdisplay; |
| 628 | vunk2b = adjusted_mode->vtotal - |
| 629 | adjusted_mode->vsync_start + adjusted_mode->vtotal; |
| 630 | |
| 631 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 632 | vsync_dur /= 2; |
| 633 | vsync_start_to_end /= 2; |
| 634 | vunk1 /= 2; |
| 635 | vunk2a /= 2; |
| 636 | vunk2b /= 2; |
| 637 | /* magic */ |
| 638 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN) { |
| 639 | vsync_start_to_end -= 1; |
| 640 | vunk1 -= 1; |
| 641 | vunk2a -= 1; |
| 642 | vunk2b -= 1; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | ret = RING_SPACE(evo, 17); |
| 647 | if (ret) |
| 648 | return ret; |
| 649 | |
| 650 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CLOCK), 2); |
| 651 | OUT_RING(evo, adjusted_mode->clock | 0x800000); |
| 652 | OUT_RING(evo, (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 0); |
| 653 | |
| 654 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, DISPLAY_START), 5); |
| 655 | OUT_RING(evo, 0); |
| 656 | OUT_RING(evo, (adjusted_mode->vtotal << 16) | adjusted_mode->htotal); |
| 657 | OUT_RING(evo, (vsync_dur - 1) << 16 | (hsync_dur - 1)); |
| 658 | OUT_RING(evo, (vsync_start_to_end - 1) << 16 | |
| 659 | (hsync_start_to_end - 1)); |
| 660 | OUT_RING(evo, (vunk1 - 1) << 16 | (hunk1 - 1)); |
| 661 | |
| 662 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 663 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, UNK0824), 1); |
| 664 | OUT_RING(evo, (vunk2b - 1) << 16 | (vunk2a - 1)); |
| 665 | } else { |
| 666 | OUT_RING(evo, 0); |
| 667 | OUT_RING(evo, 0); |
| 668 | } |
| 669 | |
| 670 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, UNK082C), 1); |
| 671 | OUT_RING(evo, 0); |
| 672 | |
| 673 | /* This is the actual resolution of the mode. */ |
| 674 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, REAL_RES), 1); |
| 675 | OUT_RING(evo, (mode->vdisplay << 16) | mode->hdisplay); |
| 676 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, SCALE_CENTER_OFFSET), 1); |
| 677 | OUT_RING(evo, NV50_EVO_CRTC_SCALE_CENTER_OFFSET_VAL(0, 0)); |
| 678 | |
| 679 | nv_crtc->set_dither(nv_crtc, nv_connector->use_dithering, false); |
| 680 | nv_crtc->set_scale(nv_crtc, nv_connector->scaling_mode, false); |
| 681 | |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 682 | return nv50_crtc_do_mode_set_base(crtc, old_fb, x, y, false); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | static int |
| 686 | nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
| 687 | struct drm_framebuffer *old_fb) |
| 688 | { |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 689 | int ret; |
| 690 | |
Ben Skeggs | 1d3fac0 | 2011-02-07 14:18:37 +1000 | [diff] [blame] | 691 | nv50_display_flip_stop(crtc); |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 692 | ret = nv50_crtc_do_mode_set_base(crtc, old_fb, x, y, false); |
| 693 | if (ret) |
| 694 | return ret; |
| 695 | |
Ben Skeggs | 1d3fac0 | 2011-02-07 14:18:37 +1000 | [diff] [blame] | 696 | ret = nv50_crtc_wait_complete(crtc); |
| 697 | if (ret) |
| 698 | return ret; |
| 699 | |
| 700 | return nv50_display_flip_next(crtc, crtc->fb, NULL); |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | static int |
| 704 | nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc, |
| 705 | struct drm_framebuffer *fb, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 706 | int x, int y, enum mode_set_atomic state) |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 707 | { |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 708 | int ret; |
| 709 | |
Ben Skeggs | 1d3fac0 | 2011-02-07 14:18:37 +1000 | [diff] [blame] | 710 | nv50_display_flip_stop(crtc); |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 711 | ret = nv50_crtc_do_mode_set_base(crtc, fb, x, y, true); |
| 712 | if (ret) |
| 713 | return ret; |
| 714 | |
| 715 | return nv50_crtc_wait_complete(crtc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | static const struct drm_crtc_helper_funcs nv50_crtc_helper_funcs = { |
| 719 | .dpms = nv50_crtc_dpms, |
| 720 | .prepare = nv50_crtc_prepare, |
| 721 | .commit = nv50_crtc_commit, |
| 722 | .mode_fixup = nv50_crtc_mode_fixup, |
| 723 | .mode_set = nv50_crtc_mode_set, |
| 724 | .mode_set_base = nv50_crtc_mode_set_base, |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 725 | .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 726 | .load_lut = nv50_crtc_lut_load, |
| 727 | }; |
| 728 | |
| 729 | int |
| 730 | nv50_crtc_create(struct drm_device *dev, int index) |
| 731 | { |
| 732 | struct nouveau_crtc *nv_crtc = NULL; |
| 733 | int ret, i; |
| 734 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 735 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 736 | |
| 737 | nv_crtc = kzalloc(sizeof(*nv_crtc), GFP_KERNEL); |
| 738 | if (!nv_crtc) |
| 739 | return -ENOMEM; |
| 740 | |
| 741 | nv_crtc->mode = kzalloc(sizeof(*nv_crtc->mode), GFP_KERNEL); |
| 742 | if (!nv_crtc->mode) { |
| 743 | kfree(nv_crtc); |
| 744 | return -ENOMEM; |
| 745 | } |
| 746 | |
| 747 | /* Default CLUT parameters, will be activated on the hw upon |
| 748 | * first mode set. |
| 749 | */ |
| 750 | for (i = 0; i < 256; i++) { |
| 751 | nv_crtc->lut.r[i] = i << 8; |
| 752 | nv_crtc->lut.g[i] = i << 8; |
| 753 | nv_crtc->lut.b[i] = i << 8; |
| 754 | } |
| 755 | nv_crtc->lut.depth = 0; |
| 756 | |
Ben Skeggs | 7375c95 | 2011-06-07 14:21:29 +1000 | [diff] [blame] | 757 | ret = nouveau_bo_new(dev, 4096, 0x100, TTM_PL_FLAG_VRAM, |
Ben Skeggs | d550c41 | 2011-02-16 08:41:56 +1000 | [diff] [blame] | 758 | 0, 0x0000, &nv_crtc->lut.nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 759 | if (!ret) { |
| 760 | ret = nouveau_bo_pin(nv_crtc->lut.nvbo, TTM_PL_FLAG_VRAM); |
| 761 | if (!ret) |
| 762 | ret = nouveau_bo_map(nv_crtc->lut.nvbo); |
| 763 | if (ret) |
| 764 | nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo); |
| 765 | } |
| 766 | |
| 767 | if (ret) { |
| 768 | kfree(nv_crtc->mode); |
| 769 | kfree(nv_crtc); |
| 770 | return ret; |
| 771 | } |
| 772 | |
| 773 | nv_crtc->index = index; |
| 774 | |
| 775 | /* set function pointers */ |
| 776 | nv_crtc->set_dither = nv50_crtc_set_dither; |
| 777 | nv_crtc->set_scale = nv50_crtc_set_scale; |
| 778 | |
| 779 | drm_crtc_init(dev, &nv_crtc->base, &nv50_crtc_funcs); |
| 780 | drm_crtc_helper_add(&nv_crtc->base, &nv50_crtc_helper_funcs); |
| 781 | drm_mode_crtc_set_gamma_size(&nv_crtc->base, 256); |
| 782 | |
Ben Skeggs | 7375c95 | 2011-06-07 14:21:29 +1000 | [diff] [blame] | 783 | ret = nouveau_bo_new(dev, 64*64*4, 0x100, TTM_PL_FLAG_VRAM, |
Ben Skeggs | d550c41 | 2011-02-16 08:41:56 +1000 | [diff] [blame] | 784 | 0, 0x0000, &nv_crtc->cursor.nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 785 | if (!ret) { |
| 786 | ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM); |
| 787 | if (!ret) |
| 788 | ret = nouveau_bo_map(nv_crtc->cursor.nvbo); |
| 789 | if (ret) |
| 790 | nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo); |
| 791 | } |
| 792 | |
| 793 | nv50_cursor_init(nv_crtc); |
| 794 | return 0; |
| 795 | } |