Staging: netwave: delete the driver
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nouveau_display.c
blobcf1c5c0a0abea357c1725d5649a12a822343edf1
1 /*
2 * Copyright (C) 2008 Maarten Maathuis.
3 * All Rights Reserved.
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:
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.
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.
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"
33 static void
34 nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb)
36 struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
37 struct drm_device *dev = drm_fb->dev;
39 if (drm_fb->fbdev)
40 nouveau_fbcon_remove(dev, drm_fb);
42 if (fb->nvbo)
43 drm_gem_object_unreference_unlocked(fb->nvbo->gem);
45 drm_framebuffer_cleanup(drm_fb);
46 kfree(fb);
49 static int
50 nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb,
51 struct drm_file *file_priv,
52 unsigned int *handle)
54 struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
56 return drm_gem_handle_create(file_priv, fb->nvbo->gem, handle);
59 static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = {
60 .destroy = nouveau_user_framebuffer_destroy,
61 .create_handle = nouveau_user_framebuffer_create_handle,
64 struct drm_framebuffer *
65 nouveau_framebuffer_create(struct drm_device *dev, struct nouveau_bo *nvbo,
66 struct drm_mode_fb_cmd *mode_cmd)
68 struct nouveau_framebuffer *fb;
69 int ret;
71 fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL);
72 if (!fb)
73 return NULL;
75 ret = drm_framebuffer_init(dev, &fb->base, &nouveau_framebuffer_funcs);
76 if (ret) {
77 kfree(fb);
78 return NULL;
81 drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd);
83 fb->nvbo = nvbo;
84 return &fb->base;
87 static struct drm_framebuffer *
88 nouveau_user_framebuffer_create(struct drm_device *dev,
89 struct drm_file *file_priv,
90 struct drm_mode_fb_cmd *mode_cmd)
92 struct drm_framebuffer *fb;
93 struct drm_gem_object *gem;
95 gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
96 if (!gem)
97 return NULL;
99 fb = nouveau_framebuffer_create(dev, nouveau_gem_object(gem), mode_cmd);
100 if (!fb) {
101 drm_gem_object_unreference(gem);
102 return NULL;
105 return fb;
108 const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
109 .fb_create = nouveau_user_framebuffer_create,
110 .fb_changed = nouveau_fbcon_probe,