0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #define dev_fmt(fmt) "pciehp: " fmt
0017
0018 #include <linux/kernel.h>
0019 #include <linux/types.h>
0020 #include <linux/pci.h>
0021 #include "../pci.h"
0022 #include "pciehp.h"
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 int pciehp_configure_device(struct controller *ctrl)
0033 {
0034 struct pci_dev *dev;
0035 struct pci_dev *bridge = ctrl->pcie->port;
0036 struct pci_bus *parent = bridge->subordinate;
0037 int num, ret = 0;
0038
0039 pci_lock_rescan_remove();
0040
0041 dev = pci_get_slot(parent, PCI_DEVFN(0, 0));
0042 if (dev) {
0043
0044
0045
0046
0047 ctrl_dbg(ctrl, "Device %s already exists at %04x:%02x:00, skipping hot-add\n",
0048 pci_name(dev), pci_domain_nr(parent), parent->number);
0049 pci_dev_put(dev);
0050 ret = -EEXIST;
0051 goto out;
0052 }
0053
0054 num = pci_scan_slot(parent, PCI_DEVFN(0, 0));
0055 if (num == 0) {
0056 ctrl_err(ctrl, "No new device found\n");
0057 ret = -ENODEV;
0058 goto out;
0059 }
0060
0061 for_each_pci_bridge(dev, parent)
0062 pci_hp_add_bridge(dev);
0063
0064 pci_assign_unassigned_bridge_resources(bridge);
0065 pcie_bus_configure_settings(parent);
0066 pci_bus_add_devices(parent);
0067
0068 out:
0069 pci_unlock_rescan_remove();
0070 return ret;
0071 }
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 void pciehp_unconfigure_device(struct controller *ctrl, bool presence)
0085 {
0086 struct pci_dev *dev, *temp;
0087 struct pci_bus *parent = ctrl->pcie->port->subordinate;
0088 u16 command;
0089
0090 ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:00\n",
0091 __func__, pci_domain_nr(parent), parent->number);
0092
0093 if (!presence)
0094 pci_walk_bus(parent, pci_dev_set_disconnected, NULL);
0095
0096 pci_lock_rescan_remove();
0097
0098
0099
0100
0101
0102
0103
0104 list_for_each_entry_safe_reverse(dev, temp, &parent->devices,
0105 bus_list) {
0106 pci_dev_get(dev);
0107 pci_stop_and_remove_bus_device(dev);
0108
0109
0110
0111
0112 if (presence) {
0113 pci_read_config_word(dev, PCI_COMMAND, &command);
0114 command &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_SERR);
0115 command |= PCI_COMMAND_INTX_DISABLE;
0116 pci_write_config_word(dev, PCI_COMMAND, command);
0117 }
0118 pci_dev_put(dev);
0119 }
0120
0121 pci_unlock_rescan_remove();
0122 }