]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/pci/hotplug/shpchp_pci.c
Merge tag 'ntb-4.10' of git://github.com/jonmason/ntb
[mirror_ubuntu-zesty-kernel.git] / drivers / pci / hotplug / shpchp_pci.c
CommitLineData
1da177e4
LT
1/*
2 * Standard Hot Plug Controller Driver
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2003-2004 Intel Corporation
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
8cf4c195 26 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
1da177e4
LT
27 *
28 */
29
1da177e4
LT
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/types.h>
1da177e4
LT
33#include <linux/pci.h>
34#include "../pci.h"
35#include "shpchp.h"
1da177e4 36
10874f5a 37int shpchp_configure_device(struct slot *p_slot)
1da177e4 38{
dbd7a788 39 struct pci_dev *dev;
f98ca311 40 struct controller *ctrl = p_slot->ctrl;
7d01f70a
YL
41 struct pci_dev *bridge = ctrl->pci_dev;
42 struct pci_bus *parent = bridge->subordinate;
c4ec84c7
RW
43 int num, ret = 0;
44
45 pci_lock_rescan_remove();
dbd7a788 46
e00e57ef 47 dev = pci_get_slot(parent, PCI_DEVFN(p_slot->device, 0));
dbd7a788 48 if (dev) {
227f0647
RD
49 ctrl_err(ctrl, "Device %s already exists at %04x:%02x:%02x, cannot hot-add\n",
50 pci_name(dev), pci_domain_nr(parent),
51 p_slot->bus, p_slot->device);
e00e57ef 52 pci_dev_put(dev);
c4ec84c7
RW
53 ret = -EINVAL;
54 goto out;
1da177e4
LT
55 }
56
dbd7a788
RS
57 num = pci_scan_slot(parent, PCI_DEVFN(p_slot->device, 0));
58 if (num == 0) {
f98ca311 59 ctrl_err(ctrl, "No new device found\n");
c4ec84c7
RW
60 ret = -ENODEV;
61 goto out;
dbd7a788 62 }
1da177e4 63
fcbed0bc
YW
64 list_for_each_entry(dev, &parent->devices, bus_list) {
65 if (PCI_SLOT(dev->devfn) != p_slot->device)
dbd7a788 66 continue;
087cfa93 67 if (pci_is_bridge(dev))
7d01f70a 68 pci_hp_add_bridge(dev);
7d01f70a
YL
69 }
70
71 pci_assign_unassigned_bridge_resources(bridge);
b4071663 72 pcie_bus_configure_settings(parent);
dbd7a788 73 pci_bus_add_devices(parent);
7d01f70a 74
c4ec84c7
RW
75 out:
76 pci_unlock_rescan_remove();
77 return ret;
1da177e4
LT
78}
79
2178bfad 80int shpchp_unconfigure_device(struct slot *p_slot)
1da177e4
LT
81{
82 int rc = 0;
2178bfad 83 u8 bctl = 0;
e00e57ef 84 struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate;
fcbed0bc 85 struct pci_dev *dev, *temp;
f98ca311 86 struct controller *ctrl = p_slot->ctrl;
e00e57ef 87
be7bce25
TI
88 ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:%02x\n",
89 __func__, pci_domain_nr(parent), p_slot->bus, p_slot->device);
1da177e4 90
c4ec84c7
RW
91 pci_lock_rescan_remove();
92
fcbed0bc
YW
93 list_for_each_entry_safe(dev, temp, &parent->devices, bus_list) {
94 if (PCI_SLOT(dev->devfn) != p_slot->device)
2178bfad 95 continue;
fcbed0bc
YW
96
97 pci_dev_get(dev);
98 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
99 pci_read_config_byte(dev, PCI_BRIDGE_CONTROL, &bctl);
2178bfad 100 if (bctl & PCI_BRIDGE_CTL_VGA) {
f98ca311
TI
101 ctrl_err(ctrl,
102 "Cannot remove display device %s\n",
fcbed0bc
YW
103 pci_name(dev));
104 pci_dev_put(dev);
0ba10bc7
PK
105 rc = -EINVAL;
106 break;
2178bfad 107 }
1da177e4 108 }
fcbed0bc
YW
109 pci_stop_and_remove_bus_device(dev);
110 pci_dev_put(dev);
1da177e4 111 }
c4ec84c7
RW
112
113 pci_unlock_rescan_remove();
1da177e4
LT
114 return rc;
115}
116