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