blob: f8cd3a27e3515e630639e86a8e58478517f5ec2a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Kristen Accardi8cf4c192005-08-16 15:16:10 -070026 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 *
28 */
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/pci.h>
34#include "../pci.h"
35#include "shpchp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Bjorn Helgaas10874f52014-04-14 16:11:40 -060037int shpchp_configure_device(struct slot *p_slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070039 struct pci_dev *dev;
Taku Izumif98ca312008-10-23 11:52:12 +090040 struct controller *ctrl = p_slot->ctrl;
Yinghai Lu7d01f702012-05-17 18:58:41 -070041 struct pci_dev *bridge = ctrl->pci_dev;
42 struct pci_bus *parent = bridge->subordinate;
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -070043 int num, ret = 0;
44
45 pci_lock_rescan_remove();
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Kenji Kaneshigee00e57e2005-11-25 12:21:25 +090047 dev = pci_get_slot(parent, PCI_DEVFN(p_slot->device, 0));
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070048 if (dev) {
Ryan Desfosses227f0642014-04-18 20:13:50 -040049 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);
Kenji Kaneshigee00e57e2005-11-25 12:21:25 +090052 pci_dev_put(dev);
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -070053 ret = -EINVAL;
54 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 }
56
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070057 num = pci_scan_slot(parent, PCI_DEVFN(p_slot->device, 0));
58 if (num == 0) {
Taku Izumif98ca312008-10-23 11:52:12 +090059 ctrl_err(ctrl, "No new device found\n");
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -070060 ret = -ENODEV;
61 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 }
63
Yijing Wangfcbed0b2013-01-15 11:12:22 +080064 list_for_each_entry(dev, &parent->devices, bus_list) {
65 if (PCI_SLOT(dev->devfn) != p_slot->device)
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070066 continue;
Yijing Wang087cfa92014-05-04 12:23:44 +080067 if (pci_is_bridge(dev))
Yinghai Lu7d01f702012-05-17 18:58:41 -070068 pci_hp_add_bridge(dev);
Yinghai Lu7d01f702012-05-17 18:58:41 -070069 }
70
71 pci_assign_unassigned_bridge_resources(bridge);
Bjorn Helgaasb4071662014-08-28 12:18:37 -060072 pcie_bus_configure_settings(parent);
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070073 pci_bus_add_devices(parent);
Yinghai Lu7d01f702012-05-17 18:58:41 -070074
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -070075 out:
76 pci_unlock_rescan_remove();
77 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -070080int shpchp_unconfigure_device(struct slot *p_slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 int rc = 0;
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -070083 u8 bctl = 0;
Kenji Kaneshigee00e57e2005-11-25 12:21:25 +090084 struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate;
Yijing Wangfcbed0b2013-01-15 11:12:22 +080085 struct pci_dev *dev, *temp;
Taku Izumif98ca312008-10-23 11:52:12 +090086 struct controller *ctrl = p_slot->ctrl;
Kenji Kaneshigee00e57e2005-11-25 12:21:25 +090087
Taku Izumibe7bce22008-10-23 11:54:39 +090088 ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:%02x\n",
89 __func__, pci_domain_nr(parent), p_slot->bus, p_slot->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -070091 pci_lock_rescan_remove();
92
Yijing Wangfcbed0b2013-01-15 11:12:22 +080093 list_for_each_entry_safe(dev, temp, &parent->devices, bus_list) {
94 if (PCI_SLOT(dev->devfn) != p_slot->device)
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -070095 continue;
Yijing Wangfcbed0b2013-01-15 11:12:22 +080096
97 pci_dev_get(dev);
98 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
99 pci_read_config_byte(dev, PCI_BRIDGE_CONTROL, &bctl);
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -0700100 if (bctl & PCI_BRIDGE_CTL_VGA) {
Taku Izumif98ca312008-10-23 11:52:12 +0900101 ctrl_err(ctrl,
102 "Cannot remove display device %s\n",
Yijing Wangfcbed0b2013-01-15 11:12:22 +0800103 pci_name(dev));
104 pci_dev_put(dev);
Praveen Kalamegham0ba10bc2010-05-20 12:15:01 -0500105 rc = -EINVAL;
106 break;
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -0700107 }
108 }
Yijing Wangfcbed0b2013-01-15 11:12:22 +0800109 pci_stop_and_remove_bus_device(dev);
110 pci_dev_put(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700112
113 pci_unlock_rescan_remove();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return rc;
115}
116