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