1 // SPDX-License-Identifier: GPL-2.0+
3 * Standard Hot Plug Controller Driver
5 * Copyright (C) 1995,2001 Compaq Computer Corporation
7 * Copyright (C) 2001 IBM Corp.
8 * Copyright (C) 2003-2004 Intel Corporation
10 * All rights reserved.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/types.h>
19 #include <linux/pci.h>
23 int shpchp_configure_device(struct slot *p_slot)
26 struct controller *ctrl = p_slot->ctrl;
27 struct pci_dev *bridge = ctrl->pci_dev;
28 struct pci_bus *parent = bridge->subordinate;
31 pci_lock_rescan_remove();
33 dev = pci_get_slot(parent, PCI_DEVFN(p_slot->device, 0));
35 ctrl_err(ctrl, "Device %s already exists at %04x:%02x:%02x, cannot hot-add\n",
36 pci_name(dev), pci_domain_nr(parent),
37 p_slot->bus, p_slot->device);
43 num = pci_scan_slot(parent, PCI_DEVFN(p_slot->device, 0));
45 ctrl_err(ctrl, "No new device found\n");
50 for_each_pci_bridge(dev, parent) {
51 if (PCI_SLOT(dev->devfn) == p_slot->device)
52 pci_hp_add_bridge(dev);
55 pci_assign_unassigned_bridge_resources(bridge);
56 pcie_bus_configure_settings(parent);
57 pci_bus_add_devices(parent);
60 pci_unlock_rescan_remove();
64 void shpchp_unconfigure_device(struct slot *p_slot)
66 struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate;
67 struct pci_dev *dev, *temp;
68 struct controller *ctrl = p_slot->ctrl;
70 ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:%02x\n",
71 __func__, pci_domain_nr(parent), p_slot->bus, p_slot->device);
73 pci_lock_rescan_remove();
75 list_for_each_entry_safe(dev, temp, &parent->devices, bus_list) {
76 if (PCI_SLOT(dev->devfn) != p_slot->device)
80 pci_stop_and_remove_bus_device(dev);
84 pci_unlock_rescan_remove();