aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2021-05-28 11:16:12 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2021-07-18 00:35:03 +0000
commit40a215e38a4d01037fadc170116e157ad129854d (patch)
tree513cf4df8abe2116f6b4a1832e50e6567fc952ae
parentaf13c69522abc992de9fe652d229de9e71251c0c (diff)
downloadsrc-40a215e38a4d01037fadc170116e157ad129854d.tar.gz
src-40a215e38a4d01037fadc170116e157ad129854d.zip
LinuxKPI: extend pci.h by various functions for wireless driver
Add dummy functions for dealing with "HotPlug" events which we currently do not support. Add pci_dev_get(), pci_find_ext_capability() and pci_pme_capable(). The added pcie_find_root_port() is a bit special as we need to create another linux pci device; for that make lkpinew_pci_dev() public which is also helpful for other cases when we want to use the Linux routines to check for device identifiers only and need a container for the "bsddev" to use natively. This has proven to avoid basic checking code for the sake of rewriting it to native field names elsewhere. Given we cache the newly created "root" we also need to make sure we clean it up. Sponsored by: The FreeBSD Foundation Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D30521 (cherry picked from commit 8e106c5230c1f0683ffc473db5c2e0d01b2bfeea)
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pci.h88
-rw-r--r--sys/compat/linuxkpi/common/src/linux_pci.c6
2 files changed, 93 insertions, 1 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
index 36a82e81b4bc..b8a801ac9f70 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -221,6 +221,7 @@ struct pci_dev {
struct list_head links;
struct pci_driver *pdrv;
struct pci_bus *bus;
+ struct pci_dev *root;
uint16_t device;
uint16_t vendor;
uint16_t subsystem_vendor;
@@ -236,6 +237,10 @@ struct pci_dev {
TAILQ_HEAD(, pci_mmio_region) mmio;
};
+/* Internal helper function(s). */
+struct pci_dev *lkpinew_pci_dev(device_t);
+
+
static inline struct resource_list_entry *
linux_pci_get_rle(struct pci_dev *pdev, int type, int rid)
{
@@ -327,6 +332,15 @@ pci_set_drvdata(struct pci_dev *pdev, void *data)
dev_set_drvdata(&pdev->dev, data);
}
+static inline struct pci_dev *
+pci_dev_get(struct pci_dev *pdev)
+{
+
+ if (pdev != NULL)
+ get_device(&pdev->dev);
+ return (pdev);
+}
+
static __inline void
pci_dev_put(struct pci_dev *pdev)
{
@@ -497,6 +511,48 @@ static inline int pci_pcie_cap(struct pci_dev *dev)
}
static inline int
+pci_find_ext_capability(struct pci_dev *pdev, int capid)
+{
+ int reg;
+
+ if (pci_find_extcap(pdev->dev.bsddev, capid, &reg))
+ return (0);
+ return (reg);
+}
+
+#define PCIM_PCAP_PME_SHIFT 11
+static __inline bool
+pci_pme_capable(struct pci_dev *pdev, uint32_t flag)
+{
+ struct pci_devinfo *dinfo;
+ pcicfgregs *cfg;
+
+ if (flag > (PCIM_PCAP_D3PME_COLD >> PCIM_PCAP_PME_SHIFT))
+ return (false);
+
+ dinfo = device_get_ivars(pdev->dev.bsddev);
+ cfg = &dinfo->cfg;
+
+ if (cfg->pp.pp_cap == 0)
+ return (false);
+
+ if ((cfg->pp.pp_cap & (1 << (PCIM_PCAP_PME_SHIFT + flag))) != 0)
+ return (true);
+
+ return (false);
+}
+
+static inline int
+pci_disable_link_state(struct pci_dev *pdev, uint32_t flags)
+{
+
+ if (!pci_enable_aspm)
+ return (-EPERM);
+
+ return (-ENXIO);
+}
+
+static inline int
pci_read_config_byte(struct pci_dev *pdev, int where, u8 *val)
{
@@ -1052,6 +1108,38 @@ pcie_bandwidth_available(struct pci_dev *pdev,
return (nwidth * PCIE_SPEED2MBS_ENC(nspeed));
}
+static inline struct pci_dev *
+pcie_find_root_port(struct pci_dev *pdev)
+{
+ device_t root;
+
+ if (pdev->root != NULL)
+ return (pdev->root);
+
+ root = pci_find_pcie_root_port(pdev->dev.bsddev);
+ if (root == NULL)
+ return (NULL);
+
+ pdev->root = lkpinew_pci_dev(root);
+ return (pdev->root);
+}
+
+/* This is needed when people rip out the device "HotPlug". */
+static inline void
+pci_lock_rescan_remove(void)
+{
+}
+
+static inline void
+pci_unlock_rescan_remove(void)
+{
+}
+
+static __inline void
+pci_stop_and_remove_bus_device(struct pci_dev *pdev)
+{
+}
+
/*
* The following functions can be used to attach/detach the LinuxKPI's
* PCI device runtime. The pci_driver and pci_device_id pointer is
diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
index 7aa159600faa..030951175a42 100644
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -243,11 +243,13 @@ lkpinew_pci_dev_release(struct device *dev)
struct pci_dev *pdev;
pdev = to_pci_dev(dev);
+ if (pdev->root != NULL)
+ pci_dev_put(pdev->root);
free(pdev->bus, M_DEVBUF);
free(pdev, M_DEVBUF);
}
-static struct pci_dev *
+struct pci_dev *
lkpinew_pci_dev(device_t dev)
{
struct pci_dev *pdev;
@@ -408,6 +410,8 @@ linux_pci_detach_device(struct pci_dev *pdev)
if (pdev->pdrv != NULL)
pdev->pdrv->remove(pdev);
+ if (pdev->root != NULL)
+ pci_dev_put(pdev->root);
free(pdev->bus, M_DEVBUF);
linux_pdev_dma_uninit(pdev);