Page MenuHomeFreeBSD

D24514.diff
No OneTemporary

D24514.diff

Index: head/sys/compat/linuxkpi/common/include/linux/pci.h
===================================================================
--- head/sys/compat/linuxkpi/common/include/linux/pci.h
+++ head/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -954,4 +954,15 @@
return (PCIE_LNK_WIDTH_UNKNOWN);
}
+/*
+ * The following functions can be used to attach/detach the LinuxKPI's
+ * PCI device runtime. The pci_driver and pci_device_id pointer is
+ * allowed to be NULL. Other pointers must be all valid.
+ * The pci_dev structure should be zero-initialized before passed
+ * to the linux_pci_attach_device function.
+ */
+extern int linux_pci_attach_device(device_t, struct pci_driver *,
+ const struct pci_device_id *, struct pci_dev *);
+extern int linux_pci_detach_device(struct pci_dev *);
+
#endif /* _LINUX_PCI_H_ */
Index: head/sys/compat/linuxkpi/common/src/linux_pci.c
===================================================================
--- head/sys/compat/linuxkpi/common/src/linux_pci.c
+++ head/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -213,22 +213,33 @@
static int
linux_pci_attach(device_t dev)
{
+ const struct pci_device_id *id;
+ struct pci_driver *pdrv;
+ struct pci_dev *pdev;
+
+ pdrv = linux_pci_find(dev, &id);
+ pdev = device_get_softc(dev);
+
+ MPASS(pdrv != NULL);
+ MPASS(pdev != NULL);
+
+ return (linux_pci_attach_device(dev, pdrv, id, pdev));
+}
+
+int
+linux_pci_attach_device(device_t dev, struct pci_driver *pdrv,
+ const struct pci_device_id *id, struct pci_dev *pdev)
+{
struct resource_list_entry *rle;
struct pci_bus *pbus;
- struct pci_dev *pdev;
struct pci_devinfo *dinfo;
- struct pci_driver *pdrv;
- const struct pci_device_id *id;
device_t parent;
int error;
linux_set_current(curthread);
- pdrv = linux_pci_find(dev, &id);
- pdev = device_get_softc(dev);
-
- parent = device_get_parent(dev);
- if (pdrv->isdrm) {
+ if (pdrv != NULL && pdrv->isdrm) {
+ parent = device_get_parent(dev);
dinfo = device_get_ivars(parent);
device_set_ivars(dev, dinfo);
} else {
@@ -270,9 +281,11 @@
list_add(&pdev->links, &pci_devices);
spin_unlock(&pci_lock);
- error = pdrv->probe(pdev, id);
- if (error)
- goto out_probe;
+ if (pdrv != NULL) {
+ error = pdrv->probe(pdev, id);
+ if (error)
+ goto out_probe;
+ }
return (0);
out_probe:
@@ -291,18 +304,30 @@
{
struct pci_dev *pdev;
- linux_set_current(curthread);
pdev = device_get_softc(dev);
- pdev->pdrv->remove(pdev);
+ MPASS(pdev != NULL);
+ device_set_desc(dev, NULL);
+
+ return (linux_pci_detach_device(pdev));
+}
+
+int
+linux_pci_detach_device(struct pci_dev *pdev)
+{
+
+ linux_set_current(curthread);
+
+ if (pdev->pdrv != NULL)
+ pdev->pdrv->remove(pdev);
+
free(pdev->bus, M_DEVBUF);
linux_pdev_dma_uninit(pdev);
spin_lock(&pci_lock);
list_del(&pdev->links);
spin_unlock(&pci_lock);
- device_set_desc(dev, NULL);
put_device(&pdev->dev);
return (0);

File Metadata

Mime Type
text/plain
Expires
Fri, Feb 14, 4:22 PM (21 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16644911
Default Alt Text
D24514.diff (2 KB)

Event Timeline