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