blob: b0e83132542e4ddb52482f899e0d0b1c29a776b2 [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
Sam Ravnborg0ab2b572008-02-17 10:45:28 +010037int __ref 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;
Yijing Wangfcbed0b2013-01-15 11:12:22 +080043 int num;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Kenji Kaneshigee00e57e2005-11-25 12:21:25 +090045 dev = pci_get_slot(parent, PCI_DEVFN(p_slot->device, 0));
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070046 if (dev) {
Taku Izumibe7bce22008-10-23 11:54:39 +090047 ctrl_err(ctrl, "Device %s already exists "
48 "at %04x:%02x:%02x, cannot hot-add\n", pci_name(dev),
49 pci_domain_nr(parent), p_slot->bus, p_slot->device);
Kenji Kaneshigee00e57e2005-11-25 12:21:25 +090050 pci_dev_put(dev);
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070051 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 }
53
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070054 num = pci_scan_slot(parent, PCI_DEVFN(p_slot->device, 0));
55 if (num == 0) {
Taku Izumif98ca312008-10-23 11:52:12 +090056 ctrl_err(ctrl, "No new device found\n");
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070057 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 }
59
Yijing Wangfcbed0b2013-01-15 11:12:22 +080060 list_for_each_entry(dev, &parent->devices, bus_list) {
61 if (PCI_SLOT(dev->devfn) != p_slot->device)
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070062 continue;
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070063 if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) ||
Yinghai Lu7d01f702012-05-17 18:58:41 -070064 (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS))
65 pci_hp_add_bridge(dev);
Yinghai Lu7d01f702012-05-17 18:58:41 -070066 }
67
68 pci_assign_unassigned_bridge_resources(bridge);
69
Yijing Wangfcbed0b2013-01-15 11:12:22 +080070 list_for_each_entry(dev, &parent->devices, bus_list) {
71 if (PCI_SLOT(dev->devfn) != p_slot->device)
Yinghai Lu7d01f702012-05-17 18:58:41 -070072 continue;
Bjorn Helgaas11876e52009-09-14 16:35:30 -060073 pci_configure_slot(dev);
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070074 }
75
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070076 pci_bus_add_devices(parent);
Yinghai Lu7d01f702012-05-17 18:58:41 -070077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 return 0;
79}
80
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -070081int shpchp_unconfigure_device(struct slot *p_slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
83 int rc = 0;
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -070084 u8 bctl = 0;
Kenji Kaneshigee00e57e2005-11-25 12:21:25 +090085 struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate;
Yijing Wangfcbed0b2013-01-15 11:12:22 +080086 struct pci_dev *dev, *temp;
Taku Izumif98ca312008-10-23 11:52:12 +090087 struct controller *ctrl = p_slot->ctrl;
Kenji Kaneshigee00e57e2005-11-25 12:21:25 +090088
Taku Izumibe7bce22008-10-23 11:54:39 +090089 ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:%02x\n",
90 __func__, pci_domain_nr(parent), p_slot->bus, p_slot->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Yijing Wangfcbed0b2013-01-15 11:12:22 +080092 list_for_each_entry_safe(dev, temp, &parent->devices, bus_list) {
93 if (PCI_SLOT(dev->devfn) != p_slot->device)
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -070094 continue;
Yijing Wangfcbed0b2013-01-15 11:12:22 +080095
96 pci_dev_get(dev);
97 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
98 pci_read_config_byte(dev, PCI_BRIDGE_CONTROL, &bctl);
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -070099 if (bctl & PCI_BRIDGE_CTL_VGA) {
Taku Izumif98ca312008-10-23 11:52:12 +0900100 ctrl_err(ctrl,
101 "Cannot remove display device %s\n",
Yijing Wangfcbed0b2013-01-15 11:12:22 +0800102 pci_name(dev));
103 pci_dev_put(dev);
Praveen Kalamegham0ba10bc2010-05-20 12:15:01 -0500104 rc = -EINVAL;
105 break;
rajesh.shah@intel.com2178bfa2005-10-13 12:05:41 -0700106 }
107 }
Yijing Wangfcbed0b2013-01-15 11:12:22 +0800108 pci_stop_and_remove_bus_device(dev);
109 pci_dev_put(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 }
111 return rc;
112}
113