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