[dpdk-dev] [PATCH 1/4] pci: allow access to PCI config space

Stephen Hemminger stephen at networkplumber.org
Mon May 11 19:31:04 CEST 2015


On Mon, 11 May 2015 12:54:54 +0000
Neil Horman <nhorman at tuxdriver.com> wrote:

> On Thu, May 07, 2015 at 04:25:32PM -0700, Stephen Hemminger wrote:
> > From: Stephen Hemminger <shemming at brocade.com>
> > 
> > Some drivers need ability to access PCI config (for example for power
> > management). This adds an abstraction to do this; only implemented
> > on Linux, but should be possible on BSD.
> > 

Could someone who has BSD infrastructure try this, not sure if it will even
build.

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 61e8921..8ba5b13 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -490,6 +490,76 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
 	return 1;
 }
 
+/* Read PCI config space. */
+int rte_eal_pci_read_config(const struct rte_pci_device *dev,
+			    void *buf, size_t len, off_t offset)
+{
+	int fd = -1;
+
+	fd = open("/dev/pci", O_RDONLY);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+		goto error;
+	}
+
+	struct pci_io pi = {
+		.pi_sel = {
+			.pc_domain = dev->addr.domain,
+			.bus = dev->addr.bus,
+			.pc_dev = dev->addr.devid,
+			.pc_func = dev->addr.function,
+		},
+		.pi_reg = offset,
+		.pi_data = buf,
+		.pi_width = len,
+	};
+
+	if (ioctl(fd, PCIIOCREAD, &pi) < 0)
+		goto error;
+	close(fd);
+	return 0;
+
+error:
+	if (fd >= 0)
+		close(fd);
+	return -1;
+}
+
+/* Write PCI config space. */
+int rte_eal_pci_write_config(const struct rte_pci_device *device,
+			     const void *buf, size_t len, off_t offset)
+{
+	int fd = -1;
+
+	fd = open("/dev/pci", O_RDONLY);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+		goto error;
+	}
+
+	struct pci_io pi = {
+		.pi_sel = {
+			.pc_domain = dev->addr.domain,
+			.bus = dev->addr.bus,
+			.pc_dev = dev->addr.devid,
+			.pc_func = dev->addr.function,
+		},
+		.pi_reg = offset,
+		.pi_data = buf,
+		.pi_width = len,
+	};
+
+	if (ioctl(fd, PCIIOCWRITE, &pi) < 0)
+		goto error;
+	close(fd);
+	return 0;
+
+error:
+	if (fd >= 0)
+		close(fd);
+	return -1;
+}
+
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)


More information about the dev mailing list