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