Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1 | /* |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 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 | |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 25 | #include <linux/dma-mapping.h> |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 26 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 27 | #include <drm/drmP.h> |
| 28 | #include <drm/drm_crtc_helper.h> |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 29 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 30 | #include "nouveau_drm.h" |
| 31 | #include "nouveau_dma.h" |
| 32 | #include "nouveau_gem.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 33 | #include "nouveau_connector.h" |
| 34 | #include "nouveau_encoder.h" |
| 35 | #include "nouveau_crtc.h" |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 36 | #include "nouveau_fence.h" |
Ben Skeggs | 3a89cd0 | 2011-07-07 10:47:10 +1000 | [diff] [blame] | 37 | #include "nv50_display.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 38 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 39 | #include <core/client.h> |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 40 | #include <core/gpuobj.h> |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 41 | #include <core/class.h> |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 42 | |
| 43 | #include <subdev/timer.h> |
| 44 | #include <subdev/bar.h> |
| 45 | #include <subdev/fb.h> |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 46 | #include <subdev/i2c.h> |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 47 | |
Ben Skeggs | 8a46438 | 2011-11-12 23:52:07 +1000 | [diff] [blame] | 48 | #define EVO_DMA_NR 9 |
| 49 | |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 50 | #define EVO_MASTER (0x00) |
Ben Skeggs | a63a97e | 2011-11-16 15:22:34 +1000 | [diff] [blame] | 51 | #define EVO_FLIP(c) (0x01 + (c)) |
Ben Skeggs | 8a46438 | 2011-11-12 23:52:07 +1000 | [diff] [blame] | 52 | #define EVO_OVLY(c) (0x05 + (c)) |
| 53 | #define EVO_OIMM(c) (0x09 + (c)) |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 54 | #define EVO_CURS(c) (0x0d + (c)) |
| 55 | |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 56 | /* offsets in shared sync bo of various structures */ |
| 57 | #define EVO_SYNC(c, o) ((c) * 0x0100 + (o)) |
| 58 | #define EVO_MAST_NTFY EVO_SYNC( 0, 0x00) |
| 59 | #define EVO_FLIP_SEM0(c) EVO_SYNC((c), 0x00) |
| 60 | #define EVO_FLIP_SEM1(c) EVO_SYNC((c), 0x10) |
| 61 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 62 | #define EVO_CORE_HANDLE (0xd1500000) |
| 63 | #define EVO_CHAN_HANDLE(t,i) (0xd15c0000 | (((t) & 0x00ff) << 8) | (i)) |
| 64 | #define EVO_CHAN_OCLASS(t,c) ((nv_hclass(c) & 0xff00) | ((t) & 0x00ff)) |
| 65 | #define EVO_PUSH_HANDLE(t,i) (0xd15b0000 | (i) | \ |
| 66 | (((NV50_DISP_##t##_CLASS) & 0x00ff) << 8)) |
| 67 | |
| 68 | /****************************************************************************** |
| 69 | * EVO channel |
| 70 | *****************************************************************************/ |
| 71 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 72 | struct nv50_chan { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 73 | struct nouveau_object *user; |
| 74 | u32 handle; |
| 75 | }; |
| 76 | |
| 77 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 78 | nv50_chan_create(struct nouveau_object *core, u32 bclass, u8 head, |
| 79 | void *data, u32 size, struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 80 | { |
| 81 | struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS); |
| 82 | const u32 oclass = EVO_CHAN_OCLASS(bclass, core); |
| 83 | const u32 handle = EVO_CHAN_HANDLE(bclass, head); |
| 84 | int ret; |
| 85 | |
| 86 | ret = nouveau_object_new(client, EVO_CORE_HANDLE, handle, |
| 87 | oclass, data, size, &chan->user); |
| 88 | if (ret) |
| 89 | return ret; |
| 90 | |
| 91 | chan->handle = handle; |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 96 | nv50_chan_destroy(struct nouveau_object *core, struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 97 | { |
| 98 | struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS); |
| 99 | if (chan->handle) |
| 100 | nouveau_object_del(client, EVO_CORE_HANDLE, chan->handle); |
| 101 | } |
| 102 | |
| 103 | /****************************************************************************** |
| 104 | * PIO EVO channel |
| 105 | *****************************************************************************/ |
| 106 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 107 | struct nv50_pioc { |
| 108 | struct nv50_chan base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 112 | nv50_pioc_destroy(struct nouveau_object *core, struct nv50_pioc *pioc) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 113 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 114 | nv50_chan_destroy(core, &pioc->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 118 | nv50_pioc_create(struct nouveau_object *core, u32 bclass, u8 head, |
| 119 | void *data, u32 size, struct nv50_pioc *pioc) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 120 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 121 | return nv50_chan_create(core, bclass, head, data, size, &pioc->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /****************************************************************************** |
| 125 | * DMA EVO channel |
| 126 | *****************************************************************************/ |
| 127 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 128 | struct nv50_dmac { |
| 129 | struct nv50_chan base; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 130 | dma_addr_t handle; |
| 131 | u32 *ptr; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 135 | nv50_dmac_destroy(struct nouveau_object *core, struct nv50_dmac *dmac) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 136 | { |
| 137 | if (dmac->ptr) { |
| 138 | struct pci_dev *pdev = nv_device(core)->pdev; |
| 139 | pci_free_consistent(pdev, PAGE_SIZE, dmac->ptr, dmac->handle); |
| 140 | } |
| 141 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 142 | nv50_chan_destroy(core, &dmac->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static int |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 146 | nv50_dmac_create_fbdma(struct nouveau_object *core, u32 parent) |
| 147 | { |
| 148 | struct nouveau_fb *pfb = nouveau_fb(core); |
| 149 | struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS); |
| 150 | struct nouveau_object *object; |
| 151 | int ret = nouveau_object_new(client, parent, NvEvoVRAM_LP, |
| 152 | NV_DMA_IN_MEMORY_CLASS, |
| 153 | &(struct nv_dma_class) { |
| 154 | .flags = NV_DMA_TARGET_VRAM | |
| 155 | NV_DMA_ACCESS_RDWR, |
| 156 | .start = 0, |
| 157 | .limit = pfb->ram.size - 1, |
| 158 | .conf0 = NV50_DMA_CONF0_ENABLE | |
| 159 | NV50_DMA_CONF0_PART_256, |
| 160 | }, sizeof(struct nv_dma_class), &object); |
| 161 | if (ret) |
| 162 | return ret; |
| 163 | |
| 164 | ret = nouveau_object_new(client, parent, NvEvoFB16, |
| 165 | NV_DMA_IN_MEMORY_CLASS, |
| 166 | &(struct nv_dma_class) { |
| 167 | .flags = NV_DMA_TARGET_VRAM | |
| 168 | NV_DMA_ACCESS_RDWR, |
| 169 | .start = 0, |
| 170 | .limit = pfb->ram.size - 1, |
| 171 | .conf0 = NV50_DMA_CONF0_ENABLE | 0x70 | |
| 172 | NV50_DMA_CONF0_PART_256, |
| 173 | }, sizeof(struct nv_dma_class), &object); |
| 174 | if (ret) |
| 175 | return ret; |
| 176 | |
| 177 | ret = nouveau_object_new(client, parent, NvEvoFB32, |
| 178 | NV_DMA_IN_MEMORY_CLASS, |
| 179 | &(struct nv_dma_class) { |
| 180 | .flags = NV_DMA_TARGET_VRAM | |
| 181 | NV_DMA_ACCESS_RDWR, |
| 182 | .start = 0, |
| 183 | .limit = pfb->ram.size - 1, |
| 184 | .conf0 = NV50_DMA_CONF0_ENABLE | 0x7a | |
| 185 | NV50_DMA_CONF0_PART_256, |
| 186 | }, sizeof(struct nv_dma_class), &object); |
| 187 | return ret; |
| 188 | } |
| 189 | |
| 190 | static int |
| 191 | nvc0_dmac_create_fbdma(struct nouveau_object *core, u32 parent) |
| 192 | { |
| 193 | struct nouveau_fb *pfb = nouveau_fb(core); |
| 194 | struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS); |
| 195 | struct nouveau_object *object; |
| 196 | int ret = nouveau_object_new(client, parent, NvEvoVRAM_LP, |
| 197 | NV_DMA_IN_MEMORY_CLASS, |
| 198 | &(struct nv_dma_class) { |
| 199 | .flags = NV_DMA_TARGET_VRAM | |
| 200 | NV_DMA_ACCESS_RDWR, |
| 201 | .start = 0, |
| 202 | .limit = pfb->ram.size - 1, |
| 203 | .conf0 = NVC0_DMA_CONF0_ENABLE, |
| 204 | }, sizeof(struct nv_dma_class), &object); |
| 205 | if (ret) |
| 206 | return ret; |
| 207 | |
| 208 | ret = nouveau_object_new(client, parent, NvEvoFB16, |
| 209 | NV_DMA_IN_MEMORY_CLASS, |
| 210 | &(struct nv_dma_class) { |
| 211 | .flags = NV_DMA_TARGET_VRAM | |
| 212 | NV_DMA_ACCESS_RDWR, |
| 213 | .start = 0, |
| 214 | .limit = pfb->ram.size - 1, |
| 215 | .conf0 = NVC0_DMA_CONF0_ENABLE | 0xfe, |
| 216 | }, sizeof(struct nv_dma_class), &object); |
| 217 | if (ret) |
| 218 | return ret; |
| 219 | |
| 220 | ret = nouveau_object_new(client, parent, NvEvoFB32, |
| 221 | NV_DMA_IN_MEMORY_CLASS, |
| 222 | &(struct nv_dma_class) { |
| 223 | .flags = NV_DMA_TARGET_VRAM | |
| 224 | NV_DMA_ACCESS_RDWR, |
| 225 | .start = 0, |
| 226 | .limit = pfb->ram.size - 1, |
| 227 | .conf0 = NVC0_DMA_CONF0_ENABLE | 0xfe, |
| 228 | }, sizeof(struct nv_dma_class), &object); |
| 229 | return ret; |
| 230 | } |
| 231 | |
| 232 | static int |
| 233 | nvd0_dmac_create_fbdma(struct nouveau_object *core, u32 parent) |
| 234 | { |
| 235 | struct nouveau_fb *pfb = nouveau_fb(core); |
| 236 | struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS); |
| 237 | struct nouveau_object *object; |
| 238 | int ret = nouveau_object_new(client, parent, NvEvoVRAM_LP, |
| 239 | NV_DMA_IN_MEMORY_CLASS, |
| 240 | &(struct nv_dma_class) { |
| 241 | .flags = NV_DMA_TARGET_VRAM | |
| 242 | NV_DMA_ACCESS_RDWR, |
| 243 | .start = 0, |
| 244 | .limit = pfb->ram.size - 1, |
| 245 | .conf0 = NVD0_DMA_CONF0_ENABLE | |
| 246 | NVD0_DMA_CONF0_PAGE_LP, |
| 247 | }, sizeof(struct nv_dma_class), &object); |
| 248 | if (ret) |
| 249 | return ret; |
| 250 | |
| 251 | ret = nouveau_object_new(client, parent, NvEvoFB32, |
| 252 | NV_DMA_IN_MEMORY_CLASS, |
| 253 | &(struct nv_dma_class) { |
| 254 | .flags = NV_DMA_TARGET_VRAM | |
| 255 | NV_DMA_ACCESS_RDWR, |
| 256 | .start = 0, |
| 257 | .limit = pfb->ram.size - 1, |
| 258 | .conf0 = NVD0_DMA_CONF0_ENABLE | 0xfe | |
| 259 | NVD0_DMA_CONF0_PAGE_LP, |
| 260 | }, sizeof(struct nv_dma_class), &object); |
| 261 | return ret; |
| 262 | } |
| 263 | |
| 264 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 265 | nv50_dmac_create(struct nouveau_object *core, u32 bclass, u8 head, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 266 | void *data, u32 size, u64 syncbuf, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 267 | struct nv50_dmac *dmac) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 268 | { |
| 269 | struct nouveau_fb *pfb = nouveau_fb(core); |
| 270 | struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS); |
| 271 | struct nouveau_object *object; |
| 272 | u32 pushbuf = *(u32 *)data; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 273 | int ret; |
| 274 | |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 275 | dmac->ptr = pci_alloc_consistent(nv_device(core)->pdev, PAGE_SIZE, |
| 276 | &dmac->handle); |
| 277 | if (!dmac->ptr) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 278 | return -ENOMEM; |
| 279 | |
| 280 | ret = nouveau_object_new(client, NVDRM_DEVICE, pushbuf, |
| 281 | NV_DMA_FROM_MEMORY_CLASS, |
| 282 | &(struct nv_dma_class) { |
| 283 | .flags = NV_DMA_TARGET_PCI_US | |
| 284 | NV_DMA_ACCESS_RD, |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 285 | .start = dmac->handle + 0x0000, |
| 286 | .limit = dmac->handle + 0x0fff, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 287 | }, sizeof(struct nv_dma_class), &object); |
| 288 | if (ret) |
| 289 | return ret; |
| 290 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 291 | ret = nv50_chan_create(core, bclass, head, data, size, &dmac->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 292 | if (ret) |
| 293 | return ret; |
| 294 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 295 | ret = nouveau_object_new(client, dmac->base.handle, NvEvoSync, |
| 296 | NV_DMA_IN_MEMORY_CLASS, |
| 297 | &(struct nv_dma_class) { |
| 298 | .flags = NV_DMA_TARGET_VRAM | |
| 299 | NV_DMA_ACCESS_RDWR, |
| 300 | .start = syncbuf + 0x0000, |
| 301 | .limit = syncbuf + 0x0fff, |
| 302 | }, sizeof(struct nv_dma_class), &object); |
| 303 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 304 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 305 | |
| 306 | ret = nouveau_object_new(client, dmac->base.handle, NvEvoVRAM, |
| 307 | NV_DMA_IN_MEMORY_CLASS, |
| 308 | &(struct nv_dma_class) { |
| 309 | .flags = NV_DMA_TARGET_VRAM | |
| 310 | NV_DMA_ACCESS_RDWR, |
| 311 | .start = 0, |
| 312 | .limit = pfb->ram.size - 1, |
| 313 | }, sizeof(struct nv_dma_class), &object); |
| 314 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 315 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 316 | |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 317 | if (nv_device(core)->card_type < NV_C0) |
| 318 | ret = nv50_dmac_create_fbdma(core, dmac->base.handle); |
| 319 | else |
| 320 | if (nv_device(core)->card_type < NV_D0) |
| 321 | ret = nvc0_dmac_create_fbdma(core, dmac->base.handle); |
| 322 | else |
| 323 | ret = nvd0_dmac_create_fbdma(core, dmac->base.handle); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 324 | return ret; |
| 325 | } |
| 326 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 327 | struct nv50_mast { |
| 328 | struct nv50_dmac base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 329 | }; |
| 330 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 331 | struct nv50_curs { |
| 332 | struct nv50_pioc base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 333 | }; |
| 334 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 335 | struct nv50_sync { |
| 336 | struct nv50_dmac base; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 337 | struct { |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 338 | u32 offset; |
| 339 | u16 value; |
| 340 | } sem; |
| 341 | }; |
| 342 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 343 | struct nv50_ovly { |
| 344 | struct nv50_dmac base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 345 | }; |
Ben Skeggs | f20ce96 | 2011-07-08 13:17:01 +1000 | [diff] [blame] | 346 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 347 | struct nv50_oimm { |
| 348 | struct nv50_pioc base; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 349 | }; |
| 350 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 351 | struct nv50_head { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 352 | struct nouveau_crtc base; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 353 | struct nv50_curs curs; |
| 354 | struct nv50_sync sync; |
| 355 | struct nv50_ovly ovly; |
| 356 | struct nv50_oimm oimm; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 357 | }; |
| 358 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 359 | #define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c)) |
| 360 | #define nv50_curs(c) (&nv50_head(c)->curs) |
| 361 | #define nv50_sync(c) (&nv50_head(c)->sync) |
| 362 | #define nv50_ovly(c) (&nv50_head(c)->ovly) |
| 363 | #define nv50_oimm(c) (&nv50_head(c)->oimm) |
| 364 | #define nv50_chan(c) (&(c)->base.base) |
| 365 | #define nv50_vers(c) nv_mclass(nv50_chan(c)->user) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 366 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 367 | struct nv50_disp { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 368 | struct nouveau_object *core; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 369 | struct nv50_mast mast; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 370 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 371 | u32 modeset; |
| 372 | |
| 373 | struct nouveau_bo *sync; |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 374 | }; |
| 375 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 376 | static struct nv50_disp * |
| 377 | nv50_disp(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 378 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 379 | return nouveau_display(dev)->priv; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 380 | } |
| 381 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 382 | #define nv50_mast(d) (&nv50_disp(d)->mast) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 383 | |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 384 | static struct drm_crtc * |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 385 | nv50_display_crtc_get(struct drm_encoder *encoder) |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 386 | { |
| 387 | return nouveau_encoder(encoder)->crtc; |
| 388 | } |
| 389 | |
| 390 | /****************************************************************************** |
| 391 | * EVO channel helpers |
| 392 | *****************************************************************************/ |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 393 | static u32 * |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 394 | evo_wait(void *evoc, int nr) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 395 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 396 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 397 | u32 put = nv_ro32(dmac->base.user, 0x0000) / 4; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 398 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 399 | if (put + nr >= (PAGE_SIZE / 4) - 8) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 400 | dmac->ptr[put] = 0x20000000; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 401 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 402 | nv_wo32(dmac->base.user, 0x0000, 0x00000000); |
| 403 | if (!nv_wait(dmac->base.user, 0x0004, ~0, 0x00000000)) { |
| 404 | NV_ERROR(dmac->base.user, "channel stalled\n"); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 405 | return NULL; |
| 406 | } |
| 407 | |
| 408 | put = 0; |
| 409 | } |
| 410 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 411 | return dmac->ptr + put; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | static void |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 415 | evo_kick(u32 *push, void *evoc) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 416 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 417 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 418 | nv_wo32(dmac->base.user, 0x0000, (push - dmac->ptr) << 2); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | #define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m)) |
| 422 | #define evo_data(p,d) *((p)++) = (d) |
| 423 | |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 424 | static bool |
| 425 | evo_sync_wait(void *data) |
| 426 | { |
Ben Skeggs | 5cc027f | 2013-02-18 17:50:51 -0500 | [diff] [blame^] | 427 | if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000) |
| 428 | return true; |
| 429 | usleep_range(1, 2); |
| 430 | return false; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static int |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 434 | evo_sync(struct drm_device *dev) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 435 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 436 | struct nouveau_device *device = nouveau_dev(dev); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 437 | struct nv50_disp *disp = nv50_disp(dev); |
| 438 | struct nv50_mast *mast = nv50_mast(dev); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 439 | u32 *push = evo_wait(mast, 8); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 440 | if (push) { |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 441 | nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 442 | evo_mthd(push, 0x0084, 1); |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 443 | evo_data(push, 0x80000000 | EVO_MAST_NTFY); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 444 | evo_mthd(push, 0x0080, 2); |
| 445 | evo_data(push, 0x00000000); |
| 446 | evo_data(push, 0x00000000); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 447 | evo_kick(push, mast); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 448 | if (nv_wait_cb(device, evo_sync_wait, disp->sync)) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | return -EBUSY; |
| 453 | } |
| 454 | |
| 455 | /****************************************************************************** |
Ben Skeggs | a63a97e | 2011-11-16 15:22:34 +1000 | [diff] [blame] | 456 | * Page flipping channel |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 457 | *****************************************************************************/ |
| 458 | struct nouveau_bo * |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 459 | nv50_display_crtc_sema(struct drm_device *dev, int crtc) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 460 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 461 | return nv50_disp(dev)->sync; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 465 | nv50_display_flip_stop(struct drm_crtc *crtc) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 466 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 467 | struct nv50_sync *sync = nv50_sync(crtc); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 468 | u32 *push; |
| 469 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 470 | push = evo_wait(sync, 8); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 471 | if (push) { |
| 472 | evo_mthd(push, 0x0084, 1); |
| 473 | evo_data(push, 0x00000000); |
| 474 | evo_mthd(push, 0x0094, 1); |
| 475 | evo_data(push, 0x00000000); |
| 476 | evo_mthd(push, 0x00c0, 1); |
| 477 | evo_data(push, 0x00000000); |
| 478 | evo_mthd(push, 0x0080, 1); |
| 479 | evo_data(push, 0x00000000); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 480 | evo_kick(push, sync); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
| 484 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 485 | nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 486 | struct nouveau_channel *chan, u32 swap_interval) |
| 487 | { |
| 488 | struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 489 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 490 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 491 | struct nv50_sync *sync = nv50_sync(crtc); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 492 | u32 *push; |
| 493 | int ret; |
| 494 | |
| 495 | swap_interval <<= 4; |
| 496 | if (swap_interval == 0) |
| 497 | swap_interval |= 0x100; |
| 498 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 499 | push = evo_wait(sync, 128); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 500 | if (unlikely(push == NULL)) |
| 501 | return -EBUSY; |
| 502 | |
| 503 | /* synchronise with the rendering channel, if necessary */ |
| 504 | if (likely(chan)) { |
| 505 | ret = RING_SPACE(chan, 10); |
| 506 | if (ret) |
| 507 | return ret; |
| 508 | |
Ben Skeggs | a34caf7 | 2013-02-14 09:28:37 +1000 | [diff] [blame] | 509 | if (nv_mclass(chan->object) < NV84_CHANNEL_IND_CLASS) { |
Ben Skeggs | ed5085a5 | 2012-11-16 13:16:51 +1000 | [diff] [blame] | 510 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2); |
| 511 | OUT_RING (chan, NvEvoSema0 + nv_crtc->index); |
| 512 | OUT_RING (chan, sync->sem.offset); |
| 513 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1); |
| 514 | OUT_RING (chan, 0xf00d0000 | sync->sem.value); |
| 515 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2); |
| 516 | OUT_RING (chan, sync->sem.offset ^ 0x10); |
| 517 | OUT_RING (chan, 0x74b1e000); |
| 518 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1); |
Ben Skeggs | a34caf7 | 2013-02-14 09:28:37 +1000 | [diff] [blame] | 519 | OUT_RING (chan, NvSema); |
| 520 | } else |
| 521 | if (nv_mclass(chan->object) < NVC0_CHANNEL_IND_CLASS) { |
| 522 | u64 offset = nv84_fence_crtc(chan, nv_crtc->index); |
| 523 | offset += sync->sem.offset; |
| 524 | |
| 525 | BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 526 | OUT_RING (chan, upper_32_bits(offset)); |
| 527 | OUT_RING (chan, lower_32_bits(offset)); |
| 528 | OUT_RING (chan, 0xf00d0000 | sync->sem.value); |
| 529 | OUT_RING (chan, 0x00000002); |
| 530 | BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 531 | OUT_RING (chan, upper_32_bits(offset)); |
| 532 | OUT_RING (chan, lower_32_bits(offset ^ 0x10)); |
| 533 | OUT_RING (chan, 0x74b1e000); |
| 534 | OUT_RING (chan, 0x00000001); |
Ben Skeggs | ed5085a5 | 2012-11-16 13:16:51 +1000 | [diff] [blame] | 535 | } else { |
Ben Skeggs | a34caf7 | 2013-02-14 09:28:37 +1000 | [diff] [blame] | 536 | u64 offset = nv84_fence_crtc(chan, nv_crtc->index); |
Ben Skeggs | ed5085a5 | 2012-11-16 13:16:51 +1000 | [diff] [blame] | 537 | offset += sync->sem.offset; |
Ben Skeggs | 35bcf5d | 2012-04-30 11:34:10 -0500 | [diff] [blame] | 538 | |
Ben Skeggs | ed5085a5 | 2012-11-16 13:16:51 +1000 | [diff] [blame] | 539 | BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 540 | OUT_RING (chan, upper_32_bits(offset)); |
| 541 | OUT_RING (chan, lower_32_bits(offset)); |
| 542 | OUT_RING (chan, 0xf00d0000 | sync->sem.value); |
Ben Skeggs | a34caf7 | 2013-02-14 09:28:37 +1000 | [diff] [blame] | 543 | OUT_RING (chan, 0x00001002); |
Ben Skeggs | ed5085a5 | 2012-11-16 13:16:51 +1000 | [diff] [blame] | 544 | BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 545 | OUT_RING (chan, upper_32_bits(offset)); |
| 546 | OUT_RING (chan, lower_32_bits(offset ^ 0x10)); |
| 547 | OUT_RING (chan, 0x74b1e000); |
Ben Skeggs | a34caf7 | 2013-02-14 09:28:37 +1000 | [diff] [blame] | 548 | OUT_RING (chan, 0x00001001); |
Ben Skeggs | ed5085a5 | 2012-11-16 13:16:51 +1000 | [diff] [blame] | 549 | } |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 550 | |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 551 | FIRE_RING (chan); |
| 552 | } else { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 553 | nouveau_bo_wr32(disp->sync, sync->sem.offset / 4, |
| 554 | 0xf00d0000 | sync->sem.value); |
| 555 | evo_sync(crtc->dev); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | /* queue the flip */ |
| 559 | evo_mthd(push, 0x0100, 1); |
| 560 | evo_data(push, 0xfffe0000); |
| 561 | evo_mthd(push, 0x0084, 1); |
| 562 | evo_data(push, swap_interval); |
| 563 | if (!(swap_interval & 0x00000100)) { |
| 564 | evo_mthd(push, 0x00e0, 1); |
| 565 | evo_data(push, 0x40000000); |
| 566 | } |
| 567 | evo_mthd(push, 0x0088, 4); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 568 | evo_data(push, sync->sem.offset); |
| 569 | evo_data(push, 0xf00d0000 | sync->sem.value); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 570 | evo_data(push, 0x74b1e000); |
| 571 | evo_data(push, NvEvoSync); |
| 572 | evo_mthd(push, 0x00a0, 2); |
| 573 | evo_data(push, 0x00000000); |
| 574 | evo_data(push, 0x00000000); |
| 575 | evo_mthd(push, 0x00c0, 1); |
| 576 | evo_data(push, nv_fb->r_dma); |
| 577 | evo_mthd(push, 0x0110, 2); |
| 578 | evo_data(push, 0x00000000); |
| 579 | evo_data(push, 0x00000000); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 580 | if (nv50_vers(sync) < NVD0_DISP_SYNC_CLASS) { |
Ben Skeggs | ed5085a5 | 2012-11-16 13:16:51 +1000 | [diff] [blame] | 581 | evo_mthd(push, 0x0800, 5); |
| 582 | evo_data(push, nv_fb->nvbo->bo.offset >> 8); |
| 583 | evo_data(push, 0); |
| 584 | evo_data(push, (fb->height << 16) | fb->width); |
| 585 | evo_data(push, nv_fb->r_pitch); |
| 586 | evo_data(push, nv_fb->r_format); |
| 587 | } else { |
| 588 | evo_mthd(push, 0x0400, 5); |
| 589 | evo_data(push, nv_fb->nvbo->bo.offset >> 8); |
| 590 | evo_data(push, 0); |
| 591 | evo_data(push, (fb->height << 16) | fb->width); |
| 592 | evo_data(push, nv_fb->r_pitch); |
| 593 | evo_data(push, nv_fb->r_format); |
| 594 | } |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 595 | evo_mthd(push, 0x0080, 1); |
| 596 | evo_data(push, 0x00000000); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 597 | evo_kick(push, sync); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 598 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 599 | sync->sem.offset ^= 0x10; |
| 600 | sync->sem.value++; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 601 | return 0; |
| 602 | } |
| 603 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 604 | /****************************************************************************** |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 605 | * CRTC |
| 606 | *****************************************************************************/ |
| 607 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 608 | nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 609 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 610 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 611 | struct nouveau_connector *nv_connector; |
| 612 | struct drm_connector *connector; |
| 613 | u32 *push, mode = 0x00; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 614 | |
Ben Skeggs | 488ff20 | 2011-10-17 10:38:10 +1000 | [diff] [blame] | 615 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 616 | connector = &nv_connector->base; |
| 617 | if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) { |
| 618 | if (nv_crtc->base.fb->depth > connector->display_info.bpc * 3) |
| 619 | mode = DITHERING_MODE_DYNAMIC2X2; |
| 620 | } else { |
| 621 | mode = nv_connector->dithering_mode; |
| 622 | } |
| 623 | |
| 624 | if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) { |
| 625 | if (connector->display_info.bpc >= 8) |
| 626 | mode |= DITHERING_DEPTH_8BPC; |
| 627 | } else { |
| 628 | mode |= nv_connector->dithering_depth; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 629 | } |
| 630 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 631 | push = evo_wait(mast, 4); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 632 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 633 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 634 | evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1); |
| 635 | evo_data(push, mode); |
| 636 | } else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 637 | if (nv50_vers(mast) < NVE0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 638 | evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1); |
| 639 | evo_data(push, mode); |
| 640 | } else { |
| 641 | evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1); |
| 642 | evo_data(push, mode); |
| 643 | } |
| 644 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 645 | if (update) { |
| 646 | evo_mthd(push, 0x0080, 1); |
| 647 | evo_data(push, 0x00000000); |
| 648 | } |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 649 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 656 | nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 657 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 658 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 659 | struct drm_display_mode *omode, *umode = &nv_crtc->base.mode; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 660 | struct drm_crtc *crtc = &nv_crtc->base; |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 661 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 662 | int mode = DRM_MODE_SCALE_NONE; |
| 663 | u32 oX, oY, *push; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 664 | |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 665 | /* start off at the resolution we programmed the crtc for, this |
| 666 | * effectively handles NONE/FULL scaling |
| 667 | */ |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 668 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 669 | if (nv_connector && nv_connector->native_mode) |
| 670 | mode = nv_connector->scaling_mode; |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 671 | |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 672 | if (mode != DRM_MODE_SCALE_NONE) |
| 673 | omode = nv_connector->native_mode; |
| 674 | else |
| 675 | omode = umode; |
| 676 | |
| 677 | oX = omode->hdisplay; |
| 678 | oY = omode->vdisplay; |
| 679 | if (omode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 680 | oY *= 2; |
| 681 | |
| 682 | /* add overscan compensation if necessary, will keep the aspect |
| 683 | * ratio the same as the backend mode unless overridden by the |
| 684 | * user setting both hborder and vborder properties. |
| 685 | */ |
| 686 | if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON || |
| 687 | (nv_connector->underscan == UNDERSCAN_AUTO && |
| 688 | nv_connector->edid && |
| 689 | drm_detect_hdmi_monitor(nv_connector->edid)))) { |
| 690 | u32 bX = nv_connector->underscan_hborder; |
| 691 | u32 bY = nv_connector->underscan_vborder; |
| 692 | u32 aspect = (oY << 19) / oX; |
| 693 | |
| 694 | if (bX) { |
| 695 | oX -= (bX * 2); |
| 696 | if (bY) oY -= (bY * 2); |
| 697 | else oY = ((oX * aspect) + (aspect / 2)) >> 19; |
| 698 | } else { |
| 699 | oX -= (oX >> 4) + 32; |
| 700 | if (bY) oY -= (bY * 2); |
| 701 | else oY = ((oX * aspect) + (aspect / 2)) >> 19; |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 702 | } |
| 703 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 704 | |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 705 | /* handle CENTER/ASPECT scaling, taking into account the areas |
| 706 | * removed already for overscan compensation |
| 707 | */ |
| 708 | switch (mode) { |
| 709 | case DRM_MODE_SCALE_CENTER: |
| 710 | oX = min((u32)umode->hdisplay, oX); |
| 711 | oY = min((u32)umode->vdisplay, oY); |
| 712 | /* fall-through */ |
| 713 | case DRM_MODE_SCALE_ASPECT: |
| 714 | if (oY < oX) { |
| 715 | u32 aspect = (umode->hdisplay << 19) / umode->vdisplay; |
| 716 | oX = ((oY * aspect) + (aspect / 2)) >> 19; |
| 717 | } else { |
| 718 | u32 aspect = (umode->vdisplay << 19) / umode->hdisplay; |
| 719 | oY = ((oX * aspect) + (aspect / 2)) >> 19; |
| 720 | } |
| 721 | break; |
| 722 | default: |
| 723 | break; |
| 724 | } |
| 725 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 726 | push = evo_wait(mast, 8); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 727 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 728 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 729 | /*XXX: SCALE_CTRL_ACTIVE??? */ |
| 730 | evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2); |
| 731 | evo_data(push, (oY << 16) | oX); |
| 732 | evo_data(push, (oY << 16) | oX); |
| 733 | evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1); |
| 734 | evo_data(push, 0x00000000); |
| 735 | evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1); |
| 736 | evo_data(push, umode->vdisplay << 16 | umode->hdisplay); |
| 737 | } else { |
| 738 | evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3); |
| 739 | evo_data(push, (oY << 16) | oX); |
| 740 | evo_data(push, (oY << 16) | oX); |
| 741 | evo_data(push, (oY << 16) | oX); |
| 742 | evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1); |
| 743 | evo_data(push, 0x00000000); |
| 744 | evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1); |
| 745 | evo_data(push, umode->vdisplay << 16 | umode->hdisplay); |
| 746 | } |
| 747 | |
| 748 | evo_kick(push, mast); |
| 749 | |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 750 | if (update) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 751 | nv50_display_flip_stop(crtc); |
| 752 | nv50_display_flip_next(crtc, crtc->fb, NULL, 1); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 753 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 760 | nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update) |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 761 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 762 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 763 | u32 *push, hue, vib; |
| 764 | int adj; |
| 765 | |
| 766 | adj = (nv_crtc->color_vibrance > 0) ? 50 : 0; |
| 767 | vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff; |
| 768 | hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff; |
| 769 | |
| 770 | push = evo_wait(mast, 16); |
| 771 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 772 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 773 | evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1); |
| 774 | evo_data(push, (hue << 20) | (vib << 8)); |
| 775 | } else { |
| 776 | evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1); |
| 777 | evo_data(push, (hue << 20) | (vib << 8)); |
| 778 | } |
| 779 | |
| 780 | if (update) { |
| 781 | evo_mthd(push, 0x0080, 1); |
| 782 | evo_data(push, 0x00000000); |
| 783 | } |
| 784 | evo_kick(push, mast); |
| 785 | } |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
| 790 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 791 | nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 792 | int x, int y, bool update) |
| 793 | { |
| 794 | struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 795 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 796 | u32 *push; |
| 797 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 798 | push = evo_wait(mast, 16); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 799 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 800 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 801 | evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1); |
| 802 | evo_data(push, nvfb->nvbo->bo.offset >> 8); |
| 803 | evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3); |
| 804 | evo_data(push, (fb->height << 16) | fb->width); |
| 805 | evo_data(push, nvfb->r_pitch); |
| 806 | evo_data(push, nvfb->r_format); |
| 807 | evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1); |
| 808 | evo_data(push, (y << 16) | x); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 809 | if (nv50_vers(mast) > NV50_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 810 | evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1); |
| 811 | evo_data(push, nvfb->r_dma); |
| 812 | } |
| 813 | } else { |
| 814 | evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1); |
| 815 | evo_data(push, nvfb->nvbo->bo.offset >> 8); |
| 816 | evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4); |
| 817 | evo_data(push, (fb->height << 16) | fb->width); |
| 818 | evo_data(push, nvfb->r_pitch); |
| 819 | evo_data(push, nvfb->r_format); |
| 820 | evo_data(push, nvfb->r_dma); |
| 821 | evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1); |
| 822 | evo_data(push, (y << 16) | x); |
| 823 | } |
| 824 | |
Ben Skeggs | a46232e | 2011-07-07 15:23:48 +1000 | [diff] [blame] | 825 | if (update) { |
| 826 | evo_mthd(push, 0x0080, 1); |
| 827 | evo_data(push, 0x00000000); |
| 828 | } |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 829 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 830 | } |
| 831 | |
Ben Skeggs | c0cc92a | 2011-07-06 11:40:45 +1000 | [diff] [blame] | 832 | nv_crtc->fb.tile_flags = nvfb->r_dma; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 837 | nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 838 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 839 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 840 | u32 *push = evo_wait(mast, 16); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 841 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 842 | if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 843 | evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2); |
| 844 | evo_data(push, 0x85000000); |
| 845 | evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8); |
| 846 | } else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 847 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 848 | evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2); |
| 849 | evo_data(push, 0x85000000); |
| 850 | evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8); |
| 851 | evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1); |
| 852 | evo_data(push, NvEvoVRAM); |
| 853 | } else { |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 854 | evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2); |
| 855 | evo_data(push, 0x85000000); |
| 856 | evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8); |
| 857 | evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1); |
Ben Skeggs | 37b034a | 2011-07-08 14:43:19 +1000 | [diff] [blame] | 858 | evo_data(push, NvEvoVRAM); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 859 | } |
| 860 | evo_kick(push, mast); |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 865 | nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc) |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 866 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 867 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 868 | u32 *push = evo_wait(mast, 16); |
| 869 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 870 | if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 871 | evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1); |
| 872 | evo_data(push, 0x05000000); |
| 873 | } else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 874 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 875 | evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1); |
| 876 | evo_data(push, 0x05000000); |
| 877 | evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1); |
| 878 | evo_data(push, 0x00000000); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 879 | } else { |
| 880 | evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1); |
| 881 | evo_data(push, 0x05000000); |
| 882 | evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1); |
| 883 | evo_data(push, 0x00000000); |
| 884 | } |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 885 | evo_kick(push, mast); |
| 886 | } |
| 887 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 888 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 889 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 890 | nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update) |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 891 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 892 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 893 | |
| 894 | if (show) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 895 | nv50_crtc_cursor_show(nv_crtc); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 896 | else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 897 | nv50_crtc_cursor_hide(nv_crtc); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 898 | |
| 899 | if (update) { |
| 900 | u32 *push = evo_wait(mast, 2); |
| 901 | if (push) { |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 902 | evo_mthd(push, 0x0080, 1); |
| 903 | evo_data(push, 0x00000000); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 904 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 905 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | |
| 909 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 910 | nv50_crtc_dpms(struct drm_crtc *crtc, int mode) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 911 | { |
| 912 | } |
| 913 | |
| 914 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 915 | nv50_crtc_prepare(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 916 | { |
| 917 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 918 | struct nv50_mast *mast = nv50_mast(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 919 | u32 *push; |
| 920 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 921 | nv50_display_flip_stop(crtc); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 922 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 923 | push = evo_wait(mast, 2); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 924 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 925 | if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 926 | evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1); |
| 927 | evo_data(push, 0x00000000); |
| 928 | evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1); |
| 929 | evo_data(push, 0x40000000); |
| 930 | } else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 931 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 932 | evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1); |
| 933 | evo_data(push, 0x00000000); |
| 934 | evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1); |
| 935 | evo_data(push, 0x40000000); |
| 936 | evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1); |
| 937 | evo_data(push, 0x00000000); |
| 938 | } else { |
| 939 | evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1); |
| 940 | evo_data(push, 0x00000000); |
| 941 | evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1); |
| 942 | evo_data(push, 0x03000000); |
| 943 | evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1); |
| 944 | evo_data(push, 0x00000000); |
| 945 | } |
| 946 | |
| 947 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 948 | } |
| 949 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 950 | nv50_crtc_cursor_show_hide(nv_crtc, false, false); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 954 | nv50_crtc_commit(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 955 | { |
| 956 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 957 | struct nv50_mast *mast = nv50_mast(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 958 | u32 *push; |
| 959 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 960 | push = evo_wait(mast, 32); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 961 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 962 | if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 963 | evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1); |
| 964 | evo_data(push, NvEvoVRAM_LP); |
| 965 | evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2); |
| 966 | evo_data(push, 0xc0000000); |
| 967 | evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8); |
| 968 | } else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 969 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 970 | evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1); |
| 971 | evo_data(push, nv_crtc->fb.tile_flags); |
| 972 | evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2); |
| 973 | evo_data(push, 0xc0000000); |
| 974 | evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8); |
| 975 | evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1); |
| 976 | evo_data(push, NvEvoVRAM); |
| 977 | } else { |
| 978 | evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1); |
| 979 | evo_data(push, nv_crtc->fb.tile_flags); |
| 980 | evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4); |
| 981 | evo_data(push, 0x83000000); |
| 982 | evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8); |
| 983 | evo_data(push, 0x00000000); |
| 984 | evo_data(push, 0x00000000); |
| 985 | evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1); |
| 986 | evo_data(push, NvEvoVRAM); |
| 987 | evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1); |
| 988 | evo_data(push, 0xffffff00); |
| 989 | } |
| 990 | |
| 991 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 992 | } |
| 993 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 994 | nv50_crtc_cursor_show_hide(nv_crtc, nv_crtc->cursor.visible, true); |
| 995 | nv50_display_flip_next(crtc, crtc->fb, NULL, 1); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | static bool |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 999 | nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1000 | struct drm_display_mode *adjusted_mode) |
| 1001 | { |
| 1002 | return true; |
| 1003 | } |
| 1004 | |
| 1005 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1006 | nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1007 | { |
| 1008 | struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->fb); |
| 1009 | int ret; |
| 1010 | |
| 1011 | ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM); |
| 1012 | if (ret) |
| 1013 | return ret; |
| 1014 | |
| 1015 | if (old_fb) { |
| 1016 | nvfb = nouveau_framebuffer(old_fb); |
| 1017 | nouveau_bo_unpin(nvfb->nvbo); |
| 1018 | } |
| 1019 | |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1024 | nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1025 | struct drm_display_mode *mode, int x, int y, |
| 1026 | struct drm_framebuffer *old_fb) |
| 1027 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1028 | struct nv50_mast *mast = nv50_mast(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1029 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 1030 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 2d1d898 | 2011-11-11 23:39:22 +1000 | [diff] [blame] | 1031 | u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1; |
| 1032 | u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1; |
| 1033 | u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks; |
| 1034 | u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks; |
| 1035 | u32 vblan2e = 0, vblan2s = 1; |
Ben Skeggs | 3488c57 | 2012-03-12 11:42:20 +1000 | [diff] [blame] | 1036 | u32 *push; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1037 | int ret; |
| 1038 | |
Ben Skeggs | 2d1d898 | 2011-11-11 23:39:22 +1000 | [diff] [blame] | 1039 | hactive = mode->htotal; |
| 1040 | hsynce = mode->hsync_end - mode->hsync_start - 1; |
| 1041 | hbackp = mode->htotal - mode->hsync_end; |
| 1042 | hblanke = hsynce + hbackp; |
| 1043 | hfrontp = mode->hsync_start - mode->hdisplay; |
| 1044 | hblanks = mode->htotal - hfrontp - 1; |
| 1045 | |
| 1046 | vactive = mode->vtotal * vscan / ilace; |
| 1047 | vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1; |
| 1048 | vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace; |
| 1049 | vblanke = vsynce + vbackp; |
| 1050 | vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace; |
| 1051 | vblanks = vactive - vfrontp - 1; |
| 1052 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 1053 | vblan2e = vactive + vsynce + vbackp; |
| 1054 | vblan2s = vblan2e + (mode->vdisplay * vscan / ilace); |
| 1055 | vactive = (vactive * 2) + 1; |
Ben Skeggs | 2d1d898 | 2011-11-11 23:39:22 +1000 | [diff] [blame] | 1056 | } |
| 1057 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1058 | ret = nv50_crtc_swap_fbs(crtc, old_fb); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1059 | if (ret) |
| 1060 | return ret; |
| 1061 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 1062 | push = evo_wait(mast, 64); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1063 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1064 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 1065 | evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2); |
| 1066 | evo_data(push, 0x00800000 | mode->clock); |
| 1067 | evo_data(push, (ilace == 2) ? 2 : 0); |
| 1068 | evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6); |
| 1069 | evo_data(push, 0x00000000); |
| 1070 | evo_data(push, (vactive << 16) | hactive); |
| 1071 | evo_data(push, ( vsynce << 16) | hsynce); |
| 1072 | evo_data(push, (vblanke << 16) | hblanke); |
| 1073 | evo_data(push, (vblanks << 16) | hblanks); |
| 1074 | evo_data(push, (vblan2e << 16) | vblan2s); |
| 1075 | evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1); |
| 1076 | evo_data(push, 0x00000000); |
| 1077 | evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2); |
| 1078 | evo_data(push, 0x00000311); |
| 1079 | evo_data(push, 0x00000100); |
| 1080 | } else { |
| 1081 | evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6); |
| 1082 | evo_data(push, 0x00000000); |
| 1083 | evo_data(push, (vactive << 16) | hactive); |
| 1084 | evo_data(push, ( vsynce << 16) | hsynce); |
| 1085 | evo_data(push, (vblanke << 16) | hblanke); |
| 1086 | evo_data(push, (vblanks << 16) | hblanks); |
| 1087 | evo_data(push, (vblan2e << 16) | vblan2s); |
| 1088 | evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1); |
| 1089 | evo_data(push, 0x00000000); /* ??? */ |
| 1090 | evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3); |
| 1091 | evo_data(push, mode->clock * 1000); |
| 1092 | evo_data(push, 0x00200000); /* ??? */ |
| 1093 | evo_data(push, mode->clock * 1000); |
| 1094 | evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2); |
| 1095 | evo_data(push, 0x00000311); |
| 1096 | evo_data(push, 0x00000100); |
| 1097 | } |
| 1098 | |
| 1099 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1103 | nv50_crtc_set_dither(nv_crtc, false); |
| 1104 | nv50_crtc_set_scale(nv_crtc, false); |
| 1105 | nv50_crtc_set_color_vibrance(nv_crtc, false); |
| 1106 | nv50_crtc_set_image(nv_crtc, crtc->fb, x, y, false); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1107 | return 0; |
| 1108 | } |
| 1109 | |
| 1110 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1111 | nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1112 | struct drm_framebuffer *old_fb) |
| 1113 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1114 | struct nouveau_drm *drm = nouveau_drm(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1115 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 1116 | int ret; |
| 1117 | |
Ben Skeggs | 84e2ad8 | 2011-08-26 09:40:39 +1000 | [diff] [blame] | 1118 | if (!crtc->fb) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1119 | NV_DEBUG(drm, "No FB bound\n"); |
Ben Skeggs | 84e2ad8 | 2011-08-26 09:40:39 +1000 | [diff] [blame] | 1120 | return 0; |
| 1121 | } |
| 1122 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1123 | ret = nv50_crtc_swap_fbs(crtc, old_fb); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1124 | if (ret) |
| 1125 | return ret; |
| 1126 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1127 | nv50_display_flip_stop(crtc); |
| 1128 | nv50_crtc_set_image(nv_crtc, crtc->fb, x, y, true); |
| 1129 | nv50_display_flip_next(crtc, crtc->fb, NULL, 1); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1130 | return 0; |
| 1131 | } |
| 1132 | |
| 1133 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1134 | nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1135 | struct drm_framebuffer *fb, int x, int y, |
| 1136 | enum mode_set_atomic state) |
| 1137 | { |
| 1138 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1139 | nv50_display_flip_stop(crtc); |
| 1140 | nv50_crtc_set_image(nv_crtc, fb, x, y, true); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1145 | nv50_crtc_lut_load(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1146 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1147 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1148 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 1149 | void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo); |
| 1150 | int i; |
| 1151 | |
| 1152 | for (i = 0; i < 256; i++) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 1153 | u16 r = nv_crtc->lut.r[i] >> 2; |
| 1154 | u16 g = nv_crtc->lut.g[i] >> 2; |
| 1155 | u16 b = nv_crtc->lut.b[i] >> 2; |
| 1156 | |
| 1157 | if (nv_mclass(disp->core) < NVD0_DISP_CLASS) { |
| 1158 | writew(r + 0x0000, lut + (i * 0x08) + 0); |
| 1159 | writew(g + 0x0000, lut + (i * 0x08) + 2); |
| 1160 | writew(b + 0x0000, lut + (i * 0x08) + 4); |
| 1161 | } else { |
| 1162 | writew(r + 0x6000, lut + (i * 0x20) + 0); |
| 1163 | writew(g + 0x6000, lut + (i * 0x20) + 2); |
| 1164 | writew(b + 0x6000, lut + (i * 0x20) + 4); |
| 1165 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1170 | nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1171 | uint32_t handle, uint32_t width, uint32_t height) |
| 1172 | { |
| 1173 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 1174 | struct drm_device *dev = crtc->dev; |
| 1175 | struct drm_gem_object *gem; |
| 1176 | struct nouveau_bo *nvbo; |
| 1177 | bool visible = (handle != 0); |
| 1178 | int i, ret = 0; |
| 1179 | |
| 1180 | if (visible) { |
| 1181 | if (width != 64 || height != 64) |
| 1182 | return -EINVAL; |
| 1183 | |
| 1184 | gem = drm_gem_object_lookup(dev, file_priv, handle); |
| 1185 | if (unlikely(!gem)) |
| 1186 | return -ENOENT; |
| 1187 | nvbo = nouveau_gem_object(gem); |
| 1188 | |
| 1189 | ret = nouveau_bo_map(nvbo); |
| 1190 | if (ret == 0) { |
| 1191 | for (i = 0; i < 64 * 64; i++) { |
| 1192 | u32 v = nouveau_bo_rd32(nvbo, i); |
| 1193 | nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v); |
| 1194 | } |
| 1195 | nouveau_bo_unmap(nvbo); |
| 1196 | } |
| 1197 | |
| 1198 | drm_gem_object_unreference_unlocked(gem); |
| 1199 | } |
| 1200 | |
| 1201 | if (visible != nv_crtc->cursor.visible) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1202 | nv50_crtc_cursor_show_hide(nv_crtc, visible, true); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1203 | nv_crtc->cursor.visible = visible; |
| 1204 | } |
| 1205 | |
| 1206 | return ret; |
| 1207 | } |
| 1208 | |
| 1209 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1210 | nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1211 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1212 | struct nv50_curs *curs = nv50_curs(crtc); |
| 1213 | struct nv50_chan *chan = nv50_chan(curs); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1214 | nv_wo32(chan->user, 0x0084, (y << 16) | (x & 0xffff)); |
| 1215 | nv_wo32(chan->user, 0x0080, 0x00000000); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1216 | return 0; |
| 1217 | } |
| 1218 | |
| 1219 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1220 | nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1221 | uint32_t start, uint32_t size) |
| 1222 | { |
| 1223 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 1224 | u32 end = max(start + size, (u32)256); |
| 1225 | u32 i; |
| 1226 | |
| 1227 | for (i = start; i < end; i++) { |
| 1228 | nv_crtc->lut.r[i] = r[i]; |
| 1229 | nv_crtc->lut.g[i] = g[i]; |
| 1230 | nv_crtc->lut.b[i] = b[i]; |
| 1231 | } |
| 1232 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1233 | nv50_crtc_lut_load(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1237 | nv50_crtc_destroy(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1238 | { |
| 1239 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1240 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
| 1241 | struct nv50_head *head = nv50_head(crtc); |
| 1242 | nv50_dmac_destroy(disp->core, &head->ovly.base); |
| 1243 | nv50_pioc_destroy(disp->core, &head->oimm.base); |
| 1244 | nv50_dmac_destroy(disp->core, &head->sync.base); |
| 1245 | nv50_pioc_destroy(disp->core, &head->curs.base); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1246 | nouveau_bo_unmap(nv_crtc->cursor.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1247 | if (nv_crtc->cursor.nvbo) |
| 1248 | nouveau_bo_unpin(nv_crtc->cursor.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1249 | nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo); |
| 1250 | nouveau_bo_unmap(nv_crtc->lut.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1251 | if (nv_crtc->lut.nvbo) |
| 1252 | nouveau_bo_unpin(nv_crtc->lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1253 | nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo); |
| 1254 | drm_crtc_cleanup(crtc); |
| 1255 | kfree(crtc); |
| 1256 | } |
| 1257 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1258 | static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = { |
| 1259 | .dpms = nv50_crtc_dpms, |
| 1260 | .prepare = nv50_crtc_prepare, |
| 1261 | .commit = nv50_crtc_commit, |
| 1262 | .mode_fixup = nv50_crtc_mode_fixup, |
| 1263 | .mode_set = nv50_crtc_mode_set, |
| 1264 | .mode_set_base = nv50_crtc_mode_set_base, |
| 1265 | .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic, |
| 1266 | .load_lut = nv50_crtc_lut_load, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1267 | }; |
| 1268 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1269 | static const struct drm_crtc_funcs nv50_crtc_func = { |
| 1270 | .cursor_set = nv50_crtc_cursor_set, |
| 1271 | .cursor_move = nv50_crtc_cursor_move, |
| 1272 | .gamma_set = nv50_crtc_gamma_set, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1273 | .set_config = drm_crtc_helper_set_config, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1274 | .destroy = nv50_crtc_destroy, |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1275 | .page_flip = nouveau_crtc_page_flip, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1276 | }; |
| 1277 | |
Ben Skeggs | c20ab3e | 2011-08-25 14:09:43 +1000 | [diff] [blame] | 1278 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1279 | nv50_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y) |
Ben Skeggs | c20ab3e | 2011-08-25 14:09:43 +1000 | [diff] [blame] | 1280 | { |
| 1281 | } |
| 1282 | |
| 1283 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1284 | nv50_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset) |
Ben Skeggs | c20ab3e | 2011-08-25 14:09:43 +1000 | [diff] [blame] | 1285 | { |
| 1286 | } |
| 1287 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1288 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1289 | nv50_crtc_create(struct drm_device *dev, struct nouveau_object *core, int index) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1290 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1291 | struct nv50_disp *disp = nv50_disp(dev); |
| 1292 | struct nv50_head *head; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1293 | struct drm_crtc *crtc; |
| 1294 | int ret, i; |
| 1295 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1296 | head = kzalloc(sizeof(*head), GFP_KERNEL); |
| 1297 | if (!head) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1298 | return -ENOMEM; |
| 1299 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1300 | head->base.index = index; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1301 | head->base.set_dither = nv50_crtc_set_dither; |
| 1302 | head->base.set_scale = nv50_crtc_set_scale; |
| 1303 | head->base.set_color_vibrance = nv50_crtc_set_color_vibrance; |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 1304 | head->base.color_vibrance = 50; |
| 1305 | head->base.vibrant_hue = 0; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1306 | head->base.cursor.set_offset = nv50_cursor_set_offset; |
| 1307 | head->base.cursor.set_pos = nv50_cursor_set_pos; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1308 | for (i = 0; i < 256; i++) { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1309 | head->base.lut.r[i] = i << 8; |
| 1310 | head->base.lut.g[i] = i << 8; |
| 1311 | head->base.lut.b[i] = i << 8; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1312 | } |
| 1313 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1314 | crtc = &head->base.base; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1315 | drm_crtc_init(dev, crtc, &nv50_crtc_func); |
| 1316 | drm_crtc_helper_add(crtc, &nv50_crtc_hfunc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1317 | drm_mode_crtc_set_gamma_size(crtc, 256); |
| 1318 | |
Ben Skeggs | 8ea0d4a | 2011-07-07 14:49:24 +1000 | [diff] [blame] | 1319 | ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM, |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1320 | 0, 0x0000, NULL, &head->base.lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1321 | if (!ret) { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1322 | ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1323 | if (!ret) { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1324 | ret = nouveau_bo_map(head->base.lut.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1325 | if (ret) |
| 1326 | nouveau_bo_unpin(head->base.lut.nvbo); |
| 1327 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1328 | if (ret) |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1329 | nouveau_bo_ref(NULL, &head->base.lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | if (ret) |
| 1333 | goto out; |
| 1334 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1335 | nv50_crtc_lut_load(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1336 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1337 | /* allocate cursor resources */ |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1338 | ret = nv50_pioc_create(disp->core, NV50_DISP_CURS_CLASS, index, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1339 | &(struct nv50_display_curs_class) { |
| 1340 | .head = index, |
| 1341 | }, sizeof(struct nv50_display_curs_class), |
| 1342 | &head->curs.base); |
| 1343 | if (ret) |
| 1344 | goto out; |
| 1345 | |
| 1346 | ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM, |
| 1347 | 0, 0x0000, NULL, &head->base.cursor.nvbo); |
| 1348 | if (!ret) { |
| 1349 | ret = nouveau_bo_pin(head->base.cursor.nvbo, TTM_PL_FLAG_VRAM); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1350 | if (!ret) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1351 | ret = nouveau_bo_map(head->base.cursor.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1352 | if (ret) |
| 1353 | nouveau_bo_unpin(head->base.lut.nvbo); |
| 1354 | } |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1355 | if (ret) |
| 1356 | nouveau_bo_ref(NULL, &head->base.cursor.nvbo); |
| 1357 | } |
| 1358 | |
| 1359 | if (ret) |
| 1360 | goto out; |
| 1361 | |
| 1362 | /* allocate page flip / sync resources */ |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1363 | ret = nv50_dmac_create(disp->core, NV50_DISP_SYNC_CLASS, index, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1364 | &(struct nv50_display_sync_class) { |
| 1365 | .pushbuf = EVO_PUSH_HANDLE(SYNC, index), |
| 1366 | .head = index, |
| 1367 | }, sizeof(struct nv50_display_sync_class), |
| 1368 | disp->sync->bo.offset, &head->sync.base); |
| 1369 | if (ret) |
| 1370 | goto out; |
| 1371 | |
| 1372 | head->sync.sem.offset = EVO_SYNC(1 + index, 0x00); |
| 1373 | |
| 1374 | /* allocate overlay resources */ |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1375 | ret = nv50_pioc_create(disp->core, NV50_DISP_OIMM_CLASS, index, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1376 | &(struct nv50_display_oimm_class) { |
| 1377 | .head = index, |
| 1378 | }, sizeof(struct nv50_display_oimm_class), |
| 1379 | &head->oimm.base); |
| 1380 | if (ret) |
| 1381 | goto out; |
| 1382 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1383 | ret = nv50_dmac_create(disp->core, NV50_DISP_OVLY_CLASS, index, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1384 | &(struct nv50_display_ovly_class) { |
| 1385 | .pushbuf = EVO_PUSH_HANDLE(OVLY, index), |
| 1386 | .head = index, |
| 1387 | }, sizeof(struct nv50_display_ovly_class), |
| 1388 | disp->sync->bo.offset, &head->ovly.base); |
| 1389 | if (ret) |
| 1390 | goto out; |
| 1391 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1392 | out: |
| 1393 | if (ret) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1394 | nv50_crtc_destroy(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1395 | return ret; |
| 1396 | } |
| 1397 | |
| 1398 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1399 | * DAC |
| 1400 | *****************************************************************************/ |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1401 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1402 | nv50_dac_dpms(struct drm_encoder *encoder, int mode) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1403 | { |
| 1404 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1405 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1406 | int or = nv_encoder->or; |
| 1407 | u32 dpms_ctrl; |
| 1408 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1409 | dpms_ctrl = 0x00000000; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1410 | if (mode == DRM_MODE_DPMS_STANDBY || mode == DRM_MODE_DPMS_OFF) |
| 1411 | dpms_ctrl |= 0x00000001; |
| 1412 | if (mode == DRM_MODE_DPMS_SUSPEND || mode == DRM_MODE_DPMS_OFF) |
| 1413 | dpms_ctrl |= 0x00000004; |
| 1414 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1415 | nv_call(disp->core, NV50_DISP_DAC_PWR + or, dpms_ctrl); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | static bool |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1419 | nv50_dac_mode_fixup(struct drm_encoder *encoder, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 1420 | const struct drm_display_mode *mode, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1421 | struct drm_display_mode *adjusted_mode) |
| 1422 | { |
| 1423 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1424 | struct nouveau_connector *nv_connector; |
| 1425 | |
| 1426 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1427 | if (nv_connector && nv_connector->native_mode) { |
| 1428 | if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) { |
| 1429 | int id = adjusted_mode->base.id; |
| 1430 | *adjusted_mode = *nv_connector->native_mode; |
| 1431 | adjusted_mode->base.id = id; |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | return true; |
| 1436 | } |
| 1437 | |
| 1438 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1439 | nv50_dac_commit(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1440 | { |
| 1441 | } |
| 1442 | |
| 1443 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1444 | nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1445 | struct drm_display_mode *adjusted_mode) |
| 1446 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1447 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1448 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1449 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1450 | u32 *push; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1451 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1452 | nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1453 | |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1454 | push = evo_wait(mast, 8); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1455 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1456 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1457 | u32 syncs = 0x00000000; |
| 1458 | |
| 1459 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 1460 | syncs |= 0x00000001; |
| 1461 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 1462 | syncs |= 0x00000002; |
| 1463 | |
| 1464 | evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2); |
| 1465 | evo_data(push, 1 << nv_crtc->index); |
| 1466 | evo_data(push, syncs); |
| 1467 | } else { |
| 1468 | u32 magic = 0x31ec6000 | (nv_crtc->index << 25); |
| 1469 | u32 syncs = 0x00000001; |
| 1470 | |
| 1471 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 1472 | syncs |= 0x00000008; |
| 1473 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 1474 | syncs |= 0x00000010; |
| 1475 | |
| 1476 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 1477 | magic |= 0x00000001; |
| 1478 | |
| 1479 | evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2); |
| 1480 | evo_data(push, syncs); |
| 1481 | evo_data(push, magic); |
| 1482 | evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1); |
| 1483 | evo_data(push, 1 << nv_crtc->index); |
| 1484 | } |
| 1485 | |
| 1486 | evo_kick(push, mast); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | nv_encoder->crtc = encoder->crtc; |
| 1490 | } |
| 1491 | |
| 1492 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1493 | nv50_dac_disconnect(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1494 | { |
| 1495 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1496 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1497 | const int or = nv_encoder->or; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1498 | u32 *push; |
| 1499 | |
| 1500 | if (nv_encoder->crtc) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1501 | nv50_crtc_prepare(nv_encoder->crtc); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1502 | |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1503 | push = evo_wait(mast, 4); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1504 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1505 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1506 | evo_mthd(push, 0x0400 + (or * 0x080), 1); |
| 1507 | evo_data(push, 0x00000000); |
| 1508 | } else { |
| 1509 | evo_mthd(push, 0x0180 + (or * 0x020), 1); |
| 1510 | evo_data(push, 0x00000000); |
| 1511 | } |
| 1512 | |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1513 | evo_mthd(push, 0x0080, 1); |
| 1514 | evo_data(push, 0x00000000); |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1515 | evo_kick(push, mast); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1516 | } |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1517 | } |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1518 | |
| 1519 | nv_encoder->crtc = NULL; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1520 | } |
| 1521 | |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 1522 | static enum drm_connector_status |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1523 | nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 1524 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1525 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1526 | int ret, or = nouveau_encoder(encoder)->or; |
Ben Skeggs | 7ebb38b | 2012-11-09 09:38:06 +1000 | [diff] [blame] | 1527 | u32 load = 0; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 1528 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1529 | ret = nv_exec(disp->core, NV50_DISP_DAC_LOAD + or, &load, sizeof(load)); |
| 1530 | if (ret || load != 7) |
| 1531 | return connector_status_disconnected; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 1532 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1533 | return connector_status_connected; |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 1534 | } |
| 1535 | |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1536 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1537 | nv50_dac_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1538 | { |
| 1539 | drm_encoder_cleanup(encoder); |
| 1540 | kfree(encoder); |
| 1541 | } |
| 1542 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1543 | static const struct drm_encoder_helper_funcs nv50_dac_hfunc = { |
| 1544 | .dpms = nv50_dac_dpms, |
| 1545 | .mode_fixup = nv50_dac_mode_fixup, |
| 1546 | .prepare = nv50_dac_disconnect, |
| 1547 | .commit = nv50_dac_commit, |
| 1548 | .mode_set = nv50_dac_mode_set, |
| 1549 | .disable = nv50_dac_disconnect, |
| 1550 | .get_crtc = nv50_display_crtc_get, |
| 1551 | .detect = nv50_dac_detect |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1552 | }; |
| 1553 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1554 | static const struct drm_encoder_funcs nv50_dac_func = { |
| 1555 | .destroy = nv50_dac_destroy, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1556 | }; |
| 1557 | |
| 1558 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1559 | nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1560 | { |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1561 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
| 1562 | struct nouveau_i2c *i2c = nouveau_i2c(drm->device); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1563 | struct nouveau_encoder *nv_encoder; |
| 1564 | struct drm_encoder *encoder; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1565 | int type = DRM_MODE_ENCODER_DAC; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1566 | |
| 1567 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 1568 | if (!nv_encoder) |
| 1569 | return -ENOMEM; |
| 1570 | nv_encoder->dcb = dcbe; |
| 1571 | nv_encoder->or = ffs(dcbe->or) - 1; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1572 | nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1573 | |
| 1574 | encoder = to_drm_encoder(nv_encoder); |
| 1575 | encoder->possible_crtcs = dcbe->heads; |
| 1576 | encoder->possible_clones = 0; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1577 | drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1578 | drm_encoder_helper_add(encoder, &nv50_dac_hfunc); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1579 | |
| 1580 | drm_mode_connector_attach_encoder(connector, encoder); |
| 1581 | return 0; |
| 1582 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1583 | |
| 1584 | /****************************************************************************** |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1585 | * Audio |
| 1586 | *****************************************************************************/ |
| 1587 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1588 | nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1589 | { |
| 1590 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1591 | struct nouveau_connector *nv_connector; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1592 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1593 | |
| 1594 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1595 | if (!drm_detect_monitor_audio(nv_connector->edid)) |
| 1596 | return; |
| 1597 | |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1598 | drm_edid_to_eld(&nv_connector->base, nv_connector->edid); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1599 | |
Ben Skeggs | 0a9e2b95 | 2012-11-08 14:03:56 +1000 | [diff] [blame] | 1600 | nv_exec(disp->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or, |
| 1601 | nv_connector->base.eld, |
| 1602 | nv_connector->base.eld[2] * 4); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1606 | nv50_audio_disconnect(struct drm_encoder *encoder) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1607 | { |
| 1608 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1609 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1610 | |
Ben Skeggs | 0a9e2b95 | 2012-11-08 14:03:56 +1000 | [diff] [blame] | 1611 | nv_exec(disp->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or, NULL, 0); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | /****************************************************************************** |
| 1615 | * HDMI |
| 1616 | *****************************************************************************/ |
| 1617 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1618 | nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1619 | { |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 1620 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1621 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
| 1622 | struct nouveau_connector *nv_connector; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1623 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 1c30cd0 | 2012-11-08 14:22:28 +1000 | [diff] [blame] | 1624 | const u32 moff = (nv_crtc->index << 3) | nv_encoder->or; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 1625 | u32 rekey = 56; /* binary driver, and tegra constant */ |
| 1626 | u32 max_ac_packet; |
| 1627 | |
| 1628 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1629 | if (!drm_detect_hdmi_monitor(nv_connector->edid)) |
| 1630 | return; |
| 1631 | |
| 1632 | max_ac_packet = mode->htotal - mode->hdisplay; |
| 1633 | max_ac_packet -= rekey; |
| 1634 | max_ac_packet -= 18; /* constant from tegra */ |
| 1635 | max_ac_packet /= 32; |
| 1636 | |
Ben Skeggs | 1c30cd0 | 2012-11-08 14:22:28 +1000 | [diff] [blame] | 1637 | nv_call(disp->core, NV84_DISP_SOR_HDMI_PWR + moff, |
| 1638 | NV84_DISP_SOR_HDMI_PWR_STATE_ON | |
| 1639 | (max_ac_packet << 16) | rekey); |
Ben Skeggs | 091e40c | 2011-11-11 20:46:00 +1000 | [diff] [blame] | 1640 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1641 | nv50_audio_mode_set(encoder, mode); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1645 | nv50_hdmi_disconnect(struct drm_encoder *encoder) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1646 | { |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 1647 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1648 | struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1649 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 1c30cd0 | 2012-11-08 14:22:28 +1000 | [diff] [blame] | 1650 | const u32 moff = (nv_crtc->index << 3) | nv_encoder->or; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 1651 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1652 | nv50_audio_disconnect(encoder); |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 1653 | |
Ben Skeggs | 1c30cd0 | 2012-11-08 14:22:28 +1000 | [diff] [blame] | 1654 | nv_call(disp->core, NV84_DISP_SOR_HDMI_PWR + moff, 0x00000000); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1658 | * SOR |
| 1659 | *****************************************************************************/ |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1660 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1661 | nv50_sor_dpms(struct drm_encoder *encoder, int mode) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1662 | { |
| 1663 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1664 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1665 | struct nv50_disp *disp = nv50_disp(dev); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1666 | struct drm_encoder *partner; |
| 1667 | int or = nv_encoder->or; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1668 | |
| 1669 | nv_encoder->last_dpms = mode; |
| 1670 | |
| 1671 | list_for_each_entry(partner, &dev->mode_config.encoder_list, head) { |
| 1672 | struct nouveau_encoder *nv_partner = nouveau_encoder(partner); |
| 1673 | |
| 1674 | if (partner->encoder_type != DRM_MODE_ENCODER_TMDS) |
| 1675 | continue; |
| 1676 | |
| 1677 | if (nv_partner != nv_encoder && |
Ben Skeggs | 26cfa81 | 2011-11-17 09:10:02 +1000 | [diff] [blame] | 1678 | nv_partner->dcb->or == nv_encoder->dcb->or) { |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1679 | if (nv_partner->last_dpms == DRM_MODE_DPMS_ON) |
| 1680 | return; |
| 1681 | break; |
| 1682 | } |
| 1683 | } |
| 1684 | |
Ben Skeggs | 74b6685 | 2012-11-08 12:01:39 +1000 | [diff] [blame] | 1685 | nv_call(disp->core, NV50_DISP_SOR_PWR + or, (mode == DRM_MODE_DPMS_ON)); |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1686 | |
Ben Skeggs | 6c8e463 | 2012-11-15 18:56:02 +1000 | [diff] [blame] | 1687 | if (nv_encoder->dcb->type == DCB_OUTPUT_DP) |
| 1688 | nouveau_dp_dpms(encoder, mode, nv_encoder->dp.datarate, disp->core); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | static bool |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1692 | nv50_sor_mode_fixup(struct drm_encoder *encoder, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 1693 | const struct drm_display_mode *mode, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1694 | struct drm_display_mode *adjusted_mode) |
| 1695 | { |
| 1696 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1697 | struct nouveau_connector *nv_connector; |
| 1698 | |
| 1699 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1700 | if (nv_connector && nv_connector->native_mode) { |
| 1701 | if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) { |
| 1702 | int id = adjusted_mode->base.id; |
| 1703 | *adjusted_mode = *nv_connector->native_mode; |
| 1704 | adjusted_mode->base.id = id; |
| 1705 | } |
| 1706 | } |
| 1707 | |
| 1708 | return true; |
| 1709 | } |
| 1710 | |
| 1711 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1712 | nv50_sor_disconnect(struct drm_encoder *encoder) |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1713 | { |
| 1714 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1715 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1716 | const int or = nv_encoder->or; |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1717 | u32 *push; |
| 1718 | |
| 1719 | if (nv_encoder->crtc) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1720 | nv50_crtc_prepare(nv_encoder->crtc); |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1721 | |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1722 | push = evo_wait(mast, 4); |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1723 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1724 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1725 | evo_mthd(push, 0x0600 + (or * 0x40), 1); |
| 1726 | evo_data(push, 0x00000000); |
| 1727 | } else { |
| 1728 | evo_mthd(push, 0x0200 + (or * 0x20), 1); |
| 1729 | evo_data(push, 0x00000000); |
| 1730 | } |
| 1731 | |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1732 | evo_mthd(push, 0x0080, 1); |
| 1733 | evo_data(push, 0x00000000); |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1734 | evo_kick(push, mast); |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1735 | } |
| 1736 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1737 | nv50_hdmi_disconnect(encoder); |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1738 | } |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1739 | |
| 1740 | nv_encoder->last_dpms = DRM_MODE_DPMS_OFF; |
| 1741 | nv_encoder->crtc = NULL; |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1745 | nv50_sor_prepare(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1746 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1747 | nv50_sor_disconnect(encoder); |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1748 | if (nouveau_encoder(encoder)->dcb->type == DCB_OUTPUT_DP) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1749 | evo_sync(encoder->dev); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1753 | nv50_sor_commit(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1754 | { |
| 1755 | } |
| 1756 | |
| 1757 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1758 | nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode, |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1759 | struct drm_display_mode *mode) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1760 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1761 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
| 1762 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1763 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1764 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1765 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1766 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1767 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1768 | struct nvbios *bios = &drm->vbios; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1769 | u32 *push, lvds = 0; |
| 1770 | u8 owner = 1 << nv_crtc->index; |
| 1771 | u8 proto = 0xf; |
| 1772 | u8 depth = 0x0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1773 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1774 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1775 | switch (nv_encoder->dcb->type) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1776 | case DCB_OUTPUT_TMDS: |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1777 | if (nv_encoder->dcb->sorconf.link & 1) { |
| 1778 | if (mode->clock < 165000) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1779 | proto = 0x1; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1780 | else |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1781 | proto = 0x5; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1782 | } else { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1783 | proto = 0x2; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1784 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1785 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1786 | nv50_hdmi_mode_set(encoder, mode); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1787 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1788 | case DCB_OUTPUT_LVDS: |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1789 | proto = 0x0; |
| 1790 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1791 | if (bios->fp_no_ddc) { |
| 1792 | if (bios->fp.dual_link) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1793 | lvds |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1794 | if (bios->fp.if_is_24bit) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1795 | lvds |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1796 | } else { |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 1797 | if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1798 | if (((u8 *)nv_connector->edid)[121] == 2) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1799 | lvds |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1800 | } else |
| 1801 | if (mode->clock >= bios->fp.duallink_transition_clk) { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1802 | lvds |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1803 | } |
| 1804 | |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1805 | if (lvds & 0x0100) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1806 | if (bios->fp.strapless_is_24bit & 2) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1807 | lvds |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1808 | } else { |
| 1809 | if (bios->fp.strapless_is_24bit & 1) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1810 | lvds |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | if (nv_connector->base.display_info.bpc == 8) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1814 | lvds |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1815 | } |
Ben Skeggs | 4a230fa | 2012-11-09 11:25:37 +1000 | [diff] [blame] | 1816 | |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1817 | nv_call(disp->core, NV50_DISP_SOR_LVDS_SCRIPT + nv_encoder->or, lvds); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1818 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1819 | case DCB_OUTPUT_DP: |
Ben Skeggs | 3488c57 | 2012-03-12 11:42:20 +1000 | [diff] [blame] | 1820 | if (nv_connector->base.display_info.bpc == 6) { |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1821 | nv_encoder->dp.datarate = mode->clock * 18 / 8; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1822 | depth = 0x2; |
Ben Skeggs | bf2c886 | 2012-11-21 14:49:54 +1000 | [diff] [blame] | 1823 | } else |
| 1824 | if (nv_connector->base.display_info.bpc == 8) { |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1825 | nv_encoder->dp.datarate = mode->clock * 24 / 8; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1826 | depth = 0x5; |
Ben Skeggs | bf2c886 | 2012-11-21 14:49:54 +1000 | [diff] [blame] | 1827 | } else { |
| 1828 | nv_encoder->dp.datarate = mode->clock * 30 / 8; |
| 1829 | depth = 0x6; |
Ben Skeggs | 3488c57 | 2012-03-12 11:42:20 +1000 | [diff] [blame] | 1830 | } |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1831 | |
| 1832 | if (nv_encoder->dcb->sorconf.link & 1) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1833 | proto = 0x8; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1834 | else |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1835 | proto = 0x9; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1836 | break; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1837 | default: |
| 1838 | BUG_ON(1); |
| 1839 | break; |
| 1840 | } |
Ben Skeggs | ff8ff50 | 2011-07-08 11:53:37 +1000 | [diff] [blame] | 1841 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1842 | nv50_sor_dpms(encoder, DRM_MODE_DPMS_ON); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1843 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1844 | push = evo_wait(nv50_mast(dev), 8); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1845 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1846 | if (nv50_vers(mast) < NVD0_DISP_CLASS) { |
Ben Skeggs | e2de179 | 2013-02-11 13:56:31 +1000 | [diff] [blame] | 1847 | u32 ctrl = (depth << 16) | (proto << 8) | owner; |
| 1848 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 1849 | ctrl |= 0x00001000; |
| 1850 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 1851 | ctrl |= 0x00002000; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1852 | evo_mthd(push, 0x0600 + (nv_encoder->or * 0x040), 1); |
Ben Skeggs | e2de179 | 2013-02-11 13:56:31 +1000 | [diff] [blame] | 1853 | evo_data(push, ctrl); |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1854 | } else { |
| 1855 | u32 magic = 0x31ec6000 | (nv_crtc->index << 25); |
| 1856 | u32 syncs = 0x00000001; |
| 1857 | |
| 1858 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 1859 | syncs |= 0x00000008; |
| 1860 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 1861 | syncs |= 0x00000010; |
| 1862 | |
| 1863 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 1864 | magic |= 0x00000001; |
| 1865 | |
| 1866 | evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2); |
| 1867 | evo_data(push, syncs | (depth << 6)); |
| 1868 | evo_data(push, magic); |
| 1869 | evo_mthd(push, 0x0200 + (nv_encoder->or * 0x020), 1); |
| 1870 | evo_data(push, owner | (proto << 8)); |
| 1871 | } |
| 1872 | |
| 1873 | evo_kick(push, mast); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | nv_encoder->crtc = encoder->crtc; |
| 1877 | } |
| 1878 | |
| 1879 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1880 | nv50_sor_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1881 | { |
| 1882 | drm_encoder_cleanup(encoder); |
| 1883 | kfree(encoder); |
| 1884 | } |
| 1885 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1886 | static const struct drm_encoder_helper_funcs nv50_sor_hfunc = { |
| 1887 | .dpms = nv50_sor_dpms, |
| 1888 | .mode_fixup = nv50_sor_mode_fixup, |
| 1889 | .prepare = nv50_sor_prepare, |
| 1890 | .commit = nv50_sor_commit, |
| 1891 | .mode_set = nv50_sor_mode_set, |
| 1892 | .disable = nv50_sor_disconnect, |
| 1893 | .get_crtc = nv50_display_crtc_get, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1894 | }; |
| 1895 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1896 | static const struct drm_encoder_funcs nv50_sor_func = { |
| 1897 | .destroy = nv50_sor_destroy, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1898 | }; |
| 1899 | |
| 1900 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1901 | nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1902 | { |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1903 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
| 1904 | struct nouveau_i2c *i2c = nouveau_i2c(drm->device); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1905 | struct nouveau_encoder *nv_encoder; |
| 1906 | struct drm_encoder *encoder; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1907 | int type; |
| 1908 | |
| 1909 | switch (dcbe->type) { |
| 1910 | case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break; |
| 1911 | case DCB_OUTPUT_TMDS: |
| 1912 | case DCB_OUTPUT_DP: |
| 1913 | default: |
| 1914 | type = DRM_MODE_ENCODER_TMDS; |
| 1915 | break; |
| 1916 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1917 | |
| 1918 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 1919 | if (!nv_encoder) |
| 1920 | return -ENOMEM; |
| 1921 | nv_encoder->dcb = dcbe; |
| 1922 | nv_encoder->or = ffs(dcbe->or) - 1; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1923 | nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1924 | nv_encoder->last_dpms = DRM_MODE_DPMS_OFF; |
| 1925 | |
| 1926 | encoder = to_drm_encoder(nv_encoder); |
| 1927 | encoder->possible_crtcs = dcbe->heads; |
| 1928 | encoder->possible_clones = 0; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1929 | drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1930 | drm_encoder_helper_add(encoder, &nv50_sor_hfunc); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1931 | |
| 1932 | drm_mode_connector_attach_encoder(connector, encoder); |
| 1933 | return 0; |
| 1934 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1935 | |
| 1936 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1937 | * Init |
| 1938 | *****************************************************************************/ |
Ben Skeggs | 2a44e49 | 2011-11-09 11:36:33 +1000 | [diff] [blame] | 1939 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1940 | nv50_display_fini(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1941 | { |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1945 | nv50_display_init(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1946 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1947 | u32 *push = evo_wait(nv50_mast(dev), 32); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1948 | if (push) { |
| 1949 | evo_mthd(push, 0x0088, 1); |
| 1950 | evo_data(push, NvEvoSync); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1951 | evo_kick(push, nv50_mast(dev)); |
Ben Skeggs | 647bf61 | 2012-11-19 10:18:25 +1000 | [diff] [blame] | 1952 | return evo_sync(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1953 | } |
| 1954 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1955 | return -EBUSY; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1959 | nv50_display_destroy(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1960 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1961 | struct nv50_disp *disp = nv50_disp(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1962 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1963 | nv50_dmac_destroy(disp->core, &disp->mast.base); |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 1964 | |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 1965 | nouveau_bo_unmap(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1966 | if (disp->sync) |
| 1967 | nouveau_bo_unpin(disp->sync); |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 1968 | nouveau_bo_ref(NULL, &disp->sync); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 1969 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1970 | nouveau_display(dev)->priv = NULL; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1971 | kfree(disp); |
| 1972 | } |
| 1973 | |
| 1974 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1975 | nv50_display_create(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1976 | { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1977 | static const u16 oclass[] = { |
| 1978 | NVE0_DISP_CLASS, |
| 1979 | NVD0_DISP_CLASS, |
Ben Skeggs | 63718a0 | 2012-11-16 11:44:14 +1000 | [diff] [blame] | 1980 | NVA3_DISP_CLASS, |
| 1981 | NV94_DISP_CLASS, |
| 1982 | NVA0_DISP_CLASS, |
| 1983 | NV84_DISP_CLASS, |
| 1984 | NV50_DISP_CLASS, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1985 | }; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1986 | struct nouveau_device *device = nouveau_dev(dev); |
| 1987 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1988 | struct dcb_table *dcb = &drm->vbios.dcb; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1989 | struct drm_connector *connector, *tmp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1990 | struct nv50_disp *disp; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1991 | struct dcb_output *dcbe; |
Ben Skeggs | 7c5f6a8 | 2012-03-04 16:25:59 +1000 | [diff] [blame] | 1992 | int crtcs, ret, i; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1993 | |
| 1994 | disp = kzalloc(sizeof(*disp), GFP_KERNEL); |
| 1995 | if (!disp) |
| 1996 | return -ENOMEM; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1997 | |
| 1998 | nouveau_display(dev)->priv = disp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1999 | nouveau_display(dev)->dtor = nv50_display_destroy; |
| 2000 | nouveau_display(dev)->init = nv50_display_init; |
| 2001 | nouveau_display(dev)->fini = nv50_display_fini; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2002 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2003 | /* small shared memory area we use for notifiers and semaphores */ |
| 2004 | ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM, |
| 2005 | 0, 0x0000, NULL, &disp->sync); |
| 2006 | if (!ret) { |
| 2007 | ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2008 | if (!ret) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2009 | ret = nouveau_bo_map(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2010 | if (ret) |
| 2011 | nouveau_bo_unpin(disp->sync); |
| 2012 | } |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2013 | if (ret) |
| 2014 | nouveau_bo_ref(NULL, &disp->sync); |
| 2015 | } |
| 2016 | |
| 2017 | if (ret) |
| 2018 | goto out; |
| 2019 | |
| 2020 | /* attempt to allocate a supported evo display class */ |
| 2021 | ret = -ENODEV; |
| 2022 | for (i = 0; ret && i < ARRAY_SIZE(oclass); i++) { |
| 2023 | ret = nouveau_object_new(nv_object(drm), NVDRM_DEVICE, |
| 2024 | 0xd1500000, oclass[i], NULL, 0, |
| 2025 | &disp->core); |
| 2026 | } |
| 2027 | |
| 2028 | if (ret) |
| 2029 | goto out; |
| 2030 | |
| 2031 | /* allocate master evo channel */ |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2032 | ret = nv50_dmac_create(disp->core, NV50_DISP_MAST_CLASS, 0, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2033 | &(struct nv50_display_mast_class) { |
| 2034 | .pushbuf = EVO_PUSH_HANDLE(MAST, 0), |
| 2035 | }, sizeof(struct nv50_display_mast_class), |
| 2036 | disp->sync->bo.offset, &disp->mast.base); |
| 2037 | if (ret) |
| 2038 | goto out; |
| 2039 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2040 | /* create crtc objects to represent the hw heads */ |
Ben Skeggs | 63718a0 | 2012-11-16 11:44:14 +1000 | [diff] [blame] | 2041 | if (nv_mclass(disp->core) >= NVD0_DISP_CLASS) |
| 2042 | crtcs = nv_rd32(device, 0x022448); |
| 2043 | else |
| 2044 | crtcs = 2; |
| 2045 | |
Ben Skeggs | 7c5f6a8 | 2012-03-04 16:25:59 +1000 | [diff] [blame] | 2046 | for (i = 0; i < crtcs; i++) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2047 | ret = nv50_crtc_create(dev, disp->core, i); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2048 | if (ret) |
| 2049 | goto out; |
| 2050 | } |
| 2051 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2052 | /* create encoder/connector objects based on VBIOS DCB table */ |
| 2053 | for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) { |
| 2054 | connector = nouveau_connector_create(dev, dcbe->connector); |
| 2055 | if (IS_ERR(connector)) |
| 2056 | continue; |
| 2057 | |
| 2058 | if (dcbe->location != DCB_LOC_ON_CHIP) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2059 | NV_WARN(drm, "skipping off-chip encoder %d/%d\n", |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2060 | dcbe->type, ffs(dcbe->or) - 1); |
| 2061 | continue; |
| 2062 | } |
| 2063 | |
| 2064 | switch (dcbe->type) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 2065 | case DCB_OUTPUT_TMDS: |
| 2066 | case DCB_OUTPUT_LVDS: |
| 2067 | case DCB_OUTPUT_DP: |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2068 | nv50_sor_create(connector, dcbe); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2069 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 2070 | case DCB_OUTPUT_ANALOG: |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2071 | nv50_dac_create(connector, dcbe); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2072 | break; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2073 | default: |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2074 | NV_WARN(drm, "skipping unsupported encoder %d/%d\n", |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2075 | dcbe->type, ffs(dcbe->or) - 1); |
| 2076 | continue; |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | /* cull any connectors we created that don't have an encoder */ |
| 2081 | list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) { |
| 2082 | if (connector->encoder_ids[0]) |
| 2083 | continue; |
| 2084 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2085 | NV_WARN(drm, "%s has no encoders, removing\n", |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2086 | drm_get_connector_name(connector)); |
| 2087 | connector->funcs->destroy(connector); |
| 2088 | } |
| 2089 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2090 | out: |
| 2091 | if (ret) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2092 | nv50_display_destroy(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2093 | return ret; |
| 2094 | } |