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 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 27 | #include <drm/drmP.h> |
| 28 | #include <drm/drm_crtc_helper.h> |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 29 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 30 | #include "nouveau_fbcon.h" |
Ben Skeggs | 1a64634 | 2013-03-21 15:45:11 +1000 | [diff] [blame] | 31 | #include "dispnv04/hw.h" |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 32 | #include "nouveau_crtc.h" |
| 33 | #include "nouveau_dma.h" |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 34 | #include "nouveau_gem.h" |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 35 | #include "nouveau_connector.h" |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 36 | #include "nv50_display.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 37 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 38 | #include "nouveau_fence.h" |
| 39 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 40 | #include <engine/disp.h> |
Ben Skeggs | e0996ae | 2012-07-10 12:20:17 +1000 | [diff] [blame] | 41 | |
Ben Skeggs | 1d7c71a | 2013-01-31 09:23:34 +1000 | [diff] [blame] | 42 | #include <core/class.h> |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 43 | #include <nvif/event.h> |
Ben Skeggs | 1d7c71a | 2013-01-31 09:23:34 +1000 | [diff] [blame] | 44 | |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 45 | static int |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 46 | nouveau_display_vblank_handler(struct nvkm_notify *notify) |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 47 | { |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 48 | struct nouveau_crtc *nv_crtc = |
| 49 | container_of(notify, typeof(*nv_crtc), vblank); |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 50 | drm_handle_vblank(nv_crtc->base.dev, nv_crtc->index); |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 51 | return NVKM_NOTIFY_KEEP; |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | int |
| 55 | nouveau_display_vblank_enable(struct drm_device *dev, int head) |
| 56 | { |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 57 | struct drm_crtc *crtc; |
| 58 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 59 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 60 | if (nv_crtc->index == head) { |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 61 | nvkm_notify_get(&nv_crtc->vblank); |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 62 | return 0; |
| 63 | } |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 64 | } |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 65 | return -EINVAL; |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void |
| 69 | nouveau_display_vblank_disable(struct drm_device *dev, int head) |
| 70 | { |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 71 | struct drm_crtc *crtc; |
| 72 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 73 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 74 | if (nv_crtc->index == head) { |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 75 | nvkm_notify_put(&nv_crtc->vblank); |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 76 | return; |
| 77 | } |
| 78 | } |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 79 | } |
| 80 | |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 81 | static inline int |
| 82 | calc(int blanks, int blanke, int total, int line) |
| 83 | { |
| 84 | if (blanke >= blanks) { |
| 85 | if (line >= blanks) |
| 86 | line -= total; |
| 87 | } else { |
| 88 | if (line >= blanks) |
| 89 | line -= total; |
| 90 | line -= blanke + 1; |
| 91 | } |
| 92 | return line; |
| 93 | } |
| 94 | |
| 95 | int |
| 96 | nouveau_display_scanoutpos_head(struct drm_crtc *crtc, int *vpos, int *hpos, |
| 97 | ktime_t *stime, ktime_t *etime) |
| 98 | { |
| 99 | const u32 mthd = NV04_DISP_SCANOUTPOS + nouveau_crtc(crtc)->index; |
| 100 | struct nouveau_display *disp = nouveau_display(crtc->dev); |
| 101 | struct nv04_display_scanoutpos args; |
| 102 | int ret, retry = 1; |
| 103 | |
| 104 | do { |
| 105 | ret = nv_exec(disp->core, mthd, &args, sizeof(args)); |
| 106 | if (ret != 0) |
| 107 | return 0; |
| 108 | |
| 109 | if (args.vline) { |
| 110 | ret |= DRM_SCANOUTPOS_ACCURATE; |
| 111 | ret |= DRM_SCANOUTPOS_VALID; |
| 112 | break; |
| 113 | } |
| 114 | |
| 115 | if (retry) ndelay(crtc->linedur_ns); |
| 116 | } while (retry--); |
| 117 | |
Mario Kleiner | 6c3252b | 2014-03-19 10:02:11 +0100 | [diff] [blame] | 118 | *hpos = args.hline; |
Ben Skeggs | d83ef85 | 2013-11-14 13:37:49 +1000 | [diff] [blame] | 119 | *vpos = calc(args.vblanks, args.vblanke, args.vtotal, args.vline); |
| 120 | if (stime) *stime = ns_to_ktime(args.time[0]); |
| 121 | if (etime) *etime = ns_to_ktime(args.time[1]); |
| 122 | |
| 123 | if (*vpos < 0) |
| 124 | ret |= DRM_SCANOUTPOS_INVBL; |
| 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | int |
| 129 | nouveau_display_scanoutpos(struct drm_device *dev, int head, unsigned int flags, |
| 130 | int *vpos, int *hpos, ktime_t *stime, ktime_t *etime) |
| 131 | { |
| 132 | struct drm_crtc *crtc; |
| 133 | |
| 134 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 135 | if (nouveau_crtc(crtc)->index == head) { |
| 136 | return nouveau_display_scanoutpos_head(crtc, vpos, hpos, |
| 137 | stime, etime); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | int |
| 145 | nouveau_display_vblstamp(struct drm_device *dev, int head, int *max_error, |
| 146 | struct timeval *time, unsigned flags) |
| 147 | { |
| 148 | struct drm_crtc *crtc; |
| 149 | |
| 150 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 151 | if (nouveau_crtc(crtc)->index == head) { |
| 152 | return drm_calc_vbltimestamp_from_scanoutpos(dev, |
| 153 | head, max_error, time, flags, crtc, |
| 154 | &crtc->hwmode); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return -EINVAL; |
| 159 | } |
| 160 | |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 161 | static void |
| 162 | nouveau_display_vblank_fini(struct drm_device *dev) |
| 163 | { |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 164 | struct drm_crtc *crtc; |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 165 | |
Ben Skeggs | 1139ffb | 2014-01-23 10:49:47 +1000 | [diff] [blame] | 166 | drm_vblank_cleanup(dev); |
| 167 | |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 168 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 169 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 170 | nvkm_notify_fini(&nv_crtc->vblank); |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 171 | } |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static int |
| 175 | nouveau_display_vblank_init(struct drm_device *dev) |
| 176 | { |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 177 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 178 | struct nouveau_disp *pdisp = nouveau_disp(drm->device); |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 179 | struct drm_crtc *crtc; |
| 180 | int ret; |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 181 | |
Ben Skeggs | b12f0ae | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 182 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 183 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 184 | ret = nvkm_notify_init(&pdisp->vblank, |
| 185 | nouveau_display_vblank_handler, false, |
| 186 | &(struct nvif_notify_head_req_v0) { |
| 187 | .head = nv_crtc->index, |
| 188 | }, |
| 189 | sizeof(struct nvif_notify_head_req_v0), |
| 190 | sizeof(struct nvif_notify_head_rep_v0), |
| 191 | &nv_crtc->vblank); |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 192 | if (ret) { |
| 193 | nouveau_display_vblank_fini(dev); |
| 194 | return ret; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | ret = drm_vblank_init(dev, dev->mode_config.num_crtc); |
| 199 | if (ret) { |
| 200 | nouveau_display_vblank_fini(dev); |
| 201 | return ret; |
| 202 | } |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 207 | static void |
| 208 | nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb) |
| 209 | { |
| 210 | struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 211 | struct nouveau_display *disp = nouveau_display(drm_fb->dev); |
| 212 | |
| 213 | if (disp->fb_dtor) |
| 214 | disp->fb_dtor(drm_fb); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 215 | |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 216 | if (fb->nvbo) |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 217 | drm_gem_object_unreference_unlocked(&fb->nvbo->gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 218 | |
| 219 | drm_framebuffer_cleanup(drm_fb); |
| 220 | kfree(fb); |
| 221 | } |
| 222 | |
| 223 | static int |
| 224 | nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb, |
| 225 | struct drm_file *file_priv, |
| 226 | unsigned int *handle) |
| 227 | { |
| 228 | struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); |
| 229 | |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 230 | return drm_gem_handle_create(file_priv, &fb->nvbo->gem, handle); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = { |
| 234 | .destroy = nouveau_user_framebuffer_destroy, |
| 235 | .create_handle = nouveau_user_framebuffer_create_handle, |
| 236 | }; |
| 237 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 238 | int |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 239 | nouveau_framebuffer_init(struct drm_device *dev, |
| 240 | struct nouveau_framebuffer *nv_fb, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 241 | struct drm_mode_fb_cmd2 *mode_cmd, |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 242 | struct nouveau_bo *nvbo) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 243 | { |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 244 | struct nouveau_display *disp = nouveau_display(dev); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 245 | struct drm_framebuffer *fb = &nv_fb->base; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 246 | int ret; |
| 247 | |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 248 | drm_helper_mode_fill_fb_struct(fb, mode_cmd); |
| 249 | nv_fb->nvbo = nvbo; |
| 250 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 251 | ret = drm_framebuffer_init(dev, fb, &nouveau_framebuffer_funcs); |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 252 | if (ret) |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 253 | return ret; |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 254 | |
| 255 | if (disp->fb_ctor) { |
| 256 | ret = disp->fb_ctor(fb); |
| 257 | if (ret) |
| 258 | disp->fb_dtor(fb); |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 261 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | static struct drm_framebuffer * |
| 265 | nouveau_user_framebuffer_create(struct drm_device *dev, |
| 266 | struct drm_file *file_priv, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 267 | struct drm_mode_fb_cmd2 *mode_cmd) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 268 | { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 269 | struct nouveau_framebuffer *nouveau_fb; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 270 | struct drm_gem_object *gem; |
Maarten Lankhorst | fdfb833 | 2013-07-08 14:50:54 +1000 | [diff] [blame] | 271 | int ret = -ENOMEM; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 272 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 273 | gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 274 | if (!gem) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 275 | return ERR_PTR(-ENOENT); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 276 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 277 | nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL); |
| 278 | if (!nouveau_fb) |
Maarten Lankhorst | fdfb833 | 2013-07-08 14:50:54 +1000 | [diff] [blame] | 279 | goto err_unref; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 280 | |
| 281 | ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem)); |
Maarten Lankhorst | fdfb833 | 2013-07-08 14:50:54 +1000 | [diff] [blame] | 282 | if (ret) |
| 283 | goto err; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 284 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 285 | return &nouveau_fb->base; |
Maarten Lankhorst | fdfb833 | 2013-07-08 14:50:54 +1000 | [diff] [blame] | 286 | |
| 287 | err: |
| 288 | kfree(nouveau_fb); |
| 289 | err_unref: |
| 290 | drm_gem_object_unreference(gem); |
| 291 | return ERR_PTR(ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 292 | } |
| 293 | |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 294 | static const struct drm_mode_config_funcs nouveau_mode_config_funcs = { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 295 | .fb_create = nouveau_user_framebuffer_create, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 296 | .output_poll_changed = nouveau_fbcon_output_poll_changed, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 297 | }; |
| 298 | |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 299 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 300 | struct nouveau_drm_prop_enum_list { |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 301 | u8 gen_mask; |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 302 | int type; |
| 303 | char *name; |
| 304 | }; |
| 305 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 306 | static struct nouveau_drm_prop_enum_list underscan[] = { |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 307 | { 6, UNDERSCAN_AUTO, "auto" }, |
| 308 | { 6, UNDERSCAN_OFF, "off" }, |
| 309 | { 6, UNDERSCAN_ON, "on" }, |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 310 | {} |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 311 | }; |
| 312 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 313 | static struct nouveau_drm_prop_enum_list dither_mode[] = { |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 314 | { 7, DITHERING_MODE_AUTO, "auto" }, |
| 315 | { 7, DITHERING_MODE_OFF, "off" }, |
| 316 | { 1, DITHERING_MODE_ON, "on" }, |
| 317 | { 6, DITHERING_MODE_STATIC2X2, "static 2x2" }, |
| 318 | { 6, DITHERING_MODE_DYNAMIC2X2, "dynamic 2x2" }, |
| 319 | { 4, DITHERING_MODE_TEMPORAL, "temporal" }, |
| 320 | {} |
| 321 | }; |
| 322 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 323 | static struct nouveau_drm_prop_enum_list dither_depth[] = { |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 324 | { 6, DITHERING_DEPTH_AUTO, "auto" }, |
| 325 | { 6, DITHERING_DEPTH_6BPC, "6 bpc" }, |
| 326 | { 6, DITHERING_DEPTH_8BPC, "8 bpc" }, |
| 327 | {} |
| 328 | }; |
| 329 | |
| 330 | #define PROP_ENUM(p,gen,n,list) do { \ |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 331 | struct nouveau_drm_prop_enum_list *l = (list); \ |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 332 | int c = 0; \ |
| 333 | while (l->gen_mask) { \ |
| 334 | if (l->gen_mask & (1 << (gen))) \ |
| 335 | c++; \ |
| 336 | l++; \ |
| 337 | } \ |
| 338 | if (c) { \ |
| 339 | p = drm_property_create(dev, DRM_MODE_PROP_ENUM, n, c); \ |
| 340 | l = (list); \ |
| 341 | c = 0; \ |
| 342 | while (p && l->gen_mask) { \ |
| 343 | if (l->gen_mask & (1 << (gen))) { \ |
| 344 | drm_property_add_enum(p, c, l->type, l->name); \ |
| 345 | c++; \ |
| 346 | } \ |
| 347 | l++; \ |
| 348 | } \ |
| 349 | } \ |
| 350 | } while(0) |
| 351 | |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 352 | int |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 353 | nouveau_display_init(struct drm_device *dev) |
| 354 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 355 | struct nouveau_display *disp = nouveau_display(dev); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 356 | struct drm_connector *connector; |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 357 | int ret; |
| 358 | |
| 359 | ret = disp->init(dev); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 360 | if (ret) |
| 361 | return ret; |
| 362 | |
Ben Skeggs | 7df898b | 2012-01-31 09:16:59 +1000 | [diff] [blame] | 363 | /* enable polling for external displays */ |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 364 | drm_kms_helper_poll_enable(dev); |
| 365 | |
| 366 | /* enable hotplug interrupts */ |
| 367 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 368 | struct nouveau_connector *conn = nouveau_connector(connector); |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 369 | nvkm_notify_get(&conn->hpd); |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | return ret; |
| 373 | } |
| 374 | |
| 375 | void |
| 376 | nouveau_display_fini(struct drm_device *dev) |
| 377 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 378 | struct nouveau_display *disp = nouveau_display(dev); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 379 | struct drm_connector *connector; |
Mario Kleiner | 9cba5ef | 2014-07-29 02:36:44 +0200 | [diff] [blame] | 380 | int head; |
| 381 | |
| 382 | /* Make sure that drm and hw vblank irqs get properly disabled. */ |
| 383 | for (head = 0; head < dev->mode_config.num_crtc; head++) |
| 384 | drm_vblank_off(dev, head); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 385 | |
| 386 | /* disable hotplug interrupts */ |
| 387 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 388 | struct nouveau_connector *conn = nouveau_connector(connector); |
Ben Skeggs | 79ca277 | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 389 | nvkm_notify_put(&conn->hpd); |
Ben Skeggs | 52c4d76 | 2011-11-24 12:59:44 +1000 | [diff] [blame] | 390 | } |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 391 | |
| 392 | drm_kms_helper_poll_disable(dev); |
| 393 | disp->fini(dev); |
| 394 | } |
| 395 | |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame^] | 396 | static void |
| 397 | nouveau_display_create_properties(struct drm_device *dev) |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 398 | { |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame^] | 399 | struct nouveau_display *disp = nouveau_display(dev); |
| 400 | int gen; |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 401 | |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame^] | 402 | if (nv_mclass(disp->core) < NV50_DISP_CLASS) |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 403 | gen = 0; |
| 404 | else |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame^] | 405 | if (nv_mclass(disp->core) < NVD0_DISP_CLASS) |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 406 | gen = 1; |
| 407 | else |
| 408 | gen = 2; |
| 409 | |
| 410 | PROP_ENUM(disp->dithering_mode, gen, "dithering mode", dither_mode); |
| 411 | PROP_ENUM(disp->dithering_depth, gen, "dithering depth", dither_depth); |
| 412 | PROP_ENUM(disp->underscan_property, gen, "underscan", underscan); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 413 | |
| 414 | disp->underscan_hborder_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 415 | drm_property_create_range(dev, 0, "underscan hborder", 0, 128); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 416 | |
| 417 | disp->underscan_vborder_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 418 | drm_property_create_range(dev, 0, "underscan vborder", 0, 128); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 419 | |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame^] | 420 | if (gen < 1) |
| 421 | return; |
Christoph Bumiller | df26bc9 | 2012-01-21 23:13:26 +0100 | [diff] [blame] | 422 | |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame^] | 423 | /* -90..+90 */ |
| 424 | disp->vibrant_hue_property = |
| 425 | drm_property_create_range(dev, 0, "vibrant hue", 0, 180); |
| 426 | |
| 427 | /* -100..+100 */ |
| 428 | disp->color_vibrance_property = |
| 429 | drm_property_create_range(dev, 0, "color vibrance", 0, 200); |
| 430 | } |
| 431 | |
| 432 | int |
| 433 | nouveau_display_create(struct drm_device *dev) |
| 434 | { |
| 435 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 436 | struct nouveau_device *device = nouveau_dev(dev); |
| 437 | struct nouveau_display *disp; |
| 438 | int ret; |
| 439 | |
| 440 | disp = drm->display = kzalloc(sizeof(*disp), GFP_KERNEL); |
| 441 | if (!disp) |
| 442 | return -ENOMEM; |
| 443 | |
| 444 | drm_mode_config_init(dev); |
| 445 | drm_mode_create_scaling_mode_property(dev); |
| 446 | drm_mode_create_dvi_i_properties(dev); |
Christoph Bumiller | df26bc9 | 2012-01-21 23:13:26 +0100 | [diff] [blame] | 447 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 448 | dev->mode_config.funcs = &nouveau_mode_config_funcs; |
Alexandre Courbot | 420b946 | 2014-02-17 15:17:26 +0900 | [diff] [blame] | 449 | dev->mode_config.fb_base = nv_device_resource_start(device, 1); |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 450 | |
| 451 | dev->mode_config.min_width = 0; |
| 452 | dev->mode_config.min_height = 0; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 453 | if (nv_device(drm->device)->card_type < NV_10) { |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 454 | dev->mode_config.max_width = 2048; |
| 455 | dev->mode_config.max_height = 2048; |
| 456 | } else |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 457 | if (nv_device(drm->device)->card_type < NV_50) { |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 458 | dev->mode_config.max_width = 4096; |
| 459 | dev->mode_config.max_height = 4096; |
| 460 | } else { |
| 461 | dev->mode_config.max_width = 8192; |
| 462 | dev->mode_config.max_height = 8192; |
| 463 | } |
| 464 | |
Dave Airlie | f137799 | 2012-02-20 14:39:11 +0000 | [diff] [blame] | 465 | dev->mode_config.preferred_depth = 24; |
| 466 | dev->mode_config.prefer_shadow = 1; |
| 467 | |
Ben Skeggs | b9d9dcd | 2013-11-11 13:59:40 +1000 | [diff] [blame] | 468 | if (nv_device(drm->device)->chipset < 0x11) |
| 469 | dev->mode_config.async_page_flip = false; |
| 470 | else |
| 471 | dev->mode_config.async_page_flip = true; |
| 472 | |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 473 | drm_kms_helper_poll_init(dev); |
| 474 | drm_kms_helper_poll_disable(dev); |
| 475 | |
Ben Skeggs | fc16208 | 2013-09-10 13:20:34 +1000 | [diff] [blame] | 476 | if (drm->vbios.dcb.entries) { |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 477 | static const u16 oclass[] = { |
Ben Skeggs | 0b68168 | 2014-02-24 14:29:55 +1000 | [diff] [blame] | 478 | GM107_DISP_CLASS, |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 479 | NVF0_DISP_CLASS, |
| 480 | NVE0_DISP_CLASS, |
| 481 | NVD0_DISP_CLASS, |
| 482 | NVA3_DISP_CLASS, |
| 483 | NV94_DISP_CLASS, |
| 484 | NVA0_DISP_CLASS, |
| 485 | NV84_DISP_CLASS, |
| 486 | NV50_DISP_CLASS, |
| 487 | NV04_DISP_CLASS, |
| 488 | }; |
| 489 | int i; |
| 490 | |
| 491 | for (i = 0, ret = -ENODEV; ret && i < ARRAY_SIZE(oclass); i++) { |
| 492 | ret = nouveau_object_new(nv_object(drm), NVDRM_DEVICE, |
| 493 | NVDRM_DISPLAY, oclass[i], |
| 494 | NULL, 0, &disp->core); |
| 495 | } |
| 496 | |
| 497 | if (ret == 0) { |
Ben Skeggs | 9c210f3 | 2014-08-10 04:10:21 +1000 | [diff] [blame^] | 498 | nouveau_display_create_properties(dev); |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 499 | if (nv_mclass(disp->core) < NV50_DISP_CLASS) |
| 500 | ret = nv04_display_create(dev); |
| 501 | else |
| 502 | ret = nv50_display_create(dev); |
| 503 | } |
Ben Skeggs | fc16208 | 2013-09-10 13:20:34 +1000 | [diff] [blame] | 504 | } else { |
| 505 | ret = 0; |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 506 | } |
| 507 | |
Ben Skeggs | fc16208 | 2013-09-10 13:20:34 +1000 | [diff] [blame] | 508 | if (ret) |
| 509 | goto disp_create_err; |
| 510 | |
| 511 | if (dev->mode_config.num_crtc) { |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 512 | ret = nouveau_display_vblank_init(dev); |
Ben Skeggs | fc16208 | 2013-09-10 13:20:34 +1000 | [diff] [blame] | 513 | if (ret) |
| 514 | goto vblank_err; |
| 515 | } |
| 516 | |
| 517 | nouveau_backlight_init(dev); |
Marcin Slusarz | 5ace2c9 | 2012-04-15 14:36:08 +0200 | [diff] [blame] | 518 | return 0; |
| 519 | |
| 520 | vblank_err: |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 521 | disp->dtor(dev); |
Marcin Slusarz | 5ace2c9 | 2012-04-15 14:36:08 +0200 | [diff] [blame] | 522 | disp_create_err: |
| 523 | drm_kms_helper_poll_fini(dev); |
| 524 | drm_mode_config_cleanup(dev); |
Ben Skeggs | 2a44e49 | 2011-11-09 11:36:33 +1000 | [diff] [blame] | 525 | return ret; |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | void |
| 529 | nouveau_display_destroy(struct drm_device *dev) |
| 530 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 531 | struct nouveau_display *disp = nouveau_display(dev); |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 532 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 533 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 534 | nouveau_backlight_exit(dev); |
Ben Skeggs | 51cb4b3 | 2013-10-03 07:02:29 +1000 | [diff] [blame] | 535 | nouveau_display_vblank_fini(dev); |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 536 | |
Ben Skeggs | d6bf2f3 | 2012-10-30 10:59:12 +1000 | [diff] [blame] | 537 | drm_kms_helper_poll_fini(dev); |
| 538 | drm_mode_config_cleanup(dev); |
| 539 | |
Ben Skeggs | 9430738 | 2012-10-31 12:11:15 +1000 | [diff] [blame] | 540 | if (disp->dtor) |
| 541 | disp->dtor(dev); |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 542 | |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 543 | nouveau_object_del(nv_object(drm), NVDRM_DEVICE, NVDRM_DISPLAY); |
| 544 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 545 | nouveau_drm(dev)->display = NULL; |
| 546 | kfree(disp); |
| 547 | } |
| 548 | |
| 549 | int |
| 550 | nouveau_display_suspend(struct drm_device *dev) |
| 551 | { |
| 552 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 553 | struct drm_crtc *crtc; |
| 554 | |
| 555 | nouveau_display_fini(dev); |
| 556 | |
Ben Skeggs | c52f4fa | 2013-11-08 14:38:40 +1000 | [diff] [blame] | 557 | NV_INFO(drm, "unpinning framebuffer(s)...\n"); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 558 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 559 | struct nouveau_framebuffer *nouveau_fb; |
| 560 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 561 | nouveau_fb = nouveau_framebuffer(crtc->primary->fb); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 562 | if (!nouveau_fb || !nouveau_fb->nvbo) |
| 563 | continue; |
| 564 | |
| 565 | nouveau_bo_unpin(nouveau_fb->nvbo); |
| 566 | } |
| 567 | |
| 568 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 569 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 570 | |
| 571 | nouveau_bo_unmap(nv_crtc->cursor.nvbo); |
| 572 | nouveau_bo_unpin(nv_crtc->cursor.nvbo); |
| 573 | } |
| 574 | |
| 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | void |
Dave Airlie | 5addcf0 | 2012-09-10 14:20:51 +1000 | [diff] [blame] | 579 | nouveau_display_repin(struct drm_device *dev) |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 580 | { |
| 581 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 582 | struct drm_crtc *crtc; |
| 583 | int ret; |
| 584 | |
| 585 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 586 | struct nouveau_framebuffer *nouveau_fb; |
| 587 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 588 | nouveau_fb = nouveau_framebuffer(crtc->primary->fb); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 589 | if (!nouveau_fb || !nouveau_fb->nvbo) |
| 590 | continue; |
| 591 | |
| 592 | nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM); |
| 593 | } |
| 594 | |
| 595 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 596 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 597 | |
| 598 | ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM); |
| 599 | if (!ret) |
| 600 | ret = nouveau_bo_map(nv_crtc->cursor.nvbo); |
| 601 | if (ret) |
| 602 | NV_ERROR(drm, "Could not pin/map cursor.\n"); |
| 603 | } |
Dave Airlie | 5addcf0 | 2012-09-10 14:20:51 +1000 | [diff] [blame] | 604 | } |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 605 | |
Dave Airlie | 5addcf0 | 2012-09-10 14:20:51 +1000 | [diff] [blame] | 606 | void |
| 607 | nouveau_display_resume(struct drm_device *dev) |
| 608 | { |
| 609 | struct drm_crtc *crtc; |
Mario Kleiner | 9cba5ef | 2014-07-29 02:36:44 +0200 | [diff] [blame] | 610 | int head; |
| 611 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 612 | nouveau_display_init(dev); |
| 613 | |
| 614 | /* Force CLUT to get re-loaded during modeset */ |
| 615 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 616 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 617 | |
| 618 | nv_crtc->lut.depth = 0; |
| 619 | } |
| 620 | |
Mario Kleiner | 9cba5ef | 2014-07-29 02:36:44 +0200 | [diff] [blame] | 621 | /* Make sure that drm and hw vblank irqs get resumed if needed. */ |
| 622 | for (head = 0; head < dev->mode_config.num_crtc; head++) |
| 623 | drm_vblank_on(dev, head); |
| 624 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 625 | drm_helper_resume_force_mode(dev); |
| 626 | |
| 627 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 628 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 629 | u32 offset = nv_crtc->cursor.nvbo->bo.offset; |
| 630 | |
| 631 | nv_crtc->cursor.set_offset(nv_crtc, offset); |
| 632 | nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x, |
| 633 | nv_crtc->cursor_saved_y); |
| 634 | } |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame] | 635 | } |
| 636 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 637 | static int |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 638 | nouveau_page_flip_emit(struct nouveau_channel *chan, |
| 639 | struct nouveau_bo *old_bo, |
| 640 | struct nouveau_bo *new_bo, |
| 641 | struct nouveau_page_flip_state *s, |
| 642 | struct nouveau_fence **pfence) |
| 643 | { |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 644 | struct nouveau_fence_chan *fctx = chan->fence; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 645 | struct nouveau_drm *drm = chan->drm; |
| 646 | struct drm_device *dev = drm->dev; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 647 | unsigned long flags; |
| 648 | int ret; |
| 649 | |
| 650 | /* Queue it to the pending list */ |
| 651 | spin_lock_irqsave(&dev->event_lock, flags); |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 652 | list_add_tail(&s->head, &fctx->flip); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 653 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 654 | |
| 655 | /* Synchronize with the old framebuffer */ |
| 656 | ret = nouveau_fence_sync(old_bo->bo.sync_obj, chan); |
| 657 | if (ret) |
| 658 | goto fail; |
| 659 | |
| 660 | /* Emit the pageflip */ |
Ben Skeggs | 1e303c0 | 2013-11-13 10:49:46 +1000 | [diff] [blame] | 661 | ret = RING_SPACE(chan, 2); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 662 | if (ret) |
| 663 | goto fail; |
| 664 | |
Ben Skeggs | 1e303c0 | 2013-11-13 10:49:46 +1000 | [diff] [blame] | 665 | if (nv_device(drm->device)->card_type < NV_C0) |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 666 | BEGIN_NV04(chan, NvSubSw, NV_SW_PAGE_FLIP, 1); |
Ben Skeggs | 1e303c0 | 2013-11-13 10:49:46 +1000 | [diff] [blame] | 667 | else |
| 668 | BEGIN_NVC0(chan, FermiSw, NV_SW_PAGE_FLIP, 1); |
| 669 | OUT_RING (chan, 0x00000000); |
Ben Skeggs | bd2f203 | 2011-02-08 15:16:23 +1000 | [diff] [blame] | 670 | FIRE_RING (chan); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 671 | |
Ben Skeggs | 264ce19 | 2013-02-14 13:43:21 +1000 | [diff] [blame] | 672 | ret = nouveau_fence_new(chan, false, pfence); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 673 | if (ret) |
| 674 | goto fail; |
| 675 | |
| 676 | return 0; |
| 677 | fail: |
| 678 | spin_lock_irqsave(&dev->event_lock, flags); |
| 679 | list_del(&s->head); |
| 680 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 681 | return ret; |
| 682 | } |
| 683 | |
| 684 | int |
| 685 | nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
Ben Skeggs | b9d9dcd | 2013-11-11 13:59:40 +1000 | [diff] [blame] | 686 | struct drm_pending_vblank_event *event, u32 flags) |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 687 | { |
Ben Skeggs | b9d9dcd | 2013-11-11 13:59:40 +1000 | [diff] [blame] | 688 | const int swap_interval = (flags & DRM_MODE_PAGE_FLIP_ASYNC) ? 0 : 1; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 689 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 690 | struct nouveau_drm *drm = nouveau_drm(dev); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 691 | struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->primary->fb)->nvbo; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 692 | struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo; |
| 693 | struct nouveau_page_flip_state *s; |
Ben Skeggs | eae389f | 2013-11-13 10:17:17 +1000 | [diff] [blame] | 694 | struct nouveau_channel *chan = drm->channel; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 695 | struct nouveau_fence *fence; |
| 696 | int ret; |
| 697 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 698 | if (!drm->channel) |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 699 | return -ENODEV; |
| 700 | |
| 701 | s = kzalloc(sizeof(*s), GFP_KERNEL); |
| 702 | if (!s) |
| 703 | return -ENOMEM; |
| 704 | |
Maarten Lankhorst | d5c1e84 | 2014-01-14 16:48:58 +0100 | [diff] [blame] | 705 | if (new_bo != old_bo) { |
| 706 | ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM); |
| 707 | if (ret) |
| 708 | goto fail_free; |
| 709 | } |
| 710 | |
| 711 | mutex_lock(&chan->cli->mutex); |
| 712 | |
Ben Skeggs | eae389f | 2013-11-13 10:17:17 +1000 | [diff] [blame] | 713 | /* synchronise rendering channel with the kernel's channel */ |
| 714 | spin_lock(&new_bo->bo.bdev->fence_lock); |
| 715 | fence = nouveau_fence_ref(new_bo->bo.sync_obj); |
| 716 | spin_unlock(&new_bo->bo.bdev->fence_lock); |
| 717 | ret = nouveau_fence_sync(fence, chan); |
Ben Skeggs | 2fd04c8 | 2013-11-21 14:22:39 +1000 | [diff] [blame] | 718 | nouveau_fence_unref(&fence); |
Ben Skeggs | eae389f | 2013-11-13 10:17:17 +1000 | [diff] [blame] | 719 | if (ret) |
Maarten Lankhorst | 09c3de1 | 2014-01-29 11:05:09 +0100 | [diff] [blame] | 720 | goto fail_unpin; |
Maarten Lankhorst | b580c9e | 2013-06-27 13:48:18 +0200 | [diff] [blame] | 721 | |
Ben Skeggs | 07ad6ca | 2013-11-13 10:00:32 +1000 | [diff] [blame] | 722 | ret = ttm_bo_reserve(&old_bo->bo, true, false, false, NULL); |
Ben Skeggs | 060810d | 2013-07-08 14:15:51 +1000 | [diff] [blame] | 723 | if (ret) |
| 724 | goto fail_unpin; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 725 | |
| 726 | /* Initialize a page flip struct */ |
| 727 | *s = (struct nouveau_page_flip_state) |
Benjamin Franzke | 2503c6f | 2011-02-16 10:04:48 +0100 | [diff] [blame] | 728 | { { }, event, nouveau_crtc(crtc)->index, |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 729 | fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y, |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 730 | new_bo->bo.offset }; |
| 731 | |
Mario Kleiner | ba124a4 | 2014-06-11 09:51:23 +0200 | [diff] [blame] | 732 | /* Keep vblanks on during flip, for the target crtc of this flip */ |
| 733 | drm_vblank_get(dev, nouveau_crtc(crtc)->index); |
| 734 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 735 | /* Emit a page flip */ |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 736 | if (nv_device(drm->device)->card_type >= NV_50) { |
Ben Skeggs | b9d9dcd | 2013-11-11 13:59:40 +1000 | [diff] [blame] | 737 | ret = nv50_display_flip_next(crtc, fb, chan, swap_interval); |
Ben Skeggs | 060810d | 2013-07-08 14:15:51 +1000 | [diff] [blame] | 738 | if (ret) |
Ben Skeggs | d7117e0 | 2011-02-07 14:27:04 +1000 | [diff] [blame] | 739 | goto fail_unreserve; |
Ben Skeggs | 78ae0ad | 2013-08-21 11:30:36 +1000 | [diff] [blame] | 740 | } else { |
| 741 | struct nv04_display *dispnv04 = nv04_display(dev); |
Ben Skeggs | b9d9dcd | 2013-11-11 13:59:40 +1000 | [diff] [blame] | 742 | int head = nouveau_crtc(crtc)->index; |
| 743 | |
| 744 | if (swap_interval) { |
| 745 | ret = RING_SPACE(chan, 8); |
| 746 | if (ret) |
| 747 | goto fail_unreserve; |
| 748 | |
| 749 | BEGIN_NV04(chan, NvSubImageBlit, 0x012c, 1); |
| 750 | OUT_RING (chan, 0); |
| 751 | BEGIN_NV04(chan, NvSubImageBlit, 0x0134, 1); |
| 752 | OUT_RING (chan, head); |
| 753 | BEGIN_NV04(chan, NvSubImageBlit, 0x0100, 1); |
| 754 | OUT_RING (chan, 0); |
| 755 | BEGIN_NV04(chan, NvSubImageBlit, 0x0130, 1); |
| 756 | OUT_RING (chan, 0); |
| 757 | } |
| 758 | |
| 759 | nouveau_bo_ref(new_bo, &dispnv04->image[head]); |
Ben Skeggs | d7117e0 | 2011-02-07 14:27:04 +1000 | [diff] [blame] | 760 | } |
| 761 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 762 | ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 763 | if (ret) |
| 764 | goto fail_unreserve; |
Maarten Lankhorst | 806cbc5 | 2014-05-01 13:58:05 +0200 | [diff] [blame] | 765 | mutex_unlock(&chan->cli->mutex); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 766 | |
| 767 | /* Update the crtc struct and cleanup */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 768 | crtc->primary->fb = fb; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 769 | |
Ben Skeggs | 07ad6ca | 2013-11-13 10:00:32 +1000 | [diff] [blame] | 770 | nouveau_bo_fence(old_bo, fence); |
| 771 | ttm_bo_unreserve(&old_bo->bo); |
Ben Skeggs | 060810d | 2013-07-08 14:15:51 +1000 | [diff] [blame] | 772 | if (old_bo != new_bo) |
Maarten Lankhorst | b580c9e | 2013-06-27 13:48:18 +0200 | [diff] [blame] | 773 | nouveau_bo_unpin(old_bo); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 774 | nouveau_fence_unref(&fence); |
| 775 | return 0; |
| 776 | |
| 777 | fail_unreserve: |
Mario Kleiner | ba124a4 | 2014-06-11 09:51:23 +0200 | [diff] [blame] | 778 | drm_vblank_put(dev, nouveau_crtc(crtc)->index); |
Ben Skeggs | 07ad6ca | 2013-11-13 10:00:32 +1000 | [diff] [blame] | 779 | ttm_bo_unreserve(&old_bo->bo); |
Ben Skeggs | 060810d | 2013-07-08 14:15:51 +1000 | [diff] [blame] | 780 | fail_unpin: |
| 781 | mutex_unlock(&chan->cli->mutex); |
| 782 | if (old_bo != new_bo) |
Maarten Lankhorst | b580c9e | 2013-06-27 13:48:18 +0200 | [diff] [blame] | 783 | nouveau_bo_unpin(new_bo); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 784 | fail_free: |
| 785 | kfree(s); |
| 786 | return ret; |
| 787 | } |
| 788 | |
| 789 | int |
| 790 | nouveau_finish_page_flip(struct nouveau_channel *chan, |
| 791 | struct nouveau_page_flip_state *ps) |
| 792 | { |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 793 | struct nouveau_fence_chan *fctx = chan->fence; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 794 | struct nouveau_drm *drm = chan->drm; |
| 795 | struct drm_device *dev = drm->dev; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 796 | struct nouveau_page_flip_state *s; |
| 797 | unsigned long flags; |
Mario Kleiner | af4870e | 2014-05-13 00:42:08 +0200 | [diff] [blame] | 798 | int crtcid = -1; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 799 | |
| 800 | spin_lock_irqsave(&dev->event_lock, flags); |
| 801 | |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 802 | if (list_empty(&fctx->flip)) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 803 | NV_ERROR(drm, "unexpected pageflip\n"); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 804 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 805 | return -EINVAL; |
| 806 | } |
| 807 | |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 808 | s = list_first_entry(&fctx->flip, struct nouveau_page_flip_state, head); |
Mario Kleiner | af4870e | 2014-05-13 00:42:08 +0200 | [diff] [blame] | 809 | if (s->event) { |
| 810 | /* Vblank timestamps/counts are only correct on >= NV-50 */ |
| 811 | if (nv_device(drm->device)->card_type >= NV_50) |
| 812 | crtcid = s->crtc; |
| 813 | |
| 814 | drm_send_vblank_event(dev, crtcid, s->event); |
| 815 | } |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 816 | |
Mario Kleiner | ba124a4 | 2014-06-11 09:51:23 +0200 | [diff] [blame] | 817 | /* Give up ownership of vblank for page-flipped crtc */ |
| 818 | drm_vblank_put(dev, s->crtc); |
| 819 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 820 | list_del(&s->head); |
Ben Skeggs | d7117e0 | 2011-02-07 14:27:04 +1000 | [diff] [blame] | 821 | if (ps) |
| 822 | *ps = *s; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 823 | kfree(s); |
| 824 | |
| 825 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 826 | return 0; |
| 827 | } |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 828 | |
| 829 | int |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 830 | nouveau_flip_complete(void *data) |
| 831 | { |
| 832 | struct nouveau_channel *chan = data; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 833 | struct nouveau_drm *drm = chan->drm; |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 834 | struct nouveau_page_flip_state state; |
| 835 | |
| 836 | if (!nouveau_finish_page_flip(chan, &state)) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 837 | if (nv_device(drm->device)->card_type < NV_50) { |
| 838 | nv_set_crtc_base(drm->dev, state.crtc, state.offset + |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 839 | state.y * state.pitch + |
| 840 | state.x * state.bpp / 8); |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | return 0; |
| 845 | } |
| 846 | |
| 847 | int |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 848 | nouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev, |
| 849 | struct drm_mode_create_dumb *args) |
| 850 | { |
| 851 | struct nouveau_bo *bo; |
| 852 | int ret; |
| 853 | |
| 854 | args->pitch = roundup(args->width * (args->bpp / 8), 256); |
| 855 | args->size = args->pitch * args->height; |
| 856 | args->size = roundup(args->size, PAGE_SIZE); |
| 857 | |
Dave Airlie | 610bd7d | 2012-09-14 13:28:23 +1000 | [diff] [blame] | 858 | ret = nouveau_gem_new(dev, args->size, 0, NOUVEAU_GEM_DOMAIN_VRAM, 0, 0, &bo); |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 859 | if (ret) |
| 860 | return ret; |
| 861 | |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 862 | ret = drm_gem_handle_create(file_priv, &bo->gem, &args->handle); |
| 863 | drm_gem_object_unreference_unlocked(&bo->gem); |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 864 | return ret; |
| 865 | } |
| 866 | |
| 867 | int |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 868 | nouveau_display_dumb_map_offset(struct drm_file *file_priv, |
| 869 | struct drm_device *dev, |
| 870 | uint32_t handle, uint64_t *poffset) |
| 871 | { |
| 872 | struct drm_gem_object *gem; |
| 873 | |
| 874 | gem = drm_gem_object_lookup(dev, file_priv, handle); |
| 875 | if (gem) { |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 876 | struct nouveau_bo *bo = nouveau_gem_object(gem); |
David Herrmann | 72525b3 | 2013-07-24 21:08:53 +0200 | [diff] [blame] | 877 | *poffset = drm_vma_node_offset_addr(&bo->bo.vma_node); |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 878 | drm_gem_object_unreference_unlocked(gem); |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | return -ENOENT; |
| 883 | } |