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