2023-04-26 13:05:58

by Thomas Zimmermann

[permalink] [raw]
Subject: [PATCH 0/5] fbdev: Move framebuffer I/O helpers to <asm/fb.h>

Fbdev provides helpers for framebuffer I/O, such as fb_readl(),
fb_writel() or fb_memcpy_to_fb(). The implementation of each helper
depends on the architecture. It's still all located in fbdev's main
header file <linux/fb.h>. Move all of it into each archtecture's
<asm/fb.h>, with shared code in <asm-generic/fb.h>.

The first patch a simple whitespace cleanup.

Until now, <linux/fb.h> contained an include of <asm/io.h>. As this
will go away patches 2 to 4 prepare include statements in the various
drivers. Source files that use regular I/O helpers, such as readl(),
now include <linux/io.h>. Source files that use framebuffer I/O
helpers, such as fb_readl(), now include <asm/fb.h>. The latter now
includes <linux/io.h> internally.

Patch 5 moves the framebuffer I/O helpers from <linux/fb.h> into
the various architecture headers. The common case, where the framebuffer
is located in I/O memory, serves as the generic implemenation.

The patchset has been built for a variety of platforms, such as x86-64,
arm, aarch64, ppc64, parisc, m64k, mips and sparc.

Thomas Zimmermann (5):
fbdev/matrox: Remove trailing whitespaces
ipu-v3: Include <linux/io.h>
fbdev: Include <linux/io.h> in various drivers
fbdev: Include <linux/io.h> via <asm/fb.h>
fbdev: Move framebuffer I/O helpers into <asm/fb.h>

arch/arc/include/asm/fb.h | 29 +++++++
arch/ia64/include/asm/fb.h | 28 +++++++
arch/loongarch/include/asm/fb.h | 29 +++++++
arch/m68k/include/asm/fb.h | 29 +++++++
arch/sparc/include/asm/fb.h | 77 +++++++++++++++++
drivers/gpu/ipu-v3/ipu-prv.h | 1 +
drivers/video/fbdev/arcfb.c | 1 +
drivers/video/fbdev/arkfb.c | 2 +
drivers/video/fbdev/aty/atyfb.h | 2 +
drivers/video/fbdev/aty/mach64_cursor.c | 2 +-
drivers/video/fbdev/chipsfb.c | 1 +
drivers/video/fbdev/cirrusfb.c | 2 +
drivers/video/fbdev/core/cfbcopyarea.c | 2 +-
drivers/video/fbdev/core/cfbfillrect.c | 1 +
drivers/video/fbdev/core/cfbimgblt.c | 1 +
drivers/video/fbdev/core/svgalib.c | 3 +-
drivers/video/fbdev/cyber2000fb.c | 2 +
drivers/video/fbdev/ep93xx-fb.c | 2 +
drivers/video/fbdev/hgafb.c | 3 +-
drivers/video/fbdev/hitfb.c | 2 +-
drivers/video/fbdev/kyro/fbdev.c | 3 +-
drivers/video/fbdev/matrox/matroxfb_accel.c | 8 +-
drivers/video/fbdev/matrox/matroxfb_base.h | 6 +-
drivers/video/fbdev/pm2fb.c | 3 +
drivers/video/fbdev/pm3fb.c | 2 +
drivers/video/fbdev/pvr2fb.c | 2 +
drivers/video/fbdev/s3fb.c | 2 +
drivers/video/fbdev/sm712fb.c | 2 +
drivers/video/fbdev/sstfb.c | 2 +-
drivers/video/fbdev/stifb.c | 2 +
drivers/video/fbdev/tdfxfb.c | 3 +-
drivers/video/fbdev/tridentfb.c | 2 +
drivers/video/fbdev/vga16fb.c | 3 +-
drivers/video/fbdev/vt8623fb.c | 2 +
drivers/video/fbdev/wmt_ge_rops.c | 2 +
include/asm-generic/fb.h | 93 +++++++++++++++++++++
include/linux/fb.h | 53 ------------
37 files changed, 340 insertions(+), 69 deletions(-)

--
2.40.0


2023-04-26 13:06:39

by Thomas Zimmermann

[permalink] [raw]
Subject: [PATCH 1/5] fbdev/matrox: Remove trailing whitespaces

Fix coding style. No functional changes.

Signed-off-by: Thomas Zimmermann <[email protected]>
---
drivers/video/fbdev/matrox/matroxfb_accel.c | 6 +++---
drivers/video/fbdev/matrox/matroxfb_base.h | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbdev/matrox/matroxfb_accel.c b/drivers/video/fbdev/matrox/matroxfb_accel.c
index 9cb0685feddd..ce51227798a1 100644
--- a/drivers/video/fbdev/matrox/matroxfb_accel.c
+++ b/drivers/video/fbdev/matrox/matroxfb_accel.c
@@ -88,7 +88,7 @@

static inline void matrox_cfb4_pal(u_int32_t* pal) {
unsigned int i;
-
+
for (i = 0; i < 16; i++) {
pal[i] = i * 0x11111111U;
}
@@ -96,7 +96,7 @@ static inline void matrox_cfb4_pal(u_int32_t* pal) {

static inline void matrox_cfb8_pal(u_int32_t* pal) {
unsigned int i;
-
+
for (i = 0; i < 16; i++) {
pal[i] = i * 0x01010101U;
}
@@ -482,7 +482,7 @@ static void matroxfb_1bpp_imageblit(struct matrox_fb_info *minfo, u_int32_t fgx,
/* Tell... well, why bother... */
while (height--) {
size_t i;
-
+
for (i = 0; i < step; i += 4) {
/* Hope that there are at least three readable bytes beyond the end of bitmap */
fb_writel(get_unaligned((u_int32_t*)(chardata + i)),mmio.vaddr);
diff --git a/drivers/video/fbdev/matrox/matroxfb_base.h b/drivers/video/fbdev/matrox/matroxfb_base.h
index 958be6805f87..c93c69bbcd57 100644
--- a/drivers/video/fbdev/matrox/matroxfb_base.h
+++ b/drivers/video/fbdev/matrox/matroxfb_base.h
@@ -301,9 +301,9 @@ struct matrox_altout {
int (*verifymode)(void* altout_dev, u_int32_t mode);
int (*getqueryctrl)(void* altout_dev,
struct v4l2_queryctrl* ctrl);
- int (*getctrl)(void* altout_dev,
+ int (*getctrl)(void *altout_dev,
struct v4l2_control* ctrl);
- int (*setctrl)(void* altout_dev,
+ int (*setctrl)(void *altout_dev,
struct v4l2_control* ctrl);
};

--
2.40.0

2023-04-26 13:07:11

by Thomas Zimmermann

[permalink] [raw]
Subject: [PATCH 4/5] fbdev: Include <linux/io.h> via <asm/fb.h>

Fbdev's main header file, <linux/fb.h>, includes <asm/io.h> to get
declarations for I/O helper functions. From these declaratons, later
defines framebuffer I/O helpers, such as fb_{read,write}[bwlq]() or
fb_memset().

The framebuffer I/O helpers depend on the system architecture and
will therefore be moved into <asm/fb.h>. Prepare this change by first
adding an include statement for <linux/io.h> to <asm-generic/fb.h>.
Include <asm/fb.h> in all source files that use the framebuffer I/O
helpers, so that they still get the necessary I/O functions.

Signed-off-by: Thomas Zimmermann <[email protected]>
---
drivers/video/fbdev/arkfb.c | 2 ++
drivers/video/fbdev/aty/mach64_cursor.c | 2 +-
drivers/video/fbdev/chipsfb.c | 1 +
drivers/video/fbdev/cirrusfb.c | 2 ++
drivers/video/fbdev/core/cfbcopyarea.c | 2 +-
drivers/video/fbdev/core/cfbfillrect.c | 1 +
drivers/video/fbdev/core/cfbimgblt.c | 1 +
drivers/video/fbdev/core/svgalib.c | 3 +--
drivers/video/fbdev/cyber2000fb.c | 2 ++
drivers/video/fbdev/ep93xx-fb.c | 2 ++
drivers/video/fbdev/hgafb.c | 3 ++-
drivers/video/fbdev/hitfb.c | 2 +-
drivers/video/fbdev/kyro/fbdev.c | 3 ++-
drivers/video/fbdev/matrox/matroxfb_accel.c | 2 ++
drivers/video/fbdev/matrox/matroxfb_base.h | 2 +-
drivers/video/fbdev/pm2fb.c | 3 +++
drivers/video/fbdev/pm3fb.c | 2 ++
drivers/video/fbdev/pvr2fb.c | 2 ++
drivers/video/fbdev/s3fb.c | 2 ++
drivers/video/fbdev/sm712fb.c | 2 ++
drivers/video/fbdev/sstfb.c | 2 +-
drivers/video/fbdev/stifb.c | 2 ++
drivers/video/fbdev/tdfxfb.c | 3 ++-
drivers/video/fbdev/tridentfb.c | 2 ++
drivers/video/fbdev/vga16fb.c | 3 ++-
drivers/video/fbdev/vt8623fb.c | 2 ++
include/asm-generic/fb.h | 1 +
27 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/drivers/video/fbdev/arkfb.c b/drivers/video/fbdev/arkfb.c
index 60a96fdb5dd8..fd38e8a073b8 100644
--- a/drivers/video/fbdev/arkfb.c
+++ b/drivers/video/fbdev/arkfb.c
@@ -27,6 +27,8 @@
#include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */
#include <video/vga.h>

+#include <asm/fb.h>
+
struct arkfb_info {
int mclk_freq;
int wc_cookie;
diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
index 4ad0331a8c57..a848aaff510c 100644
--- a/drivers/video/fbdev/aty/mach64_cursor.c
+++ b/drivers/video/fbdev/aty/mach64_cursor.c
@@ -8,7 +8,7 @@
#include <linux/string.h>
#include "../core/fb_draw.h"

-#include <asm/io.h>
+#include <asm/fb.h>

#ifdef __sparc__
#include <asm/fbio.h>
diff --git a/drivers/video/fbdev/chipsfb.c b/drivers/video/fbdev/chipsfb.c
index 7799d52a651f..9f9ee13ba2be 100644
--- a/drivers/video/fbdev/chipsfb.c
+++ b/drivers/video/fbdev/chipsfb.c
@@ -32,6 +32,7 @@
#ifdef CONFIG_PMAC_BACKLIGHT
#include <asm/backlight.h>
#endif
+#include <asm/fb.h>

/*
* Since we access the display with inb/outb to fixed port numbers,
diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c
index ba45e2147c52..cc306b3733e2 100644
--- a/drivers/video/fbdev/cirrusfb.c
+++ b/drivers/video/fbdev/cirrusfb.c
@@ -57,6 +57,8 @@
#include <video/vga.h>
#include <video/cirrus.h>

+#include <asm/fb.h>
+
/*****************************************************************
*
* debugging and utility macros
diff --git a/drivers/video/fbdev/core/cfbcopyarea.c b/drivers/video/fbdev/core/cfbcopyarea.c
index 6d4bfeecee35..128fdd0cdcdc 100644
--- a/drivers/video/fbdev/core/cfbcopyarea.c
+++ b/drivers/video/fbdev/core/cfbcopyarea.c
@@ -26,8 +26,8 @@
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/fb.h>
+#include <asm/fb.h>
#include <asm/types.h>
-#include <asm/io.h>
#include "fb_draw.h"

#if BITS_PER_LONG == 32
diff --git a/drivers/video/fbdev/core/cfbfillrect.c b/drivers/video/fbdev/core/cfbfillrect.c
index ba9f58b2a5e8..2c6aac987786 100644
--- a/drivers/video/fbdev/core/cfbfillrect.c
+++ b/drivers/video/fbdev/core/cfbfillrect.c
@@ -16,6 +16,7 @@
#include <linux/module.h>
#include <linux/string.h>
#include <linux/fb.h>
+#include <asm/fb.h>
#include <asm/types.h>
#include "fb_draw.h"

diff --git a/drivers/video/fbdev/core/cfbimgblt.c b/drivers/video/fbdev/core/cfbimgblt.c
index 9ebda4e0dc7a..d1e071148a4b 100644
--- a/drivers/video/fbdev/core/cfbimgblt.c
+++ b/drivers/video/fbdev/core/cfbimgblt.c
@@ -32,6 +32,7 @@
#include <linux/module.h>
#include <linux/string.h>
#include <linux/fb.h>
+#include <asm/fb.h>
#include <asm/types.h>
#include "fb_draw.h"

diff --git a/drivers/video/fbdev/core/svgalib.c b/drivers/video/fbdev/core/svgalib.c
index 9e01322fabe3..5ddd498024a8 100644
--- a/drivers/video/fbdev/core/svgalib.c
+++ b/drivers/video/fbdev/core/svgalib.c
@@ -15,9 +15,8 @@
#include <linux/string.h>
#include <linux/fb.h>
#include <linux/svga.h>
+#include <asm/fb.h>
#include <asm/types.h>
-#include <asm/io.h>
-

/* Write a CRT register value spread across multiple registers */
void svga_wcrt_multi(void __iomem *regbase, const struct vga_regset *regset, u32 value)
diff --git a/drivers/video/fbdev/cyber2000fb.c b/drivers/video/fbdev/cyber2000fb.c
index 38c0a6866d76..9fbc0994b3ae 100644
--- a/drivers/video/fbdev/cyber2000fb.c
+++ b/drivers/video/fbdev/cyber2000fb.c
@@ -48,6 +48,8 @@
#include <linux/i2c.h>
#include <linux/i2c-algo-bit.h>

+#include <asm/fb.h>
+
#ifdef __arm__
#include <asm/mach-types.h>
#endif
diff --git a/drivers/video/fbdev/ep93xx-fb.c b/drivers/video/fbdev/ep93xx-fb.c
index 305f1587bd89..5dce00500f0a 100644
--- a/drivers/video/fbdev/ep93xx-fb.c
+++ b/drivers/video/fbdev/ep93xx-fb.c
@@ -23,6 +23,8 @@

#include <linux/platform_data/video-ep93xx.h>

+#include <asm/fb.h>
+
/* Vertical Frame Timing Registers */
#define EP93XXFB_VLINES_TOTAL 0x0000 /* SW locked */
#define EP93XXFB_VSYNC 0x0004 /* SW locked */
diff --git a/drivers/video/fbdev/hgafb.c b/drivers/video/fbdev/hgafb.c
index 40879d9facdf..b15271c52d05 100644
--- a/drivers/video/fbdev/hgafb.c
+++ b/drivers/video/fbdev/hgafb.c
@@ -41,7 +41,8 @@
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/platform_device.h>
-#include <asm/io.h>
+
+#include <asm/fb.h>
#include <asm/vga.h>

#if 0
diff --git a/drivers/video/fbdev/hitfb.c b/drivers/video/fbdev/hitfb.c
index bbb0f1d953cc..a2b5c58f7b7c 100644
--- a/drivers/video/fbdev/hitfb.c
+++ b/drivers/video/fbdev/hitfb.c
@@ -23,7 +23,7 @@

#include <asm/machvec.h>
#include <linux/uaccess.h>
-#include <asm/io.h>
+#include <asm/fb.h>
#include <asm/hd64461.h>
#include <cpu/dac.h>

diff --git a/drivers/video/fbdev/kyro/fbdev.c b/drivers/video/fbdev/kyro/fbdev.c
index 0596573ef140..8b6c3318bf8c 100644
--- a/drivers/video/fbdev/kyro/fbdev.c
+++ b/drivers/video/fbdev/kyro/fbdev.c
@@ -21,9 +21,10 @@
#include <linux/ioctl.h>
#include <linux/init.h>
#include <linux/pci.h>
-#include <asm/io.h>
#include <linux/uaccess.h>

+#include <asm/fb.h>
+
#include <video/kyro.h>

#include "STG4000Reg.h"
diff --git a/drivers/video/fbdev/matrox/matroxfb_accel.c b/drivers/video/fbdev/matrox/matroxfb_accel.c
index ce51227798a1..c982cfe68ab8 100644
--- a/drivers/video/fbdev/matrox/matroxfb_accel.c
+++ b/drivers/video/fbdev/matrox/matroxfb_accel.c
@@ -82,6 +82,8 @@
#include "matroxfb_Ti3026.h"
#include "matroxfb_misc.h"

+#include <asm/fb.h>
+
#define curr_ydstorg(x) ((x)->curr.ydstorg.pixels)

#define mga_ydstlen(y,l) mga_outl(M_YDSTLEN | M_EXEC, ((y) << 16) | (l))
diff --git a/drivers/video/fbdev/matrox/matroxfb_base.h b/drivers/video/fbdev/matrox/matroxfb_base.h
index c93c69bbcd57..184a6d733b93 100644
--- a/drivers/video/fbdev/matrox/matroxfb_base.h
+++ b/drivers/video/fbdev/matrox/matroxfb_base.h
@@ -43,7 +43,7 @@
#include <linux/spinlock.h>
#include <linux/kd.h>

-#include <asm/io.h>
+#include <asm/fb.h>
#include <asm/unaligned.h>

#if defined(CONFIG_PPC_PMAC)
diff --git a/drivers/video/fbdev/pm2fb.c b/drivers/video/fbdev/pm2fb.c
index 47d212944f30..b6a37aff057e 100644
--- a/drivers/video/fbdev/pm2fb.c
+++ b/drivers/video/fbdev/pm2fb.c
@@ -39,6 +39,9 @@
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/pci.h>
+
+#include <asm/fb.h>
+
#include <video/permedia2.h>
#include <video/cvisionppc.h>

diff --git a/drivers/video/fbdev/pm3fb.c b/drivers/video/fbdev/pm3fb.c
index b46a471df9ae..95e152969d30 100644
--- a/drivers/video/fbdev/pm3fb.c
+++ b/drivers/video/fbdev/pm3fb.c
@@ -34,6 +34,8 @@
#include <linux/init.h>
#include <linux/pci.h>

+#include <asm/fb.h>
+
#include <video/pm3fb.h>

#if !defined(CONFIG_PCI)
diff --git a/drivers/video/fbdev/pvr2fb.c b/drivers/video/fbdev/pvr2fb.c
index 6888127a5eb8..1dfb75b15eea 100644
--- a/drivers/video/fbdev/pvr2fb.c
+++ b/drivers/video/fbdev/pvr2fb.c
@@ -74,6 +74,8 @@
#include <cpu/sq.h>
#endif

+#include <asm/fb.h>
+
#ifndef PCI_DEVICE_ID_NEC_NEON250
# define PCI_DEVICE_ID_NEC_NEON250 0x0067
#endif
diff --git a/drivers/video/fbdev/s3fb.c b/drivers/video/fbdev/s3fb.c
index 7d257489edcc..eb16beba10c5 100644
--- a/drivers/video/fbdev/s3fb.c
+++ b/drivers/video/fbdev/s3fb.c
@@ -29,6 +29,8 @@
#include <linux/i2c.h>
#include <linux/i2c-algo-bit.h>

+#include <asm/fb.h>
+
struct s3fb_info {
int chip, rev, mclk_freq;
int wc_cookie;
diff --git a/drivers/video/fbdev/sm712fb.c b/drivers/video/fbdev/sm712fb.c
index b528776c7612..ca15938ce603 100644
--- a/drivers/video/fbdev/sm712fb.c
+++ b/drivers/video/fbdev/sm712fb.c
@@ -31,6 +31,8 @@

#include <linux/pm.h>

+#include <asm/fb.h>
+
#include "sm712.h"

/*
diff --git a/drivers/video/fbdev/sstfb.c b/drivers/video/fbdev/sstfb.c
index da296b2ab54a..1ee4bea467b4 100644
--- a/drivers/video/fbdev/sstfb.c
+++ b/drivers/video/fbdev/sstfb.c
@@ -88,10 +88,10 @@
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/init.h>
-#include <asm/io.h>
#include <linux/uaccess.h>
#include <video/sstfb.h>

+#include <asm/fb.h>

/* initialized by setup */

diff --git a/drivers/video/fbdev/stifb.c b/drivers/video/fbdev/stifb.c
index baca6974e288..a3b837a5fb81 100644
--- a/drivers/video/fbdev/stifb.c
+++ b/drivers/video/fbdev/stifb.c
@@ -69,6 +69,8 @@
#include <asm/grfioctl.h> /* for HP-UX compatibility */
#include <linux/uaccess.h>

+#include <asm/fb.h>
+
#include <video/sticore.h>

/* REGION_BASE(fb_info, index) returns the virtual address for region <index> */
diff --git a/drivers/video/fbdev/tdfxfb.c b/drivers/video/fbdev/tdfxfb.c
index d17e5e1472aa..5ed8f670f51c 100644
--- a/drivers/video/fbdev/tdfxfb.c
+++ b/drivers/video/fbdev/tdfxfb.c
@@ -74,7 +74,8 @@
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/pci.h>
-#include <asm/io.h>
+
+#include <asm/fb.h>

#include <video/tdfx.h>

diff --git a/drivers/video/fbdev/tridentfb.c b/drivers/video/fbdev/tridentfb.c
index 6099b9768ba1..1bd12606c9e0 100644
--- a/drivers/video/fbdev/tridentfb.c
+++ b/drivers/video/fbdev/tridentfb.c
@@ -30,6 +30,8 @@
#include <linux/i2c.h>
#include <linux/i2c-algo-bit.h>

+#include <asm/fb.h>
+
struct tridentfb_par {
void __iomem *io_virt; /* iospace virtual memory address */
u32 pseudo_pal[16];
diff --git a/drivers/video/fbdev/vga16fb.c b/drivers/video/fbdev/vga16fb.c
index 1a8ffdb2be26..2899d4ce0f6f 100644
--- a/drivers/video/fbdev/vga16fb.c
+++ b/drivers/video/fbdev/vga16fb.c
@@ -23,7 +23,8 @@
#include <linux/platform_device.h>
#include <linux/screen_info.h>

-#include <asm/io.h>
+#include <asm/fb.h>
+
#include <video/vga.h>

#define MODE_SKIP4 1
diff --git a/drivers/video/fbdev/vt8623fb.c b/drivers/video/fbdev/vt8623fb.c
index 034333ee6e45..bc345d4fee9e 100644
--- a/drivers/video/fbdev/vt8623fb.c
+++ b/drivers/video/fbdev/vt8623fb.c
@@ -27,6 +27,8 @@
#include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */
#include <video/vga.h>

+#include <asm/fb.h>
+
struct vt8623fb_info {
char __iomem *mmio_base;
int wc_cookie;
diff --git a/include/asm-generic/fb.h b/include/asm-generic/fb.h
index c8af99f5a535..6922dd248c51 100644
--- a/include/asm-generic/fb.h
+++ b/include/asm-generic/fb.h
@@ -7,6 +7,7 @@
* Only include this header file from your architecture's <asm/fb.h>.
*/

+#include <linux/io.h>
#include <linux/mm_types.h>
#include <linux/pgtable.h>

--
2.40.0

2023-04-26 13:07:17

by Thomas Zimmermann

[permalink] [raw]
Subject: [PATCH 5/5] fbdev: Move framebuffer I/O helpers into <asm/fb.h>

Implement framebuffer I/O helpers, such as fb_read*() and fb_write*(),
in the architecture's <asm/fb.h> header file or the generic one.

The general solution is to use regular I/O functions, such as
__raw_readb() or memset_io(). This has been the most-common case so
far.

The implementations for arc, ia64, loongarch and m68k operate on system
memory. As framebuffer memory is declared with volatile __iomem, the
helpers add a __force cast to avoid warnings.

Sparc uses SBus to connect framebuffer devices. It provides respective
implementations of the framebuffer I/O helpers.

Signed-off-by: Thomas Zimmermann <[email protected]>
---
arch/arc/include/asm/fb.h | 29 +++++++++++
arch/ia64/include/asm/fb.h | 28 ++++++++++
arch/loongarch/include/asm/fb.h | 29 +++++++++++
arch/m68k/include/asm/fb.h | 29 +++++++++++
arch/sparc/include/asm/fb.h | 77 +++++++++++++++++++++++++++
include/asm-generic/fb.h | 92 +++++++++++++++++++++++++++++++++
include/linux/fb.h | 53 -------------------
7 files changed, 284 insertions(+), 53 deletions(-)

diff --git a/arch/arc/include/asm/fb.h b/arch/arc/include/asm/fb.h
index 9c2383d29cbb..88fd9051e74a 100644
--- a/arch/arc/include/asm/fb.h
+++ b/arch/arc/include/asm/fb.h
@@ -3,6 +3,35 @@
#ifndef _ASM_FB_H_
#define _ASM_FB_H_

+#include <linux/string.h>
+
+#define fb_readb(addr) (*(volatile u8 __force *) (addr))
+#define fb_readw(addr) (*(volatile u16 __force *) (addr))
+#define fb_readl(addr) (*(volatile u32 __force *) (addr))
+#define fb_readq(addr) (*(volatile u64 __force *) (addr))
+#define fb_writeb(b, addr) (*(volatile u8 __force *) (addr) = (b))
+#define fb_writew(b, addr) (*(volatile u16 __force *) (addr) = (b))
+#define fb_writel(b, addr) (*(volatile u32 __force *) (addr) = (b))
+#define fb_writeq(b, addr) (*(volatile u64 __force *) (addr) = (b))
+
+static inline void fb_memcpy_fromfb(void *to, const volatile void __iomem *from, size_t n)
+{
+ memcpy(to, (const void __force *)from, n);
+}
+#define fb_memcpy_fromfb fb_memcpy_fromfb
+
+static inline void fb_memcpy_tofb(volatile void __iomem *to, const void *from, size_t n)
+{
+ memcpy((void __force *)to, from, n);
+}
+#define fb_memcpy_tofb fb_memcpy_tofb
+
+static inline void fb_memset(volatile void __iomem *addr, int c, size_t n)
+{
+ memset((void __force *)addr, c, n);
+}
+#define fb_memset fb_memset
+
#include <asm-generic/fb.h>

#endif /* _ASM_FB_H_ */
diff --git a/arch/ia64/include/asm/fb.h b/arch/ia64/include/asm/fb.h
index 0208f64a0da0..9aea9461850c 100644
--- a/arch/ia64/include/asm/fb.h
+++ b/arch/ia64/include/asm/fb.h
@@ -3,6 +3,7 @@
#define _ASM_FB_H_

#include <linux/efi.h>
+#include <linux/string.h>

#include <asm/page.h>

@@ -18,6 +19,33 @@ static inline void fb_pgprotect(struct file *file, struct vm_area_struct *vma,
}
#define fb_pgprotect fb_pgprotect

+#define fb_readb(addr) (*(volatile u8 __force *) (addr))
+#define fb_readw(addr) (*(volatile u16 __force *) (addr))
+#define fb_readl(addr) (*(volatile u32 __force *) (addr))
+#define fb_readq(addr) (*(volatile u64 __force *) (addr))
+#define fb_writeb(b, addr) (*(volatile u8 __force *) (addr) = (b))
+#define fb_writew(b, addr) (*(volatile u16 __force *) (addr) = (b))
+#define fb_writel(b, addr) (*(volatile u32 __force *) (addr) = (b))
+#define fb_writeq(b, addr) (*(volatile u64 __force *) (addr) = (b))
+
+static inline void fb_memcpy_fromfb(void *to, const volatile void __iomem *from, size_t n)
+{
+ memcpy(to, (const void __force *)from, n);
+}
+#define fb_memcpy_fromfb fb_memcpy_fromfb
+
+static inline void fb_memcpy_tofb(volatile void __iomem *to, const void *from, size_t n)
+{
+ memcpy((void __force *)to, from, n);
+}
+#define fb_memcpy_tofb fb_memcpy_tofb
+
+static inline void fb_memset(volatile void __iomem *addr, int c, size_t n)
+{
+ memset((void __force *)addr, c, n);
+}
+#define fb_memset fb_memset
+
#include <asm-generic/fb.h>

#endif /* _ASM_FB_H_ */
diff --git a/arch/loongarch/include/asm/fb.h b/arch/loongarch/include/asm/fb.h
index ff82f20685c8..97b0f02ffd0c 100644
--- a/arch/loongarch/include/asm/fb.h
+++ b/arch/loongarch/include/asm/fb.h
@@ -5,6 +5,35 @@
#ifndef _ASM_FB_H_
#define _ASM_FB_H_

+#include <linux/string.h>
+
+#define fb_readb(addr) (*(volatile u8 __force *) (addr))
+#define fb_readw(addr) (*(volatile u16 __force *) (addr))
+#define fb_readl(addr) (*(volatile u32 __force *) (addr))
+#define fb_readq(addr) (*(volatile u64 __force *) (addr))
+#define fb_writeb(b, addr) (*(volatile u8 __force *) (addr) = (b))
+#define fb_writew(b, addr) (*(volatile u16 __force *) (addr) = (b))
+#define fb_writel(b, addr) (*(volatile u32 __force *) (addr) = (b))
+#define fb_writeq(b, addr) (*(volatile u64 __force *) (addr) = (b))
+
+static inline void fb_memcpy_fromfb(void *to, const volatile void __iomem *from, size_t n)
+{
+ memcpy(to, (const void __force *)from, n);
+}
+#define fb_memcpy_fromfb fb_memcpy_fromfb
+
+static inline void fb_memcpy_tofb(volatile void __iomem *to, const void *from, size_t n)
+{
+ memcpy((void __force *)to, from, n);
+}
+#define fb_memcpy_tofb fb_memcpy_tofb
+
+static inline void fb_memset(volatile void __iomem *addr, int c, size_t n)
+{
+ memset((void __force *)addr, c, n);
+}
+#define fb_memset fb_memset
+
#include <asm-generic/fb.h>

#endif /* _ASM_FB_H_ */
diff --git a/arch/m68k/include/asm/fb.h b/arch/m68k/include/asm/fb.h
index 24273fc7ad91..8530d09fa04d 100644
--- a/arch/m68k/include/asm/fb.h
+++ b/arch/m68k/include/asm/fb.h
@@ -2,6 +2,8 @@
#ifndef _ASM_FB_H_
#define _ASM_FB_H_

+#include <linux/string.h>
+
#include <asm/page.h>
#include <asm/setup.h>

@@ -26,6 +28,33 @@ static inline void fb_pgprotect(struct file *file, struct vm_area_struct *vma,
}
#define fb_pgprotect fb_pgprotect

+#define fb_readb(addr) (*(volatile u8 __force *) (addr))
+#define fb_readw(addr) (*(volatile u16 __force *) (addr))
+#define fb_readl(addr) (*(volatile u32 __force *) (addr))
+#define fb_readq(addr) (*(volatile u64 __force *) (addr))
+#define fb_writeb(b, addr) (*(volatile u8 __force *) (addr) = (b))
+#define fb_writew(b, addr) (*(volatile u16 __force *) (addr) = (b))
+#define fb_writel(b, addr) (*(volatile u32 __force *) (addr) = (b))
+#define fb_writeq(b, addr) (*(volatile u64 __force *) (addr) = (b))
+
+static inline void fb_memcpy_fromfb(void *to, const volatile void __iomem *from, size_t n)
+{
+ memcpy(to, (const void __force *)from, n);
+}
+#define fb_memcpy_fromfb fb_memcpy_fromfb
+
+static inline void fb_memcpy_tofb(volatile void __iomem *to, const void *from, size_t n)
+{
+ memcpy((void __force *)to, from, n);
+}
+#define fb_memcpy_tofb fb_memcpy_tofb
+
+static inline void fb_memset(volatile void __iomem *addr, int c, size_t n)
+{
+ memset((void __force *)addr, c, n);
+}
+#define fb_memset fb_memset
+
#include <asm-generic/fb.h>

#endif /* _ASM_FB_H_ */
diff --git a/arch/sparc/include/asm/fb.h b/arch/sparc/include/asm/fb.h
index 689ee5c60054..c702892b2db7 100644
--- a/arch/sparc/include/asm/fb.h
+++ b/arch/sparc/include/asm/fb.h
@@ -2,6 +2,8 @@
#ifndef _SPARC_FB_H_
#define _SPARC_FB_H_

+#include <asm/io.h>
+
struct fb_info;
struct file;
struct vm_area_struct;
@@ -16,6 +18,81 @@ static inline void fb_pgprotect(struct file *file, struct vm_area_struct *vma,
int fb_is_primary_device(struct fb_info *info);
#define fb_is_primary_device fb_is_primary_device

+/*
+ * We map all of our framebuffers such that big-endian accesses
+ * are what we want, so the following is sufficient.
+ */
+
+static inline u8 fb_readb(const volatile void __iomem *addr)
+{
+ return sbus_readb(addr);
+}
+#define fb_readb fb_readb
+
+static inline u16 fb_readw(const volatile void __iomem *addr)
+{
+ return sbus_readw(addr);
+}
+#define fb_readw fb_readw
+
+static inline u32 fb_readl(const volatile void __iomem *addr)
+{
+ return sbus_readl(addr);
+}
+#define fb_readl fb_readl
+
+#ifdef CONFIG_SPARC64
+static inline u64 fb_readq(const volatile void __iomem *addr)
+{
+ return sbus_readq(addr);
+}
+#define fb_readq fb_readq
+#endif
+
+static inline void fb_writeb(u8 b, volatile void __iomem *addr)
+{
+ sbus_writeb(b, addr);
+}
+#define fb_writeb fb_writeb
+
+static inline void fb_writew(u16 b, volatile void __iomem *addr)
+{
+ sbus_writew(b, addr);
+}
+#define fb_writew fb_writew
+
+static inline void fb_writel(u32 b, volatile void __iomem *addr)
+{
+ sbus_writel(b, addr);
+}
+#define fb_writel fb_writel
+
+#ifdef CONFIG_SPARC64
+static inline void fb_writeq(u64 b, volatile void __iomem *addr)
+{
+ sbus_writeq(b, addr);
+}
+#define fb_writeq fb_writeq
+#endif
+
+static inline void fb_memcpy_fromfb(void *to, const volatile void __iomem *from, size_t n)
+{
+ sbus_memcpy_fromio(to, from, n);
+}
+#define fb_memcpy_fromfb fb_memcpy_fromfb
+
+static inline void fb_memcpy_tofb(volatile void __iomem *to, const void *from, size_t n)
+{
+ sbus_memcpy_toio(to, from, n);
+}
+#define fb_memcpy_tofb fb_memcpy_tofb
+
+static inline void fb_memset(volatile void __iomem *addr, int c, size_t n)
+{
+ sbus_memset_io(addr, c, n);
+}
+#define fb_memset fb_memset
+
#include <asm-generic/fb.h>

#endif /* _SPARC_FB_H_ */
diff --git a/include/asm-generic/fb.h b/include/asm-generic/fb.h
index 6922dd248c51..49eb63629ffe 100644
--- a/include/asm-generic/fb.h
+++ b/include/asm-generic/fb.h
@@ -31,4 +31,96 @@ static inline int fb_is_primary_device(struct fb_info *info)
}
#endif

+#ifndef fb_readb
+static inline u8 fb_readb(const volatile void __iomem *addr)
+{
+ return __raw_readb(addr);
+}
+#define fb_readb fb_readb
+#endif
+
+#ifndef fb_readw
+static inline u16 fb_readw(const volatile void __iomem *addr)
+{
+ return __raw_readw(addr);
+}
+#define fb_readw fb_readw
+#endif
+
+#ifndef fb_readl
+static inline u32 fb_readl(const volatile void __iomem *addr)
+{
+ return __raw_readl(addr);
+}
+#define fb_readl fb_readl
+#endif
+
+#if defined(CONFIG_64BIT)
+#ifndef fb_readq
+static inline u64 fb_readq(const volatile void __iomem *addr)
+{
+ return __raw_readq(addr);
+}
+#define fb_readq fb_readq
+#endif
+#endif /* CONFIG_64BIT */
+
+#ifndef fb_writeb
+static inline void fb_writeb(u8 b, volatile void __iomem *addr)
+{
+ __raw_writeb(b, addr);
+}
+#define fb_writeb fb_writeb
+#endif
+
+#ifndef fb_writew
+static inline void fb_writew(u16 b, volatile void __iomem *addr)
+{
+ __raw_writew(b, addr);
+}
+#define fb_writew fb_writew
+#endif
+
+#ifndef fb_writel
+static inline void fb_writel(u32 b, volatile void __iomem *addr)
+{
+ __raw_writel(b, addr);
+}
+#define fb_writel fb_writel
+#endif
+
+#if defined(CONFIG_64BIT)
+#ifndef fb_writeq
+static inline void fb_writeq(u64 b, volatile void __iomem *addr)
+{
+ __raw_writeq(b, addr);
+}
+#define fb_writeq fb_writeq
+#endif
+#endif /* CONFIG_64BIT */
+
+#ifndef fb_memcpy_fromfb
+static inline void fb_memcpy_fromfb(void *to, const volatile void __iomem *from, size_t n)
+{
+ memcpy_fromio(to, from, n);
+}
+#define fb_memcpy_fromfb fb_memcpy_fromfb
+#endif
+
+#ifndef fb_memcpy_tofb
+static inline void fb_memcpy_tofb(volatile void __iomem *to, const void *from, size_t n)
+{
+ memcpy_toio(to, from, n);
+}
+#define fb_memcpy_tofb fb_memcpy_tofb
+#endif
+
+#ifndef fb_memset
+static inline void fb_memset(volatile void __iomem *addr, int c, size_t n)
+{
+ memset_io(addr, c, n);
+}
+#define fb_memset fb_memset
+#endif
+
#endif /* __ASM_GENERIC_FB_H_ */
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 08cb47da71f8..7d80ee62a9d5 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -15,7 +15,6 @@
#include <linux/list.h>
#include <linux/backlight.h>
#include <linux/slab.h>
-#include <asm/io.h>

struct vm_area_struct;
struct fb_info;
@@ -511,58 +510,6 @@ struct fb_info {
*/
#define STUPID_ACCELF_TEXT_SHIT

-// This will go away
-#if defined(__sparc__)
-
-/* We map all of our framebuffers such that big-endian accesses
- * are what we want, so the following is sufficient.
- */
-
-// This will go away
-#define fb_readb sbus_readb
-#define fb_readw sbus_readw
-#define fb_readl sbus_readl
-#define fb_readq sbus_readq
-#define fb_writeb sbus_writeb
-#define fb_writew sbus_writew
-#define fb_writel sbus_writel
-#define fb_writeq sbus_writeq
-#define fb_memset sbus_memset_io
-#define fb_memcpy_fromfb sbus_memcpy_fromio
-#define fb_memcpy_tofb sbus_memcpy_toio
-
-#elif defined(__i386__) || defined(__alpha__) || defined(__x86_64__) || \
- defined(__hppa__) || defined(__sh__) || defined(__powerpc__) || \
- defined(__arm__) || defined(__aarch64__) || defined(__mips__)
-
-#define fb_readb __raw_readb
-#define fb_readw __raw_readw
-#define fb_readl __raw_readl
-#define fb_readq __raw_readq
-#define fb_writeb __raw_writeb
-#define fb_writew __raw_writew
-#define fb_writel __raw_writel
-#define fb_writeq __raw_writeq
-#define fb_memset memset_io
-#define fb_memcpy_fromfb memcpy_fromio
-#define fb_memcpy_tofb memcpy_toio
-
-#else
-
-#define fb_readb(addr) (*(volatile u8 *) (addr))
-#define fb_readw(addr) (*(volatile u16 *) (addr))
-#define fb_readl(addr) (*(volatile u32 *) (addr))
-#define fb_readq(addr) (*(volatile u64 *) (addr))
-#define fb_writeb(b,addr) (*(volatile u8 *) (addr) = (b))
-#define fb_writew(b,addr) (*(volatile u16 *) (addr) = (b))
-#define fb_writel(b,addr) (*(volatile u32 *) (addr) = (b))
-#define fb_writeq(b,addr) (*(volatile u64 *) (addr) = (b))
-#define fb_memset memset
-#define fb_memcpy_fromfb memcpy
-#define fb_memcpy_tofb memcpy
-
-#endif
-
#define FB_LEFT_POS(p, bpp) (fb_be_math(p) ? (32 - (bpp)) : 0)
#define FB_SHIFT_HIGH(p, val, bits) (fb_be_math(p) ? (val) >> (bits) : \
(val) << (bits))
--
2.40.0

2023-04-26 20:39:26

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH 0/5] fbdev: Move framebuffer I/O helpers to <asm/fb.h>

Hi Thomas.

On Wed, Apr 26, 2023 at 03:04:15PM +0200, Thomas Zimmermann wrote:
> Fbdev provides helpers for framebuffer I/O, such as fb_readl(),
> fb_writel() or fb_memcpy_to_fb(). The implementation of each helper
> depends on the architecture. It's still all located in fbdev's main
> header file <linux/fb.h>. Move all of it into each archtecture's
> <asm/fb.h>, with shared code in <asm-generic/fb.h>.

For once I think this cleanup is moving things in the wrong direction.

The fb_* helpers predates the generic io.h support and try to
add a generic layer for read read / write operations.

The right fix would be to migrate fb_* to use the io helpers
we have today - so we use the existing way to handle the architecture
specific details.

From a quick look there seems to be some challenges but the current
helpers that re-do part of io.h is not the way forward and hiding them
in arch/include/asm/fb.h seems counter productive.

Sam

2023-04-27 07:24:30

by Thomas Zimmermann

[permalink] [raw]
Subject: Re: [PATCH 0/5] fbdev: Move framebuffer I/O helpers to <asm/fb.h>

Hi Sam

Am 26.04.23 um 21:21 schrieb Sam Ravnborg:
> Hi Thomas.
>
> On Wed, Apr 26, 2023 at 03:04:15PM +0200, Thomas Zimmermann wrote:
>> Fbdev provides helpers for framebuffer I/O, such as fb_readl(),
>> fb_writel() or fb_memcpy_to_fb(). The implementation of each helper
>> depends on the architecture. It's still all located in fbdev's main
>> header file <linux/fb.h>. Move all of it into each archtecture's
>> <asm/fb.h>, with shared code in <asm-generic/fb.h>.
>
> For once I think this cleanup is moving things in the wrong direction.
>
> The fb_* helpers predates the generic io.h support and try to
> add a generic layer for read read / write operations.
>
> The right fix would be to migrate fb_* to use the io helpers
> we have today - so we use the existing way to handle the architecture
> specific details.

I looked through the existing versions of the fb_() I/O helpers. They
can apparently be implemented with the regular helpers of similar names.

I'm not sure, but even Sparc looks compatible. At least these sbus_
functions seem to be equivalent to the __raw_() I/O helpers of similar
names. Do you still have that Sparc emulator?

>
> From a quick look there seems to be some challenges but the current
> helpers that re-do part of io.h is not the way forward and hiding them
> in arch/include/asm/fb.h seems counter productive.

Which challenges did you see?

Best regards
Thomas

>
> Sam

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)


Attachments:
OpenPGP_signature (855.00 B)
OpenPGP digital signature

2023-04-27 10:24:00

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 0/5] fbdev: Move framebuffer I/O helpers to <asm/fb.h>

On Thu, Apr 27, 2023, at 08:22, Thomas Zimmermann wrote:
> Am 26.04.23 um 21:21 schrieb Sam Ravnborg:
>> On Wed, Apr 26, 2023 at 03:04:15PM +0200, Thomas Zimmermann wrote:
>>> Fbdev provides helpers for framebuffer I/O, such as fb_readl(),
>>> fb_writel() or fb_memcpy_to_fb(). The implementation of each helper
>>> depends on the architecture. It's still all located in fbdev's main
>>> header file <linux/fb.h>. Move all of it into each archtecture's
>>> <asm/fb.h>, with shared code in <asm-generic/fb.h>.
>>
>> For once I think this cleanup is moving things in the wrong direction.
>>
>> The fb_* helpers predates the generic io.h support and try to
>> add a generic layer for read read / write operations.
>>
>> The right fix would be to migrate fb_* to use the io helpers
>> we have today - so we use the existing way to handle the architecture
>> specific details.
>
> I looked through the existing versions of the fb_() I/O helpers. They
> can apparently be implemented with the regular helpers of similar names.
>
> I'm not sure, but even Sparc looks compatible. At least these sbus_
> functions seem to be equivalent to the __raw_() I/O helpers of similar
> names. Do you still have that Sparc emulator?

I looked at the current code and came to the same conclusion: all
architectures we support today do the same thing in __raw_readl()
and fb_readl() etc, so we can completely remove the latter without
changing semantics.

I think the original list was necessary since not all architectures
supported the __raw_ accessors in the past, so they were open-coded
here for the rest. I thought there were also architectures on which
__raw_readl() does a byteswap to reverse the swap done in a PCI
host bridge, but it apears that none of those remain now, if we ever
had them.

Arnd

2023-04-27 17:19:29

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH 0/5] fbdev: Move framebuffer I/O helpers to <asm/fb.h>

Hi Thomas,

On Thu, Apr 27, 2023 at 09:22:47AM +0200, Thomas Zimmermann wrote:
> Hi Sam
>
> Am 26.04.23 um 21:21 schrieb Sam Ravnborg:
> > Hi Thomas.
> >
> > On Wed, Apr 26, 2023 at 03:04:15PM +0200, Thomas Zimmermann wrote:
> > > Fbdev provides helpers for framebuffer I/O, such as fb_readl(),
> > > fb_writel() or fb_memcpy_to_fb(). The implementation of each helper
> > > depends on the architecture. It's still all located in fbdev's main
> > > header file <linux/fb.h>. Move all of it into each archtecture's
> > > <asm/fb.h>, with shared code in <asm-generic/fb.h>.
> >
> > For once I think this cleanup is moving things in the wrong direction.
> >
> > The fb_* helpers predates the generic io.h support and try to
> > add a generic layer for read read / write operations.
> >
> > The right fix would be to migrate fb_* to use the io helpers
> > we have today - so we use the existing way to handle the architecture
> > specific details.
>
> I looked through the existing versions of the fb_() I/O helpers. They can
> apparently be implemented with the regular helpers of similar names.
>
> I'm not sure, but even Sparc looks compatible. At least these sbus_
> functions seem to be equivalent to the __raw_() I/O helpers of similar
> names.

> Do you still have that Sparc emulator?
I used qemu the last time I played with sparc and saved the instructions
somewhere how to redo it - but that would use to bohcs driver only I think.
I have saprc machines, but none of these are easy to get operational.
We can always ask on sparclinux to get some testing feedback.

>
> >
> > From a quick look there seems to be some challenges but the current
> > helpers that re-do part of io.h is not the way forward and hiding them
> > in arch/include/asm/fb.h seems counter productive.
>
> Which challenges did you see?
sparc was the main thing - but maybe I did not look close enough.
And then I tried to map the macros to some of the more highlevel ones
from io.h, but as Arnd says the __raw* is the way to go here.

Sam