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" |
| 32 | |
| 33 | static void |
| 34 | nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb) |
| 35 | { |
| 36 | struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 37 | |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 38 | if (fb->nvbo) |
| 39 | drm_gem_object_unreference_unlocked(fb->nvbo->gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 40 | |
| 41 | drm_framebuffer_cleanup(drm_fb); |
| 42 | kfree(fb); |
| 43 | } |
| 44 | |
| 45 | static int |
| 46 | nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb, |
| 47 | struct drm_file *file_priv, |
| 48 | unsigned int *handle) |
| 49 | { |
| 50 | struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); |
| 51 | |
| 52 | return drm_gem_handle_create(file_priv, fb->nvbo->gem, handle); |
| 53 | } |
| 54 | |
| 55 | static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = { |
| 56 | .destroy = nouveau_user_framebuffer_destroy, |
| 57 | .create_handle = nouveau_user_framebuffer_create_handle, |
| 58 | }; |
| 59 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 60 | int |
| 61 | nouveau_framebuffer_init(struct drm_device *dev, struct nouveau_framebuffer *nouveau_fb, |
| 62 | struct drm_mode_fb_cmd *mode_cmd, struct nouveau_bo *nvbo) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 63 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 64 | int ret; |
| 65 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 66 | ret = drm_framebuffer_init(dev, &nouveau_fb->base, &nouveau_framebuffer_funcs); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 67 | if (ret) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 68 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 69 | } |
| 70 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 71 | drm_helper_mode_fill_fb_struct(&nouveau_fb->base, mode_cmd); |
| 72 | nouveau_fb->nvbo = nvbo; |
| 73 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static struct drm_framebuffer * |
| 77 | nouveau_user_framebuffer_create(struct drm_device *dev, |
| 78 | struct drm_file *file_priv, |
| 79 | struct drm_mode_fb_cmd *mode_cmd) |
| 80 | { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 81 | struct nouveau_framebuffer *nouveau_fb; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 82 | struct drm_gem_object *gem; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 83 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 84 | |
| 85 | gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle); |
| 86 | if (!gem) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame^] | 87 | return ERR_PTR(-ENOENT); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 88 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 89 | nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL); |
| 90 | if (!nouveau_fb) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame^] | 91 | return ERR_PTR(-ENOMEM); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 92 | |
| 93 | ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem)); |
| 94 | if (ret) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 95 | drm_gem_object_unreference(gem); |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame^] | 96 | return ERR_PTR(ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 97 | } |
| 98 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 99 | return &nouveau_fb->base; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | const struct drm_mode_config_funcs nouveau_mode_config_funcs = { |
| 103 | .fb_create = nouveau_user_framebuffer_create, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 104 | .output_poll_changed = nouveau_fbcon_output_poll_changed, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 105 | }; |
| 106 | |