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