Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 May 2020 17:00:51 +0000 (UTC)
From:      Emmanuel Vadot <manu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r360787 - in head/sys/compat/linuxkpi/common: include/linux src
Message-ID:  <202005071700.047H0pEl034066@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: manu
Date: Thu May  7 17:00:51 2020
New Revision: 360787
URL: https://svnweb.freebsd.org/changeset/base/360787

Log:
  linuxkpi: Add pci_iomap and pci_iounmap
  
  Those function are use to map/unmap io region of a pci device.
  Different resource can be mapped depending on the bar so use a
  tailq to store them all.
  
  Sponsored-by: The FreeBSD Foundation
  
  Reviewed by:	emaste, hselasky
  Differential Revision:	https://reviews.freebsd.org/D24696

Modified:
  head/sys/compat/linuxkpi/common/include/linux/pci.h
  head/sys/compat/linuxkpi/common/src/linux_pci.c

Modified: head/sys/compat/linuxkpi/common/include/linux/pci.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/pci.h	Thu May  7 16:56:18 2020	(r360786)
+++ head/sys/compat/linuxkpi/common/include/linux/pci.h	Thu May  7 17:00:51 2020	(r360787)
@@ -222,6 +222,13 @@ extern spinlock_t pci_lock;
 
 #define	__devexit_p(x)	x
 
+struct pci_mmio_region {
+	TAILQ_ENTRY(pci_mmio_region)	next;
+	struct resource			*res;
+	int				rid;
+	int				type;
+};
+
 struct pci_dev {
 	struct device		dev;
 	struct list_head	links;
@@ -236,6 +243,8 @@ struct pci_dev {
 	uint32_t		class;
 	uint8_t			revision;
 	bool			msi_enabled;
+
+	TAILQ_HEAD(, pci_mmio_region)	mmio;
 };
 
 static inline struct resource_list_entry *
@@ -657,6 +666,41 @@ static inline int pci_enable_sriov(struct pci_dev *dev
 }
 static inline void pci_disable_sriov(struct pci_dev *dev)
 {
+}
+
+static inline void *
+pci_iomap(struct pci_dev *dev, int mmio_bar, int mmio_size __unused)
+{
+	struct pci_mmio_region *mmio;
+
+	mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO);
+	mmio->rid = PCIR_BAR(mmio_bar);
+	mmio->type = pci_resource_type(dev, mmio_bar);
+	mmio->res = bus_alloc_resource_any(dev->dev.bsddev, mmio->type,
+	    &mmio->rid, RF_ACTIVE);
+	if (mmio->res == NULL) {
+		free(mmio, M_DEVBUF);
+		return (NULL);
+	}
+	TAILQ_INSERT_TAIL(&dev->mmio, mmio, next);
+
+	return ((void *)rman_get_bushandle(mmio->res));
+}
+
+static inline void
+pci_iounmap(struct pci_dev *dev, void *res)
+{
+	struct pci_mmio_region *mmio, *p;
+
+	TAILQ_FOREACH_SAFE(mmio, &dev->mmio, next, p) {
+		if (res != (void *)rman_get_bushandle(mmio->res))
+			continue;
+		bus_release_resource(dev->dev.bsddev,
+		    mmio->type, mmio->rid, mmio->res);
+		TAILQ_REMOVE(&dev->mmio, mmio, next);
+		free(mmio, M_DEVBUF);
+		return;
+	}
 }
 
 #define DEFINE_PCI_DEVICE_TABLE(_table) \

Modified: head/sys/compat/linuxkpi/common/src/linux_pci.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_pci.c	Thu May  7 16:56:18 2020	(r360786)
+++ head/sys/compat/linuxkpi/common/src/linux_pci.c	Thu May  7 17:00:51 2020	(r360787)
@@ -271,6 +271,7 @@ linux_pci_attach_device(device_t dev, struct pci_drive
 	if (error)
 		goto out_dma_init;
 
+	TAILQ_INIT(&pdev->mmio);
 	pbus = malloc(sizeof(*pbus), M_DEVBUF, M_WAITOK | M_ZERO);
 	pbus->self = pdev;
 	pbus->number = pci_get_bus(dev);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005071700.047H0pEl034066>