Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Maarten Maathuis. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | * |
| 25 | */ |
| 26 | |
Hans de Goede | 3a6536c | 2016-11-09 18:17:44 +0100 | [diff] [blame] | 27 | #include <acpi/video.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 28 | #include <drm/drmP.h> |
Ben Skeggs | b167db0 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 29 | #include <drm/drm_atomic.h> |
| 30 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 31 | #include <drm/drm_crtc_helper.h> |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 32 | |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 33 | #include <nvif/class.h> |
| 34 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 35 | #include "nouveau_fbcon.h" |
Ben Skeggs | 1a64634 | 2013-03-21 15:45:11 +1000 | [diff] [blame] | 36 | #include "dispnv04/hw.h" |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 37 | #include "nouveau_crtc.h" |
| 38 | #include "nouveau_dma.h" |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 39 | #include "nouveau_gem.h" |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 40 | #include "nouveau_connector.h" |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 41 | #include "nv50_display.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 42 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 43 | #include "nouveau_fence.h" |
| 44 | |
Ben Skeggs | 7568b10 | 2015-11-08 10:44:19 +1000 | [diff] [blame] | 45 | #include <nvif/cl0046.h> |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 46 | #include <nvif/event.h> |
Ben Skeggs | 1d7c71a | 2013-01-31 09:23:34 +1000 | [diff] [blame] | 47 | |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 48 | static int |
Ben Skeggs | 80bc340 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 49 | nouveau_display_vblank_handler(struct nvif_notify *notify) |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 50 | { |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 51 | struct nouveau_crtc *nv_crtc = |
| 52 | container_of(notify, typeof(*nv_crtc), vblank); |
Gustavo Padovan | d297b02 | 2016-07-04 21:04:50 -0300 | [diff] [blame] | 53 | drm_crtc_handle_vblank(&nv_crtc->base); |
Ben Skeggs | 80bc340 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 54 | return NVIF_NOTIFY_KEEP; |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | int |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 58 | nouveau_display_vblank_enable(struct drm_device *dev, unsigned int pipe) |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 59 | { |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 60 | struct drm_crtc *crtc; |
Shawn Guo | ea441bd | 2017-01-09 19:25:43 +0800 | [diff] [blame] | 61 | struct nouveau_crtc *nv_crtc; |
| 62 | |
| 63 | crtc = drm_crtc_from_index(dev, pipe); |
| 64 | if (!crtc) |
| 65 | return -EINVAL; |
| 66 | |
| 67 | nv_crtc = nouveau_crtc(crtc); |
| 68 | nvif_notify_get(&nv_crtc->vblank); |
| 69 | |
| 70 | return 0; |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 74 | nouveau_display_vblank_disable(struct drm_device *dev, unsigned int pipe) |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 75 | { |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 76 | struct drm_crtc *crtc; |
Shawn Guo | ea441bd | 2017-01-09 19:25:43 +0800 | [diff] [blame] | 77 | struct nouveau_crtc *nv_crtc; |
| 78 | |
| 79 | crtc = drm_crtc_from_index(dev, pipe); |
| 80 | if (!crtc) |
| 81 | return; |
| 82 | |
| 83 | nv_crtc = nouveau_crtc(crtc); |
| 84 | nvif_notify_put(&nv_crtc->vblank); |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 85 | } |
| 86 | |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 87 | static inline int |
| 88 | calc(int blanks, int blanke, int total, int line) |
| 89 | { |
| 90 | if (blanke >= blanks) { |
| 91 | if (line >= blanks) |
| 92 | line -= total; |
| 93 | } else { |
| 94 | if (line >= blanks) |
| 95 | line -= total; |
| 96 | line -= blanke + 1; |
| 97 | } |
| 98 | return line; |
| 99 | } |
| 100 | |
Daniel Vetter | 1bf6ad6 | 2017-05-09 16:03:28 +0200 | [diff] [blame^] | 101 | static bool |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 102 | nouveau_display_scanoutpos_head(struct drm_crtc *crtc, int *vpos, int *hpos, |
| 103 | ktime_t *stime, ktime_t *etime) |
| 104 | { |
Ben Skeggs | 4952b4d | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 105 | struct { |
| 106 | struct nv04_disp_mthd_v0 base; |
| 107 | struct nv04_disp_scanoutpos_v0 scan; |
| 108 | } args = { |
| 109 | .base.method = NV04_DISP_SCANOUTPOS, |
| 110 | .base.head = nouveau_crtc(crtc)->index, |
| 111 | }; |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 112 | struct nouveau_display *disp = nouveau_display(crtc->dev); |
Ville Syrjälä | eba1f35 | 2015-09-14 22:43:43 +0300 | [diff] [blame] | 113 | struct drm_vblank_crtc *vblank = &crtc->dev->vblank[drm_crtc_index(crtc)]; |
Daniel Vetter | 1bf6ad6 | 2017-05-09 16:03:28 +0200 | [diff] [blame^] | 114 | int retry = 20; |
| 115 | bool ret = false; |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 116 | |
| 117 | do { |
Ben Skeggs | 4952b4d | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 118 | ret = nvif_mthd(&disp->disp, 0, &args, sizeof(args)); |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 119 | if (ret != 0) |
Daniel Vetter | 1bf6ad6 | 2017-05-09 16:03:28 +0200 | [diff] [blame^] | 120 | return false; |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 121 | |
Ben Skeggs | 4952b4d | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 122 | if (args.scan.vline) { |
Daniel Vetter | 1bf6ad6 | 2017-05-09 16:03:28 +0200 | [diff] [blame^] | 123 | ret = true; |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 124 | break; |
| 125 | } |
| 126 | |
Ville Syrjälä | eba1f35 | 2015-09-14 22:43:43 +0300 | [diff] [blame] | 127 | if (retry) ndelay(vblank->linedur_ns); |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 128 | } while (retry--); |
| 129 | |
Ben Skeggs | 4952b4d | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 130 | *hpos = args.scan.hline; |
| 131 | *vpos = calc(args.scan.vblanks, args.scan.vblanke, |
| 132 | args.scan.vtotal, args.scan.vline); |
| 133 | if (stime) *stime = ns_to_ktime(args.scan.time[0]); |
| 134 | if (etime) *etime = ns_to_ktime(args.scan.time[1]); |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 135 | |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 136 | return ret; |
| 137 | } |
| 138 | |
Daniel Vetter | 1bf6ad6 | 2017-05-09 16:03:28 +0200 | [diff] [blame^] | 139 | bool |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 140 | nouveau_display_scanoutpos(struct drm_device *dev, unsigned int pipe, |
Daniel Vetter | 1bf6ad6 | 2017-05-09 16:03:28 +0200 | [diff] [blame^] | 141 | bool in_vblank_irq, int *vpos, int *hpos, |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 142 | ktime_t *stime, ktime_t *etime, |
Ville Syrjälä | 3bb403b | 2015-09-14 22:43:44 +0300 | [diff] [blame] | 143 | const struct drm_display_mode *mode) |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 144 | { |
| 145 | struct drm_crtc *crtc; |
| 146 | |
| 147 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 148 | if (nouveau_crtc(crtc)->index == pipe) { |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 149 | return nouveau_display_scanoutpos_head(crtc, vpos, hpos, |
| 150 | stime, etime); |
| 151 | } |
| 152 | } |
| 153 | |
Daniel Vetter | d673c02 | 2017-05-09 16:03:25 +0200 | [diff] [blame] | 154 | return false; |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 155 | } |
| 156 | |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 157 | static void |
| 158 | nouveau_display_vblank_fini(struct drm_device *dev) |
| 159 | { |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 160 | struct drm_crtc *crtc; |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 161 | |
Ben Skeggs | 1139ffb | 2014-01-23 10:49:47 +1000 | [diff] [blame] | 162 | drm_vblank_cleanup(dev); |
| 163 | |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 164 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 165 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 80bc340 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 166 | nvif_notify_fini(&nv_crtc->vblank); |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 167 | } |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static int |
| 171 | nouveau_display_vblank_init(struct drm_device *dev) |
| 172 | { |
Ben Skeggs | 80bc340 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 173 | struct nouveau_display *disp = nouveau_display(dev); |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 174 | struct drm_crtc *crtc; |
| 175 | int ret; |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 176 | |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 177 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 178 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 179 | ret = nvif_notify_init(&disp->disp, |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 180 | nouveau_display_vblank_handler, false, |
Ben Skeggs | 80bc340 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 181 | NV04_DISP_NTFY_VBLANK, |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 182 | &(struct nvif_notify_head_req_v0) { |
| 183 | .head = nv_crtc->index, |
| 184 | }, |
| 185 | sizeof(struct nvif_notify_head_req_v0), |
| 186 | sizeof(struct nvif_notify_head_rep_v0), |
| 187 | &nv_crtc->vblank); |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 188 | if (ret) { |
| 189 | nouveau_display_vblank_fini(dev); |
| 190 | return ret; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | ret = drm_vblank_init(dev, dev->mode_config.num_crtc); |
| 195 | if (ret) { |
| 196 | nouveau_display_vblank_fini(dev); |
| 197 | return ret; |
| 198 | } |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 203 | static void |
| 204 | nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb) |
| 205 | { |
| 206 | struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 207 | |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 208 | if (fb->nvbo) |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 209 | drm_gem_object_unreference_unlocked(&fb->nvbo->gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 210 | |
| 211 | drm_framebuffer_cleanup(drm_fb); |
| 212 | kfree(fb); |
| 213 | } |
| 214 | |
| 215 | static int |
| 216 | nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb, |
| 217 | struct drm_file *file_priv, |
| 218 | unsigned int *handle) |
| 219 | { |
| 220 | struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); |
| 221 | |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 222 | return drm_gem_handle_create(file_priv, &fb->nvbo->gem, handle); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = { |
| 226 | .destroy = nouveau_user_framebuffer_destroy, |
| 227 | .create_handle = nouveau_user_framebuffer_create_handle, |
| 228 | }; |
| 229 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 230 | int |
Ben Skeggs | 1608a0f | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 231 | nouveau_framebuffer_new(struct drm_device *dev, |
| 232 | const struct drm_mode_fb_cmd2 *mode_cmd, |
| 233 | struct nouveau_bo *nvbo, |
| 234 | struct nouveau_framebuffer **pfb) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 235 | { |
Ben Skeggs | 1608a0f | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 236 | struct nouveau_framebuffer *fb; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 237 | int ret; |
| 238 | |
Ben Skeggs | f00f0e2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 239 | if (!(fb = *pfb = kzalloc(sizeof(*fb), GFP_KERNEL))) |
Ben Skeggs | 1608a0f | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 240 | return -ENOMEM; |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 241 | |
Ville Syrjälä | a3f913c | 2016-12-14 22:48:59 +0200 | [diff] [blame] | 242 | drm_helper_mode_fill_fb_struct(dev, &fb->base, mode_cmd); |
Ben Skeggs | 1608a0f | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 243 | fb->nvbo = nvbo; |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 244 | |
Ben Skeggs | 1608a0f | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 245 | ret = drm_framebuffer_init(dev, &fb->base, &nouveau_framebuffer_funcs); |
Ben Skeggs | f00f0e2 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 246 | if (ret) |
| 247 | kfree(fb); |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 248 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 249 | } |
| 250 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 251 | struct drm_framebuffer * |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 252 | nouveau_user_framebuffer_create(struct drm_device *dev, |
| 253 | struct drm_file *file_priv, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 254 | const struct drm_mode_fb_cmd2 *mode_cmd) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 255 | { |
Ben Skeggs | 1608a0f | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 256 | struct nouveau_framebuffer *fb; |
| 257 | struct nouveau_bo *nvbo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 258 | struct drm_gem_object *gem; |
Ben Skeggs | 1608a0f | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 259 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 260 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 261 | gem = drm_gem_object_lookup(file_priv, mode_cmd->handles[0]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 262 | if (!gem) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 263 | return ERR_PTR(-ENOENT); |
Ben Skeggs | 1608a0f | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 264 | nvbo = nouveau_gem_object(gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 265 | |
Ben Skeggs | 1608a0f | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 266 | ret = nouveau_framebuffer_new(dev, mode_cmd, nvbo, &fb); |
| 267 | if (ret == 0) |
| 268 | return &fb->base; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 269 | |
Daniel Vetter | e889c24 | 2016-03-30 11:40:40 +0200 | [diff] [blame] | 270 | drm_gem_object_unreference_unlocked(gem); |
Maarten Lankhorst | fdfb833 | 2013-07-08 14:50:54 +1000 | [diff] [blame] | 271 | return ERR_PTR(ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 272 | } |
| 273 | |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 274 | static const struct drm_mode_config_funcs nouveau_mode_config_funcs = { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 275 | .fb_create = nouveau_user_framebuffer_create, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 276 | .output_poll_changed = nouveau_fbcon_output_poll_changed, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 277 | }; |
| 278 | |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 279 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 280 | struct nouveau_drm_prop_enum_list { |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 281 | u8 gen_mask; |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 282 | int type; |
| 283 | char *name; |
| 284 | }; |
| 285 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 286 | static struct nouveau_drm_prop_enum_list underscan[] = { |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 287 | { 6, UNDERSCAN_AUTO, "auto" }, |
| 288 | { 6, UNDERSCAN_OFF, "off" }, |
| 289 | { 6, UNDERSCAN_ON, "on" }, |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 290 | {} |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 291 | }; |
| 292 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 293 | static struct nouveau_drm_prop_enum_list dither_mode[] = { |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 294 | { 7, DITHERING_MODE_AUTO, "auto" }, |
| 295 | { 7, DITHERING_MODE_OFF, "off" }, |
| 296 | { 1, DITHERING_MODE_ON, "on" }, |
| 297 | { 6, DITHERING_MODE_STATIC2X2, "static 2x2" }, |
| 298 | { 6, DITHERING_MODE_DYNAMIC2X2, "dynamic 2x2" }, |
| 299 | { 4, DITHERING_MODE_TEMPORAL, "temporal" }, |
| 300 | {} |
| 301 | }; |
| 302 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 303 | static struct nouveau_drm_prop_enum_list dither_depth[] = { |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 304 | { 6, DITHERING_DEPTH_AUTO, "auto" }, |
| 305 | { 6, DITHERING_DEPTH_6BPC, "6 bpc" }, |
| 306 | { 6, DITHERING_DEPTH_8BPC, "8 bpc" }, |
| 307 | {} |
| 308 | }; |
| 309 | |
| 310 | #define PROP_ENUM(p,gen,n,list) do { \ |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 311 | struct nouveau_drm_prop_enum_list *l = (list); \ |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 312 | int c = 0; \ |
| 313 | while (l->gen_mask) { \ |
| 314 | if (l->gen_mask & (1 << (gen))) \ |
| 315 | c++; \ |
| 316 | l++; \ |
| 317 | } \ |
| 318 | if (c) { \ |
| 319 | p = drm_property_create(dev, DRM_MODE_PROP_ENUM, n, c); \ |
| 320 | l = (list); \ |
| 321 | c = 0; \ |
| 322 | while (p && l->gen_mask) { \ |
| 323 | if (l->gen_mask & (1 << (gen))) { \ |
| 324 | drm_property_add_enum(p, c, l->type, l->name); \ |
| 325 | c++; \ |
| 326 | } \ |
| 327 | l++; \ |
| 328 | } \ |
| 329 | } \ |
| 330 | } while(0) |
| 331 | |
Hans de Goede | 81280d0 | 2016-11-21 17:50:54 +0100 | [diff] [blame] | 332 | static void |
| 333 | nouveau_display_hpd_work(struct work_struct *work) |
| 334 | { |
| 335 | struct nouveau_drm *drm = container_of(work, typeof(*drm), hpd_work); |
| 336 | |
| 337 | pm_runtime_get_sync(drm->dev->dev); |
| 338 | |
| 339 | drm_helper_hpd_irq_event(drm->dev); |
| 340 | |
| 341 | pm_runtime_mark_last_busy(drm->dev->dev); |
| 342 | pm_runtime_put_sync(drm->dev->dev); |
| 343 | } |
| 344 | |
Hans de Goede | 3a6536c | 2016-11-09 18:17:44 +0100 | [diff] [blame] | 345 | #ifdef CONFIG_ACPI |
| 346 | |
| 347 | /* |
| 348 | * Hans de Goede: This define belongs in acpi/video.h, I've submitted a patch |
| 349 | * to the acpi subsys to move it there from drivers/acpi/acpi_video.c . |
| 350 | * This should be dropped once that is merged. |
| 351 | */ |
| 352 | #ifndef ACPI_VIDEO_NOTIFY_PROBE |
| 353 | #define ACPI_VIDEO_NOTIFY_PROBE 0x81 |
| 354 | #endif |
| 355 | |
Hans de Goede | 3a6536c | 2016-11-09 18:17:44 +0100 | [diff] [blame] | 356 | static int |
| 357 | nouveau_display_acpi_ntfy(struct notifier_block *nb, unsigned long val, |
| 358 | void *data) |
| 359 | { |
| 360 | struct nouveau_drm *drm = container_of(nb, typeof(*drm), acpi_nb); |
| 361 | struct acpi_bus_event *info = data; |
| 362 | |
| 363 | if (!strcmp(info->device_class, ACPI_VIDEO_CLASS)) { |
| 364 | if (info->type == ACPI_VIDEO_NOTIFY_PROBE) { |
| 365 | /* |
| 366 | * This may be the only indication we receive of a |
| 367 | * connector hotplug on a runtime suspended GPU, |
Hans de Goede | 81280d0 | 2016-11-21 17:50:54 +0100 | [diff] [blame] | 368 | * schedule hpd_work to check. |
Hans de Goede | 3a6536c | 2016-11-09 18:17:44 +0100 | [diff] [blame] | 369 | */ |
Hans de Goede | 81280d0 | 2016-11-21 17:50:54 +0100 | [diff] [blame] | 370 | schedule_work(&drm->hpd_work); |
Hans de Goede | 3a6536c | 2016-11-09 18:17:44 +0100 | [diff] [blame] | 371 | |
| 372 | /* acpi-video should not generate keypresses for this */ |
| 373 | return NOTIFY_BAD; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | return NOTIFY_DONE; |
| 378 | } |
| 379 | #endif |
| 380 | |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 381 | int |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 382 | nouveau_display_init(struct drm_device *dev) |
| 383 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 384 | struct nouveau_display *disp = nouveau_display(dev); |
Ben Skeggs | 898a2b3 | 2015-08-20 14:54:18 +1000 | [diff] [blame] | 385 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 386 | struct drm_connector *connector; |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 387 | int ret; |
| 388 | |
| 389 | ret = disp->init(dev); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 390 | if (ret) |
| 391 | return ret; |
| 392 | |
Ben Skeggs | 7df898b | 2012-01-31 09:16:59 +1000 | [diff] [blame] | 393 | /* enable polling for external displays */ |
Lyude Paul | cae9ff0 | 2017-01-11 21:25:23 -0500 | [diff] [blame] | 394 | if (!dev->mode_config.poll_enabled) |
| 395 | drm_kms_helper_poll_enable(dev); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 396 | |
| 397 | /* enable hotplug interrupts */ |
| 398 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 399 | struct nouveau_connector *conn = nouveau_connector(connector); |
Ben Skeggs | 80bc340 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 400 | nvif_notify_get(&conn->hpd); |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 401 | } |
| 402 | |
Ben Skeggs | 898a2b3 | 2015-08-20 14:54:18 +1000 | [diff] [blame] | 403 | /* enable flip completion events */ |
| 404 | nvif_notify_get(&drm->flip); |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 405 | return ret; |
| 406 | } |
| 407 | |
| 408 | void |
Ben Skeggs | 3b4c0ab | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 409 | nouveau_display_fini(struct drm_device *dev, bool suspend) |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 410 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 411 | struct nouveau_display *disp = nouveau_display(dev); |
Ben Skeggs | 898a2b3 | 2015-08-20 14:54:18 +1000 | [diff] [blame] | 412 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 413 | struct drm_connector *connector; |
Daniel Vetter | 9bc6db0d | 2016-11-15 22:58:19 +0100 | [diff] [blame] | 414 | struct drm_crtc *crtc; |
Mario Kleiner | 9cba5ef | 2014-07-29 02:36:44 +0200 | [diff] [blame] | 415 | |
Daniel Vetter | 18dddad | 2017-03-21 17:41:49 +0100 | [diff] [blame] | 416 | if (!suspend) { |
| 417 | if (drm_drv_uses_atomic_modeset(dev)) |
| 418 | drm_atomic_helper_shutdown(dev); |
| 419 | else |
| 420 | drm_crtc_force_disable_all(dev); |
| 421 | } |
Ben Skeggs | 3b4c0ab | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 422 | |
Mario Kleiner | 9cba5ef | 2014-07-29 02:36:44 +0200 | [diff] [blame] | 423 | /* Make sure that drm and hw vblank irqs get properly disabled. */ |
Daniel Vetter | 9bc6db0d | 2016-11-15 22:58:19 +0100 | [diff] [blame] | 424 | drm_for_each_crtc(crtc, dev) |
| 425 | drm_crtc_vblank_off(crtc); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 426 | |
Ben Skeggs | 898a2b3 | 2015-08-20 14:54:18 +1000 | [diff] [blame] | 427 | /* disable flip completion events */ |
| 428 | nvif_notify_put(&drm->flip); |
| 429 | |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 430 | /* disable hotplug interrupts */ |
| 431 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 432 | struct nouveau_connector *conn = nouveau_connector(connector); |
Ben Skeggs | 80bc340 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 433 | nvif_notify_put(&conn->hpd); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 434 | } |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 435 | |
| 436 | drm_kms_helper_poll_disable(dev); |
| 437 | disp->fini(dev); |
| 438 | } |
| 439 | |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 440 | static void |
| 441 | nouveau_display_create_properties(struct drm_device *dev) |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 442 | { |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 443 | struct nouveau_display *disp = nouveau_display(dev); |
| 444 | int gen; |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 445 | |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 446 | if (disp->disp.oclass < NV50_DISP) |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 447 | gen = 0; |
| 448 | else |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 449 | if (disp->disp.oclass < GF110_DISP) |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 450 | gen = 1; |
| 451 | else |
| 452 | gen = 2; |
| 453 | |
| 454 | PROP_ENUM(disp->dithering_mode, gen, "dithering mode", dither_mode); |
| 455 | PROP_ENUM(disp->dithering_depth, gen, "dithering depth", dither_depth); |
| 456 | PROP_ENUM(disp->underscan_property, gen, "underscan", underscan); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 457 | |
| 458 | disp->underscan_hborder_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 459 | drm_property_create_range(dev, 0, "underscan hborder", 0, 128); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 460 | |
| 461 | disp->underscan_vborder_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 462 | drm_property_create_range(dev, 0, "underscan vborder", 0, 128); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 463 | |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 464 | if (gen < 1) |
| 465 | return; |
Christoph Bumiller | df26bc9 | 2012-01-21 23:13:26 +0100 | [diff] [blame] | 466 | |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 467 | /* -90..+90 */ |
| 468 | disp->vibrant_hue_property = |
| 469 | drm_property_create_range(dev, 0, "vibrant hue", 0, 180); |
| 470 | |
| 471 | /* -100..+100 */ |
| 472 | disp->color_vibrance_property = |
| 473 | drm_property_create_range(dev, 0, "color vibrance", 0, 200); |
| 474 | } |
| 475 | |
| 476 | int |
| 477 | nouveau_display_create(struct drm_device *dev) |
| 478 | { |
| 479 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 480 | struct nvkm_device *device = nvxx_device(&drm->client.device); |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 481 | struct nouveau_display *disp; |
| 482 | int ret; |
| 483 | |
| 484 | disp = drm->display = kzalloc(sizeof(*disp), GFP_KERNEL); |
| 485 | if (!disp) |
| 486 | return -ENOMEM; |
| 487 | |
| 488 | drm_mode_config_init(dev); |
| 489 | drm_mode_create_scaling_mode_property(dev); |
| 490 | drm_mode_create_dvi_i_properties(dev); |
Christoph Bumiller | df26bc9 | 2012-01-21 23:13:26 +0100 | [diff] [blame] | 491 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 492 | dev->mode_config.funcs = &nouveau_mode_config_funcs; |
Ben Skeggs | 7e8820f | 2015-08-20 14:54:23 +1000 | [diff] [blame] | 493 | dev->mode_config.fb_base = device->func->resource_addr(device, 1); |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 494 | |
| 495 | dev->mode_config.min_width = 0; |
| 496 | dev->mode_config.min_height = 0; |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 497 | if (drm->client.device.info.family < NV_DEVICE_INFO_V0_CELSIUS) { |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 498 | dev->mode_config.max_width = 2048; |
| 499 | dev->mode_config.max_height = 2048; |
| 500 | } else |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 501 | if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 502 | dev->mode_config.max_width = 4096; |
| 503 | dev->mode_config.max_height = 4096; |
Ilia Mirkin | 5102ec3 | 2015-09-17 22:31:20 -0400 | [diff] [blame] | 504 | } else |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 505 | if (drm->client.device.info.family < NV_DEVICE_INFO_V0_FERMI) { |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 506 | dev->mode_config.max_width = 8192; |
| 507 | dev->mode_config.max_height = 8192; |
Ilia Mirkin | 5102ec3 | 2015-09-17 22:31:20 -0400 | [diff] [blame] | 508 | } else { |
| 509 | dev->mode_config.max_width = 16384; |
| 510 | dev->mode_config.max_height = 16384; |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 511 | } |
| 512 | |
Dave Airlie | f137799 | 2012-02-20 14:39:11 +0000 | [diff] [blame] | 513 | dev->mode_config.preferred_depth = 24; |
| 514 | dev->mode_config.prefer_shadow = 1; |
| 515 | |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 516 | if (drm->client.device.info.chipset < 0x11) |
Ben Skeggs | b9d9dcd | 2013-11-11 13:59:40 +1000 | [diff] [blame] | 517 | dev->mode_config.async_page_flip = false; |
| 518 | else |
| 519 | dev->mode_config.async_page_flip = true; |
| 520 | |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 521 | drm_kms_helper_poll_init(dev); |
| 522 | drm_kms_helper_poll_disable(dev); |
| 523 | |
Ben Skeggs | 771fa0e | 2014-08-10 04:10:31 +1000 | [diff] [blame] | 524 | if (nouveau_modeset != 2 && drm->vbios.dcb.entries) { |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 525 | static const u16 oclass[] = { |
Ben Skeggs | ed82866 | 2016-11-16 15:03:07 +1000 | [diff] [blame] | 526 | GP102_DISP, |
Ben Skeggs | f9d5cbb | 2016-07-09 10:41:01 +1000 | [diff] [blame] | 527 | GP100_DISP, |
Ben Skeggs | db1eb52 | 2016-02-11 08:35:32 +1000 | [diff] [blame] | 528 | GM200_DISP, |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 529 | GM107_DISP, |
| 530 | GK110_DISP, |
| 531 | GK104_DISP, |
| 532 | GF110_DISP, |
| 533 | GT214_DISP, |
| 534 | GT206_DISP, |
| 535 | GT200_DISP, |
| 536 | G82_DISP, |
| 537 | NV50_DISP, |
| 538 | NV04_DISP, |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 539 | }; |
| 540 | int i; |
| 541 | |
| 542 | for (i = 0, ret = -ENODEV; ret && i < ARRAY_SIZE(oclass); i++) { |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 543 | ret = nvif_object_init(&drm->client.device.object, 0, |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 544 | oclass[i], NULL, 0, &disp->disp); |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | if (ret == 0) { |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 548 | nouveau_display_create_properties(dev); |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 549 | if (disp->disp.oclass < NV50_DISP) |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 550 | ret = nv04_display_create(dev); |
| 551 | else |
| 552 | ret = nv50_display_create(dev); |
| 553 | } |
Ben Skeggs | fc16208 | 2013-09-10 13:20:34 +1000 | [diff] [blame] | 554 | } else { |
| 555 | ret = 0; |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 556 | } |
| 557 | |
Ben Skeggs | fc16208 | 2013-09-10 13:20:34 +1000 | [diff] [blame] | 558 | if (ret) |
| 559 | goto disp_create_err; |
| 560 | |
Ben Skeggs | 07193f7 | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 561 | drm_mode_config_reset(dev); |
| 562 | |
Ben Skeggs | fc16208 | 2013-09-10 13:20:34 +1000 | [diff] [blame] | 563 | if (dev->mode_config.num_crtc) { |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 564 | ret = nouveau_display_vblank_init(dev); |
Ben Skeggs | fc16208 | 2013-09-10 13:20:34 +1000 | [diff] [blame] | 565 | if (ret) |
| 566 | goto vblank_err; |
| 567 | } |
| 568 | |
| 569 | nouveau_backlight_init(dev); |
Hans de Goede | 81280d0 | 2016-11-21 17:50:54 +0100 | [diff] [blame] | 570 | INIT_WORK(&drm->hpd_work, nouveau_display_hpd_work); |
Hans de Goede | 3a6536c | 2016-11-09 18:17:44 +0100 | [diff] [blame] | 571 | #ifdef CONFIG_ACPI |
Hans de Goede | 3a6536c | 2016-11-09 18:17:44 +0100 | [diff] [blame] | 572 | drm->acpi_nb.notifier_call = nouveau_display_acpi_ntfy; |
| 573 | register_acpi_notifier(&drm->acpi_nb); |
| 574 | #endif |
| 575 | |
Marcin Slusarz | 5ace2c9 | 2012-04-15 14:36:08 +0200 | [diff] [blame] | 576 | return 0; |
| 577 | |
| 578 | vblank_err: |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 579 | disp->dtor(dev); |
Marcin Slusarz | 5ace2c9 | 2012-04-15 14:36:08 +0200 | [diff] [blame] | 580 | disp_create_err: |
| 581 | drm_kms_helper_poll_fini(dev); |
| 582 | drm_mode_config_cleanup(dev); |
Ben Skeggs | 2a44e49 | 2011-11-09 11:36:33 +1000 | [diff] [blame] | 583 | return ret; |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | void |
| 587 | nouveau_display_destroy(struct drm_device *dev) |
| 588 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 589 | struct nouveau_display *disp = nouveau_display(dev); |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 590 | |
Hans de Goede | 3a6536c | 2016-11-09 18:17:44 +0100 | [diff] [blame] | 591 | #ifdef CONFIG_ACPI |
| 592 | unregister_acpi_notifier(&nouveau_drm(dev)->acpi_nb); |
| 593 | #endif |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 594 | nouveau_backlight_exit(dev); |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 595 | nouveau_display_vblank_fini(dev); |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 596 | |
Ben Skeggs | d6bf2f3 | 2012-10-30 10:59:12 +1000 | [diff] [blame] | 597 | drm_kms_helper_poll_fini(dev); |
| 598 | drm_mode_config_cleanup(dev); |
| 599 | |
Ben Skeggs | 9430738 | 2012-10-31 12:11:15 +1000 | [diff] [blame] | 600 | if (disp->dtor) |
| 601 | disp->dtor(dev); |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 602 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 603 | nvif_object_fini(&disp->disp); |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 604 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 605 | nouveau_drm(dev)->display = NULL; |
| 606 | kfree(disp); |
| 607 | } |
| 608 | |
| 609 | int |
Ben Skeggs | 6fbb702 | 2014-10-02 13:22:27 +1000 | [diff] [blame] | 610 | nouveau_display_suspend(struct drm_device *dev, bool runtime) |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 611 | { |
Ben Skeggs | b167db0 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 612 | struct nouveau_display *disp = nouveau_display(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 613 | struct drm_crtc *crtc; |
| 614 | |
Dhinakaran Pandiyan | a743d75 | 2016-12-22 00:50:42 -0800 | [diff] [blame] | 615 | if (drm_drv_uses_atomic_modeset(dev)) { |
Ben Skeggs | b167db0 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 616 | if (!runtime) { |
Maarten Lankhorst | 9b2104f | 2017-02-21 14:51:40 +0100 | [diff] [blame] | 617 | disp->suspend = drm_atomic_helper_suspend(dev); |
Ben Skeggs | b167db0 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 618 | if (IS_ERR(disp->suspend)) { |
| 619 | int ret = PTR_ERR(disp->suspend); |
| 620 | disp->suspend = NULL; |
| 621 | return ret; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | nouveau_display_fini(dev, true); |
| 626 | return 0; |
| 627 | } |
| 628 | |
Ben Skeggs | 3b4c0ab | 2016-11-04 17:20:35 +1000 | [diff] [blame] | 629 | nouveau_display_fini(dev, true); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 630 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 631 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 632 | struct nouveau_framebuffer *nouveau_fb; |
| 633 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 634 | nouveau_fb = nouveau_framebuffer(crtc->primary->fb); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 635 | if (!nouveau_fb || !nouveau_fb->nvbo) |
| 636 | continue; |
| 637 | |
| 638 | nouveau_bo_unpin(nouveau_fb->nvbo); |
| 639 | } |
| 640 | |
| 641 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 642 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 643 | if (nv_crtc->cursor.nvbo) { |
Maarten Lankhorst | 4dc6393 | 2015-01-13 09:18:49 +0100 | [diff] [blame] | 644 | if (nv_crtc->cursor.set_offset) |
| 645 | nouveau_bo_unmap(nv_crtc->cursor.nvbo); |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 646 | nouveau_bo_unpin(nv_crtc->cursor.nvbo); |
| 647 | } |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | void |
Ben Skeggs | 6fbb702 | 2014-10-02 13:22:27 +1000 | [diff] [blame] | 654 | nouveau_display_resume(struct drm_device *dev, bool runtime) |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 655 | { |
Ben Skeggs | b167db0 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 656 | struct nouveau_display *disp = nouveau_display(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 657 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 658 | struct drm_crtc *crtc; |
Daniel Vetter | 9bc6db0d | 2016-11-15 22:58:19 +0100 | [diff] [blame] | 659 | int ret; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 660 | |
Dhinakaran Pandiyan | a743d75 | 2016-12-22 00:50:42 -0800 | [diff] [blame] | 661 | if (drm_drv_uses_atomic_modeset(dev)) { |
Ben Skeggs | b167db0 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 662 | nouveau_display_init(dev); |
| 663 | if (disp->suspend) { |
| 664 | drm_atomic_helper_resume(dev, disp->suspend); |
| 665 | disp->suspend = NULL; |
| 666 | } |
| 667 | return; |
| 668 | } |
| 669 | |
Ben Skeggs | 6fbb702 | 2014-10-02 13:22:27 +1000 | [diff] [blame] | 670 | /* re-pin fb/cursors */ |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 671 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 672 | struct nouveau_framebuffer *nouveau_fb; |
| 673 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 674 | nouveau_fb = nouveau_framebuffer(crtc->primary->fb); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 675 | if (!nouveau_fb || !nouveau_fb->nvbo) |
| 676 | continue; |
| 677 | |
Ben Skeggs | 547ad07 | 2014-11-10 12:35:06 +1000 | [diff] [blame] | 678 | ret = nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM, true); |
Ben Skeggs | c9a6fd9 | 2014-08-12 23:35:35 +1000 | [diff] [blame] | 679 | if (ret) |
| 680 | NV_ERROR(drm, "Could not pin framebuffer\n"); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 684 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 685 | if (!nv_crtc->cursor.nvbo) |
| 686 | continue; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 687 | |
Ben Skeggs | 547ad07 | 2014-11-10 12:35:06 +1000 | [diff] [blame] | 688 | ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM, true); |
Maarten Lankhorst | 4dc6393 | 2015-01-13 09:18:49 +0100 | [diff] [blame] | 689 | if (!ret && nv_crtc->cursor.set_offset) |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 690 | ret = nouveau_bo_map(nv_crtc->cursor.nvbo); |
| 691 | if (ret) |
| 692 | NV_ERROR(drm, "Could not pin/map cursor.\n"); |
| 693 | } |
Mario Kleiner | 9cba5ef | 2014-07-29 02:36:44 +0200 | [diff] [blame] | 694 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 695 | nouveau_display_init(dev); |
| 696 | |
| 697 | /* Force CLUT to get re-loaded during modeset */ |
| 698 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 699 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 700 | |
| 701 | nv_crtc->lut.depth = 0; |
| 702 | } |
| 703 | |
Ben Skeggs | 6fbb702 | 2014-10-02 13:22:27 +1000 | [diff] [blame] | 704 | /* This should ensure we don't hit a locking problem when someone |
| 705 | * wakes us up via a connector. We should never go into suspend |
| 706 | * while the display is on anyways. |
| 707 | */ |
| 708 | if (runtime) |
| 709 | return; |
| 710 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 711 | drm_helper_resume_force_mode(dev); |
| 712 | |
| 713 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 714 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 715 | |
Ben Skeggs | 5a56025 | 2014-11-10 15:52:02 +1000 | [diff] [blame] | 716 | if (!nv_crtc->cursor.nvbo) |
Ben Skeggs | 036a12b | 2014-11-03 14:33:01 +1000 | [diff] [blame] | 717 | continue; |
Maarten Lankhorst | 4dc6393 | 2015-01-13 09:18:49 +0100 | [diff] [blame] | 718 | |
| 719 | if (nv_crtc->cursor.set_offset) |
| 720 | nv_crtc->cursor.set_offset(nv_crtc, nv_crtc->cursor.nvbo->bo.offset); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 721 | nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x, |
| 722 | nv_crtc->cursor_saved_y); |
| 723 | } |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 724 | } |
| 725 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 726 | static int |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 727 | nouveau_page_flip_emit(struct nouveau_channel *chan, |
| 728 | struct nouveau_bo *old_bo, |
| 729 | struct nouveau_bo *new_bo, |
| 730 | struct nouveau_page_flip_state *s, |
| 731 | struct nouveau_fence **pfence) |
| 732 | { |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 733 | struct nouveau_fence_chan *fctx = chan->fence; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 734 | struct nouveau_drm *drm = chan->drm; |
| 735 | struct drm_device *dev = drm->dev; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 736 | unsigned long flags; |
| 737 | int ret; |
| 738 | |
| 739 | /* Queue it to the pending list */ |
| 740 | spin_lock_irqsave(&dev->event_lock, flags); |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 741 | list_add_tail(&s->head, &fctx->flip); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 742 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 743 | |
| 744 | /* Synchronize with the old framebuffer */ |
Maarten Lankhorst | e3be4c2 | 2014-09-16 11:15:07 +0200 | [diff] [blame] | 745 | ret = nouveau_fence_sync(old_bo, chan, false, false); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 746 | if (ret) |
| 747 | goto fail; |
| 748 | |
| 749 | /* Emit the pageflip */ |
Ben Skeggs | 1e303c0 | 2013-11-13 10:49:46 +1000 | [diff] [blame] | 750 | ret = RING_SPACE(chan, 2); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 751 | if (ret) |
| 752 | goto fail; |
| 753 | |
Ben Skeggs | e1ef6b4 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 754 | BEGIN_NV04(chan, NvSubSw, NV_SW_PAGE_FLIP, 1); |
Ben Skeggs | 1e303c0 | 2013-11-13 10:49:46 +1000 | [diff] [blame] | 755 | OUT_RING (chan, 0x00000000); |
Ben Skeggs | bd2f203 | 2011-02-08 15:16:23 +1000 | [diff] [blame] | 756 | FIRE_RING (chan); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 757 | |
Ben Skeggs | 264ce19 | 2013-02-14 13:43:21 +1000 | [diff] [blame] | 758 | ret = nouveau_fence_new(chan, false, pfence); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 759 | if (ret) |
| 760 | goto fail; |
| 761 | |
| 762 | return 0; |
| 763 | fail: |
| 764 | spin_lock_irqsave(&dev->event_lock, flags); |
| 765 | list_del(&s->head); |
| 766 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 767 | return ret; |
| 768 | } |
| 769 | |
| 770 | int |
| 771 | nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
Daniel Vetter | 41292b1f | 2017-03-22 22:50:50 +0100 | [diff] [blame] | 772 | struct drm_pending_vblank_event *event, u32 flags, |
| 773 | struct drm_modeset_acquire_ctx *ctx) |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 774 | { |
Ben Skeggs | b9d9dcd | 2013-11-11 13:59:40 +1000 | [diff] [blame] | 775 | const int swap_interval = (flags & DRM_MODE_PAGE_FLIP_ASYNC) ? 0 : 1; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 776 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 777 | struct nouveau_drm *drm = nouveau_drm(dev); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 778 | struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->primary->fb)->nvbo; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 779 | struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo; |
| 780 | struct nouveau_page_flip_state *s; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 781 | struct nouveau_channel *chan; |
| 782 | struct nouveau_cli *cli; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 783 | struct nouveau_fence *fence; |
Ben Skeggs | e1ef6b4 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 784 | struct nv04_display *dispnv04 = nv04_display(dev); |
| 785 | int head = nouveau_crtc(crtc)->index; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 786 | int ret; |
| 787 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 788 | chan = drm->channel; |
| 789 | if (!chan) |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 790 | return -ENODEV; |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 791 | cli = (void *)chan->user.client; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 792 | |
| 793 | s = kzalloc(sizeof(*s), GFP_KERNEL); |
| 794 | if (!s) |
| 795 | return -ENOMEM; |
| 796 | |
Maarten Lankhorst | d5c1e84 | 2014-01-14 16:48:58 +0100 | [diff] [blame] | 797 | if (new_bo != old_bo) { |
Ben Skeggs | 547ad07 | 2014-11-10 12:35:06 +1000 | [diff] [blame] | 798 | ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM, true); |
Maarten Lankhorst | d5c1e84 | 2014-01-14 16:48:58 +0100 | [diff] [blame] | 799 | if (ret) |
| 800 | goto fail_free; |
| 801 | } |
| 802 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 803 | mutex_lock(&cli->mutex); |
Christian König | dfd5e50 | 2016-04-06 11:12:03 +0200 | [diff] [blame] | 804 | ret = ttm_bo_reserve(&new_bo->bo, true, false, NULL); |
Maarten Lankhorst | bdaf7dd | 2014-01-21 13:02:14 +0100 | [diff] [blame] | 805 | if (ret) |
| 806 | goto fail_unpin; |
Maarten Lankhorst | d5c1e84 | 2014-01-14 16:48:58 +0100 | [diff] [blame] | 807 | |
Ben Skeggs | eae389f | 2013-11-13 10:17:17 +1000 | [diff] [blame] | 808 | /* synchronise rendering channel with the kernel's channel */ |
Maarten Lankhorst | e3be4c2 | 2014-09-16 11:15:07 +0200 | [diff] [blame] | 809 | ret = nouveau_fence_sync(new_bo, chan, false, true); |
Maarten Lankhorst | bdaf7dd | 2014-01-21 13:02:14 +0100 | [diff] [blame] | 810 | if (ret) { |
| 811 | ttm_bo_unreserve(&new_bo->bo); |
Maarten Lankhorst | 09c3de1 | 2014-01-29 11:05:09 +0100 | [diff] [blame] | 812 | goto fail_unpin; |
Maarten Lankhorst | bdaf7dd | 2014-01-21 13:02:14 +0100 | [diff] [blame] | 813 | } |
Maarten Lankhorst | b580c9e | 2013-06-27 13:48:18 +0200 | [diff] [blame] | 814 | |
Maarten Lankhorst | bdaf7dd | 2014-01-21 13:02:14 +0100 | [diff] [blame] | 815 | if (new_bo != old_bo) { |
| 816 | ttm_bo_unreserve(&new_bo->bo); |
| 817 | |
Christian König | dfd5e50 | 2016-04-06 11:12:03 +0200 | [diff] [blame] | 818 | ret = ttm_bo_reserve(&old_bo->bo, true, false, NULL); |
Maarten Lankhorst | bdaf7dd | 2014-01-21 13:02:14 +0100 | [diff] [blame] | 819 | if (ret) |
| 820 | goto fail_unpin; |
| 821 | } |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 822 | |
| 823 | /* Initialize a page flip struct */ |
| 824 | *s = (struct nouveau_page_flip_state) |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 825 | { { }, event, crtc, fb->format->cpp[0] * 8, fb->pitches[0], |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 826 | new_bo->bo.offset }; |
| 827 | |
Mario Kleiner | ba124a41 | 2014-06-11 09:51:23 +0200 | [diff] [blame] | 828 | /* Keep vblanks on during flip, for the target crtc of this flip */ |
Gustavo Padovan | dc4ff11 | 2016-06-07 11:07:53 -0300 | [diff] [blame] | 829 | drm_crtc_vblank_get(crtc); |
Mario Kleiner | ba124a41 | 2014-06-11 09:51:23 +0200 | [diff] [blame] | 830 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 831 | /* Emit a page flip */ |
Ben Skeggs | e1ef6b4 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 832 | if (swap_interval) { |
| 833 | ret = RING_SPACE(chan, 8); |
Ben Skeggs | 060810d | 2013-07-08 14:15:51 +1000 | [diff] [blame] | 834 | if (ret) |
Ben Skeggs | d7117e0 | 2011-02-07 14:27:04 +1000 | [diff] [blame] | 835 | goto fail_unreserve; |
Ben Skeggs | b9d9dcd | 2013-11-11 13:59:40 +1000 | [diff] [blame] | 836 | |
Ben Skeggs | e1ef6b4 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 837 | BEGIN_NV04(chan, NvSubImageBlit, 0x012c, 1); |
| 838 | OUT_RING (chan, 0); |
| 839 | BEGIN_NV04(chan, NvSubImageBlit, 0x0134, 1); |
| 840 | OUT_RING (chan, head); |
| 841 | BEGIN_NV04(chan, NvSubImageBlit, 0x0100, 1); |
| 842 | OUT_RING (chan, 0); |
| 843 | BEGIN_NV04(chan, NvSubImageBlit, 0x0130, 1); |
| 844 | OUT_RING (chan, 0); |
Ben Skeggs | d7117e0 | 2011-02-07 14:27:04 +1000 | [diff] [blame] | 845 | } |
| 846 | |
Ben Skeggs | e1ef6b4 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 847 | nouveau_bo_ref(new_bo, &dispnv04->image[head]); |
| 848 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 849 | ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 850 | if (ret) |
| 851 | goto fail_unreserve; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 852 | mutex_unlock(&cli->mutex); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 853 | |
| 854 | /* Update the crtc struct and cleanup */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 855 | crtc->primary->fb = fb; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 856 | |
Maarten Lankhorst | 809e944 | 2014-04-09 16:19:30 +0200 | [diff] [blame] | 857 | nouveau_bo_fence(old_bo, fence, false); |
Ben Skeggs | 07ad6ca | 2013-11-13 10:00:32 +1000 | [diff] [blame] | 858 | ttm_bo_unreserve(&old_bo->bo); |
Ben Skeggs | 060810d | 2013-07-08 14:15:51 +1000 | [diff] [blame] | 859 | if (old_bo != new_bo) |
Maarten Lankhorst | b580c9e | 2013-06-27 13:48:18 +0200 | [diff] [blame] | 860 | nouveau_bo_unpin(old_bo); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 861 | nouveau_fence_unref(&fence); |
| 862 | return 0; |
| 863 | |
| 864 | fail_unreserve: |
Gustavo Padovan | dc4ff11 | 2016-06-07 11:07:53 -0300 | [diff] [blame] | 865 | drm_crtc_vblank_put(crtc); |
Ben Skeggs | 07ad6ca | 2013-11-13 10:00:32 +1000 | [diff] [blame] | 866 | ttm_bo_unreserve(&old_bo->bo); |
Ben Skeggs | 060810d | 2013-07-08 14:15:51 +1000 | [diff] [blame] | 867 | fail_unpin: |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 868 | mutex_unlock(&cli->mutex); |
Ben Skeggs | 060810d | 2013-07-08 14:15:51 +1000 | [diff] [blame] | 869 | if (old_bo != new_bo) |
Maarten Lankhorst | b580c9e | 2013-06-27 13:48:18 +0200 | [diff] [blame] | 870 | nouveau_bo_unpin(new_bo); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 871 | fail_free: |
| 872 | kfree(s); |
| 873 | return ret; |
| 874 | } |
| 875 | |
| 876 | int |
| 877 | nouveau_finish_page_flip(struct nouveau_channel *chan, |
| 878 | struct nouveau_page_flip_state *ps) |
| 879 | { |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 880 | struct nouveau_fence_chan *fctx = chan->fence; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 881 | struct nouveau_drm *drm = chan->drm; |
| 882 | struct drm_device *dev = drm->dev; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 883 | struct nouveau_page_flip_state *s; |
| 884 | unsigned long flags; |
| 885 | |
| 886 | spin_lock_irqsave(&dev->event_lock, flags); |
| 887 | |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 888 | if (list_empty(&fctx->flip)) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 889 | NV_ERROR(drm, "unexpected pageflip\n"); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 890 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 891 | return -EINVAL; |
| 892 | } |
| 893 | |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 894 | s = list_first_entry(&fctx->flip, struct nouveau_page_flip_state, head); |
Mario Kleiner | af4870e | 2014-05-13 00:42:08 +0200 | [diff] [blame] | 895 | if (s->event) { |
Ben Skeggs | e1ef6b4 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 896 | drm_crtc_arm_vblank_event(s->crtc, s->event); |
| 897 | } else { |
Daniel Vetter | bbc8764 | 2015-11-10 17:37:31 +0100 | [diff] [blame] | 898 | /* Give up ownership of vblank for page-flipped crtc */ |
Gustavo Padovan | dc4ff11 | 2016-06-07 11:07:53 -0300 | [diff] [blame] | 899 | drm_crtc_vblank_put(s->crtc); |
Daniel Vetter | bbc8764 | 2015-11-10 17:37:31 +0100 | [diff] [blame] | 900 | } |
Mario Kleiner | ba124a41 | 2014-06-11 09:51:23 +0200 | [diff] [blame] | 901 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 902 | list_del(&s->head); |
Ben Skeggs | d7117e0 | 2011-02-07 14:27:04 +1000 | [diff] [blame] | 903 | if (ps) |
| 904 | *ps = *s; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 905 | kfree(s); |
| 906 | |
| 907 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 908 | return 0; |
| 909 | } |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 910 | |
| 911 | int |
Ben Skeggs | 898a2b3 | 2015-08-20 14:54:18 +1000 | [diff] [blame] | 912 | nouveau_flip_complete(struct nvif_notify *notify) |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 913 | { |
Ben Skeggs | 898a2b3 | 2015-08-20 14:54:18 +1000 | [diff] [blame] | 914 | struct nouveau_drm *drm = container_of(notify, typeof(*drm), flip); |
| 915 | struct nouveau_channel *chan = drm->channel; |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 916 | struct nouveau_page_flip_state state; |
| 917 | |
| 918 | if (!nouveau_finish_page_flip(chan, &state)) { |
Ben Skeggs | e1ef6b4 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 919 | nv_set_crtc_base(drm->dev, drm_crtc_index(state.crtc), |
| 920 | state.offset + state.crtc->y * |
| 921 | state.pitch + state.crtc->x * |
| 922 | state.bpp / 8); |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 923 | } |
| 924 | |
Ben Skeggs | 898a2b3 | 2015-08-20 14:54:18 +1000 | [diff] [blame] | 925 | return NVIF_NOTIFY_KEEP; |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | int |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 929 | nouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev, |
| 930 | struct drm_mode_create_dumb *args) |
| 931 | { |
Ben Skeggs | fc1b0a0 | 2016-05-24 17:29:55 +1000 | [diff] [blame] | 932 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 933 | struct nouveau_bo *bo; |
Alexandre Courbot | eaecf03 | 2015-02-20 18:22:59 +0900 | [diff] [blame] | 934 | uint32_t domain; |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 935 | int ret; |
| 936 | |
| 937 | args->pitch = roundup(args->width * (args->bpp / 8), 256); |
| 938 | args->size = args->pitch * args->height; |
| 939 | args->size = roundup(args->size, PAGE_SIZE); |
| 940 | |
Alexandre Courbot | eaecf03 | 2015-02-20 18:22:59 +0900 | [diff] [blame] | 941 | /* Use VRAM if there is any ; otherwise fallback to system memory */ |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 942 | if (nouveau_drm(dev)->client.device.info.ram_size != 0) |
Alexandre Courbot | eaecf03 | 2015-02-20 18:22:59 +0900 | [diff] [blame] | 943 | domain = NOUVEAU_GEM_DOMAIN_VRAM; |
| 944 | else |
| 945 | domain = NOUVEAU_GEM_DOMAIN_GART; |
| 946 | |
Ben Skeggs | fc1b0a0 | 2016-05-24 17:29:55 +1000 | [diff] [blame] | 947 | ret = nouveau_gem_new(cli, args->size, 0, domain, 0, 0, &bo); |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 948 | if (ret) |
| 949 | return ret; |
| 950 | |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 951 | ret = drm_gem_handle_create(file_priv, &bo->gem, &args->handle); |
| 952 | drm_gem_object_unreference_unlocked(&bo->gem); |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 953 | return ret; |
| 954 | } |
| 955 | |
| 956 | int |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 957 | nouveau_display_dumb_map_offset(struct drm_file *file_priv, |
| 958 | struct drm_device *dev, |
| 959 | uint32_t handle, uint64_t *poffset) |
| 960 | { |
| 961 | struct drm_gem_object *gem; |
| 962 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 963 | gem = drm_gem_object_lookup(file_priv, handle); |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 964 | if (gem) { |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 965 | struct nouveau_bo *bo = nouveau_gem_object(gem); |
David Herrmann | 72525b3 | 2013-07-24 21:08:53 +0200 | [diff] [blame] | 966 | *poffset = drm_vma_node_offset_addr(&bo->bo.vma_node); |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 967 | drm_gem_object_unreference_unlocked(gem); |
| 968 | return 0; |
| 969 | } |
| 970 | |
| 971 | return -ENOENT; |
| 972 | } |