Skip to content

Commit f1061fa

Browse files
committed
fbdev: Add initializer macros for struct fb_ops
For framebuffers in I/O and system memory, add macros that set struct fb_ops to the respective callback functions. For deferred I/O, add macros that generate callback functions with damage handling. Add initializer macros that set struct fb_ops to the generated callbacks. These macros can remove a lot boilerplate code from fbdev drivers. The drivers are supposed to use the macro that is required for its framebuffer. Each macro is split into smaller helpers, so that drivers with non-standard callbacks can pick and customize callbacks as needed. There are individual helper macros for read/write, mmap and drawing. v5: * fix whitespace errors (Jingfeng) Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Link: https://patchwork.freedesktop.org/patch/msgid/20230530151228.22979-3-tzimmermann@suse.de
1 parent 3b99ee5 commit f1061fa

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

include/linux/fb.h

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,31 @@ extern ssize_t fb_io_read(struct fb_info *info, char __user *buf,
538538
extern ssize_t fb_io_write(struct fb_info *info, const char __user *buf,
539539
size_t count, loff_t *ppos);
540540

541+
/*
542+
* Initializes struct fb_ops for framebuffers in I/O memory.
543+
*/
544+
545+
#define __FB_DEFAULT_IO_OPS_RDWR \
546+
.fb_read = fb_io_read, \
547+
.fb_write = fb_io_write
548+
549+
#define __FB_DEFAULT_IO_OPS_DRAW \
550+
.fb_fillrect = cfb_fillrect, \
551+
.fb_copyarea = cfb_copyarea, \
552+
.fb_imageblit = cfb_imageblit
553+
554+
#define __FB_DEFAULT_IO_OPS_MMAP \
555+
.fb_mmap = NULL // default implementation
556+
557+
#define FB_DEFAULT_IO_OPS \
558+
__FB_DEFAULT_IO_OPS_RDWR, \
559+
__FB_DEFAULT_IO_OPS_DRAW, \
560+
__FB_DEFAULT_IO_OPS_MMAP
561+
541562
/*
542563
* Drawing operations where framebuffer is in system RAM
543564
*/
565+
544566
extern void sys_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
545567
extern void sys_copyarea(struct fb_info *info, const struct fb_copyarea *area);
546568
extern void sys_imageblit(struct fb_info *info, const struct fb_image *image);
@@ -549,6 +571,27 @@ extern ssize_t fb_sys_read(struct fb_info *info, char __user *buf,
549571
extern ssize_t fb_sys_write(struct fb_info *info, const char __user *buf,
550572
size_t count, loff_t *ppos);
551573

574+
/*
575+
* Initializes struct fb_ops for framebuffers in system memory.
576+
*/
577+
578+
#define __FB_DEFAULT_SYS_OPS_RDWR \
579+
.fb_read = fb_sys_read, \
580+
.fb_write = fb_sys_write
581+
582+
#define __FB_DEFAULT_SYS_OPS_DRAW \
583+
.fb_fillrect = sys_fillrect, \
584+
.fb_copyarea = sys_copyarea, \
585+
.fb_imageblit = sys_imageblit
586+
587+
#define __FB_DEFAULT_SYS_OPS_MMAP \
588+
.fb_mmap = NULL // default implementation
589+
590+
#define FB_DEFAULT_SYS_OPS \
591+
__FB_DEFAULT_SYS_OPS_RDWR, \
592+
__FB_DEFAULT_SYS_OPS_DRAW, \
593+
__FB_DEFAULT_SYS_OPS_MMAP
594+
552595
/* drivers/video/fbmem.c */
553596
extern int register_framebuffer(struct fb_info *fb_info);
554597
extern void unregister_framebuffer(struct fb_info *fb_info);
@@ -604,6 +647,75 @@ extern void fb_deferred_io_cleanup(struct fb_info *info);
604647
extern int fb_deferred_io_fsync(struct file *file, loff_t start,
605648
loff_t end, int datasync);
606649

650+
/*
651+
* Generate callbacks for deferred I/O
652+
*/
653+
654+
#define __FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, __mode) \
655+
static ssize_t __prefix ## _defio_read(struct fb_info *info, char __user *buf, \
656+
size_t count, loff_t *ppos) \
657+
{ \
658+
return fb_ ## __mode ## _read(info, buf, count, ppos); \
659+
} \
660+
static ssize_t __prefix ## _defio_write(struct fb_info *info, const char __user *buf, \
661+
size_t count, loff_t *ppos) \
662+
{ \
663+
unsigned long offset = *ppos; \
664+
ssize_t ret = fb_ ## __mode ## _write(info, buf, count, ppos); \
665+
if (ret > 0) \
666+
__damage_range(info, offset, ret); \
667+
return ret; \
668+
}
669+
670+
#define __FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, __mode) \
671+
static void __prefix ## _defio_fillrect(struct fb_info *info, \
672+
const struct fb_fillrect *rect) \
673+
{ \
674+
__mode ## _fillrect(info, rect); \
675+
__damage_area(info, rect->dx, rect->dy, rect->width, rect->height); \
676+
} \
677+
static void __prefix ## _defio_copyarea(struct fb_info *info, \
678+
const struct fb_copyarea *area) \
679+
{ \
680+
__mode ## _copyarea(info, area); \
681+
__damage_area(info, area->dx, area->dy, area->width, area->height); \
682+
} \
683+
static void __prefix ## _defio_imageblit(struct fb_info *info, \
684+
const struct fb_image *image) \
685+
{ \
686+
__mode ## _imageblit(info, image); \
687+
__damage_area(info, image->dx, image->dy, image->width, image->height); \
688+
}
689+
690+
#define FB_GEN_DEFAULT_DEFERRED_IO_OPS(__prefix, __damage_range, __damage_area) \
691+
__FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, io) \
692+
__FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, cfb)
693+
694+
#define FB_GEN_DEFAULT_DEFERRED_SYS_OPS(__prefix, __damage_range, __damage_area) \
695+
__FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, sys) \
696+
__FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, sys)
697+
698+
/*
699+
* Initializes struct fb_ops for deferred I/O.
700+
*/
701+
702+
#define __FB_DEFAULT_DEFERRED_OPS_RDWR(__prefix) \
703+
.fb_read = __prefix ## _defio_read, \
704+
.fb_write = __prefix ## _defio_write
705+
706+
#define __FB_DEFAULT_DEFERRED_OPS_DRAW(__prefix) \
707+
.fb_fillrect = __prefix ## _defio_fillrect, \
708+
.fb_copyarea = __prefix ## _defio_copyarea, \
709+
.fb_imageblit = __prefix ## _defio_imageblit
710+
711+
#define __FB_DEFAULT_DEFERRED_OPS_MMAP(__prefix) \
712+
.fb_mmap = fb_deferred_io_mmap
713+
714+
#define FB_DEFAULT_DEFERRED_OPS(__prefix) \
715+
__FB_DEFAULT_DEFERRED_OPS_RDWR(__prefix), \
716+
__FB_DEFAULT_DEFERRED_OPS_DRAW(__prefix), \
717+
__FB_DEFAULT_DEFERRED_OPS_MMAP(__prefix)
718+
607719
static inline bool fb_be_math(struct fb_info *info)
608720
{
609721
#ifdef CONFIG_FB_FOREIGN_ENDIAN

0 commit comments

Comments
 (0)