Skip to content

Commit 33253d9

Browse files
author
Thomas Zimmermann
committed
fbdev: Move default fb_mmap code into helper function
Move the default fb_mmap code for I/O address spaces into the helper function fb_io_mmap(). The helper can either be called via struct fb_ops.fb_mmap or as the default if no fb_mmap has been set. Also set the new helper in __FB_DEFAULT_IOMEM_OPS_MMAP. In the mid-term, fb_io_mmap() is supposed to become optional. Fbdev drivers will initialize their struct fb_ops.fb_mmap to the helper and select a corresponding Kconfig token. The helper can then be made optional at compile time. Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Javier Martinez Canillas <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 76f9220 commit 33253d9

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

drivers/video/fbdev/core/fb_chrdev.c

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -314,56 +314,32 @@ static long fb_compat_ioctl(struct file *file, unsigned int cmd,
314314
static int fb_mmap(struct file *file, struct vm_area_struct *vma)
315315
{
316316
struct fb_info *info = file_fb_info(file);
317-
unsigned long mmio_pgoff;
318-
unsigned long start;
319-
u32 len;
317+
int res;
320318

321319
if (!info)
322320
return -ENODEV;
321+
323322
mutex_lock(&info->mm_lock);
324323

325324
if (info->fbops->fb_mmap) {
326-
int res;
327325

328326
res = info->fbops->fb_mmap(info, vma);
329-
mutex_unlock(&info->mm_lock);
330-
return res;
331327
#if IS_ENABLED(CONFIG_FB_DEFERRED_IO)
332328
} else if (info->fbdefio) {
333329
/*
334330
* FB deferred I/O wants you to handle mmap in your drivers. At a
335331
* minimum, point struct fb_ops.fb_mmap to fb_deferred_io_mmap().
336332
*/
337333
dev_warn_once(info->dev, "fbdev mmap not set up for deferred I/O.\n");
338-
mutex_unlock(&info->mm_lock);
339-
return -ENODEV;
334+
res = -ENODEV;
340335
#endif
336+
} else {
337+
res = fb_io_mmap(info, vma);
341338
}
342339

343-
/*
344-
* Ugh. This can be either the frame buffer mapping, or
345-
* if pgoff points past it, the mmio mapping.
346-
*/
347-
start = info->fix.smem_start;
348-
len = info->fix.smem_len;
349-
mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT;
350-
if (vma->vm_pgoff >= mmio_pgoff) {
351-
if (info->var.accel_flags) {
352-
mutex_unlock(&info->mm_lock);
353-
return -EINVAL;
354-
}
355-
356-
vma->vm_pgoff -= mmio_pgoff;
357-
start = info->fix.mmio_start;
358-
len = info->fix.mmio_len;
359-
}
360340
mutex_unlock(&info->mm_lock);
361341

362-
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
363-
vma->vm_page_prot = pgprot_framebuffer(vma->vm_page_prot, vma->vm_start,
364-
vma->vm_end, start);
365-
366-
return vm_iomap_memory(vma, start, len);
342+
return res;
367343
}
368344

369345
static int fb_open(struct inode *inode, struct file *file)

drivers/video/fbdev/core/fb_io_fops.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,32 @@ ssize_t fb_io_write(struct fb_info *info, const char __user *buf, size_t count,
132132
}
133133
EXPORT_SYMBOL(fb_io_write);
134134

135+
int fb_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
136+
{
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;
140+
141+
/*
142+
* This can be either the framebuffer mapping, or if pgoff points
143+
* past it, the mmio mapping.
144+
*/
145+
if (vma->vm_pgoff >= mmio_pgoff) {
146+
if (info->var.accel_flags)
147+
return -EINVAL;
148+
149+
vma->vm_pgoff -= mmio_pgoff;
150+
start = info->fix.mmio_start;
151+
len = info->fix.mmio_len;
152+
}
153+
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,
156+
vma->vm_end, start);
157+
158+
return vm_iomap_memory(vma, start, len);
159+
}
160+
EXPORT_SYMBOL(fb_io_mmap);
161+
135162
MODULE_DESCRIPTION("Fbdev helpers for framebuffers in I/O memory");
136163
MODULE_LICENSE("GPL");

include/linux/fb.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ extern ssize_t fb_io_read(struct fb_info *info, char __user *buf,
536536
size_t count, loff_t *ppos);
537537
extern ssize_t fb_io_write(struct fb_info *info, const char __user *buf,
538538
size_t count, loff_t *ppos);
539+
int fb_io_mmap(struct fb_info *info, struct vm_area_struct *vma);
539540

540541
#define __FB_DEFAULT_IOMEM_OPS_RDWR \
541542
.fb_read = fb_io_read, \
@@ -547,7 +548,7 @@ extern ssize_t fb_io_write(struct fb_info *info, const char __user *buf,
547548
.fb_imageblit = cfb_imageblit
548549

549550
#define __FB_DEFAULT_IOMEM_OPS_MMAP \
550-
.fb_mmap = NULL /* default implementation */
551+
.fb_mmap = fb_io_mmap
551552

552553
#define FB_DEFAULT_IOMEM_OPS \
553554
__FB_DEFAULT_IOMEM_OPS_RDWR, \

0 commit comments

Comments
 (0)