Add io{read|write}64 to io-64-atomic headers
Subsystems (9)
Logan Gunthorpe
maintainerv25 cover Add io{read|write}64 to io-64-atomic headers
This is resend number 6 since the last change to this series.
This cleanup was requested by Greg KH back in June of 2017. I've resent the series a couple times a cycle since then, updating and fixing as feedback was slowly recieved some patches were alread accepted by specific arches. In June 2018, Andrew picked the remainder of this up and it was in linux-next for a couple weeks. There were a couple problems that were identified and addressed back then and I'd really like to get the ball rolling again. A year and a half of sending this without much feedback is far too long.
@Andrew, can you please pick this set up again so it can get into linux-next? Or let me know if there's something else I should be doing.
Thanks,
Logan
--
Changes since v24:
- Rebased onto v5.0-rc2 (No Changes)
Changes since v23:
- Rebased onto v4.20-rc4 (No Changes)
Changes since v22:
- Rebased onto v4.20-rc1 (No Changes)
Changes since v21:
- Rebased onto v4.19-rc6 (No Changes)
Changes since v20:
- Rebased onto v4.19-rc3 (No Changes)
Changes since v19:
- Rebased onto v4.19-rc1 (No Changes)
Changes since v18:
- Dropped the CAAM patch as it was subtly wrong and broke when people tested it in linux-next. Seeing the code is much trickier than it appears, we'll leave it to its maintainers to clean it up, should they chose.
- Restored the ioread64/iowrite64 extern prototypes as despite appearing to be unusued, they are in fact used in a rare corner case by the caam driver on 64bit powerpc. This was reported by Guenter testing on linux-next.
- Rebased onto v4.18-rc4 (No Changes)
Changes since v17:
- Rebased onto v4.18-rc1 (No Changes)
Changes since v16:
- Rebased onto v4.17-rc4 (No Changes)
Changes since v15:
- Rebased onto v4.17-rc1, dropping the powerpc patches which were picked up by Michael
Changes since v14:
- Rebased onto v4.16-rc7
- Replace the first two patches so that instead of correcting the endianness annotations we change to using writeX() and readX() with swabX() calls. This makes the big-endian functions more symmetric with the little-endian versions (with respect to barriers that are not included in the raw functions). As a side effect, it also fixes the kbuild warnings that the first two patches tried to address.
Changes since v13:
- Changed the subject of patch 0001 to correct a nit pointed out by Luc
Changes since v12:
- Rebased onto v4.16-rc6
- Split patch 0001 into two and reworked the commit log as requested by Luc Van Oostenryck
Changes since v11:
- Rebased onto v4.16-rc5
- Added a patch (0001) to fix some old and new sparse warnings that the kbuild robot warned about this cycle. The latest version of sparse was required to reproduce these.
- Added a patch (0002) to add io{read|write}64 to parisc which the kbuild robot also found errors for this cycle
Changes since v10:
- Rebased onto v4.16-rc4, this droped the drm/tilcdc patch which was picked up by that tree and is already in 4.16.
Changes since v9:
- Rebased onto v4.15-rc6
- Fixed a couple of issues in the new version of the CAAM patch as pointed out by Horia
Changes since v8:
- Rebased onto v4.15-rc2, as a result rewrote patch 7 seeing someone did some similar cleanup in that area.
- Added a patch to clean up the Switchtec NTB driver which landed in v4.15-rc1
Changes since v7:
- Fix minor nits from Andy Shevchenko
- Rebased onto v4.14-rc1
Changes since v6:
** none **
Changes since v5:
- Added a fix to the tilcdc driver to ensure it doesn't use the non-atomic operation. (This includes adding io{read|write}64[be]_is_nonatomic defines).
Changes since v4:
- Add functions so the powerpc implementation of iomap.c compiles. (As noticed by Horia)
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.
(earlier versions were drastically different)
--
Logan Gunthorpe (6):
iomap: Use non-raw io functions for io{read|write}XXbe
parisc: iomap: introduce io{read|write}64
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
ntb: ntb_hw_switchtec: Cleanup 64bit IO defines to use the common
header
arch/parisc/include/asm/io.h | 9 ++ arch/parisc/lib/iomap.c | 64 +++++++++++ arch/powerpc/include/asm/io.h | 2 + drivers/ntb/hw/intel/ntb_hw_intel.h | 30 +----- drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 36 +------ include/asm-generic/iomap.h | 22 ++++ include/linux/io-64-nonatomic-hi-lo.h | 64 +++++++++++ include/linux/io-64-nonatomic-lo-hi.h | 64 +++++++++++ lib/iomap.c | 140 ++++++++++++++++++++++++- 9 files changed, 366 insertions(+), 65 deletions(-)
--
2.19.0
Logan Gunthorpe
maintainerPATCH v25 1/6 iomap: Use non-raw io functions for io{read|write}XXbe
Fix an asymmetry in the io{read|write}XXbe functions in that the big-endian variants make use of the raw io accessors while the little-endian variants use the regular accessors. Some architectures implement barriers to order against both spinlocks and DMA accesses and for these case, the big-endian variant of the API would not be protected.
Thus, change the mmio_XXXXbe macros to use the appropriate swab() function wrapping the regular accessor. This is similar to what was done for PIO.
When this code was originally written, barriers in the IO accessors were not common and the accessors simply wrapped the raw functions in a conversion to CPU endianness. Since then, barriers have been added in some architectures and are now missing in the big endian variant of the API.
This also manages to silence a few sparse warnings that check for using the correct endian types which the original code did not annotate correctly.
--- lib/iomap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/iomap.c +4 -4
@@ -65,8 +65,8 @@ static void bad_io_access(unsigned long port, const char *access)#endif #ifndef mmio_read16be -#define mmio_read16be (addr) be16_to_cpu(__raw_readw(addr)) -#define mmio_read32be (addr) be32_to_cpu(__raw_readl(addr)) +#define mmio_read16be (addr) swab16(readw(addr)) +#define mmio_read32be (addr) swab32(readl(addr))#endif unsigned int ioread8 (void __iomem *addr)
@@ -106,8 +106,8 @@ EXPORT_SYMBOL(ioread32be);#endif #ifndef mmio_write16be -#define mmio_write16be (val,port) __raw_writew(be16_to_cpu(val),port) -#define mmio_write32be (val,port) __raw_writel(be32_to_cpu(val),port) +#define mmio_write16be (val,port) writew(swab16(val),port) +#define mmio_write32be (val,port) writel(swab32(val),port)#endif void iowrite8 (u8 val,void __iomem *addr)
Signature · 1 line
2.19.0
Logan Gunthorpe
maintainerPATCH v25 2/6 parisc: iomap: introduce io{read|write}64
In reply to Logan GunthorpeAdd support for io{read|write}64() functions in parisc architecture. These are pretty straightforward copies of similar functions which make use of readq and writeq.
Also, indicate that the lo_hi and hi_lo variants of these functions are not provided by this architecture.
--- arch/parisc/include/asm/io.h | 9 +++++ arch/parisc/lib/iomap.c | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+)
arch/parisc/include/asm/io.h +9 -0
@@ -311,6 +311,15 @@ extern void outsl (unsigned long port, const void *src, unsigned long count);* value for either 32 or 64 bit mode */ #define F_EXTEND (x) ((unsigned long)((x) | (0xffffffff00000000ULL))) +#define ioread64 ioread64 +#define ioread64be ioread64be +#define iowrite64 iowrite64 +#define iowrite64be iowrite64be +extern u64 ioread64 (void __iomem *addr); +extern u64 ioread64be (void __iomem *addr); +extern void iowrite64 (u64 val,void __iomem *addr); +extern void iowrite64be (u64 val,void __iomem *addr); +#include <asm-generic/iomap.h> /*
arch/parisc/lib/iomap.c +64 -0
121 lines not on this page · raw message
Signature · 1 line
2.19.0
Logan Gunthorpe
maintainerPATCH v25 3/6 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 | 22 ++++++ lib/iomap.c | 132 ++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+)
arch/powerpc/include/asm/io.h +2 -0
@@ -783,8 +783,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 +22 -0
@@ -36,6 +36,17 @@ extern u64 ioread64(void __iomem *);extern u64 ioread64be (void __iomem *);#endif +#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 *);extern void iowrite16 (u16 ,void __iomem *);extern void iowrite16be (u16 ,void __iomem *);
@@ -46,6 +57,17 @@ extern void iowrite64(u64, void __iomem *);extern void iowrite64be (u64 ,void __iomem *);#endif +#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 +extern void iowrite64_lo_hi (u64 val,void __iomem *addr); +extern void iowrite64_hi_lo (u64 val,void __iomem *addr); +extern void iowrite64be_lo_hi (u64 val,void __iomem *addr); +extern void iowrite64be_hi_lo (u64 val,void __iomem *addr); +#endif +/* * "string" versions of the above. Note that they * use native byte ordering for the accesses (on
lib/iomap.c +132 -0
156 lines not on this page · raw message
Signature · 1 line
2.19.0
Logan Gunthorpe
maintainerPATCH v25 4/6 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 | 64 +++++++++++++++++++++++++++ include/linux/io-64-nonatomic-lo-hi.h | 64 +++++++++++++++++++++++++++ 2 files changed, 128 insertions(+)
include/linux/io-64-nonatomic-hi-lo.h +64 -0
@@ -55,4 +55,68 @@ 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_is_nonatomic +#define ioread64 ioread64_hi_lo +#endif + +#ifndef iowrite64 +#define iowrite64_is_nonatomic +#define iowrite64 iowrite64_hi_lo +#endif + +#ifndef ioread64be +#define ioread64be_is_nonatomic +#define ioread64be ioread64be_hi_lo +#endif + +#ifndef iowrite64be +#define iowrite64be_is_nonatomic +#define iowrite64be iowrite64be_hi_lo +#endif +#endif /* _LINUX_IO_64_NONATOMIC_HI_LO_H_ */
include/linux/io-64-nonatomic-lo-hi.h +64 -0
68 lines not on this page · raw message
Signature · 1 line
2.19.0
Logan Gunthorpe
maintainerPATCH v25 5/6 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.h | 30 +---------------------------- 1 file changed, 1 insertion(+), 29 deletions(-)
drivers/ntb/hw/intel/ntb_hw_intel.h +1 -29
@@ -53,6 +53,7 @@#include <linux/ntb.h> #include <linux/pci.h> +#include <linux/io-64-nonatomic-lo-hi.h> /* PCI device IDs */ #define PCI_DEVICE_ID_INTEL_NTB_B2B_JSF 0x3725
@@ -218,33 +219,4 @@ static inline int pdev_is_gen3(struct pci_dev *pdev) return 0; } -#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 -#endif
Signature · 1 line
2.19.0
Logan Gunthorpe
maintainerPATCH v25 6/6 ntb: ntb_hw_switchtec: Cleanup 64bit IO defines to use the common header
In reply to Logan GunthorpeClean up the ifdefs which conditionally defined the io{read|write}64 functions in favour of the new common io-64-nonatomic-lo-hi header.
Per a nit from Andy Shevchenko, the include list is also made alphabetical.
--- drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 36 +++----------------------- 1 file changed, 4 insertions(+), 32 deletions(-)
drivers/ntb/hw/mscc/ntb_hw_switchtec.c +4 -32
@@ -13,13 +13,14 @@* */ -#include <linux/switchtec.h> -#include <linux/module.h> +#include <linux/interrupt.h> +#include <linux/io-64-nonatomic-lo-hi.h> #include <linux/delay.h> #include <linux/kthread.h> -#include <linux/interrupt.h> +#include <linux/module.h> #include <linux/ntb.h> #include <linux/pci.h> +#include <linux/switchtec.h> MODULE_DESCRIPTION ("Microsemi Switchtec(tm) NTB Driver" );MODULE_VERSION ("0.1" );
@@ -36,35 +37,6 @@ module_param(use_lut_mws, bool, 0644);MODULE_PARM_DESC (use_lut_mws,"Enable the use of the LUT based memory windows" ); -#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 -#define SWITCHTEC_NTB_MAGIC 0x45CC0001#define MAX_MWS 128
Signature · 1 line
2.19.0
Quoted 10 lines · Logan Gunthorpe
This is resend number 6 since the last change to this series.
This cleanup was requested by Greg KH back in June of 2017. I've resent the series a couple times a cycle since then, updating and fixing as feedback was slowly recieved some patches were alread accepted by specific arches. In June 2018, Andrew picked the remainder of this up and it was in linux-next for a couple weeks. There were a couple problems that were identified and addressed back then and I'd really like to get the ball rolling again. A year and a half of sending this without much feedback is far too long.
Quoted 2 lines
@Andrew, can you please pick this set up again so it can get into linux-next? Or let me know if there's something else I should be doing.
version 25? That's crazy, this has gone on too long. I've taken this into my char/misc driver tree now, so sorry for the long suffering you have gone through for this.
Thanks for being persistent,
greg k-h
Logan Gunthorpe
maintainerQuoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Logan Gunthorpe
This is resend number 6 since the last change to this series.
This cleanup was requested by Greg KH back in June of 2017. I've resent the series a couple times a cycle since then, updating and fixing as feedback was slowly recieved some patches were alread accepted by specific arches. In June 2018, Andrew picked the remainder of this up and it was in linux-next for a couple weeks. There were a couple problems that were identified and addressed back then and I'd really like to get the ball rolling again. A year and a half of sending this without much feedback is far too long.
Quoted 6 lines
Quoted 2 lines
@Andrew, can you please pick this set up again so it can get into linux-next? Or let me know if there's something else I should be doing.
version 25? That's crazy, this has gone on too long. I've taken this into my char/misc driver tree now, so sorry for the long suffering you have gone through for this.
Thanks a lot!
Logan