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