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