[04/15] bus/pci: factor out various ifdefs in pci_uio_ioport_{read, write}

Message ID 20190311173702.24471-5-ncopa@alpinelinux.org (mailing list archive)
State Superseded, archived
Headers
Series Build fixes for musl libc |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation fail Compilation issues

Commit Message

Natanael Copa March 11, 2019, 5:36 p.m. UTC
  define the macros so we can remove various #if defined(RTE_ARCH_X86)

Ref: https://bugs.dpdk.org/show_bug.cgi?id=35#c6

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---

Please note that this is only compile tested with musl libc on x86_64.

 drivers/bus/pci/linux/pci_uio.c | 54 +++++++++++++++------------------
 1 file changed, 24 insertions(+), 30 deletions(-)
  

Patch

diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c
index 6058cd9f8..dfa42c565 100644
--- a/drivers/bus/pci/linux/pci_uio.c
+++ b/drivers/bus/pci/linux/pci_uio.c
@@ -14,11 +14,18 @@ 
 
 #if defined(RTE_ARCH_X86)
 #include <sys/io.h>
+
+#define pci_uio_inl(reg) inl(reg)
+#define pci_uio_inw(reg) inw(reg)
+#define pci_uio_inb(reg) inb(reg)
+
 #if defined(__GLIBC__)
+
 #define pci_uio_outl_p outl_p
 #define pci_uio_outw_p outw_p
 #define pci_uio_outb_p outb_p
-#else
+
+#else /* defined(__GLIBC__) */
 static inline void
 pci_uio_outl_p(unsigned int value, unsigned short int port)
 {
@@ -39,8 +46,19 @@  pci_uio_outb_p(unsigned char value, unsigned short int port)
   __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
 			"Nd" (port));
 }
-#endif
-#endif
+#endif /* defined(__GLIBC__) */
+
+#else /* RTE_ARCH_X86 */
+
+#define pci_uio_inl(reg) *(volatile uint32_t *)(reg)
+#define pci_uio_inw(reg) *(volatile uint16_t *)(reg)
+#define pci_uio_inb(reg) *(volatile uint8_t *)(reg)
+
+#define pci_uio_outl_p(value, reg) *(volatile uint32_t *)(reg) = (value)
+#define pci_uio_outw_p(value, reg) *(volatile uint16_t *)(reg) = (value)
+#define pci_uio_outb_p(value, reg) *(volatile uint8_t *)(reg) = (value)
+
+#endif /* RTE_ARCH_X86 */
 
 #include <rte_log.h>
 #include <rte_pci.h>
@@ -518,25 +536,13 @@  pci_uio_ioport_read(struct rte_pci_ioport *p,
 	for (d = data; len > 0; d += size, reg += size, len -= size) {
 		if (len >= 4) {
 			size = 4;
-#if defined(RTE_ARCH_X86)
-			*(uint32_t *)d = inl(reg);
-#else
-			*(uint32_t *)d = *(volatile uint32_t *)reg;
-#endif
+			*(uint32_t *)d = pci_uio_inl(reg);
 		} else if (len >= 2) {
 			size = 2;
-#if defined(RTE_ARCH_X86)
-			*(uint16_t *)d = inw(reg);
-#else
-			*(uint16_t *)d = *(volatile uint16_t *)reg;
-#endif
+			*(uint16_t *)d = pci_uio_inw(reg);
 		} else {
 			size = 1;
-#if defined(RTE_ARCH_X86)
-			*d = inb(reg);
-#else
-			*d = *(volatile uint8_t *)reg;
-#endif
+			*d = pci_uio_inb(reg);
 		}
 	}
 }
@@ -552,25 +558,13 @@  pci_uio_ioport_write(struct rte_pci_ioport *p,
 	for (s = data; len > 0; s += size, reg += size, len -= size) {
 		if (len >= 4) {
 			size = 4;
-#if defined(RTE_ARCH_X86)
 			pci_uio_outl_p(*(const uint32_t *)s, reg);
-#else
-			*(volatile uint32_t *)reg = *(const uint32_t *)s;
-#endif
 		} else if (len >= 2) {
 			size = 2;
-#if defined(RTE_ARCH_X86)
 			pci_uio_outw_p(*(const uint16_t *)s, reg);
-#else
-			*(volatile uint16_t *)reg = *(const uint16_t *)s;
-#endif
 		} else {
 			size = 1;
-#if defined(RTE_ARCH_X86)
 			pci_uio_outb_p(*s, reg);
-#else
-			*(volatile uint8_t *)reg = *s;
-#endif
 		}
 	}
 }