1 // SPDX-License-Identifier: GPL-2.0
4 #include <linux/module.h>
5 #include <linux/uaccess.h>
7 ssize_t fb_io_read(struct fb_info *info, char __user *buf, size_t count, loff_t *ppos)
9 unsigned long p = *ppos;
12 int c, cnt = 0, err = 0;
13 unsigned long total_size, trailing;
15 if (!info->screen_base)
18 total_size = info->screen_size;
21 total_size = info->fix.smem_len;
26 if (count >= total_size)
29 if (count + p > total_size)
30 count = total_size - p;
32 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
37 src = (u8 __iomem *) (info->screen_base + p);
39 if (info->fbops->fb_sync)
40 info->fbops->fb_sync(info);
43 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
45 fb_memcpy_fromio(dst, src, c);
49 trailing = copy_to_user(buf, buffer, c);
64 return cnt ? cnt : err;
66 EXPORT_SYMBOL(fb_io_read);
68 ssize_t fb_io_write(struct fb_info *info, const char __user *buf, size_t count, loff_t *ppos)
70 unsigned long p = *ppos;
73 int c, cnt = 0, err = 0;
74 unsigned long total_size, trailing;
76 if (!info->screen_base)
79 total_size = info->screen_size;
82 total_size = info->fix.smem_len;
87 if (count > total_size) {
92 if (count + p > total_size) {
96 count = total_size - p;
99 buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
104 dst = (u8 __iomem *) (info->screen_base + p);
106 if (info->fbops->fb_sync)
107 info->fbops->fb_sync(info);
110 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
113 trailing = copy_from_user(src, buf, c);
120 fb_memcpy_toio(dst, src, c);
131 return (cnt) ? cnt : err;
133 EXPORT_SYMBOL(fb_io_write);
135 int fb_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
137 unsigned long start = info->fix.smem_start;
138 u32 len = info->fix.smem_len;
139 unsigned long mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT;
142 * This can be either the framebuffer mapping, or if pgoff points
143 * past it, the mmio mapping.
145 if (vma->vm_pgoff >= mmio_pgoff) {
146 if (info->var.accel_flags)
149 vma->vm_pgoff -= mmio_pgoff;
150 start = info->fix.mmio_start;
151 len = info->fix.mmio_len;
154 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
155 vma->vm_page_prot = pgprot_framebuffer(vma->vm_page_prot, vma->vm_start,
158 return vm_iomap_memory(vma, start, len);
160 EXPORT_SYMBOL(fb_io_mmap);
162 MODULE_DESCRIPTION("Fbdev helpers for framebuffers in I/O memory");
163 MODULE_LICENSE("GPL");