Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Kristen Accardi | 8cf4c19 | 2005-08-16 15:16:10 -0700 | [diff] [blame] | 26 | * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * |
| 28 | */ |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/pci.h> |
| 34 | #include "../pci.h" |
| 35 | #include "shpchp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Bjorn Helgaas | 10874f5 | 2014-04-14 16:11:40 -0600 | [diff] [blame] | 37 | int shpchp_configure_device(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | { |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 39 | struct pci_dev *dev; |
Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 40 | struct controller *ctrl = p_slot->ctrl; |
Yinghai Lu | 7d01f70 | 2012-05-17 18:58:41 -0700 | [diff] [blame] | 41 | struct pci_dev *bridge = ctrl->pci_dev; |
| 42 | struct pci_bus *parent = bridge->subordinate; |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 43 | int num, ret = 0; |
| 44 | |
| 45 | pci_lock_rescan_remove(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Kenji Kaneshige | e00e57e | 2005-11-25 12:21:25 +0900 | [diff] [blame] | 47 | dev = pci_get_slot(parent, PCI_DEVFN(p_slot->device, 0)); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 48 | if (dev) { |
Ryan Desfosses | 227f064 | 2014-04-18 20:13:50 -0400 | [diff] [blame] | 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); |
Kenji Kaneshige | e00e57e | 2005-11-25 12:21:25 +0900 | [diff] [blame] | 52 | pci_dev_put(dev); |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 53 | ret = -EINVAL; |
| 54 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 57 | num = pci_scan_slot(parent, PCI_DEVFN(p_slot->device, 0)); |
| 58 | if (num == 0) { |
Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 59 | ctrl_err(ctrl, "No new device found\n"); |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 60 | ret = -ENODEV; |
| 61 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 64 | list_for_each_entry(dev, &parent->devices, bus_list) { |
| 65 | if (PCI_SLOT(dev->devfn) != p_slot->device) |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 66 | continue; |
Yijing Wang | 087cfa9 | 2014-05-04 12:23:44 +0800 | [diff] [blame] | 67 | if (pci_is_bridge(dev)) |
Yinghai Lu | 7d01f70 | 2012-05-17 18:58:41 -0700 | [diff] [blame] | 68 | pci_hp_add_bridge(dev); |
Yinghai Lu | 7d01f70 | 2012-05-17 18:58:41 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | pci_assign_unassigned_bridge_resources(bridge); |
Bjorn Helgaas | b407166 | 2014-08-28 12:18:37 -0600 | [diff] [blame] | 72 | pcie_bus_configure_settings(parent); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 73 | pci_bus_add_devices(parent); |
Yinghai Lu | 7d01f70 | 2012-05-17 18:58:41 -0700 | [diff] [blame] | 74 | |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 75 | out: |
| 76 | pci_unlock_rescan_remove(); |
| 77 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 80 | int shpchp_unconfigure_device(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | int rc = 0; |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 83 | u8 bctl = 0; |
Kenji Kaneshige | e00e57e | 2005-11-25 12:21:25 +0900 | [diff] [blame] | 84 | struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate; |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 85 | struct pci_dev *dev, *temp; |
Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 86 | struct controller *ctrl = p_slot->ctrl; |
Kenji Kaneshige | e00e57e | 2005-11-25 12:21:25 +0900 | [diff] [blame] | 87 | |
Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 88 | ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:%02x\n", |
| 89 | __func__, pci_domain_nr(parent), p_slot->bus, p_slot->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 91 | pci_lock_rescan_remove(); |
| 92 | |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 93 | list_for_each_entry_safe(dev, temp, &parent->devices, bus_list) { |
| 94 | if (PCI_SLOT(dev->devfn) != p_slot->device) |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 95 | continue; |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 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); |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 100 | if (bctl & PCI_BRIDGE_CTL_VGA) { |
Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 101 | ctrl_err(ctrl, |
| 102 | "Cannot remove display device %s\n", |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 103 | pci_name(dev)); |
| 104 | pci_dev_put(dev); |
Praveen Kalamegham | 0ba10bc | 2010-05-20 12:15:01 -0500 | [diff] [blame] | 105 | rc = -EINVAL; |
| 106 | break; |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 107 | } |
| 108 | } |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 109 | pci_stop_and_remove_bus_device(dev); |
| 110 | pci_dev_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 112 | |
| 113 | pci_unlock_rescan_remove(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return rc; |
| 115 | } |
| 116 | |