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