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 | |
| 27 | #include "drmP.h" |
| 28 | #include "drm_crtc_helper.h" |
| 29 | #include "nouveau_drv.h" |
| 30 | #include "nouveau_fb.h" |
| 31 | #include "nouveau_fbcon.h" |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 32 | #include "nouveau_hw.h" |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 33 | #include "nouveau_crtc.h" |
| 34 | #include "nouveau_dma.h" |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 35 | #include "nv50_display.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 36 | |
| 37 | static void |
| 38 | nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb) |
| 39 | { |
| 40 | struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 41 | |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 42 | if (fb->nvbo) |
| 43 | drm_gem_object_unreference_unlocked(fb->nvbo->gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 44 | |
| 45 | drm_framebuffer_cleanup(drm_fb); |
| 46 | kfree(fb); |
| 47 | } |
| 48 | |
| 49 | static int |
| 50 | nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb, |
| 51 | struct drm_file *file_priv, |
| 52 | unsigned int *handle) |
| 53 | { |
| 54 | struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); |
| 55 | |
| 56 | return drm_gem_handle_create(file_priv, fb->nvbo->gem, handle); |
| 57 | } |
| 58 | |
| 59 | static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = { |
| 60 | .destroy = nouveau_user_framebuffer_destroy, |
| 61 | .create_handle = nouveau_user_framebuffer_create_handle, |
| 62 | }; |
| 63 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 64 | int |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 65 | nouveau_framebuffer_init(struct drm_device *dev, |
| 66 | struct nouveau_framebuffer *nv_fb, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 67 | struct drm_mode_fb_cmd2 *mode_cmd, |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 68 | struct nouveau_bo *nvbo) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 69 | { |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 70 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 71 | struct drm_framebuffer *fb = &nv_fb->base; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 72 | int ret; |
| 73 | |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 74 | ret = drm_framebuffer_init(dev, fb, &nouveau_framebuffer_funcs); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 75 | if (ret) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 76 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 77 | } |
| 78 | |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 79 | drm_helper_mode_fill_fb_struct(fb, mode_cmd); |
| 80 | nv_fb->nvbo = nvbo; |
| 81 | |
| 82 | if (dev_priv->card_type >= NV_50) { |
| 83 | u32 tile_flags = nouveau_bo_tile_layout(nvbo); |
| 84 | if (tile_flags == 0x7a00 || |
| 85 | tile_flags == 0xfe00) |
| 86 | nv_fb->r_dma = NvEvoFB32; |
| 87 | else |
| 88 | if (tile_flags == 0x7000) |
| 89 | nv_fb->r_dma = NvEvoFB16; |
| 90 | else |
| 91 | nv_fb->r_dma = NvEvoVRAM_LP; |
| 92 | |
| 93 | switch (fb->depth) { |
| 94 | case 8: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_8; break; |
| 95 | case 15: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_15; break; |
| 96 | case 16: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_16; break; |
| 97 | case 24: |
| 98 | case 32: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_24; break; |
| 99 | case 30: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_30; break; |
| 100 | default: |
| 101 | NV_ERROR(dev, "unknown depth %d\n", fb->depth); |
| 102 | return -EINVAL; |
| 103 | } |
| 104 | |
| 105 | if (dev_priv->chipset == 0x50) |
| 106 | nv_fb->r_format |= (tile_flags << 8); |
| 107 | |
Ben Skeggs | 2fad3d5 | 2011-07-06 09:59:40 +1000 | [diff] [blame] | 108 | if (!tile_flags) { |
| 109 | if (dev_priv->card_type < NV_D0) |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 110 | nv_fb->r_pitch = 0x00100000 | fb->pitches[0]; |
Ben Skeggs | 2fad3d5 | 2011-07-06 09:59:40 +1000 | [diff] [blame] | 111 | else |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 112 | nv_fb->r_pitch = 0x01000000 | fb->pitches[0]; |
Ben Skeggs | 2fad3d5 | 2011-07-06 09:59:40 +1000 | [diff] [blame] | 113 | } else { |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 114 | u32 mode = nvbo->tile_mode; |
| 115 | if (dev_priv->card_type >= NV_C0) |
| 116 | mode >>= 4; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 117 | nv_fb->r_pitch = ((fb->pitches[0] / 4) << 4) | mode; |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 121 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static struct drm_framebuffer * |
| 125 | nouveau_user_framebuffer_create(struct drm_device *dev, |
| 126 | struct drm_file *file_priv, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 127 | struct drm_mode_fb_cmd2 *mode_cmd) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 128 | { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 129 | struct nouveau_framebuffer *nouveau_fb; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 130 | struct drm_gem_object *gem; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 131 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 132 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 133 | gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 134 | if (!gem) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 135 | return ERR_PTR(-ENOENT); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 136 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 137 | nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL); |
| 138 | if (!nouveau_fb) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 139 | return ERR_PTR(-ENOMEM); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 140 | |
| 141 | ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem)); |
| 142 | if (ret) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 143 | drm_gem_object_unreference(gem); |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 144 | return ERR_PTR(ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 145 | } |
| 146 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 147 | return &nouveau_fb->base; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 148 | } |
| 149 | |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame^] | 150 | static const struct drm_mode_config_funcs nouveau_mode_config_funcs = { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 151 | .fb_create = nouveau_user_framebuffer_create, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 152 | .output_poll_changed = nouveau_fbcon_output_poll_changed, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 153 | }; |
| 154 | |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 155 | int |
Ben Skeggs | 27d5030 | 2011-10-06 12:46:40 +1000 | [diff] [blame^] | 156 | nouveau_display_create(struct drm_device *dev) |
| 157 | { |
| 158 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 159 | struct nouveau_display_engine *disp = &dev_priv->engine.display; |
| 160 | int ret; |
| 161 | |
| 162 | drm_mode_config_init(dev); |
| 163 | drm_mode_create_scaling_mode_property(dev); |
| 164 | drm_mode_create_dithering_property(dev); |
| 165 | |
| 166 | dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs; |
| 167 | dev->mode_config.fb_base = pci_resource_start(dev->pdev, 1); |
| 168 | |
| 169 | dev->mode_config.min_width = 0; |
| 170 | dev->mode_config.min_height = 0; |
| 171 | if (dev_priv->card_type < NV_10) { |
| 172 | dev->mode_config.max_width = 2048; |
| 173 | dev->mode_config.max_height = 2048; |
| 174 | } else |
| 175 | if (dev_priv->card_type < NV_50) { |
| 176 | dev->mode_config.max_width = 4096; |
| 177 | dev->mode_config.max_height = 4096; |
| 178 | } else { |
| 179 | dev->mode_config.max_width = 8192; |
| 180 | dev->mode_config.max_height = 8192; |
| 181 | } |
| 182 | |
| 183 | ret = disp->create(dev); |
| 184 | if (ret) |
| 185 | return ret; |
| 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | void |
| 191 | nouveau_display_destroy(struct drm_device *dev) |
| 192 | { |
| 193 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 194 | struct nouveau_display_engine *disp = &dev_priv->engine.display; |
| 195 | |
| 196 | disp->destroy(dev); |
| 197 | drm_mode_config_cleanup(dev); |
| 198 | } |
| 199 | |
| 200 | int |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 201 | nouveau_vblank_enable(struct drm_device *dev, int crtc) |
| 202 | { |
| 203 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 204 | |
| 205 | if (dev_priv->card_type >= NV_50) |
| 206 | nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, 0, |
| 207 | NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc)); |
| 208 | else |
| 209 | NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, |
| 210 | NV_PCRTC_INTR_0_VBLANK); |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | void |
| 216 | nouveau_vblank_disable(struct drm_device *dev, int crtc) |
| 217 | { |
| 218 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 219 | |
| 220 | if (dev_priv->card_type >= NV_50) |
| 221 | nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, |
| 222 | NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc), 0); |
| 223 | else |
| 224 | NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, 0); |
| 225 | } |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 226 | |
| 227 | static int |
| 228 | nouveau_page_flip_reserve(struct nouveau_bo *old_bo, |
| 229 | struct nouveau_bo *new_bo) |
| 230 | { |
| 231 | int ret; |
| 232 | |
| 233 | ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM); |
| 234 | if (ret) |
| 235 | return ret; |
| 236 | |
| 237 | ret = ttm_bo_reserve(&new_bo->bo, false, false, false, 0); |
| 238 | if (ret) |
| 239 | goto fail; |
| 240 | |
| 241 | ret = ttm_bo_reserve(&old_bo->bo, false, false, false, 0); |
| 242 | if (ret) |
| 243 | goto fail_unreserve; |
| 244 | |
| 245 | return 0; |
| 246 | |
| 247 | fail_unreserve: |
| 248 | ttm_bo_unreserve(&new_bo->bo); |
| 249 | fail: |
| 250 | nouveau_bo_unpin(new_bo); |
| 251 | return ret; |
| 252 | } |
| 253 | |
| 254 | static void |
| 255 | nouveau_page_flip_unreserve(struct nouveau_bo *old_bo, |
| 256 | struct nouveau_bo *new_bo, |
| 257 | struct nouveau_fence *fence) |
| 258 | { |
| 259 | nouveau_bo_fence(new_bo, fence); |
| 260 | ttm_bo_unreserve(&new_bo->bo); |
| 261 | |
| 262 | nouveau_bo_fence(old_bo, fence); |
| 263 | ttm_bo_unreserve(&old_bo->bo); |
| 264 | |
| 265 | nouveau_bo_unpin(old_bo); |
| 266 | } |
| 267 | |
| 268 | static int |
| 269 | nouveau_page_flip_emit(struct nouveau_channel *chan, |
| 270 | struct nouveau_bo *old_bo, |
| 271 | struct nouveau_bo *new_bo, |
| 272 | struct nouveau_page_flip_state *s, |
| 273 | struct nouveau_fence **pfence) |
| 274 | { |
Ben Skeggs | bd2f203 | 2011-02-08 15:16:23 +1000 | [diff] [blame] | 275 | struct drm_nouveau_private *dev_priv = chan->dev->dev_private; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 276 | struct drm_device *dev = chan->dev; |
| 277 | unsigned long flags; |
| 278 | int ret; |
| 279 | |
| 280 | /* Queue it to the pending list */ |
| 281 | spin_lock_irqsave(&dev->event_lock, flags); |
| 282 | list_add_tail(&s->head, &chan->nvsw.flip); |
| 283 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 284 | |
| 285 | /* Synchronize with the old framebuffer */ |
| 286 | ret = nouveau_fence_sync(old_bo->bo.sync_obj, chan); |
| 287 | if (ret) |
| 288 | goto fail; |
| 289 | |
| 290 | /* Emit the pageflip */ |
| 291 | ret = RING_SPACE(chan, 2); |
| 292 | if (ret) |
| 293 | goto fail; |
| 294 | |
Ben Skeggs | bd2f203 | 2011-02-08 15:16:23 +1000 | [diff] [blame] | 295 | if (dev_priv->card_type < NV_C0) |
| 296 | BEGIN_RING(chan, NvSubSw, NV_SW_PAGE_FLIP, 1); |
| 297 | else |
| 298 | BEGIN_NVC0(chan, 2, NvSubM2MF, 0x0500, 1); |
| 299 | OUT_RING (chan, 0); |
| 300 | FIRE_RING (chan); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 301 | |
| 302 | ret = nouveau_fence_new(chan, pfence, true); |
| 303 | if (ret) |
| 304 | goto fail; |
| 305 | |
| 306 | return 0; |
| 307 | fail: |
| 308 | spin_lock_irqsave(&dev->event_lock, flags); |
| 309 | list_del(&s->head); |
| 310 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | int |
| 315 | nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 316 | struct drm_pending_vblank_event *event) |
| 317 | { |
| 318 | struct drm_device *dev = crtc->dev; |
| 319 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 320 | struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->fb)->nvbo; |
| 321 | struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo; |
| 322 | struct nouveau_page_flip_state *s; |
| 323 | struct nouveau_channel *chan; |
| 324 | struct nouveau_fence *fence; |
| 325 | int ret; |
| 326 | |
Ben Skeggs | a82dd49 | 2011-04-01 13:56:05 +1000 | [diff] [blame] | 327 | if (!dev_priv->channel) |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 328 | return -ENODEV; |
| 329 | |
| 330 | s = kzalloc(sizeof(*s), GFP_KERNEL); |
| 331 | if (!s) |
| 332 | return -ENOMEM; |
| 333 | |
| 334 | /* Don't let the buffers go away while we flip */ |
| 335 | ret = nouveau_page_flip_reserve(old_bo, new_bo); |
| 336 | if (ret) |
| 337 | goto fail_free; |
| 338 | |
| 339 | /* Initialize a page flip struct */ |
| 340 | *s = (struct nouveau_page_flip_state) |
Benjamin Franzke | 2503c6f | 2011-02-16 10:04:48 +0100 | [diff] [blame] | 341 | { { }, event, nouveau_crtc(crtc)->index, |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 342 | fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y, |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 343 | new_bo->bo.offset }; |
| 344 | |
| 345 | /* Choose the channel the flip will be handled in */ |
| 346 | chan = nouveau_fence_channel(new_bo->bo.sync_obj); |
| 347 | if (!chan) |
| 348 | chan = nouveau_channel_get_unlocked(dev_priv->channel); |
| 349 | mutex_lock(&chan->mutex); |
| 350 | |
| 351 | /* Emit a page flip */ |
Ben Skeggs | d7117e0 | 2011-02-07 14:27:04 +1000 | [diff] [blame] | 352 | if (dev_priv->card_type >= NV_50) { |
| 353 | ret = nv50_display_flip_next(crtc, fb, chan); |
| 354 | if (ret) { |
| 355 | nouveau_channel_put(&chan); |
| 356 | goto fail_unreserve; |
| 357 | } |
| 358 | } |
| 359 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 360 | ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence); |
| 361 | nouveau_channel_put(&chan); |
| 362 | if (ret) |
| 363 | goto fail_unreserve; |
| 364 | |
| 365 | /* Update the crtc struct and cleanup */ |
| 366 | crtc->fb = fb; |
| 367 | |
| 368 | nouveau_page_flip_unreserve(old_bo, new_bo, fence); |
| 369 | nouveau_fence_unref(&fence); |
| 370 | return 0; |
| 371 | |
| 372 | fail_unreserve: |
| 373 | nouveau_page_flip_unreserve(old_bo, new_bo, NULL); |
| 374 | fail_free: |
| 375 | kfree(s); |
| 376 | return ret; |
| 377 | } |
| 378 | |
| 379 | int |
| 380 | nouveau_finish_page_flip(struct nouveau_channel *chan, |
| 381 | struct nouveau_page_flip_state *ps) |
| 382 | { |
| 383 | struct drm_device *dev = chan->dev; |
| 384 | struct nouveau_page_flip_state *s; |
| 385 | unsigned long flags; |
| 386 | |
| 387 | spin_lock_irqsave(&dev->event_lock, flags); |
| 388 | |
| 389 | if (list_empty(&chan->nvsw.flip)) { |
| 390 | NV_ERROR(dev, "Unexpected pageflip in channel %d.\n", chan->id); |
| 391 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 392 | return -EINVAL; |
| 393 | } |
| 394 | |
| 395 | s = list_first_entry(&chan->nvsw.flip, |
| 396 | struct nouveau_page_flip_state, head); |
| 397 | if (s->event) { |
| 398 | struct drm_pending_vblank_event *e = s->event; |
| 399 | struct timeval now; |
| 400 | |
| 401 | do_gettimeofday(&now); |
| 402 | e->event.sequence = 0; |
| 403 | e->event.tv_sec = now.tv_sec; |
| 404 | e->event.tv_usec = now.tv_usec; |
| 405 | list_add_tail(&e->base.link, &e->base.file_priv->event_list); |
| 406 | wake_up_interruptible(&e->base.file_priv->event_wait); |
| 407 | } |
| 408 | |
| 409 | list_del(&s->head); |
Ben Skeggs | d7117e0 | 2011-02-07 14:27:04 +1000 | [diff] [blame] | 410 | if (ps) |
| 411 | *ps = *s; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 412 | kfree(s); |
| 413 | |
| 414 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 415 | return 0; |
| 416 | } |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 417 | |
| 418 | int |
| 419 | nouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev, |
| 420 | struct drm_mode_create_dumb *args) |
| 421 | { |
| 422 | struct nouveau_bo *bo; |
| 423 | int ret; |
| 424 | |
| 425 | args->pitch = roundup(args->width * (args->bpp / 8), 256); |
| 426 | args->size = args->pitch * args->height; |
| 427 | args->size = roundup(args->size, PAGE_SIZE); |
| 428 | |
| 429 | ret = nouveau_gem_new(dev, args->size, 0, TTM_PL_FLAG_VRAM, 0, 0, &bo); |
| 430 | if (ret) |
| 431 | return ret; |
| 432 | |
| 433 | ret = drm_gem_handle_create(file_priv, bo->gem, &args->handle); |
| 434 | drm_gem_object_unreference_unlocked(bo->gem); |
| 435 | return ret; |
| 436 | } |
| 437 | |
| 438 | int |
| 439 | nouveau_display_dumb_destroy(struct drm_file *file_priv, struct drm_device *dev, |
| 440 | uint32_t handle) |
| 441 | { |
| 442 | return drm_gem_handle_delete(file_priv, handle); |
| 443 | } |
| 444 | |
| 445 | int |
| 446 | nouveau_display_dumb_map_offset(struct drm_file *file_priv, |
| 447 | struct drm_device *dev, |
| 448 | uint32_t handle, uint64_t *poffset) |
| 449 | { |
| 450 | struct drm_gem_object *gem; |
| 451 | |
| 452 | gem = drm_gem_object_lookup(dev, file_priv, handle); |
| 453 | if (gem) { |
| 454 | struct nouveau_bo *bo = gem->driver_private; |
| 455 | *poffset = bo->bo.addr_space_offset; |
| 456 | drm_gem_object_unreference_unlocked(gem); |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | return -ENOENT; |
| 461 | } |