make io{read|write}64 globally usable
Subsystems (7)
v4 cover make io{read|write}64 globally usable
This is version four of my patchset to enable drivers to use io{read|write}64 on all arches.
Changes since v3:
- I noticed powerpc didn't use the appropriate functions seeing readq/writeq were not defined when iomap.h was included. Thus I've included a patch to adjust this
- Fixed some mistakes with a couple of the defines in io-64-nonatomic* headers
- Fixed a typo noticed by Horia.
Horia Geantă (1):
crypto: caam: cleanup CONFIG_64BIT ifdefs when using io{read|write}64
Logan Gunthorpe (4):
powerpc: io.h: move iomap.h include so that it can use readq/writeq
defs
iomap: introduce io{read|write}64_{lo_hi|hi_lo}
io-64-nonatomic: add io{read|write}64[be]{_lo_hi|_hi_lo} macros
ntb: ntb_hw_intel: use io-64-nonatomic instead of in-driver hacks
arch/powerpc/include/asm/io.h | 6 +- drivers/crypto/caam/regs.h | 35 ++------- drivers/ntb/hw/intel/ntb_hw_intel.c | 30 +------- include/asm-generic/iomap.h | 26 +++++-- include/linux/io-64-nonatomic-hi-lo.h | 60 ++++++++++++++++ include/linux/io-64-nonatomic-lo-hi.h | 60 ++++++++++++++++ lib/iomap.c | 132 ++++++++++++++++++++++++++++++++++ 7 files changed, 282 insertions(+), 67 deletions(-)
PATCH v4 1/5 powerpc: io.h: move iomap.h include so that it can use readq/writeq defs
Subsequent patches in this series makes use of the readq and writeq defines in iomap.h. However, as is, they get missed on the powerpc platform seeing the include comes before the define. This patch moves the include down to fix this.
--- arch/powerpc/include/asm/io.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/io.h +2 -2
@@ -33,8 +33,6 @@ extern struct pci_dev *isa_bridge_pcidev;#include <asm/mmu.h> #include <asm/ppc_asm.h> -#include <asm-generic/iomap.h> -#ifdef CONFIG_PPC64 #include <asm/paca.h> #endif
@@ -663,6 +661,8 @@ static inline void name at \#define writel_relaxed (v, addr) writel(v, addr)#define writeq_relaxed (v, addr) writeq(v, addr) +#include <asm-generic/iomap.h> +#ifdef CONFIG_PPC32 #define mmiowb ()#else
Signature · 1 line
2.11.0
Michael Ellerman
reviewerRe: [PATCH v4 1/5] powerpc: io.h: move iomap.h include so that it can use readq/writeq defs
Quoted 12 lines · Logan Gunthorpe
Subsequent patches in this series makes use of the readq and writeq defines in
iomap.h. However, as is, they get missed on the powerpc platform seeing the include comes before the define. This patch moves the include down to fix this.Signed-off-by Logan Gunthorpe <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Suresh Warrier <[email protected]>Cc "Oliver O'Halloran" <[email protected]>
Quoted 3 lines
--- arch/powerpc/include/asm/io.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Seems fair enough, have you tested it at all?
cheers
Re: [PATCH v4 1/5] powerpc: io.h: move iomap.h include so that it can use readq/writeq defs
Quoted 1 line · Michael Ellerman
Seems fair enough, have you tested it at all?
It's only been compile tested and the kbuild robot has beat up on it a bit.
Thanks,
Logan
Horia Geantă
maintainerRe: [PATCH v4 1/5] powerpc: io.h: move iomap.h include so that it can use readq/writeq defs
Quoted 7 lines · Logan Gunthorpe
Quoted 1 line · Michael Ellerman
Seems fair enough, have you tested it at all?
It's only been compile tested and the kbuild robot has beat up on it a bit.
Looks like the patch set does not compile on PPC (.config generated using make corenet64_smp_defconfig):
[...]
LD vmlinux.o
MODPOST vmlinux.odrivers/crypto/caam/jr.o: In function `rd_reg64':/home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:154:
undefined reference to `.ioread64be_lo_hi' /home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:151:
undefined reference to `.ioread64_lo_hi' /home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:151:
undefined reference to `.ioread64_lo_hi' /home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:154:
undefined reference to .ioread64be_lo_hi' drivers/crypto/caam/jr.o: In function wr_reg64':/home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:141:
undefined reference to `.iowrite64_lo_hi' /home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:141:
undefined reference to `.iowrite64_lo_hi' /home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:144:
undefined reference to `.iowrite64be_lo_hi' /home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:144:
undefined reference to `.iowrite64be_lo_hi'
make: *** [vmlinux] Error 1
Regards,
Horia
Horia Geantă
maintainerRe: [PATCH v4 1/5] powerpc: io.h: move iomap.h include so that it can use readq/writeq defs
Quoted 25 lines · Horia Geantă
Quoted 7 lines · Logan Gunthorpe
Quoted 1 line · Michael Ellerman
Seems fair enough, have you tested it at all?
It's only been compile tested and the kbuild robot has beat up on it a bit.
Looks like the patch set does not compile on PPC (.config generated using make
corenet64_smp_defconfig):[...]
LD vmlinux.o
MODPOST vmlinux.odrivers/crypto/caam/jr.o: In function `rd_reg64':/home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:154:
undefined reference to `.ioread64be_lo_hi'/home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:151:
undefined reference to `.ioread64_lo_hi'/home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:151:
undefined reference to `.ioread64_lo_hi'/home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:154:
undefined reference to.ioread64be_lo_hi' drivers/crypto/caam/jr.o: In functionwr_reg64':/home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:141:
Quoted 9 lines
undefined reference to `.iowrite64_lo_hi'
/home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:141:
undefined reference to `.iowrite64_lo_hi'/home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:144:
undefined reference to `.iowrite64be_lo_hi'/home/b05471/repos/cryptodev-2.6/drivers/crypto/caam/regs.h:144:
undefined reference to `.iowrite64be_lo_hi'
make: *** [vmlinux] Error 1
include/asm-generic/iomap.h is included beforeinclude/linux/io-64-nonatomic-lo-hi.h:
include/linux/io.h -> arch/powerpc/include/asm/io.h -> include/asm-generic/iomap.h
Thus, the "extern" version of ioread64_lo_hi and friends will be used (and not the inline version from io-64-nonatomic-lo-hi.h).
But for this kernel .config:
-CONFIG_GENERIC_IOMAP=n and
-there is no implementation of io{read|write}64[be]{_lo_hi|_hi_lo} in arch/powerpc/kernel/iomap.c
Regards,
Horia
Re: [PATCH v4 1/5] powerpc: io.h: move iomap.h include so that it can use readq/writeq defs
Quoted 12 lines · Horia Geantă
include/asm-generic/iomap.his included beforeinclude/linux/io-64-nonatomic-lo-hi.h:
include/linux/io.h->arch/powerpc/include/asm/io.h->include/asm-generic/iomap.hThus, the "extern" version of
ioread64_lo_hiand friends will be used (and not the inline version fromio-64-nonatomic-lo-hi.h).But for this kernel .config:
(quoted diff) +0
-2-CONFIG_GENERIC_IOMAP=n and -there is no implementation of io{read|write}64[be]{_lo_hi|_hi_lo} in
Quoted 1 line
arch/powerpc/kernel/iomap.c
Ah, thanks for the triage. I'll take a look at fixing this for a v5.
Logan
Re: [PATCH v4 1/5] powerpc: io.h: move iomap.h include so that it can use readq/writeq defs
In reply to Logan GunthorpeQuoted 4 lines · Logan Gunthorpe
Quoted 1 line · Michael Ellerman
Seems fair enough, have you tested it at all?
It's only been compile tested and the kbuild robot has beat up on it a bit.
OK. I don't think I see any way it can break anything, so feel free to merge it, it'll get boot testing on powerpc once it's in linux-next.
cheers
PATCH v4 2/5 iomap: introduce io{read|write}64_{lo_hi|hi_lo}
In reply to Logan GunthorpeIn order to provide non-atomic functions for io{read|write}64 that will use readq and writeq when appropriate. We define a number of variants of these functions in the generic iomap that will do non-atomic operations on pio but atomic operations on mmio.
These functions are only defined if readq and writeq are defined. If they are not, then the wrappers that always use non-atomic operations from include/linux/io-64-nonatomic*.h will be used.
--- arch/powerpc/include/asm/io.h | 2 + include/asm-generic/iomap.h | 26 +++++++-- lib/iomap.c | 132 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/io.h +2 -0
@@ -788,8 +788,10 @@ extern void __iounmap_at(void *ea, unsigned long size);#define mmio_read16be (addr) readw_be(addr)#define mmio_read32be (addr) readl_be(addr) +#define mmio_read64be (addr) readq_be(addr)#define mmio_write16be (val, addr) writew_be(val, addr)#define mmio_write32be (val, addr) writel_be(val, addr) +#define mmio_write64be (val, addr) writeq_be(val, addr)#define mmio_insb (addr, dst, count) readsb(addr, dst, count)#define mmio_insw (addr, dst, count) readsw(addr, dst, count)#define mmio_insl (addr, dst, count) readsl(addr, dst, count)
include/asm-generic/iomap.h +20 -6
@@ -30,9 +30,16 @@ extern unsigned int ioread16(void __iomem *);extern unsigned int ioread16be (void __iomem *);extern unsigned int ioread32 (void __iomem *);extern unsigned int ioread32be (void __iomem *); -#ifdef CONFIG_64BIT -extern u64 ioread64 (void __iomem *); -extern u64 ioread64be (void __iomem *); + +#ifdef readq +#define ioread64_lo_hi ioread64_lo_hi +#define ioread64_hi_lo ioread64_hi_lo +#define ioread64be_lo_hi ioread64be_lo_hi +#define ioread64be_hi_lo ioread64be_hi_lo +extern u64 ioread64_lo_hi (void __iomem *addr); +extern u64 ioread64_hi_lo (void __iomem *addr); +extern u64 ioread64be_lo_hi (void __iomem *addr); +extern u64 ioread64be_hi_lo (void __iomem *addr);#endif extern void iowrite8 (u8 ,void __iomem *);
@@ -40,9 +47,16 @@ extern void iowrite16(u16, void __iomem *);extern void iowrite16be (u16 ,void __iomem *);extern void iowrite32 (u32 ,void __iomem *);extern void iowrite32be (u32 ,void __iomem *); -#ifdef CONFIG_64BIT -extern void iowrite64 (u64 ,void __iomem *); -extern void iowrite64be (u64 ,void __iomem *); + +#ifdef writeq +#define iowrite64_lo_hi iowrite64_lo_hi +#define iowrite64_hi_lo iowrite64_hi_lo +#define iowrite64be_lo_hi iowrite64be_lo_hi +#define iowrite64be_hi_lo iowrite64be_hi_lo +void iowrite64_lo_hi (u64 val,void __iomem *addr); +void iowrite64_hi_lo (u64 val,void __iomem *addr); +void iowrite64be_lo_hi (u64 val,void __iomem *addr); +void iowrite64be_hi_lo (u64 val,void __iomem *addr);#endif /*
lib/iomap.c +132 -0
156 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v4 3/5 io-64-nonatomic: add io{read|write}64[be]{_lo_hi|_hi_lo} macros
In reply to Logan GunthorpeThis patch adds generic io{read|write}64[be]{_lo_hi|_hi_lo} macros if they are not already defined by the architecture. (As they are provided by the generic iomap library).
The patch also points io{read|write}64[be] to the variant specified by the header name.
This is because new drivers are encouraged to use ioreadXX, et al instead of readX[1], et al -- and mixing ioreadXX with readq is pretty ugly.
[1] ldd3: section 9.4.2
--- include/linux/io-64-nonatomic-hi-lo.h | 60 +++++++++++++++++++++++++++++++++++ include/linux/io-64-nonatomic-lo-hi.h | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+)
include/linux/io-64-nonatomic-hi-lo.h +60 -0
@@ -54,4 +54,64 @@ static inline void hi_lo_writeq_relaxed(__u64 val, volatile void __iomem *addr)#define writeq_relaxed hi_lo_writeq_relaxed#endif +#ifndef ioread64_hi_lo +#define ioread64_hi_lo ioread64_hi_lo +static inline u64 ioread64_hi_lo (void __iomem *addr) +{ +u32 low, high; + + high =ioread32 (addr +sizeof (u32)); + low =ioread32 (addr); + +return low + ((u64 )high <<32 ); +} +#endif + +#ifndef iowrite64_hi_lo +#define iowrite64_hi_lo iowrite64_hi_lo +static inline void iowrite64_hi_lo (u64 val,void __iomem *addr) +{ +iowrite32 (val >>32 , addr +sizeof (u32)); +iowrite32 (val, addr); +} +#endif + +#ifndef ioread64be_hi_lo +#define ioread64be_hi_lo ioread64be_hi_lo +static inline u64 ioread64be_hi_lo (void __iomem *addr) +{ +u32 low, high; + + high =ioread32be (addr); + low =ioread32be (addr +sizeof (u32)); + +return low + ((u64 )high <<32 ); +} +#endif + +#ifndef iowrite64be_hi_lo +#define iowrite64be_hi_lo iowrite64be_hi_lo +static inline void iowrite64be_hi_lo (u64 val,void __iomem *addr) +{ +iowrite32be (val >>32 , addr); +iowrite32be (val, addr +sizeof (u32)); +} +#endif + +#ifndef ioread64 +#define ioread64 ioread64_hi_lo +#endif + +#ifndef iowrite64 +#define iowrite64 iowrite64_hi_lo +#endif + +#ifndef ioread64be +#define ioread64be ioread64be_hi_lo +#endif + +#ifndef iowrite64be +#define iowrite64be iowrite64be_hi_lo +#endif +#endif /* _LINUX_IO_64_NONATOMIC_HI_LO_H_ */
include/linux/io-64-nonatomic-lo-hi.h +60 -0
64 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v4 4/5 ntb: ntb_hw_intel: use io-64-nonatomic instead of in-driver hacks
In reply to Logan GunthorpeNow that ioread64 and iowrite64 are available in io-64-nonatomic, we can remove the hack at the top of ntb_hw_intel.c and replace it with an include.
--- drivers/ntb/hw/intel/ntb_hw_intel.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-)
drivers/ntb/hw/intel/ntb_hw_intel.c +1 -29
@@ -59,6 +59,7 @@#include <linux/random.h> #include <linux/slab.h> #include <linux/ntb.h> +#include <linux/io-64-nonatomic-lo-hi.h> #include "ntb_hw_intel.h"
@@ -155,35 +156,6 @@ MODULE_PARM_DESC(xeon_b2b_dsd_bar5_addr32,static inline enum ntb_topo xeon_ppd_topo (struct intel_ntb_dev *ndev,u8 ppd);static int xeon_init_isr (struct intel_ntb_dev *ndev); -#ifndef ioread64 -#ifdef readq -#define ioread64 readq -#else -#define ioread64 _ioread64 -static inline u64 _ioread64 (void __iomem *mmio) -{ -u64 low, high; - - low =ioread32 (mmio); - high =ioread32 (mmio +sizeof (u32)); -return low | (high <<32 ); -} -#endif -#endif - -#ifndef iowrite64 -#ifdef writeq -#define iowrite64 writeq -#else -#define iowrite64 _iowrite64 -static inline void _iowrite64 (u64 val,void __iomem *mmio) -{ -iowrite32 (val, mmio); -iowrite32 (val >>32 , mmio +sizeof (u32)); -} -#endif -#endif -static inline int pdev_is_atom (struct pci_dev *pdev) {switch (pdev->device) {
Signature · 1 line
2.11.0
RE: [PATCH v4 4/5] ntb: ntb_hw_intel: use io-64-nonatomic instead of in-driver hacks
From: Logan Gunthorpe
Quoted 8 lines
Now that ioread64 and iowrite64 are available in io-64-nonatomic, we can remove the hack at the top of
ntb_hw_intel.cand replace it with an include.Signed-off-by Logan Gunthorpe <[email protected]>Cc Jon Mason <[email protected]>Cc Allen Hubbe <[email protected]>Acked-by Dave Jiang <[email protected]>
Quoted 54 lines
--- drivers/ntb/hw/intel/ntb_hw_intel.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-)drivers/ntb/hw/intel/ntb_hw_intel.c +1
-30@@ -59,6 +59,7 @@#include <linux/random.h> #include <linux/slab.h> #include <linux/ntb.h> +#include <linux/io-64-nonatomic-lo-hi.h> #include "ntb_hw_intel.h" @@ -155,35 +156,6 @@ MODULE_PARM_DESC(xeon_b2b_dsd_bar5_addr32,static inline enum ntb_topo xeon_ppd_topo (struct intel_ntb_dev *ndev,u8 ppd);static int xeon_init_isr (struct intel_ntb_dev *ndev); -#ifndef ioread64 -#ifdef readq -#define ioread64 readq -#else -#define ioread64 _ioread64 -static inline u64 _ioread64 (void __iomem *mmio) -{ -u64 low, high; - - low =ioread32 (mmio); - high =ioread32 (mmio +sizeof (u32)); -return low | (high <<32 ); -} -#endif -#endif - -#ifndef iowrite64 -#ifdef writeq -#define iowrite64 writeq -#else -#define iowrite64 _iowrite64 -static inline void _iowrite64 (u64 val,void __iomem *mmio) -{ -iowrite32 (val, mmio); -iowrite32 (val >>32 , mmio +sizeof (u32)); -} -#endif -#endif -static inline int pdev_is_atom (struct pci_dev *pdev) {switch (pdev->device) { --2.11.0
PATCH v4 5/5 crypto: caam: cleanup CONFIG_64BIT ifdefs when using io{read|write}64
In reply to Logan GunthorpeFrom: Horia Geantă <[email protected]>
We can now make use of the io-64-nonatomic-lo-hi header to always provide 64 bit IO operations. So this patch cleans up the extra CONFIG_64BIT ifdefs.
To be consistent with CAAM engine HW spec: in case of 64-bit registers, irrespective of device endianness, the lower address should be read from / written to first, followed by the upper address. Indeed the I/O accessors in CAAM driver currently don't follow the spec, however this is a good opportunity to fix the code.
--- drivers/crypto/caam/regs.h | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-)
drivers/crypto/caam/regs.h +5 -30
@@ -9,7 +9,7 @@#include <linux/types.h> #include <linux/bitops.h> -#include <linux/io.h> +#include <linux/io-64-nonatomic-lo-hi.h> /* * Architecture-specific register access methods
@@ -134,50 +134,25 @@ static inline void clrsetbits_32(void __iomem *reg, u32 clear, u32 set)* base + 0x0000 : least-significant 32 bits * base + 0x0004 : most-significant 32 bits */ -#ifdef CONFIG_64BIT static inline void wr_reg64 (void __iomem *reg,u64 data) { +#ifndef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX if (caam_little_end)iowrite64 (data, reg); else -iowrite64be (data, reg); -} - -static inline u64 rd_reg64 (void __iomem *reg) -{ -if (caam_little_end) -return ioread64 (reg); -else -return ioread64be (reg); -} - -#else /* CONFIG_64BIT */ -static inline void wr_reg64 (void __iomem *reg,u64 data) -{ -#ifndef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX -if (caam_little_end) { -wr_reg32 ((u32 __iomem *)(reg) +1 , data >>32 ); -wr_reg32 ((u32 __iomem *)(reg), data); - } else#endif - { -wr_reg32 ((u32 __iomem *)(reg), data >>32 ); -wr_reg32 ((u32 __iomem *)(reg) +1 , data); - } +iowrite64be (data, reg); }static inline u64 rd_reg64 (void __iomem *reg) {#ifndef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX if (caam_little_end) -return ((u64 )rd_reg32 ((u32 __iomem *)(reg) +1 ) <<32 | - (u64 )rd_reg32 ((u32 __iomem *)(reg))); +return ioread64 (reg); else#endif -return ((u64 )rd_reg32 ((u32 __iomem *)(reg)) <<32 | - (u64 )rd_reg32 ((u32 __iomem *)(reg) +1 )); +return ioread64be (reg); } -#endif /* CONFIG_64BIT */ #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT #ifdef CONFIG_SOC_IMX7D
Signature · 1 line
2.11.0