Merge to Fedora kernel-2.6.17-1.2187_FC5 patched with stable patch-2.6.17.13-vs2...
[linux-2.6.git] / drivers / video / console / softcursor.c
1 /*
2  * linux/drivers/video/softcursor.c -- Generic software cursor for frame buffer devices
3  *
4  *  Created 14 Nov 2002 by James Simmons
5  *
6  * This file is subject to the terms and conditions of the GNU General Public
7  * License.  See the file COPYING in the main directory of this archive
8  * for more details.
9  */
10
11 #include <linux/module.h>
12 #include <linux/string.h>
13 #include <linux/tty.h>
14 #include <linux/fb.h>
15 #include <linux/slab.h>
16
17 #include <asm/uaccess.h>
18 #include <asm/io.h>
19
20 #include "fbcon.h"
21
22 int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
23 {
24         unsigned int scan_align = info->pixmap.scan_align - 1;
25         unsigned int buf_align = info->pixmap.buf_align - 1;
26         unsigned int i, size, dsize, s_pitch, d_pitch;
27         struct fb_image *image;
28         u8 *dst;
29         static u8 *src=NULL;
30         static int allocsize = 0;
31
32         if (info->state != FBINFO_STATE_RUNNING)
33                 return 0;
34
35         s_pitch = (cursor->image.width + 7) >> 3;
36         dsize = s_pitch * cursor->image.height;
37
38         if (dsize + sizeof(struct fb_image) != allocsize) {
39                 if (src != NULL)
40                         kfree(src);
41                 allocsize = dsize + sizeof(struct fb_image);
42
43                 src = kmalloc(allocsize, GFP_ATOMIC);
44                 if (!src) {
45                         allocsize = 0;
46                         return -ENOMEM;
47                 }
48         }
49
50         image = (struct fb_image *) (src + dsize);
51         *image = cursor->image;
52         d_pitch = (s_pitch + scan_align) & ~scan_align;
53
54         size = d_pitch * image->height + buf_align;
55         size &= ~buf_align;
56         dst = fb_get_buffer_offset(info, &info->pixmap, size);
57
58         if (cursor->enable) {
59                 switch (cursor->rop) {
60                 case ROP_XOR:
61                         for (i = 0; i < dsize; i++)
62                                 src[i] = image->data[i] ^ cursor->mask[i];
63                         break;
64                 case ROP_COPY:
65                 default:
66                         for (i = 0; i < dsize; i++)
67                                 src[i] = image->data[i] & cursor->mask[i];
68                         break;
69                 }
70         } else
71                 memcpy(src, image->data, dsize);
72
73         fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height);
74         image->data = dst;
75         info->fbops->fb_imageblit(info, image);
76         return 0;
77 }
78
79 EXPORT_SYMBOL(soft_cursor);
80
81 MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
82 MODULE_DESCRIPTION("Generic software cursor");
83 MODULE_LICENSE("GPL");