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