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> |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 26 | #include <linux/hdmi.h> |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 27 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 28 | #include <drm/drmP.h> |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 29 | #include <drm/drm_atomic.h> |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 30 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 31 | #include <drm/drm_crtc_helper.h> |
Ben Skeggs | 4874322 | 2014-05-31 01:48:06 +1000 | [diff] [blame] | 32 | #include <drm/drm_dp_helper.h> |
Daniel Vetter | b516a9e | 2015-12-04 09:45:43 +0100 | [diff] [blame] | 33 | #include <drm/drm_fb_helper.h> |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 34 | #include <drm/drm_plane_helper.h> |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 35 | #include <drm/drm_edid.h> |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 36 | |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 37 | #include <nvif/class.h> |
Ben Skeggs | 845f272 | 2015-11-08 12:16:40 +1000 | [diff] [blame] | 38 | #include <nvif/cl0002.h> |
Ben Skeggs | 7568b10 | 2015-11-08 10:44:19 +1000 | [diff] [blame] | 39 | #include <nvif/cl5070.h> |
| 40 | #include <nvif/cl507a.h> |
| 41 | #include <nvif/cl507b.h> |
| 42 | #include <nvif/cl507c.h> |
| 43 | #include <nvif/cl507d.h> |
| 44 | #include <nvif/cl507e.h> |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 45 | #include <nvif/event.h> |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 46 | |
Ben Skeggs | 4dc2813 | 2016-05-20 09:22:55 +1000 | [diff] [blame] | 47 | #include "nouveau_drv.h" |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 48 | #include "nouveau_dma.h" |
| 49 | #include "nouveau_gem.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 50 | #include "nouveau_connector.h" |
| 51 | #include "nouveau_encoder.h" |
| 52 | #include "nouveau_crtc.h" |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 53 | #include "nouveau_fence.h" |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 54 | #include "nouveau_fbcon.h" |
Ben Skeggs | 3a89cd0 | 2011-07-07 10:47:10 +1000 | [diff] [blame] | 55 | #include "nv50_display.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 56 | |
Ben Skeggs | 8a46438 | 2011-11-12 23:52:07 +1000 | [diff] [blame] | 57 | #define EVO_DMA_NR 9 |
| 58 | |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 59 | #define EVO_MASTER (0x00) |
Ben Skeggs | a63a97e | 2011-11-16 15:22:34 +1000 | [diff] [blame] | 60 | #define EVO_FLIP(c) (0x01 + (c)) |
Ben Skeggs | 8a46438 | 2011-11-12 23:52:07 +1000 | [diff] [blame] | 61 | #define EVO_OVLY(c) (0x05 + (c)) |
| 62 | #define EVO_OIMM(c) (0x09 + (c)) |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 63 | #define EVO_CURS(c) (0x0d + (c)) |
| 64 | |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 65 | /* offsets in shared sync bo of various structures */ |
| 66 | #define EVO_SYNC(c, o) ((c) * 0x0100 + (o)) |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 67 | #define EVO_MAST_NTFY EVO_SYNC( 0, 0x00) |
| 68 | #define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00) |
| 69 | #define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10) |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 70 | #define EVO_FLIP_NTFY0(c) EVO_SYNC((c) + 1, 0x20) |
| 71 | #define EVO_FLIP_NTFY1(c) EVO_SYNC((c) + 1, 0x30) |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 72 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 73 | /****************************************************************************** |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 74 | * Atomic state |
| 75 | *****************************************************************************/ |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 76 | #define nv50_atom(p) container_of((p), struct nv50_atom, state) |
| 77 | |
| 78 | struct nv50_atom { |
| 79 | struct drm_atomic_state state; |
| 80 | |
| 81 | struct list_head outp; |
| 82 | bool lock_core; |
| 83 | bool flush_disable; |
| 84 | }; |
| 85 | |
| 86 | struct nv50_outp_atom { |
| 87 | struct list_head head; |
| 88 | |
| 89 | struct drm_encoder *encoder; |
| 90 | bool flush_disable; |
| 91 | |
| 92 | union { |
| 93 | struct { |
| 94 | bool ctrl:1; |
| 95 | }; |
| 96 | u8 mask; |
| 97 | } clr; |
| 98 | |
| 99 | union { |
| 100 | struct { |
| 101 | bool ctrl:1; |
| 102 | }; |
| 103 | u8 mask; |
| 104 | } set; |
| 105 | }; |
| 106 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 107 | #define nv50_head_atom(p) container_of((p), struct nv50_head_atom, state) |
| 108 | |
| 109 | struct nv50_head_atom { |
| 110 | struct drm_crtc_state state; |
| 111 | |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 112 | struct { |
| 113 | u16 iW; |
| 114 | u16 iH; |
| 115 | u16 oW; |
| 116 | u16 oH; |
| 117 | } view; |
| 118 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 119 | struct nv50_head_mode { |
| 120 | bool interlace; |
| 121 | u32 clock; |
| 122 | struct { |
| 123 | u16 active; |
| 124 | u16 synce; |
| 125 | u16 blanke; |
| 126 | u16 blanks; |
| 127 | } h; |
| 128 | struct { |
| 129 | u32 active; |
| 130 | u16 synce; |
| 131 | u16 blanke; |
| 132 | u16 blanks; |
| 133 | u16 blank2s; |
| 134 | u16 blank2e; |
| 135 | u16 blankus; |
| 136 | } v; |
| 137 | } mode; |
| 138 | |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 139 | struct { |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 140 | u32 handle; |
| 141 | u64 offset:40; |
| 142 | } lut; |
| 143 | |
| 144 | struct { |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 145 | bool visible; |
| 146 | u32 handle; |
| 147 | u64 offset:40; |
| 148 | u8 format; |
| 149 | u8 kind:7; |
| 150 | u8 layout:1; |
| 151 | u8 block:4; |
| 152 | u32 pitch:20; |
| 153 | u16 x; |
| 154 | u16 y; |
| 155 | u16 w; |
| 156 | u16 h; |
| 157 | } core; |
| 158 | |
| 159 | struct { |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 160 | bool visible; |
| 161 | u32 handle; |
| 162 | u64 offset:40; |
| 163 | u8 layout:1; |
| 164 | u8 format:1; |
| 165 | } curs; |
| 166 | |
| 167 | struct { |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 168 | u8 depth; |
| 169 | u8 cpp; |
| 170 | u16 x; |
| 171 | u16 y; |
| 172 | u16 w; |
| 173 | u16 h; |
| 174 | } base; |
| 175 | |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 176 | struct { |
| 177 | u8 cpp; |
| 178 | } ovly; |
| 179 | |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 180 | struct { |
| 181 | bool enable:1; |
| 182 | u8 bits:2; |
| 183 | u8 mode:4; |
| 184 | } dither; |
| 185 | |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 186 | struct { |
| 187 | struct { |
| 188 | u16 cos:12; |
| 189 | u16 sin:12; |
| 190 | } sat; |
| 191 | } procamp; |
| 192 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 193 | union { |
| 194 | struct { |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 195 | bool core:1; |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 196 | bool curs:1; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 197 | }; |
| 198 | u8 mask; |
| 199 | } clr; |
| 200 | |
| 201 | union { |
| 202 | struct { |
| 203 | bool core:1; |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 204 | bool curs:1; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 205 | bool view:1; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 206 | bool mode:1; |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 207 | bool base:1; |
| 208 | bool ovly:1; |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 209 | bool dither:1; |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 210 | bool procamp:1; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 211 | }; |
| 212 | u16 mask; |
| 213 | } set; |
| 214 | }; |
| 215 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 216 | static inline struct nv50_head_atom * |
| 217 | nv50_head_atom_get(struct drm_atomic_state *state, struct drm_crtc *crtc) |
| 218 | { |
| 219 | struct drm_crtc_state *statec = drm_atomic_get_crtc_state(state, crtc); |
| 220 | if (IS_ERR(statec)) |
| 221 | return (void *)statec; |
| 222 | return nv50_head_atom(statec); |
| 223 | } |
| 224 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 225 | #define nv50_wndw_atom(p) container_of((p), struct nv50_wndw_atom, state) |
| 226 | |
| 227 | struct nv50_wndw_atom { |
| 228 | struct drm_plane_state state; |
| 229 | u8 interval; |
| 230 | |
| 231 | struct drm_rect clip; |
| 232 | |
| 233 | struct { |
| 234 | u32 handle; |
| 235 | u16 offset:12; |
| 236 | bool awaken:1; |
| 237 | } ntfy; |
| 238 | |
| 239 | struct { |
| 240 | u32 handle; |
| 241 | u16 offset:12; |
| 242 | u32 acquire; |
| 243 | u32 release; |
| 244 | } sema; |
| 245 | |
| 246 | struct { |
| 247 | u8 enable:2; |
| 248 | } lut; |
| 249 | |
| 250 | struct { |
| 251 | u8 mode:2; |
| 252 | u8 interval:4; |
| 253 | |
| 254 | u8 format; |
| 255 | u8 kind:7; |
| 256 | u8 layout:1; |
| 257 | u8 block:4; |
| 258 | u32 pitch:20; |
| 259 | u16 w; |
| 260 | u16 h; |
| 261 | |
| 262 | u32 handle; |
| 263 | u64 offset; |
| 264 | } image; |
| 265 | |
| 266 | struct { |
| 267 | u16 x; |
| 268 | u16 y; |
| 269 | } point; |
| 270 | |
| 271 | union { |
| 272 | struct { |
| 273 | bool ntfy:1; |
| 274 | bool sema:1; |
| 275 | bool image:1; |
| 276 | }; |
| 277 | u8 mask; |
| 278 | } clr; |
| 279 | |
| 280 | union { |
| 281 | struct { |
| 282 | bool ntfy:1; |
| 283 | bool sema:1; |
| 284 | bool image:1; |
| 285 | bool lut:1; |
| 286 | bool point:1; |
| 287 | }; |
| 288 | u8 mask; |
| 289 | } set; |
| 290 | }; |
| 291 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 292 | /****************************************************************************** |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 293 | * EVO channel |
| 294 | *****************************************************************************/ |
| 295 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 296 | struct nv50_chan { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 297 | struct nvif_object user; |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 298 | struct nvif_device *device; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 302 | nv50_chan_create(struct nvif_device *device, struct nvif_object *disp, |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 303 | const s32 *oclass, u8 head, void *data, u32 size, |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 304 | struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 305 | { |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 306 | struct nvif_sclass *sclass; |
| 307 | int ret, i, n; |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 308 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 309 | chan->device = device; |
| 310 | |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 311 | ret = n = nvif_object_sclass_get(disp, &sclass); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 312 | if (ret < 0) |
| 313 | return ret; |
| 314 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 315 | while (oclass[0]) { |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 316 | for (i = 0; i < n; i++) { |
| 317 | if (sclass[i].oclass == oclass[0]) { |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 318 | ret = nvif_object_init(disp, 0, oclass[0], |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 319 | data, size, &chan->user); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 320 | if (ret == 0) |
| 321 | nvif_object_map(&chan->user); |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 322 | nvif_object_sclass_put(&sclass); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 323 | return ret; |
| 324 | } |
Ben Skeggs | b76f152 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 325 | } |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 326 | oclass++; |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 327 | } |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 328 | |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 329 | nvif_object_sclass_put(&sclass); |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 330 | return -ENOSYS; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | static void |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 334 | nv50_chan_destroy(struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 335 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 336 | nvif_object_fini(&chan->user); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /****************************************************************************** |
| 340 | * PIO EVO channel |
| 341 | *****************************************************************************/ |
| 342 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 343 | struct nv50_pioc { |
| 344 | struct nv50_chan base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | static void |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 348 | nv50_pioc_destroy(struct nv50_pioc *pioc) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 349 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 350 | nv50_chan_destroy(&pioc->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 354 | nv50_pioc_create(struct nvif_device *device, struct nvif_object *disp, |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 355 | const s32 *oclass, u8 head, void *data, u32 size, |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 356 | struct nv50_pioc *pioc) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 357 | { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 358 | return nv50_chan_create(device, disp, oclass, head, data, size, |
| 359 | &pioc->base); |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /****************************************************************************** |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 363 | * Overlay Immediate |
| 364 | *****************************************************************************/ |
| 365 | |
| 366 | struct nv50_oimm { |
| 367 | struct nv50_pioc base; |
| 368 | }; |
| 369 | |
| 370 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 371 | nv50_oimm_create(struct nvif_device *device, struct nvif_object *disp, |
| 372 | int head, struct nv50_oimm *oimm) |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 373 | { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 374 | struct nv50_disp_cursor_v0 args = { |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 375 | .head = head, |
| 376 | }; |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 377 | static const s32 oclass[] = { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 378 | GK104_DISP_OVERLAY, |
| 379 | GF110_DISP_OVERLAY, |
| 380 | GT214_DISP_OVERLAY, |
| 381 | G82_DISP_OVERLAY, |
| 382 | NV50_DISP_OVERLAY, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 383 | 0 |
| 384 | }; |
| 385 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 386 | return nv50_pioc_create(device, disp, oclass, head, &args, sizeof(args), |
| 387 | &oimm->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /****************************************************************************** |
| 391 | * DMA EVO channel |
| 392 | *****************************************************************************/ |
| 393 | |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 394 | struct nv50_dmac_ctxdma { |
| 395 | struct list_head head; |
| 396 | struct nvif_object object; |
| 397 | }; |
| 398 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 399 | struct nv50_dmac { |
| 400 | struct nv50_chan base; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 401 | dma_addr_t handle; |
| 402 | u32 *ptr; |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 403 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 404 | struct nvif_object sync; |
| 405 | struct nvif_object vram; |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 406 | struct list_head ctxdma; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 407 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 408 | /* Protects against concurrent pushbuf access to this channel, lock is |
| 409 | * grabbed by evo_wait (if the pushbuf reservation is successful) and |
| 410 | * dropped again by evo_kick. */ |
| 411 | struct mutex lock; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 412 | }; |
| 413 | |
| 414 | static void |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 415 | nv50_dmac_ctxdma_del(struct nv50_dmac_ctxdma *ctxdma) |
| 416 | { |
| 417 | nvif_object_fini(&ctxdma->object); |
| 418 | list_del(&ctxdma->head); |
| 419 | kfree(ctxdma); |
| 420 | } |
| 421 | |
| 422 | static struct nv50_dmac_ctxdma * |
Ben Skeggs | f00f0e2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 423 | nv50_dmac_ctxdma_new(struct nv50_dmac *dmac, struct nouveau_framebuffer *fb) |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 424 | { |
| 425 | struct nouveau_drm *drm = nouveau_drm(fb->base.dev); |
| 426 | struct nv50_dmac_ctxdma *ctxdma; |
Ben Skeggs | f00f0e2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 427 | const u8 kind = (fb->nvbo->tile_flags & 0x0000ff00) >> 8; |
| 428 | const u32 handle = 0xfb000000 | kind; |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 429 | struct { |
| 430 | struct nv_dma_v0 base; |
| 431 | union { |
| 432 | struct nv50_dma_v0 nv50; |
| 433 | struct gf100_dma_v0 gf100; |
| 434 | struct gf119_dma_v0 gf119; |
| 435 | }; |
| 436 | } args = {}; |
| 437 | u32 argc = sizeof(args.base); |
| 438 | int ret; |
| 439 | |
| 440 | list_for_each_entry(ctxdma, &dmac->ctxdma, head) { |
| 441 | if (ctxdma->object.handle == handle) |
| 442 | return ctxdma; |
| 443 | } |
| 444 | |
| 445 | if (!(ctxdma = kzalloc(sizeof(*ctxdma), GFP_KERNEL))) |
| 446 | return ERR_PTR(-ENOMEM); |
| 447 | list_add(&ctxdma->head, &dmac->ctxdma); |
| 448 | |
| 449 | args.base.target = NV_DMA_V0_TARGET_VRAM; |
| 450 | args.base.access = NV_DMA_V0_ACCESS_RDWR; |
| 451 | args.base.start = 0; |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 452 | args.base.limit = drm->client.device.info.ram_user - 1; |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 453 | |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 454 | if (drm->client.device.info.chipset < 0x80) { |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 455 | args.nv50.part = NV50_DMA_V0_PART_256; |
| 456 | argc += sizeof(args.nv50); |
| 457 | } else |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 458 | if (drm->client.device.info.chipset < 0xc0) { |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 459 | args.nv50.part = NV50_DMA_V0_PART_256; |
| 460 | args.nv50.kind = kind; |
| 461 | argc += sizeof(args.nv50); |
| 462 | } else |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 463 | if (drm->client.device.info.chipset < 0xd0) { |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 464 | args.gf100.kind = kind; |
| 465 | argc += sizeof(args.gf100); |
| 466 | } else { |
| 467 | args.gf119.page = GF119_DMA_V0_PAGE_LP; |
| 468 | args.gf119.kind = kind; |
| 469 | argc += sizeof(args.gf119); |
| 470 | } |
| 471 | |
| 472 | ret = nvif_object_init(&dmac->base.user, handle, NV_DMA_IN_MEMORY, |
| 473 | &args, argc, &ctxdma->object); |
| 474 | if (ret) { |
| 475 | nv50_dmac_ctxdma_del(ctxdma); |
| 476 | return ERR_PTR(ret); |
| 477 | } |
| 478 | |
| 479 | return ctxdma; |
| 480 | } |
| 481 | |
| 482 | static void |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 483 | nv50_dmac_destroy(struct nv50_dmac *dmac, struct nvif_object *disp) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 484 | { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 485 | struct nvif_device *device = dmac->base.device; |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 486 | struct nv50_dmac_ctxdma *ctxdma, *ctxtmp; |
| 487 | |
| 488 | list_for_each_entry_safe(ctxdma, ctxtmp, &dmac->ctxdma, head) { |
| 489 | nv50_dmac_ctxdma_del(ctxdma); |
| 490 | } |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 491 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 492 | nvif_object_fini(&dmac->vram); |
| 493 | nvif_object_fini(&dmac->sync); |
| 494 | |
| 495 | nv50_chan_destroy(&dmac->base); |
| 496 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 497 | if (dmac->ptr) { |
Ben Skeggs | 26c9e8e | 2015-08-20 14:54:23 +1000 | [diff] [blame] | 498 | struct device *dev = nvxx_device(device)->dev; |
| 499 | dma_free_coherent(dev, PAGE_SIZE, dmac->ptr, dmac->handle); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 500 | } |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 504 | nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp, |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 505 | const s32 *oclass, u8 head, void *data, u32 size, u64 syncbuf, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 506 | struct nv50_dmac *dmac) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 507 | { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 508 | struct nv50_disp_core_channel_dma_v0 *args = data; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 509 | struct nvif_object pushbuf; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 510 | int ret; |
| 511 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 512 | mutex_init(&dmac->lock); |
| 513 | |
Ben Skeggs | 26c9e8e | 2015-08-20 14:54:23 +1000 | [diff] [blame] | 514 | dmac->ptr = dma_alloc_coherent(nvxx_device(device)->dev, PAGE_SIZE, |
| 515 | &dmac->handle, GFP_KERNEL); |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 516 | if (!dmac->ptr) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 517 | return -ENOMEM; |
| 518 | |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 519 | ret = nvif_object_init(&device->object, 0, NV_DMA_FROM_MEMORY, |
| 520 | &(struct nv_dma_v0) { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 521 | .target = NV_DMA_V0_TARGET_PCI_US, |
| 522 | .access = NV_DMA_V0_ACCESS_RD, |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 523 | .start = dmac->handle + 0x0000, |
| 524 | .limit = dmac->handle + 0x0fff, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 525 | }, sizeof(struct nv_dma_v0), &pushbuf); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 526 | if (ret) |
| 527 | return ret; |
| 528 | |
Ben Skeggs | bf81df9 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 529 | args->pushbuf = nvif_handle(&pushbuf); |
| 530 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 531 | ret = nv50_chan_create(device, disp, oclass, head, data, size, |
| 532 | &dmac->base); |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 533 | nvif_object_fini(&pushbuf); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 534 | if (ret) |
| 535 | return ret; |
| 536 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 537 | ret = nvif_object_init(&dmac->base.user, 0xf0000000, NV_DMA_IN_MEMORY, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 538 | &(struct nv_dma_v0) { |
| 539 | .target = NV_DMA_V0_TARGET_VRAM, |
| 540 | .access = NV_DMA_V0_ACCESS_RDWR, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 541 | .start = syncbuf + 0x0000, |
| 542 | .limit = syncbuf + 0x0fff, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 543 | }, sizeof(struct nv_dma_v0), |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 544 | &dmac->sync); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 545 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 546 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 547 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 548 | ret = nvif_object_init(&dmac->base.user, 0xf0000001, NV_DMA_IN_MEMORY, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 549 | &(struct nv_dma_v0) { |
| 550 | .target = NV_DMA_V0_TARGET_VRAM, |
| 551 | .access = NV_DMA_V0_ACCESS_RDWR, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 552 | .start = 0, |
Ben Skeggs | f392ec4 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 553 | .limit = device->info.ram_user - 1, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 554 | }, sizeof(struct nv_dma_v0), |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 555 | &dmac->vram); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 556 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 557 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 558 | |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 559 | INIT_LIST_HEAD(&dmac->ctxdma); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 560 | return ret; |
| 561 | } |
| 562 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 563 | /****************************************************************************** |
| 564 | * Core |
| 565 | *****************************************************************************/ |
| 566 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 567 | struct nv50_mast { |
| 568 | struct nv50_dmac base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 569 | }; |
| 570 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 571 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 572 | nv50_core_create(struct nvif_device *device, struct nvif_object *disp, |
| 573 | u64 syncbuf, struct nv50_mast *core) |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 574 | { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 575 | struct nv50_disp_core_channel_dma_v0 args = { |
| 576 | .pushbuf = 0xb0007d00, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 577 | }; |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 578 | static const s32 oclass[] = { |
Ben Skeggs | ed82866 | 2016-11-16 15:03:07 +1000 | [diff] [blame] | 579 | GP102_DISP_CORE_CHANNEL_DMA, |
Ben Skeggs | f9d5cbb | 2016-07-09 10:41:01 +1000 | [diff] [blame] | 580 | GP100_DISP_CORE_CHANNEL_DMA, |
Ben Skeggs | db1eb52 | 2016-02-11 08:35:32 +1000 | [diff] [blame] | 581 | GM200_DISP_CORE_CHANNEL_DMA, |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 582 | GM107_DISP_CORE_CHANNEL_DMA, |
| 583 | GK110_DISP_CORE_CHANNEL_DMA, |
| 584 | GK104_DISP_CORE_CHANNEL_DMA, |
| 585 | GF110_DISP_CORE_CHANNEL_DMA, |
| 586 | GT214_DISP_CORE_CHANNEL_DMA, |
| 587 | GT206_DISP_CORE_CHANNEL_DMA, |
| 588 | GT200_DISP_CORE_CHANNEL_DMA, |
| 589 | G82_DISP_CORE_CHANNEL_DMA, |
| 590 | NV50_DISP_CORE_CHANNEL_DMA, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 591 | 0 |
| 592 | }; |
| 593 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 594 | return nv50_dmac_create(device, disp, oclass, 0, &args, sizeof(args), |
| 595 | syncbuf, &core->base); |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /****************************************************************************** |
| 599 | * Base |
| 600 | *****************************************************************************/ |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 601 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 602 | struct nv50_sync { |
| 603 | struct nv50_dmac base; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 604 | u32 addr; |
| 605 | u32 data; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 606 | }; |
| 607 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 608 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 609 | nv50_base_create(struct nvif_device *device, struct nvif_object *disp, |
| 610 | int head, u64 syncbuf, struct nv50_sync *base) |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 611 | { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 612 | struct nv50_disp_base_channel_dma_v0 args = { |
| 613 | .pushbuf = 0xb0007c00 | head, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 614 | .head = head, |
| 615 | }; |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 616 | static const s32 oclass[] = { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 617 | GK110_DISP_BASE_CHANNEL_DMA, |
| 618 | GK104_DISP_BASE_CHANNEL_DMA, |
| 619 | GF110_DISP_BASE_CHANNEL_DMA, |
| 620 | GT214_DISP_BASE_CHANNEL_DMA, |
| 621 | GT200_DISP_BASE_CHANNEL_DMA, |
| 622 | G82_DISP_BASE_CHANNEL_DMA, |
| 623 | NV50_DISP_BASE_CHANNEL_DMA, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 624 | 0 |
| 625 | }; |
| 626 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 627 | return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args), |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 628 | syncbuf, &base->base); |
| 629 | } |
| 630 | |
| 631 | /****************************************************************************** |
| 632 | * Overlay |
| 633 | *****************************************************************************/ |
| 634 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 635 | struct nv50_ovly { |
| 636 | struct nv50_dmac base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 637 | }; |
Ben Skeggs | f20ce96 | 2011-07-08 13:17:01 +1000 | [diff] [blame] | 638 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 639 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 640 | nv50_ovly_create(struct nvif_device *device, struct nvif_object *disp, |
| 641 | int head, u64 syncbuf, struct nv50_ovly *ovly) |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 642 | { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 643 | struct nv50_disp_overlay_channel_dma_v0 args = { |
| 644 | .pushbuf = 0xb0007e00 | head, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 645 | .head = head, |
| 646 | }; |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 647 | static const s32 oclass[] = { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 648 | GK104_DISP_OVERLAY_CONTROL_DMA, |
| 649 | GF110_DISP_OVERLAY_CONTROL_DMA, |
| 650 | GT214_DISP_OVERLAY_CHANNEL_DMA, |
| 651 | GT200_DISP_OVERLAY_CHANNEL_DMA, |
| 652 | G82_DISP_OVERLAY_CHANNEL_DMA, |
| 653 | NV50_DISP_OVERLAY_CHANNEL_DMA, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 654 | 0 |
| 655 | }; |
| 656 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 657 | return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args), |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 658 | syncbuf, &ovly->base); |
| 659 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 660 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 661 | struct nv50_head { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 662 | struct nouveau_crtc base; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 663 | struct nv50_ovly ovly; |
| 664 | struct nv50_oimm oimm; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 665 | }; |
| 666 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 667 | #define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c)) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 668 | #define nv50_ovly(c) (&nv50_head(c)->ovly) |
| 669 | #define nv50_oimm(c) (&nv50_head(c)->oimm) |
| 670 | #define nv50_chan(c) (&(c)->base.base) |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 671 | #define nv50_vers(c) nv50_chan(c)->user.oclass |
| 672 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 673 | struct nv50_disp { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 674 | struct nvif_object *disp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 675 | struct nv50_mast mast; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 676 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 677 | struct nouveau_bo *sync; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 678 | |
| 679 | struct mutex mutex; |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 680 | }; |
| 681 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 682 | static struct nv50_disp * |
| 683 | nv50_disp(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 684 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 685 | return nouveau_display(dev)->priv; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 686 | } |
| 687 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 688 | #define nv50_mast(d) (&nv50_disp(d)->mast) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 689 | |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 690 | /****************************************************************************** |
| 691 | * EVO channel helpers |
| 692 | *****************************************************************************/ |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 693 | static u32 * |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 694 | evo_wait(void *evoc, int nr) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 695 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 696 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 697 | struct nvif_device *device = dmac->base.device; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 698 | u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 699 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 700 | mutex_lock(&dmac->lock); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 701 | if (put + nr >= (PAGE_SIZE / 4) - 8) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 702 | dmac->ptr[put] = 0x20000000; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 703 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 704 | nvif_wr32(&dmac->base.user, 0x0000, 0x00000000); |
Ben Skeggs | 5444204 | 2015-08-20 14:54:11 +1000 | [diff] [blame] | 705 | if (nvif_msec(device, 2000, |
| 706 | if (!nvif_rd32(&dmac->base.user, 0x0004)) |
| 707 | break; |
| 708 | ) < 0) { |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 709 | mutex_unlock(&dmac->lock); |
Joe Perches | 8dfe162 | 2017-02-28 04:55:54 -0800 | [diff] [blame] | 710 | pr_err("nouveau: evo channel stalled\n"); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 711 | return NULL; |
| 712 | } |
| 713 | |
| 714 | put = 0; |
| 715 | } |
| 716 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 717 | return dmac->ptr + put; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | static void |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 721 | evo_kick(u32 *push, void *evoc) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 722 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 723 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 724 | nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2); |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 725 | mutex_unlock(&dmac->lock); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 726 | } |
| 727 | |
Joe Perches | 8dfe162 | 2017-02-28 04:55:54 -0800 | [diff] [blame] | 728 | #define evo_mthd(p, m, s) do { \ |
| 729 | const u32 _m = (m), _s = (s); \ |
| 730 | if (drm_debug & DRM_UT_KMS) \ |
| 731 | pr_err("%04x %d %s\n", _m, _s, __func__); \ |
| 732 | *((p)++) = ((_s << 18) | _m); \ |
Ben Skeggs | 2b1930c | 2014-11-03 16:43:59 +1000 | [diff] [blame] | 733 | } while(0) |
Ben Skeggs | 7f55a07 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 734 | |
Joe Perches | 8dfe162 | 2017-02-28 04:55:54 -0800 | [diff] [blame] | 735 | #define evo_data(p, d) do { \ |
| 736 | const u32 _d = (d); \ |
| 737 | if (drm_debug & DRM_UT_KMS) \ |
| 738 | pr_err("\t%08x\n", _d); \ |
| 739 | *((p)++) = _d; \ |
Ben Skeggs | 2b1930c | 2014-11-03 16:43:59 +1000 | [diff] [blame] | 740 | } while(0) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 741 | |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 742 | /****************************************************************************** |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 743 | * Plane |
| 744 | *****************************************************************************/ |
| 745 | #define nv50_wndw(p) container_of((p), struct nv50_wndw, plane) |
| 746 | |
| 747 | struct nv50_wndw { |
| 748 | const struct nv50_wndw_func *func; |
| 749 | struct nv50_dmac *dmac; |
| 750 | |
| 751 | struct drm_plane plane; |
| 752 | |
| 753 | struct nvif_notify notify; |
| 754 | u16 ntfy; |
| 755 | u16 sema; |
| 756 | u32 data; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 757 | }; |
| 758 | |
| 759 | struct nv50_wndw_func { |
| 760 | void *(*dtor)(struct nv50_wndw *); |
| 761 | int (*acquire)(struct nv50_wndw *, struct nv50_wndw_atom *asyw, |
| 762 | struct nv50_head_atom *asyh); |
| 763 | void (*release)(struct nv50_wndw *, struct nv50_wndw_atom *asyw, |
| 764 | struct nv50_head_atom *asyh); |
| 765 | void (*prepare)(struct nv50_wndw *, struct nv50_head_atom *asyh, |
| 766 | struct nv50_wndw_atom *asyw); |
| 767 | |
| 768 | void (*sema_set)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 769 | void (*sema_clr)(struct nv50_wndw *); |
| 770 | void (*ntfy_set)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 771 | void (*ntfy_clr)(struct nv50_wndw *); |
| 772 | int (*ntfy_wait_begun)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 773 | void (*image_set)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 774 | void (*image_clr)(struct nv50_wndw *); |
| 775 | void (*lut)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 776 | void (*point)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 777 | |
| 778 | u32 (*update)(struct nv50_wndw *, u32 interlock); |
| 779 | }; |
| 780 | |
| 781 | static int |
| 782 | nv50_wndw_wait_armed(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 783 | { |
| 784 | if (asyw->set.ntfy) |
| 785 | return wndw->func->ntfy_wait_begun(wndw, asyw); |
| 786 | return 0; |
| 787 | } |
| 788 | |
| 789 | static u32 |
| 790 | nv50_wndw_flush_clr(struct nv50_wndw *wndw, u32 interlock, bool flush, |
| 791 | struct nv50_wndw_atom *asyw) |
| 792 | { |
| 793 | if (asyw->clr.sema && (!asyw->set.sema || flush)) |
| 794 | wndw->func->sema_clr(wndw); |
| 795 | if (asyw->clr.ntfy && (!asyw->set.ntfy || flush)) |
| 796 | wndw->func->ntfy_clr(wndw); |
| 797 | if (asyw->clr.image && (!asyw->set.image || flush)) |
| 798 | wndw->func->image_clr(wndw); |
| 799 | |
| 800 | return flush ? wndw->func->update(wndw, interlock) : 0; |
| 801 | } |
| 802 | |
| 803 | static u32 |
| 804 | nv50_wndw_flush_set(struct nv50_wndw *wndw, u32 interlock, |
| 805 | struct nv50_wndw_atom *asyw) |
| 806 | { |
| 807 | if (interlock) { |
| 808 | asyw->image.mode = 0; |
| 809 | asyw->image.interval = 1; |
| 810 | } |
| 811 | |
| 812 | if (asyw->set.sema ) wndw->func->sema_set (wndw, asyw); |
| 813 | if (asyw->set.ntfy ) wndw->func->ntfy_set (wndw, asyw); |
| 814 | if (asyw->set.image) wndw->func->image_set(wndw, asyw); |
| 815 | if (asyw->set.lut ) wndw->func->lut (wndw, asyw); |
| 816 | if (asyw->set.point) wndw->func->point (wndw, asyw); |
| 817 | |
| 818 | return wndw->func->update(wndw, interlock); |
| 819 | } |
| 820 | |
| 821 | static void |
| 822 | nv50_wndw_atomic_check_release(struct nv50_wndw *wndw, |
| 823 | struct nv50_wndw_atom *asyw, |
| 824 | struct nv50_head_atom *asyh) |
| 825 | { |
| 826 | struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev); |
| 827 | NV_ATOMIC(drm, "%s release\n", wndw->plane.name); |
| 828 | wndw->func->release(wndw, asyw, asyh); |
| 829 | asyw->ntfy.handle = 0; |
| 830 | asyw->sema.handle = 0; |
| 831 | } |
| 832 | |
| 833 | static int |
| 834 | nv50_wndw_atomic_check_acquire(struct nv50_wndw *wndw, |
| 835 | struct nv50_wndw_atom *asyw, |
Ben Skeggs | f42c570 | 2017-05-01 16:59:29 +1000 | [diff] [blame] | 836 | struct nv50_head_atom *asyh) |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 837 | { |
| 838 | struct nouveau_framebuffer *fb = nouveau_framebuffer(asyw->state.fb); |
| 839 | struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev); |
| 840 | int ret; |
| 841 | |
| 842 | NV_ATOMIC(drm, "%s acquire\n", wndw->plane.name); |
| 843 | asyw->clip.x1 = 0; |
| 844 | asyw->clip.y1 = 0; |
| 845 | asyw->clip.x2 = asyh->state.mode.hdisplay; |
| 846 | asyw->clip.y2 = asyh->state.mode.vdisplay; |
| 847 | |
| 848 | asyw->image.w = fb->base.width; |
| 849 | asyw->image.h = fb->base.height; |
| 850 | asyw->image.kind = (fb->nvbo->tile_flags & 0x0000ff00) >> 8; |
Andrey Grodzovsky | 612fb5d | 2017-02-02 16:56:30 -0500 | [diff] [blame] | 851 | |
Ben Skeggs | f42c570 | 2017-05-01 16:59:29 +1000 | [diff] [blame] | 852 | if (asyh->state.pageflip_flags & DRM_MODE_PAGE_FLIP_ASYNC) |
| 853 | asyw->interval = 0; |
| 854 | else |
| 855 | asyw->interval = 1; |
Andrey Grodzovsky | 612fb5d | 2017-02-02 16:56:30 -0500 | [diff] [blame] | 856 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 857 | if (asyw->image.kind) { |
| 858 | asyw->image.layout = 0; |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 859 | if (drm->client.device.info.chipset >= 0xc0) |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 860 | asyw->image.block = fb->nvbo->tile_mode >> 4; |
| 861 | else |
| 862 | asyw->image.block = fb->nvbo->tile_mode; |
| 863 | asyw->image.pitch = (fb->base.pitches[0] / 4) << 4; |
| 864 | } else { |
| 865 | asyw->image.layout = 1; |
| 866 | asyw->image.block = 0; |
| 867 | asyw->image.pitch = fb->base.pitches[0]; |
| 868 | } |
| 869 | |
| 870 | ret = wndw->func->acquire(wndw, asyw, asyh); |
| 871 | if (ret) |
| 872 | return ret; |
| 873 | |
| 874 | if (asyw->set.image) { |
| 875 | if (!(asyw->image.mode = asyw->interval ? 0 : 1)) |
| 876 | asyw->image.interval = asyw->interval; |
| 877 | else |
| 878 | asyw->image.interval = 0; |
| 879 | } |
| 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | static int |
| 885 | nv50_wndw_atomic_check(struct drm_plane *plane, struct drm_plane_state *state) |
| 886 | { |
| 887 | struct nouveau_drm *drm = nouveau_drm(plane->dev); |
| 888 | struct nv50_wndw *wndw = nv50_wndw(plane); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 889 | struct nv50_wndw_atom *armw = nv50_wndw_atom(wndw->plane.state); |
| 890 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(state); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 891 | struct nv50_head_atom *harm = NULL, *asyh = NULL; |
| 892 | bool varm = false, asyv = false, asym = false; |
| 893 | int ret; |
| 894 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 895 | NV_ATOMIC(drm, "%s atomic_check\n", plane->name); |
| 896 | if (asyw->state.crtc) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 897 | asyh = nv50_head_atom_get(asyw->state.state, asyw->state.crtc); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 898 | if (IS_ERR(asyh)) |
| 899 | return PTR_ERR(asyh); |
| 900 | asym = drm_atomic_crtc_needs_modeset(&asyh->state); |
| 901 | asyv = asyh->state.active; |
| 902 | } |
| 903 | |
| 904 | if (armw->state.crtc) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 905 | harm = nv50_head_atom_get(asyw->state.state, armw->state.crtc); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 906 | if (IS_ERR(harm)) |
| 907 | return PTR_ERR(harm); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 908 | varm = harm->state.crtc->state->active; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | if (asyv) { |
| 912 | asyw->point.x = asyw->state.crtc_x; |
| 913 | asyw->point.y = asyw->state.crtc_y; |
| 914 | if (memcmp(&armw->point, &asyw->point, sizeof(asyw->point))) |
| 915 | asyw->set.point = true; |
| 916 | |
Ben Skeggs | 36601c2 | 2017-05-01 16:52:03 +1000 | [diff] [blame] | 917 | ret = nv50_wndw_atomic_check_acquire(wndw, asyw, asyh); |
| 918 | if (ret) |
| 919 | return ret; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 920 | } else |
| 921 | if (varm) { |
| 922 | nv50_wndw_atomic_check_release(wndw, asyw, harm); |
| 923 | } else { |
| 924 | return 0; |
| 925 | } |
| 926 | |
| 927 | if (!asyv || asym) { |
| 928 | asyw->clr.ntfy = armw->ntfy.handle != 0; |
| 929 | asyw->clr.sema = armw->sema.handle != 0; |
| 930 | if (wndw->func->image_clr) |
| 931 | asyw->clr.image = armw->image.handle != 0; |
| 932 | asyw->set.lut = wndw->func->lut && asyv; |
| 933 | } |
| 934 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 935 | return 0; |
| 936 | } |
| 937 | |
| 938 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 939 | nv50_wndw_cleanup_fb(struct drm_plane *plane, struct drm_plane_state *old_state) |
| 940 | { |
| 941 | struct nouveau_framebuffer *fb = nouveau_framebuffer(old_state->fb); |
| 942 | struct nouveau_drm *drm = nouveau_drm(plane->dev); |
| 943 | |
| 944 | NV_ATOMIC(drm, "%s cleanup: %p\n", plane->name, old_state->fb); |
| 945 | if (!old_state->fb) |
| 946 | return; |
| 947 | |
| 948 | nouveau_bo_unpin(fb->nvbo); |
| 949 | } |
| 950 | |
| 951 | static int |
| 952 | nv50_wndw_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state) |
| 953 | { |
| 954 | struct nouveau_framebuffer *fb = nouveau_framebuffer(state->fb); |
| 955 | struct nouveau_drm *drm = nouveau_drm(plane->dev); |
| 956 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 957 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(state); |
| 958 | struct nv50_head_atom *asyh; |
| 959 | struct nv50_dmac_ctxdma *ctxdma; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 960 | int ret; |
| 961 | |
| 962 | NV_ATOMIC(drm, "%s prepare: %p\n", plane->name, state->fb); |
| 963 | if (!asyw->state.fb) |
| 964 | return 0; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 965 | |
| 966 | ret = nouveau_bo_pin(fb->nvbo, TTM_PL_FLAG_VRAM, true); |
| 967 | if (ret) |
| 968 | return ret; |
| 969 | |
Ben Skeggs | f00f0e2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 970 | ctxdma = nv50_dmac_ctxdma_new(wndw->dmac, fb); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 971 | if (IS_ERR(ctxdma)) { |
| 972 | nouveau_bo_unpin(fb->nvbo); |
| 973 | return PTR_ERR(ctxdma); |
| 974 | } |
| 975 | |
| 976 | asyw->state.fence = reservation_object_get_excl_rcu(fb->nvbo->bo.resv); |
| 977 | asyw->image.handle = ctxdma->object.handle; |
| 978 | asyw->image.offset = fb->nvbo->bo.offset; |
| 979 | |
| 980 | if (wndw->func->prepare) { |
| 981 | asyh = nv50_head_atom_get(asyw->state.state, asyw->state.crtc); |
| 982 | if (IS_ERR(asyh)) |
| 983 | return PTR_ERR(asyh); |
| 984 | |
| 985 | wndw->func->prepare(wndw, asyh, asyw); |
| 986 | } |
| 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | static const struct drm_plane_helper_funcs |
| 992 | nv50_wndw_helper = { |
| 993 | .prepare_fb = nv50_wndw_prepare_fb, |
| 994 | .cleanup_fb = nv50_wndw_cleanup_fb, |
| 995 | .atomic_check = nv50_wndw_atomic_check, |
| 996 | }; |
| 997 | |
| 998 | static void |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 999 | nv50_wndw_atomic_destroy_state(struct drm_plane *plane, |
| 1000 | struct drm_plane_state *state) |
| 1001 | { |
| 1002 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(state); |
| 1003 | __drm_atomic_helper_plane_destroy_state(&asyw->state); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1004 | kfree(asyw); |
| 1005 | } |
| 1006 | |
| 1007 | static struct drm_plane_state * |
| 1008 | nv50_wndw_atomic_duplicate_state(struct drm_plane *plane) |
| 1009 | { |
| 1010 | struct nv50_wndw_atom *armw = nv50_wndw_atom(plane->state); |
| 1011 | struct nv50_wndw_atom *asyw; |
| 1012 | if (!(asyw = kmalloc(sizeof(*asyw), GFP_KERNEL))) |
| 1013 | return NULL; |
| 1014 | __drm_atomic_helper_plane_duplicate_state(plane, &asyw->state); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1015 | asyw->interval = 1; |
| 1016 | asyw->sema = armw->sema; |
| 1017 | asyw->ntfy = armw->ntfy; |
| 1018 | asyw->image = armw->image; |
| 1019 | asyw->point = armw->point; |
| 1020 | asyw->lut = armw->lut; |
| 1021 | asyw->clr.mask = 0; |
| 1022 | asyw->set.mask = 0; |
| 1023 | return &asyw->state; |
| 1024 | } |
| 1025 | |
| 1026 | static void |
| 1027 | nv50_wndw_reset(struct drm_plane *plane) |
| 1028 | { |
| 1029 | struct nv50_wndw_atom *asyw; |
| 1030 | |
| 1031 | if (WARN_ON(!(asyw = kzalloc(sizeof(*asyw), GFP_KERNEL)))) |
| 1032 | return; |
| 1033 | |
| 1034 | if (plane->state) |
| 1035 | plane->funcs->atomic_destroy_state(plane, plane->state); |
| 1036 | plane->state = &asyw->state; |
| 1037 | plane->state->plane = plane; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 1038 | plane->state->rotation = DRM_MODE_ROTATE_0; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | static void |
| 1042 | nv50_wndw_destroy(struct drm_plane *plane) |
| 1043 | { |
| 1044 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 1045 | void *data; |
| 1046 | nvif_notify_fini(&wndw->notify); |
| 1047 | data = wndw->func->dtor(wndw); |
| 1048 | drm_plane_cleanup(&wndw->plane); |
| 1049 | kfree(data); |
| 1050 | } |
| 1051 | |
| 1052 | static const struct drm_plane_funcs |
| 1053 | nv50_wndw = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1054 | .update_plane = drm_atomic_helper_update_plane, |
| 1055 | .disable_plane = drm_atomic_helper_disable_plane, |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1056 | .destroy = nv50_wndw_destroy, |
| 1057 | .reset = nv50_wndw_reset, |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1058 | .atomic_duplicate_state = nv50_wndw_atomic_duplicate_state, |
| 1059 | .atomic_destroy_state = nv50_wndw_atomic_destroy_state, |
| 1060 | }; |
| 1061 | |
| 1062 | static void |
| 1063 | nv50_wndw_fini(struct nv50_wndw *wndw) |
| 1064 | { |
| 1065 | nvif_notify_put(&wndw->notify); |
| 1066 | } |
| 1067 | |
| 1068 | static void |
| 1069 | nv50_wndw_init(struct nv50_wndw *wndw) |
| 1070 | { |
| 1071 | nvif_notify_get(&wndw->notify); |
| 1072 | } |
| 1073 | |
| 1074 | static int |
| 1075 | nv50_wndw_ctor(const struct nv50_wndw_func *func, struct drm_device *dev, |
| 1076 | enum drm_plane_type type, const char *name, int index, |
| 1077 | struct nv50_dmac *dmac, const u32 *format, int nformat, |
| 1078 | struct nv50_wndw *wndw) |
| 1079 | { |
| 1080 | int ret; |
| 1081 | |
| 1082 | wndw->func = func; |
| 1083 | wndw->dmac = dmac; |
| 1084 | |
Ben Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame] | 1085 | ret = drm_universal_plane_init(dev, &wndw->plane, 0, &nv50_wndw, |
| 1086 | format, nformat, NULL, |
| 1087 | type, "%s-%d", name, index); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1088 | if (ret) |
| 1089 | return ret; |
| 1090 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1091 | drm_plane_helper_add(&wndw->plane, &nv50_wndw_helper); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | /****************************************************************************** |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1096 | * Cursor plane |
| 1097 | *****************************************************************************/ |
| 1098 | #define nv50_curs(p) container_of((p), struct nv50_curs, wndw) |
| 1099 | |
| 1100 | struct nv50_curs { |
| 1101 | struct nv50_wndw wndw; |
| 1102 | struct nvif_object chan; |
| 1103 | }; |
| 1104 | |
| 1105 | static u32 |
| 1106 | nv50_curs_update(struct nv50_wndw *wndw, u32 interlock) |
| 1107 | { |
| 1108 | struct nv50_curs *curs = nv50_curs(wndw); |
| 1109 | nvif_wr32(&curs->chan, 0x0080, 0x00000000); |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
| 1113 | static void |
| 1114 | nv50_curs_point(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1115 | { |
| 1116 | struct nv50_curs *curs = nv50_curs(wndw); |
| 1117 | nvif_wr32(&curs->chan, 0x0084, (asyw->point.y << 16) | asyw->point.x); |
| 1118 | } |
| 1119 | |
| 1120 | static void |
| 1121 | nv50_curs_prepare(struct nv50_wndw *wndw, struct nv50_head_atom *asyh, |
| 1122 | struct nv50_wndw_atom *asyw) |
| 1123 | { |
Ben Skeggs | e6db957 | 2017-05-01 16:53:40 +1000 | [diff] [blame] | 1124 | u32 handle = nv50_disp(wndw->plane.dev)->mast.base.vram.handle; |
| 1125 | u32 offset = asyw->image.offset; |
| 1126 | if (asyh->curs.handle != handle || asyh->curs.offset != offset) { |
| 1127 | asyh->curs.handle = handle; |
| 1128 | asyh->curs.offset = offset; |
| 1129 | asyh->set.curs = asyh->curs.visible; |
| 1130 | } |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | static void |
| 1134 | nv50_curs_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, |
| 1135 | struct nv50_head_atom *asyh) |
| 1136 | { |
| 1137 | asyh->curs.visible = false; |
| 1138 | } |
| 1139 | |
| 1140 | static int |
| 1141 | nv50_curs_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, |
| 1142 | struct nv50_head_atom *asyh) |
| 1143 | { |
| 1144 | int ret; |
| 1145 | |
| 1146 | ret = drm_plane_helper_check_state(&asyw->state, &asyw->clip, |
| 1147 | DRM_PLANE_HELPER_NO_SCALING, |
| 1148 | DRM_PLANE_HELPER_NO_SCALING, |
| 1149 | true, true); |
| 1150 | asyh->curs.visible = asyw->state.visible; |
| 1151 | if (ret || !asyh->curs.visible) |
| 1152 | return ret; |
| 1153 | |
| 1154 | switch (asyw->state.fb->width) { |
| 1155 | case 32: asyh->curs.layout = 0; break; |
| 1156 | case 64: asyh->curs.layout = 1; break; |
| 1157 | default: |
| 1158 | return -EINVAL; |
| 1159 | } |
| 1160 | |
| 1161 | if (asyw->state.fb->width != asyw->state.fb->height) |
| 1162 | return -EINVAL; |
| 1163 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 1164 | switch (asyw->state.fb->format->format) { |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1165 | case DRM_FORMAT_ARGB8888: asyh->curs.format = 1; break; |
| 1166 | default: |
| 1167 | WARN_ON(1); |
| 1168 | return -EINVAL; |
| 1169 | } |
| 1170 | |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
| 1174 | static void * |
| 1175 | nv50_curs_dtor(struct nv50_wndw *wndw) |
| 1176 | { |
| 1177 | struct nv50_curs *curs = nv50_curs(wndw); |
| 1178 | nvif_object_fini(&curs->chan); |
| 1179 | return curs; |
| 1180 | } |
| 1181 | |
| 1182 | static const u32 |
| 1183 | nv50_curs_format[] = { |
| 1184 | DRM_FORMAT_ARGB8888, |
| 1185 | }; |
| 1186 | |
| 1187 | static const struct nv50_wndw_func |
| 1188 | nv50_curs = { |
| 1189 | .dtor = nv50_curs_dtor, |
| 1190 | .acquire = nv50_curs_acquire, |
| 1191 | .release = nv50_curs_release, |
| 1192 | .prepare = nv50_curs_prepare, |
| 1193 | .point = nv50_curs_point, |
| 1194 | .update = nv50_curs_update, |
| 1195 | }; |
| 1196 | |
| 1197 | static int |
| 1198 | nv50_curs_new(struct nouveau_drm *drm, struct nv50_head *head, |
| 1199 | struct nv50_curs **pcurs) |
| 1200 | { |
| 1201 | static const struct nvif_mclass curses[] = { |
| 1202 | { GK104_DISP_CURSOR, 0 }, |
| 1203 | { GF110_DISP_CURSOR, 0 }, |
| 1204 | { GT214_DISP_CURSOR, 0 }, |
| 1205 | { G82_DISP_CURSOR, 0 }, |
| 1206 | { NV50_DISP_CURSOR, 0 }, |
| 1207 | {} |
| 1208 | }; |
| 1209 | struct nv50_disp_cursor_v0 args = { |
| 1210 | .head = head->base.index, |
| 1211 | }; |
| 1212 | struct nv50_disp *disp = nv50_disp(drm->dev); |
| 1213 | struct nv50_curs *curs; |
| 1214 | int cid, ret; |
| 1215 | |
| 1216 | cid = nvif_mclass(disp->disp, curses); |
| 1217 | if (cid < 0) { |
| 1218 | NV_ERROR(drm, "No supported cursor immediate class\n"); |
| 1219 | return cid; |
| 1220 | } |
| 1221 | |
| 1222 | if (!(curs = *pcurs = kzalloc(sizeof(*curs), GFP_KERNEL))) |
| 1223 | return -ENOMEM; |
| 1224 | |
| 1225 | ret = nv50_wndw_ctor(&nv50_curs, drm->dev, DRM_PLANE_TYPE_CURSOR, |
| 1226 | "curs", head->base.index, &disp->mast.base, |
| 1227 | nv50_curs_format, ARRAY_SIZE(nv50_curs_format), |
| 1228 | &curs->wndw); |
| 1229 | if (ret) { |
| 1230 | kfree(curs); |
| 1231 | return ret; |
| 1232 | } |
| 1233 | |
| 1234 | ret = nvif_object_init(disp->disp, 0, curses[cid].oclass, &args, |
| 1235 | sizeof(args), &curs->chan); |
| 1236 | if (ret) { |
| 1237 | NV_ERROR(drm, "curs%04x allocation failed: %d\n", |
| 1238 | curses[cid].oclass, ret); |
| 1239 | return ret; |
| 1240 | } |
| 1241 | |
| 1242 | return 0; |
| 1243 | } |
| 1244 | |
| 1245 | /****************************************************************************** |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1246 | * Primary plane |
| 1247 | *****************************************************************************/ |
| 1248 | #define nv50_base(p) container_of((p), struct nv50_base, wndw) |
| 1249 | |
| 1250 | struct nv50_base { |
| 1251 | struct nv50_wndw wndw; |
| 1252 | struct nv50_sync chan; |
| 1253 | int id; |
| 1254 | }; |
| 1255 | |
| 1256 | static int |
| 1257 | nv50_base_notify(struct nvif_notify *notify) |
| 1258 | { |
| 1259 | return NVIF_NOTIFY_KEEP; |
| 1260 | } |
| 1261 | |
| 1262 | static void |
| 1263 | nv50_base_lut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1264 | { |
| 1265 | struct nv50_base *base = nv50_base(wndw); |
| 1266 | u32 *push; |
| 1267 | if ((push = evo_wait(&base->chan, 2))) { |
| 1268 | evo_mthd(push, 0x00e0, 1); |
| 1269 | evo_data(push, asyw->lut.enable << 30); |
| 1270 | evo_kick(push, &base->chan); |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | static void |
| 1275 | nv50_base_image_clr(struct nv50_wndw *wndw) |
| 1276 | { |
| 1277 | struct nv50_base *base = nv50_base(wndw); |
| 1278 | u32 *push; |
| 1279 | if ((push = evo_wait(&base->chan, 4))) { |
| 1280 | evo_mthd(push, 0x0084, 1); |
| 1281 | evo_data(push, 0x00000000); |
| 1282 | evo_mthd(push, 0x00c0, 1); |
| 1283 | evo_data(push, 0x00000000); |
| 1284 | evo_kick(push, &base->chan); |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | static void |
| 1289 | nv50_base_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1290 | { |
| 1291 | struct nv50_base *base = nv50_base(wndw); |
| 1292 | const s32 oclass = base->chan.base.base.user.oclass; |
| 1293 | u32 *push; |
| 1294 | if ((push = evo_wait(&base->chan, 10))) { |
| 1295 | evo_mthd(push, 0x0084, 1); |
| 1296 | evo_data(push, (asyw->image.mode << 8) | |
| 1297 | (asyw->image.interval << 4)); |
| 1298 | evo_mthd(push, 0x00c0, 1); |
| 1299 | evo_data(push, asyw->image.handle); |
| 1300 | if (oclass < G82_DISP_BASE_CHANNEL_DMA) { |
| 1301 | evo_mthd(push, 0x0800, 5); |
| 1302 | evo_data(push, asyw->image.offset >> 8); |
| 1303 | evo_data(push, 0x00000000); |
| 1304 | evo_data(push, (asyw->image.h << 16) | asyw->image.w); |
| 1305 | evo_data(push, (asyw->image.layout << 20) | |
| 1306 | asyw->image.pitch | |
| 1307 | asyw->image.block); |
| 1308 | evo_data(push, (asyw->image.kind << 16) | |
| 1309 | (asyw->image.format << 8)); |
| 1310 | } else |
| 1311 | if (oclass < GF110_DISP_BASE_CHANNEL_DMA) { |
| 1312 | evo_mthd(push, 0x0800, 5); |
| 1313 | evo_data(push, asyw->image.offset >> 8); |
| 1314 | evo_data(push, 0x00000000); |
| 1315 | evo_data(push, (asyw->image.h << 16) | asyw->image.w); |
| 1316 | evo_data(push, (asyw->image.layout << 20) | |
| 1317 | asyw->image.pitch | |
| 1318 | asyw->image.block); |
| 1319 | evo_data(push, asyw->image.format << 8); |
| 1320 | } else { |
| 1321 | evo_mthd(push, 0x0400, 5); |
| 1322 | evo_data(push, asyw->image.offset >> 8); |
| 1323 | evo_data(push, 0x00000000); |
| 1324 | evo_data(push, (asyw->image.h << 16) | asyw->image.w); |
| 1325 | evo_data(push, (asyw->image.layout << 24) | |
| 1326 | asyw->image.pitch | |
| 1327 | asyw->image.block); |
| 1328 | evo_data(push, asyw->image.format << 8); |
| 1329 | } |
| 1330 | evo_kick(push, &base->chan); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | static void |
| 1335 | nv50_base_ntfy_clr(struct nv50_wndw *wndw) |
| 1336 | { |
| 1337 | struct nv50_base *base = nv50_base(wndw); |
| 1338 | u32 *push; |
| 1339 | if ((push = evo_wait(&base->chan, 2))) { |
| 1340 | evo_mthd(push, 0x00a4, 1); |
| 1341 | evo_data(push, 0x00000000); |
| 1342 | evo_kick(push, &base->chan); |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | static void |
| 1347 | nv50_base_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1348 | { |
| 1349 | struct nv50_base *base = nv50_base(wndw); |
| 1350 | u32 *push; |
| 1351 | if ((push = evo_wait(&base->chan, 3))) { |
| 1352 | evo_mthd(push, 0x00a0, 2); |
| 1353 | evo_data(push, (asyw->ntfy.awaken << 30) | asyw->ntfy.offset); |
| 1354 | evo_data(push, asyw->ntfy.handle); |
| 1355 | evo_kick(push, &base->chan); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | static void |
| 1360 | nv50_base_sema_clr(struct nv50_wndw *wndw) |
| 1361 | { |
| 1362 | struct nv50_base *base = nv50_base(wndw); |
| 1363 | u32 *push; |
| 1364 | if ((push = evo_wait(&base->chan, 2))) { |
| 1365 | evo_mthd(push, 0x0094, 1); |
| 1366 | evo_data(push, 0x00000000); |
| 1367 | evo_kick(push, &base->chan); |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | static void |
| 1372 | nv50_base_sema_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1373 | { |
| 1374 | struct nv50_base *base = nv50_base(wndw); |
| 1375 | u32 *push; |
| 1376 | if ((push = evo_wait(&base->chan, 5))) { |
| 1377 | evo_mthd(push, 0x0088, 4); |
| 1378 | evo_data(push, asyw->sema.offset); |
| 1379 | evo_data(push, asyw->sema.acquire); |
| 1380 | evo_data(push, asyw->sema.release); |
| 1381 | evo_data(push, asyw->sema.handle); |
| 1382 | evo_kick(push, &base->chan); |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | static u32 |
| 1387 | nv50_base_update(struct nv50_wndw *wndw, u32 interlock) |
| 1388 | { |
| 1389 | struct nv50_base *base = nv50_base(wndw); |
| 1390 | u32 *push; |
| 1391 | |
| 1392 | if (!(push = evo_wait(&base->chan, 2))) |
| 1393 | return 0; |
| 1394 | evo_mthd(push, 0x0080, 1); |
| 1395 | evo_data(push, interlock); |
| 1396 | evo_kick(push, &base->chan); |
| 1397 | |
| 1398 | if (base->chan.base.base.user.oclass < GF110_DISP_BASE_CHANNEL_DMA) |
| 1399 | return interlock ? 2 << (base->id * 8) : 0; |
| 1400 | return interlock ? 2 << (base->id * 4) : 0; |
| 1401 | } |
| 1402 | |
| 1403 | static int |
| 1404 | nv50_base_ntfy_wait_begun(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1405 | { |
| 1406 | struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev); |
| 1407 | struct nv50_disp *disp = nv50_disp(wndw->plane.dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 1408 | if (nvif_msec(&drm->client.device, 2000ULL, |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1409 | u32 data = nouveau_bo_rd32(disp->sync, asyw->ntfy.offset / 4); |
| 1410 | if ((data & 0xc0000000) == 0x40000000) |
| 1411 | break; |
| 1412 | usleep_range(1, 2); |
| 1413 | ) < 0) |
| 1414 | return -ETIMEDOUT; |
| 1415 | return 0; |
| 1416 | } |
| 1417 | |
| 1418 | static void |
| 1419 | nv50_base_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, |
| 1420 | struct nv50_head_atom *asyh) |
| 1421 | { |
| 1422 | asyh->base.cpp = 0; |
| 1423 | } |
| 1424 | |
| 1425 | static int |
| 1426 | nv50_base_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, |
| 1427 | struct nv50_head_atom *asyh) |
| 1428 | { |
Ville Syrjälä | 9857ecb | 2016-11-18 21:53:03 +0200 | [diff] [blame] | 1429 | const struct drm_framebuffer *fb = asyw->state.fb; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1430 | int ret; |
| 1431 | |
Ville Syrjälä | 9857ecb | 2016-11-18 21:53:03 +0200 | [diff] [blame] | 1432 | if (!fb->format->depth) |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1433 | return -EINVAL; |
| 1434 | |
| 1435 | ret = drm_plane_helper_check_state(&asyw->state, &asyw->clip, |
| 1436 | DRM_PLANE_HELPER_NO_SCALING, |
| 1437 | DRM_PLANE_HELPER_NO_SCALING, |
| 1438 | false, true); |
| 1439 | if (ret) |
| 1440 | return ret; |
| 1441 | |
Ville Syrjälä | 9857ecb | 2016-11-18 21:53:03 +0200 | [diff] [blame] | 1442 | asyh->base.depth = fb->format->depth; |
| 1443 | asyh->base.cpp = fb->format->cpp[0]; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1444 | asyh->base.x = asyw->state.src.x1 >> 16; |
| 1445 | asyh->base.y = asyw->state.src.y1 >> 16; |
| 1446 | asyh->base.w = asyw->state.fb->width; |
| 1447 | asyh->base.h = asyw->state.fb->height; |
| 1448 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 1449 | switch (fb->format->format) { |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1450 | case DRM_FORMAT_C8 : asyw->image.format = 0x1e; break; |
| 1451 | case DRM_FORMAT_RGB565 : asyw->image.format = 0xe8; break; |
| 1452 | case DRM_FORMAT_XRGB1555 : |
| 1453 | case DRM_FORMAT_ARGB1555 : asyw->image.format = 0xe9; break; |
| 1454 | case DRM_FORMAT_XRGB8888 : |
| 1455 | case DRM_FORMAT_ARGB8888 : asyw->image.format = 0xcf; break; |
| 1456 | case DRM_FORMAT_XBGR2101010: |
| 1457 | case DRM_FORMAT_ABGR2101010: asyw->image.format = 0xd1; break; |
| 1458 | case DRM_FORMAT_XBGR8888 : |
| 1459 | case DRM_FORMAT_ABGR8888 : asyw->image.format = 0xd5; break; |
| 1460 | default: |
| 1461 | WARN_ON(1); |
| 1462 | return -EINVAL; |
| 1463 | } |
| 1464 | |
| 1465 | asyw->lut.enable = 1; |
| 1466 | asyw->set.image = true; |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
| 1470 | static void * |
| 1471 | nv50_base_dtor(struct nv50_wndw *wndw) |
| 1472 | { |
| 1473 | struct nv50_disp *disp = nv50_disp(wndw->plane.dev); |
| 1474 | struct nv50_base *base = nv50_base(wndw); |
| 1475 | nv50_dmac_destroy(&base->chan.base, disp->disp); |
| 1476 | return base; |
| 1477 | } |
| 1478 | |
| 1479 | static const u32 |
| 1480 | nv50_base_format[] = { |
| 1481 | DRM_FORMAT_C8, |
| 1482 | DRM_FORMAT_RGB565, |
| 1483 | DRM_FORMAT_XRGB1555, |
| 1484 | DRM_FORMAT_ARGB1555, |
| 1485 | DRM_FORMAT_XRGB8888, |
| 1486 | DRM_FORMAT_ARGB8888, |
| 1487 | DRM_FORMAT_XBGR2101010, |
| 1488 | DRM_FORMAT_ABGR2101010, |
| 1489 | DRM_FORMAT_XBGR8888, |
| 1490 | DRM_FORMAT_ABGR8888, |
| 1491 | }; |
| 1492 | |
| 1493 | static const struct nv50_wndw_func |
| 1494 | nv50_base = { |
| 1495 | .dtor = nv50_base_dtor, |
| 1496 | .acquire = nv50_base_acquire, |
| 1497 | .release = nv50_base_release, |
| 1498 | .sema_set = nv50_base_sema_set, |
| 1499 | .sema_clr = nv50_base_sema_clr, |
| 1500 | .ntfy_set = nv50_base_ntfy_set, |
| 1501 | .ntfy_clr = nv50_base_ntfy_clr, |
| 1502 | .ntfy_wait_begun = nv50_base_ntfy_wait_begun, |
| 1503 | .image_set = nv50_base_image_set, |
| 1504 | .image_clr = nv50_base_image_clr, |
| 1505 | .lut = nv50_base_lut, |
| 1506 | .update = nv50_base_update, |
| 1507 | }; |
| 1508 | |
| 1509 | static int |
| 1510 | nv50_base_new(struct nouveau_drm *drm, struct nv50_head *head, |
| 1511 | struct nv50_base **pbase) |
| 1512 | { |
| 1513 | struct nv50_disp *disp = nv50_disp(drm->dev); |
| 1514 | struct nv50_base *base; |
| 1515 | int ret; |
| 1516 | |
| 1517 | if (!(base = *pbase = kzalloc(sizeof(*base), GFP_KERNEL))) |
| 1518 | return -ENOMEM; |
| 1519 | base->id = head->base.index; |
| 1520 | base->wndw.ntfy = EVO_FLIP_NTFY0(base->id); |
| 1521 | base->wndw.sema = EVO_FLIP_SEM0(base->id); |
| 1522 | base->wndw.data = 0x00000000; |
| 1523 | |
| 1524 | ret = nv50_wndw_ctor(&nv50_base, drm->dev, DRM_PLANE_TYPE_PRIMARY, |
| 1525 | "base", base->id, &base->chan.base, |
| 1526 | nv50_base_format, ARRAY_SIZE(nv50_base_format), |
| 1527 | &base->wndw); |
| 1528 | if (ret) { |
| 1529 | kfree(base); |
| 1530 | return ret; |
| 1531 | } |
| 1532 | |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 1533 | ret = nv50_base_create(&drm->client.device, disp->disp, base->id, |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1534 | disp->sync->bo.offset, &base->chan); |
| 1535 | if (ret) |
| 1536 | return ret; |
| 1537 | |
| 1538 | return nvif_notify_init(&base->chan.base.base.user, nv50_base_notify, |
| 1539 | false, |
| 1540 | NV50_DISP_BASE_CHANNEL_DMA_V0_NTFY_UEVENT, |
| 1541 | &(struct nvif_notify_uevent_req) {}, |
| 1542 | sizeof(struct nvif_notify_uevent_req), |
| 1543 | sizeof(struct nvif_notify_uevent_rep), |
| 1544 | &base->wndw.notify); |
| 1545 | } |
| 1546 | |
| 1547 | /****************************************************************************** |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1548 | * Head |
| 1549 | *****************************************************************************/ |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1550 | static void |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1551 | nv50_head_procamp(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1552 | { |
| 1553 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1554 | u32 *push; |
| 1555 | if ((push = evo_wait(core, 2))) { |
| 1556 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) |
| 1557 | evo_mthd(push, 0x08a8 + (head->base.index * 0x400), 1); |
| 1558 | else |
| 1559 | evo_mthd(push, 0x0498 + (head->base.index * 0x300), 1); |
| 1560 | evo_data(push, (asyh->procamp.sat.sin << 20) | |
| 1561 | (asyh->procamp.sat.cos << 8)); |
| 1562 | evo_kick(push, core); |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | static void |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1567 | nv50_head_dither(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1568 | { |
| 1569 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1570 | u32 *push; |
| 1571 | if ((push = evo_wait(core, 2))) { |
| 1572 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) |
| 1573 | evo_mthd(push, 0x08a0 + (head->base.index * 0x0400), 1); |
| 1574 | else |
| 1575 | if (core->base.user.oclass < GK104_DISP_CORE_CHANNEL_DMA) |
| 1576 | evo_mthd(push, 0x0490 + (head->base.index * 0x0300), 1); |
| 1577 | else |
| 1578 | evo_mthd(push, 0x04a0 + (head->base.index * 0x0300), 1); |
| 1579 | evo_data(push, (asyh->dither.mode << 3) | |
| 1580 | (asyh->dither.bits << 1) | |
| 1581 | asyh->dither.enable); |
| 1582 | evo_kick(push, core); |
| 1583 | } |
| 1584 | } |
| 1585 | |
| 1586 | static void |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1587 | nv50_head_ovly(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1588 | { |
| 1589 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1590 | u32 bounds = 0; |
| 1591 | u32 *push; |
| 1592 | |
| 1593 | if (asyh->base.cpp) { |
| 1594 | switch (asyh->base.cpp) { |
| 1595 | case 8: bounds |= 0x00000500; break; |
| 1596 | case 4: bounds |= 0x00000300; break; |
| 1597 | case 2: bounds |= 0x00000100; break; |
| 1598 | default: |
| 1599 | WARN_ON(1); |
| 1600 | break; |
| 1601 | } |
| 1602 | bounds |= 0x00000001; |
| 1603 | } |
| 1604 | |
| 1605 | if ((push = evo_wait(core, 2))) { |
| 1606 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) |
| 1607 | evo_mthd(push, 0x0904 + head->base.index * 0x400, 1); |
| 1608 | else |
| 1609 | evo_mthd(push, 0x04d4 + head->base.index * 0x300, 1); |
| 1610 | evo_data(push, bounds); |
| 1611 | evo_kick(push, core); |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | static void |
| 1616 | nv50_head_base(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1617 | { |
| 1618 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1619 | u32 bounds = 0; |
| 1620 | u32 *push; |
| 1621 | |
| 1622 | if (asyh->base.cpp) { |
| 1623 | switch (asyh->base.cpp) { |
| 1624 | case 8: bounds |= 0x00000500; break; |
| 1625 | case 4: bounds |= 0x00000300; break; |
| 1626 | case 2: bounds |= 0x00000100; break; |
| 1627 | case 1: bounds |= 0x00000000; break; |
| 1628 | default: |
| 1629 | WARN_ON(1); |
| 1630 | break; |
| 1631 | } |
| 1632 | bounds |= 0x00000001; |
| 1633 | } |
| 1634 | |
| 1635 | if ((push = evo_wait(core, 2))) { |
| 1636 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) |
| 1637 | evo_mthd(push, 0x0900 + head->base.index * 0x400, 1); |
| 1638 | else |
| 1639 | evo_mthd(push, 0x04d0 + head->base.index * 0x300, 1); |
| 1640 | evo_data(push, bounds); |
| 1641 | evo_kick(push, core); |
| 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | static void |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1646 | nv50_head_curs_clr(struct nv50_head *head) |
| 1647 | { |
| 1648 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1649 | u32 *push; |
| 1650 | if ((push = evo_wait(core, 4))) { |
| 1651 | if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) { |
| 1652 | evo_mthd(push, 0x0880 + head->base.index * 0x400, 1); |
| 1653 | evo_data(push, 0x05000000); |
| 1654 | } else |
| 1655 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1656 | evo_mthd(push, 0x0880 + head->base.index * 0x400, 1); |
| 1657 | evo_data(push, 0x05000000); |
| 1658 | evo_mthd(push, 0x089c + head->base.index * 0x400, 1); |
| 1659 | evo_data(push, 0x00000000); |
| 1660 | } else { |
| 1661 | evo_mthd(push, 0x0480 + head->base.index * 0x300, 1); |
| 1662 | evo_data(push, 0x05000000); |
| 1663 | evo_mthd(push, 0x048c + head->base.index * 0x300, 1); |
| 1664 | evo_data(push, 0x00000000); |
| 1665 | } |
| 1666 | evo_kick(push, core); |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | static void |
| 1671 | nv50_head_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1672 | { |
| 1673 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1674 | u32 *push; |
| 1675 | if ((push = evo_wait(core, 5))) { |
| 1676 | if (core->base.user.oclass < G82_DISP_BASE_CHANNEL_DMA) { |
| 1677 | evo_mthd(push, 0x0880 + head->base.index * 0x400, 2); |
| 1678 | evo_data(push, 0x80000000 | (asyh->curs.layout << 26) | |
| 1679 | (asyh->curs.format << 24)); |
| 1680 | evo_data(push, asyh->curs.offset >> 8); |
| 1681 | } else |
| 1682 | if (core->base.user.oclass < GF110_DISP_BASE_CHANNEL_DMA) { |
| 1683 | evo_mthd(push, 0x0880 + head->base.index * 0x400, 2); |
| 1684 | evo_data(push, 0x80000000 | (asyh->curs.layout << 26) | |
| 1685 | (asyh->curs.format << 24)); |
| 1686 | evo_data(push, asyh->curs.offset >> 8); |
| 1687 | evo_mthd(push, 0x089c + head->base.index * 0x400, 1); |
| 1688 | evo_data(push, asyh->curs.handle); |
| 1689 | } else { |
| 1690 | evo_mthd(push, 0x0480 + head->base.index * 0x300, 2); |
| 1691 | evo_data(push, 0x80000000 | (asyh->curs.layout << 26) | |
| 1692 | (asyh->curs.format << 24)); |
| 1693 | evo_data(push, asyh->curs.offset >> 8); |
| 1694 | evo_mthd(push, 0x048c + head->base.index * 0x300, 1); |
| 1695 | evo_data(push, asyh->curs.handle); |
| 1696 | } |
| 1697 | evo_kick(push, core); |
| 1698 | } |
| 1699 | } |
| 1700 | |
| 1701 | static void |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1702 | nv50_head_core_clr(struct nv50_head *head) |
| 1703 | { |
| 1704 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1705 | u32 *push; |
| 1706 | if ((push = evo_wait(core, 2))) { |
| 1707 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) |
| 1708 | evo_mthd(push, 0x0874 + head->base.index * 0x400, 1); |
| 1709 | else |
| 1710 | evo_mthd(push, 0x0474 + head->base.index * 0x300, 1); |
| 1711 | evo_data(push, 0x00000000); |
| 1712 | evo_kick(push, core); |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | static void |
| 1717 | nv50_head_core_set(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1718 | { |
| 1719 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1720 | u32 *push; |
| 1721 | if ((push = evo_wait(core, 9))) { |
| 1722 | if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) { |
| 1723 | evo_mthd(push, 0x0860 + head->base.index * 0x400, 1); |
| 1724 | evo_data(push, asyh->core.offset >> 8); |
| 1725 | evo_mthd(push, 0x0868 + head->base.index * 0x400, 4); |
| 1726 | evo_data(push, (asyh->core.h << 16) | asyh->core.w); |
| 1727 | evo_data(push, asyh->core.layout << 20 | |
| 1728 | (asyh->core.pitch >> 8) << 8 | |
| 1729 | asyh->core.block); |
| 1730 | evo_data(push, asyh->core.kind << 16 | |
| 1731 | asyh->core.format << 8); |
| 1732 | evo_data(push, asyh->core.handle); |
| 1733 | evo_mthd(push, 0x08c0 + head->base.index * 0x400, 1); |
| 1734 | evo_data(push, (asyh->core.y << 16) | asyh->core.x); |
Ben Skeggs | 19d53d0 | 2016-12-13 11:18:46 +1000 | [diff] [blame] | 1735 | /* EVO will complain with INVALID_STATE if we have an |
| 1736 | * active cursor and (re)specify HeadSetContextDmaIso |
| 1737 | * without also updating HeadSetOffsetCursor. |
| 1738 | */ |
| 1739 | asyh->set.curs = asyh->curs.visible; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1740 | } else |
| 1741 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1742 | evo_mthd(push, 0x0860 + head->base.index * 0x400, 1); |
| 1743 | evo_data(push, asyh->core.offset >> 8); |
| 1744 | evo_mthd(push, 0x0868 + head->base.index * 0x400, 4); |
| 1745 | evo_data(push, (asyh->core.h << 16) | asyh->core.w); |
| 1746 | evo_data(push, asyh->core.layout << 20 | |
| 1747 | (asyh->core.pitch >> 8) << 8 | |
| 1748 | asyh->core.block); |
| 1749 | evo_data(push, asyh->core.format << 8); |
| 1750 | evo_data(push, asyh->core.handle); |
| 1751 | evo_mthd(push, 0x08c0 + head->base.index * 0x400, 1); |
| 1752 | evo_data(push, (asyh->core.y << 16) | asyh->core.x); |
| 1753 | } else { |
| 1754 | evo_mthd(push, 0x0460 + head->base.index * 0x300, 1); |
| 1755 | evo_data(push, asyh->core.offset >> 8); |
| 1756 | evo_mthd(push, 0x0468 + head->base.index * 0x300, 4); |
| 1757 | evo_data(push, (asyh->core.h << 16) | asyh->core.w); |
| 1758 | evo_data(push, asyh->core.layout << 24 | |
| 1759 | (asyh->core.pitch >> 8) << 8 | |
| 1760 | asyh->core.block); |
| 1761 | evo_data(push, asyh->core.format << 8); |
| 1762 | evo_data(push, asyh->core.handle); |
| 1763 | evo_mthd(push, 0x04b0 + head->base.index * 0x300, 1); |
| 1764 | evo_data(push, (asyh->core.y << 16) | asyh->core.x); |
| 1765 | } |
| 1766 | evo_kick(push, core); |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | static void |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1771 | nv50_head_lut_clr(struct nv50_head *head) |
| 1772 | { |
| 1773 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1774 | u32 *push; |
| 1775 | if ((push = evo_wait(core, 4))) { |
| 1776 | if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) { |
| 1777 | evo_mthd(push, 0x0840 + (head->base.index * 0x400), 1); |
| 1778 | evo_data(push, 0x40000000); |
| 1779 | } else |
| 1780 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1781 | evo_mthd(push, 0x0840 + (head->base.index * 0x400), 1); |
| 1782 | evo_data(push, 0x40000000); |
| 1783 | evo_mthd(push, 0x085c + (head->base.index * 0x400), 1); |
| 1784 | evo_data(push, 0x00000000); |
| 1785 | } else { |
| 1786 | evo_mthd(push, 0x0440 + (head->base.index * 0x300), 1); |
| 1787 | evo_data(push, 0x03000000); |
| 1788 | evo_mthd(push, 0x045c + (head->base.index * 0x300), 1); |
| 1789 | evo_data(push, 0x00000000); |
| 1790 | } |
| 1791 | evo_kick(push, core); |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | static void |
| 1796 | nv50_head_lut_set(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1797 | { |
| 1798 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1799 | u32 *push; |
| 1800 | if ((push = evo_wait(core, 7))) { |
| 1801 | if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) { |
| 1802 | evo_mthd(push, 0x0840 + (head->base.index * 0x400), 2); |
| 1803 | evo_data(push, 0xc0000000); |
| 1804 | evo_data(push, asyh->lut.offset >> 8); |
| 1805 | } else |
| 1806 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1807 | evo_mthd(push, 0x0840 + (head->base.index * 0x400), 2); |
| 1808 | evo_data(push, 0xc0000000); |
| 1809 | evo_data(push, asyh->lut.offset >> 8); |
| 1810 | evo_mthd(push, 0x085c + (head->base.index * 0x400), 1); |
| 1811 | evo_data(push, asyh->lut.handle); |
| 1812 | } else { |
| 1813 | evo_mthd(push, 0x0440 + (head->base.index * 0x300), 4); |
| 1814 | evo_data(push, 0x83000000); |
| 1815 | evo_data(push, asyh->lut.offset >> 8); |
| 1816 | evo_data(push, 0x00000000); |
| 1817 | evo_data(push, 0x00000000); |
| 1818 | evo_mthd(push, 0x045c + (head->base.index * 0x300), 1); |
| 1819 | evo_data(push, asyh->lut.handle); |
| 1820 | } |
| 1821 | evo_kick(push, core); |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | static void |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1826 | nv50_head_mode(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1827 | { |
| 1828 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1829 | struct nv50_head_mode *m = &asyh->mode; |
| 1830 | u32 *push; |
| 1831 | if ((push = evo_wait(core, 14))) { |
| 1832 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1833 | evo_mthd(push, 0x0804 + (head->base.index * 0x400), 2); |
| 1834 | evo_data(push, 0x00800000 | m->clock); |
| 1835 | evo_data(push, m->interlace ? 0x00000002 : 0x00000000); |
Ben Skeggs | 06ab282 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1836 | evo_mthd(push, 0x0810 + (head->base.index * 0x400), 7); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1837 | evo_data(push, 0x00000000); |
| 1838 | evo_data(push, (m->v.active << 16) | m->h.active ); |
| 1839 | evo_data(push, (m->v.synce << 16) | m->h.synce ); |
| 1840 | evo_data(push, (m->v.blanke << 16) | m->h.blanke ); |
| 1841 | evo_data(push, (m->v.blanks << 16) | m->h.blanks ); |
| 1842 | evo_data(push, (m->v.blank2e << 16) | m->v.blank2s); |
Ben Skeggs | 06ab282 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1843 | evo_data(push, asyh->mode.v.blankus); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1844 | evo_mthd(push, 0x082c + (head->base.index * 0x400), 1); |
| 1845 | evo_data(push, 0x00000000); |
| 1846 | } else { |
| 1847 | evo_mthd(push, 0x0410 + (head->base.index * 0x300), 6); |
| 1848 | evo_data(push, 0x00000000); |
| 1849 | evo_data(push, (m->v.active << 16) | m->h.active ); |
| 1850 | evo_data(push, (m->v.synce << 16) | m->h.synce ); |
| 1851 | evo_data(push, (m->v.blanke << 16) | m->h.blanke ); |
| 1852 | evo_data(push, (m->v.blanks << 16) | m->h.blanks ); |
| 1853 | evo_data(push, (m->v.blank2e << 16) | m->v.blank2s); |
| 1854 | evo_mthd(push, 0x042c + (head->base.index * 0x300), 2); |
| 1855 | evo_data(push, 0x00000000); /* ??? */ |
| 1856 | evo_data(push, 0xffffff00); |
| 1857 | evo_mthd(push, 0x0450 + (head->base.index * 0x300), 3); |
| 1858 | evo_data(push, m->clock * 1000); |
| 1859 | evo_data(push, 0x00200000); /* ??? */ |
| 1860 | evo_data(push, m->clock * 1000); |
| 1861 | } |
| 1862 | evo_kick(push, core); |
| 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | static void |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1867 | nv50_head_view(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1868 | { |
| 1869 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1870 | u32 *push; |
| 1871 | if ((push = evo_wait(core, 10))) { |
| 1872 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1873 | evo_mthd(push, 0x08a4 + (head->base.index * 0x400), 1); |
| 1874 | evo_data(push, 0x00000000); |
| 1875 | evo_mthd(push, 0x08c8 + (head->base.index * 0x400), 1); |
| 1876 | evo_data(push, (asyh->view.iH << 16) | asyh->view.iW); |
| 1877 | evo_mthd(push, 0x08d8 + (head->base.index * 0x400), 2); |
| 1878 | evo_data(push, (asyh->view.oH << 16) | asyh->view.oW); |
| 1879 | evo_data(push, (asyh->view.oH << 16) | asyh->view.oW); |
| 1880 | } else { |
| 1881 | evo_mthd(push, 0x0494 + (head->base.index * 0x300), 1); |
| 1882 | evo_data(push, 0x00000000); |
| 1883 | evo_mthd(push, 0x04b8 + (head->base.index * 0x300), 1); |
| 1884 | evo_data(push, (asyh->view.iH << 16) | asyh->view.iW); |
| 1885 | evo_mthd(push, 0x04c0 + (head->base.index * 0x300), 3); |
| 1886 | evo_data(push, (asyh->view.oH << 16) | asyh->view.oW); |
| 1887 | evo_data(push, (asyh->view.oH << 16) | asyh->view.oW); |
| 1888 | evo_data(push, (asyh->view.oH << 16) | asyh->view.oW); |
| 1889 | } |
| 1890 | evo_kick(push, core); |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | static void |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1895 | nv50_head_flush_clr(struct nv50_head *head, struct nv50_head_atom *asyh, bool y) |
| 1896 | { |
| 1897 | if (asyh->clr.core && (!asyh->set.core || y)) |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1898 | nv50_head_lut_clr(head); |
| 1899 | if (asyh->clr.core && (!asyh->set.core || y)) |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1900 | nv50_head_core_clr(head); |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1901 | if (asyh->clr.curs && (!asyh->set.curs || y)) |
| 1902 | nv50_head_curs_clr(head); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | static void |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1906 | nv50_head_flush_set(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1907 | { |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1908 | if (asyh->set.view ) nv50_head_view (head, asyh); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1909 | if (asyh->set.mode ) nv50_head_mode (head, asyh); |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1910 | if (asyh->set.core ) nv50_head_lut_set (head, asyh); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1911 | if (asyh->set.core ) nv50_head_core_set(head, asyh); |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1912 | if (asyh->set.curs ) nv50_head_curs_set(head, asyh); |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1913 | if (asyh->set.base ) nv50_head_base (head, asyh); |
| 1914 | if (asyh->set.ovly ) nv50_head_ovly (head, asyh); |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1915 | if (asyh->set.dither ) nv50_head_dither (head, asyh); |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1916 | if (asyh->set.procamp) nv50_head_procamp (head, asyh); |
| 1917 | } |
| 1918 | |
| 1919 | static void |
| 1920 | nv50_head_atomic_check_procamp(struct nv50_head_atom *armh, |
| 1921 | struct nv50_head_atom *asyh, |
| 1922 | struct nouveau_conn_atom *asyc) |
| 1923 | { |
| 1924 | const int vib = asyc->procamp.color_vibrance - 100; |
| 1925 | const int hue = asyc->procamp.vibrant_hue - 90; |
| 1926 | const int adj = (vib > 0) ? 50 : 0; |
| 1927 | asyh->procamp.sat.cos = ((vib * 2047 + adj) / 100) & 0xfff; |
| 1928 | asyh->procamp.sat.sin = ((hue * 2047) / 100) & 0xfff; |
| 1929 | asyh->set.procamp = true; |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | static void |
| 1933 | nv50_head_atomic_check_dither(struct nv50_head_atom *armh, |
| 1934 | struct nv50_head_atom *asyh, |
| 1935 | struct nouveau_conn_atom *asyc) |
| 1936 | { |
| 1937 | struct drm_connector *connector = asyc->state.connector; |
| 1938 | u32 mode = 0x00; |
| 1939 | |
| 1940 | if (asyc->dither.mode == DITHERING_MODE_AUTO) { |
| 1941 | if (asyh->base.depth > connector->display_info.bpc * 3) |
| 1942 | mode = DITHERING_MODE_DYNAMIC2X2; |
| 1943 | } else { |
| 1944 | mode = asyc->dither.mode; |
| 1945 | } |
| 1946 | |
| 1947 | if (asyc->dither.depth == DITHERING_DEPTH_AUTO) { |
| 1948 | if (connector->display_info.bpc >= 8) |
| 1949 | mode |= DITHERING_DEPTH_8BPC; |
| 1950 | } else { |
| 1951 | mode |= asyc->dither.depth; |
| 1952 | } |
| 1953 | |
| 1954 | asyh->dither.enable = mode; |
| 1955 | asyh->dither.bits = mode >> 1; |
| 1956 | asyh->dither.mode = mode >> 3; |
| 1957 | asyh->set.dither = true; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | static void |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1961 | nv50_head_atomic_check_view(struct nv50_head_atom *armh, |
| 1962 | struct nv50_head_atom *asyh, |
| 1963 | struct nouveau_conn_atom *asyc) |
| 1964 | { |
| 1965 | struct drm_connector *connector = asyc->state.connector; |
| 1966 | struct drm_display_mode *omode = &asyh->state.adjusted_mode; |
| 1967 | struct drm_display_mode *umode = &asyh->state.mode; |
| 1968 | int mode = asyc->scaler.mode; |
| 1969 | struct edid *edid; |
Alastair Bridgewater | 37aa224 | 2017-04-11 13:11:24 -0400 | [diff] [blame] | 1970 | int umode_vdisplay, omode_hdisplay, omode_vdisplay; |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1971 | |
| 1972 | if (connector->edid_blob_ptr) |
| 1973 | edid = (struct edid *)connector->edid_blob_ptr->data; |
| 1974 | else |
| 1975 | edid = NULL; |
| 1976 | |
| 1977 | if (!asyc->scaler.full) { |
| 1978 | if (mode == DRM_MODE_SCALE_NONE) |
| 1979 | omode = umode; |
| 1980 | } else { |
| 1981 | /* Non-EDID LVDS/eDP mode. */ |
| 1982 | mode = DRM_MODE_SCALE_FULLSCREEN; |
| 1983 | } |
| 1984 | |
Alastair Bridgewater | 37aa224 | 2017-04-11 13:11:24 -0400 | [diff] [blame] | 1985 | /* For the user-specified mode, we must ignore doublescan and |
| 1986 | * the like, but honor frame packing. |
| 1987 | */ |
| 1988 | umode_vdisplay = umode->vdisplay; |
| 1989 | if ((umode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING) |
| 1990 | umode_vdisplay += umode->vtotal; |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1991 | asyh->view.iW = umode->hdisplay; |
Alastair Bridgewater | 37aa224 | 2017-04-11 13:11:24 -0400 | [diff] [blame] | 1992 | asyh->view.iH = umode_vdisplay; |
| 1993 | /* For the output mode, we can just use the stock helper. */ |
| 1994 | drm_mode_get_hv_timing(omode, &omode_hdisplay, &omode_vdisplay); |
| 1995 | asyh->view.oW = omode_hdisplay; |
| 1996 | asyh->view.oH = omode_vdisplay; |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1997 | |
| 1998 | /* Add overscan compensation if necessary, will keep the aspect |
| 1999 | * ratio the same as the backend mode unless overridden by the |
| 2000 | * user setting both hborder and vborder properties. |
| 2001 | */ |
| 2002 | if ((asyc->scaler.underscan.mode == UNDERSCAN_ON || |
| 2003 | (asyc->scaler.underscan.mode == UNDERSCAN_AUTO && |
| 2004 | drm_detect_hdmi_monitor(edid)))) { |
| 2005 | u32 bX = asyc->scaler.underscan.hborder; |
| 2006 | u32 bY = asyc->scaler.underscan.vborder; |
| 2007 | u32 r = (asyh->view.oH << 19) / asyh->view.oW; |
| 2008 | |
| 2009 | if (bX) { |
| 2010 | asyh->view.oW -= (bX * 2); |
| 2011 | if (bY) asyh->view.oH -= (bY * 2); |
| 2012 | else asyh->view.oH = ((asyh->view.oW * r) + (r / 2)) >> 19; |
| 2013 | } else { |
| 2014 | asyh->view.oW -= (asyh->view.oW >> 4) + 32; |
| 2015 | if (bY) asyh->view.oH -= (bY * 2); |
| 2016 | else asyh->view.oH = ((asyh->view.oW * r) + (r / 2)) >> 19; |
| 2017 | } |
| 2018 | } |
| 2019 | |
| 2020 | /* Handle CENTER/ASPECT scaling, taking into account the areas |
| 2021 | * removed already for overscan compensation. |
| 2022 | */ |
| 2023 | switch (mode) { |
| 2024 | case DRM_MODE_SCALE_CENTER: |
| 2025 | asyh->view.oW = min((u16)umode->hdisplay, asyh->view.oW); |
Alastair Bridgewater | 37aa224 | 2017-04-11 13:11:24 -0400 | [diff] [blame] | 2026 | asyh->view.oH = min((u16)umode_vdisplay, asyh->view.oH); |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2027 | /* fall-through */ |
| 2028 | case DRM_MODE_SCALE_ASPECT: |
| 2029 | if (asyh->view.oH < asyh->view.oW) { |
| 2030 | u32 r = (asyh->view.iW << 19) / asyh->view.iH; |
| 2031 | asyh->view.oW = ((asyh->view.oH * r) + (r / 2)) >> 19; |
| 2032 | } else { |
| 2033 | u32 r = (asyh->view.iH << 19) / asyh->view.iW; |
| 2034 | asyh->view.oH = ((asyh->view.oW * r) + (r / 2)) >> 19; |
| 2035 | } |
| 2036 | break; |
| 2037 | default: |
| 2038 | break; |
| 2039 | } |
| 2040 | |
| 2041 | asyh->set.view = true; |
| 2042 | } |
| 2043 | |
| 2044 | static void |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2045 | nv50_head_atomic_check_mode(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 2046 | { |
| 2047 | struct drm_display_mode *mode = &asyh->state.adjusted_mode; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2048 | struct nv50_head_mode *m = &asyh->mode; |
Alastair Bridgewater | 35dd987 | 2017-04-11 13:11:16 -0400 | [diff] [blame] | 2049 | u32 blankus; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2050 | |
Alastair Bridgewater | 37aa224 | 2017-04-11 13:11:24 -0400 | [diff] [blame] | 2051 | drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V | CRTC_STEREO_DOUBLE); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2052 | |
Alastair Bridgewater | 35dd987 | 2017-04-11 13:11:16 -0400 | [diff] [blame] | 2053 | /* |
| 2054 | * DRM modes are defined in terms of a repeating interval |
| 2055 | * starting with the active display area. The hardware modes |
| 2056 | * are defined in terms of a repeating interval starting one |
| 2057 | * unit (pixel or line) into the sync pulse. So, add bias. |
| 2058 | */ |
| 2059 | |
| 2060 | m->h.active = mode->crtc_htotal; |
| 2061 | m->h.synce = mode->crtc_hsync_end - mode->crtc_hsync_start - 1; |
| 2062 | m->h.blanke = mode->crtc_hblank_end - mode->crtc_hsync_start - 1; |
| 2063 | m->h.blanks = m->h.blanke + mode->crtc_hdisplay; |
| 2064 | |
| 2065 | m->v.active = mode->crtc_vtotal; |
| 2066 | m->v.synce = mode->crtc_vsync_end - mode->crtc_vsync_start - 1; |
| 2067 | m->v.blanke = mode->crtc_vblank_end - mode->crtc_vsync_start - 1; |
| 2068 | m->v.blanks = m->v.blanke + mode->crtc_vdisplay; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2069 | |
| 2070 | /*XXX: Safe underestimate, even "0" works */ |
Alastair Bridgewater | 35dd987 | 2017-04-11 13:11:16 -0400 | [diff] [blame] | 2071 | blankus = (m->v.active - mode->crtc_vdisplay - 2) * m->h.active; |
Ben Skeggs | aeecfcd | 2017-04-05 09:12:54 +1000 | [diff] [blame] | 2072 | blankus *= 1000; |
Alastair Bridgewater | 35dd987 | 2017-04-11 13:11:16 -0400 | [diff] [blame] | 2073 | blankus /= mode->crtc_clock; |
Ben Skeggs | aeecfcd | 2017-04-05 09:12:54 +1000 | [diff] [blame] | 2074 | m->v.blankus = blankus; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2075 | |
| 2076 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Alastair Bridgewater | 35dd987 | 2017-04-11 13:11:16 -0400 | [diff] [blame] | 2077 | m->v.blank2e = m->v.active + m->v.blanke; |
| 2078 | m->v.blank2s = m->v.blank2e + mode->crtc_vdisplay; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2079 | m->v.active = (m->v.active * 2) + 1; |
| 2080 | m->interlace = true; |
| 2081 | } else { |
| 2082 | m->v.blank2e = 0; |
| 2083 | m->v.blank2s = 1; |
| 2084 | m->interlace = false; |
| 2085 | } |
Alastair Bridgewater | 35dd987 | 2017-04-11 13:11:16 -0400 | [diff] [blame] | 2086 | m->clock = mode->crtc_clock; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2087 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2088 | asyh->set.mode = true; |
| 2089 | } |
| 2090 | |
| 2091 | static int |
| 2092 | nv50_head_atomic_check(struct drm_crtc *crtc, struct drm_crtc_state *state) |
| 2093 | { |
| 2094 | struct nouveau_drm *drm = nouveau_drm(crtc->dev); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2095 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2096 | struct nv50_head *head = nv50_head(crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2097 | struct nv50_head_atom *armh = nv50_head_atom(crtc->state); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2098 | struct nv50_head_atom *asyh = nv50_head_atom(state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2099 | struct nouveau_conn_atom *asyc = NULL; |
| 2100 | struct drm_connector_state *conns; |
| 2101 | struct drm_connector *conn; |
| 2102 | int i; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2103 | |
| 2104 | NV_ATOMIC(drm, "%s atomic_check %d\n", crtc->name, asyh->state.active); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2105 | if (asyh->state.active) { |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 2106 | for_each_new_connector_in_state(asyh->state.state, conn, conns, i) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2107 | if (conns->crtc == crtc) { |
| 2108 | asyc = nouveau_conn_atom(conns); |
| 2109 | break; |
| 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | if (armh->state.active) { |
| 2114 | if (asyc) { |
| 2115 | if (asyh->state.mode_changed) |
| 2116 | asyc->set.scaler = true; |
| 2117 | if (armh->base.depth != asyh->base.depth) |
| 2118 | asyc->set.dither = true; |
| 2119 | } |
| 2120 | } else { |
Gustavo A. R. Silva | 8627692 | 2017-05-22 14:12:37 -0500 | [diff] [blame] | 2121 | if (asyc) |
| 2122 | asyc->set.mask = ~0; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2123 | asyh->set.mask = ~0; |
| 2124 | } |
| 2125 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2126 | if (asyh->state.mode_changed) |
| 2127 | nv50_head_atomic_check_mode(head, asyh); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2128 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2129 | if (asyc) { |
| 2130 | if (asyc->set.scaler) |
| 2131 | nv50_head_atomic_check_view(armh, asyh, asyc); |
| 2132 | if (asyc->set.dither) |
| 2133 | nv50_head_atomic_check_dither(armh, asyh, asyc); |
| 2134 | if (asyc->set.procamp) |
| 2135 | nv50_head_atomic_check_procamp(armh, asyh, asyc); |
| 2136 | } |
| 2137 | |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2138 | if ((asyh->core.visible = (asyh->base.cpp != 0))) { |
| 2139 | asyh->core.x = asyh->base.x; |
| 2140 | asyh->core.y = asyh->base.y; |
| 2141 | asyh->core.w = asyh->base.w; |
| 2142 | asyh->core.h = asyh->base.h; |
| 2143 | } else |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2144 | if ((asyh->core.visible = asyh->curs.visible)) { |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2145 | /*XXX: We need to either find some way of having the |
| 2146 | * primary base layer appear black, while still |
| 2147 | * being able to display the other layers, or we |
| 2148 | * need to allocate a dummy black surface here. |
| 2149 | */ |
| 2150 | asyh->core.x = 0; |
| 2151 | asyh->core.y = 0; |
| 2152 | asyh->core.w = asyh->state.mode.hdisplay; |
| 2153 | asyh->core.h = asyh->state.mode.vdisplay; |
| 2154 | } |
| 2155 | asyh->core.handle = disp->mast.base.vram.handle; |
| 2156 | asyh->core.offset = 0; |
| 2157 | asyh->core.format = 0xcf; |
| 2158 | asyh->core.kind = 0; |
| 2159 | asyh->core.layout = 1; |
| 2160 | asyh->core.block = 0; |
| 2161 | asyh->core.pitch = ALIGN(asyh->core.w, 64) * 4; |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2162 | asyh->lut.handle = disp->mast.base.vram.handle; |
| 2163 | asyh->lut.offset = head->base.lut.nvbo->bo.offset; |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2164 | asyh->set.base = armh->base.cpp != asyh->base.cpp; |
| 2165 | asyh->set.ovly = armh->ovly.cpp != asyh->ovly.cpp; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2166 | } else { |
| 2167 | asyh->core.visible = false; |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2168 | asyh->curs.visible = false; |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2169 | asyh->base.cpp = 0; |
| 2170 | asyh->ovly.cpp = 0; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | if (!drm_atomic_crtc_needs_modeset(&asyh->state)) { |
| 2174 | if (asyh->core.visible) { |
| 2175 | if (memcmp(&armh->core, &asyh->core, sizeof(asyh->core))) |
| 2176 | asyh->set.core = true; |
| 2177 | } else |
| 2178 | if (armh->core.visible) { |
| 2179 | asyh->clr.core = true; |
| 2180 | } |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2181 | |
| 2182 | if (asyh->curs.visible) { |
| 2183 | if (memcmp(&armh->curs, &asyh->curs, sizeof(asyh->curs))) |
| 2184 | asyh->set.curs = true; |
| 2185 | } else |
| 2186 | if (armh->curs.visible) { |
| 2187 | asyh->clr.curs = true; |
| 2188 | } |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2189 | } else { |
| 2190 | asyh->clr.core = armh->core.visible; |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2191 | asyh->clr.curs = armh->curs.visible; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2192 | asyh->set.core = asyh->core.visible; |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2193 | asyh->set.curs = asyh->curs.visible; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2194 | } |
| 2195 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2196 | if (asyh->clr.mask || asyh->set.mask) |
| 2197 | nv50_atom(asyh->state.state)->lock_core = true; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2198 | return 0; |
| 2199 | } |
| 2200 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2201 | static void |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2202 | nv50_head_lut_load(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2203 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2204 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2205 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 2206 | void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo); |
Peter Rosin | 804ea3e | 2017-07-13 18:25:35 +0200 | [diff] [blame] | 2207 | u16 *r, *g, *b; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2208 | int i; |
| 2209 | |
Peter Rosin | 804ea3e | 2017-07-13 18:25:35 +0200 | [diff] [blame] | 2210 | r = crtc->gamma_store; |
| 2211 | g = r + crtc->gamma_size; |
| 2212 | b = g + crtc->gamma_size; |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2213 | |
Peter Rosin | 804ea3e | 2017-07-13 18:25:35 +0200 | [diff] [blame] | 2214 | for (i = 0; i < 256; i++) { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 2215 | if (disp->disp->oclass < GF110_DISP) { |
Peter Rosin | 804ea3e | 2017-07-13 18:25:35 +0200 | [diff] [blame] | 2216 | writew((*r++ >> 2) + 0x0000, lut + (i * 0x08) + 0); |
| 2217 | writew((*g++ >> 2) + 0x0000, lut + (i * 0x08) + 2); |
| 2218 | writew((*b++ >> 2) + 0x0000, lut + (i * 0x08) + 4); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2219 | } else { |
Peter Rosin | 804ea3e | 2017-07-13 18:25:35 +0200 | [diff] [blame] | 2220 | /* 0x6000 interferes with the 14-bit color??? */ |
| 2221 | writew((*r++ >> 2) + 0x6000, lut + (i * 0x20) + 0); |
| 2222 | writew((*g++ >> 2) + 0x6000, lut + (i * 0x20) + 2); |
| 2223 | writew((*b++ >> 2) + 0x6000, lut + (i * 0x20) + 4); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2224 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2225 | } |
| 2226 | } |
| 2227 | |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2228 | static const struct drm_crtc_helper_funcs |
| 2229 | nv50_head_help = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2230 | .atomic_check = nv50_head_atomic_check, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2231 | }; |
| 2232 | |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2233 | static int |
| 2234 | nv50_head_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, |
Daniel Vetter | 6d124ff | 2017-04-03 10:33:01 +0200 | [diff] [blame] | 2235 | uint32_t size, |
| 2236 | struct drm_modeset_acquire_ctx *ctx) |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2237 | { |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2238 | nv50_head_lut_load(crtc); |
| 2239 | return 0; |
| 2240 | } |
| 2241 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2242 | static void |
| 2243 | nv50_head_atomic_destroy_state(struct drm_crtc *crtc, |
| 2244 | struct drm_crtc_state *state) |
| 2245 | { |
| 2246 | struct nv50_head_atom *asyh = nv50_head_atom(state); |
| 2247 | __drm_atomic_helper_crtc_destroy_state(&asyh->state); |
| 2248 | kfree(asyh); |
| 2249 | } |
| 2250 | |
| 2251 | static struct drm_crtc_state * |
| 2252 | nv50_head_atomic_duplicate_state(struct drm_crtc *crtc) |
| 2253 | { |
| 2254 | struct nv50_head_atom *armh = nv50_head_atom(crtc->state); |
| 2255 | struct nv50_head_atom *asyh; |
| 2256 | if (!(asyh = kmalloc(sizeof(*asyh), GFP_KERNEL))) |
| 2257 | return NULL; |
| 2258 | __drm_atomic_helper_crtc_duplicate_state(crtc, &asyh->state); |
| 2259 | asyh->view = armh->view; |
| 2260 | asyh->mode = armh->mode; |
| 2261 | asyh->lut = armh->lut; |
| 2262 | asyh->core = armh->core; |
| 2263 | asyh->curs = armh->curs; |
| 2264 | asyh->base = armh->base; |
| 2265 | asyh->ovly = armh->ovly; |
| 2266 | asyh->dither = armh->dither; |
| 2267 | asyh->procamp = armh->procamp; |
| 2268 | asyh->clr.mask = 0; |
| 2269 | asyh->set.mask = 0; |
| 2270 | return &asyh->state; |
| 2271 | } |
| 2272 | |
| 2273 | static void |
| 2274 | __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc, |
| 2275 | struct drm_crtc_state *state) |
| 2276 | { |
| 2277 | if (crtc->state) |
| 2278 | crtc->funcs->atomic_destroy_state(crtc, crtc->state); |
| 2279 | crtc->state = state; |
| 2280 | crtc->state->crtc = crtc; |
| 2281 | } |
| 2282 | |
| 2283 | static void |
| 2284 | nv50_head_reset(struct drm_crtc *crtc) |
| 2285 | { |
| 2286 | struct nv50_head_atom *asyh; |
| 2287 | |
| 2288 | if (WARN_ON(!(asyh = kzalloc(sizeof(*asyh), GFP_KERNEL)))) |
| 2289 | return; |
| 2290 | |
| 2291 | __drm_atomic_helper_crtc_reset(crtc, &asyh->state); |
| 2292 | } |
| 2293 | |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2294 | static void |
| 2295 | nv50_head_destroy(struct drm_crtc *crtc) |
| 2296 | { |
| 2297 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 2298 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
| 2299 | struct nv50_head *head = nv50_head(crtc); |
| 2300 | |
| 2301 | nv50_dmac_destroy(&head->ovly.base, disp->disp); |
| 2302 | nv50_pioc_destroy(&head->oimm.base); |
| 2303 | |
| 2304 | nouveau_bo_unmap(nv_crtc->lut.nvbo); |
| 2305 | if (nv_crtc->lut.nvbo) |
| 2306 | nouveau_bo_unpin(nv_crtc->lut.nvbo); |
| 2307 | nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo); |
| 2308 | |
| 2309 | drm_crtc_cleanup(crtc); |
| 2310 | kfree(crtc); |
| 2311 | } |
| 2312 | |
| 2313 | static const struct drm_crtc_funcs |
| 2314 | nv50_head_func = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2315 | .reset = nv50_head_reset, |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2316 | .gamma_set = nv50_head_gamma_set, |
| 2317 | .destroy = nv50_head_destroy, |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2318 | .set_config = drm_atomic_helper_set_config, |
Andrey Grodzovsky | 612fb5d | 2017-02-02 16:56:30 -0500 | [diff] [blame] | 2319 | .page_flip = drm_atomic_helper_page_flip, |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2320 | .atomic_duplicate_state = nv50_head_atomic_duplicate_state, |
| 2321 | .atomic_destroy_state = nv50_head_atomic_destroy_state, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2322 | }; |
| 2323 | |
| 2324 | static int |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2325 | nv50_head_create(struct drm_device *dev, int index) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2326 | { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 2327 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 2328 | struct nvif_device *device = &drm->client.device; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2329 | struct nv50_disp *disp = nv50_disp(dev); |
| 2330 | struct nv50_head *head; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2331 | struct nv50_base *base; |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2332 | struct nv50_curs *curs; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2333 | struct drm_crtc *crtc; |
Peter Rosin | 804ea3e | 2017-07-13 18:25:35 +0200 | [diff] [blame] | 2334 | int ret; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2335 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2336 | head = kzalloc(sizeof(*head), GFP_KERNEL); |
| 2337 | if (!head) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2338 | return -ENOMEM; |
| 2339 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2340 | head->base.index = index; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2341 | ret = nv50_base_new(drm, head, &base); |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2342 | if (ret == 0) |
| 2343 | ret = nv50_curs_new(drm, head, &curs); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2344 | if (ret) { |
| 2345 | kfree(head); |
| 2346 | return ret; |
| 2347 | } |
| 2348 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2349 | crtc = &head->base.base; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2350 | drm_crtc_init_with_planes(dev, crtc, &base->wndw.plane, |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2351 | &curs->wndw.plane, &nv50_head_func, |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2352 | "head-%d", head->base.index); |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2353 | drm_crtc_helper_add(crtc, &nv50_head_help); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2354 | drm_mode_crtc_set_gamma_size(crtc, 256); |
| 2355 | |
Ben Skeggs | bab7cc1 | 2016-05-24 17:26:48 +1000 | [diff] [blame] | 2356 | ret = nouveau_bo_new(&drm->client, 8192, 0x100, TTM_PL_FLAG_VRAM, |
Maarten Lankhorst | bb6178b | 2014-01-09 11:03:15 +0100 | [diff] [blame] | 2357 | 0, 0x0000, NULL, NULL, &head->base.lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2358 | if (!ret) { |
Ben Skeggs | 547ad07 | 2014-11-10 12:35:06 +1000 | [diff] [blame] | 2359 | 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] | 2360 | if (!ret) { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2361 | ret = nouveau_bo_map(head->base.lut.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2362 | if (ret) |
| 2363 | nouveau_bo_unpin(head->base.lut.nvbo); |
| 2364 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2365 | if (ret) |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2366 | nouveau_bo_ref(NULL, &head->base.lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | if (ret) |
| 2370 | goto out; |
| 2371 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2372 | /* allocate overlay resources */ |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 2373 | ret = nv50_oimm_create(device, disp->disp, index, &head->oimm); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2374 | if (ret) |
| 2375 | goto out; |
| 2376 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 2377 | ret = nv50_ovly_create(device, disp->disp, index, disp->sync->bo.offset, |
| 2378 | &head->ovly); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2379 | if (ret) |
| 2380 | goto out; |
| 2381 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2382 | out: |
| 2383 | if (ret) |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2384 | nv50_head_destroy(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2385 | return ret; |
| 2386 | } |
| 2387 | |
| 2388 | /****************************************************************************** |
Ben Skeggs | d92c8ad | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2389 | * Output path helpers |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 2390 | *****************************************************************************/ |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 2391 | static void |
| 2392 | nv50_outp_release(struct nouveau_encoder *nv_encoder) |
| 2393 | { |
| 2394 | struct nv50_disp *disp = nv50_disp(nv_encoder->base.base.dev); |
| 2395 | struct { |
| 2396 | struct nv50_disp_mthd_v1 base; |
| 2397 | } args = { |
| 2398 | .base.version = 1, |
| 2399 | .base.method = NV50_DISP_MTHD_V1_RELEASE, |
| 2400 | .base.hasht = nv_encoder->dcb->hasht, |
| 2401 | .base.hashm = nv_encoder->dcb->hashm, |
| 2402 | }; |
| 2403 | |
| 2404 | nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
| 2405 | nv_encoder->or = -1; |
| 2406 | nv_encoder->link = 0; |
| 2407 | } |
| 2408 | |
| 2409 | static int |
| 2410 | nv50_outp_acquire(struct nouveau_encoder *nv_encoder) |
| 2411 | { |
| 2412 | struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); |
| 2413 | struct nv50_disp *disp = nv50_disp(drm->dev); |
| 2414 | struct { |
| 2415 | struct nv50_disp_mthd_v1 base; |
| 2416 | struct nv50_disp_acquire_v0 info; |
| 2417 | } args = { |
| 2418 | .base.version = 1, |
| 2419 | .base.method = NV50_DISP_MTHD_V1_ACQUIRE, |
| 2420 | .base.hasht = nv_encoder->dcb->hasht, |
| 2421 | .base.hashm = nv_encoder->dcb->hashm, |
| 2422 | }; |
| 2423 | int ret; |
| 2424 | |
| 2425 | ret = nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
| 2426 | if (ret) { |
| 2427 | NV_ERROR(drm, "error acquiring output path: %d\n", ret); |
| 2428 | return ret; |
| 2429 | } |
| 2430 | |
| 2431 | nv_encoder->or = args.info.or; |
| 2432 | nv_encoder->link = args.info.link; |
| 2433 | return 0; |
| 2434 | } |
| 2435 | |
Ben Skeggs | d92c8ad | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2436 | static int |
| 2437 | nv50_outp_atomic_check_view(struct drm_encoder *encoder, |
| 2438 | struct drm_crtc_state *crtc_state, |
| 2439 | struct drm_connector_state *conn_state, |
| 2440 | struct drm_display_mode *native_mode) |
| 2441 | { |
| 2442 | struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode; |
| 2443 | struct drm_display_mode *mode = &crtc_state->mode; |
| 2444 | struct drm_connector *connector = conn_state->connector; |
| 2445 | struct nouveau_conn_atom *asyc = nouveau_conn_atom(conn_state); |
| 2446 | struct nouveau_drm *drm = nouveau_drm(encoder->dev); |
| 2447 | |
| 2448 | NV_ATOMIC(drm, "%s atomic_check\n", encoder->name); |
| 2449 | asyc->scaler.full = false; |
| 2450 | if (!native_mode) |
| 2451 | return 0; |
| 2452 | |
| 2453 | if (asyc->scaler.mode == DRM_MODE_SCALE_NONE) { |
| 2454 | switch (connector->connector_type) { |
| 2455 | case DRM_MODE_CONNECTOR_LVDS: |
| 2456 | case DRM_MODE_CONNECTOR_eDP: |
| 2457 | /* Force use of scaler for non-EDID modes. */ |
| 2458 | if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER) |
| 2459 | break; |
| 2460 | mode = native_mode; |
| 2461 | asyc->scaler.full = true; |
| 2462 | break; |
| 2463 | default: |
| 2464 | break; |
| 2465 | } |
| 2466 | } else { |
| 2467 | mode = native_mode; |
| 2468 | } |
| 2469 | |
| 2470 | if (!drm_mode_equal(adjusted_mode, mode)) { |
| 2471 | drm_mode_copy(adjusted_mode, mode); |
| 2472 | crtc_state->mode_changed = true; |
| 2473 | } |
| 2474 | |
| 2475 | return 0; |
| 2476 | } |
| 2477 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2478 | static int |
| 2479 | nv50_outp_atomic_check(struct drm_encoder *encoder, |
| 2480 | struct drm_crtc_state *crtc_state, |
| 2481 | struct drm_connector_state *conn_state) |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 2482 | { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2483 | struct nouveau_connector *nv_connector = |
| 2484 | nouveau_connector(conn_state->connector); |
| 2485 | return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state, |
| 2486 | nv_connector->native_mode); |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2490 | * DAC |
| 2491 | *****************************************************************************/ |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2492 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2493 | nv50_dac_disable(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2494 | { |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2495 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 2496 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
| 2497 | const int or = nv_encoder->or; |
| 2498 | u32 *push; |
| 2499 | |
| 2500 | if (nv_encoder->crtc) { |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2501 | push = evo_wait(mast, 4); |
| 2502 | if (push) { |
| 2503 | if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) { |
| 2504 | evo_mthd(push, 0x0400 + (or * 0x080), 1); |
| 2505 | evo_data(push, 0x00000000); |
| 2506 | } else { |
| 2507 | evo_mthd(push, 0x0180 + (or * 0x020), 1); |
| 2508 | evo_data(push, 0x00000000); |
| 2509 | } |
| 2510 | evo_kick(push, mast); |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | nv_encoder->crtc = NULL; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 2515 | nv50_outp_release(nv_encoder); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2519 | nv50_dac_enable(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2520 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2521 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2522 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 2523 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2524 | struct drm_display_mode *mode = &nv_crtc->base.state->adjusted_mode; |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2525 | u32 *push; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2526 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 2527 | nv50_outp_acquire(nv_encoder); |
| 2528 | |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2529 | push = evo_wait(mast, 8); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2530 | if (push) { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 2531 | if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) { |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2532 | u32 syncs = 0x00000000; |
| 2533 | |
| 2534 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 2535 | syncs |= 0x00000001; |
| 2536 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 2537 | syncs |= 0x00000002; |
| 2538 | |
| 2539 | evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2); |
| 2540 | evo_data(push, 1 << nv_crtc->index); |
| 2541 | evo_data(push, syncs); |
| 2542 | } else { |
| 2543 | u32 magic = 0x31ec6000 | (nv_crtc->index << 25); |
| 2544 | u32 syncs = 0x00000001; |
| 2545 | |
| 2546 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 2547 | syncs |= 0x00000008; |
| 2548 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 2549 | syncs |= 0x00000010; |
| 2550 | |
| 2551 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 2552 | magic |= 0x00000001; |
| 2553 | |
| 2554 | evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2); |
| 2555 | evo_data(push, syncs); |
| 2556 | evo_data(push, magic); |
| 2557 | evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1); |
| 2558 | evo_data(push, 1 << nv_crtc->index); |
| 2559 | } |
| 2560 | |
| 2561 | evo_kick(push, mast); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | nv_encoder->crtc = encoder->crtc; |
| 2565 | } |
| 2566 | |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 2567 | static enum drm_connector_status |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2568 | nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 2569 | { |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2570 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2571 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2572 | struct { |
| 2573 | struct nv50_disp_mthd_v1 base; |
| 2574 | struct nv50_disp_dac_load_v0 load; |
| 2575 | } args = { |
| 2576 | .base.version = 1, |
| 2577 | .base.method = NV50_DISP_MTHD_V1_DAC_LOAD, |
| 2578 | .base.hasht = nv_encoder->dcb->hasht, |
| 2579 | .base.hashm = nv_encoder->dcb->hashm, |
| 2580 | }; |
| 2581 | int ret; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 2582 | |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2583 | args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval; |
| 2584 | if (args.load.data == 0) |
| 2585 | args.load.data = 340; |
| 2586 | |
| 2587 | ret = nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
| 2588 | if (ret || !args.load.load) |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 2589 | return connector_status_disconnected; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 2590 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 2591 | return connector_status_connected; |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 2592 | } |
| 2593 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2594 | static const struct drm_encoder_helper_funcs |
| 2595 | nv50_dac_help = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2596 | .atomic_check = nv50_outp_atomic_check, |
| 2597 | .enable = nv50_dac_enable, |
| 2598 | .disable = nv50_dac_disable, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2599 | .detect = nv50_dac_detect |
| 2600 | }; |
| 2601 | |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2602 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2603 | nv50_dac_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2604 | { |
| 2605 | drm_encoder_cleanup(encoder); |
| 2606 | kfree(encoder); |
| 2607 | } |
| 2608 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2609 | static const struct drm_encoder_funcs |
| 2610 | nv50_dac_func = { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2611 | .destroy = nv50_dac_destroy, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2612 | }; |
| 2613 | |
| 2614 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2615 | nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2616 | { |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 2617 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 2618 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 2619 | struct nvkm_i2c_bus *bus; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2620 | struct nouveau_encoder *nv_encoder; |
| 2621 | struct drm_encoder *encoder; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 2622 | int type = DRM_MODE_ENCODER_DAC; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2623 | |
| 2624 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 2625 | if (!nv_encoder) |
| 2626 | return -ENOMEM; |
| 2627 | nv_encoder->dcb = dcbe; |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 2628 | |
| 2629 | bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index); |
| 2630 | if (bus) |
| 2631 | nv_encoder->i2c = &bus->i2c; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2632 | |
| 2633 | encoder = to_drm_encoder(nv_encoder); |
| 2634 | encoder->possible_crtcs = dcbe->heads; |
| 2635 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2636 | drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type, |
| 2637 | "dac-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2638 | drm_encoder_helper_add(encoder, &nv50_dac_help); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2639 | |
| 2640 | drm_mode_connector_attach_encoder(connector, encoder); |
| 2641 | return 0; |
| 2642 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2643 | |
| 2644 | /****************************************************************************** |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2645 | * Audio |
| 2646 | *****************************************************************************/ |
| 2647 | static void |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2648 | nv50_audio_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc) |
| 2649 | { |
| 2650 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 2651 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
| 2652 | struct { |
| 2653 | struct nv50_disp_mthd_v1 base; |
| 2654 | struct nv50_disp_sor_hda_eld_v0 eld; |
| 2655 | } args = { |
| 2656 | .base.version = 1, |
| 2657 | .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD, |
| 2658 | .base.hasht = nv_encoder->dcb->hasht, |
| 2659 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 2660 | (0x0100 << nv_crtc->index), |
| 2661 | }; |
| 2662 | |
| 2663 | nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
| 2664 | } |
| 2665 | |
| 2666 | static void |
| 2667 | nv50_audio_enable(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2668 | { |
| 2669 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 2670 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2671 | struct nouveau_connector *nv_connector; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2672 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | d889c52 | 2014-09-15 21:11:51 +1000 | [diff] [blame] | 2673 | struct __packed { |
| 2674 | struct { |
| 2675 | struct nv50_disp_mthd_v1 mthd; |
| 2676 | struct nv50_disp_sor_hda_eld_v0 eld; |
| 2677 | } base; |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2678 | u8 data[sizeof(nv_connector->base.eld)]; |
| 2679 | } args = { |
Ben Skeggs | d889c52 | 2014-09-15 21:11:51 +1000 | [diff] [blame] | 2680 | .base.mthd.version = 1, |
| 2681 | .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD, |
| 2682 | .base.mthd.hasht = nv_encoder->dcb->hasht, |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 2683 | .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 2684 | (0x0100 << nv_crtc->index), |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2685 | }; |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2686 | |
| 2687 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 2688 | if (!drm_detect_monitor_audio(nv_connector->edid)) |
| 2689 | return; |
| 2690 | |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2691 | drm_edid_to_eld(&nv_connector->base, nv_connector->edid); |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2692 | memcpy(args.data, nv_connector->base.eld, sizeof(args.data)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2693 | |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 2694 | nvif_mthd(disp->disp, 0, &args, |
| 2695 | sizeof(args.base) + drm_eld_size(args.data)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2696 | } |
| 2697 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2698 | /****************************************************************************** |
| 2699 | * HDMI |
| 2700 | *****************************************************************************/ |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2701 | static void |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2702 | nv50_hdmi_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2703 | { |
| 2704 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2705 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2706 | struct { |
| 2707 | struct nv50_disp_mthd_v1 base; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2708 | struct nv50_disp_sor_hdmi_pwr_v0 pwr; |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2709 | } args = { |
| 2710 | .base.version = 1, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2711 | .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR, |
| 2712 | .base.hasht = nv_encoder->dcb->hasht, |
| 2713 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 2714 | (0x0100 << nv_crtc->index), |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2715 | }; |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2716 | |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2717 | nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2718 | } |
| 2719 | |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2720 | static void |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2721 | nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2722 | { |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 2723 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 2724 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2725 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2726 | struct { |
| 2727 | struct nv50_disp_mthd_v1 base; |
| 2728 | struct nv50_disp_sor_hdmi_pwr_v0 pwr; |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 2729 | u8 infoframes[2 * 17]; /* two frames, up to 17 bytes each */ |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2730 | } args = { |
| 2731 | .base.version = 1, |
| 2732 | .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR, |
| 2733 | .base.hasht = nv_encoder->dcb->hasht, |
| 2734 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 2735 | (0x0100 << nv_crtc->index), |
| 2736 | .pwr.state = 1, |
| 2737 | .pwr.rekey = 56, /* binary driver, and tegra, constant */ |
| 2738 | }; |
| 2739 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 2740 | u32 max_ac_packet; |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 2741 | union hdmi_infoframe avi_frame; |
| 2742 | union hdmi_infoframe vendor_frame; |
| 2743 | int ret; |
| 2744 | int size; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 2745 | |
| 2746 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 2747 | if (!drm_detect_hdmi_monitor(nv_connector->edid)) |
| 2748 | return; |
| 2749 | |
Shashank Sharma | 0c1f528 | 2017-07-13 21:03:07 +0530 | [diff] [blame] | 2750 | ret = drm_hdmi_avi_infoframe_from_display_mode(&avi_frame.avi, mode, |
| 2751 | false); |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 2752 | if (!ret) { |
| 2753 | /* We have an AVI InfoFrame, populate it to the display */ |
| 2754 | args.pwr.avi_infoframe_length |
| 2755 | = hdmi_infoframe_pack(&avi_frame, args.infoframes, 17); |
| 2756 | } |
| 2757 | |
| 2758 | ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi, mode); |
| 2759 | if (!ret) { |
| 2760 | /* We have a Vendor InfoFrame, populate it to the display */ |
| 2761 | args.pwr.vendor_infoframe_length |
| 2762 | = hdmi_infoframe_pack(&vendor_frame, |
| 2763 | args.infoframes |
| 2764 | + args.pwr.avi_infoframe_length, |
| 2765 | 17); |
| 2766 | } |
| 2767 | |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 2768 | max_ac_packet = mode->htotal - mode->hdisplay; |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2769 | max_ac_packet -= args.pwr.rekey; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 2770 | max_ac_packet -= 18; /* constant from tegra */ |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2771 | args.pwr.max_ac_packet = max_ac_packet / 32; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 2772 | |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 2773 | size = sizeof(args.base) |
| 2774 | + sizeof(args.pwr) |
| 2775 | + args.pwr.avi_infoframe_length |
| 2776 | + args.pwr.vendor_infoframe_length; |
| 2777 | nvif_mthd(disp->disp, 0, &args, size); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2778 | nv50_audio_enable(encoder, mode); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | /****************************************************************************** |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2782 | * MST |
| 2783 | *****************************************************************************/ |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2784 | #define nv50_mstm(p) container_of((p), struct nv50_mstm, mgr) |
| 2785 | #define nv50_mstc(p) container_of((p), struct nv50_mstc, connector) |
| 2786 | #define nv50_msto(p) container_of((p), struct nv50_msto, encoder) |
| 2787 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2788 | struct nv50_mstm { |
| 2789 | struct nouveau_encoder *outp; |
| 2790 | |
| 2791 | struct drm_dp_mst_topology_mgr mgr; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2792 | struct nv50_msto *msto[4]; |
| 2793 | |
| 2794 | bool modified; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 2795 | bool disabled; |
| 2796 | int links; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2797 | }; |
| 2798 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2799 | struct nv50_mstc { |
| 2800 | struct nv50_mstm *mstm; |
| 2801 | struct drm_dp_mst_port *port; |
| 2802 | struct drm_connector connector; |
| 2803 | |
| 2804 | struct drm_display_mode *native; |
| 2805 | struct edid *edid; |
| 2806 | |
| 2807 | int pbn; |
| 2808 | }; |
| 2809 | |
| 2810 | struct nv50_msto { |
| 2811 | struct drm_encoder encoder; |
| 2812 | |
| 2813 | struct nv50_head *head; |
| 2814 | struct nv50_mstc *mstc; |
| 2815 | bool disabled; |
| 2816 | }; |
| 2817 | |
| 2818 | static struct drm_dp_payload * |
| 2819 | nv50_msto_payload(struct nv50_msto *msto) |
| 2820 | { |
| 2821 | struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev); |
| 2822 | struct nv50_mstc *mstc = msto->mstc; |
| 2823 | struct nv50_mstm *mstm = mstc->mstm; |
| 2824 | int vcpi = mstc->port->vcpi.vcpi, i; |
| 2825 | |
| 2826 | NV_ATOMIC(drm, "%s: vcpi %d\n", msto->encoder.name, vcpi); |
| 2827 | for (i = 0; i < mstm->mgr.max_payloads; i++) { |
| 2828 | struct drm_dp_payload *payload = &mstm->mgr.payloads[i]; |
| 2829 | NV_ATOMIC(drm, "%s: %d: vcpi %d start 0x%02x slots 0x%02x\n", |
| 2830 | mstm->outp->base.base.name, i, payload->vcpi, |
| 2831 | payload->start_slot, payload->num_slots); |
| 2832 | } |
| 2833 | |
| 2834 | for (i = 0; i < mstm->mgr.max_payloads; i++) { |
| 2835 | struct drm_dp_payload *payload = &mstm->mgr.payloads[i]; |
| 2836 | if (payload->vcpi == vcpi) |
| 2837 | return payload; |
| 2838 | } |
| 2839 | |
| 2840 | return NULL; |
| 2841 | } |
| 2842 | |
| 2843 | static void |
| 2844 | nv50_msto_cleanup(struct nv50_msto *msto) |
| 2845 | { |
| 2846 | struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev); |
| 2847 | struct nv50_mstc *mstc = msto->mstc; |
| 2848 | struct nv50_mstm *mstm = mstc->mstm; |
| 2849 | |
| 2850 | NV_ATOMIC(drm, "%s: msto cleanup\n", msto->encoder.name); |
| 2851 | if (mstc->port && mstc->port->vcpi.vcpi > 0 && !nv50_msto_payload(msto)) |
| 2852 | drm_dp_mst_deallocate_vcpi(&mstm->mgr, mstc->port); |
| 2853 | if (msto->disabled) { |
| 2854 | msto->mstc = NULL; |
| 2855 | msto->head = NULL; |
| 2856 | msto->disabled = false; |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | static void |
| 2861 | nv50_msto_prepare(struct nv50_msto *msto) |
| 2862 | { |
| 2863 | struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev); |
| 2864 | struct nv50_mstc *mstc = msto->mstc; |
| 2865 | struct nv50_mstm *mstm = mstc->mstm; |
| 2866 | struct { |
| 2867 | struct nv50_disp_mthd_v1 base; |
| 2868 | struct nv50_disp_sor_dp_mst_vcpi_v0 vcpi; |
| 2869 | } args = { |
| 2870 | .base.version = 1, |
| 2871 | .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_VCPI, |
| 2872 | .base.hasht = mstm->outp->dcb->hasht, |
| 2873 | .base.hashm = (0xf0ff & mstm->outp->dcb->hashm) | |
| 2874 | (0x0100 << msto->head->base.index), |
| 2875 | }; |
| 2876 | |
| 2877 | NV_ATOMIC(drm, "%s: msto prepare\n", msto->encoder.name); |
| 2878 | if (mstc->port && mstc->port->vcpi.vcpi > 0) { |
| 2879 | struct drm_dp_payload *payload = nv50_msto_payload(msto); |
| 2880 | if (payload) { |
| 2881 | args.vcpi.start_slot = payload->start_slot; |
| 2882 | args.vcpi.num_slots = payload->num_slots; |
| 2883 | args.vcpi.pbn = mstc->port->vcpi.pbn; |
| 2884 | args.vcpi.aligned_pbn = mstc->port->vcpi.aligned_pbn; |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | NV_ATOMIC(drm, "%s: %s: %02x %02x %04x %04x\n", |
| 2889 | msto->encoder.name, msto->head->base.base.name, |
| 2890 | args.vcpi.start_slot, args.vcpi.num_slots, |
| 2891 | args.vcpi.pbn, args.vcpi.aligned_pbn); |
| 2892 | nvif_mthd(&drm->display->disp, 0, &args, sizeof(args)); |
| 2893 | } |
| 2894 | |
| 2895 | static int |
| 2896 | nv50_msto_atomic_check(struct drm_encoder *encoder, |
| 2897 | struct drm_crtc_state *crtc_state, |
| 2898 | struct drm_connector_state *conn_state) |
| 2899 | { |
| 2900 | struct nv50_mstc *mstc = nv50_mstc(conn_state->connector); |
| 2901 | struct nv50_mstm *mstm = mstc->mstm; |
| 2902 | int bpp = conn_state->connector->display_info.bpc * 3; |
| 2903 | int slots; |
| 2904 | |
| 2905 | mstc->pbn = drm_dp_calc_pbn_mode(crtc_state->adjusted_mode.clock, bpp); |
| 2906 | |
| 2907 | slots = drm_dp_find_vcpi_slots(&mstm->mgr, mstc->pbn); |
| 2908 | if (slots < 0) |
| 2909 | return slots; |
| 2910 | |
| 2911 | return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state, |
| 2912 | mstc->native); |
| 2913 | } |
| 2914 | |
| 2915 | static void |
| 2916 | nv50_msto_enable(struct drm_encoder *encoder) |
| 2917 | { |
| 2918 | struct nv50_head *head = nv50_head(encoder->crtc); |
| 2919 | struct nv50_msto *msto = nv50_msto(encoder); |
| 2920 | struct nv50_mstc *mstc = NULL; |
| 2921 | struct nv50_mstm *mstm = NULL; |
| 2922 | struct drm_connector *connector; |
Gustavo Padovan | 875dd62 | 2017-05-11 16:10:46 -0300 | [diff] [blame] | 2923 | struct drm_connector_list_iter conn_iter; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2924 | u8 proto, depth; |
| 2925 | int slots; |
| 2926 | bool r; |
| 2927 | |
Gustavo Padovan | 875dd62 | 2017-05-11 16:10:46 -0300 | [diff] [blame] | 2928 | drm_connector_list_iter_begin(encoder->dev, &conn_iter); |
| 2929 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2930 | if (connector->state->best_encoder == &msto->encoder) { |
| 2931 | mstc = nv50_mstc(connector); |
| 2932 | mstm = mstc->mstm; |
| 2933 | break; |
| 2934 | } |
| 2935 | } |
Gustavo Padovan | 875dd62 | 2017-05-11 16:10:46 -0300 | [diff] [blame] | 2936 | drm_connector_list_iter_end(&conn_iter); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2937 | |
| 2938 | if (WARN_ON(!mstc)) |
| 2939 | return; |
| 2940 | |
Pandiyan, Dhinakaran | 1e797f5 | 2017-03-16 00:10:26 -0700 | [diff] [blame] | 2941 | slots = drm_dp_find_vcpi_slots(&mstm->mgr, mstc->pbn); |
| 2942 | r = drm_dp_mst_allocate_vcpi(&mstm->mgr, mstc->port, mstc->pbn, slots); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2943 | WARN_ON(!r); |
| 2944 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 2945 | if (!mstm->links++) |
| 2946 | nv50_outp_acquire(mstm->outp); |
| 2947 | |
| 2948 | if (mstm->outp->link & 1) |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2949 | proto = 0x8; |
| 2950 | else |
| 2951 | proto = 0x9; |
| 2952 | |
| 2953 | switch (mstc->connector.display_info.bpc) { |
| 2954 | case 6: depth = 0x2; break; |
| 2955 | case 8: depth = 0x5; break; |
| 2956 | case 10: |
| 2957 | default: depth = 0x6; break; |
| 2958 | } |
| 2959 | |
| 2960 | mstm->outp->update(mstm->outp, head->base.index, |
| 2961 | &head->base.base.state->adjusted_mode, proto, depth); |
| 2962 | |
| 2963 | msto->head = head; |
| 2964 | msto->mstc = mstc; |
| 2965 | mstm->modified = true; |
| 2966 | } |
| 2967 | |
| 2968 | static void |
| 2969 | nv50_msto_disable(struct drm_encoder *encoder) |
| 2970 | { |
| 2971 | struct nv50_msto *msto = nv50_msto(encoder); |
| 2972 | struct nv50_mstc *mstc = msto->mstc; |
| 2973 | struct nv50_mstm *mstm = mstc->mstm; |
| 2974 | |
| 2975 | if (mstc->port) |
| 2976 | drm_dp_mst_reset_vcpi_slots(&mstm->mgr, mstc->port); |
| 2977 | |
| 2978 | mstm->outp->update(mstm->outp, msto->head->base.index, NULL, 0, 0); |
| 2979 | mstm->modified = true; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 2980 | if (!--mstm->links) |
| 2981 | mstm->disabled = true; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2982 | msto->disabled = true; |
| 2983 | } |
| 2984 | |
| 2985 | static const struct drm_encoder_helper_funcs |
| 2986 | nv50_msto_help = { |
| 2987 | .disable = nv50_msto_disable, |
| 2988 | .enable = nv50_msto_enable, |
| 2989 | .atomic_check = nv50_msto_atomic_check, |
| 2990 | }; |
| 2991 | |
| 2992 | static void |
| 2993 | nv50_msto_destroy(struct drm_encoder *encoder) |
| 2994 | { |
| 2995 | struct nv50_msto *msto = nv50_msto(encoder); |
| 2996 | drm_encoder_cleanup(&msto->encoder); |
| 2997 | kfree(msto); |
| 2998 | } |
| 2999 | |
| 3000 | static const struct drm_encoder_funcs |
| 3001 | nv50_msto = { |
| 3002 | .destroy = nv50_msto_destroy, |
| 3003 | }; |
| 3004 | |
| 3005 | static int |
| 3006 | nv50_msto_new(struct drm_device *dev, u32 heads, const char *name, int id, |
| 3007 | struct nv50_msto **pmsto) |
| 3008 | { |
| 3009 | struct nv50_msto *msto; |
| 3010 | int ret; |
| 3011 | |
| 3012 | if (!(msto = *pmsto = kzalloc(sizeof(*msto), GFP_KERNEL))) |
| 3013 | return -ENOMEM; |
| 3014 | |
| 3015 | ret = drm_encoder_init(dev, &msto->encoder, &nv50_msto, |
| 3016 | DRM_MODE_ENCODER_DPMST, "%s-mst-%d", name, id); |
| 3017 | if (ret) { |
| 3018 | kfree(*pmsto); |
| 3019 | *pmsto = NULL; |
| 3020 | return ret; |
| 3021 | } |
| 3022 | |
| 3023 | drm_encoder_helper_add(&msto->encoder, &nv50_msto_help); |
| 3024 | msto->encoder.possible_crtcs = heads; |
| 3025 | return 0; |
| 3026 | } |
| 3027 | |
| 3028 | static struct drm_encoder * |
| 3029 | nv50_mstc_atomic_best_encoder(struct drm_connector *connector, |
| 3030 | struct drm_connector_state *connector_state) |
| 3031 | { |
| 3032 | struct nv50_head *head = nv50_head(connector_state->crtc); |
| 3033 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 3034 | if (mstc->port) { |
| 3035 | struct nv50_mstm *mstm = mstc->mstm; |
| 3036 | return &mstm->msto[head->base.index]->encoder; |
| 3037 | } |
| 3038 | return NULL; |
| 3039 | } |
| 3040 | |
| 3041 | static struct drm_encoder * |
| 3042 | nv50_mstc_best_encoder(struct drm_connector *connector) |
| 3043 | { |
| 3044 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 3045 | if (mstc->port) { |
| 3046 | struct nv50_mstm *mstm = mstc->mstm; |
| 3047 | return &mstm->msto[0]->encoder; |
| 3048 | } |
| 3049 | return NULL; |
| 3050 | } |
| 3051 | |
| 3052 | static enum drm_mode_status |
| 3053 | nv50_mstc_mode_valid(struct drm_connector *connector, |
| 3054 | struct drm_display_mode *mode) |
| 3055 | { |
| 3056 | return MODE_OK; |
| 3057 | } |
| 3058 | |
| 3059 | static int |
| 3060 | nv50_mstc_get_modes(struct drm_connector *connector) |
| 3061 | { |
| 3062 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 3063 | int ret = 0; |
| 3064 | |
| 3065 | mstc->edid = drm_dp_mst_get_edid(&mstc->connector, mstc->port->mgr, mstc->port); |
| 3066 | drm_mode_connector_update_edid_property(&mstc->connector, mstc->edid); |
| 3067 | if (mstc->edid) { |
| 3068 | ret = drm_add_edid_modes(&mstc->connector, mstc->edid); |
| 3069 | drm_edid_to_eld(&mstc->connector, mstc->edid); |
| 3070 | } |
| 3071 | |
| 3072 | if (!mstc->connector.display_info.bpc) |
| 3073 | mstc->connector.display_info.bpc = 8; |
| 3074 | |
| 3075 | if (mstc->native) |
| 3076 | drm_mode_destroy(mstc->connector.dev, mstc->native); |
| 3077 | mstc->native = nouveau_conn_native_mode(&mstc->connector); |
| 3078 | return ret; |
| 3079 | } |
| 3080 | |
| 3081 | static const struct drm_connector_helper_funcs |
| 3082 | nv50_mstc_help = { |
| 3083 | .get_modes = nv50_mstc_get_modes, |
| 3084 | .mode_valid = nv50_mstc_mode_valid, |
| 3085 | .best_encoder = nv50_mstc_best_encoder, |
| 3086 | .atomic_best_encoder = nv50_mstc_atomic_best_encoder, |
| 3087 | }; |
| 3088 | |
| 3089 | static enum drm_connector_status |
| 3090 | nv50_mstc_detect(struct drm_connector *connector, bool force) |
| 3091 | { |
| 3092 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 3093 | if (!mstc->port) |
| 3094 | return connector_status_disconnected; |
| 3095 | return drm_dp_mst_detect_port(connector, mstc->port->mgr, mstc->port); |
| 3096 | } |
| 3097 | |
| 3098 | static void |
| 3099 | nv50_mstc_destroy(struct drm_connector *connector) |
| 3100 | { |
| 3101 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 3102 | drm_connector_cleanup(&mstc->connector); |
| 3103 | kfree(mstc); |
| 3104 | } |
| 3105 | |
| 3106 | static const struct drm_connector_funcs |
| 3107 | nv50_mstc = { |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3108 | .reset = nouveau_conn_reset, |
| 3109 | .detect = nv50_mstc_detect, |
| 3110 | .fill_modes = drm_helper_probe_single_connector_modes, |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3111 | .destroy = nv50_mstc_destroy, |
| 3112 | .atomic_duplicate_state = nouveau_conn_atomic_duplicate_state, |
| 3113 | .atomic_destroy_state = nouveau_conn_atomic_destroy_state, |
| 3114 | .atomic_set_property = nouveau_conn_atomic_set_property, |
| 3115 | .atomic_get_property = nouveau_conn_atomic_get_property, |
| 3116 | }; |
| 3117 | |
| 3118 | static int |
| 3119 | nv50_mstc_new(struct nv50_mstm *mstm, struct drm_dp_mst_port *port, |
| 3120 | const char *path, struct nv50_mstc **pmstc) |
| 3121 | { |
| 3122 | struct drm_device *dev = mstm->outp->base.base.dev; |
| 3123 | struct nv50_mstc *mstc; |
| 3124 | int ret, i; |
| 3125 | |
| 3126 | if (!(mstc = *pmstc = kzalloc(sizeof(*mstc), GFP_KERNEL))) |
| 3127 | return -ENOMEM; |
| 3128 | mstc->mstm = mstm; |
| 3129 | mstc->port = port; |
| 3130 | |
| 3131 | ret = drm_connector_init(dev, &mstc->connector, &nv50_mstc, |
| 3132 | DRM_MODE_CONNECTOR_DisplayPort); |
| 3133 | if (ret) { |
| 3134 | kfree(*pmstc); |
| 3135 | *pmstc = NULL; |
| 3136 | return ret; |
| 3137 | } |
| 3138 | |
| 3139 | drm_connector_helper_add(&mstc->connector, &nv50_mstc_help); |
| 3140 | |
| 3141 | mstc->connector.funcs->reset(&mstc->connector); |
| 3142 | nouveau_conn_attach_properties(&mstc->connector); |
| 3143 | |
| 3144 | for (i = 0; i < ARRAY_SIZE(mstm->msto) && mstm->msto; i++) |
| 3145 | drm_mode_connector_attach_encoder(&mstc->connector, &mstm->msto[i]->encoder); |
| 3146 | |
| 3147 | drm_object_attach_property(&mstc->connector.base, dev->mode_config.path_property, 0); |
| 3148 | drm_object_attach_property(&mstc->connector.base, dev->mode_config.tile_property, 0); |
| 3149 | drm_mode_connector_set_path_property(&mstc->connector, path); |
| 3150 | return 0; |
| 3151 | } |
| 3152 | |
| 3153 | static void |
| 3154 | nv50_mstm_cleanup(struct nv50_mstm *mstm) |
| 3155 | { |
| 3156 | struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev); |
| 3157 | struct drm_encoder *encoder; |
| 3158 | int ret; |
| 3159 | |
| 3160 | NV_ATOMIC(drm, "%s: mstm cleanup\n", mstm->outp->base.base.name); |
| 3161 | ret = drm_dp_check_act_status(&mstm->mgr); |
| 3162 | |
| 3163 | ret = drm_dp_update_payload_part2(&mstm->mgr); |
| 3164 | |
| 3165 | drm_for_each_encoder(encoder, mstm->outp->base.base.dev) { |
| 3166 | if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) { |
| 3167 | struct nv50_msto *msto = nv50_msto(encoder); |
| 3168 | struct nv50_mstc *mstc = msto->mstc; |
| 3169 | if (mstc && mstc->mstm == mstm) |
| 3170 | nv50_msto_cleanup(msto); |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | mstm->modified = false; |
| 3175 | } |
| 3176 | |
| 3177 | static void |
| 3178 | nv50_mstm_prepare(struct nv50_mstm *mstm) |
| 3179 | { |
| 3180 | struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev); |
| 3181 | struct drm_encoder *encoder; |
| 3182 | int ret; |
| 3183 | |
| 3184 | NV_ATOMIC(drm, "%s: mstm prepare\n", mstm->outp->base.base.name); |
| 3185 | ret = drm_dp_update_payload_part1(&mstm->mgr); |
| 3186 | |
| 3187 | drm_for_each_encoder(encoder, mstm->outp->base.base.dev) { |
| 3188 | if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) { |
| 3189 | struct nv50_msto *msto = nv50_msto(encoder); |
| 3190 | struct nv50_mstc *mstc = msto->mstc; |
| 3191 | if (mstc && mstc->mstm == mstm) |
| 3192 | nv50_msto_prepare(msto); |
| 3193 | } |
| 3194 | } |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 3195 | |
| 3196 | if (mstm->disabled) { |
| 3197 | if (!mstm->links) |
| 3198 | nv50_outp_release(mstm->outp); |
| 3199 | mstm->disabled = false; |
| 3200 | } |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | static void |
| 3204 | nv50_mstm_hotplug(struct drm_dp_mst_topology_mgr *mgr) |
| 3205 | { |
| 3206 | struct nv50_mstm *mstm = nv50_mstm(mgr); |
| 3207 | drm_kms_helper_hotplug_event(mstm->outp->base.base.dev); |
| 3208 | } |
| 3209 | |
| 3210 | static void |
| 3211 | nv50_mstm_destroy_connector(struct drm_dp_mst_topology_mgr *mgr, |
| 3212 | struct drm_connector *connector) |
| 3213 | { |
| 3214 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
| 3215 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 3216 | |
| 3217 | drm_connector_unregister(&mstc->connector); |
| 3218 | |
| 3219 | drm_modeset_lock_all(drm->dev); |
| 3220 | drm_fb_helper_remove_one_connector(&drm->fbcon->helper, &mstc->connector); |
| 3221 | mstc->port = NULL; |
| 3222 | drm_modeset_unlock_all(drm->dev); |
| 3223 | |
| 3224 | drm_connector_unreference(&mstc->connector); |
| 3225 | } |
| 3226 | |
| 3227 | static void |
| 3228 | nv50_mstm_register_connector(struct drm_connector *connector) |
| 3229 | { |
| 3230 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
| 3231 | |
| 3232 | drm_modeset_lock_all(drm->dev); |
| 3233 | drm_fb_helper_add_one_connector(&drm->fbcon->helper, connector); |
| 3234 | drm_modeset_unlock_all(drm->dev); |
| 3235 | |
| 3236 | drm_connector_register(connector); |
| 3237 | } |
| 3238 | |
| 3239 | static struct drm_connector * |
| 3240 | nv50_mstm_add_connector(struct drm_dp_mst_topology_mgr *mgr, |
| 3241 | struct drm_dp_mst_port *port, const char *path) |
| 3242 | { |
| 3243 | struct nv50_mstm *mstm = nv50_mstm(mgr); |
| 3244 | struct nv50_mstc *mstc; |
| 3245 | int ret; |
| 3246 | |
| 3247 | ret = nv50_mstc_new(mstm, port, path, &mstc); |
| 3248 | if (ret) { |
| 3249 | if (mstc) |
| 3250 | mstc->connector.funcs->destroy(&mstc->connector); |
| 3251 | return NULL; |
| 3252 | } |
| 3253 | |
| 3254 | return &mstc->connector; |
| 3255 | } |
| 3256 | |
| 3257 | static const struct drm_dp_mst_topology_cbs |
| 3258 | nv50_mstm = { |
| 3259 | .add_connector = nv50_mstm_add_connector, |
| 3260 | .register_connector = nv50_mstm_register_connector, |
| 3261 | .destroy_connector = nv50_mstm_destroy_connector, |
| 3262 | .hotplug = nv50_mstm_hotplug, |
| 3263 | }; |
| 3264 | |
| 3265 | void |
| 3266 | nv50_mstm_service(struct nv50_mstm *mstm) |
| 3267 | { |
| 3268 | struct drm_dp_aux *aux = mstm->mgr.aux; |
| 3269 | bool handled = true; |
| 3270 | int ret; |
| 3271 | u8 esi[8] = {}; |
| 3272 | |
| 3273 | while (handled) { |
| 3274 | ret = drm_dp_dpcd_read(aux, DP_SINK_COUNT_ESI, esi, 8); |
| 3275 | if (ret != 8) { |
| 3276 | drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, false); |
| 3277 | return; |
| 3278 | } |
| 3279 | |
| 3280 | drm_dp_mst_hpd_irq(&mstm->mgr, esi, &handled); |
| 3281 | if (!handled) |
| 3282 | break; |
| 3283 | |
| 3284 | drm_dp_dpcd_write(aux, DP_SINK_COUNT_ESI + 1, &esi[1], 3); |
| 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | void |
| 3289 | nv50_mstm_remove(struct nv50_mstm *mstm) |
| 3290 | { |
| 3291 | if (mstm) |
| 3292 | drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, false); |
| 3293 | } |
| 3294 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3295 | static int |
| 3296 | nv50_mstm_enable(struct nv50_mstm *mstm, u8 dpcd, int state) |
| 3297 | { |
| 3298 | struct nouveau_encoder *outp = mstm->outp; |
| 3299 | struct { |
| 3300 | struct nv50_disp_mthd_v1 base; |
| 3301 | struct nv50_disp_sor_dp_mst_link_v0 mst; |
| 3302 | } args = { |
| 3303 | .base.version = 1, |
| 3304 | .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_LINK, |
| 3305 | .base.hasht = outp->dcb->hasht, |
| 3306 | .base.hashm = outp->dcb->hashm, |
| 3307 | .mst.state = state, |
| 3308 | }; |
| 3309 | struct nouveau_drm *drm = nouveau_drm(outp->base.base.dev); |
| 3310 | struct nvif_object *disp = &drm->display->disp; |
| 3311 | int ret; |
| 3312 | |
| 3313 | if (dpcd >= 0x12) { |
| 3314 | ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CTRL, &dpcd); |
| 3315 | if (ret < 0) |
| 3316 | return ret; |
| 3317 | |
| 3318 | dpcd &= ~DP_MST_EN; |
| 3319 | if (state) |
| 3320 | dpcd |= DP_MST_EN; |
| 3321 | |
| 3322 | ret = drm_dp_dpcd_writeb(mstm->mgr.aux, DP_MSTM_CTRL, dpcd); |
| 3323 | if (ret < 0) |
| 3324 | return ret; |
| 3325 | } |
| 3326 | |
| 3327 | return nvif_mthd(disp, 0, &args, sizeof(args)); |
| 3328 | } |
| 3329 | |
| 3330 | int |
| 3331 | nv50_mstm_detect(struct nv50_mstm *mstm, u8 dpcd[8], int allow) |
| 3332 | { |
| 3333 | int ret, state = 0; |
| 3334 | |
| 3335 | if (!mstm) |
| 3336 | return 0; |
| 3337 | |
Ben Skeggs | 3ca03ca | 2016-11-07 14:51:53 +1000 | [diff] [blame] | 3338 | if (dpcd[0] >= 0x12) { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3339 | ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CAP, &dpcd[1]); |
| 3340 | if (ret < 0) |
| 3341 | return ret; |
| 3342 | |
Ben Skeggs | 3ca03ca | 2016-11-07 14:51:53 +1000 | [diff] [blame] | 3343 | if (!(dpcd[1] & DP_MST_CAP)) |
| 3344 | dpcd[0] = 0x11; |
| 3345 | else |
| 3346 | state = allow; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | ret = nv50_mstm_enable(mstm, dpcd[0], state); |
| 3350 | if (ret) |
| 3351 | return ret; |
| 3352 | |
| 3353 | ret = drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, state); |
| 3354 | if (ret) |
| 3355 | return nv50_mstm_enable(mstm, dpcd[0], 0); |
| 3356 | |
| 3357 | return mstm->mgr.mst_state; |
| 3358 | } |
| 3359 | |
| 3360 | static void |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3361 | nv50_mstm_fini(struct nv50_mstm *mstm) |
| 3362 | { |
| 3363 | if (mstm && mstm->mgr.mst_state) |
| 3364 | drm_dp_mst_topology_mgr_suspend(&mstm->mgr); |
| 3365 | } |
| 3366 | |
| 3367 | static void |
| 3368 | nv50_mstm_init(struct nv50_mstm *mstm) |
| 3369 | { |
| 3370 | if (mstm && mstm->mgr.mst_state) |
| 3371 | drm_dp_mst_topology_mgr_resume(&mstm->mgr); |
| 3372 | } |
| 3373 | |
| 3374 | static void |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3375 | nv50_mstm_del(struct nv50_mstm **pmstm) |
| 3376 | { |
| 3377 | struct nv50_mstm *mstm = *pmstm; |
| 3378 | if (mstm) { |
| 3379 | kfree(*pmstm); |
| 3380 | *pmstm = NULL; |
| 3381 | } |
| 3382 | } |
| 3383 | |
| 3384 | static int |
| 3385 | nv50_mstm_new(struct nouveau_encoder *outp, struct drm_dp_aux *aux, int aux_max, |
| 3386 | int conn_base_id, struct nv50_mstm **pmstm) |
| 3387 | { |
| 3388 | const int max_payloads = hweight8(outp->dcb->heads); |
| 3389 | struct drm_device *dev = outp->base.base.dev; |
| 3390 | struct nv50_mstm *mstm; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3391 | int ret, i; |
| 3392 | u8 dpcd; |
| 3393 | |
| 3394 | /* This is a workaround for some monitors not functioning |
| 3395 | * correctly in MST mode on initial module load. I think |
| 3396 | * some bad interaction with the VBIOS may be responsible. |
| 3397 | * |
| 3398 | * A good ol' off and on again seems to work here ;) |
| 3399 | */ |
| 3400 | ret = drm_dp_dpcd_readb(aux, DP_DPCD_REV, &dpcd); |
| 3401 | if (ret >= 0 && dpcd >= 0x12) |
| 3402 | drm_dp_dpcd_writeb(aux, DP_MSTM_CTRL, 0); |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3403 | |
| 3404 | if (!(mstm = *pmstm = kzalloc(sizeof(*mstm), GFP_KERNEL))) |
| 3405 | return -ENOMEM; |
| 3406 | mstm->outp = outp; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3407 | mstm->mgr.cbs = &nv50_mstm; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3408 | |
Dhinakaran Pandiyan | 7b0a89a | 2017-01-24 15:49:29 -0800 | [diff] [blame] | 3409 | ret = drm_dp_mst_topology_mgr_init(&mstm->mgr, dev, aux, aux_max, |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3410 | max_payloads, conn_base_id); |
| 3411 | if (ret) |
| 3412 | return ret; |
| 3413 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3414 | for (i = 0; i < max_payloads; i++) { |
| 3415 | ret = nv50_msto_new(dev, outp->dcb->heads, outp->base.base.name, |
| 3416 | i, &mstm->msto[i]); |
| 3417 | if (ret) |
| 3418 | return ret; |
| 3419 | } |
| 3420 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3421 | return 0; |
| 3422 | } |
| 3423 | |
| 3424 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3425 | * SOR |
| 3426 | *****************************************************************************/ |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 3427 | static void |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3428 | nv50_sor_update(struct nouveau_encoder *nv_encoder, u8 head, |
| 3429 | struct drm_display_mode *mode, u8 proto, u8 depth) |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3430 | { |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3431 | struct nv50_dmac *core = &nv50_mast(nv_encoder->base.base.dev)->base; |
| 3432 | u32 *push; |
| 3433 | |
| 3434 | if (!mode) { |
| 3435 | nv_encoder->ctrl &= ~BIT(head); |
| 3436 | if (!(nv_encoder->ctrl & 0x0000000f)) |
| 3437 | nv_encoder->ctrl = 0; |
| 3438 | } else { |
| 3439 | nv_encoder->ctrl |= proto << 8; |
| 3440 | nv_encoder->ctrl |= BIT(head); |
| 3441 | } |
| 3442 | |
| 3443 | if ((push = evo_wait(core, 6))) { |
| 3444 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 3445 | if (mode) { |
| 3446 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 3447 | nv_encoder->ctrl |= 0x00001000; |
| 3448 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 3449 | nv_encoder->ctrl |= 0x00002000; |
| 3450 | nv_encoder->ctrl |= depth << 16; |
| 3451 | } |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3452 | evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3453 | } else { |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3454 | if (mode) { |
| 3455 | u32 magic = 0x31ec6000 | (head << 25); |
| 3456 | u32 syncs = 0x00000001; |
| 3457 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 3458 | syncs |= 0x00000008; |
| 3459 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 3460 | syncs |= 0x00000010; |
| 3461 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 3462 | magic |= 0x00000001; |
| 3463 | |
| 3464 | evo_mthd(push, 0x0404 + (head * 0x300), 2); |
| 3465 | evo_data(push, syncs | (depth << 6)); |
| 3466 | evo_data(push, magic); |
| 3467 | } |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3468 | evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3469 | } |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3470 | evo_data(push, nv_encoder->ctrl); |
| 3471 | evo_kick(push, core); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3472 | } |
| 3473 | } |
| 3474 | |
| 3475 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3476 | nv50_sor_disable(struct drm_encoder *encoder) |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 3477 | { |
| 3478 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3479 | struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc); |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3480 | |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3481 | nv_encoder->crtc = NULL; |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3482 | |
| 3483 | if (nv_crtc) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3484 | struct nvkm_i2c_aux *aux = nv_encoder->aux; |
| 3485 | u8 pwr; |
| 3486 | |
| 3487 | if (aux) { |
| 3488 | int ret = nvkm_rdaux(aux, DP_SET_POWER, &pwr, 1); |
| 3489 | if (ret == 0) { |
| 3490 | pwr &= ~DP_SET_POWER_MASK; |
| 3491 | pwr |= DP_SET_POWER_D3; |
| 3492 | nvkm_wraux(aux, DP_SET_POWER, &pwr, 1); |
| 3493 | } |
| 3494 | } |
| 3495 | |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3496 | nv_encoder->update(nv_encoder, nv_crtc->index, NULL, 0, 0); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3497 | nv50_audio_disable(encoder, nv_crtc); |
| 3498 | nv50_hdmi_disable(&nv_encoder->base.base, nv_crtc); |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 3499 | nv50_outp_release(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3500 | } |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3504 | nv50_sor_enable(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3505 | { |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3506 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 3507 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3508 | struct drm_display_mode *mode = &nv_crtc->base.state->adjusted_mode; |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3509 | struct { |
| 3510 | struct nv50_disp_mthd_v1 base; |
| 3511 | struct nv50_disp_sor_lvds_script_v0 lvds; |
| 3512 | } lvds = { |
| 3513 | .base.version = 1, |
| 3514 | .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT, |
| 3515 | .base.hasht = nv_encoder->dcb->hasht, |
| 3516 | .base.hashm = nv_encoder->dcb->hashm, |
| 3517 | }; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3518 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3519 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 3520 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3521 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 3522 | struct nvbios *bios = &drm->vbios; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3523 | u8 proto = 0xf; |
| 3524 | u8 depth = 0x0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3525 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3526 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3527 | nv_encoder->crtc = encoder->crtc; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 3528 | nv50_outp_acquire(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3529 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3530 | switch (nv_encoder->dcb->type) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 3531 | case DCB_OUTPUT_TMDS: |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 3532 | if (nv_encoder->link & 1) { |
Hauke Mehrtens | 16ef53a9 | 2015-11-03 21:00:10 -0500 | [diff] [blame] | 3533 | proto = 0x1; |
| 3534 | /* Only enable dual-link if: |
| 3535 | * - Need to (i.e. rate > 165MHz) |
| 3536 | * - DCB says we can |
| 3537 | * - Not an HDMI monitor, since there's no dual-link |
| 3538 | * on HDMI. |
| 3539 | */ |
| 3540 | if (mode->clock >= 165000 && |
| 3541 | nv_encoder->dcb->duallink_possible && |
| 3542 | !drm_detect_hdmi_monitor(nv_connector->edid)) |
| 3543 | proto |= 0x4; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3544 | } else { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3545 | proto = 0x2; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3546 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3547 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3548 | nv50_hdmi_enable(&nv_encoder->base.base, mode); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3549 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 3550 | case DCB_OUTPUT_LVDS: |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3551 | proto = 0x0; |
| 3552 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3553 | if (bios->fp_no_ddc) { |
| 3554 | if (bios->fp.dual_link) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3555 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3556 | if (bios->fp.if_is_24bit) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3557 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3558 | } else { |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 3559 | if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3560 | if (((u8 *)nv_connector->edid)[121] == 2) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3561 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3562 | } else |
| 3563 | if (mode->clock >= bios->fp.duallink_transition_clk) { |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3564 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3565 | } |
| 3566 | |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3567 | if (lvds.lvds.script & 0x0100) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3568 | if (bios->fp.strapless_is_24bit & 2) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3569 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3570 | } else { |
| 3571 | if (bios->fp.strapless_is_24bit & 1) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3572 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3573 | } |
| 3574 | |
| 3575 | if (nv_connector->base.display_info.bpc == 8) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3576 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3577 | } |
Ben Skeggs | 4a230fa | 2012-11-09 11:25:37 +1000 | [diff] [blame] | 3578 | |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3579 | nvif_mthd(disp->disp, 0, &lvds, sizeof(lvds)); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3580 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 3581 | case DCB_OUTPUT_DP: |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3582 | if (nv_connector->base.display_info.bpc == 6) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3583 | depth = 0x2; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3584 | else |
| 3585 | if (nv_connector->base.display_info.bpc == 8) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3586 | depth = 0x5; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3587 | else |
Ben Skeggs | bf2c886 | 2012-11-21 14:49:54 +1000 | [diff] [blame] | 3588 | depth = 0x6; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 3589 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 3590 | if (nv_encoder->link & 1) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3591 | proto = 0x8; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 3592 | else |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3593 | proto = 0x9; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3594 | |
| 3595 | nv50_audio_enable(encoder, mode); |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 3596 | break; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3597 | default: |
Ben Skeggs | af7db03 | 2016-03-03 12:56:33 +1000 | [diff] [blame] | 3598 | BUG(); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3599 | break; |
| 3600 | } |
Ben Skeggs | ff8ff50 | 2011-07-08 11:53:37 +1000 | [diff] [blame] | 3601 | |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3602 | nv_encoder->update(nv_encoder, nv_crtc->index, mode, proto, depth); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3603 | } |
| 3604 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3605 | static const struct drm_encoder_helper_funcs |
| 3606 | nv50_sor_help = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3607 | .atomic_check = nv50_outp_atomic_check, |
| 3608 | .enable = nv50_sor_enable, |
| 3609 | .disable = nv50_sor_disable, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3610 | }; |
| 3611 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3612 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3613 | nv50_sor_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3614 | { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3615 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 3616 | nv50_mstm_del(&nv_encoder->dp.mstm); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3617 | drm_encoder_cleanup(encoder); |
| 3618 | kfree(encoder); |
| 3619 | } |
| 3620 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3621 | static const struct drm_encoder_funcs |
| 3622 | nv50_sor_func = { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3623 | .destroy = nv50_sor_destroy, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3624 | }; |
| 3625 | |
| 3626 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3627 | nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3628 | { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3629 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 3630 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 3631 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3632 | struct nouveau_encoder *nv_encoder; |
| 3633 | struct drm_encoder *encoder; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3634 | int type, ret; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 3635 | |
| 3636 | switch (dcbe->type) { |
| 3637 | case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break; |
| 3638 | case DCB_OUTPUT_TMDS: |
| 3639 | case DCB_OUTPUT_DP: |
| 3640 | default: |
| 3641 | type = DRM_MODE_ENCODER_TMDS; |
| 3642 | break; |
| 3643 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3644 | |
| 3645 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 3646 | if (!nv_encoder) |
| 3647 | return -ENOMEM; |
| 3648 | nv_encoder->dcb = dcbe; |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3649 | nv_encoder->update = nv50_sor_update; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3650 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3651 | encoder = to_drm_encoder(nv_encoder); |
| 3652 | encoder->possible_crtcs = dcbe->heads; |
| 3653 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3654 | drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type, |
| 3655 | "sor-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3656 | drm_encoder_helper_add(encoder, &nv50_sor_help); |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3657 | |
| 3658 | drm_mode_connector_attach_encoder(connector, encoder); |
| 3659 | |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3660 | if (dcbe->type == DCB_OUTPUT_DP) { |
Ben Skeggs | 13a8651 | 2017-07-19 16:49:59 +1000 | [diff] [blame] | 3661 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3662 | struct nvkm_i2c_aux *aux = |
| 3663 | nvkm_i2c_aux_find(i2c, dcbe->i2c_index); |
| 3664 | if (aux) { |
Ben Skeggs | 13a8651 | 2017-07-19 16:49:59 +1000 | [diff] [blame] | 3665 | if (disp->disp->oclass < GF110_DISP) { |
| 3666 | /* HW has no support for address-only |
| 3667 | * transactions, so we're required to |
| 3668 | * use custom I2C-over-AUX code. |
| 3669 | */ |
| 3670 | nv_encoder->i2c = &aux->i2c; |
| 3671 | } else { |
| 3672 | nv_encoder->i2c = &nv_connector->aux.ddc; |
| 3673 | } |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3674 | nv_encoder->aux = aux; |
| 3675 | } |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3676 | |
| 3677 | /*TODO: Use DP Info Table to check for support. */ |
Ben Skeggs | 13a8651 | 2017-07-19 16:49:59 +1000 | [diff] [blame] | 3678 | if (disp->disp->oclass >= GF110_DISP) { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3679 | ret = nv50_mstm_new(nv_encoder, &nv_connector->aux, 16, |
| 3680 | nv_connector->base.base.id, |
| 3681 | &nv_encoder->dp.mstm); |
| 3682 | if (ret) |
| 3683 | return ret; |
| 3684 | } |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3685 | } else { |
| 3686 | struct nvkm_i2c_bus *bus = |
| 3687 | nvkm_i2c_bus_find(i2c, dcbe->i2c_index); |
| 3688 | if (bus) |
| 3689 | nv_encoder->i2c = &bus->i2c; |
| 3690 | } |
| 3691 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3692 | return 0; |
| 3693 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3694 | |
| 3695 | /****************************************************************************** |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3696 | * PIOR |
| 3697 | *****************************************************************************/ |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3698 | static int |
| 3699 | nv50_pior_atomic_check(struct drm_encoder *encoder, |
| 3700 | struct drm_crtc_state *crtc_state, |
| 3701 | struct drm_connector_state *conn_state) |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3702 | { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3703 | int ret = nv50_outp_atomic_check(encoder, crtc_state, conn_state); |
| 3704 | if (ret) |
| 3705 | return ret; |
| 3706 | crtc_state->adjusted_mode.clock *= 2; |
| 3707 | return 0; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3711 | nv50_pior_disable(struct drm_encoder *encoder) |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3712 | { |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3713 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 3714 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
| 3715 | const int or = nv_encoder->or; |
| 3716 | u32 *push; |
| 3717 | |
| 3718 | if (nv_encoder->crtc) { |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3719 | push = evo_wait(mast, 4); |
| 3720 | if (push) { |
| 3721 | if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) { |
| 3722 | evo_mthd(push, 0x0700 + (or * 0x040), 1); |
| 3723 | evo_data(push, 0x00000000); |
| 3724 | } |
| 3725 | evo_kick(push, mast); |
| 3726 | } |
| 3727 | } |
| 3728 | |
| 3729 | nv_encoder->crtc = NULL; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 3730 | nv50_outp_release(nv_encoder); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3734 | nv50_pior_enable(struct drm_encoder *encoder) |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3735 | { |
| 3736 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
| 3737 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 3738 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
| 3739 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3740 | struct drm_display_mode *mode = &nv_crtc->base.state->adjusted_mode; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3741 | u8 owner = 1 << nv_crtc->index; |
| 3742 | u8 proto, depth; |
| 3743 | u32 *push; |
| 3744 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 3745 | nv50_outp_acquire(nv_encoder); |
| 3746 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3747 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 3748 | switch (nv_connector->base.display_info.bpc) { |
| 3749 | case 10: depth = 0x6; break; |
| 3750 | case 8: depth = 0x5; break; |
| 3751 | case 6: depth = 0x2; break; |
| 3752 | default: depth = 0x0; break; |
| 3753 | } |
| 3754 | |
| 3755 | switch (nv_encoder->dcb->type) { |
| 3756 | case DCB_OUTPUT_TMDS: |
| 3757 | case DCB_OUTPUT_DP: |
| 3758 | proto = 0x0; |
| 3759 | break; |
| 3760 | default: |
Ben Skeggs | af7db03 | 2016-03-03 12:56:33 +1000 | [diff] [blame] | 3761 | BUG(); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3762 | break; |
| 3763 | } |
| 3764 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3765 | push = evo_wait(mast, 8); |
| 3766 | if (push) { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3767 | if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) { |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3768 | u32 ctrl = (depth << 16) | (proto << 8) | owner; |
| 3769 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 3770 | ctrl |= 0x00001000; |
| 3771 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 3772 | ctrl |= 0x00002000; |
| 3773 | evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1); |
| 3774 | evo_data(push, ctrl); |
| 3775 | } |
| 3776 | |
| 3777 | evo_kick(push, mast); |
| 3778 | } |
| 3779 | |
| 3780 | nv_encoder->crtc = encoder->crtc; |
| 3781 | } |
| 3782 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3783 | static const struct drm_encoder_helper_funcs |
| 3784 | nv50_pior_help = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3785 | .atomic_check = nv50_pior_atomic_check, |
| 3786 | .enable = nv50_pior_enable, |
| 3787 | .disable = nv50_pior_disable, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3788 | }; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3789 | |
| 3790 | static void |
| 3791 | nv50_pior_destroy(struct drm_encoder *encoder) |
| 3792 | { |
| 3793 | drm_encoder_cleanup(encoder); |
| 3794 | kfree(encoder); |
| 3795 | } |
| 3796 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3797 | static const struct drm_encoder_funcs |
| 3798 | nv50_pior_func = { |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3799 | .destroy = nv50_pior_destroy, |
| 3800 | }; |
| 3801 | |
| 3802 | static int |
| 3803 | nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe) |
| 3804 | { |
Ben Skeggs | df8dc97 | 2017-03-01 09:42:04 +1000 | [diff] [blame] | 3805 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3806 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 3807 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3808 | struct nvkm_i2c_bus *bus = NULL; |
| 3809 | struct nvkm_i2c_aux *aux = NULL; |
| 3810 | struct i2c_adapter *ddc; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3811 | struct nouveau_encoder *nv_encoder; |
| 3812 | struct drm_encoder *encoder; |
| 3813 | int type; |
| 3814 | |
| 3815 | switch (dcbe->type) { |
| 3816 | case DCB_OUTPUT_TMDS: |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3817 | bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev)); |
| 3818 | ddc = bus ? &bus->i2c : NULL; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3819 | type = DRM_MODE_ENCODER_TMDS; |
| 3820 | break; |
| 3821 | case DCB_OUTPUT_DP: |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3822 | aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev)); |
Ben Skeggs | df8dc97 | 2017-03-01 09:42:04 +1000 | [diff] [blame] | 3823 | ddc = aux ? &nv_connector->aux.ddc : NULL; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3824 | type = DRM_MODE_ENCODER_TMDS; |
| 3825 | break; |
| 3826 | default: |
| 3827 | return -ENODEV; |
| 3828 | } |
| 3829 | |
| 3830 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 3831 | if (!nv_encoder) |
| 3832 | return -ENOMEM; |
| 3833 | nv_encoder->dcb = dcbe; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3834 | nv_encoder->i2c = ddc; |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3835 | nv_encoder->aux = aux; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3836 | |
| 3837 | encoder = to_drm_encoder(nv_encoder); |
| 3838 | encoder->possible_crtcs = dcbe->heads; |
| 3839 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3840 | drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type, |
| 3841 | "pior-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3842 | drm_encoder_helper_add(encoder, &nv50_pior_help); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3843 | |
| 3844 | drm_mode_connector_attach_encoder(connector, encoder); |
| 3845 | return 0; |
| 3846 | } |
| 3847 | |
| 3848 | /****************************************************************************** |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3849 | * Atomic |
| 3850 | *****************************************************************************/ |
| 3851 | |
| 3852 | static void |
| 3853 | nv50_disp_atomic_commit_core(struct nouveau_drm *drm, u32 interlock) |
| 3854 | { |
| 3855 | struct nv50_disp *disp = nv50_disp(drm->dev); |
| 3856 | struct nv50_dmac *core = &disp->mast.base; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3857 | struct nv50_mstm *mstm; |
| 3858 | struct drm_encoder *encoder; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3859 | u32 *push; |
| 3860 | |
| 3861 | NV_ATOMIC(drm, "commit core %08x\n", interlock); |
| 3862 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3863 | drm_for_each_encoder(encoder, drm->dev) { |
| 3864 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
| 3865 | mstm = nouveau_encoder(encoder)->dp.mstm; |
| 3866 | if (mstm && mstm->modified) |
| 3867 | nv50_mstm_prepare(mstm); |
| 3868 | } |
| 3869 | } |
| 3870 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3871 | if ((push = evo_wait(core, 5))) { |
| 3872 | evo_mthd(push, 0x0084, 1); |
| 3873 | evo_data(push, 0x80000000); |
| 3874 | evo_mthd(push, 0x0080, 2); |
| 3875 | evo_data(push, interlock); |
| 3876 | evo_data(push, 0x00000000); |
| 3877 | nouveau_bo_wr32(disp->sync, 0, 0x00000000); |
| 3878 | evo_kick(push, core); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 3879 | if (nvif_msec(&drm->client.device, 2000ULL, |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3880 | if (nouveau_bo_rd32(disp->sync, 0)) |
| 3881 | break; |
| 3882 | usleep_range(1, 2); |
| 3883 | ) < 0) |
| 3884 | NV_ERROR(drm, "EVO timeout\n"); |
| 3885 | } |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3886 | |
| 3887 | drm_for_each_encoder(encoder, drm->dev) { |
| 3888 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
| 3889 | mstm = nouveau_encoder(encoder)->dp.mstm; |
| 3890 | if (mstm && mstm->modified) |
| 3891 | nv50_mstm_cleanup(mstm); |
| 3892 | } |
| 3893 | } |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | static void |
| 3897 | nv50_disp_atomic_commit_tail(struct drm_atomic_state *state) |
| 3898 | { |
| 3899 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame^] | 3900 | struct drm_crtc_state *new_crtc_state, *old_crtc_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3901 | struct drm_crtc *crtc; |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 3902 | struct drm_plane_state *new_plane_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3903 | struct drm_plane *plane; |
| 3904 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 3905 | struct nv50_disp *disp = nv50_disp(dev); |
| 3906 | struct nv50_atom *atom = nv50_atom(state); |
| 3907 | struct nv50_outp_atom *outp, *outt; |
| 3908 | u32 interlock_core = 0; |
| 3909 | u32 interlock_chan = 0; |
| 3910 | int i; |
| 3911 | |
| 3912 | NV_ATOMIC(drm, "commit %d %d\n", atom->lock_core, atom->flush_disable); |
| 3913 | drm_atomic_helper_wait_for_fences(dev, state, false); |
| 3914 | drm_atomic_helper_wait_for_dependencies(state); |
| 3915 | drm_atomic_helper_update_legacy_modeset_state(dev, state); |
| 3916 | |
| 3917 | if (atom->lock_core) |
| 3918 | mutex_lock(&disp->mutex); |
| 3919 | |
| 3920 | /* Disable head(s). */ |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame^] | 3921 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 3922 | struct nv50_head_atom *asyh = nv50_head_atom(new_crtc_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3923 | struct nv50_head *head = nv50_head(crtc); |
| 3924 | |
| 3925 | NV_ATOMIC(drm, "%s: clr %04x (set %04x)\n", crtc->name, |
| 3926 | asyh->clr.mask, asyh->set.mask); |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame^] | 3927 | if (old_crtc_state->active && !new_crtc_state->active) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 3928 | drm_crtc_vblank_off(crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3929 | |
| 3930 | if (asyh->clr.mask) { |
| 3931 | nv50_head_flush_clr(head, asyh, atom->flush_disable); |
| 3932 | interlock_core |= 1; |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | /* Disable plane(s). */ |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 3937 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 3938 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3939 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 3940 | |
| 3941 | NV_ATOMIC(drm, "%s: clr %02x (set %02x)\n", plane->name, |
| 3942 | asyw->clr.mask, asyw->set.mask); |
| 3943 | if (!asyw->clr.mask) |
| 3944 | continue; |
| 3945 | |
| 3946 | interlock_chan |= nv50_wndw_flush_clr(wndw, interlock_core, |
| 3947 | atom->flush_disable, |
| 3948 | asyw); |
| 3949 | } |
| 3950 | |
| 3951 | /* Disable output path(s). */ |
| 3952 | list_for_each_entry(outp, &atom->outp, head) { |
| 3953 | const struct drm_encoder_helper_funcs *help; |
| 3954 | struct drm_encoder *encoder; |
| 3955 | |
| 3956 | encoder = outp->encoder; |
| 3957 | help = encoder->helper_private; |
| 3958 | |
| 3959 | NV_ATOMIC(drm, "%s: clr %02x (set %02x)\n", encoder->name, |
| 3960 | outp->clr.mask, outp->set.mask); |
| 3961 | |
| 3962 | if (outp->clr.mask) { |
| 3963 | help->disable(encoder); |
| 3964 | interlock_core |= 1; |
| 3965 | if (outp->flush_disable) { |
| 3966 | nv50_disp_atomic_commit_core(drm, interlock_chan); |
| 3967 | interlock_core = 0; |
| 3968 | interlock_chan = 0; |
| 3969 | } |
| 3970 | } |
| 3971 | } |
| 3972 | |
| 3973 | /* Flush disable. */ |
| 3974 | if (interlock_core) { |
| 3975 | if (atom->flush_disable) { |
| 3976 | nv50_disp_atomic_commit_core(drm, interlock_chan); |
| 3977 | interlock_core = 0; |
| 3978 | interlock_chan = 0; |
| 3979 | } |
| 3980 | } |
| 3981 | |
| 3982 | /* Update output path(s). */ |
| 3983 | list_for_each_entry_safe(outp, outt, &atom->outp, head) { |
| 3984 | const struct drm_encoder_helper_funcs *help; |
| 3985 | struct drm_encoder *encoder; |
| 3986 | |
| 3987 | encoder = outp->encoder; |
| 3988 | help = encoder->helper_private; |
| 3989 | |
| 3990 | NV_ATOMIC(drm, "%s: set %02x (clr %02x)\n", encoder->name, |
| 3991 | outp->set.mask, outp->clr.mask); |
| 3992 | |
| 3993 | if (outp->set.mask) { |
| 3994 | help->enable(encoder); |
| 3995 | interlock_core = 1; |
| 3996 | } |
| 3997 | |
| 3998 | list_del(&outp->head); |
| 3999 | kfree(outp); |
| 4000 | } |
| 4001 | |
| 4002 | /* Update head(s). */ |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame^] | 4003 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4004 | struct nv50_head_atom *asyh = nv50_head_atom(new_crtc_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4005 | struct nv50_head *head = nv50_head(crtc); |
| 4006 | |
| 4007 | NV_ATOMIC(drm, "%s: set %04x (clr %04x)\n", crtc->name, |
| 4008 | asyh->set.mask, asyh->clr.mask); |
| 4009 | |
| 4010 | if (asyh->set.mask) { |
| 4011 | nv50_head_flush_set(head, asyh); |
| 4012 | interlock_core = 1; |
| 4013 | } |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4014 | |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame^] | 4015 | if (new_crtc_state->active) { |
| 4016 | if (!old_crtc_state->active) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 4017 | drm_crtc_vblank_on(crtc); |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame^] | 4018 | if (new_crtc_state->event) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 4019 | drm_crtc_vblank_get(crtc); |
| 4020 | } |
Ben Skeggs | 2b50789 | 2017-01-24 09:32:26 +1000 | [diff] [blame] | 4021 | } |
| 4022 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4023 | /* Update plane(s). */ |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4024 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 4025 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4026 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 4027 | |
| 4028 | NV_ATOMIC(drm, "%s: set %02x (clr %02x)\n", plane->name, |
| 4029 | asyw->set.mask, asyw->clr.mask); |
| 4030 | if ( !asyw->set.mask && |
| 4031 | (!asyw->clr.mask || atom->flush_disable)) |
| 4032 | continue; |
| 4033 | |
| 4034 | interlock_chan |= nv50_wndw_flush_set(wndw, interlock_core, asyw); |
| 4035 | } |
| 4036 | |
| 4037 | /* Flush update. */ |
| 4038 | if (interlock_core) { |
| 4039 | if (!interlock_chan && atom->state.legacy_cursor_update) { |
| 4040 | u32 *push = evo_wait(&disp->mast, 2); |
| 4041 | if (push) { |
| 4042 | evo_mthd(push, 0x0080, 1); |
| 4043 | evo_data(push, 0x00000000); |
| 4044 | evo_kick(push, &disp->mast); |
| 4045 | } |
| 4046 | } else { |
| 4047 | nv50_disp_atomic_commit_core(drm, interlock_chan); |
| 4048 | } |
| 4049 | } |
| 4050 | |
| 4051 | if (atom->lock_core) |
| 4052 | mutex_unlock(&disp->mutex); |
| 4053 | |
| 4054 | /* Wait for HW to signal completion. */ |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4055 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 4056 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4057 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 4058 | int ret = nv50_wndw_wait_armed(wndw, asyw); |
| 4059 | if (ret) |
| 4060 | NV_ERROR(drm, "%s: timeout\n", plane->name); |
| 4061 | } |
| 4062 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4063 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 4064 | if (new_crtc_state->event) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4065 | unsigned long flags; |
Mario Kleiner | bd9f660 | 2016-11-23 07:58:54 +0100 | [diff] [blame] | 4066 | /* Get correct count/ts if racing with vblank irq */ |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame^] | 4067 | if (new_crtc_state->active) |
Dave Airlie | 0c697fa | 2017-08-15 16:16:58 +1000 | [diff] [blame] | 4068 | drm_crtc_accurate_vblank_count(crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4069 | spin_lock_irqsave(&crtc->dev->event_lock, flags); |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4070 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4071 | spin_unlock_irqrestore(&crtc->dev->event_lock, flags); |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame^] | 4072 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4073 | new_crtc_state->event = NULL; |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame^] | 4074 | if (new_crtc_state->active) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 4075 | drm_crtc_vblank_put(crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4076 | } |
| 4077 | } |
| 4078 | |
| 4079 | drm_atomic_helper_commit_hw_done(state); |
| 4080 | drm_atomic_helper_cleanup_planes(dev, state); |
| 4081 | drm_atomic_helper_commit_cleanup_done(state); |
| 4082 | drm_atomic_state_put(state); |
| 4083 | } |
| 4084 | |
| 4085 | static void |
| 4086 | nv50_disp_atomic_commit_work(struct work_struct *work) |
| 4087 | { |
| 4088 | struct drm_atomic_state *state = |
| 4089 | container_of(work, typeof(*state), commit_work); |
| 4090 | nv50_disp_atomic_commit_tail(state); |
| 4091 | } |
| 4092 | |
| 4093 | static int |
| 4094 | nv50_disp_atomic_commit(struct drm_device *dev, |
| 4095 | struct drm_atomic_state *state, bool nonblock) |
| 4096 | { |
| 4097 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 4098 | struct nv50_disp *disp = nv50_disp(dev); |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4099 | struct drm_plane_state *old_plane_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4100 | struct drm_plane *plane; |
| 4101 | struct drm_crtc *crtc; |
| 4102 | bool active = false; |
| 4103 | int ret, i; |
| 4104 | |
| 4105 | ret = pm_runtime_get_sync(dev->dev); |
| 4106 | if (ret < 0 && ret != -EACCES) |
| 4107 | return ret; |
| 4108 | |
| 4109 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 4110 | if (ret) |
| 4111 | goto done; |
| 4112 | |
| 4113 | INIT_WORK(&state->commit_work, nv50_disp_atomic_commit_work); |
| 4114 | |
| 4115 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 4116 | if (ret) |
| 4117 | goto done; |
| 4118 | |
| 4119 | if (!nonblock) { |
| 4120 | ret = drm_atomic_helper_wait_for_fences(dev, state, true); |
| 4121 | if (ret) |
Maarten Lankhorst | 813a7e1 | 2017-07-11 16:33:03 +0200 | [diff] [blame] | 4122 | goto err_cleanup; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4123 | } |
| 4124 | |
Maarten Lankhorst | 8572636 | 2017-07-11 16:33:05 +0200 | [diff] [blame] | 4125 | ret = drm_atomic_helper_swap_state(state, true); |
| 4126 | if (ret) |
| 4127 | goto err_cleanup; |
| 4128 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4129 | for_each_old_plane_in_state(state, plane, old_plane_state, i) { |
| 4130 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(old_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4131 | struct nv50_wndw *wndw = nv50_wndw(plane); |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4132 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4133 | if (asyw->set.image) { |
| 4134 | asyw->ntfy.handle = wndw->dmac->sync.handle; |
| 4135 | asyw->ntfy.offset = wndw->ntfy; |
| 4136 | asyw->ntfy.awaken = false; |
| 4137 | asyw->set.ntfy = true; |
| 4138 | nouveau_bo_wr32(disp->sync, wndw->ntfy / 4, 0x00000000); |
| 4139 | wndw->ntfy ^= 0x10; |
| 4140 | } |
| 4141 | } |
| 4142 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4143 | drm_atomic_state_get(state); |
| 4144 | |
| 4145 | if (nonblock) |
| 4146 | queue_work(system_unbound_wq, &state->commit_work); |
| 4147 | else |
| 4148 | nv50_disp_atomic_commit_tail(state); |
| 4149 | |
| 4150 | drm_for_each_crtc(crtc, dev) { |
| 4151 | if (crtc->state->enable) { |
| 4152 | if (!drm->have_disp_power_ref) { |
| 4153 | drm->have_disp_power_ref = true; |
Maarten Lankhorst | 813a7e1 | 2017-07-11 16:33:03 +0200 | [diff] [blame] | 4154 | return 0; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4155 | } |
| 4156 | active = true; |
| 4157 | break; |
| 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | if (!active && drm->have_disp_power_ref) { |
| 4162 | pm_runtime_put_autosuspend(dev->dev); |
| 4163 | drm->have_disp_power_ref = false; |
| 4164 | } |
| 4165 | |
Maarten Lankhorst | 813a7e1 | 2017-07-11 16:33:03 +0200 | [diff] [blame] | 4166 | err_cleanup: |
| 4167 | if (ret) |
| 4168 | drm_atomic_helper_cleanup_planes(dev, state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4169 | done: |
| 4170 | pm_runtime_put_autosuspend(dev->dev); |
| 4171 | return ret; |
| 4172 | } |
| 4173 | |
| 4174 | static struct nv50_outp_atom * |
| 4175 | nv50_disp_outp_atomic_add(struct nv50_atom *atom, struct drm_encoder *encoder) |
| 4176 | { |
| 4177 | struct nv50_outp_atom *outp; |
| 4178 | |
| 4179 | list_for_each_entry(outp, &atom->outp, head) { |
| 4180 | if (outp->encoder == encoder) |
| 4181 | return outp; |
| 4182 | } |
| 4183 | |
| 4184 | outp = kzalloc(sizeof(*outp), GFP_KERNEL); |
| 4185 | if (!outp) |
| 4186 | return ERR_PTR(-ENOMEM); |
| 4187 | |
| 4188 | list_add(&outp->head, &atom->outp); |
| 4189 | outp->encoder = encoder; |
| 4190 | return outp; |
| 4191 | } |
| 4192 | |
| 4193 | static int |
| 4194 | nv50_disp_outp_atomic_check_clr(struct nv50_atom *atom, |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4195 | struct drm_connector_state *old_connector_state) |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4196 | { |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4197 | struct drm_encoder *encoder = old_connector_state->best_encoder; |
| 4198 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4199 | struct drm_crtc *crtc; |
| 4200 | struct nv50_outp_atom *outp; |
| 4201 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4202 | if (!(crtc = old_connector_state->crtc)) |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4203 | return 0; |
| 4204 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4205 | old_crtc_state = drm_atomic_get_old_crtc_state(&atom->state, crtc); |
| 4206 | new_crtc_state = drm_atomic_get_new_crtc_state(&atom->state, crtc); |
| 4207 | if (old_crtc_state->active && drm_atomic_crtc_needs_modeset(new_crtc_state)) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4208 | outp = nv50_disp_outp_atomic_add(atom, encoder); |
| 4209 | if (IS_ERR(outp)) |
| 4210 | return PTR_ERR(outp); |
| 4211 | |
| 4212 | if (outp->encoder->encoder_type == DRM_MODE_ENCODER_DPMST) { |
| 4213 | outp->flush_disable = true; |
| 4214 | atom->flush_disable = true; |
| 4215 | } |
| 4216 | outp->clr.ctrl = true; |
| 4217 | atom->lock_core = true; |
| 4218 | } |
| 4219 | |
| 4220 | return 0; |
| 4221 | } |
| 4222 | |
| 4223 | static int |
| 4224 | nv50_disp_outp_atomic_check_set(struct nv50_atom *atom, |
| 4225 | struct drm_connector_state *connector_state) |
| 4226 | { |
| 4227 | struct drm_encoder *encoder = connector_state->best_encoder; |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4228 | struct drm_crtc_state *new_crtc_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4229 | struct drm_crtc *crtc; |
| 4230 | struct nv50_outp_atom *outp; |
| 4231 | |
| 4232 | if (!(crtc = connector_state->crtc)) |
| 4233 | return 0; |
| 4234 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4235 | new_crtc_state = drm_atomic_get_new_crtc_state(&atom->state, crtc); |
| 4236 | if (new_crtc_state->active && drm_atomic_crtc_needs_modeset(new_crtc_state)) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4237 | outp = nv50_disp_outp_atomic_add(atom, encoder); |
| 4238 | if (IS_ERR(outp)) |
| 4239 | return PTR_ERR(outp); |
| 4240 | |
| 4241 | outp->set.ctrl = true; |
| 4242 | atom->lock_core = true; |
| 4243 | } |
| 4244 | |
| 4245 | return 0; |
| 4246 | } |
| 4247 | |
| 4248 | static int |
| 4249 | nv50_disp_atomic_check(struct drm_device *dev, struct drm_atomic_state *state) |
| 4250 | { |
| 4251 | struct nv50_atom *atom = nv50_atom(state); |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4252 | struct drm_connector_state *old_connector_state, *new_connector_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4253 | struct drm_connector *connector; |
| 4254 | int ret, i; |
| 4255 | |
| 4256 | ret = drm_atomic_helper_check(dev, state); |
| 4257 | if (ret) |
| 4258 | return ret; |
| 4259 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4260 | for_each_oldnew_connector_in_state(state, connector, old_connector_state, new_connector_state, i) { |
| 4261 | ret = nv50_disp_outp_atomic_check_clr(atom, old_connector_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4262 | if (ret) |
| 4263 | return ret; |
| 4264 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 4265 | ret = nv50_disp_outp_atomic_check_set(atom, new_connector_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4266 | if (ret) |
| 4267 | return ret; |
| 4268 | } |
| 4269 | |
| 4270 | return 0; |
| 4271 | } |
| 4272 | |
| 4273 | static void |
| 4274 | nv50_disp_atomic_state_clear(struct drm_atomic_state *state) |
| 4275 | { |
| 4276 | struct nv50_atom *atom = nv50_atom(state); |
| 4277 | struct nv50_outp_atom *outp, *outt; |
| 4278 | |
| 4279 | list_for_each_entry_safe(outp, outt, &atom->outp, head) { |
| 4280 | list_del(&outp->head); |
| 4281 | kfree(outp); |
| 4282 | } |
| 4283 | |
| 4284 | drm_atomic_state_default_clear(state); |
| 4285 | } |
| 4286 | |
| 4287 | static void |
| 4288 | nv50_disp_atomic_state_free(struct drm_atomic_state *state) |
| 4289 | { |
| 4290 | struct nv50_atom *atom = nv50_atom(state); |
| 4291 | drm_atomic_state_default_release(&atom->state); |
| 4292 | kfree(atom); |
| 4293 | } |
| 4294 | |
| 4295 | static struct drm_atomic_state * |
| 4296 | nv50_disp_atomic_state_alloc(struct drm_device *dev) |
| 4297 | { |
| 4298 | struct nv50_atom *atom; |
| 4299 | if (!(atom = kzalloc(sizeof(*atom), GFP_KERNEL)) || |
| 4300 | drm_atomic_state_init(dev, &atom->state) < 0) { |
| 4301 | kfree(atom); |
| 4302 | return NULL; |
| 4303 | } |
| 4304 | INIT_LIST_HEAD(&atom->outp); |
| 4305 | return &atom->state; |
| 4306 | } |
| 4307 | |
| 4308 | static const struct drm_mode_config_funcs |
| 4309 | nv50_disp_func = { |
| 4310 | .fb_create = nouveau_user_framebuffer_create, |
| 4311 | .output_poll_changed = nouveau_fbcon_output_poll_changed, |
| 4312 | .atomic_check = nv50_disp_atomic_check, |
| 4313 | .atomic_commit = nv50_disp_atomic_commit, |
| 4314 | .atomic_state_alloc = nv50_disp_atomic_state_alloc, |
| 4315 | .atomic_state_clear = nv50_disp_atomic_state_clear, |
| 4316 | .atomic_state_free = nv50_disp_atomic_state_free, |
| 4317 | }; |
| 4318 | |
| 4319 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4320 | * Init |
| 4321 | *****************************************************************************/ |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 4322 | |
Ben Skeggs | 2a44e49 | 2011-11-09 11:36:33 +1000 | [diff] [blame] | 4323 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 4324 | nv50_display_fini(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4325 | { |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4326 | struct nouveau_encoder *nv_encoder; |
| 4327 | struct drm_encoder *encoder; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4328 | struct drm_plane *plane; |
| 4329 | |
| 4330 | drm_for_each_plane(plane, dev) { |
| 4331 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 4332 | if (plane->funcs != &nv50_wndw) |
| 4333 | continue; |
| 4334 | nv50_wndw_fini(wndw); |
| 4335 | } |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4336 | |
| 4337 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 4338 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
| 4339 | nv_encoder = nouveau_encoder(encoder); |
| 4340 | nv50_mstm_fini(nv_encoder->dp.mstm); |
| 4341 | } |
| 4342 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4343 | } |
| 4344 | |
| 4345 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 4346 | nv50_display_init(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4347 | { |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4348 | struct drm_encoder *encoder; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4349 | struct drm_plane *plane; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 4350 | struct drm_crtc *crtc; |
| 4351 | u32 *push; |
| 4352 | |
| 4353 | push = evo_wait(nv50_mast(dev), 32); |
| 4354 | if (!push) |
| 4355 | return -EBUSY; |
| 4356 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 4357 | evo_mthd(push, 0x0088, 1); |
Ben Skeggs | f45f55c | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 4358 | evo_data(push, nv50_mast(dev)->base.sync.handle); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 4359 | evo_kick(push, nv50_mast(dev)); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4360 | |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4361 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 4362 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
Ben Skeggs | 9c5753b | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 4363 | struct nouveau_encoder *nv_encoder = |
| 4364 | nouveau_encoder(encoder); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4365 | nv50_mstm_init(nv_encoder->dp.mstm); |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4366 | } |
| 4367 | } |
| 4368 | |
Ben Skeggs | e1ef6b4 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4369 | drm_for_each_crtc(crtc, dev) { |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4370 | nv50_head_lut_load(crtc); |
Ben Skeggs | e1ef6b4 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4371 | } |
| 4372 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4373 | drm_for_each_plane(plane, dev) { |
| 4374 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 4375 | if (plane->funcs != &nv50_wndw) |
| 4376 | continue; |
| 4377 | nv50_wndw_init(wndw); |
| 4378 | } |
| 4379 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 4380 | return 0; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 4384 | nv50_display_destroy(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4385 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 4386 | struct nv50_disp *disp = nv50_disp(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4387 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 4388 | nv50_dmac_destroy(&disp->mast.base, disp->disp); |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 4389 | |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 4390 | nouveau_bo_unmap(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 4391 | if (disp->sync) |
| 4392 | nouveau_bo_unpin(disp->sync); |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 4393 | nouveau_bo_ref(NULL, &disp->sync); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 4394 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 4395 | nouveau_display(dev)->priv = NULL; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4396 | kfree(disp); |
| 4397 | } |
| 4398 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4399 | MODULE_PARM_DESC(atomic, "Expose atomic ioctl (default: disabled)"); |
| 4400 | static int nouveau_atomic = 0; |
| 4401 | module_param_named(atomic, nouveau_atomic, int, 0400); |
| 4402 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4403 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 4404 | nv50_display_create(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4405 | { |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 4406 | struct nvif_device *device = &nouveau_drm(dev)->client.device; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 4407 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 4408 | struct dcb_table *dcb = &drm->vbios.dcb; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 4409 | struct drm_connector *connector, *tmp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 4410 | struct nv50_disp *disp; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 4411 | struct dcb_output *dcbe; |
Ben Skeggs | 7c5f6a8 | 2012-03-04 16:25:59 +1000 | [diff] [blame] | 4412 | int crtcs, ret, i; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4413 | |
| 4414 | disp = kzalloc(sizeof(*disp), GFP_KERNEL); |
| 4415 | if (!disp) |
| 4416 | return -ENOMEM; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 4417 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4418 | mutex_init(&disp->mutex); |
| 4419 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 4420 | nouveau_display(dev)->priv = disp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 4421 | nouveau_display(dev)->dtor = nv50_display_destroy; |
| 4422 | nouveau_display(dev)->init = nv50_display_init; |
| 4423 | nouveau_display(dev)->fini = nv50_display_fini; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 4424 | disp->disp = &nouveau_display(dev)->disp; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4425 | dev->mode_config.funcs = &nv50_disp_func; |
| 4426 | if (nouveau_atomic) |
| 4427 | dev->driver->driver_features |= DRIVER_ATOMIC; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4428 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 4429 | /* small shared memory area we use for notifiers and semaphores */ |
Ben Skeggs | bab7cc1 | 2016-05-24 17:26:48 +1000 | [diff] [blame] | 4430 | ret = nouveau_bo_new(&drm->client, 4096, 0x1000, TTM_PL_FLAG_VRAM, |
Maarten Lankhorst | bb6178b | 2014-01-09 11:03:15 +0100 | [diff] [blame] | 4431 | 0, 0x0000, NULL, NULL, &disp->sync); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 4432 | if (!ret) { |
Ben Skeggs | 547ad07 | 2014-11-10 12:35:06 +1000 | [diff] [blame] | 4433 | ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 4434 | if (!ret) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 4435 | ret = nouveau_bo_map(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 4436 | if (ret) |
| 4437 | nouveau_bo_unpin(disp->sync); |
| 4438 | } |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 4439 | if (ret) |
| 4440 | nouveau_bo_ref(NULL, &disp->sync); |
| 4441 | } |
| 4442 | |
| 4443 | if (ret) |
| 4444 | goto out; |
| 4445 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 4446 | /* allocate master evo channel */ |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 4447 | ret = nv50_core_create(device, disp->disp, disp->sync->bo.offset, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 4448 | &disp->mast); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 4449 | if (ret) |
| 4450 | goto out; |
| 4451 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 4452 | /* create crtc objects to represent the hw heads */ |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 4453 | if (disp->disp->oclass >= GF110_DISP) |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 4454 | crtcs = nvif_rd32(&device->object, 0x022448); |
Ben Skeggs | 63718a0 | 2012-11-16 11:44:14 +1000 | [diff] [blame] | 4455 | else |
| 4456 | crtcs = 2; |
| 4457 | |
Ben Skeggs | 7c5f6a8 | 2012-03-04 16:25:59 +1000 | [diff] [blame] | 4458 | for (i = 0; i < crtcs; i++) { |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 4459 | ret = nv50_head_create(dev, i); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 4460 | if (ret) |
| 4461 | goto out; |
| 4462 | } |
| 4463 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 4464 | /* create encoder/connector objects based on VBIOS DCB table */ |
| 4465 | for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) { |
| 4466 | connector = nouveau_connector_create(dev, dcbe->connector); |
| 4467 | if (IS_ERR(connector)) |
| 4468 | continue; |
| 4469 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 4470 | if (dcbe->location == DCB_LOC_ON_CHIP) { |
| 4471 | switch (dcbe->type) { |
| 4472 | case DCB_OUTPUT_TMDS: |
| 4473 | case DCB_OUTPUT_LVDS: |
| 4474 | case DCB_OUTPUT_DP: |
| 4475 | ret = nv50_sor_create(connector, dcbe); |
| 4476 | break; |
| 4477 | case DCB_OUTPUT_ANALOG: |
| 4478 | ret = nv50_dac_create(connector, dcbe); |
| 4479 | break; |
| 4480 | default: |
| 4481 | ret = -ENODEV; |
| 4482 | break; |
| 4483 | } |
| 4484 | } else { |
| 4485 | ret = nv50_pior_create(connector, dcbe); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 4486 | } |
| 4487 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 4488 | if (ret) { |
| 4489 | NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n", |
| 4490 | dcbe->location, dcbe->type, |
| 4491 | ffs(dcbe->or) - 1, ret); |
Ben Skeggs | 94f54f5 | 2013-03-05 22:26:06 +1000 | [diff] [blame] | 4492 | ret = 0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 4493 | } |
| 4494 | } |
| 4495 | |
| 4496 | /* cull any connectors we created that don't have an encoder */ |
| 4497 | list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) { |
| 4498 | if (connector->encoder_ids[0]) |
| 4499 | continue; |
| 4500 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 4501 | NV_WARN(drm, "%s has no encoders, removing\n", |
Jani Nikula | 8c6c361 | 2014-06-03 14:56:18 +0300 | [diff] [blame] | 4502 | connector->name); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 4503 | connector->funcs->destroy(connector); |
| 4504 | } |
| 4505 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4506 | out: |
| 4507 | if (ret) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 4508 | nv50_display_destroy(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 4509 | return ret; |
| 4510 | } |