patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: ncopa@alpinelinux.org, stable@dpdk.org,
	Ferruh Yigit <ferruh.yigit@intel.com>,
	Yuanhan Liu <yuanhan.liu@linux.intel.com>,
	David Marchand <david.marchand@6wind.com>
Subject: [dpdk-stable] [PATCH v6 08/17] bus/pci: support I/O port operations with musl
Date: Sun, 28 Feb 2021 13:53:43 +0100	[thread overview]
Message-ID: <20210228125353.2436562-9-thomas@monjalon.net> (raw)
In-Reply-To: <20210228125353.2436562-1-thomas@monjalon.net>

From: Natanael Copa <ncopa@alpinelinux.org>

Add a fallback for non-GNU libc systems like musl libc for the
non-standard functions outl_p, outw_p and outb_p.

This solves the following buildtime errors when building with musl libc:
pci_uio.c:(.text+0xaa1): undefined reference to `outw_p'
pci_uio.c:(.text+0xac5): undefined reference to `outl_p'
pci_uio.c:(.text+0xadf): undefined reference to `outb_p'

The non-x86 case are handled with macros to factor out various ifdefs.

Bugzilla ID: 35
Fixes: 756ce64b1ecd ("eal: introduce PCI ioport API")
Cc: stable@dpdk.org

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 drivers/bus/pci/linux/pci_uio.c | 91 ++++++++++++++++++++++-----------
 1 file changed, 61 insertions(+), 30 deletions(-)

diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c
index f3305a2f28..1294f505be 100644
--- a/drivers/bus/pci/linux/pci_uio.c
+++ b/drivers/bus/pci/linux/pci_uio.c
@@ -489,6 +489,16 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar,
 }
 #endif
 
+#ifdef RTE_ARCH_X86
+#define pci_uio_inl(reg) inl(reg)
+#define pci_uio_inw(reg) inw(reg)
+#define pci_uio_inb(reg) inb(reg)
+#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))
+#endif
+
 void
 pci_uio_ioport_read(struct rte_pci_ioport *p,
 		    void *data, size_t len, off_t offset)
@@ -500,29 +510,62 @@ 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);
 		}
 	}
 }
 
+#ifdef RTE_ARCH_X86
+static inline void
+pci_uio_outl_p(unsigned int value, unsigned short int port)
+{
+#ifdef __GLIBC__
+	outl_p(value, port);
+#else
+	__asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80" : : "a" (value),
+			      "Nd" (port));
+#endif
+}
+#else /* !RTE_ARCH_X86 */
+#define pci_uio_outl_p(value, reg) (*(volatile uint32_t *)(reg) = (value))
+#endif
+
+#ifdef RTE_ARCH_X86
+static inline void
+pci_uio_outw_p(unsigned short int value, unsigned short int port)
+{
+#ifdef __GLIBC__
+	outw_p(value, port);
+#else
+	__asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80" : : "a" (value),
+			      "Nd" (port));
+#endif
+}
+#else /* !RTE_ARCH_X86 */
+#define pci_uio_outw_p(value, reg) (*(volatile uint16_t *)(reg) = (value))
+#endif
+
+#ifdef RTE_ARCH_X86
+static inline void
+pci_uio_outb_p(unsigned char value, unsigned short int port)
+{
+#ifdef __GLIBC__
+	outb_p(value, port);
+#else
+	__asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80" : : "a" (value),
+			      "Nd" (port));
+#endif
+}
+#else /* !RTE_ARCH_X86 */
+#define pci_uio_outb_p(value, reg) (*(volatile uint8_t *)(reg) = (value))
+#endif
+
 void
 pci_uio_ioport_write(struct rte_pci_ioport *p,
 		     const void *data, size_t len, off_t offset)
@@ -534,25 +577,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)
-			outl_p(*(const uint32_t *)s, reg);
-#else
-			*(volatile uint32_t *)reg = *(const uint32_t *)s;
-#endif
+			pci_uio_outl_p(*(const uint32_t *)s, reg);
 		} else if (len >= 2) {
 			size = 2;
-#if defined(RTE_ARCH_X86)
-			outw_p(*(const uint16_t *)s, reg);
-#else
-			*(volatile uint16_t *)reg = *(const uint16_t *)s;
-#endif
+			pci_uio_outw_p(*(const uint16_t *)s, reg);
 		} else {
 			size = 1;
-#if defined(RTE_ARCH_X86)
-			outb_p(*s, reg);
-#else
-			*(volatile uint8_t *)reg = *s;
-#endif
+			pci_uio_outb_p(*s, reg);
 		}
 	}
 }
-- 
2.30.1


  parent reply	other threads:[~2021-02-28 12:54 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190313170657.16688-1-ncopa@alpinelinux.org>
     [not found] ` <20210225182250.1149592-1-thomas@monjalon.net>
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 01/17] eal: fix comment of OS-specific header files Thomas Monjalon
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 02/17] buildtools: fix build with busybox Thomas Monjalon
2021-02-26  9:11     ` Bruce Richardson
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 03/17] build: detect execinfo library on Linux Thomas Monjalon
2021-02-26  9:08     ` Bruce Richardson
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 04/17] build: define _GNU_SOURCE globally Thomas Monjalon
2021-02-26  9:08     ` Bruce Richardson
2021-02-26  9:40       ` Thomas Monjalon
2021-02-26  9:46         ` Bruce Richardson
2021-02-26 10:04           ` Thomas Monjalon
2021-02-28 12:53             ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 05/17] eal/linux: fix build with musl Thomas Monjalon
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 06/17] drivers: fix header includes for musl Thomas Monjalon
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 08/17] bus/pci: support I/O port operations with musl Thomas Monjalon
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 09/17] bus/dpaa: fix 64-bit arch detection Thomas Monjalon
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 10/17] bus/dpaa: fix build with musl Thomas Monjalon
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 11/17] common/dpaax/caamflib: " Thomas Monjalon
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 13/17] net/cxgbe: remove use of uint type Thomas Monjalon
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 14/17] net/igc: " Thomas Monjalon
2021-02-26  0:49     ` Wang, Haiyue
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 15/17] vdpa/mlx5: replace pthread functions unavailable in musl Thomas Monjalon
2021-03-01  7:30     ` Matan Azrad
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 16/17] app/testpmd: fix build with musl Thomas Monjalon
2021-02-25 18:22   ` [dpdk-stable] [PATCH v5 17/17] examples/bbdev: fix header include for musl Thomas Monjalon
     [not found] ` <20210228125353.2436562-1-thomas@monjalon.net>
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 01/17] eal: fix comment of OS-specific header files Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 02/17] buildtools: fix build with busybox Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 03/17] build: detect execinfo library on Linux Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 04/17] build: remove redundant _GNU_SOURCE definitions Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 05/17] eal: fix build with musl Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 06/17] drivers: fix header includes for musl Thomas Monjalon
2021-02-28 12:53   ` Thomas Monjalon [this message]
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 09/17] bus/dpaa: fix 64-bit arch detection Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 10/17] bus/dpaa: fix build with musl Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 11/17] common/dpaax/caamflib: " Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 13/17] net/cxgbe: remove use of uint type Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 14/17] net/igc: " Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 15/17] vdpa/mlx5: replace pthread functions unavailable in musl Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 16/17] app/testpmd: fix build with musl Thomas Monjalon
2021-02-28 12:53   ` [dpdk-stable] [PATCH v6 17/17] examples/bbdev: fix header include for musl Thomas Monjalon
     [not found] ` <20210319145730.3555384-1-thomas@monjalon.net>
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 01/17] eal: fix comment of OS-specific header files Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 02/17] buildtools: fix build with busybox Thomas Monjalon
2021-03-22  8:52     ` Kinsella, Ray
2021-03-22  8:55       ` Thomas Monjalon
2021-03-22  9:01         ` Kinsella, Ray
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 03/17] build: detect execinfo library on Linux Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 04/17] build: remove redundant _GNU_SOURCE definitions Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 05/17] eal: fix build with musl Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 07/17] common/dpaax/caamflib: " Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 09/17] bus/dpaa: fix 64-bit arch detection Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 10/17] bus/dpaa: fix build with musl Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 11/17] bus/pci: support I/O port operations " Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 12/17] net/cxgbe: remove use of uint type Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 13/17] net/igc: " Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 14/17] vdpa/mlx5: replace pthread functions unavailable in musl Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 15/17] event/dlb: fix header includes for musl Thomas Monjalon
2021-03-19 15:47     ` McDaniel, Timothy
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 16/17] app/testpmd: fix build with musl Thomas Monjalon
2021-03-19 14:57   ` [dpdk-stable] [PATCH v7 17/17] examples/bbdev: fix header include for musl Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210228125353.2436562-9-thomas@monjalon.net \
    --to=thomas@monjalon.net \
    --cc=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=ncopa@alpinelinux.org \
    --cc=stable@dpdk.org \
    --cc=yuanhan.liu@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).