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