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