mbox series

[00/32] fbdev: Modularize helpers for struct fb_ops

Message ID 20231115102954.7102-1-tzimmermann@suse.de
Headers show
Series fbdev: Modularize helpers for struct fb_ops | expand

Message

Thomas Zimmermann Nov. 15, 2023, 10:19 a.m. UTC
Convert the remaining fbdev drivers to use fbdev's helpers macros
for struct fb_ops. Then push the current default code for file-I/O
operations into a module and remove it as default. Each driver now
selects the helpers its needs for file I/O and drawing to its
framebuffer. If no helper has been set for an operation in struct
fb_ops, the operation is unsupported. Once applied, fbdev drivers
will not include unnecessary helper code. The helpers will also be
more robust against mis-use.

The first 2 patches are bug fixes. Patches 3 to 26 modify fbdev
drivers to set up their fb_ops structures correctly and select the
necessary helpers.

Patches 27 and 28 do a few additional minor cleanups.

Patches 29 to 32 move all helpers for struct fb_ops into modules
and drop the default. Helpers also warn if they operate on the
wrong type of framebuffer memory. Framebuffers in I/O memory and
system memory can only be used with the correct helper functions.

Thomas Zimmermann (32):
  fbdev/acornfb: Fix name of fb_ops initializer macro
  fbdev/sm712fb: Use correct initializer macros for struct fb_ops
  fbdev/vfb: Set FBINFO_VIRTFB flag
  fbdev/vfb: Initialize fb_ops with fbdev macros
  fbdev/arcfb: Set FBINFO_VIRTFB flag
  fbdev/arcfb: Use generator macros for deferred I/O
  auxdisplay/cfag12864bfb: Set FBINFO_VIRTFB flag
  auxdisplay/cfag12864bfb: Initialize fb_ops with fbdev macros
  auxdisplay/ht16k33: Set FBINFO_VIRTFB flag
  auxdisplay/ht16k33: Initialize fb_ops with fbdev macros
  hid/picolcd_fb: Set FBINFO_VIRTFB flag
  fbdev/sh_mobile_lcdcfb: Set FBINFO_VIRTFB flag
  fbdev/sh_mobile_lcdcfb: Initialize fb_ops with fbdev macros
  fbdev/smscufx: Select correct helpers
  fbdev/udlfb: Select correct helpers
  fbdev/au1200fb: Set FBINFO_VIRTFB flag
  fbdev/au1200fb: Initialize fb_ops with fbdev macros
  fbdev/ps3fb: Set FBINFO_VIRTFB flag
  fbdev/ps3fb: Initialize fb_ops with fbdev macros
  media/ivtvfb: Initialize fb_ops to fbdev I/O-memory helpers
  fbdev/clps711x-fb: Initialize fb_ops with fbdev macros
  fbdev/vt8500lcdfb: Initialize fb_ops with fbdev macros
  fbdev/wm8505fb: Initialize fb_ops to fbdev I/O-memory helpers
  fbdev/cyber2000fb: Initialize fb_ops with fbdev macros
  staging/sm750fb: Declare fb_ops as constant
  staging/sm750fb: Initialize fb_ops with fbdev macros
  fbdev: Rename FB_SYS_FOPS token to FB_SYSMEM_FOPS
  fbdev: Remove trailing whitespaces
  fbdev: Push pgprot_decrypted() into mmap implementations
  fbdev: Move default fb_mmap code into helper function
  fbdev: Warn on incorrect framebuffer access
  fbdev: Remove default file-I/O implementations

 drivers/auxdisplay/Kconfig                    |  10 +-
 drivers/auxdisplay/cfag12864bfb.c             |  10 +-
 drivers/auxdisplay/ht16k33.c                  |  10 +-
 drivers/hid/hid-picolcd_fb.c                  |   1 +
 drivers/media/pci/ivtv/Kconfig                |   4 +-
 drivers/media/pci/ivtv/ivtvfb.c               |   6 +-
 drivers/staging/sm750fb/sm750.c               |  65 ++++++++--
 drivers/video/fbdev/Kconfig                   |  50 ++------
 drivers/video/fbdev/acornfb.c                 |   2 +-
 drivers/video/fbdev/amba-clcd.c               |   2 +
 drivers/video/fbdev/arcfb.c                   | 114 +++++-------------
 drivers/video/fbdev/au1100fb.c                |   2 +
 drivers/video/fbdev/au1200fb.c                |  11 +-
 drivers/video/fbdev/clps711x-fb.c             |   4 +-
 drivers/video/fbdev/core/Kconfig              |   7 +-
 drivers/video/fbdev/core/Makefile             |   2 +-
 drivers/video/fbdev/core/cfbcopyarea.c        |   3 +
 drivers/video/fbdev/core/cfbfillrect.c        |   3 +
 drivers/video/fbdev/core/cfbimgblt.c          |   3 +
 drivers/video/fbdev/core/fb_chrdev.c          |  68 ++---------
 drivers/video/fbdev/core/fb_defio.c           |   2 +
 drivers/video/fbdev/core/fb_io_fops.c         |  36 ++++++
 drivers/video/fbdev/core/fb_sys_fops.c        |   6 +
 drivers/video/fbdev/core/syscopyarea.c        |   3 +
 drivers/video/fbdev/core/sysfillrect.c        |   3 +
 drivers/video/fbdev/core/sysimgblt.c          |   3 +
 drivers/video/fbdev/cyber2000fb.c             |   9 +-
 drivers/video/fbdev/ep93xx-fb.c               |   2 +
 drivers/video/fbdev/gbefb.c                   |   2 +
 drivers/video/fbdev/omap/omapfb_main.c        |   2 +
 .../video/fbdev/omap2/omapfb/omapfb-main.c    |   2 +
 drivers/video/fbdev/ps3fb.c                   |  11 +-
 drivers/video/fbdev/sa1100fb.c                |   2 +
 drivers/video/fbdev/sbuslib.c                 |   5 +-
 drivers/video/fbdev/sh_mobile_lcdcfb.c        |  16 +--
 drivers/video/fbdev/sm712fb.c                 |   6 +-
 drivers/video/fbdev/smscufx.c                 |   2 +
 drivers/video/fbdev/udlfb.c                   |   2 +
 drivers/video/fbdev/vermilion/vermilion.c     |   2 +
 drivers/video/fbdev/vfb.c                     |  10 +-
 drivers/video/fbdev/vt8500lcdfb.c             |   4 +-
 drivers/video/fbdev/wm8505fb.c                |   2 +
 include/linux/fb.h                            |  11 +-
 43 files changed, 254 insertions(+), 266 deletions(-)


base-commit: ab54663d6cd21c6748f91c1cc0fe3456d4e38ce6

Comments

Javier Martinez Canillas Nov. 16, 2023, 9:45 a.m. UTC | #1
Thomas Zimmermann <tzimmermann@suse.de> writes:

> Fix build by using the correct name for the initializer macro
> for struct fb_ops.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Fixes: 9037afde8b9d ("fbdev/acornfb: Use fbdev I/O helpers")
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Javier Martinez Canillas <javierm@redhat.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: <stable@vger.kernel.org> # v6.6+
> ---

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 9:46 a.m. UTC | #2
Thomas Zimmermann <tzimmermann@suse.de> writes:

> Only initialize mmap and draw helpers with macros; leave read/write
> callbacks to driver implementations. Fixes the following warnings:
>
>   CC [M]  drivers/video/fbdev/sm712fb.o
>   sm712fb.c:1355:25: warning: initialized field overwritten [-Woverride-init]
>   1355 |         .fb_fillrect  = cfb_fillrect,
>        |                         ^~~~~~~~~~~~
>   sm712fb.c:1355:25: note: (near initialization for 'smtcfb_ops.fb_fillrect')
>   sm712fb.c:1356:25: warning: initialized field overwritten [-Woverride-init]
>   1356 |         .fb_imageblit = cfb_imageblit,
>        |                         ^~~~~~~~~~~~~
>   sm712fb.c:1356:25: note: (near initialization for 'smtcfb_ops.fb_imageblit')
>   sm712fb.c:1357:25: warning: initialized field overwritten [-Woverride-init]
>   1357 |         .fb_copyarea  = cfb_copyarea,
>        |                         ^~~~~~~~~~~~
>   sm712fb.c:1357:25: note: (near initialization for 'smtcfb_ops.fb_copyarea')
>   sm712fb.c:1358:25: warning: initialized field overwritten [-Woverride-init]
>   1358 |         .fb_read      = smtcfb_read,
>        |                         ^~~~~~~~~~~
>   sm712fb.c:1358:25: note: (near initialization for 'smtcfb_ops.fb_read')
>   sm712fb.c:1359:25: warning: initialized field overwritten [-Woverride-init]
>   1359 |         .fb_write     = smtcfb_write,
>        |                         ^~~~~~~~~~~~
>   sm712fb.c:1359:25: note: (near initialization for 'smtcfb_ops.fb_write')
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Fixes: 586132cf1d38 ("fbdev/sm712fb: Initialize fb_ops to fbdev I/O-memory helpers")
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Javier Martinez Canillas <javierm@redhat.com>
> Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> Cc: Teddy Wang <teddy.wang@siliconmotion.com>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: linux-fbdev@vger.kernel.org
> ---
>  drivers/video/fbdev/sm712fb.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 10:16 a.m. UTC | #3
Thomas Zimmermann <tzimmermann@suse.de> writes:

> The cfag12864bfb driver operates on system memory. Mark the framebuffer
> accordingly. Helpers operating on the framebuffer memory will test for
> the presence of this flag.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Miguel Ojeda <ojeda@kernel.org>
> ---
>  drivers/auxdisplay/cfag12864bfb.c | 1 +
>  1 file changed, 1 insertion(+)
>

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 10:23 a.m. UTC | #4
Thomas Zimmermann <tzimmermann@suse.de> writes:

> Initialize the instance of struct fb_ops with fbdev initializer
> macros for framebuffers in virtual address space. Set the read/write,
> draw and mmap callbacks to the correct implementation and avoid
> implicit defaults. Also select the necessary helpers in Kconfig.
>
> Fbdev drivers sometimes rely on the callbacks being NULL for a
> default I/O-memory-based implementation to be invoked; hence
> requiring the I/O helpers to be built in any case. Setting all
> callbacks in all drivers explicitly will allow to make the I/O
> helpers optional. This benefits systems that do not use these
> functions.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Miguel Ojeda <ojeda@kernel.org>
> Cc: Robin van der Gracht <robin@protonic.nl>
> ---
>  drivers/auxdisplay/Kconfig   | 5 +----
>  drivers/auxdisplay/ht16k33.c | 7 ++-----
>  2 files changed, 3 insertions(+), 9 deletions(-)
>

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 10:27 a.m. UTC | #5
Thomas Zimmermann <tzimmermann@suse.de> writes:

> The picolcd_fb driver operates on system memory. Mark the framebuffer
> accordingly. Helpers operating on the framebuffer memory will test
> for the presence of this flag.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: "Bruno Prémont" <bonbons@linux-vserver.org>
> Cc: Jiri Kosina <jikos@kernel.org>
> Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> Cc: linux-input@vger.kernel.org
> ---
>  drivers/hid/hid-picolcd_fb.c | 1 +
>  1 file changed, 1 insertion(+)
>

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 10:29 a.m. UTC | #6
Thomas Zimmermann <tzimmermann@suse.de> writes:

> The sh_mobile_lcdcfb driver operates on DMA-able system memory. Mark
> the framebuffer accordingly. Helpers operating on the framebuffer memory
> will test for the presence of this flag.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 10:46 a.m. UTC | #7
Thomas Zimmermann <tzimmermann@suse.de> writes:

> The driver uses deferred I/O. Select the correct helpers via
> FB_SYSMEM_HELPERS_DEFERRED in the Kconfig file.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 10:46 a.m. UTC | #8
Thomas Zimmermann <tzimmermann@suse.de> writes:

> The driver uses deferred I/O. Select the correct helpers via
> FB_SYSMEM_HELPERS_DEFERRED in the Kconfig file.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 10:47 a.m. UTC | #9
Thomas Zimmermann <tzimmermann@suse.de> writes:

> The au1200fb driver operates on DMA-able system memory. Mark the
> framebuffer accordingly. Helpers operating on the framebuffer memory
> will test for the presence of this flag.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 10:48 a.m. UTC | #10
Thomas Zimmermann <tzimmermann@suse.de> writes:

> Initialize the instance of struct fb_ops with fbdev initializer
> macros for framebuffers in DMA-able virtual address space. Set the
> read/write, draw and mmap callbacks to the correct implementation
> and avoid implicit defaults. Also select the necessary helpers in
> Kconfig.
>
> Fbdev drivers sometimes rely on the callbacks being NULL for a
> default I/O-memory-based implementation to be invoked; hence
> requiring the I/O helpers to be built in any case. Setting all
> callbacks in all drivers explicitly will allow to make the I/O
> helpers optional. This benefits systems that do not use these
> functions.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 11:30 a.m. UTC | #11
Thomas Zimmermann <tzimmermann@suse.de> writes:

> Initialize the instance of struct fb_ops with fbdev initializer
> macros for framebuffers in DMA-able virtual address space. Set the
> read/write, draw and mmap callbacks to the correct implementation
> and avoid implicit defaults. Also select the necessary helpers in
> Kconfig.
>
> Fbdev drivers sometimes rely on the callbacks being NULL for a
> default I/O-memory-based implementation to be invoked; hence
> requiring the I/O helpers to be built in any case. Setting all
> callbacks in all drivers explicitly will allow to make the I/O
> helpers optional. This benefits systems that do not use these
> functions.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 11:34 a.m. UTC | #12
Thomas Zimmermann <tzimmermann@suse.de> writes:

> Initialize the instance of struct fb_ops with fbdev initializer
> macros for framebuffers in DMA-able address space. This explictily
> sets the read/write, draw and mmap callbacks to the correct default
> implementation. Also select the necessary helpers in Kconfig.
>
> Fbdev drivers sometimes rely on the callbacks being NULL for a
> default implementation to be invoked; hence requireing the I/O
> helpers to be built in any case. Setting all callbacks in all
> drivers explicitly will allow to make the I/O helpers optional.
> This benefits systems that do not use these functions.
>
> Set the callbacks via macros. No functional changes.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 11:57 a.m. UTC | #13
Thomas Zimmermann <tzimmermann@suse.de> writes:

> Initialize all instances of struct fb_ops with fbdev initializer
> macros for framebuffers in I/O address space. Set the read/write,
> draw and mmap callbacks to the correct implementation and avoid
> implicit defaults. Also select the necessary helpers in Kconfig.
>
> Fbdev drivers sometimes rely on the callbacks being NULL for a
> default I/O-memory-based implementation to be invoked; hence
> requiring the I/O helpers to be built in any case. Setting all
> callbacks in all drivers explicitly will allow to make the I/O
> helpers optional. This benefits systems that do not use these
> functions.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> Cc: Teddy Wang <teddy.wang@siliconmotion.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: linux-staging@lists.linux.dev
> ---
>  drivers/staging/sm750fb/sm750.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 12:05 p.m. UTC | #14
Thomas Zimmermann <tzimmermann@suse.de> writes:

> Rename the token to harmonize naming among various helpers. For
> example, I/O-memory helpers use FB_IOMEM_FOPS.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

I wonder if the object names should also be changed to fb_iomem_fops.o
and fb_sysmem_fops.o for consistency with the Kconfig symbols names.

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 1:04 p.m. UTC | #15
Thomas Zimmermann <tzimmermann@suse.de> writes:

> If a driver sets struct fb_ops.fb_mmap, the fbdev core automatically
> calls pgprot_decrypted(). But the default fb_mmap code doesn't handle
> pgprot_decrypted().
>
> Move the call to pgprot_decrypted() into each drivers' fb_mmap function.
> This only concerns fb_mmap functions for system and DMA memory. For
> I/O memory, which is the default case, nothing changes. The fb_mmap
> for I/O-memory can later be moved into a helper as well.
>
> DRM's fbdev emulation handles pgprot_decrypted() internally via the
> Prime helpers. Fbdev doesn't have to do anything in this case. In
> cases where DRM uses deferred I/O, this patch updates fb_mmap correctly.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Javier Martinez Canillas Nov. 16, 2023, 1:15 p.m. UTC | #16
Thomas Zimmermann <tzimmermann@suse.de> writes:

> Drop the default implementations for file read, write and mmap
> operations. Each fbdev driver must now provide an implementation
> and select any necessary helpers. If no implementation has been
> set, fbdev returns an errno code to user space. The code is the
> same as if the operation had not been set in the file_operations
> struct.
>
> This change makes the fbdev helpers for I/O memory optional. Most
> systems only use system-memory framebuffers via DRM's fbdev emulation.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

[...]

> @@ -34,13 +34,13 @@ static ssize_t fb_read(struct file *file, char __user *buf, size_t count, loff_t
>  	if (!info)
>  		return -ENODEV;
>  
> +	if (!info->fbops->fb_read)
> +		return -EINVAL;
> +

Can we also add a warn here? In case that it was missed to set a driver
callback. Probably can be figured out from the -EINVAL but better to be
explicit about the issue to make finding that easier.

And same for the other fops.

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Bruno Prémont Nov. 17, 2023, 8:51 a.m. UTC | #17
On Thu, 16 Nov 2023 11:27:55 +0100 Javier Martinez Canillas wrote:
> Thomas Zimmermann <tzimmermann@suse.de> writes:
> 
> > The picolcd_fb driver operates on system memory. Mark the framebuffer
> > accordingly. Helpers operating on the framebuffer memory will test
> > for the presence of this flag.
> >
> > Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> > Cc: "Bruno Prémont" <bonbons@linux-vserver.org>
> > Cc: Jiri Kosina <jikos@kernel.org>
> > Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> > Cc: linux-input@vger.kernel.org
> > ---
> >  drivers/hid/hid-picolcd_fb.c | 1 +
> >  1 file changed, 1 insertion(+)
> >  
> 
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

Acked-by: Bruno Prémont  <bonbons@linux-vserver.org>