-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fbdev: add fb_read/fb_write functions for framebuffers in system RAM
The functions fb_read() and fb_write in fbmem.c assume that the framebuffer is in IO memory. However, we have 3 drivers (hecubafb, arcfb, and vfb) where the framebuffer is allocated from system RAM (via vmalloc). Using __raw_read/__raw_write (fb_readl/fb_writel) for these drivers is illegal, especially in other platforms. Create file read and write methods for these types of drivers. These are named fb_sys_read() and fb_sys_write(). Signed-off-by: Antonino Daplas <adaplas@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
- Loading branch information
Antonino A. Daplas
authored and
Linus Torvalds
committed
May 8, 2007
1 parent
3f9b088
commit 09aaf26
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* linux/drivers/video/fb_sys_read.c - Generic file operations where | ||
* framebuffer is in system RAM | ||
* | ||
* Copyright (C) 2007 Antonino Daplas <adaplas@pol.net> | ||
* | ||
* This file is subject to the terms and conditions of the GNU General Public | ||
* License. See the file COPYING in the main directory of this archive | ||
* for more details. | ||
* | ||
*/ | ||
#include <linux/fb.h> | ||
#include <linux/module.h> | ||
#include <asm/uaccess.h> | ||
|
||
ssize_t fb_sys_read(struct fb_info *info, char __user *buf, size_t count, | ||
loff_t *ppos) | ||
{ | ||
unsigned long p = *ppos; | ||
void *src; | ||
int err = 0; | ||
unsigned long total_size; | ||
|
||
if (info->state != FBINFO_STATE_RUNNING) | ||
return -EPERM; | ||
|
||
total_size = info->screen_size; | ||
|
||
if (total_size == 0) | ||
total_size = info->fix.smem_len; | ||
|
||
if (p >= total_size) | ||
return 0; | ||
|
||
if (count >= total_size) | ||
count = total_size; | ||
|
||
if (count + p > total_size) | ||
count = total_size - p; | ||
|
||
src = (void __force *)(info->screen_base + p); | ||
|
||
if (info->fbops->fb_sync) | ||
info->fbops->fb_sync(info); | ||
|
||
if (copy_to_user(buf, src, count)) | ||
err = -EFAULT; | ||
|
||
if (!err) | ||
*ppos += count; | ||
|
||
return (err) ? err : count; | ||
} | ||
EXPORT_SYMBOL_GPL(fb_sys_read); | ||
|
||
ssize_t fb_sys_write(struct fb_info *info, const char __user *buf, | ||
size_t count, loff_t *ppos) | ||
{ | ||
unsigned long p = *ppos; | ||
void *dst; | ||
int err = 0; | ||
unsigned long total_size; | ||
|
||
if (info->state != FBINFO_STATE_RUNNING) | ||
return -EPERM; | ||
|
||
total_size = info->screen_size; | ||
|
||
if (total_size == 0) | ||
total_size = info->fix.smem_len; | ||
|
||
if (p > total_size) | ||
return -EFBIG; | ||
|
||
if (count > total_size) { | ||
err = -EFBIG; | ||
count = total_size; | ||
} | ||
|
||
if (count + p > total_size) { | ||
if (!err) | ||
err = -ENOSPC; | ||
|
||
count = total_size - p; | ||
} | ||
|
||
dst = (void __force *) (info->screen_base + p); | ||
|
||
if (info->fbops->fb_sync) | ||
info->fbops->fb_sync(info); | ||
|
||
if (copy_from_user(dst, buf, count)) | ||
err = -EFAULT; | ||
|
||
if (!err) | ||
*ppos += count; | ||
|
||
return (err) ? err : count; | ||
} | ||
EXPORT_SYMBOL_GPL(fb_sys_write); | ||
|
||
MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>"); | ||
MODULE_DESCRIPTION("Generic file read (fb in system RAM)"); | ||
MODULE_LICENSE("GPL"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters