Ben Skeggs | 56d237d | 2014-05-19 14:54:33 +1000 | [diff] [blame] | 1 | /* |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2 | * Copyright 2011 Red Hat Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | * Authors: Ben Skeggs |
| 23 | */ |
| 24 | |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 25 | #include <linux/dma-mapping.h> |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 26 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 27 | #include <drm/drmP.h> |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 28 | #include <drm/drm_atomic.h> |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 29 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 30 | #include <drm/drm_crtc_helper.h> |
Ben Skeggs | 4874322 | 2014-05-31 01:48:06 +1000 | [diff] [blame] | 31 | #include <drm/drm_dp_helper.h> |
Daniel Vetter | b516a9e | 2015-12-04 09:45:43 +0100 | [diff] [blame] | 32 | #include <drm/drm_fb_helper.h> |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 33 | #include <drm/drm_plane_helper.h> |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 34 | |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 35 | #include <nvif/class.h> |
Ben Skeggs | 845f272 | 2015-11-08 12:16:40 +1000 | [diff] [blame] | 36 | #include <nvif/cl0002.h> |
Ben Skeggs | 7568b10 | 2015-11-08 10:44:19 +1000 | [diff] [blame] | 37 | #include <nvif/cl5070.h> |
| 38 | #include <nvif/cl507a.h> |
| 39 | #include <nvif/cl507b.h> |
| 40 | #include <nvif/cl507c.h> |
| 41 | #include <nvif/cl507d.h> |
| 42 | #include <nvif/cl507e.h> |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 43 | #include <nvif/event.h> |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 44 | |
Ben Skeggs | 4dc2813 | 2016-05-20 09:22:55 +1000 | [diff] [blame] | 45 | #include "nouveau_drv.h" |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 46 | #include "nouveau_dma.h" |
| 47 | #include "nouveau_gem.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 48 | #include "nouveau_connector.h" |
| 49 | #include "nouveau_encoder.h" |
| 50 | #include "nouveau_crtc.h" |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 51 | #include "nouveau_fence.h" |
Ben Skeggs | 3a89cd0 | 2011-07-07 10:47:10 +1000 | [diff] [blame] | 52 | #include "nv50_display.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 53 | |
Ben Skeggs | 8a46438 | 2011-11-12 23:52:07 +1000 | [diff] [blame] | 54 | #define EVO_DMA_NR 9 |
| 55 | |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 56 | #define EVO_MASTER (0x00) |
Ben Skeggs | a63a97e | 2011-11-16 15:22:34 +1000 | [diff] [blame] | 57 | #define EVO_FLIP(c) (0x01 + (c)) |
Ben Skeggs | 8a46438 | 2011-11-12 23:52:07 +1000 | [diff] [blame] | 58 | #define EVO_OVLY(c) (0x05 + (c)) |
| 59 | #define EVO_OIMM(c) (0x09 + (c)) |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 60 | #define EVO_CURS(c) (0x0d + (c)) |
| 61 | |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 62 | /* offsets in shared sync bo of various structures */ |
| 63 | #define EVO_SYNC(c, o) ((c) * 0x0100 + (o)) |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 64 | #define EVO_MAST_NTFY EVO_SYNC( 0, 0x00) |
| 65 | #define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00) |
| 66 | #define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10) |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 67 | #define EVO_FLIP_NTFY0(c) EVO_SYNC((c) + 1, 0x20) |
| 68 | #define EVO_FLIP_NTFY1(c) EVO_SYNC((c) + 1, 0x30) |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 69 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 70 | /****************************************************************************** |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 71 | * Atomic state |
| 72 | *****************************************************************************/ |
| 73 | #define nv50_head_atom(p) container_of((p), struct nv50_head_atom, state) |
| 74 | |
| 75 | struct nv50_head_atom { |
| 76 | struct drm_crtc_state state; |
| 77 | |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 78 | struct { |
| 79 | u16 iW; |
| 80 | u16 iH; |
| 81 | u16 oW; |
| 82 | u16 oH; |
| 83 | } view; |
| 84 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 85 | struct nv50_head_mode { |
| 86 | bool interlace; |
| 87 | u32 clock; |
| 88 | struct { |
| 89 | u16 active; |
| 90 | u16 synce; |
| 91 | u16 blanke; |
| 92 | u16 blanks; |
| 93 | } h; |
| 94 | struct { |
| 95 | u32 active; |
| 96 | u16 synce; |
| 97 | u16 blanke; |
| 98 | u16 blanks; |
| 99 | u16 blank2s; |
| 100 | u16 blank2e; |
| 101 | u16 blankus; |
| 102 | } v; |
| 103 | } mode; |
| 104 | |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 105 | struct { |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 106 | u32 handle; |
| 107 | u64 offset:40; |
| 108 | } lut; |
| 109 | |
| 110 | struct { |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 111 | bool visible; |
| 112 | u32 handle; |
| 113 | u64 offset:40; |
| 114 | u8 format; |
| 115 | u8 kind:7; |
| 116 | u8 layout:1; |
| 117 | u8 block:4; |
| 118 | u32 pitch:20; |
| 119 | u16 x; |
| 120 | u16 y; |
| 121 | u16 w; |
| 122 | u16 h; |
| 123 | } core; |
| 124 | |
| 125 | struct { |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 126 | bool visible; |
| 127 | u32 handle; |
| 128 | u64 offset:40; |
| 129 | u8 layout:1; |
| 130 | u8 format:1; |
| 131 | } curs; |
| 132 | |
| 133 | struct { |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 134 | u8 depth; |
| 135 | u8 cpp; |
| 136 | u16 x; |
| 137 | u16 y; |
| 138 | u16 w; |
| 139 | u16 h; |
| 140 | } base; |
| 141 | |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 142 | struct { |
| 143 | u8 cpp; |
| 144 | } ovly; |
| 145 | |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 146 | struct { |
| 147 | bool enable:1; |
| 148 | u8 bits:2; |
| 149 | u8 mode:4; |
| 150 | } dither; |
| 151 | |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 152 | struct { |
| 153 | struct { |
| 154 | u16 cos:12; |
| 155 | u16 sin:12; |
| 156 | } sat; |
| 157 | } procamp; |
| 158 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 159 | union { |
| 160 | struct { |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 161 | bool core:1; |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 162 | bool curs:1; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 163 | }; |
| 164 | u8 mask; |
| 165 | } clr; |
| 166 | |
| 167 | union { |
| 168 | struct { |
| 169 | bool core:1; |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 170 | bool curs:1; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 171 | bool view:1; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 172 | bool mode:1; |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 173 | bool base:1; |
| 174 | bool ovly:1; |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 175 | bool dither:1; |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 176 | bool procamp:1; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 177 | }; |
| 178 | u16 mask; |
| 179 | } set; |
| 180 | }; |
| 181 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 182 | #define nv50_wndw_atom(p) container_of((p), struct nv50_wndw_atom, state) |
| 183 | |
| 184 | struct nv50_wndw_atom { |
| 185 | struct drm_plane_state state; |
| 186 | u8 interval; |
| 187 | |
| 188 | struct drm_rect clip; |
| 189 | |
| 190 | struct { |
| 191 | u32 handle; |
| 192 | u16 offset:12; |
| 193 | bool awaken:1; |
| 194 | } ntfy; |
| 195 | |
| 196 | struct { |
| 197 | u32 handle; |
| 198 | u16 offset:12; |
| 199 | u32 acquire; |
| 200 | u32 release; |
| 201 | } sema; |
| 202 | |
| 203 | struct { |
| 204 | u8 enable:2; |
| 205 | } lut; |
| 206 | |
| 207 | struct { |
| 208 | u8 mode:2; |
| 209 | u8 interval:4; |
| 210 | |
| 211 | u8 format; |
| 212 | u8 kind:7; |
| 213 | u8 layout:1; |
| 214 | u8 block:4; |
| 215 | u32 pitch:20; |
| 216 | u16 w; |
| 217 | u16 h; |
| 218 | |
| 219 | u32 handle; |
| 220 | u64 offset; |
| 221 | } image; |
| 222 | |
| 223 | struct { |
| 224 | u16 x; |
| 225 | u16 y; |
| 226 | } point; |
| 227 | |
| 228 | union { |
| 229 | struct { |
| 230 | bool ntfy:1; |
| 231 | bool sema:1; |
| 232 | bool image:1; |
| 233 | }; |
| 234 | u8 mask; |
| 235 | } clr; |
| 236 | |
| 237 | union { |
| 238 | struct { |
| 239 | bool ntfy:1; |
| 240 | bool sema:1; |
| 241 | bool image:1; |
| 242 | bool lut:1; |
| 243 | bool point:1; |
| 244 | }; |
| 245 | u8 mask; |
| 246 | } set; |
| 247 | }; |
| 248 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 249 | /****************************************************************************** |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 250 | * EVO channel |
| 251 | *****************************************************************************/ |
| 252 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 253 | struct nv50_chan { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 254 | struct nvif_object user; |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 255 | struct nvif_device *device; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 256 | }; |
| 257 | |
| 258 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 259 | nv50_chan_create(struct nvif_device *device, struct nvif_object *disp, |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 260 | const s32 *oclass, u8 head, void *data, u32 size, |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 261 | struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 262 | { |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 263 | struct nvif_sclass *sclass; |
| 264 | int ret, i, n; |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 265 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 266 | chan->device = device; |
| 267 | |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 268 | ret = n = nvif_object_sclass_get(disp, &sclass); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 269 | if (ret < 0) |
| 270 | return ret; |
| 271 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 272 | while (oclass[0]) { |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 273 | for (i = 0; i < n; i++) { |
| 274 | if (sclass[i].oclass == oclass[0]) { |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 275 | ret = nvif_object_init(disp, 0, oclass[0], |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 276 | data, size, &chan->user); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 277 | if (ret == 0) |
| 278 | nvif_object_map(&chan->user); |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 279 | nvif_object_sclass_put(&sclass); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 280 | return ret; |
| 281 | } |
Ben Skeggs | b76f152 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 282 | } |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 283 | oclass++; |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 284 | } |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 285 | |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 286 | nvif_object_sclass_put(&sclass); |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 287 | return -ENOSYS; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static void |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 291 | nv50_chan_destroy(struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 292 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 293 | nvif_object_fini(&chan->user); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /****************************************************************************** |
| 297 | * PIO EVO channel |
| 298 | *****************************************************************************/ |
| 299 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 300 | struct nv50_pioc { |
| 301 | struct nv50_chan base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | static void |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 305 | nv50_pioc_destroy(struct nv50_pioc *pioc) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 306 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 307 | nv50_chan_destroy(&pioc->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 311 | nv50_pioc_create(struct nvif_device *device, struct nvif_object *disp, |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 312 | const s32 *oclass, u8 head, void *data, u32 size, |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 313 | struct nv50_pioc *pioc) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 314 | { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 315 | return nv50_chan_create(device, disp, oclass, head, data, size, |
| 316 | &pioc->base); |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /****************************************************************************** |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 320 | * Overlay Immediate |
| 321 | *****************************************************************************/ |
| 322 | |
| 323 | struct nv50_oimm { |
| 324 | struct nv50_pioc base; |
| 325 | }; |
| 326 | |
| 327 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 328 | nv50_oimm_create(struct nvif_device *device, struct nvif_object *disp, |
| 329 | int head, struct nv50_oimm *oimm) |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 330 | { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 331 | struct nv50_disp_cursor_v0 args = { |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 332 | .head = head, |
| 333 | }; |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 334 | static const s32 oclass[] = { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 335 | GK104_DISP_OVERLAY, |
| 336 | GF110_DISP_OVERLAY, |
| 337 | GT214_DISP_OVERLAY, |
| 338 | G82_DISP_OVERLAY, |
| 339 | NV50_DISP_OVERLAY, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 340 | 0 |
| 341 | }; |
| 342 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 343 | return nv50_pioc_create(device, disp, oclass, head, &args, sizeof(args), |
| 344 | &oimm->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | /****************************************************************************** |
| 348 | * DMA EVO channel |
| 349 | *****************************************************************************/ |
| 350 | |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 351 | struct nv50_dmac_ctxdma { |
| 352 | struct list_head head; |
| 353 | struct nvif_object object; |
| 354 | }; |
| 355 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 356 | struct nv50_dmac { |
| 357 | struct nv50_chan base; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 358 | dma_addr_t handle; |
| 359 | u32 *ptr; |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 360 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 361 | struct nvif_object sync; |
| 362 | struct nvif_object vram; |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 363 | struct list_head ctxdma; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 364 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 365 | /* Protects against concurrent pushbuf access to this channel, lock is |
| 366 | * grabbed by evo_wait (if the pushbuf reservation is successful) and |
| 367 | * dropped again by evo_kick. */ |
| 368 | struct mutex lock; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 369 | }; |
| 370 | |
| 371 | static void |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 372 | nv50_dmac_ctxdma_del(struct nv50_dmac_ctxdma *ctxdma) |
| 373 | { |
| 374 | nvif_object_fini(&ctxdma->object); |
| 375 | list_del(&ctxdma->head); |
| 376 | kfree(ctxdma); |
| 377 | } |
| 378 | |
| 379 | static struct nv50_dmac_ctxdma * |
| 380 | nv50_dmac_ctxdma_new(struct nv50_dmac *dmac, u32 handle, |
| 381 | struct nouveau_framebuffer *fb) |
| 382 | { |
| 383 | struct nouveau_drm *drm = nouveau_drm(fb->base.dev); |
| 384 | struct nv50_dmac_ctxdma *ctxdma; |
| 385 | const u8 kind = (fb->nvbo->tile_flags & 0x0000ff00) >> 8; |
| 386 | struct { |
| 387 | struct nv_dma_v0 base; |
| 388 | union { |
| 389 | struct nv50_dma_v0 nv50; |
| 390 | struct gf100_dma_v0 gf100; |
| 391 | struct gf119_dma_v0 gf119; |
| 392 | }; |
| 393 | } args = {}; |
| 394 | u32 argc = sizeof(args.base); |
| 395 | int ret; |
| 396 | |
| 397 | list_for_each_entry(ctxdma, &dmac->ctxdma, head) { |
| 398 | if (ctxdma->object.handle == handle) |
| 399 | return ctxdma; |
| 400 | } |
| 401 | |
| 402 | if (!(ctxdma = kzalloc(sizeof(*ctxdma), GFP_KERNEL))) |
| 403 | return ERR_PTR(-ENOMEM); |
| 404 | list_add(&ctxdma->head, &dmac->ctxdma); |
| 405 | |
| 406 | args.base.target = NV_DMA_V0_TARGET_VRAM; |
| 407 | args.base.access = NV_DMA_V0_ACCESS_RDWR; |
| 408 | args.base.start = 0; |
| 409 | args.base.limit = drm->device.info.ram_user - 1; |
| 410 | |
| 411 | if (drm->device.info.chipset < 0x80) { |
| 412 | args.nv50.part = NV50_DMA_V0_PART_256; |
| 413 | argc += sizeof(args.nv50); |
| 414 | } else |
| 415 | if (drm->device.info.chipset < 0xc0) { |
| 416 | args.nv50.part = NV50_DMA_V0_PART_256; |
| 417 | args.nv50.kind = kind; |
| 418 | argc += sizeof(args.nv50); |
| 419 | } else |
| 420 | if (drm->device.info.chipset < 0xd0) { |
| 421 | args.gf100.kind = kind; |
| 422 | argc += sizeof(args.gf100); |
| 423 | } else { |
| 424 | args.gf119.page = GF119_DMA_V0_PAGE_LP; |
| 425 | args.gf119.kind = kind; |
| 426 | argc += sizeof(args.gf119); |
| 427 | } |
| 428 | |
| 429 | ret = nvif_object_init(&dmac->base.user, handle, NV_DMA_IN_MEMORY, |
| 430 | &args, argc, &ctxdma->object); |
| 431 | if (ret) { |
| 432 | nv50_dmac_ctxdma_del(ctxdma); |
| 433 | return ERR_PTR(ret); |
| 434 | } |
| 435 | |
| 436 | return ctxdma; |
| 437 | } |
| 438 | |
| 439 | static void |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 440 | nv50_dmac_destroy(struct nv50_dmac *dmac, struct nvif_object *disp) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 441 | { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 442 | struct nvif_device *device = dmac->base.device; |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 443 | struct nv50_dmac_ctxdma *ctxdma, *ctxtmp; |
| 444 | |
| 445 | list_for_each_entry_safe(ctxdma, ctxtmp, &dmac->ctxdma, head) { |
| 446 | nv50_dmac_ctxdma_del(ctxdma); |
| 447 | } |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 448 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 449 | nvif_object_fini(&dmac->vram); |
| 450 | nvif_object_fini(&dmac->sync); |
| 451 | |
| 452 | nv50_chan_destroy(&dmac->base); |
| 453 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 454 | if (dmac->ptr) { |
Ben Skeggs | 26c9e8e | 2015-08-20 14:54:23 +1000 | [diff] [blame] | 455 | struct device *dev = nvxx_device(device)->dev; |
| 456 | dma_free_coherent(dev, PAGE_SIZE, dmac->ptr, dmac->handle); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 457 | } |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 461 | nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp, |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 462 | const s32 *oclass, u8 head, void *data, u32 size, u64 syncbuf, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 463 | struct nv50_dmac *dmac) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 464 | { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 465 | struct nv50_disp_core_channel_dma_v0 *args = data; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 466 | struct nvif_object pushbuf; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 467 | int ret; |
| 468 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 469 | mutex_init(&dmac->lock); |
| 470 | |
Ben Skeggs | 26c9e8e | 2015-08-20 14:54:23 +1000 | [diff] [blame] | 471 | dmac->ptr = dma_alloc_coherent(nvxx_device(device)->dev, PAGE_SIZE, |
| 472 | &dmac->handle, GFP_KERNEL); |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 473 | if (!dmac->ptr) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 474 | return -ENOMEM; |
| 475 | |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 476 | ret = nvif_object_init(&device->object, 0, NV_DMA_FROM_MEMORY, |
| 477 | &(struct nv_dma_v0) { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 478 | .target = NV_DMA_V0_TARGET_PCI_US, |
| 479 | .access = NV_DMA_V0_ACCESS_RD, |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 480 | .start = dmac->handle + 0x0000, |
| 481 | .limit = dmac->handle + 0x0fff, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 482 | }, sizeof(struct nv_dma_v0), &pushbuf); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 483 | if (ret) |
| 484 | return ret; |
| 485 | |
Ben Skeggs | bf81df9 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 486 | args->pushbuf = nvif_handle(&pushbuf); |
| 487 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 488 | ret = nv50_chan_create(device, disp, oclass, head, data, size, |
| 489 | &dmac->base); |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 490 | nvif_object_fini(&pushbuf); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 491 | if (ret) |
| 492 | return ret; |
| 493 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 494 | ret = nvif_object_init(&dmac->base.user, 0xf0000000, NV_DMA_IN_MEMORY, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 495 | &(struct nv_dma_v0) { |
| 496 | .target = NV_DMA_V0_TARGET_VRAM, |
| 497 | .access = NV_DMA_V0_ACCESS_RDWR, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 498 | .start = syncbuf + 0x0000, |
| 499 | .limit = syncbuf + 0x0fff, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 500 | }, sizeof(struct nv_dma_v0), |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 501 | &dmac->sync); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 502 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 503 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 504 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 505 | ret = nvif_object_init(&dmac->base.user, 0xf0000001, NV_DMA_IN_MEMORY, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 506 | &(struct nv_dma_v0) { |
| 507 | .target = NV_DMA_V0_TARGET_VRAM, |
| 508 | .access = NV_DMA_V0_ACCESS_RDWR, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 509 | .start = 0, |
Ben Skeggs | f392ec4 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 510 | .limit = device->info.ram_user - 1, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 511 | }, sizeof(struct nv_dma_v0), |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 512 | &dmac->vram); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 513 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 514 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 515 | |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 516 | INIT_LIST_HEAD(&dmac->ctxdma); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 517 | return ret; |
| 518 | } |
| 519 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 520 | /****************************************************************************** |
| 521 | * Core |
| 522 | *****************************************************************************/ |
| 523 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 524 | struct nv50_mast { |
| 525 | struct nv50_dmac base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 526 | }; |
| 527 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 528 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 529 | nv50_core_create(struct nvif_device *device, struct nvif_object *disp, |
| 530 | u64 syncbuf, struct nv50_mast *core) |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 531 | { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 532 | struct nv50_disp_core_channel_dma_v0 args = { |
| 533 | .pushbuf = 0xb0007d00, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 534 | }; |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 535 | static const s32 oclass[] = { |
Ben Skeggs | fd47877 | 2016-07-09 10:41:01 +1000 | [diff] [blame] | 536 | GP104_DISP_CORE_CHANNEL_DMA, |
Ben Skeggs | f9d5cbb | 2016-07-09 10:41:01 +1000 | [diff] [blame] | 537 | GP100_DISP_CORE_CHANNEL_DMA, |
Ben Skeggs | db1eb52 | 2016-02-11 08:35:32 +1000 | [diff] [blame] | 538 | GM200_DISP_CORE_CHANNEL_DMA, |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 539 | GM107_DISP_CORE_CHANNEL_DMA, |
| 540 | GK110_DISP_CORE_CHANNEL_DMA, |
| 541 | GK104_DISP_CORE_CHANNEL_DMA, |
| 542 | GF110_DISP_CORE_CHANNEL_DMA, |
| 543 | GT214_DISP_CORE_CHANNEL_DMA, |
| 544 | GT206_DISP_CORE_CHANNEL_DMA, |
| 545 | GT200_DISP_CORE_CHANNEL_DMA, |
| 546 | G82_DISP_CORE_CHANNEL_DMA, |
| 547 | NV50_DISP_CORE_CHANNEL_DMA, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 548 | 0 |
| 549 | }; |
| 550 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 551 | return nv50_dmac_create(device, disp, oclass, 0, &args, sizeof(args), |
| 552 | syncbuf, &core->base); |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /****************************************************************************** |
| 556 | * Base |
| 557 | *****************************************************************************/ |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 558 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 559 | struct nv50_sync { |
| 560 | struct nv50_dmac base; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 561 | u32 addr; |
| 562 | u32 data; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 563 | }; |
| 564 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 565 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 566 | nv50_base_create(struct nvif_device *device, struct nvif_object *disp, |
| 567 | int head, u64 syncbuf, struct nv50_sync *base) |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 568 | { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 569 | struct nv50_disp_base_channel_dma_v0 args = { |
| 570 | .pushbuf = 0xb0007c00 | head, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 571 | .head = head, |
| 572 | }; |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 573 | static const s32 oclass[] = { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 574 | GK110_DISP_BASE_CHANNEL_DMA, |
| 575 | GK104_DISP_BASE_CHANNEL_DMA, |
| 576 | GF110_DISP_BASE_CHANNEL_DMA, |
| 577 | GT214_DISP_BASE_CHANNEL_DMA, |
| 578 | GT200_DISP_BASE_CHANNEL_DMA, |
| 579 | G82_DISP_BASE_CHANNEL_DMA, |
| 580 | NV50_DISP_BASE_CHANNEL_DMA, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 581 | 0 |
| 582 | }; |
| 583 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 584 | return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args), |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 585 | syncbuf, &base->base); |
| 586 | } |
| 587 | |
| 588 | /****************************************************************************** |
| 589 | * Overlay |
| 590 | *****************************************************************************/ |
| 591 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 592 | struct nv50_ovly { |
| 593 | struct nv50_dmac base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 594 | }; |
Ben Skeggs | f20ce96 | 2011-07-08 13:17:01 +1000 | [diff] [blame] | 595 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 596 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 597 | nv50_ovly_create(struct nvif_device *device, struct nvif_object *disp, |
| 598 | int head, u64 syncbuf, struct nv50_ovly *ovly) |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 599 | { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 600 | struct nv50_disp_overlay_channel_dma_v0 args = { |
| 601 | .pushbuf = 0xb0007e00 | head, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 602 | .head = head, |
| 603 | }; |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 604 | static const s32 oclass[] = { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 605 | GK104_DISP_OVERLAY_CONTROL_DMA, |
| 606 | GF110_DISP_OVERLAY_CONTROL_DMA, |
| 607 | GT214_DISP_OVERLAY_CHANNEL_DMA, |
| 608 | GT200_DISP_OVERLAY_CHANNEL_DMA, |
| 609 | G82_DISP_OVERLAY_CHANNEL_DMA, |
| 610 | NV50_DISP_OVERLAY_CHANNEL_DMA, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 611 | 0 |
| 612 | }; |
| 613 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 614 | return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args), |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 615 | syncbuf, &ovly->base); |
| 616 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 617 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 618 | struct nv50_head { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 619 | struct nouveau_crtc base; |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 620 | struct nouveau_bo *image; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 621 | struct nv50_ovly ovly; |
| 622 | struct nv50_oimm oimm; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 623 | |
| 624 | struct nv50_head_atom arm; |
| 625 | struct nv50_head_atom asy; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 626 | |
| 627 | struct nv50_base *_base; |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 628 | struct nv50_curs *_curs; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 629 | }; |
| 630 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 631 | #define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c)) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 632 | #define nv50_ovly(c) (&nv50_head(c)->ovly) |
| 633 | #define nv50_oimm(c) (&nv50_head(c)->oimm) |
| 634 | #define nv50_chan(c) (&(c)->base.base) |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 635 | #define nv50_vers(c) nv50_chan(c)->user.oclass |
| 636 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 637 | struct nv50_disp { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 638 | struct nvif_object *disp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 639 | struct nv50_mast mast; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 640 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 641 | struct nouveau_bo *sync; |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 642 | }; |
| 643 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 644 | static struct nv50_disp * |
| 645 | nv50_disp(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 646 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 647 | return nouveau_display(dev)->priv; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 648 | } |
| 649 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 650 | #define nv50_mast(d) (&nv50_disp(d)->mast) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 651 | |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 652 | static struct drm_crtc * |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 653 | nv50_display_crtc_get(struct drm_encoder *encoder) |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 654 | { |
| 655 | return nouveau_encoder(encoder)->crtc; |
| 656 | } |
| 657 | |
| 658 | /****************************************************************************** |
| 659 | * EVO channel helpers |
| 660 | *****************************************************************************/ |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 661 | static u32 * |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 662 | evo_wait(void *evoc, int nr) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 663 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 664 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 665 | struct nvif_device *device = dmac->base.device; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 666 | u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 667 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 668 | mutex_lock(&dmac->lock); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 669 | if (put + nr >= (PAGE_SIZE / 4) - 8) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 670 | dmac->ptr[put] = 0x20000000; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 671 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 672 | nvif_wr32(&dmac->base.user, 0x0000, 0x00000000); |
Ben Skeggs | 5444204 | 2015-08-20 14:54:11 +1000 | [diff] [blame] | 673 | if (nvif_msec(device, 2000, |
| 674 | if (!nvif_rd32(&dmac->base.user, 0x0004)) |
| 675 | break; |
| 676 | ) < 0) { |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 677 | mutex_unlock(&dmac->lock); |
Ben Skeggs | 9ad97ed | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 678 | printk(KERN_ERR "nouveau: evo channel stalled\n"); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 679 | return NULL; |
| 680 | } |
| 681 | |
| 682 | put = 0; |
| 683 | } |
| 684 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 685 | return dmac->ptr + put; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | static void |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 689 | evo_kick(u32 *push, void *evoc) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 690 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 691 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 692 | nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2); |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 693 | mutex_unlock(&dmac->lock); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 694 | } |
| 695 | |
Ben Skeggs | 2b1930c | 2014-11-03 16:43:59 +1000 | [diff] [blame] | 696 | #define evo_mthd(p,m,s) do { \ |
| 697 | const u32 _m = (m), _s = (s); \ |
Ben Skeggs | 7f55a07 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 698 | if (drm_debug & DRM_UT_KMS) \ |
| 699 | printk(KERN_ERR "%04x %d %s\n", _m, _s, __func__); \ |
Ben Skeggs | 2b1930c | 2014-11-03 16:43:59 +1000 | [diff] [blame] | 700 | *((p)++) = ((_s << 18) | _m); \ |
| 701 | } while(0) |
Ben Skeggs | 7f55a07 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 702 | |
Ben Skeggs | 2b1930c | 2014-11-03 16:43:59 +1000 | [diff] [blame] | 703 | #define evo_data(p,d) do { \ |
| 704 | const u32 _d = (d); \ |
Ben Skeggs | 7f55a07 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 705 | if (drm_debug & DRM_UT_KMS) \ |
| 706 | printk(KERN_ERR "\t%08x\n", _d); \ |
Ben Skeggs | 2b1930c | 2014-11-03 16:43:59 +1000 | [diff] [blame] | 707 | *((p)++) = _d; \ |
| 708 | } while(0) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 709 | |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 710 | static bool |
| 711 | evo_sync_wait(void *data) |
| 712 | { |
Ben Skeggs | 5cc027f | 2013-02-18 17:50:51 -0500 | [diff] [blame] | 713 | if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000) |
| 714 | return true; |
| 715 | usleep_range(1, 2); |
| 716 | return false; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | static int |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 720 | evo_sync(struct drm_device *dev) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 721 | { |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 722 | struct nvif_device *device = &nouveau_drm(dev)->device; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 723 | struct nv50_disp *disp = nv50_disp(dev); |
| 724 | struct nv50_mast *mast = nv50_mast(dev); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 725 | u32 *push = evo_wait(mast, 8); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 726 | if (push) { |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 727 | nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 728 | evo_mthd(push, 0x0084, 1); |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 729 | evo_data(push, 0x80000000 | EVO_MAST_NTFY); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 730 | evo_mthd(push, 0x0080, 2); |
| 731 | evo_data(push, 0x00000000); |
| 732 | evo_data(push, 0x00000000); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 733 | evo_kick(push, mast); |
Ben Skeggs | 5444204 | 2015-08-20 14:54:11 +1000 | [diff] [blame] | 734 | if (nvif_msec(device, 2000, |
| 735 | if (evo_sync_wait(disp->sync)) |
| 736 | break; |
| 737 | ) >= 0) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | return -EBUSY; |
| 742 | } |
| 743 | |
| 744 | /****************************************************************************** |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 745 | * Plane |
| 746 | *****************************************************************************/ |
| 747 | #define nv50_wndw(p) container_of((p), struct nv50_wndw, plane) |
| 748 | |
| 749 | struct nv50_wndw { |
| 750 | const struct nv50_wndw_func *func; |
| 751 | struct nv50_dmac *dmac; |
| 752 | |
| 753 | struct drm_plane plane; |
| 754 | |
| 755 | struct nvif_notify notify; |
| 756 | u16 ntfy; |
| 757 | u16 sema; |
| 758 | u32 data; |
| 759 | |
| 760 | struct nv50_wndw_atom arm; |
| 761 | struct nv50_wndw_atom asy; |
| 762 | }; |
| 763 | |
| 764 | struct nv50_wndw_func { |
| 765 | void *(*dtor)(struct nv50_wndw *); |
| 766 | int (*acquire)(struct nv50_wndw *, struct nv50_wndw_atom *asyw, |
| 767 | struct nv50_head_atom *asyh); |
| 768 | void (*release)(struct nv50_wndw *, struct nv50_wndw_atom *asyw, |
| 769 | struct nv50_head_atom *asyh); |
| 770 | void (*prepare)(struct nv50_wndw *, struct nv50_head_atom *asyh, |
| 771 | struct nv50_wndw_atom *asyw); |
| 772 | |
| 773 | void (*sema_set)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 774 | void (*sema_clr)(struct nv50_wndw *); |
| 775 | void (*ntfy_set)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 776 | void (*ntfy_clr)(struct nv50_wndw *); |
| 777 | int (*ntfy_wait_begun)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 778 | void (*image_set)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 779 | void (*image_clr)(struct nv50_wndw *); |
| 780 | void (*lut)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 781 | void (*point)(struct nv50_wndw *, struct nv50_wndw_atom *); |
| 782 | |
| 783 | u32 (*update)(struct nv50_wndw *, u32 interlock); |
| 784 | }; |
| 785 | |
| 786 | static int |
| 787 | nv50_wndw_wait_armed(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 788 | { |
| 789 | if (asyw->set.ntfy) |
| 790 | return wndw->func->ntfy_wait_begun(wndw, asyw); |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | static u32 |
| 795 | nv50_wndw_flush_clr(struct nv50_wndw *wndw, u32 interlock, bool flush, |
| 796 | struct nv50_wndw_atom *asyw) |
| 797 | { |
| 798 | if (asyw->clr.sema && (!asyw->set.sema || flush)) |
| 799 | wndw->func->sema_clr(wndw); |
| 800 | if (asyw->clr.ntfy && (!asyw->set.ntfy || flush)) |
| 801 | wndw->func->ntfy_clr(wndw); |
| 802 | if (asyw->clr.image && (!asyw->set.image || flush)) |
| 803 | wndw->func->image_clr(wndw); |
| 804 | |
| 805 | return flush ? wndw->func->update(wndw, interlock) : 0; |
| 806 | } |
| 807 | |
| 808 | static u32 |
| 809 | nv50_wndw_flush_set(struct nv50_wndw *wndw, u32 interlock, |
| 810 | struct nv50_wndw_atom *asyw) |
| 811 | { |
| 812 | if (interlock) { |
| 813 | asyw->image.mode = 0; |
| 814 | asyw->image.interval = 1; |
| 815 | } |
| 816 | |
| 817 | if (asyw->set.sema ) wndw->func->sema_set (wndw, asyw); |
| 818 | if (asyw->set.ntfy ) wndw->func->ntfy_set (wndw, asyw); |
| 819 | if (asyw->set.image) wndw->func->image_set(wndw, asyw); |
| 820 | if (asyw->set.lut ) wndw->func->lut (wndw, asyw); |
| 821 | if (asyw->set.point) wndw->func->point (wndw, asyw); |
| 822 | |
| 823 | return wndw->func->update(wndw, interlock); |
| 824 | } |
| 825 | |
| 826 | static void |
| 827 | nv50_wndw_atomic_check_release(struct nv50_wndw *wndw, |
| 828 | struct nv50_wndw_atom *asyw, |
| 829 | struct nv50_head_atom *asyh) |
| 830 | { |
| 831 | struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev); |
| 832 | NV_ATOMIC(drm, "%s release\n", wndw->plane.name); |
| 833 | wndw->func->release(wndw, asyw, asyh); |
| 834 | asyw->ntfy.handle = 0; |
| 835 | asyw->sema.handle = 0; |
| 836 | } |
| 837 | |
| 838 | static int |
| 839 | nv50_wndw_atomic_check_acquire(struct nv50_wndw *wndw, |
| 840 | struct nv50_wndw_atom *asyw, |
| 841 | struct nv50_head_atom *asyh) |
| 842 | { |
| 843 | struct nouveau_framebuffer *fb = nouveau_framebuffer(asyw->state.fb); |
| 844 | struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev); |
| 845 | int ret; |
| 846 | |
| 847 | NV_ATOMIC(drm, "%s acquire\n", wndw->plane.name); |
| 848 | asyw->clip.x1 = 0; |
| 849 | asyw->clip.y1 = 0; |
| 850 | asyw->clip.x2 = asyh->state.mode.hdisplay; |
| 851 | asyw->clip.y2 = asyh->state.mode.vdisplay; |
| 852 | |
| 853 | asyw->image.w = fb->base.width; |
| 854 | asyw->image.h = fb->base.height; |
| 855 | asyw->image.kind = (fb->nvbo->tile_flags & 0x0000ff00) >> 8; |
| 856 | if (asyw->image.kind) { |
| 857 | asyw->image.layout = 0; |
| 858 | if (drm->device.info.chipset >= 0xc0) |
| 859 | asyw->image.block = fb->nvbo->tile_mode >> 4; |
| 860 | else |
| 861 | asyw->image.block = fb->nvbo->tile_mode; |
| 862 | asyw->image.pitch = (fb->base.pitches[0] / 4) << 4; |
| 863 | } else { |
| 864 | asyw->image.layout = 1; |
| 865 | asyw->image.block = 0; |
| 866 | asyw->image.pitch = fb->base.pitches[0]; |
| 867 | } |
| 868 | |
| 869 | ret = wndw->func->acquire(wndw, asyw, asyh); |
| 870 | if (ret) |
| 871 | return ret; |
| 872 | |
| 873 | if (asyw->set.image) { |
| 874 | if (!(asyw->image.mode = asyw->interval ? 0 : 1)) |
| 875 | asyw->image.interval = asyw->interval; |
| 876 | else |
| 877 | asyw->image.interval = 0; |
| 878 | } |
| 879 | |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | static int |
| 884 | nv50_wndw_atomic_check(struct drm_plane *plane, struct drm_plane_state *state) |
| 885 | { |
| 886 | struct nouveau_drm *drm = nouveau_drm(plane->dev); |
| 887 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 888 | struct nv50_wndw_atom *armw = &wndw->arm; |
| 889 | struct nv50_wndw_atom *asyw = &wndw->asy; |
| 890 | struct nv50_head_atom *harm = NULL, *asyh = NULL; |
| 891 | bool varm = false, asyv = false, asym = false; |
| 892 | int ret; |
| 893 | |
| 894 | asyw->clr.mask = 0; |
| 895 | asyw->set.mask = 0; |
| 896 | |
| 897 | NV_ATOMIC(drm, "%s atomic_check\n", plane->name); |
| 898 | if (asyw->state.crtc) { |
| 899 | asyh = &nv50_head(asyw->state.crtc)->asy; |
| 900 | if (IS_ERR(asyh)) |
| 901 | return PTR_ERR(asyh); |
| 902 | asym = drm_atomic_crtc_needs_modeset(&asyh->state); |
| 903 | asyv = asyh->state.active; |
| 904 | } |
| 905 | |
| 906 | if (armw->state.crtc) { |
| 907 | harm = &nv50_head(armw->state.crtc)->asy; |
| 908 | if (IS_ERR(harm)) |
| 909 | return PTR_ERR(harm); |
| 910 | varm = nv50_head(harm->state.crtc)->arm.state.active; |
| 911 | } |
| 912 | |
| 913 | if (asyv) { |
| 914 | asyw->point.x = asyw->state.crtc_x; |
| 915 | asyw->point.y = asyw->state.crtc_y; |
| 916 | if (memcmp(&armw->point, &asyw->point, sizeof(asyw->point))) |
| 917 | asyw->set.point = true; |
| 918 | |
| 919 | if (!varm || asym || armw->state.fb != asyw->state.fb) { |
| 920 | ret = nv50_wndw_atomic_check_acquire(wndw, asyw, asyh); |
| 921 | if (ret) |
| 922 | return ret; |
| 923 | } |
| 924 | } else |
| 925 | if (varm) { |
| 926 | nv50_wndw_atomic_check_release(wndw, asyw, harm); |
| 927 | } else { |
| 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | if (!asyv || asym) { |
| 932 | asyw->clr.ntfy = armw->ntfy.handle != 0; |
| 933 | asyw->clr.sema = armw->sema.handle != 0; |
| 934 | if (wndw->func->image_clr) |
| 935 | asyw->clr.image = armw->image.handle != 0; |
| 936 | asyw->set.lut = wndw->func->lut && asyv; |
| 937 | } |
| 938 | |
| 939 | memcpy(armw, asyw, sizeof(*asyw)); |
| 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | static void |
| 944 | nv50_wndw_atomic_destroy_state(struct drm_plane *plane, |
| 945 | struct drm_plane_state *state) |
| 946 | { |
| 947 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(state); |
| 948 | __drm_atomic_helper_plane_destroy_state(&asyw->state); |
| 949 | dma_fence_put(asyw->state.fence); |
| 950 | kfree(asyw); |
| 951 | } |
| 952 | |
| 953 | static struct drm_plane_state * |
| 954 | nv50_wndw_atomic_duplicate_state(struct drm_plane *plane) |
| 955 | { |
| 956 | struct nv50_wndw_atom *armw = nv50_wndw_atom(plane->state); |
| 957 | struct nv50_wndw_atom *asyw; |
| 958 | if (!(asyw = kmalloc(sizeof(*asyw), GFP_KERNEL))) |
| 959 | return NULL; |
| 960 | __drm_atomic_helper_plane_duplicate_state(plane, &asyw->state); |
| 961 | asyw->state.fence = NULL; |
| 962 | asyw->interval = 1; |
| 963 | asyw->sema = armw->sema; |
| 964 | asyw->ntfy = armw->ntfy; |
| 965 | asyw->image = armw->image; |
| 966 | asyw->point = armw->point; |
| 967 | asyw->lut = armw->lut; |
| 968 | asyw->clr.mask = 0; |
| 969 | asyw->set.mask = 0; |
| 970 | return &asyw->state; |
| 971 | } |
| 972 | |
| 973 | static void |
| 974 | nv50_wndw_reset(struct drm_plane *plane) |
| 975 | { |
| 976 | struct nv50_wndw_atom *asyw; |
| 977 | |
| 978 | if (WARN_ON(!(asyw = kzalloc(sizeof(*asyw), GFP_KERNEL)))) |
| 979 | return; |
| 980 | |
| 981 | if (plane->state) |
| 982 | plane->funcs->atomic_destroy_state(plane, plane->state); |
| 983 | plane->state = &asyw->state; |
| 984 | plane->state->plane = plane; |
| 985 | plane->state->rotation = DRM_ROTATE_0; |
| 986 | } |
| 987 | |
| 988 | static void |
| 989 | nv50_wndw_destroy(struct drm_plane *plane) |
| 990 | { |
| 991 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 992 | void *data; |
| 993 | nvif_notify_fini(&wndw->notify); |
| 994 | data = wndw->func->dtor(wndw); |
| 995 | drm_plane_cleanup(&wndw->plane); |
| 996 | kfree(data); |
| 997 | } |
| 998 | |
| 999 | static const struct drm_plane_funcs |
| 1000 | nv50_wndw = { |
| 1001 | .destroy = nv50_wndw_destroy, |
| 1002 | .reset = nv50_wndw_reset, |
| 1003 | .set_property = drm_atomic_helper_plane_set_property, |
| 1004 | .atomic_duplicate_state = nv50_wndw_atomic_duplicate_state, |
| 1005 | .atomic_destroy_state = nv50_wndw_atomic_destroy_state, |
| 1006 | }; |
| 1007 | |
| 1008 | static void |
| 1009 | nv50_wndw_fini(struct nv50_wndw *wndw) |
| 1010 | { |
| 1011 | nvif_notify_put(&wndw->notify); |
| 1012 | } |
| 1013 | |
| 1014 | static void |
| 1015 | nv50_wndw_init(struct nv50_wndw *wndw) |
| 1016 | { |
| 1017 | nvif_notify_get(&wndw->notify); |
| 1018 | } |
| 1019 | |
| 1020 | static int |
| 1021 | nv50_wndw_ctor(const struct nv50_wndw_func *func, struct drm_device *dev, |
| 1022 | enum drm_plane_type type, const char *name, int index, |
| 1023 | struct nv50_dmac *dmac, const u32 *format, int nformat, |
| 1024 | struct nv50_wndw *wndw) |
| 1025 | { |
| 1026 | int ret; |
| 1027 | |
| 1028 | wndw->func = func; |
| 1029 | wndw->dmac = dmac; |
| 1030 | |
| 1031 | ret = drm_universal_plane_init(dev, &wndw->plane, 0, &nv50_wndw, format, |
| 1032 | nformat, type, "%s-%d", name, index); |
| 1033 | if (ret) |
| 1034 | return ret; |
| 1035 | |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
| 1039 | /****************************************************************************** |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1040 | * Cursor plane |
| 1041 | *****************************************************************************/ |
| 1042 | #define nv50_curs(p) container_of((p), struct nv50_curs, wndw) |
| 1043 | |
| 1044 | struct nv50_curs { |
| 1045 | struct nv50_wndw wndw; |
| 1046 | struct nvif_object chan; |
| 1047 | }; |
| 1048 | |
| 1049 | static u32 |
| 1050 | nv50_curs_update(struct nv50_wndw *wndw, u32 interlock) |
| 1051 | { |
| 1052 | struct nv50_curs *curs = nv50_curs(wndw); |
| 1053 | nvif_wr32(&curs->chan, 0x0080, 0x00000000); |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
| 1057 | static void |
| 1058 | nv50_curs_point(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1059 | { |
| 1060 | struct nv50_curs *curs = nv50_curs(wndw); |
| 1061 | nvif_wr32(&curs->chan, 0x0084, (asyw->point.y << 16) | asyw->point.x); |
| 1062 | } |
| 1063 | |
| 1064 | static void |
| 1065 | nv50_curs_prepare(struct nv50_wndw *wndw, struct nv50_head_atom *asyh, |
| 1066 | struct nv50_wndw_atom *asyw) |
| 1067 | { |
| 1068 | asyh->curs.handle = nv50_disp(wndw->plane.dev)->mast.base.vram.handle; |
| 1069 | asyh->curs.offset = asyw->image.offset; |
| 1070 | asyh->set.curs = asyh->curs.visible; |
| 1071 | } |
| 1072 | |
| 1073 | static void |
| 1074 | nv50_curs_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, |
| 1075 | struct nv50_head_atom *asyh) |
| 1076 | { |
| 1077 | asyh->curs.visible = false; |
| 1078 | } |
| 1079 | |
| 1080 | static int |
| 1081 | nv50_curs_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, |
| 1082 | struct nv50_head_atom *asyh) |
| 1083 | { |
| 1084 | int ret; |
| 1085 | |
| 1086 | ret = drm_plane_helper_check_state(&asyw->state, &asyw->clip, |
| 1087 | DRM_PLANE_HELPER_NO_SCALING, |
| 1088 | DRM_PLANE_HELPER_NO_SCALING, |
| 1089 | true, true); |
| 1090 | asyh->curs.visible = asyw->state.visible; |
| 1091 | if (ret || !asyh->curs.visible) |
| 1092 | return ret; |
| 1093 | |
| 1094 | switch (asyw->state.fb->width) { |
| 1095 | case 32: asyh->curs.layout = 0; break; |
| 1096 | case 64: asyh->curs.layout = 1; break; |
| 1097 | default: |
| 1098 | return -EINVAL; |
| 1099 | } |
| 1100 | |
| 1101 | if (asyw->state.fb->width != asyw->state.fb->height) |
| 1102 | return -EINVAL; |
| 1103 | |
| 1104 | switch (asyw->state.fb->pixel_format) { |
| 1105 | case DRM_FORMAT_ARGB8888: asyh->curs.format = 1; break; |
| 1106 | default: |
| 1107 | WARN_ON(1); |
| 1108 | return -EINVAL; |
| 1109 | } |
| 1110 | |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
| 1114 | static void * |
| 1115 | nv50_curs_dtor(struct nv50_wndw *wndw) |
| 1116 | { |
| 1117 | struct nv50_curs *curs = nv50_curs(wndw); |
| 1118 | nvif_object_fini(&curs->chan); |
| 1119 | return curs; |
| 1120 | } |
| 1121 | |
| 1122 | static const u32 |
| 1123 | nv50_curs_format[] = { |
| 1124 | DRM_FORMAT_ARGB8888, |
| 1125 | }; |
| 1126 | |
| 1127 | static const struct nv50_wndw_func |
| 1128 | nv50_curs = { |
| 1129 | .dtor = nv50_curs_dtor, |
| 1130 | .acquire = nv50_curs_acquire, |
| 1131 | .release = nv50_curs_release, |
| 1132 | .prepare = nv50_curs_prepare, |
| 1133 | .point = nv50_curs_point, |
| 1134 | .update = nv50_curs_update, |
| 1135 | }; |
| 1136 | |
| 1137 | static int |
| 1138 | nv50_curs_new(struct nouveau_drm *drm, struct nv50_head *head, |
| 1139 | struct nv50_curs **pcurs) |
| 1140 | { |
| 1141 | static const struct nvif_mclass curses[] = { |
| 1142 | { GK104_DISP_CURSOR, 0 }, |
| 1143 | { GF110_DISP_CURSOR, 0 }, |
| 1144 | { GT214_DISP_CURSOR, 0 }, |
| 1145 | { G82_DISP_CURSOR, 0 }, |
| 1146 | { NV50_DISP_CURSOR, 0 }, |
| 1147 | {} |
| 1148 | }; |
| 1149 | struct nv50_disp_cursor_v0 args = { |
| 1150 | .head = head->base.index, |
| 1151 | }; |
| 1152 | struct nv50_disp *disp = nv50_disp(drm->dev); |
| 1153 | struct nv50_curs *curs; |
| 1154 | int cid, ret; |
| 1155 | |
| 1156 | cid = nvif_mclass(disp->disp, curses); |
| 1157 | if (cid < 0) { |
| 1158 | NV_ERROR(drm, "No supported cursor immediate class\n"); |
| 1159 | return cid; |
| 1160 | } |
| 1161 | |
| 1162 | if (!(curs = *pcurs = kzalloc(sizeof(*curs), GFP_KERNEL))) |
| 1163 | return -ENOMEM; |
| 1164 | |
| 1165 | ret = nv50_wndw_ctor(&nv50_curs, drm->dev, DRM_PLANE_TYPE_CURSOR, |
| 1166 | "curs", head->base.index, &disp->mast.base, |
| 1167 | nv50_curs_format, ARRAY_SIZE(nv50_curs_format), |
| 1168 | &curs->wndw); |
| 1169 | if (ret) { |
| 1170 | kfree(curs); |
| 1171 | return ret; |
| 1172 | } |
| 1173 | |
| 1174 | ret = nvif_object_init(disp->disp, 0, curses[cid].oclass, &args, |
| 1175 | sizeof(args), &curs->chan); |
| 1176 | if (ret) { |
| 1177 | NV_ERROR(drm, "curs%04x allocation failed: %d\n", |
| 1178 | curses[cid].oclass, ret); |
| 1179 | return ret; |
| 1180 | } |
| 1181 | |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | /****************************************************************************** |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1186 | * Primary plane |
| 1187 | *****************************************************************************/ |
| 1188 | #define nv50_base(p) container_of((p), struct nv50_base, wndw) |
| 1189 | |
| 1190 | struct nv50_base { |
| 1191 | struct nv50_wndw wndw; |
| 1192 | struct nv50_sync chan; |
| 1193 | int id; |
| 1194 | }; |
| 1195 | |
| 1196 | static int |
| 1197 | nv50_base_notify(struct nvif_notify *notify) |
| 1198 | { |
| 1199 | return NVIF_NOTIFY_KEEP; |
| 1200 | } |
| 1201 | |
| 1202 | static void |
| 1203 | nv50_base_lut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1204 | { |
| 1205 | struct nv50_base *base = nv50_base(wndw); |
| 1206 | u32 *push; |
| 1207 | if ((push = evo_wait(&base->chan, 2))) { |
| 1208 | evo_mthd(push, 0x00e0, 1); |
| 1209 | evo_data(push, asyw->lut.enable << 30); |
| 1210 | evo_kick(push, &base->chan); |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | static void |
| 1215 | nv50_base_image_clr(struct nv50_wndw *wndw) |
| 1216 | { |
| 1217 | struct nv50_base *base = nv50_base(wndw); |
| 1218 | u32 *push; |
| 1219 | if ((push = evo_wait(&base->chan, 4))) { |
| 1220 | evo_mthd(push, 0x0084, 1); |
| 1221 | evo_data(push, 0x00000000); |
| 1222 | evo_mthd(push, 0x00c0, 1); |
| 1223 | evo_data(push, 0x00000000); |
| 1224 | evo_kick(push, &base->chan); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | static void |
| 1229 | nv50_base_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1230 | { |
| 1231 | struct nv50_base *base = nv50_base(wndw); |
| 1232 | const s32 oclass = base->chan.base.base.user.oclass; |
| 1233 | u32 *push; |
| 1234 | if ((push = evo_wait(&base->chan, 10))) { |
| 1235 | evo_mthd(push, 0x0084, 1); |
| 1236 | evo_data(push, (asyw->image.mode << 8) | |
| 1237 | (asyw->image.interval << 4)); |
| 1238 | evo_mthd(push, 0x00c0, 1); |
| 1239 | evo_data(push, asyw->image.handle); |
| 1240 | if (oclass < G82_DISP_BASE_CHANNEL_DMA) { |
| 1241 | evo_mthd(push, 0x0800, 5); |
| 1242 | evo_data(push, asyw->image.offset >> 8); |
| 1243 | evo_data(push, 0x00000000); |
| 1244 | evo_data(push, (asyw->image.h << 16) | asyw->image.w); |
| 1245 | evo_data(push, (asyw->image.layout << 20) | |
| 1246 | asyw->image.pitch | |
| 1247 | asyw->image.block); |
| 1248 | evo_data(push, (asyw->image.kind << 16) | |
| 1249 | (asyw->image.format << 8)); |
| 1250 | } else |
| 1251 | if (oclass < GF110_DISP_BASE_CHANNEL_DMA) { |
| 1252 | evo_mthd(push, 0x0800, 5); |
| 1253 | evo_data(push, asyw->image.offset >> 8); |
| 1254 | evo_data(push, 0x00000000); |
| 1255 | evo_data(push, (asyw->image.h << 16) | asyw->image.w); |
| 1256 | evo_data(push, (asyw->image.layout << 20) | |
| 1257 | asyw->image.pitch | |
| 1258 | asyw->image.block); |
| 1259 | evo_data(push, asyw->image.format << 8); |
| 1260 | } else { |
| 1261 | evo_mthd(push, 0x0400, 5); |
| 1262 | evo_data(push, asyw->image.offset >> 8); |
| 1263 | evo_data(push, 0x00000000); |
| 1264 | evo_data(push, (asyw->image.h << 16) | asyw->image.w); |
| 1265 | evo_data(push, (asyw->image.layout << 24) | |
| 1266 | asyw->image.pitch | |
| 1267 | asyw->image.block); |
| 1268 | evo_data(push, asyw->image.format << 8); |
| 1269 | } |
| 1270 | evo_kick(push, &base->chan); |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | static void |
| 1275 | nv50_base_ntfy_clr(struct nv50_wndw *wndw) |
| 1276 | { |
| 1277 | struct nv50_base *base = nv50_base(wndw); |
| 1278 | u32 *push; |
| 1279 | if ((push = evo_wait(&base->chan, 2))) { |
| 1280 | evo_mthd(push, 0x00a4, 1); |
| 1281 | evo_data(push, 0x00000000); |
| 1282 | evo_kick(push, &base->chan); |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | static void |
| 1287 | nv50_base_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1288 | { |
| 1289 | struct nv50_base *base = nv50_base(wndw); |
| 1290 | u32 *push; |
| 1291 | if ((push = evo_wait(&base->chan, 3))) { |
| 1292 | evo_mthd(push, 0x00a0, 2); |
| 1293 | evo_data(push, (asyw->ntfy.awaken << 30) | asyw->ntfy.offset); |
| 1294 | evo_data(push, asyw->ntfy.handle); |
| 1295 | evo_kick(push, &base->chan); |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | static void |
| 1300 | nv50_base_sema_clr(struct nv50_wndw *wndw) |
| 1301 | { |
| 1302 | struct nv50_base *base = nv50_base(wndw); |
| 1303 | u32 *push; |
| 1304 | if ((push = evo_wait(&base->chan, 2))) { |
| 1305 | evo_mthd(push, 0x0094, 1); |
| 1306 | evo_data(push, 0x00000000); |
| 1307 | evo_kick(push, &base->chan); |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | static void |
| 1312 | nv50_base_sema_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1313 | { |
| 1314 | struct nv50_base *base = nv50_base(wndw); |
| 1315 | u32 *push; |
| 1316 | if ((push = evo_wait(&base->chan, 5))) { |
| 1317 | evo_mthd(push, 0x0088, 4); |
| 1318 | evo_data(push, asyw->sema.offset); |
| 1319 | evo_data(push, asyw->sema.acquire); |
| 1320 | evo_data(push, asyw->sema.release); |
| 1321 | evo_data(push, asyw->sema.handle); |
| 1322 | evo_kick(push, &base->chan); |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | static u32 |
| 1327 | nv50_base_update(struct nv50_wndw *wndw, u32 interlock) |
| 1328 | { |
| 1329 | struct nv50_base *base = nv50_base(wndw); |
| 1330 | u32 *push; |
| 1331 | |
| 1332 | if (!(push = evo_wait(&base->chan, 2))) |
| 1333 | return 0; |
| 1334 | evo_mthd(push, 0x0080, 1); |
| 1335 | evo_data(push, interlock); |
| 1336 | evo_kick(push, &base->chan); |
| 1337 | |
| 1338 | if (base->chan.base.base.user.oclass < GF110_DISP_BASE_CHANNEL_DMA) |
| 1339 | return interlock ? 2 << (base->id * 8) : 0; |
| 1340 | return interlock ? 2 << (base->id * 4) : 0; |
| 1341 | } |
| 1342 | |
| 1343 | static int |
| 1344 | nv50_base_ntfy_wait_begun(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) |
| 1345 | { |
| 1346 | struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev); |
| 1347 | struct nv50_disp *disp = nv50_disp(wndw->plane.dev); |
| 1348 | if (nvif_msec(&drm->device, 2000ULL, |
| 1349 | u32 data = nouveau_bo_rd32(disp->sync, asyw->ntfy.offset / 4); |
| 1350 | if ((data & 0xc0000000) == 0x40000000) |
| 1351 | break; |
| 1352 | usleep_range(1, 2); |
| 1353 | ) < 0) |
| 1354 | return -ETIMEDOUT; |
| 1355 | return 0; |
| 1356 | } |
| 1357 | |
| 1358 | static void |
| 1359 | nv50_base_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, |
| 1360 | struct nv50_head_atom *asyh) |
| 1361 | { |
| 1362 | asyh->base.cpp = 0; |
| 1363 | } |
| 1364 | |
| 1365 | static int |
| 1366 | nv50_base_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, |
| 1367 | struct nv50_head_atom *asyh) |
| 1368 | { |
| 1369 | const u32 format = asyw->state.fb->pixel_format; |
| 1370 | const struct drm_format_info *info; |
| 1371 | int ret; |
| 1372 | |
| 1373 | info = drm_format_info(format); |
| 1374 | if (!info || !info->depth) |
| 1375 | return -EINVAL; |
| 1376 | |
| 1377 | ret = drm_plane_helper_check_state(&asyw->state, &asyw->clip, |
| 1378 | DRM_PLANE_HELPER_NO_SCALING, |
| 1379 | DRM_PLANE_HELPER_NO_SCALING, |
| 1380 | false, true); |
| 1381 | if (ret) |
| 1382 | return ret; |
| 1383 | |
| 1384 | asyh->base.depth = info->depth; |
| 1385 | asyh->base.cpp = info->cpp[0]; |
| 1386 | asyh->base.x = asyw->state.src.x1 >> 16; |
| 1387 | asyh->base.y = asyw->state.src.y1 >> 16; |
| 1388 | asyh->base.w = asyw->state.fb->width; |
| 1389 | asyh->base.h = asyw->state.fb->height; |
| 1390 | |
| 1391 | switch (format) { |
| 1392 | case DRM_FORMAT_C8 : asyw->image.format = 0x1e; break; |
| 1393 | case DRM_FORMAT_RGB565 : asyw->image.format = 0xe8; break; |
| 1394 | case DRM_FORMAT_XRGB1555 : |
| 1395 | case DRM_FORMAT_ARGB1555 : asyw->image.format = 0xe9; break; |
| 1396 | case DRM_FORMAT_XRGB8888 : |
| 1397 | case DRM_FORMAT_ARGB8888 : asyw->image.format = 0xcf; break; |
| 1398 | case DRM_FORMAT_XBGR2101010: |
| 1399 | case DRM_FORMAT_ABGR2101010: asyw->image.format = 0xd1; break; |
| 1400 | case DRM_FORMAT_XBGR8888 : |
| 1401 | case DRM_FORMAT_ABGR8888 : asyw->image.format = 0xd5; break; |
| 1402 | default: |
| 1403 | WARN_ON(1); |
| 1404 | return -EINVAL; |
| 1405 | } |
| 1406 | |
| 1407 | asyw->lut.enable = 1; |
| 1408 | asyw->set.image = true; |
| 1409 | return 0; |
| 1410 | } |
| 1411 | |
| 1412 | static void * |
| 1413 | nv50_base_dtor(struct nv50_wndw *wndw) |
| 1414 | { |
| 1415 | struct nv50_disp *disp = nv50_disp(wndw->plane.dev); |
| 1416 | struct nv50_base *base = nv50_base(wndw); |
| 1417 | nv50_dmac_destroy(&base->chan.base, disp->disp); |
| 1418 | return base; |
| 1419 | } |
| 1420 | |
| 1421 | static const u32 |
| 1422 | nv50_base_format[] = { |
| 1423 | DRM_FORMAT_C8, |
| 1424 | DRM_FORMAT_RGB565, |
| 1425 | DRM_FORMAT_XRGB1555, |
| 1426 | DRM_FORMAT_ARGB1555, |
| 1427 | DRM_FORMAT_XRGB8888, |
| 1428 | DRM_FORMAT_ARGB8888, |
| 1429 | DRM_FORMAT_XBGR2101010, |
| 1430 | DRM_FORMAT_ABGR2101010, |
| 1431 | DRM_FORMAT_XBGR8888, |
| 1432 | DRM_FORMAT_ABGR8888, |
| 1433 | }; |
| 1434 | |
| 1435 | static const struct nv50_wndw_func |
| 1436 | nv50_base = { |
| 1437 | .dtor = nv50_base_dtor, |
| 1438 | .acquire = nv50_base_acquire, |
| 1439 | .release = nv50_base_release, |
| 1440 | .sema_set = nv50_base_sema_set, |
| 1441 | .sema_clr = nv50_base_sema_clr, |
| 1442 | .ntfy_set = nv50_base_ntfy_set, |
| 1443 | .ntfy_clr = nv50_base_ntfy_clr, |
| 1444 | .ntfy_wait_begun = nv50_base_ntfy_wait_begun, |
| 1445 | .image_set = nv50_base_image_set, |
| 1446 | .image_clr = nv50_base_image_clr, |
| 1447 | .lut = nv50_base_lut, |
| 1448 | .update = nv50_base_update, |
| 1449 | }; |
| 1450 | |
| 1451 | static int |
| 1452 | nv50_base_new(struct nouveau_drm *drm, struct nv50_head *head, |
| 1453 | struct nv50_base **pbase) |
| 1454 | { |
| 1455 | struct nv50_disp *disp = nv50_disp(drm->dev); |
| 1456 | struct nv50_base *base; |
| 1457 | int ret; |
| 1458 | |
| 1459 | if (!(base = *pbase = kzalloc(sizeof(*base), GFP_KERNEL))) |
| 1460 | return -ENOMEM; |
| 1461 | base->id = head->base.index; |
| 1462 | base->wndw.ntfy = EVO_FLIP_NTFY0(base->id); |
| 1463 | base->wndw.sema = EVO_FLIP_SEM0(base->id); |
| 1464 | base->wndw.data = 0x00000000; |
| 1465 | |
| 1466 | ret = nv50_wndw_ctor(&nv50_base, drm->dev, DRM_PLANE_TYPE_PRIMARY, |
| 1467 | "base", base->id, &base->chan.base, |
| 1468 | nv50_base_format, ARRAY_SIZE(nv50_base_format), |
| 1469 | &base->wndw); |
| 1470 | if (ret) { |
| 1471 | kfree(base); |
| 1472 | return ret; |
| 1473 | } |
| 1474 | |
| 1475 | ret = nv50_base_create(&drm->device, disp->disp, base->id, |
| 1476 | disp->sync->bo.offset, &base->chan); |
| 1477 | if (ret) |
| 1478 | return ret; |
| 1479 | |
| 1480 | return nvif_notify_init(&base->chan.base.base.user, nv50_base_notify, |
| 1481 | false, |
| 1482 | NV50_DISP_BASE_CHANNEL_DMA_V0_NTFY_UEVENT, |
| 1483 | &(struct nvif_notify_uevent_req) {}, |
| 1484 | sizeof(struct nvif_notify_uevent_req), |
| 1485 | sizeof(struct nvif_notify_uevent_rep), |
| 1486 | &base->wndw.notify); |
| 1487 | } |
| 1488 | |
| 1489 | /****************************************************************************** |
Ben Skeggs | a63a97e | 2011-11-16 15:22:34 +1000 | [diff] [blame] | 1490 | * Page flipping channel |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1491 | *****************************************************************************/ |
| 1492 | struct nouveau_bo * |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1493 | nv50_display_crtc_sema(struct drm_device *dev, int crtc) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1494 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1495 | return nv50_disp(dev)->sync; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1496 | } |
| 1497 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1498 | struct nv50_display_flip { |
| 1499 | struct nv50_disp *disp; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1500 | struct nv50_base *base; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1501 | }; |
| 1502 | |
| 1503 | static bool |
| 1504 | nv50_display_flip_wait(void *data) |
| 1505 | { |
| 1506 | struct nv50_display_flip *flip = data; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1507 | if (nouveau_bo_rd32(flip->disp->sync, flip->base->wndw.sema / 4) == |
| 1508 | flip->base->wndw.data) |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1509 | return true; |
| 1510 | usleep_range(1, 2); |
| 1511 | return false; |
| 1512 | } |
| 1513 | |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1514 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1515 | nv50_display_flip_stop(struct drm_crtc *crtc) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1516 | { |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1517 | struct nvif_device *device = &nouveau_drm(crtc->dev)->device; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1518 | struct nv50_base *base = nv50_head(crtc)->_base; |
| 1519 | struct nv50_wndw *wndw = &base->wndw; |
| 1520 | struct nv50_wndw_atom *asyw = &wndw->asy; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1521 | struct nv50_display_flip flip = { |
| 1522 | .disp = nv50_disp(crtc->dev), |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1523 | .base = base, |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1524 | }; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1525 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1526 | asyw->state.crtc = NULL; |
| 1527 | asyw->state.fb = NULL; |
| 1528 | nv50_wndw_atomic_check(&wndw->plane, &asyw->state); |
| 1529 | nv50_wndw_flush_clr(wndw, 0, true, asyw); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1530 | |
Ben Skeggs | 5444204 | 2015-08-20 14:54:11 +1000 | [diff] [blame] | 1531 | nvif_msec(device, 2000, |
| 1532 | if (nv50_display_flip_wait(&flip)) |
| 1533 | break; |
| 1534 | ); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1538 | nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1539 | struct nouveau_channel *chan, u32 swap_interval) |
| 1540 | { |
| 1541 | struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1542 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1543 | struct nv50_head *head = nv50_head(crtc); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1544 | struct nv50_base *base = nv50_head(crtc)->_base; |
| 1545 | struct nv50_wndw *wndw = &base->wndw; |
| 1546 | struct nv50_wndw_atom *asyw = &wndw->asy; |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1547 | int ret; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1548 | |
Ben Skeggs | 9ba8310 | 2014-12-22 19:50:23 +1000 | [diff] [blame] | 1549 | if (crtc->primary->fb->width != fb->width || |
| 1550 | crtc->primary->fb->height != fb->height) |
| 1551 | return -EINVAL; |
| 1552 | |
Ben Skeggs | f60b6e7 | 2013-03-19 15:20:00 +1000 | [diff] [blame] | 1553 | if (chan == NULL) |
| 1554 | evo_sync(crtc->dev); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1555 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1556 | if (chan && chan->user.oclass < G82_CHANNEL_GPFIFO) { |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1557 | ret = RING_SPACE(chan, 8); |
| 1558 | if (ret) |
| 1559 | return ret; |
Ben Skeggs | 67f9718 | 2013-02-26 12:02:54 +1000 | [diff] [blame] | 1560 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1561 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1562 | OUT_RING (chan, NvEvoSema0 + nv_crtc->index); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1563 | OUT_RING (chan, base->wndw.sema ^ 0x10); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1564 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1565 | OUT_RING (chan, base->wndw.data + 1); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1566 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1567 | OUT_RING (chan, base->wndw.sema); |
| 1568 | OUT_RING (chan, base->wndw.data); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1569 | } else |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1570 | if (chan && chan->user.oclass < FERMI_CHANNEL_GPFIFO) { |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1571 | u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + base->wndw.sema; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1572 | ret = RING_SPACE(chan, 12); |
| 1573 | if (ret) |
| 1574 | return ret; |
Ben Skeggs | a34caf7 | 2013-02-14 09:28:37 +1000 | [diff] [blame] | 1575 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1576 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1); |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1577 | OUT_RING (chan, chan->vram.handle); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1578 | BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 1579 | OUT_RING (chan, upper_32_bits(addr ^ 0x10)); |
| 1580 | OUT_RING (chan, lower_32_bits(addr ^ 0x10)); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1581 | OUT_RING (chan, base->wndw.data + 1); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1582 | OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG); |
| 1583 | BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 1584 | OUT_RING (chan, upper_32_bits(addr)); |
| 1585 | OUT_RING (chan, lower_32_bits(addr)); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1586 | OUT_RING (chan, base->wndw.data); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1587 | OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL); |
| 1588 | } else |
| 1589 | if (chan) { |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1590 | u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + base->wndw.sema; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1591 | ret = RING_SPACE(chan, 10); |
| 1592 | if (ret) |
| 1593 | return ret; |
Ben Skeggs | 67f9718 | 2013-02-26 12:02:54 +1000 | [diff] [blame] | 1594 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1595 | BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 1596 | OUT_RING (chan, upper_32_bits(addr ^ 0x10)); |
| 1597 | OUT_RING (chan, lower_32_bits(addr ^ 0x10)); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1598 | OUT_RING (chan, base->wndw.data + 1); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1599 | OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG | |
| 1600 | NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD); |
| 1601 | BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 1602 | OUT_RING (chan, upper_32_bits(addr)); |
| 1603 | OUT_RING (chan, lower_32_bits(addr)); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1604 | OUT_RING (chan, base->wndw.data); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1605 | OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL | |
| 1606 | NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD); |
| 1607 | } |
Ben Skeggs | 35bcf5d | 2012-04-30 11:34:10 -0500 | [diff] [blame] | 1608 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1609 | if (chan) { |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1610 | base->wndw.sema ^= 0x10; |
| 1611 | base->wndw.data++; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1612 | FIRE_RING (chan); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | /* queue the flip */ |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1616 | asyw->state.crtc = &head->base.base; |
| 1617 | asyw->state.fb = fb; |
| 1618 | asyw->interval = swap_interval; |
| 1619 | asyw->image.handle = nv_fb->r_handle; |
| 1620 | asyw->image.offset = nv_fb->nvbo->bo.offset; |
| 1621 | asyw->sema.handle = base->chan.base.sync.handle; |
| 1622 | asyw->sema.offset = base->wndw.sema; |
| 1623 | asyw->sema.acquire = base->wndw.data++; |
| 1624 | asyw->sema.release = base->wndw.data; |
| 1625 | nv50_wndw_atomic_check(&wndw->plane, &asyw->state); |
| 1626 | asyw->set.sema = true; |
| 1627 | nv50_wndw_flush_set(wndw, 0, asyw); |
| 1628 | nv50_wndw_wait_armed(wndw, asyw); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1629 | |
| 1630 | nouveau_bo_ref(nv_fb->nvbo, &head->image); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1631 | return 0; |
| 1632 | } |
| 1633 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1634 | /****************************************************************************** |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1635 | * Head |
| 1636 | *****************************************************************************/ |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1637 | static void |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1638 | nv50_head_procamp(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1639 | { |
| 1640 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1641 | u32 *push; |
| 1642 | if ((push = evo_wait(core, 2))) { |
| 1643 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) |
| 1644 | evo_mthd(push, 0x08a8 + (head->base.index * 0x400), 1); |
| 1645 | else |
| 1646 | evo_mthd(push, 0x0498 + (head->base.index * 0x300), 1); |
| 1647 | evo_data(push, (asyh->procamp.sat.sin << 20) | |
| 1648 | (asyh->procamp.sat.cos << 8)); |
| 1649 | evo_kick(push, core); |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | static void |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1654 | nv50_head_dither(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1655 | { |
| 1656 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1657 | u32 *push; |
| 1658 | if ((push = evo_wait(core, 2))) { |
| 1659 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) |
| 1660 | evo_mthd(push, 0x08a0 + (head->base.index * 0x0400), 1); |
| 1661 | else |
| 1662 | if (core->base.user.oclass < GK104_DISP_CORE_CHANNEL_DMA) |
| 1663 | evo_mthd(push, 0x0490 + (head->base.index * 0x0300), 1); |
| 1664 | else |
| 1665 | evo_mthd(push, 0x04a0 + (head->base.index * 0x0300), 1); |
| 1666 | evo_data(push, (asyh->dither.mode << 3) | |
| 1667 | (asyh->dither.bits << 1) | |
| 1668 | asyh->dither.enable); |
| 1669 | evo_kick(push, core); |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | static void |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1674 | nv50_head_ovly(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1675 | { |
| 1676 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1677 | u32 bounds = 0; |
| 1678 | u32 *push; |
| 1679 | |
| 1680 | if (asyh->base.cpp) { |
| 1681 | switch (asyh->base.cpp) { |
| 1682 | case 8: bounds |= 0x00000500; break; |
| 1683 | case 4: bounds |= 0x00000300; break; |
| 1684 | case 2: bounds |= 0x00000100; break; |
| 1685 | default: |
| 1686 | WARN_ON(1); |
| 1687 | break; |
| 1688 | } |
| 1689 | bounds |= 0x00000001; |
| 1690 | } |
| 1691 | |
| 1692 | if ((push = evo_wait(core, 2))) { |
| 1693 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) |
| 1694 | evo_mthd(push, 0x0904 + head->base.index * 0x400, 1); |
| 1695 | else |
| 1696 | evo_mthd(push, 0x04d4 + head->base.index * 0x300, 1); |
| 1697 | evo_data(push, bounds); |
| 1698 | evo_kick(push, core); |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | static void |
| 1703 | nv50_head_base(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1704 | { |
| 1705 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1706 | u32 bounds = 0; |
| 1707 | u32 *push; |
| 1708 | |
| 1709 | if (asyh->base.cpp) { |
| 1710 | switch (asyh->base.cpp) { |
| 1711 | case 8: bounds |= 0x00000500; break; |
| 1712 | case 4: bounds |= 0x00000300; break; |
| 1713 | case 2: bounds |= 0x00000100; break; |
| 1714 | case 1: bounds |= 0x00000000; break; |
| 1715 | default: |
| 1716 | WARN_ON(1); |
| 1717 | break; |
| 1718 | } |
| 1719 | bounds |= 0x00000001; |
| 1720 | } |
| 1721 | |
| 1722 | if ((push = evo_wait(core, 2))) { |
| 1723 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) |
| 1724 | evo_mthd(push, 0x0900 + head->base.index * 0x400, 1); |
| 1725 | else |
| 1726 | evo_mthd(push, 0x04d0 + head->base.index * 0x300, 1); |
| 1727 | evo_data(push, bounds); |
| 1728 | evo_kick(push, core); |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | static void |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1733 | nv50_head_curs_clr(struct nv50_head *head) |
| 1734 | { |
| 1735 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1736 | u32 *push; |
| 1737 | if ((push = evo_wait(core, 4))) { |
| 1738 | if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) { |
| 1739 | evo_mthd(push, 0x0880 + head->base.index * 0x400, 1); |
| 1740 | evo_data(push, 0x05000000); |
| 1741 | } else |
| 1742 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1743 | evo_mthd(push, 0x0880 + head->base.index * 0x400, 1); |
| 1744 | evo_data(push, 0x05000000); |
| 1745 | evo_mthd(push, 0x089c + head->base.index * 0x400, 1); |
| 1746 | evo_data(push, 0x00000000); |
| 1747 | } else { |
| 1748 | evo_mthd(push, 0x0480 + head->base.index * 0x300, 1); |
| 1749 | evo_data(push, 0x05000000); |
| 1750 | evo_mthd(push, 0x048c + head->base.index * 0x300, 1); |
| 1751 | evo_data(push, 0x00000000); |
| 1752 | } |
| 1753 | evo_kick(push, core); |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | static void |
| 1758 | nv50_head_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1759 | { |
| 1760 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1761 | u32 *push; |
| 1762 | if ((push = evo_wait(core, 5))) { |
| 1763 | if (core->base.user.oclass < G82_DISP_BASE_CHANNEL_DMA) { |
| 1764 | evo_mthd(push, 0x0880 + head->base.index * 0x400, 2); |
| 1765 | evo_data(push, 0x80000000 | (asyh->curs.layout << 26) | |
| 1766 | (asyh->curs.format << 24)); |
| 1767 | evo_data(push, asyh->curs.offset >> 8); |
| 1768 | } else |
| 1769 | if (core->base.user.oclass < GF110_DISP_BASE_CHANNEL_DMA) { |
| 1770 | evo_mthd(push, 0x0880 + head->base.index * 0x400, 2); |
| 1771 | evo_data(push, 0x80000000 | (asyh->curs.layout << 26) | |
| 1772 | (asyh->curs.format << 24)); |
| 1773 | evo_data(push, asyh->curs.offset >> 8); |
| 1774 | evo_mthd(push, 0x089c + head->base.index * 0x400, 1); |
| 1775 | evo_data(push, asyh->curs.handle); |
| 1776 | } else { |
| 1777 | evo_mthd(push, 0x0480 + head->base.index * 0x300, 2); |
| 1778 | evo_data(push, 0x80000000 | (asyh->curs.layout << 26) | |
| 1779 | (asyh->curs.format << 24)); |
| 1780 | evo_data(push, asyh->curs.offset >> 8); |
| 1781 | evo_mthd(push, 0x048c + head->base.index * 0x300, 1); |
| 1782 | evo_data(push, asyh->curs.handle); |
| 1783 | } |
| 1784 | evo_kick(push, core); |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | static void |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1789 | nv50_head_core_clr(struct nv50_head *head) |
| 1790 | { |
| 1791 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1792 | u32 *push; |
| 1793 | if ((push = evo_wait(core, 2))) { |
| 1794 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) |
| 1795 | evo_mthd(push, 0x0874 + head->base.index * 0x400, 1); |
| 1796 | else |
| 1797 | evo_mthd(push, 0x0474 + head->base.index * 0x300, 1); |
| 1798 | evo_data(push, 0x00000000); |
| 1799 | evo_kick(push, core); |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | static void |
| 1804 | nv50_head_core_set(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1805 | { |
| 1806 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1807 | u32 *push; |
| 1808 | if ((push = evo_wait(core, 9))) { |
| 1809 | if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) { |
| 1810 | evo_mthd(push, 0x0860 + head->base.index * 0x400, 1); |
| 1811 | evo_data(push, asyh->core.offset >> 8); |
| 1812 | evo_mthd(push, 0x0868 + head->base.index * 0x400, 4); |
| 1813 | evo_data(push, (asyh->core.h << 16) | asyh->core.w); |
| 1814 | evo_data(push, asyh->core.layout << 20 | |
| 1815 | (asyh->core.pitch >> 8) << 8 | |
| 1816 | asyh->core.block); |
| 1817 | evo_data(push, asyh->core.kind << 16 | |
| 1818 | asyh->core.format << 8); |
| 1819 | evo_data(push, asyh->core.handle); |
| 1820 | evo_mthd(push, 0x08c0 + head->base.index * 0x400, 1); |
| 1821 | evo_data(push, (asyh->core.y << 16) | asyh->core.x); |
| 1822 | } else |
| 1823 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1824 | evo_mthd(push, 0x0860 + head->base.index * 0x400, 1); |
| 1825 | evo_data(push, asyh->core.offset >> 8); |
| 1826 | evo_mthd(push, 0x0868 + head->base.index * 0x400, 4); |
| 1827 | evo_data(push, (asyh->core.h << 16) | asyh->core.w); |
| 1828 | evo_data(push, asyh->core.layout << 20 | |
| 1829 | (asyh->core.pitch >> 8) << 8 | |
| 1830 | asyh->core.block); |
| 1831 | evo_data(push, asyh->core.format << 8); |
| 1832 | evo_data(push, asyh->core.handle); |
| 1833 | evo_mthd(push, 0x08c0 + head->base.index * 0x400, 1); |
| 1834 | evo_data(push, (asyh->core.y << 16) | asyh->core.x); |
| 1835 | } else { |
| 1836 | evo_mthd(push, 0x0460 + head->base.index * 0x300, 1); |
| 1837 | evo_data(push, asyh->core.offset >> 8); |
| 1838 | evo_mthd(push, 0x0468 + head->base.index * 0x300, 4); |
| 1839 | evo_data(push, (asyh->core.h << 16) | asyh->core.w); |
| 1840 | evo_data(push, asyh->core.layout << 24 | |
| 1841 | (asyh->core.pitch >> 8) << 8 | |
| 1842 | asyh->core.block); |
| 1843 | evo_data(push, asyh->core.format << 8); |
| 1844 | evo_data(push, asyh->core.handle); |
| 1845 | evo_mthd(push, 0x04b0 + head->base.index * 0x300, 1); |
| 1846 | evo_data(push, (asyh->core.y << 16) | asyh->core.x); |
| 1847 | } |
| 1848 | evo_kick(push, core); |
| 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | static void |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1853 | nv50_head_lut_clr(struct nv50_head *head) |
| 1854 | { |
| 1855 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1856 | u32 *push; |
| 1857 | if ((push = evo_wait(core, 4))) { |
| 1858 | if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) { |
| 1859 | evo_mthd(push, 0x0840 + (head->base.index * 0x400), 1); |
| 1860 | evo_data(push, 0x40000000); |
| 1861 | } else |
| 1862 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1863 | evo_mthd(push, 0x0840 + (head->base.index * 0x400), 1); |
| 1864 | evo_data(push, 0x40000000); |
| 1865 | evo_mthd(push, 0x085c + (head->base.index * 0x400), 1); |
| 1866 | evo_data(push, 0x00000000); |
| 1867 | } else { |
| 1868 | evo_mthd(push, 0x0440 + (head->base.index * 0x300), 1); |
| 1869 | evo_data(push, 0x03000000); |
| 1870 | evo_mthd(push, 0x045c + (head->base.index * 0x300), 1); |
| 1871 | evo_data(push, 0x00000000); |
| 1872 | } |
| 1873 | evo_kick(push, core); |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | static void |
| 1878 | nv50_head_lut_set(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1879 | { |
| 1880 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1881 | u32 *push; |
| 1882 | if ((push = evo_wait(core, 7))) { |
| 1883 | if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) { |
| 1884 | evo_mthd(push, 0x0840 + (head->base.index * 0x400), 2); |
| 1885 | evo_data(push, 0xc0000000); |
| 1886 | evo_data(push, asyh->lut.offset >> 8); |
| 1887 | } else |
| 1888 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1889 | evo_mthd(push, 0x0840 + (head->base.index * 0x400), 2); |
| 1890 | evo_data(push, 0xc0000000); |
| 1891 | evo_data(push, asyh->lut.offset >> 8); |
| 1892 | evo_mthd(push, 0x085c + (head->base.index * 0x400), 1); |
| 1893 | evo_data(push, asyh->lut.handle); |
| 1894 | } else { |
| 1895 | evo_mthd(push, 0x0440 + (head->base.index * 0x300), 4); |
| 1896 | evo_data(push, 0x83000000); |
| 1897 | evo_data(push, asyh->lut.offset >> 8); |
| 1898 | evo_data(push, 0x00000000); |
| 1899 | evo_data(push, 0x00000000); |
| 1900 | evo_mthd(push, 0x045c + (head->base.index * 0x300), 1); |
| 1901 | evo_data(push, asyh->lut.handle); |
| 1902 | } |
| 1903 | evo_kick(push, core); |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | static void |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1908 | nv50_head_mode(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1909 | { |
| 1910 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1911 | struct nv50_head_mode *m = &asyh->mode; |
| 1912 | u32 *push; |
| 1913 | if ((push = evo_wait(core, 14))) { |
| 1914 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1915 | evo_mthd(push, 0x0804 + (head->base.index * 0x400), 2); |
| 1916 | evo_data(push, 0x00800000 | m->clock); |
| 1917 | evo_data(push, m->interlace ? 0x00000002 : 0x00000000); |
Ben Skeggs | 06ab282 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1918 | evo_mthd(push, 0x0810 + (head->base.index * 0x400), 7); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1919 | evo_data(push, 0x00000000); |
| 1920 | evo_data(push, (m->v.active << 16) | m->h.active ); |
| 1921 | evo_data(push, (m->v.synce << 16) | m->h.synce ); |
| 1922 | evo_data(push, (m->v.blanke << 16) | m->h.blanke ); |
| 1923 | evo_data(push, (m->v.blanks << 16) | m->h.blanks ); |
| 1924 | evo_data(push, (m->v.blank2e << 16) | m->v.blank2s); |
Ben Skeggs | 06ab282 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1925 | evo_data(push, asyh->mode.v.blankus); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1926 | evo_mthd(push, 0x082c + (head->base.index * 0x400), 1); |
| 1927 | evo_data(push, 0x00000000); |
| 1928 | } else { |
| 1929 | evo_mthd(push, 0x0410 + (head->base.index * 0x300), 6); |
| 1930 | evo_data(push, 0x00000000); |
| 1931 | evo_data(push, (m->v.active << 16) | m->h.active ); |
| 1932 | evo_data(push, (m->v.synce << 16) | m->h.synce ); |
| 1933 | evo_data(push, (m->v.blanke << 16) | m->h.blanke ); |
| 1934 | evo_data(push, (m->v.blanks << 16) | m->h.blanks ); |
| 1935 | evo_data(push, (m->v.blank2e << 16) | m->v.blank2s); |
| 1936 | evo_mthd(push, 0x042c + (head->base.index * 0x300), 2); |
| 1937 | evo_data(push, 0x00000000); /* ??? */ |
| 1938 | evo_data(push, 0xffffff00); |
| 1939 | evo_mthd(push, 0x0450 + (head->base.index * 0x300), 3); |
| 1940 | evo_data(push, m->clock * 1000); |
| 1941 | evo_data(push, 0x00200000); /* ??? */ |
| 1942 | evo_data(push, m->clock * 1000); |
| 1943 | } |
| 1944 | evo_kick(push, core); |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | static void |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1949 | nv50_head_view(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1950 | { |
| 1951 | struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base; |
| 1952 | u32 *push; |
| 1953 | if ((push = evo_wait(core, 10))) { |
| 1954 | if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) { |
| 1955 | evo_mthd(push, 0x08a4 + (head->base.index * 0x400), 1); |
| 1956 | evo_data(push, 0x00000000); |
| 1957 | evo_mthd(push, 0x08c8 + (head->base.index * 0x400), 1); |
| 1958 | evo_data(push, (asyh->view.iH << 16) | asyh->view.iW); |
| 1959 | evo_mthd(push, 0x08d8 + (head->base.index * 0x400), 2); |
| 1960 | evo_data(push, (asyh->view.oH << 16) | asyh->view.oW); |
| 1961 | evo_data(push, (asyh->view.oH << 16) | asyh->view.oW); |
| 1962 | } else { |
| 1963 | evo_mthd(push, 0x0494 + (head->base.index * 0x300), 1); |
| 1964 | evo_data(push, 0x00000000); |
| 1965 | evo_mthd(push, 0x04b8 + (head->base.index * 0x300), 1); |
| 1966 | evo_data(push, (asyh->view.iH << 16) | asyh->view.iW); |
| 1967 | evo_mthd(push, 0x04c0 + (head->base.index * 0x300), 3); |
| 1968 | evo_data(push, (asyh->view.oH << 16) | asyh->view.oW); |
| 1969 | evo_data(push, (asyh->view.oH << 16) | asyh->view.oW); |
| 1970 | evo_data(push, (asyh->view.oH << 16) | asyh->view.oW); |
| 1971 | } |
| 1972 | evo_kick(push, core); |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | static void |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1977 | nv50_head_flush_clr(struct nv50_head *head, struct nv50_head_atom *asyh, bool y) |
| 1978 | { |
| 1979 | if (asyh->clr.core && (!asyh->set.core || y)) |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1980 | nv50_head_lut_clr(head); |
| 1981 | if (asyh->clr.core && (!asyh->set.core || y)) |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1982 | nv50_head_core_clr(head); |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1983 | if (asyh->clr.curs && (!asyh->set.curs || y)) |
| 1984 | nv50_head_curs_clr(head); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | static void |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1988 | nv50_head_flush_set(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 1989 | { |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1990 | if (asyh->set.view ) nv50_head_view (head, asyh); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1991 | if (asyh->set.mode ) nv50_head_mode (head, asyh); |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1992 | if (asyh->set.core ) nv50_head_lut_set (head, asyh); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1993 | if (asyh->set.core ) nv50_head_core_set(head, asyh); |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1994 | if (asyh->set.curs ) nv50_head_curs_set(head, asyh); |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1995 | if (asyh->set.base ) nv50_head_base (head, asyh); |
| 1996 | if (asyh->set.ovly ) nv50_head_ovly (head, asyh); |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1997 | if (asyh->set.dither ) nv50_head_dither (head, asyh); |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1998 | if (asyh->set.procamp) nv50_head_procamp (head, asyh); |
| 1999 | } |
| 2000 | |
| 2001 | static void |
| 2002 | nv50_head_atomic_check_procamp(struct nv50_head_atom *armh, |
| 2003 | struct nv50_head_atom *asyh, |
| 2004 | struct nouveau_conn_atom *asyc) |
| 2005 | { |
| 2006 | const int vib = asyc->procamp.color_vibrance - 100; |
| 2007 | const int hue = asyc->procamp.vibrant_hue - 90; |
| 2008 | const int adj = (vib > 0) ? 50 : 0; |
| 2009 | asyh->procamp.sat.cos = ((vib * 2047 + adj) / 100) & 0xfff; |
| 2010 | asyh->procamp.sat.sin = ((hue * 2047) / 100) & 0xfff; |
| 2011 | asyh->set.procamp = true; |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | static void |
| 2015 | nv50_head_atomic_check_dither(struct nv50_head_atom *armh, |
| 2016 | struct nv50_head_atom *asyh, |
| 2017 | struct nouveau_conn_atom *asyc) |
| 2018 | { |
| 2019 | struct drm_connector *connector = asyc->state.connector; |
| 2020 | u32 mode = 0x00; |
| 2021 | |
| 2022 | if (asyc->dither.mode == DITHERING_MODE_AUTO) { |
| 2023 | if (asyh->base.depth > connector->display_info.bpc * 3) |
| 2024 | mode = DITHERING_MODE_DYNAMIC2X2; |
| 2025 | } else { |
| 2026 | mode = asyc->dither.mode; |
| 2027 | } |
| 2028 | |
| 2029 | if (asyc->dither.depth == DITHERING_DEPTH_AUTO) { |
| 2030 | if (connector->display_info.bpc >= 8) |
| 2031 | mode |= DITHERING_DEPTH_8BPC; |
| 2032 | } else { |
| 2033 | mode |= asyc->dither.depth; |
| 2034 | } |
| 2035 | |
| 2036 | asyh->dither.enable = mode; |
| 2037 | asyh->dither.bits = mode >> 1; |
| 2038 | asyh->dither.mode = mode >> 3; |
| 2039 | asyh->set.dither = true; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | static void |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2043 | nv50_head_atomic_check_view(struct nv50_head_atom *armh, |
| 2044 | struct nv50_head_atom *asyh, |
| 2045 | struct nouveau_conn_atom *asyc) |
| 2046 | { |
| 2047 | struct drm_connector *connector = asyc->state.connector; |
| 2048 | struct drm_display_mode *omode = &asyh->state.adjusted_mode; |
| 2049 | struct drm_display_mode *umode = &asyh->state.mode; |
| 2050 | int mode = asyc->scaler.mode; |
| 2051 | struct edid *edid; |
| 2052 | |
| 2053 | if (connector->edid_blob_ptr) |
| 2054 | edid = (struct edid *)connector->edid_blob_ptr->data; |
| 2055 | else |
| 2056 | edid = NULL; |
| 2057 | |
| 2058 | if (!asyc->scaler.full) { |
| 2059 | if (mode == DRM_MODE_SCALE_NONE) |
| 2060 | omode = umode; |
| 2061 | } else { |
| 2062 | /* Non-EDID LVDS/eDP mode. */ |
| 2063 | mode = DRM_MODE_SCALE_FULLSCREEN; |
| 2064 | } |
| 2065 | |
| 2066 | asyh->view.iW = umode->hdisplay; |
| 2067 | asyh->view.iH = umode->vdisplay; |
| 2068 | asyh->view.oW = omode->hdisplay; |
| 2069 | asyh->view.oH = omode->vdisplay; |
| 2070 | if (omode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 2071 | asyh->view.oH *= 2; |
| 2072 | |
| 2073 | /* Add overscan compensation if necessary, will keep the aspect |
| 2074 | * ratio the same as the backend mode unless overridden by the |
| 2075 | * user setting both hborder and vborder properties. |
| 2076 | */ |
| 2077 | if ((asyc->scaler.underscan.mode == UNDERSCAN_ON || |
| 2078 | (asyc->scaler.underscan.mode == UNDERSCAN_AUTO && |
| 2079 | drm_detect_hdmi_monitor(edid)))) { |
| 2080 | u32 bX = asyc->scaler.underscan.hborder; |
| 2081 | u32 bY = asyc->scaler.underscan.vborder; |
| 2082 | u32 r = (asyh->view.oH << 19) / asyh->view.oW; |
| 2083 | |
| 2084 | if (bX) { |
| 2085 | asyh->view.oW -= (bX * 2); |
| 2086 | if (bY) asyh->view.oH -= (bY * 2); |
| 2087 | else asyh->view.oH = ((asyh->view.oW * r) + (r / 2)) >> 19; |
| 2088 | } else { |
| 2089 | asyh->view.oW -= (asyh->view.oW >> 4) + 32; |
| 2090 | if (bY) asyh->view.oH -= (bY * 2); |
| 2091 | else asyh->view.oH = ((asyh->view.oW * r) + (r / 2)) >> 19; |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | /* Handle CENTER/ASPECT scaling, taking into account the areas |
| 2096 | * removed already for overscan compensation. |
| 2097 | */ |
| 2098 | switch (mode) { |
| 2099 | case DRM_MODE_SCALE_CENTER: |
| 2100 | asyh->view.oW = min((u16)umode->hdisplay, asyh->view.oW); |
| 2101 | asyh->view.oH = min((u16)umode->vdisplay, asyh->view.oH); |
| 2102 | /* fall-through */ |
| 2103 | case DRM_MODE_SCALE_ASPECT: |
| 2104 | if (asyh->view.oH < asyh->view.oW) { |
| 2105 | u32 r = (asyh->view.iW << 19) / asyh->view.iH; |
| 2106 | asyh->view.oW = ((asyh->view.oH * r) + (r / 2)) >> 19; |
| 2107 | } else { |
| 2108 | u32 r = (asyh->view.iH << 19) / asyh->view.iW; |
| 2109 | asyh->view.oH = ((asyh->view.oW * r) + (r / 2)) >> 19; |
| 2110 | } |
| 2111 | break; |
| 2112 | default: |
| 2113 | break; |
| 2114 | } |
| 2115 | |
| 2116 | asyh->set.view = true; |
| 2117 | } |
| 2118 | |
| 2119 | static void |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2120 | nv50_head_atomic_check_mode(struct nv50_head *head, struct nv50_head_atom *asyh) |
| 2121 | { |
| 2122 | struct drm_display_mode *mode = &asyh->state.adjusted_mode; |
| 2123 | u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1; |
| 2124 | u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1; |
| 2125 | u32 hbackp = mode->htotal - mode->hsync_end; |
| 2126 | u32 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace; |
| 2127 | u32 hfrontp = mode->hsync_start - mode->hdisplay; |
| 2128 | u32 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace; |
| 2129 | struct nv50_head_mode *m = &asyh->mode; |
| 2130 | |
| 2131 | m->h.active = mode->htotal; |
| 2132 | m->h.synce = mode->hsync_end - mode->hsync_start - 1; |
| 2133 | m->h.blanke = m->h.synce + hbackp; |
| 2134 | m->h.blanks = mode->htotal - hfrontp - 1; |
| 2135 | |
| 2136 | m->v.active = mode->vtotal * vscan / ilace; |
| 2137 | m->v.synce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1; |
| 2138 | m->v.blanke = m->v.synce + vbackp; |
| 2139 | m->v.blanks = m->v.active - vfrontp - 1; |
| 2140 | |
| 2141 | /*XXX: Safe underestimate, even "0" works */ |
| 2142 | m->v.blankus = (m->v.active - mode->vdisplay - 2) * m->h.active; |
| 2143 | m->v.blankus *= 1000; |
| 2144 | m->v.blankus /= mode->clock; |
| 2145 | |
| 2146 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 2147 | m->v.blank2e = m->v.active + m->v.synce + vbackp; |
| 2148 | m->v.blank2s = m->v.blank2e + (mode->vdisplay * vscan / ilace); |
| 2149 | m->v.active = (m->v.active * 2) + 1; |
| 2150 | m->interlace = true; |
| 2151 | } else { |
| 2152 | m->v.blank2e = 0; |
| 2153 | m->v.blank2s = 1; |
| 2154 | m->interlace = false; |
| 2155 | } |
| 2156 | m->clock = mode->clock; |
| 2157 | |
| 2158 | drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); |
| 2159 | asyh->set.mode = true; |
| 2160 | } |
| 2161 | |
| 2162 | static int |
| 2163 | nv50_head_atomic_check(struct drm_crtc *crtc, struct drm_crtc_state *state) |
| 2164 | { |
| 2165 | struct nouveau_drm *drm = nouveau_drm(crtc->dev); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2166 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2167 | struct nv50_head *head = nv50_head(crtc); |
| 2168 | struct nv50_head_atom *armh = &head->arm; |
| 2169 | struct nv50_head_atom *asyh = nv50_head_atom(state); |
| 2170 | |
| 2171 | NV_ATOMIC(drm, "%s atomic_check %d\n", crtc->name, asyh->state.active); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2172 | asyh->clr.mask = 0; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2173 | asyh->set.mask = 0; |
| 2174 | |
| 2175 | if (asyh->state.active) { |
| 2176 | if (asyh->state.mode_changed) |
| 2177 | nv50_head_atomic_check_mode(head, asyh); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2178 | |
| 2179 | if ((asyh->core.visible = (asyh->base.cpp != 0))) { |
| 2180 | asyh->core.x = asyh->base.x; |
| 2181 | asyh->core.y = asyh->base.y; |
| 2182 | asyh->core.w = asyh->base.w; |
| 2183 | asyh->core.h = asyh->base.h; |
| 2184 | } else |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2185 | if ((asyh->core.visible = asyh->curs.visible)) { |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2186 | /*XXX: We need to either find some way of having the |
| 2187 | * primary base layer appear black, while still |
| 2188 | * being able to display the other layers, or we |
| 2189 | * need to allocate a dummy black surface here. |
| 2190 | */ |
| 2191 | asyh->core.x = 0; |
| 2192 | asyh->core.y = 0; |
| 2193 | asyh->core.w = asyh->state.mode.hdisplay; |
| 2194 | asyh->core.h = asyh->state.mode.vdisplay; |
| 2195 | } |
| 2196 | asyh->core.handle = disp->mast.base.vram.handle; |
| 2197 | asyh->core.offset = 0; |
| 2198 | asyh->core.format = 0xcf; |
| 2199 | asyh->core.kind = 0; |
| 2200 | asyh->core.layout = 1; |
| 2201 | asyh->core.block = 0; |
| 2202 | asyh->core.pitch = ALIGN(asyh->core.w, 64) * 4; |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2203 | asyh->lut.handle = disp->mast.base.vram.handle; |
| 2204 | asyh->lut.offset = head->base.lut.nvbo->bo.offset; |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2205 | asyh->set.base = armh->base.cpp != asyh->base.cpp; |
| 2206 | asyh->set.ovly = armh->ovly.cpp != asyh->ovly.cpp; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2207 | } else { |
| 2208 | asyh->core.visible = false; |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2209 | asyh->curs.visible = false; |
Ben Skeggs | 6bbab3b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2210 | asyh->base.cpp = 0; |
| 2211 | asyh->ovly.cpp = 0; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | if (!drm_atomic_crtc_needs_modeset(&asyh->state)) { |
| 2215 | if (asyh->core.visible) { |
| 2216 | if (memcmp(&armh->core, &asyh->core, sizeof(asyh->core))) |
| 2217 | asyh->set.core = true; |
| 2218 | } else |
| 2219 | if (armh->core.visible) { |
| 2220 | asyh->clr.core = true; |
| 2221 | } |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2222 | |
| 2223 | if (asyh->curs.visible) { |
| 2224 | if (memcmp(&armh->curs, &asyh->curs, sizeof(asyh->curs))) |
| 2225 | asyh->set.curs = true; |
| 2226 | } else |
| 2227 | if (armh->curs.visible) { |
| 2228 | asyh->clr.curs = true; |
| 2229 | } |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2230 | } else { |
| 2231 | asyh->clr.core = armh->core.visible; |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2232 | asyh->clr.curs = armh->curs.visible; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2233 | asyh->set.core = asyh->core.visible; |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2234 | asyh->set.curs = asyh->curs.visible; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | memcpy(armh, asyh, sizeof(*asyh)); |
| 2238 | asyh->state.mode_changed = 0; |
| 2239 | return 0; |
| 2240 | } |
| 2241 | |
| 2242 | /****************************************************************************** |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2243 | * CRTC |
| 2244 | *****************************************************************************/ |
| 2245 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2246 | nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2247 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2248 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2249 | struct nv50_head *head = nv50_head(&nv_crtc->base); |
| 2250 | struct nv50_head_atom *asyh = &head->asy; |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 2251 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2252 | struct nouveau_conn_atom asyc; |
| 2253 | u32 *push; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2254 | |
Ben Skeggs | 488ff20 | 2011-10-17 10:38:10 +1000 | [diff] [blame] | 2255 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 2256 | |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2257 | asyc.state.connector = &nv_connector->base; |
| 2258 | asyc.dither.mode = nv_connector->dithering_mode; |
| 2259 | asyc.dither.depth = nv_connector->dithering_depth; |
| 2260 | asyh->state.crtc = &nv_crtc->base; |
| 2261 | nv50_head_atomic_check(&head->base.base, &asyh->state); |
| 2262 | nv50_head_atomic_check_dither(&head->arm, asyh, &asyc); |
| 2263 | nv50_head_flush_set(head, asyh); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2264 | |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2265 | if (update) { |
| 2266 | if ((push = evo_wait(mast, 2))) { |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2267 | evo_mthd(push, 0x0080, 1); |
| 2268 | evo_data(push, 0x00000000); |
Ben Skeggs | 7e91833 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2269 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2270 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | return 0; |
| 2274 | } |
| 2275 | |
| 2276 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2277 | nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2278 | { |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2279 | struct nv50_head *head = nv50_head(&nv_crtc->base); |
| 2280 | struct nv50_head_atom *asyh = &head->asy; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 2281 | struct drm_crtc *crtc = &nv_crtc->base; |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 2282 | struct nouveau_connector *nv_connector; |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2283 | struct nouveau_conn_atom asyc; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2284 | |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 2285 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 2286 | |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2287 | asyc.state.connector = &nv_connector->base; |
| 2288 | asyc.scaler.mode = nv_connector->scaling_mode; |
| 2289 | asyc.scaler.full = nv_connector->scaling_full; |
| 2290 | asyc.scaler.underscan.mode = nv_connector->underscan; |
| 2291 | asyc.scaler.underscan.hborder = nv_connector->underscan_hborder; |
| 2292 | asyc.scaler.underscan.vborder = nv_connector->underscan_vborder; |
| 2293 | nv50_head_atomic_check(&head->base.base, &asyh->state); |
| 2294 | nv50_head_atomic_check_view(&head->arm, asyh, &asyc); |
| 2295 | nv50_head_flush_set(head, asyh); |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 2296 | |
Ben Skeggs | c4e6812 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2297 | if (update) { |
| 2298 | nv50_display_flip_stop(crtc); |
| 2299 | nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | return 0; |
| 2303 | } |
| 2304 | |
| 2305 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2306 | nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update) |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 2307 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2308 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2309 | struct nv50_head *head = nv50_head(&nv_crtc->base); |
| 2310 | struct nv50_head_atom *asyh = &head->asy; |
| 2311 | struct nouveau_conn_atom asyc; |
| 2312 | u32 *push; |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 2313 | |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2314 | asyc.procamp.color_vibrance = nv_crtc->color_vibrance + 100; |
| 2315 | asyc.procamp.vibrant_hue = nv_crtc->vibrant_hue + 90; |
| 2316 | nv50_head_atomic_check(&head->base.base, &asyh->state); |
| 2317 | nv50_head_atomic_check_procamp(&head->arm, asyh, &asyc); |
| 2318 | nv50_head_flush_set(head, asyh); |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 2319 | |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2320 | if (update) { |
| 2321 | if ((push = evo_wait(mast, 2))) { |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 2322 | evo_mthd(push, 0x0080, 1); |
| 2323 | evo_data(push, 0x00000000); |
Ben Skeggs | 7e08d67 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2324 | evo_kick(push, mast); |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 2325 | } |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | return 0; |
| 2329 | } |
| 2330 | |
| 2331 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2332 | nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2333 | int x, int y, bool update) |
| 2334 | { |
| 2335 | struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2336 | struct nv50_head *head = nv50_head(&nv_crtc->base); |
| 2337 | struct nv50_head_atom *asyh = &head->asy; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2338 | struct nv50_wndw_atom *asyw = &head->_base->wndw.asy; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2339 | const struct drm_format_info *info; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2340 | |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2341 | info = drm_format_info(nvfb->base.pixel_format); |
| 2342 | if (!info || !info->depth) |
| 2343 | return -EINVAL; |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2344 | |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2345 | asyh->base.depth = info->depth; |
| 2346 | asyh->base.cpp = info->cpp[0]; |
| 2347 | asyh->base.x = x; |
| 2348 | asyh->base.y = y; |
| 2349 | asyh->base.w = nvfb->base.width; |
| 2350 | asyh->base.h = nvfb->base.height; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2351 | asyw->state.src_x = x << 16; |
| 2352 | asyw->state.src_y = y << 16; |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2353 | nv50_head_atomic_check(&head->base.base, &asyh->state); |
| 2354 | nv50_head_flush_set(head, asyh); |
| 2355 | |
| 2356 | if (update) { |
| 2357 | struct nv50_mast *core = nv50_mast(nv_crtc->base.dev); |
| 2358 | u32 *push = evo_wait(core, 2); |
| 2359 | if (push) { |
Ben Skeggs | a46232e | 2011-07-07 15:23:48 +1000 | [diff] [blame] | 2360 | evo_mthd(push, 0x0080, 1); |
| 2361 | evo_data(push, 0x00000000); |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2362 | evo_kick(push, core); |
Ben Skeggs | a46232e | 2011-07-07 15:23:48 +1000 | [diff] [blame] | 2363 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2364 | } |
| 2365 | |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2366 | nv_crtc->fb.handle = nvfb->r_handle; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2367 | return 0; |
| 2368 | } |
| 2369 | |
| 2370 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2371 | nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2372 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2373 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2374 | struct nv50_head *head = nv50_head(&nv_crtc->base); |
| 2375 | struct nv50_head_atom *asyh = &head->asy; |
| 2376 | |
| 2377 | asyh->curs.visible = true; |
| 2378 | asyh->curs.handle = mast->base.vram.handle; |
| 2379 | asyh->curs.offset = nv_crtc->cursor.nvbo->bo.offset; |
| 2380 | asyh->curs.layout = 1; |
| 2381 | asyh->curs.format = 1; |
| 2382 | nv50_head_atomic_check(&head->base.base, &asyh->state); |
| 2383 | nv50_head_flush_set(head, asyh); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2387 | nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc) |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2388 | { |
Ben Skeggs | ea8ee39 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2389 | struct nv50_head *head = nv50_head(&nv_crtc->base); |
| 2390 | struct nv50_head_atom *asyh = &head->asy; |
| 2391 | |
| 2392 | asyh->curs.visible = false; |
| 2393 | nv50_head_atomic_check(&head->base.base, &asyh->state); |
| 2394 | nv50_head_flush_clr(head, asyh, false); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2395 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2396 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2397 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2398 | nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update) |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2399 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2400 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2401 | |
Ben Skeggs | 697bb72 | 2015-07-28 17:20:57 +1000 | [diff] [blame] | 2402 | if (show && nv_crtc->cursor.nvbo && nv_crtc->base.enabled) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2403 | nv50_crtc_cursor_show(nv_crtc); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2404 | else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2405 | nv50_crtc_cursor_hide(nv_crtc); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2406 | |
| 2407 | if (update) { |
| 2408 | u32 *push = evo_wait(mast, 2); |
| 2409 | if (push) { |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2410 | evo_mthd(push, 0x0080, 1); |
| 2411 | evo_data(push, 0x00000000); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2412 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2413 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2418 | nv50_crtc_dpms(struct drm_crtc *crtc, int mode) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2419 | { |
| 2420 | } |
| 2421 | |
| 2422 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2423 | nv50_crtc_prepare(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2424 | { |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2425 | struct nv50_head *head = nv50_head(crtc); |
| 2426 | struct nv50_head_atom *asyh = &head->asy; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2427 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2428 | nv50_display_flip_stop(crtc); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 2429 | |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2430 | asyh->state.active = false; |
| 2431 | nv50_head_atomic_check(&head->base.base, &asyh->state); |
| 2432 | nv50_head_flush_clr(head, asyh, false); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2436 | nv50_crtc_commit(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2437 | { |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2438 | struct nv50_head *head = nv50_head(crtc); |
| 2439 | struct nv50_head_atom *asyh = &head->asy; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2440 | |
Ben Skeggs | a7ae156 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2441 | asyh->state.active = true; |
| 2442 | nv50_head_atomic_check(&head->base.base, &asyh->state); |
| 2443 | nv50_head_flush_set(head, asyh); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2444 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2445 | nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | static bool |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2449 | nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2450 | struct drm_display_mode *adjusted_mode) |
| 2451 | { |
Ben Skeggs | eb2e968 | 2014-01-24 10:13:23 +1000 | [diff] [blame] | 2452 | drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2453 | return true; |
| 2454 | } |
| 2455 | |
| 2456 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2457 | nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2458 | { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2459 | struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 2460 | struct nv50_head *head = nv50_head(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2461 | int ret; |
| 2462 | |
Ben Skeggs | 547ad07 | 2014-11-10 12:35:06 +1000 | [diff] [blame] | 2463 | ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM, true); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 2464 | if (ret == 0) { |
| 2465 | if (head->image) |
| 2466 | nouveau_bo_unpin(head->image); |
| 2467 | nouveau_bo_ref(nvfb->nvbo, &head->image); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2468 | } |
| 2469 | |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 2470 | return ret; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2474 | nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2475 | struct drm_display_mode *mode, int x, int y, |
| 2476 | struct drm_framebuffer *old_fb) |
| 2477 | { |
| 2478 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 2479 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2480 | int ret; |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2481 | struct nv50_head *head = nv50_head(crtc); |
| 2482 | struct nv50_head_atom *asyh = &head->asy; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2483 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2484 | memcpy(&asyh->state.mode, umode, sizeof(*umode)); |
| 2485 | memcpy(&asyh->state.adjusted_mode, mode, sizeof(*mode)); |
| 2486 | asyh->state.active = true; |
| 2487 | asyh->state.mode_changed = true; |
| 2488 | nv50_head_atomic_check(&head->base.base, &asyh->state); |
Ben Skeggs | 2d1d898 | 2011-11-11 23:39:22 +1000 | [diff] [blame] | 2489 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2490 | ret = nv50_crtc_swap_fbs(crtc, old_fb); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2491 | if (ret) |
| 2492 | return ret; |
| 2493 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2494 | nv50_head_flush_set(head, asyh); |
| 2495 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2496 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2497 | nv50_crtc_set_dither(nv_crtc, false); |
| 2498 | nv50_crtc_set_scale(nv_crtc, false); |
Roy Spliet | eae7382 | 2014-10-30 22:57:45 +0100 | [diff] [blame] | 2499 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2500 | nv50_crtc_set_color_vibrance(nv_crtc, false); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2501 | nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2502 | return 0; |
| 2503 | } |
| 2504 | |
| 2505 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2506 | nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2507 | struct drm_framebuffer *old_fb) |
| 2508 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2509 | struct nouveau_drm *drm = nouveau_drm(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2510 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 2511 | int ret; |
| 2512 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2513 | if (!crtc->primary->fb) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2514 | NV_DEBUG(drm, "No FB bound\n"); |
Ben Skeggs | 84e2ad8 | 2011-08-26 09:40:39 +1000 | [diff] [blame] | 2515 | return 0; |
| 2516 | } |
| 2517 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2518 | ret = nv50_crtc_swap_fbs(crtc, old_fb); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2519 | if (ret) |
| 2520 | return ret; |
| 2521 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2522 | nv50_display_flip_stop(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2523 | nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true); |
| 2524 | nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2525 | return 0; |
| 2526 | } |
| 2527 | |
| 2528 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2529 | nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2530 | struct drm_framebuffer *fb, int x, int y, |
| 2531 | enum mode_set_atomic state) |
| 2532 | { |
| 2533 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2534 | nv50_display_flip_stop(crtc); |
| 2535 | nv50_crtc_set_image(nv_crtc, fb, x, y, true); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2536 | return 0; |
| 2537 | } |
| 2538 | |
| 2539 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2540 | nv50_crtc_lut_load(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2541 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2542 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2543 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 2544 | void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo); |
| 2545 | int i; |
| 2546 | |
| 2547 | for (i = 0; i < 256; i++) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2548 | u16 r = nv_crtc->lut.r[i] >> 2; |
| 2549 | u16 g = nv_crtc->lut.g[i] >> 2; |
| 2550 | u16 b = nv_crtc->lut.b[i] >> 2; |
| 2551 | |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 2552 | if (disp->disp->oclass < GF110_DISP) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 2553 | writew(r + 0x0000, lut + (i * 0x08) + 0); |
| 2554 | writew(g + 0x0000, lut + (i * 0x08) + 2); |
| 2555 | writew(b + 0x0000, lut + (i * 0x08) + 4); |
| 2556 | } else { |
| 2557 | writew(r + 0x6000, lut + (i * 0x20) + 0); |
| 2558 | writew(g + 0x6000, lut + (i * 0x20) + 2); |
| 2559 | writew(b + 0x6000, lut + (i * 0x20) + 4); |
| 2560 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2561 | } |
| 2562 | } |
| 2563 | |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 2564 | static void |
| 2565 | nv50_crtc_disable(struct drm_crtc *crtc) |
| 2566 | { |
| 2567 | struct nv50_head *head = nv50_head(crtc); |
Ben Skeggs | efa366f | 2014-06-05 12:56:35 +1000 | [diff] [blame] | 2568 | evo_sync(crtc->dev); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 2569 | if (head->image) |
| 2570 | nouveau_bo_unpin(head->image); |
| 2571 | nouveau_bo_ref(NULL, &head->image); |
| 2572 | } |
| 2573 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2574 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2575 | nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2576 | uint32_t handle, uint32_t width, uint32_t height) |
| 2577 | { |
| 2578 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 2579 | struct drm_gem_object *gem = NULL; |
| 2580 | struct nouveau_bo *nvbo = NULL; |
| 2581 | int ret = 0; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2582 | |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 2583 | if (handle) { |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2584 | if (width != 64 || height != 64) |
| 2585 | return -EINVAL; |
| 2586 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 2587 | gem = drm_gem_object_lookup(file_priv, handle); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2588 | if (unlikely(!gem)) |
| 2589 | return -ENOENT; |
| 2590 | nvbo = nouveau_gem_object(gem); |
| 2591 | |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 2592 | ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_VRAM, true); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2593 | } |
| 2594 | |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 2595 | if (ret == 0) { |
Maarten Lankhorst | 4dc6393 | 2015-01-13 09:18:49 +0100 | [diff] [blame] | 2596 | if (nv_crtc->cursor.nvbo) |
| 2597 | nouveau_bo_unpin(nv_crtc->cursor.nvbo); |
| 2598 | nouveau_bo_ref(nvbo, &nv_crtc->cursor.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2599 | } |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 2600 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2601 | |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 2602 | nv50_crtc_cursor_show_hide(nv_crtc, true, true); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2603 | return ret; |
| 2604 | } |
| 2605 | |
| 2606 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2607 | nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2608 | { |
Maarten Lankhorst | 4dc6393 | 2015-01-13 09:18:49 +0100 | [diff] [blame] | 2609 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2610 | struct nv50_wndw *wndw = &nv50_head(crtc)->_curs->wndw; |
| 2611 | struct nv50_wndw_atom *asyw = &wndw->asy; |
| 2612 | |
| 2613 | asyw->point.x = x; |
| 2614 | asyw->point.y = y; |
| 2615 | asyw->set.point = true; |
| 2616 | nv50_wndw_flush_set(wndw, 0, asyw); |
Maarten Lankhorst | 4dc6393 | 2015-01-13 09:18:49 +0100 | [diff] [blame] | 2617 | |
| 2618 | nv_crtc->cursor_saved_x = x; |
| 2619 | nv_crtc->cursor_saved_y = y; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2620 | return 0; |
| 2621 | } |
| 2622 | |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 2623 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2624 | nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 2625 | uint32_t size) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2626 | { |
| 2627 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2628 | u32 i; |
| 2629 | |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 2630 | for (i = 0; i < size; i++) { |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2631 | nv_crtc->lut.r[i] = r[i]; |
| 2632 | nv_crtc->lut.g[i] = g[i]; |
| 2633 | nv_crtc->lut.b[i] = b[i]; |
| 2634 | } |
| 2635 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2636 | nv50_crtc_lut_load(crtc); |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 2637 | |
| 2638 | return 0; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | static void |
Maarten Lankhorst | 4dc6393 | 2015-01-13 09:18:49 +0100 | [diff] [blame] | 2642 | nv50_crtc_cursor_restore(struct nouveau_crtc *nv_crtc, int x, int y) |
| 2643 | { |
| 2644 | nv50_crtc_cursor_move(&nv_crtc->base, x, y); |
| 2645 | |
| 2646 | nv50_crtc_cursor_show_hide(nv_crtc, true, true); |
| 2647 | } |
| 2648 | |
| 2649 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2650 | nv50_crtc_destroy(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2651 | { |
| 2652 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2653 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
| 2654 | struct nv50_head *head = nv50_head(crtc); |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 2655 | |
| 2656 | nv50_dmac_destroy(&head->ovly.base, disp->disp); |
| 2657 | nv50_pioc_destroy(&head->oimm.base); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 2658 | |
| 2659 | /*XXX: this shouldn't be necessary, but the core doesn't call |
| 2660 | * disconnect() during the cleanup paths |
| 2661 | */ |
| 2662 | if (head->image) |
| 2663 | nouveau_bo_unpin(head->image); |
| 2664 | nouveau_bo_ref(NULL, &head->image); |
| 2665 | |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 2666 | /*XXX: ditto */ |
Maarten Lankhorst | 4dc6393 | 2015-01-13 09:18:49 +0100 | [diff] [blame] | 2667 | if (nv_crtc->cursor.nvbo) |
| 2668 | nouveau_bo_unpin(nv_crtc->cursor.nvbo); |
| 2669 | nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 2670 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2671 | nouveau_bo_unmap(nv_crtc->lut.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2672 | if (nv_crtc->lut.nvbo) |
| 2673 | nouveau_bo_unpin(nv_crtc->lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2674 | nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 2675 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2676 | drm_crtc_cleanup(crtc); |
| 2677 | kfree(crtc); |
| 2678 | } |
| 2679 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2680 | static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = { |
| 2681 | .dpms = nv50_crtc_dpms, |
| 2682 | .prepare = nv50_crtc_prepare, |
| 2683 | .commit = nv50_crtc_commit, |
| 2684 | .mode_fixup = nv50_crtc_mode_fixup, |
| 2685 | .mode_set = nv50_crtc_mode_set, |
| 2686 | .mode_set_base = nv50_crtc_mode_set_base, |
| 2687 | .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic, |
| 2688 | .load_lut = nv50_crtc_lut_load, |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 2689 | .disable = nv50_crtc_disable, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2690 | }; |
| 2691 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2692 | static const struct drm_crtc_funcs nv50_crtc_func = { |
| 2693 | .cursor_set = nv50_crtc_cursor_set, |
| 2694 | .cursor_move = nv50_crtc_cursor_move, |
| 2695 | .gamma_set = nv50_crtc_gamma_set, |
Dave Airlie | 5addcf0 | 2012-09-10 14:20:51 +1000 | [diff] [blame] | 2696 | .set_config = nouveau_crtc_set_config, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2697 | .destroy = nv50_crtc_destroy, |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 2698 | .page_flip = nouveau_crtc_page_flip, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2699 | }; |
| 2700 | |
| 2701 | static int |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 2702 | nv50_crtc_create(struct drm_device *dev, int index) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2703 | { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 2704 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 2705 | struct nvif_device *device = &drm->device; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2706 | struct nv50_disp *disp = nv50_disp(dev); |
| 2707 | struct nv50_head *head; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2708 | struct nv50_base *base; |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2709 | struct nv50_curs *curs; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2710 | struct drm_crtc *crtc; |
| 2711 | int ret, i; |
| 2712 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2713 | head = kzalloc(sizeof(*head), GFP_KERNEL); |
| 2714 | if (!head) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2715 | return -ENOMEM; |
| 2716 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2717 | head->base.index = index; |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 2718 | head->base.color_vibrance = 50; |
| 2719 | head->base.vibrant_hue = 0; |
Maarten Lankhorst | 4dc6393 | 2015-01-13 09:18:49 +0100 | [diff] [blame] | 2720 | head->base.cursor.set_pos = nv50_crtc_cursor_restore; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2721 | for (i = 0; i < 256; i++) { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2722 | head->base.lut.r[i] = i << 8; |
| 2723 | head->base.lut.g[i] = i << 8; |
| 2724 | head->base.lut.b[i] = i << 8; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2725 | } |
| 2726 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2727 | ret = nv50_base_new(drm, head, &base); |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2728 | if (ret == 0) |
| 2729 | ret = nv50_curs_new(drm, head, &curs); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2730 | if (ret) { |
| 2731 | kfree(head); |
| 2732 | return ret; |
| 2733 | } |
| 2734 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2735 | crtc = &head->base.base; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2736 | head->_base = base; |
Ben Skeggs | 22e927d | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2737 | head->_curs = curs; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2738 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2739 | drm_crtc_init(dev, crtc, &nv50_crtc_func); |
| 2740 | drm_crtc_helper_add(crtc, &nv50_crtc_hfunc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2741 | drm_mode_crtc_set_gamma_size(crtc, 256); |
| 2742 | |
Ben Skeggs | 8ea0d4a | 2011-07-07 14:49:24 +1000 | [diff] [blame] | 2743 | ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM, |
Maarten Lankhorst | bb6178b | 2014-01-09 11:03:15 +0100 | [diff] [blame] | 2744 | 0, 0x0000, NULL, NULL, &head->base.lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2745 | if (!ret) { |
Ben Skeggs | 547ad07 | 2014-11-10 12:35:06 +1000 | [diff] [blame] | 2746 | 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] | 2747 | if (!ret) { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2748 | ret = nouveau_bo_map(head->base.lut.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2749 | if (ret) |
| 2750 | nouveau_bo_unpin(head->base.lut.nvbo); |
| 2751 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2752 | if (ret) |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 2753 | nouveau_bo_ref(NULL, &head->base.lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | if (ret) |
| 2757 | goto out; |
| 2758 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2759 | /* allocate overlay resources */ |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 2760 | ret = nv50_oimm_create(device, disp->disp, index, &head->oimm); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2761 | if (ret) |
| 2762 | goto out; |
| 2763 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 2764 | ret = nv50_ovly_create(device, disp->disp, index, disp->sync->bo.offset, |
| 2765 | &head->ovly); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2766 | if (ret) |
| 2767 | goto out; |
| 2768 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2769 | out: |
| 2770 | if (ret) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2771 | nv50_crtc_destroy(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2772 | return ret; |
| 2773 | } |
| 2774 | |
| 2775 | /****************************************************************************** |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 2776 | * Encoder helpers |
| 2777 | *****************************************************************************/ |
| 2778 | static bool |
| 2779 | nv50_encoder_mode_fixup(struct drm_encoder *encoder, |
| 2780 | const struct drm_display_mode *mode, |
| 2781 | struct drm_display_mode *adjusted_mode) |
| 2782 | { |
| 2783 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 2784 | struct nouveau_connector *nv_connector; |
| 2785 | |
| 2786 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 2787 | if (nv_connector && nv_connector->native_mode) { |
Ben Skeggs | 576f791 | 2014-12-22 17:19:26 +1000 | [diff] [blame] | 2788 | nv_connector->scaling_full = false; |
| 2789 | if (nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) { |
| 2790 | switch (nv_connector->type) { |
| 2791 | case DCB_CONNECTOR_LVDS: |
| 2792 | case DCB_CONNECTOR_LVDS_SPWG: |
| 2793 | case DCB_CONNECTOR_eDP: |
| 2794 | /* force use of scaler for non-edid modes */ |
| 2795 | if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER) |
| 2796 | return true; |
| 2797 | nv_connector->scaling_full = true; |
| 2798 | break; |
| 2799 | default: |
| 2800 | return true; |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | drm_mode_copy(adjusted_mode, nv_connector->native_mode); |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | return true; |
| 2808 | } |
| 2809 | |
| 2810 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2811 | * DAC |
| 2812 | *****************************************************************************/ |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2813 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2814 | nv50_dac_dpms(struct drm_encoder *encoder, int mode) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2815 | { |
| 2816 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2817 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | bf0eb89 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2818 | struct { |
| 2819 | struct nv50_disp_mthd_v1 base; |
| 2820 | struct nv50_disp_dac_pwr_v0 pwr; |
| 2821 | } args = { |
| 2822 | .base.version = 1, |
| 2823 | .base.method = NV50_DISP_MTHD_V1_DAC_PWR, |
| 2824 | .base.hasht = nv_encoder->dcb->hasht, |
| 2825 | .base.hashm = nv_encoder->dcb->hashm, |
| 2826 | .pwr.state = 1, |
| 2827 | .pwr.data = 1, |
| 2828 | .pwr.vsync = (mode != DRM_MODE_DPMS_SUSPEND && |
| 2829 | mode != DRM_MODE_DPMS_OFF), |
| 2830 | .pwr.hsync = (mode != DRM_MODE_DPMS_STANDBY && |
| 2831 | mode != DRM_MODE_DPMS_OFF), |
| 2832 | }; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2833 | |
Ben Skeggs | bf0eb89 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2834 | nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2835 | } |
| 2836 | |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2837 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2838 | nv50_dac_commit(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2839 | { |
| 2840 | } |
| 2841 | |
| 2842 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2843 | nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2844 | struct drm_display_mode *adjusted_mode) |
| 2845 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2846 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2847 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 2848 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2849 | u32 *push; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2850 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2851 | nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2852 | |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2853 | push = evo_wait(mast, 8); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2854 | if (push) { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 2855 | if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) { |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2856 | u32 syncs = 0x00000000; |
| 2857 | |
| 2858 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 2859 | syncs |= 0x00000001; |
| 2860 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 2861 | syncs |= 0x00000002; |
| 2862 | |
| 2863 | evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2); |
| 2864 | evo_data(push, 1 << nv_crtc->index); |
| 2865 | evo_data(push, syncs); |
| 2866 | } else { |
| 2867 | u32 magic = 0x31ec6000 | (nv_crtc->index << 25); |
| 2868 | u32 syncs = 0x00000001; |
| 2869 | |
| 2870 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 2871 | syncs |= 0x00000008; |
| 2872 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 2873 | syncs |= 0x00000010; |
| 2874 | |
| 2875 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 2876 | magic |= 0x00000001; |
| 2877 | |
| 2878 | evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2); |
| 2879 | evo_data(push, syncs); |
| 2880 | evo_data(push, magic); |
| 2881 | evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1); |
| 2882 | evo_data(push, 1 << nv_crtc->index); |
| 2883 | } |
| 2884 | |
| 2885 | evo_kick(push, mast); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | nv_encoder->crtc = encoder->crtc; |
| 2889 | } |
| 2890 | |
| 2891 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2892 | nv50_dac_disconnect(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2893 | { |
| 2894 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2895 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2896 | const int or = nv_encoder->or; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2897 | u32 *push; |
| 2898 | |
| 2899 | if (nv_encoder->crtc) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2900 | nv50_crtc_prepare(nv_encoder->crtc); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2901 | |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2902 | push = evo_wait(mast, 4); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2903 | if (push) { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 2904 | if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) { |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2905 | evo_mthd(push, 0x0400 + (or * 0x080), 1); |
| 2906 | evo_data(push, 0x00000000); |
| 2907 | } else { |
| 2908 | evo_mthd(push, 0x0180 + (or * 0x020), 1); |
| 2909 | evo_data(push, 0x00000000); |
| 2910 | } |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2911 | evo_kick(push, mast); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2912 | } |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2913 | } |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 2914 | |
| 2915 | nv_encoder->crtc = NULL; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2916 | } |
| 2917 | |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 2918 | static enum drm_connector_status |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2919 | nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 2920 | { |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2921 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2922 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2923 | struct { |
| 2924 | struct nv50_disp_mthd_v1 base; |
| 2925 | struct nv50_disp_dac_load_v0 load; |
| 2926 | } args = { |
| 2927 | .base.version = 1, |
| 2928 | .base.method = NV50_DISP_MTHD_V1_DAC_LOAD, |
| 2929 | .base.hasht = nv_encoder->dcb->hasht, |
| 2930 | .base.hashm = nv_encoder->dcb->hashm, |
| 2931 | }; |
| 2932 | int ret; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 2933 | |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 2934 | args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval; |
| 2935 | if (args.load.data == 0) |
| 2936 | args.load.data = 340; |
| 2937 | |
| 2938 | ret = nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
| 2939 | if (ret || !args.load.load) |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 2940 | return connector_status_disconnected; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 2941 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 2942 | return connector_status_connected; |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 2943 | } |
| 2944 | |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2945 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2946 | nv50_dac_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2947 | { |
| 2948 | drm_encoder_cleanup(encoder); |
| 2949 | kfree(encoder); |
| 2950 | } |
| 2951 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2952 | static const struct drm_encoder_helper_funcs nv50_dac_hfunc = { |
| 2953 | .dpms = nv50_dac_dpms, |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 2954 | .mode_fixup = nv50_encoder_mode_fixup, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2955 | .prepare = nv50_dac_disconnect, |
| 2956 | .commit = nv50_dac_commit, |
| 2957 | .mode_set = nv50_dac_mode_set, |
| 2958 | .disable = nv50_dac_disconnect, |
| 2959 | .get_crtc = nv50_display_crtc_get, |
| 2960 | .detect = nv50_dac_detect |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2961 | }; |
| 2962 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2963 | static const struct drm_encoder_funcs nv50_dac_func = { |
| 2964 | .destroy = nv50_dac_destroy, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2965 | }; |
| 2966 | |
| 2967 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2968 | nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2969 | { |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 2970 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | be83cd4 | 2015-01-14 15:36:34 +1000 | [diff] [blame] | 2971 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->device); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 2972 | struct nvkm_i2c_bus *bus; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2973 | struct nouveau_encoder *nv_encoder; |
| 2974 | struct drm_encoder *encoder; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 2975 | int type = DRM_MODE_ENCODER_DAC; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2976 | |
| 2977 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 2978 | if (!nv_encoder) |
| 2979 | return -ENOMEM; |
| 2980 | nv_encoder->dcb = dcbe; |
| 2981 | nv_encoder->or = ffs(dcbe->or) - 1; |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 2982 | |
| 2983 | bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index); |
| 2984 | if (bus) |
| 2985 | nv_encoder->i2c = &bus->i2c; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2986 | |
| 2987 | encoder = to_drm_encoder(nv_encoder); |
| 2988 | encoder->possible_crtcs = dcbe->heads; |
| 2989 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2990 | drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type, |
| 2991 | "dac-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2992 | drm_encoder_helper_add(encoder, &nv50_dac_hfunc); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 2993 | |
| 2994 | drm_mode_connector_attach_encoder(connector, encoder); |
| 2995 | return 0; |
| 2996 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2997 | |
| 2998 | /****************************************************************************** |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 2999 | * Audio |
| 3000 | *****************************************************************************/ |
| 3001 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3002 | nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3003 | { |
| 3004 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 3005 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3006 | struct nouveau_connector *nv_connector; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3007 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | d889c52 | 2014-09-15 21:11:51 +1000 | [diff] [blame] | 3008 | struct __packed { |
| 3009 | struct { |
| 3010 | struct nv50_disp_mthd_v1 mthd; |
| 3011 | struct nv50_disp_sor_hda_eld_v0 eld; |
| 3012 | } base; |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3013 | u8 data[sizeof(nv_connector->base.eld)]; |
| 3014 | } args = { |
Ben Skeggs | d889c52 | 2014-09-15 21:11:51 +1000 | [diff] [blame] | 3015 | .base.mthd.version = 1, |
| 3016 | .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD, |
| 3017 | .base.mthd.hasht = nv_encoder->dcb->hasht, |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 3018 | .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 3019 | (0x0100 << nv_crtc->index), |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3020 | }; |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3021 | |
| 3022 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 3023 | if (!drm_detect_monitor_audio(nv_connector->edid)) |
| 3024 | return; |
| 3025 | |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3026 | drm_edid_to_eld(&nv_connector->base, nv_connector->edid); |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3027 | memcpy(args.data, nv_connector->base.eld, sizeof(args.data)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3028 | |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 3029 | nvif_mthd(disp->disp, 0, &args, |
| 3030 | sizeof(args.base) + drm_eld_size(args.data)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | static void |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 3034 | nv50_audio_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3035 | { |
| 3036 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3037 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3038 | struct { |
| 3039 | struct nv50_disp_mthd_v1 base; |
| 3040 | struct nv50_disp_sor_hda_eld_v0 eld; |
| 3041 | } args = { |
| 3042 | .base.version = 1, |
| 3043 | .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD, |
| 3044 | .base.hasht = nv_encoder->dcb->hasht, |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 3045 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 3046 | (0x0100 << nv_crtc->index), |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3047 | }; |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3048 | |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3049 | nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | /****************************************************************************** |
| 3053 | * HDMI |
| 3054 | *****************************************************************************/ |
| 3055 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3056 | nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3057 | { |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 3058 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 3059 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3060 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3061 | struct { |
| 3062 | struct nv50_disp_mthd_v1 base; |
| 3063 | struct nv50_disp_sor_hdmi_pwr_v0 pwr; |
| 3064 | } args = { |
| 3065 | .base.version = 1, |
| 3066 | .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR, |
| 3067 | .base.hasht = nv_encoder->dcb->hasht, |
| 3068 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 3069 | (0x0100 << nv_crtc->index), |
| 3070 | .pwr.state = 1, |
| 3071 | .pwr.rekey = 56, /* binary driver, and tegra, constant */ |
| 3072 | }; |
| 3073 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 3074 | u32 max_ac_packet; |
| 3075 | |
| 3076 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 3077 | if (!drm_detect_hdmi_monitor(nv_connector->edid)) |
| 3078 | return; |
| 3079 | |
| 3080 | max_ac_packet = mode->htotal - mode->hdisplay; |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3081 | max_ac_packet -= args.pwr.rekey; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 3082 | max_ac_packet -= 18; /* constant from tegra */ |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3083 | args.pwr.max_ac_packet = max_ac_packet / 32; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 3084 | |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3085 | nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3086 | nv50_audio_mode_set(encoder, mode); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | static void |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3090 | nv50_hdmi_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3091 | { |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 3092 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3093 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3094 | struct { |
| 3095 | struct nv50_disp_mthd_v1 base; |
| 3096 | struct nv50_disp_sor_hdmi_pwr_v0 pwr; |
| 3097 | } args = { |
| 3098 | .base.version = 1, |
| 3099 | .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR, |
| 3100 | .base.hasht = nv_encoder->dcb->hasht, |
| 3101 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 3102 | (0x0100 << nv_crtc->index), |
| 3103 | }; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 3104 | |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3105 | nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | /****************************************************************************** |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3109 | * MST |
| 3110 | *****************************************************************************/ |
| 3111 | struct nv50_mstm { |
| 3112 | struct nouveau_encoder *outp; |
| 3113 | |
| 3114 | struct drm_dp_mst_topology_mgr mgr; |
| 3115 | }; |
| 3116 | |
| 3117 | static int |
| 3118 | nv50_mstm_enable(struct nv50_mstm *mstm, u8 dpcd, int state) |
| 3119 | { |
| 3120 | struct nouveau_encoder *outp = mstm->outp; |
| 3121 | struct { |
| 3122 | struct nv50_disp_mthd_v1 base; |
| 3123 | struct nv50_disp_sor_dp_mst_link_v0 mst; |
| 3124 | } args = { |
| 3125 | .base.version = 1, |
| 3126 | .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_LINK, |
| 3127 | .base.hasht = outp->dcb->hasht, |
| 3128 | .base.hashm = outp->dcb->hashm, |
| 3129 | .mst.state = state, |
| 3130 | }; |
| 3131 | struct nouveau_drm *drm = nouveau_drm(outp->base.base.dev); |
| 3132 | struct nvif_object *disp = &drm->display->disp; |
| 3133 | int ret; |
| 3134 | |
| 3135 | if (dpcd >= 0x12) { |
| 3136 | ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CTRL, &dpcd); |
| 3137 | if (ret < 0) |
| 3138 | return ret; |
| 3139 | |
| 3140 | dpcd &= ~DP_MST_EN; |
| 3141 | if (state) |
| 3142 | dpcd |= DP_MST_EN; |
| 3143 | |
| 3144 | ret = drm_dp_dpcd_writeb(mstm->mgr.aux, DP_MSTM_CTRL, dpcd); |
| 3145 | if (ret < 0) |
| 3146 | return ret; |
| 3147 | } |
| 3148 | |
| 3149 | return nvif_mthd(disp, 0, &args, sizeof(args)); |
| 3150 | } |
| 3151 | |
| 3152 | int |
| 3153 | nv50_mstm_detect(struct nv50_mstm *mstm, u8 dpcd[8], int allow) |
| 3154 | { |
| 3155 | int ret, state = 0; |
| 3156 | |
| 3157 | if (!mstm) |
| 3158 | return 0; |
| 3159 | |
| 3160 | if (dpcd[0] >= 0x12 && allow) { |
| 3161 | ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CAP, &dpcd[1]); |
| 3162 | if (ret < 0) |
| 3163 | return ret; |
| 3164 | |
| 3165 | state = dpcd[1] & DP_MST_CAP; |
| 3166 | } |
| 3167 | |
| 3168 | ret = nv50_mstm_enable(mstm, dpcd[0], state); |
| 3169 | if (ret) |
| 3170 | return ret; |
| 3171 | |
| 3172 | ret = drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, state); |
| 3173 | if (ret) |
| 3174 | return nv50_mstm_enable(mstm, dpcd[0], 0); |
| 3175 | |
| 3176 | return mstm->mgr.mst_state; |
| 3177 | } |
| 3178 | |
| 3179 | static void |
| 3180 | nv50_mstm_del(struct nv50_mstm **pmstm) |
| 3181 | { |
| 3182 | struct nv50_mstm *mstm = *pmstm; |
| 3183 | if (mstm) { |
| 3184 | kfree(*pmstm); |
| 3185 | *pmstm = NULL; |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | static int |
| 3190 | nv50_mstm_new(struct nouveau_encoder *outp, struct drm_dp_aux *aux, int aux_max, |
| 3191 | int conn_base_id, struct nv50_mstm **pmstm) |
| 3192 | { |
| 3193 | const int max_payloads = hweight8(outp->dcb->heads); |
| 3194 | struct drm_device *dev = outp->base.base.dev; |
| 3195 | struct nv50_mstm *mstm; |
| 3196 | int ret; |
| 3197 | |
| 3198 | if (!(mstm = *pmstm = kzalloc(sizeof(*mstm), GFP_KERNEL))) |
| 3199 | return -ENOMEM; |
| 3200 | mstm->outp = outp; |
| 3201 | |
| 3202 | ret = drm_dp_mst_topology_mgr_init(&mstm->mgr, dev->dev, aux, aux_max, |
| 3203 | max_payloads, conn_base_id); |
| 3204 | if (ret) |
| 3205 | return ret; |
| 3206 | |
| 3207 | return 0; |
| 3208 | } |
| 3209 | |
| 3210 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3211 | * SOR |
| 3212 | *****************************************************************************/ |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 3213 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3214 | nv50_sor_dpms(struct drm_encoder *encoder, int mode) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3215 | { |
| 3216 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | d55b4af | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3217 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
| 3218 | struct { |
| 3219 | struct nv50_disp_mthd_v1 base; |
| 3220 | struct nv50_disp_sor_pwr_v0 pwr; |
| 3221 | } args = { |
| 3222 | .base.version = 1, |
| 3223 | .base.method = NV50_DISP_MTHD_V1_SOR_PWR, |
| 3224 | .base.hasht = nv_encoder->dcb->hasht, |
| 3225 | .base.hashm = nv_encoder->dcb->hashm, |
| 3226 | .pwr.state = mode == DRM_MODE_DPMS_ON, |
| 3227 | }; |
Ben Skeggs | c02ed2b | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3228 | struct { |
| 3229 | struct nv50_disp_mthd_v1 base; |
| 3230 | struct nv50_disp_sor_dp_pwr_v0 pwr; |
| 3231 | } link = { |
| 3232 | .base.version = 1, |
| 3233 | .base.method = NV50_DISP_MTHD_V1_SOR_DP_PWR, |
| 3234 | .base.hasht = nv_encoder->dcb->hasht, |
| 3235 | .base.hashm = nv_encoder->dcb->hashm, |
| 3236 | .pwr.state = mode == DRM_MODE_DPMS_ON, |
| 3237 | }; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3238 | struct drm_device *dev = encoder->dev; |
| 3239 | struct drm_encoder *partner; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3240 | |
| 3241 | nv_encoder->last_dpms = mode; |
| 3242 | |
| 3243 | list_for_each_entry(partner, &dev->mode_config.encoder_list, head) { |
| 3244 | struct nouveau_encoder *nv_partner = nouveau_encoder(partner); |
| 3245 | |
| 3246 | if (partner->encoder_type != DRM_MODE_ENCODER_TMDS) |
| 3247 | continue; |
| 3248 | |
| 3249 | if (nv_partner != nv_encoder && |
Ben Skeggs | 26cfa81 | 2011-11-17 09:10:02 +1000 | [diff] [blame] | 3250 | nv_partner->dcb->or == nv_encoder->dcb->or) { |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3251 | if (nv_partner->last_dpms == DRM_MODE_DPMS_ON) |
| 3252 | return; |
| 3253 | break; |
| 3254 | } |
| 3255 | } |
| 3256 | |
Ben Skeggs | 4874322 | 2014-05-31 01:48:06 +1000 | [diff] [blame] | 3257 | if (nv_encoder->dcb->type == DCB_OUTPUT_DP) { |
Ben Skeggs | d55b4af | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3258 | args.pwr.state = 1; |
| 3259 | nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
Ben Skeggs | c02ed2b | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3260 | nvif_mthd(disp->disp, 0, &link, sizeof(link)); |
Ben Skeggs | 4874322 | 2014-05-31 01:48:06 +1000 | [diff] [blame] | 3261 | } else { |
Ben Skeggs | d55b4af | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 3262 | nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
Ben Skeggs | 4874322 | 2014-05-31 01:48:06 +1000 | [diff] [blame] | 3263 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3264 | } |
| 3265 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3266 | static void |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3267 | nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data) |
| 3268 | { |
| 3269 | struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev); |
| 3270 | u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push; |
| 3271 | if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3272 | if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) { |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3273 | evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1); |
| 3274 | evo_data(push, (nv_encoder->ctrl = temp)); |
| 3275 | } else { |
| 3276 | evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1); |
| 3277 | evo_data(push, (nv_encoder->ctrl = temp)); |
| 3278 | } |
| 3279 | evo_kick(push, mast); |
| 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3284 | nv50_sor_disconnect(struct drm_encoder *encoder) |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 3285 | { |
| 3286 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3287 | struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc); |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3288 | |
| 3289 | nv_encoder->last_dpms = DRM_MODE_DPMS_OFF; |
| 3290 | nv_encoder->crtc = NULL; |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3291 | |
| 3292 | if (nv_crtc) { |
| 3293 | nv50_crtc_prepare(&nv_crtc->base); |
| 3294 | nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0); |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 3295 | nv50_audio_disconnect(encoder, nv_crtc); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3296 | nv50_hdmi_disconnect(&nv_encoder->base.base, nv_crtc); |
| 3297 | } |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 3298 | } |
| 3299 | |
| 3300 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3301 | nv50_sor_commit(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3302 | { |
| 3303 | } |
| 3304 | |
| 3305 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3306 | nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode, |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3307 | struct drm_display_mode *mode) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3308 | { |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3309 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 3310 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
| 3311 | struct { |
| 3312 | struct nv50_disp_mthd_v1 base; |
| 3313 | struct nv50_disp_sor_lvds_script_v0 lvds; |
| 3314 | } lvds = { |
| 3315 | .base.version = 1, |
| 3316 | .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT, |
| 3317 | .base.hasht = nv_encoder->dcb->hasht, |
| 3318 | .base.hashm = nv_encoder->dcb->hashm, |
| 3319 | }; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3320 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
| 3321 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 3322 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 3323 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3324 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 3325 | struct nvbios *bios = &drm->vbios; |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3326 | u32 mask, ctrl; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3327 | u8 owner = 1 << nv_crtc->index; |
| 3328 | u8 proto = 0xf; |
| 3329 | u8 depth = 0x0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3330 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3331 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3332 | nv_encoder->crtc = encoder->crtc; |
| 3333 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3334 | switch (nv_encoder->dcb->type) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 3335 | case DCB_OUTPUT_TMDS: |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3336 | if (nv_encoder->dcb->sorconf.link & 1) { |
Hauke Mehrtens | 16ef53a9 | 2015-11-03 21:00:10 -0500 | [diff] [blame] | 3337 | proto = 0x1; |
| 3338 | /* Only enable dual-link if: |
| 3339 | * - Need to (i.e. rate > 165MHz) |
| 3340 | * - DCB says we can |
| 3341 | * - Not an HDMI monitor, since there's no dual-link |
| 3342 | * on HDMI. |
| 3343 | */ |
| 3344 | if (mode->clock >= 165000 && |
| 3345 | nv_encoder->dcb->duallink_possible && |
| 3346 | !drm_detect_hdmi_monitor(nv_connector->edid)) |
| 3347 | proto |= 0x4; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3348 | } else { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3349 | proto = 0x2; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3350 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3351 | |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3352 | nv50_hdmi_mode_set(&nv_encoder->base.base, mode); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3353 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 3354 | case DCB_OUTPUT_LVDS: |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3355 | proto = 0x0; |
| 3356 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3357 | if (bios->fp_no_ddc) { |
| 3358 | if (bios->fp.dual_link) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3359 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3360 | if (bios->fp.if_is_24bit) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3361 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3362 | } else { |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 3363 | if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3364 | if (((u8 *)nv_connector->edid)[121] == 2) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3365 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3366 | } else |
| 3367 | if (mode->clock >= bios->fp.duallink_transition_clk) { |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3368 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3369 | } |
| 3370 | |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3371 | if (lvds.lvds.script & 0x0100) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3372 | if (bios->fp.strapless_is_24bit & 2) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3373 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3374 | } else { |
| 3375 | if (bios->fp.strapless_is_24bit & 1) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3376 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | if (nv_connector->base.display_info.bpc == 8) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3380 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3381 | } |
Ben Skeggs | 4a230fa | 2012-11-09 11:25:37 +1000 | [diff] [blame] | 3382 | |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3383 | nvif_mthd(disp->disp, 0, &lvds, sizeof(lvds)); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3384 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 3385 | case DCB_OUTPUT_DP: |
Ben Skeggs | 3488c57 | 2012-03-12 11:42:20 +1000 | [diff] [blame] | 3386 | if (nv_connector->base.display_info.bpc == 6) { |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 3387 | nv_encoder->dp.datarate = mode->clock * 18 / 8; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3388 | depth = 0x2; |
Ben Skeggs | bf2c886 | 2012-11-21 14:49:54 +1000 | [diff] [blame] | 3389 | } else |
| 3390 | if (nv_connector->base.display_info.bpc == 8) { |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 3391 | nv_encoder->dp.datarate = mode->clock * 24 / 8; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3392 | depth = 0x5; |
Ben Skeggs | bf2c886 | 2012-11-21 14:49:54 +1000 | [diff] [blame] | 3393 | } else { |
| 3394 | nv_encoder->dp.datarate = mode->clock * 30 / 8; |
| 3395 | depth = 0x6; |
Ben Skeggs | 3488c57 | 2012-03-12 11:42:20 +1000 | [diff] [blame] | 3396 | } |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 3397 | |
| 3398 | if (nv_encoder->dcb->sorconf.link & 1) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3399 | proto = 0x8; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 3400 | else |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3401 | proto = 0x9; |
Ben Skeggs | 3eee864 | 2014-09-15 15:20:47 +1000 | [diff] [blame] | 3402 | nv50_audio_mode_set(encoder, mode); |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 3403 | break; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 3404 | default: |
| 3405 | BUG_ON(1); |
| 3406 | break; |
| 3407 | } |
Ben Skeggs | ff8ff50 | 2011-07-08 11:53:37 +1000 | [diff] [blame] | 3408 | |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3409 | nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3410 | |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3411 | if (nv50_vers(mast) >= GF110_DISP) { |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3412 | u32 *push = evo_wait(mast, 3); |
| 3413 | if (push) { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3414 | u32 magic = 0x31ec6000 | (nv_crtc->index << 25); |
| 3415 | u32 syncs = 0x00000001; |
| 3416 | |
| 3417 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 3418 | syncs |= 0x00000008; |
| 3419 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 3420 | syncs |= 0x00000010; |
| 3421 | |
| 3422 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 3423 | magic |= 0x00000001; |
| 3424 | |
| 3425 | evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2); |
| 3426 | evo_data(push, syncs | (depth << 6)); |
| 3427 | evo_data(push, magic); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3428 | evo_kick(push, mast); |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 3429 | } |
| 3430 | |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3431 | ctrl = proto << 8; |
| 3432 | mask = 0x00000f00; |
| 3433 | } else { |
| 3434 | ctrl = (depth << 16) | (proto << 8); |
| 3435 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 3436 | ctrl |= 0x00001000; |
| 3437 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 3438 | ctrl |= 0x00002000; |
| 3439 | mask = 0x000f3f00; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3440 | } |
| 3441 | |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 3442 | nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3446 | nv50_sor_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3447 | { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3448 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 3449 | nv50_mstm_del(&nv_encoder->dp.mstm); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3450 | drm_encoder_cleanup(encoder); |
| 3451 | kfree(encoder); |
| 3452 | } |
| 3453 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3454 | static const struct drm_encoder_helper_funcs nv50_sor_hfunc = { |
| 3455 | .dpms = nv50_sor_dpms, |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 3456 | .mode_fixup = nv50_encoder_mode_fixup, |
Ben Skeggs | 5a885f0 | 2013-02-20 14:34:18 +1000 | [diff] [blame] | 3457 | .prepare = nv50_sor_disconnect, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3458 | .commit = nv50_sor_commit, |
| 3459 | .mode_set = nv50_sor_mode_set, |
| 3460 | .disable = nv50_sor_disconnect, |
| 3461 | .get_crtc = nv50_display_crtc_get, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3462 | }; |
| 3463 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3464 | static const struct drm_encoder_funcs nv50_sor_func = { |
| 3465 | .destroy = nv50_sor_destroy, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3466 | }; |
| 3467 | |
| 3468 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3469 | nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3470 | { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3471 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 3472 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | be83cd4 | 2015-01-14 15:36:34 +1000 | [diff] [blame] | 3473 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->device); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3474 | struct nouveau_encoder *nv_encoder; |
| 3475 | struct drm_encoder *encoder; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3476 | int type, ret; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 3477 | |
| 3478 | switch (dcbe->type) { |
| 3479 | case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break; |
| 3480 | case DCB_OUTPUT_TMDS: |
| 3481 | case DCB_OUTPUT_DP: |
| 3482 | default: |
| 3483 | type = DRM_MODE_ENCODER_TMDS; |
| 3484 | break; |
| 3485 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3486 | |
| 3487 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 3488 | if (!nv_encoder) |
| 3489 | return -ENOMEM; |
| 3490 | nv_encoder->dcb = dcbe; |
| 3491 | nv_encoder->or = ffs(dcbe->or) - 1; |
| 3492 | nv_encoder->last_dpms = DRM_MODE_DPMS_OFF; |
| 3493 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3494 | encoder = to_drm_encoder(nv_encoder); |
| 3495 | encoder->possible_crtcs = dcbe->heads; |
| 3496 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3497 | drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type, |
| 3498 | "sor-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3499 | drm_encoder_helper_add(encoder, &nv50_sor_hfunc); |
| 3500 | |
| 3501 | drm_mode_connector_attach_encoder(connector, encoder); |
| 3502 | |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3503 | if (dcbe->type == DCB_OUTPUT_DP) { |
| 3504 | struct nvkm_i2c_aux *aux = |
| 3505 | nvkm_i2c_aux_find(i2c, dcbe->i2c_index); |
| 3506 | if (aux) { |
| 3507 | nv_encoder->i2c = &aux->i2c; |
| 3508 | nv_encoder->aux = aux; |
| 3509 | } |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3510 | |
| 3511 | /*TODO: Use DP Info Table to check for support. */ |
| 3512 | if (nv50_disp(encoder->dev)->disp->oclass >= GF110_DISP) { |
| 3513 | ret = nv50_mstm_new(nv_encoder, &nv_connector->aux, 16, |
| 3514 | nv_connector->base.base.id, |
| 3515 | &nv_encoder->dp.mstm); |
| 3516 | if (ret) |
| 3517 | return ret; |
| 3518 | } |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3519 | } else { |
| 3520 | struct nvkm_i2c_bus *bus = |
| 3521 | nvkm_i2c_bus_find(i2c, dcbe->i2c_index); |
| 3522 | if (bus) |
| 3523 | nv_encoder->i2c = &bus->i2c; |
| 3524 | } |
| 3525 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3526 | return 0; |
| 3527 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3528 | |
| 3529 | /****************************************************************************** |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3530 | * PIOR |
| 3531 | *****************************************************************************/ |
| 3532 | |
| 3533 | static void |
| 3534 | nv50_pior_dpms(struct drm_encoder *encoder, int mode) |
| 3535 | { |
| 3536 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 3537 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 67cb49c | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3538 | struct { |
| 3539 | struct nv50_disp_mthd_v1 base; |
| 3540 | struct nv50_disp_pior_pwr_v0 pwr; |
| 3541 | } args = { |
| 3542 | .base.version = 1, |
| 3543 | .base.method = NV50_DISP_MTHD_V1_PIOR_PWR, |
| 3544 | .base.hasht = nv_encoder->dcb->hasht, |
| 3545 | .base.hashm = nv_encoder->dcb->hashm, |
| 3546 | .pwr.state = mode == DRM_MODE_DPMS_ON, |
| 3547 | .pwr.type = nv_encoder->dcb->type, |
| 3548 | }; |
| 3549 | |
| 3550 | nvif_mthd(disp->disp, 0, &args, sizeof(args)); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | static bool |
| 3554 | nv50_pior_mode_fixup(struct drm_encoder *encoder, |
| 3555 | const struct drm_display_mode *mode, |
| 3556 | struct drm_display_mode *adjusted_mode) |
| 3557 | { |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 3558 | if (!nv50_encoder_mode_fixup(encoder, mode, adjusted_mode)) |
| 3559 | return false; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3560 | adjusted_mode->clock *= 2; |
| 3561 | return true; |
| 3562 | } |
| 3563 | |
| 3564 | static void |
| 3565 | nv50_pior_commit(struct drm_encoder *encoder) |
| 3566 | { |
| 3567 | } |
| 3568 | |
| 3569 | static void |
| 3570 | nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, |
| 3571 | struct drm_display_mode *adjusted_mode) |
| 3572 | { |
| 3573 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
| 3574 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 3575 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
| 3576 | struct nouveau_connector *nv_connector; |
| 3577 | u8 owner = 1 << nv_crtc->index; |
| 3578 | u8 proto, depth; |
| 3579 | u32 *push; |
| 3580 | |
| 3581 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 3582 | switch (nv_connector->base.display_info.bpc) { |
| 3583 | case 10: depth = 0x6; break; |
| 3584 | case 8: depth = 0x5; break; |
| 3585 | case 6: depth = 0x2; break; |
| 3586 | default: depth = 0x0; break; |
| 3587 | } |
| 3588 | |
| 3589 | switch (nv_encoder->dcb->type) { |
| 3590 | case DCB_OUTPUT_TMDS: |
| 3591 | case DCB_OUTPUT_DP: |
| 3592 | proto = 0x0; |
| 3593 | break; |
| 3594 | default: |
| 3595 | BUG_ON(1); |
| 3596 | break; |
| 3597 | } |
| 3598 | |
| 3599 | nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON); |
| 3600 | |
| 3601 | push = evo_wait(mast, 8); |
| 3602 | if (push) { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3603 | if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) { |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3604 | u32 ctrl = (depth << 16) | (proto << 8) | owner; |
| 3605 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 3606 | ctrl |= 0x00001000; |
| 3607 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 3608 | ctrl |= 0x00002000; |
| 3609 | evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1); |
| 3610 | evo_data(push, ctrl); |
| 3611 | } |
| 3612 | |
| 3613 | evo_kick(push, mast); |
| 3614 | } |
| 3615 | |
| 3616 | nv_encoder->crtc = encoder->crtc; |
| 3617 | } |
| 3618 | |
| 3619 | static void |
| 3620 | nv50_pior_disconnect(struct drm_encoder *encoder) |
| 3621 | { |
| 3622 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 3623 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
| 3624 | const int or = nv_encoder->or; |
| 3625 | u32 *push; |
| 3626 | |
| 3627 | if (nv_encoder->crtc) { |
| 3628 | nv50_crtc_prepare(nv_encoder->crtc); |
| 3629 | |
| 3630 | push = evo_wait(mast, 4); |
| 3631 | if (push) { |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3632 | if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) { |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3633 | evo_mthd(push, 0x0700 + (or * 0x040), 1); |
| 3634 | evo_data(push, 0x00000000); |
| 3635 | } |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3636 | evo_kick(push, mast); |
| 3637 | } |
| 3638 | } |
| 3639 | |
| 3640 | nv_encoder->crtc = NULL; |
| 3641 | } |
| 3642 | |
| 3643 | static void |
| 3644 | nv50_pior_destroy(struct drm_encoder *encoder) |
| 3645 | { |
| 3646 | drm_encoder_cleanup(encoder); |
| 3647 | kfree(encoder); |
| 3648 | } |
| 3649 | |
| 3650 | static const struct drm_encoder_helper_funcs nv50_pior_hfunc = { |
| 3651 | .dpms = nv50_pior_dpms, |
| 3652 | .mode_fixup = nv50_pior_mode_fixup, |
| 3653 | .prepare = nv50_pior_disconnect, |
| 3654 | .commit = nv50_pior_commit, |
| 3655 | .mode_set = nv50_pior_mode_set, |
| 3656 | .disable = nv50_pior_disconnect, |
| 3657 | .get_crtc = nv50_display_crtc_get, |
| 3658 | }; |
| 3659 | |
| 3660 | static const struct drm_encoder_funcs nv50_pior_func = { |
| 3661 | .destroy = nv50_pior_destroy, |
| 3662 | }; |
| 3663 | |
| 3664 | static int |
| 3665 | nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe) |
| 3666 | { |
| 3667 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | be83cd4 | 2015-01-14 15:36:34 +1000 | [diff] [blame] | 3668 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->device); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3669 | struct nvkm_i2c_bus *bus = NULL; |
| 3670 | struct nvkm_i2c_aux *aux = NULL; |
| 3671 | struct i2c_adapter *ddc; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3672 | struct nouveau_encoder *nv_encoder; |
| 3673 | struct drm_encoder *encoder; |
| 3674 | int type; |
| 3675 | |
| 3676 | switch (dcbe->type) { |
| 3677 | case DCB_OUTPUT_TMDS: |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3678 | bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev)); |
| 3679 | ddc = bus ? &bus->i2c : NULL; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3680 | type = DRM_MODE_ENCODER_TMDS; |
| 3681 | break; |
| 3682 | case DCB_OUTPUT_DP: |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3683 | aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev)); |
| 3684 | ddc = aux ? &aux->i2c : NULL; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3685 | type = DRM_MODE_ENCODER_TMDS; |
| 3686 | break; |
| 3687 | default: |
| 3688 | return -ENODEV; |
| 3689 | } |
| 3690 | |
| 3691 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 3692 | if (!nv_encoder) |
| 3693 | return -ENOMEM; |
| 3694 | nv_encoder->dcb = dcbe; |
| 3695 | nv_encoder->or = ffs(dcbe->or) - 1; |
| 3696 | nv_encoder->i2c = ddc; |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3697 | nv_encoder->aux = aux; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3698 | |
| 3699 | encoder = to_drm_encoder(nv_encoder); |
| 3700 | encoder->possible_crtcs = dcbe->heads; |
| 3701 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3702 | drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type, |
| 3703 | "pior-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3704 | drm_encoder_helper_add(encoder, &nv50_pior_hfunc); |
| 3705 | |
| 3706 | drm_mode_connector_attach_encoder(connector, encoder); |
| 3707 | return 0; |
| 3708 | } |
| 3709 | |
| 3710 | /****************************************************************************** |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3711 | * Framebuffer |
| 3712 | *****************************************************************************/ |
| 3713 | |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3714 | static void |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3715 | nv50_fb_dtor(struct drm_framebuffer *fb) |
| 3716 | { |
| 3717 | } |
| 3718 | |
| 3719 | static int |
| 3720 | nv50_fb_ctor(struct drm_framebuffer *fb) |
| 3721 | { |
| 3722 | struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb); |
| 3723 | struct nouveau_drm *drm = nouveau_drm(fb->dev); |
| 3724 | struct nouveau_bo *nvbo = nv_fb->nvbo; |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3725 | struct nv50_disp *disp = nv50_disp(fb->dev); |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3726 | u8 kind = nouveau_bo_tile_layout(nvbo) >> 8; |
| 3727 | u8 tile = nvbo->tile_mode; |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3728 | struct drm_crtc *crtc; |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3729 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 3730 | if (drm->device.info.chipset >= 0xc0) |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3731 | tile >>= 4; /* yep.. */ |
| 3732 | |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3733 | switch (fb->depth) { |
| 3734 | case 8: nv_fb->r_format = 0x1e00; break; |
| 3735 | case 15: nv_fb->r_format = 0xe900; break; |
| 3736 | case 16: nv_fb->r_format = 0xe800; break; |
| 3737 | case 24: |
| 3738 | case 32: nv_fb->r_format = 0xcf00; break; |
| 3739 | case 30: nv_fb->r_format = 0xd100; break; |
| 3740 | default: |
| 3741 | NV_ERROR(drm, "unknown depth %d\n", fb->depth); |
| 3742 | return -EINVAL; |
| 3743 | } |
| 3744 | |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3745 | if (disp->disp->oclass < G82_DISP) { |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3746 | nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) : |
| 3747 | (fb->pitches[0] | 0x00100000); |
| 3748 | nv_fb->r_format |= kind << 16; |
| 3749 | } else |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3750 | if (disp->disp->oclass < GF110_DISP) { |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3751 | nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) : |
| 3752 | (fb->pitches[0] | 0x00100000); |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3753 | } else { |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3754 | nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) : |
| 3755 | (fb->pitches[0] | 0x01000000); |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3756 | } |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3757 | nv_fb->r_handle = 0xffff0000 | kind; |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3758 | |
Ben Skeggs | accdea2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3759 | list_for_each_entry(crtc, &drm->dev->mode_config.crtc_list, head) { |
| 3760 | struct nv50_head *head = nv50_head(crtc); |
| 3761 | struct nv50_dmac_ctxdma *ctxdma; |
| 3762 | |
| 3763 | ctxdma = nv50_dmac_ctxdma_new(&head->_base->chan.base, |
| 3764 | nv_fb->r_handle, nv_fb); |
| 3765 | if (IS_ERR(ctxdma)) |
| 3766 | return PTR_ERR(ctxdma); |
| 3767 | } |
| 3768 | |
| 3769 | return 0; |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3773 | * Init |
| 3774 | *****************************************************************************/ |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3775 | |
Ben Skeggs | 2a44e49 | 2011-11-09 11:36:33 +1000 | [diff] [blame] | 3776 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3777 | nv50_display_fini(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3778 | { |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3779 | struct drm_plane *plane; |
| 3780 | |
| 3781 | drm_for_each_plane(plane, dev) { |
| 3782 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 3783 | if (plane->funcs != &nv50_wndw) |
| 3784 | continue; |
| 3785 | nv50_wndw_fini(wndw); |
| 3786 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3790 | nv50_display_init(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3791 | { |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 3792 | struct nv50_disp *disp = nv50_disp(dev); |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame^] | 3793 | struct drm_encoder *encoder; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3794 | struct drm_plane *plane; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 3795 | struct drm_crtc *crtc; |
| 3796 | u32 *push; |
| 3797 | |
| 3798 | push = evo_wait(nv50_mast(dev), 32); |
| 3799 | if (!push) |
| 3800 | return -EBUSY; |
| 3801 | |
| 3802 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3803 | struct nv50_wndw *wndw = &nv50_head(crtc)->_base->wndw; |
Maarten Lankhorst | 4dc6393 | 2015-01-13 09:18:49 +0100 | [diff] [blame] | 3804 | |
| 3805 | nv50_crtc_lut_load(crtc); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3806 | nouveau_bo_wr32(disp->sync, wndw->sema / 4, wndw->data); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3807 | } |
| 3808 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 3809 | evo_mthd(push, 0x0088, 1); |
Ben Skeggs | f45f55c | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 3810 | evo_data(push, nv50_mast(dev)->base.sync.handle); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 3811 | evo_kick(push, nv50_mast(dev)); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3812 | |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame^] | 3813 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 3814 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
| 3815 | const struct drm_encoder_helper_funcs *help; |
| 3816 | struct nouveau_encoder *nv_encoder; |
| 3817 | |
| 3818 | nv_encoder = nouveau_encoder(encoder); |
| 3819 | if (nv_encoder->dcb->type == DCB_OUTPUT_DP) |
| 3820 | nv_encoder->dcb->type = DCB_OUTPUT_EOL; |
| 3821 | |
| 3822 | help = encoder->helper_private; |
| 3823 | if (help && help->dpms) |
| 3824 | help->dpms(encoder, DRM_MODE_DPMS_ON); |
| 3825 | |
| 3826 | if (nv_encoder->dcb->type == DCB_OUTPUT_EOL) |
| 3827 | nv_encoder->dcb->type = DCB_OUTPUT_DP; |
| 3828 | } |
| 3829 | } |
| 3830 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 3831 | drm_for_each_plane(plane, dev) { |
| 3832 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 3833 | if (plane->funcs != &nv50_wndw) |
| 3834 | continue; |
| 3835 | nv50_wndw_init(wndw); |
| 3836 | } |
| 3837 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 3838 | return 0; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3842 | nv50_display_destroy(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3843 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3844 | struct nv50_disp *disp = nv50_disp(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3845 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 3846 | nv50_dmac_destroy(&disp->mast.base, disp->disp); |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 3847 | |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 3848 | nouveau_bo_unmap(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 3849 | if (disp->sync) |
| 3850 | nouveau_bo_unpin(disp->sync); |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 3851 | nouveau_bo_ref(NULL, &disp->sync); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 3852 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 3853 | nouveau_display(dev)->priv = NULL; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3854 | kfree(disp); |
| 3855 | } |
| 3856 | |
| 3857 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3858 | nv50_display_create(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3859 | { |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 3860 | struct nvif_device *device = &nouveau_drm(dev)->device; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 3861 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 3862 | struct dcb_table *dcb = &drm->vbios.dcb; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3863 | struct drm_connector *connector, *tmp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3864 | struct nv50_disp *disp; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 3865 | struct dcb_output *dcbe; |
Ben Skeggs | 7c5f6a8 | 2012-03-04 16:25:59 +1000 | [diff] [blame] | 3866 | int crtcs, ret, i; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3867 | |
| 3868 | disp = kzalloc(sizeof(*disp), GFP_KERNEL); |
| 3869 | if (!disp) |
| 3870 | return -ENOMEM; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 3871 | |
| 3872 | nouveau_display(dev)->priv = disp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3873 | nouveau_display(dev)->dtor = nv50_display_destroy; |
| 3874 | nouveau_display(dev)->init = nv50_display_init; |
| 3875 | nouveau_display(dev)->fini = nv50_display_fini; |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 3876 | nouveau_display(dev)->fb_ctor = nv50_fb_ctor; |
| 3877 | nouveau_display(dev)->fb_dtor = nv50_fb_dtor; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 3878 | disp->disp = &nouveau_display(dev)->disp; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3879 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 3880 | /* small shared memory area we use for notifiers and semaphores */ |
| 3881 | ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM, |
Maarten Lankhorst | bb6178b | 2014-01-09 11:03:15 +0100 | [diff] [blame] | 3882 | 0, 0x0000, NULL, NULL, &disp->sync); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 3883 | if (!ret) { |
Ben Skeggs | 547ad07 | 2014-11-10 12:35:06 +1000 | [diff] [blame] | 3884 | ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 3885 | if (!ret) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 3886 | ret = nouveau_bo_map(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 3887 | if (ret) |
| 3888 | nouveau_bo_unpin(disp->sync); |
| 3889 | } |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 3890 | if (ret) |
| 3891 | nouveau_bo_ref(NULL, &disp->sync); |
| 3892 | } |
| 3893 | |
| 3894 | if (ret) |
| 3895 | goto out; |
| 3896 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 3897 | /* allocate master evo channel */ |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3898 | ret = nv50_core_create(device, disp->disp, disp->sync->bo.offset, |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 3899 | &disp->mast); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 3900 | if (ret) |
| 3901 | goto out; |
| 3902 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 3903 | /* create crtc objects to represent the hw heads */ |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 3904 | if (disp->disp->oclass >= GF110_DISP) |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 3905 | crtcs = nvif_rd32(&device->object, 0x022448); |
Ben Skeggs | 63718a0 | 2012-11-16 11:44:14 +1000 | [diff] [blame] | 3906 | else |
| 3907 | crtcs = 2; |
| 3908 | |
Ben Skeggs | 7c5f6a8 | 2012-03-04 16:25:59 +1000 | [diff] [blame] | 3909 | for (i = 0; i < crtcs; i++) { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 3910 | ret = nv50_crtc_create(dev, i); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 3911 | if (ret) |
| 3912 | goto out; |
| 3913 | } |
| 3914 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3915 | /* create encoder/connector objects based on VBIOS DCB table */ |
| 3916 | for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) { |
| 3917 | connector = nouveau_connector_create(dev, dcbe->connector); |
| 3918 | if (IS_ERR(connector)) |
| 3919 | continue; |
| 3920 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3921 | if (dcbe->location == DCB_LOC_ON_CHIP) { |
| 3922 | switch (dcbe->type) { |
| 3923 | case DCB_OUTPUT_TMDS: |
| 3924 | case DCB_OUTPUT_LVDS: |
| 3925 | case DCB_OUTPUT_DP: |
| 3926 | ret = nv50_sor_create(connector, dcbe); |
| 3927 | break; |
| 3928 | case DCB_OUTPUT_ANALOG: |
| 3929 | ret = nv50_dac_create(connector, dcbe); |
| 3930 | break; |
| 3931 | default: |
| 3932 | ret = -ENODEV; |
| 3933 | break; |
| 3934 | } |
| 3935 | } else { |
| 3936 | ret = nv50_pior_create(connector, dcbe); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3937 | } |
| 3938 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 3939 | if (ret) { |
| 3940 | NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n", |
| 3941 | dcbe->location, dcbe->type, |
| 3942 | ffs(dcbe->or) - 1, ret); |
Ben Skeggs | 94f54f5 | 2013-03-05 22:26:06 +1000 | [diff] [blame] | 3943 | ret = 0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | /* cull any connectors we created that don't have an encoder */ |
| 3948 | list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) { |
| 3949 | if (connector->encoder_ids[0]) |
| 3950 | continue; |
| 3951 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 3952 | NV_WARN(drm, "%s has no encoders, removing\n", |
Jani Nikula | 8c6c361 | 2014-06-03 14:56:18 +0300 | [diff] [blame] | 3953 | connector->name); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 3954 | connector->funcs->destroy(connector); |
| 3955 | } |
| 3956 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3957 | out: |
| 3958 | if (ret) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 3959 | nv50_display_destroy(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 3960 | return ret; |
| 3961 | } |