ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / video / fbsysfs.c
1 /*
2  * fbsysfs.c - framebuffer device class and attributes
3  *
4  * Copyright (c) 2004 James Simmons <jsimmons@infradead.org>
5  * 
6  *      This program is free software you can redistribute it and/or
7  *      modify it under the terms of the GNU General Public License
8  *      as published by the Free Software Foundation; either version
9  *      2 of the License, or (at your option) any later version.
10  */
11
12 /*
13  * Note:  currently there's only stubs for framebuffer_alloc and
14  * framebuffer_release here.  The reson for that is that until all drivers
15  * are converted to use it a sysfsification will open OOPSable races.
16  */
17
18 #include <linux/kernel.h>
19 #include <linux/fb.h>
20
21 /**
22  * framebuffer_alloc - creates a new frame buffer info structure
23  *
24  * @size: size of driver private data, can be zero
25  * @dev: pointer to the device for this fb, this can be NULL
26  *
27  * Creates a new frame buffer info structure. Also reserves @size bytes
28  * for driver private data (info->par). info->par (if any) will be
29  * aligned to sizeof(long).
30  *
31  * Returns the new structure, or NULL if an error occured.
32  *
33  */
34 struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
35 {
36 #define BYTES_PER_LONG (BITS_PER_LONG/8)
37 #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
38         int fb_info_size = sizeof(struct fb_info);
39         struct fb_info *info;
40         char *p;
41
42         if (size)
43                 fb_info_size += PADDING;
44
45         p = kmalloc(fb_info_size + size, GFP_KERNEL);
46         if (!p)
47                 return NULL;
48         memset(p, 0, fb_info_size + size);
49         info = (struct fb_info *) p;
50
51         if (size)
52                 info->par = p + fb_info_size;
53
54         return info;
55 #undef PADDING
56 #undef BYTES_PER_LONG
57 }
58
59 /**
60  * framebuffer_release - marks the structure available for freeing
61  *
62  * @info: frame buffer info structure
63  *
64  * Drop the reference count of the class_device embedded in the
65  * framebuffer info structure.
66  *
67  */
68 void framebuffer_release(struct fb_info *info)
69 {
70         kfree(info);
71 }
72
73 EXPORT_SYMBOL(framebuffer_release);
74 EXPORT_SYMBOL(framebuffer_alloc);