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