| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Uwe Kleine-König | 5886269 | 2007-05-09 07:51:49 +0200 | [diff] [blame] | 2 |  * linux/drivers/video/console/softcursor.c | 
| Franck Bui-Huu | 024cd7e | 2006-12-08 02:40:48 -0800 | [diff] [blame] | 3 |  * | 
 | 4 |  * Generic software cursor for frame buffer devices | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 |  * | 
| Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 6 |  *  Created 14 Nov 2002 by James Simmons | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 |  * | 
| Franck Bui-Huu | 024cd7e | 2006-12-08 02:40:48 -0800 | [diff] [blame] | 8 |  * This file is subject to the terms and conditions of the GNU General | 
 | 9 |  * Public License.  See the file COPYING in the main directory of this | 
 | 10 |  * archive for more details. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 |  */ | 
 | 12 |  | 
 | 13 | #include <linux/module.h> | 
 | 14 | #include <linux/string.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/fb.h> | 
 | 16 | #include <linux/slab.h> | 
 | 17 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/io.h> | 
 | 19 |  | 
| Adrian Bunk | a0aa7d0 | 2006-01-09 20:54:04 -0800 | [diff] [blame] | 20 | #include "fbcon.h" | 
 | 21 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | int soft_cursor(struct fb_info *info, struct fb_cursor *cursor) | 
 | 23 | { | 
| Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 24 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | 	unsigned int scan_align = info->pixmap.scan_align - 1; | 
 | 26 | 	unsigned int buf_align = info->pixmap.buf_align - 1; | 
 | 27 | 	unsigned int i, size, dsize, s_pitch, d_pitch; | 
 | 28 | 	struct fb_image *image; | 
| Franck Bui-Huu | 024cd7e | 2006-12-08 02:40:48 -0800 | [diff] [blame] | 29 | 	u8 *src, *dst; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 |  | 
 | 31 | 	if (info->state != FBINFO_STATE_RUNNING) | 
 | 32 | 		return 0; | 
 | 33 |  | 
 | 34 | 	s_pitch = (cursor->image.width + 7) >> 3; | 
 | 35 | 	dsize = s_pitch * cursor->image.height; | 
 | 36 |  | 
| Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 37 | 	if (dsize + sizeof(struct fb_image) != ops->cursor_size) { | 
 | 38 | 		if (ops->cursor_src != NULL) | 
 | 39 | 			kfree(ops->cursor_src); | 
 | 40 | 		ops->cursor_size = dsize + sizeof(struct fb_image); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 |  | 
| Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 42 | 		ops->cursor_src = kmalloc(ops->cursor_size, GFP_ATOMIC); | 
 | 43 | 		if (!ops->cursor_src) { | 
 | 44 | 			ops->cursor_size = 0; | 
 | 45 | 			return -ENOMEM; | 
 | 46 | 		} | 
 | 47 | 	} | 
 | 48 |  | 
| Franck Bui-Huu | 024cd7e | 2006-12-08 02:40:48 -0800 | [diff] [blame] | 49 | 	src = ops->cursor_src + sizeof(struct fb_image); | 
 | 50 | 	image = (struct fb_image *)ops->cursor_src; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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++) | 
| Franck Bui-Huu | 024cd7e | 2006-12-08 02:40:48 -0800 | [diff] [blame] | 62 | 				src[i] = image->data[i] ^ cursor->mask[i]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | 			break; | 
 | 64 | 		case ROP_COPY: | 
 | 65 | 		default: | 
 | 66 | 			for (i = 0; i < dsize; i++) | 
| Franck Bui-Huu | 024cd7e | 2006-12-08 02:40:48 -0800 | [diff] [blame] | 67 | 				src[i] = image->data[i] & cursor->mask[i]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | 			break; | 
 | 69 | 		} | 
| Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 70 | 	} else | 
| Franck Bui-Huu | 024cd7e | 2006-12-08 02:40:48 -0800 | [diff] [blame] | 71 | 		memcpy(src, image->data, dsize); | 
| Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 72 |  | 
| Franck Bui-Huu | 024cd7e | 2006-12-08 02:40:48 -0800 | [diff] [blame] | 73 | 	fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | 	image->data = dst; | 
 | 75 | 	info->fbops->fb_imageblit(info, image); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | 	return 0; | 
 | 77 | } | 
 | 78 |  | 
 | 79 | EXPORT_SYMBOL(soft_cursor); | 
| Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 80 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>"); | 
 | 82 | MODULE_DESCRIPTION("Generic software cursor"); | 
 | 83 | MODULE_LICENSE("GPL"); |