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