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