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 | |
Sam Ravnborg | 0ab2b57 | 2008-02-17 10:45:28 +0100 | [diff] [blame] | 37 | int __ref 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; |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 43 | int num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Kenji Kaneshige | e00e57e | 2005-11-25 12:21:25 +0900 | [diff] [blame] | 45 | 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] | 46 | if (dev) { |
Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 47 | 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 Kaneshige | e00e57e | 2005-11-25 12:21:25 +0900 | [diff] [blame] | 50 | pci_dev_put(dev); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 51 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 54 | num = pci_scan_slot(parent, PCI_DEVFN(p_slot->device, 0)); |
| 55 | if (num == 0) { |
Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 56 | ctrl_err(ctrl, "No new device found\n"); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 57 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 60 | list_for_each_entry(dev, &parent->devices, bus_list) { |
| 61 | if (PCI_SLOT(dev->devfn) != p_slot->device) |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 62 | continue; |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 63 | if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || |
Yinghai Lu | 7d01f70 | 2012-05-17 18:58:41 -0700 | [diff] [blame] | 64 | (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) |
| 65 | pci_hp_add_bridge(dev); |
Yinghai Lu | 7d01f70 | 2012-05-17 18:58:41 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | pci_assign_unassigned_bridge_resources(bridge); |
| 69 | |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 70 | list_for_each_entry(dev, &parent->devices, bus_list) { |
| 71 | if (PCI_SLOT(dev->devfn) != p_slot->device) |
Yinghai Lu | 7d01f70 | 2012-05-17 18:58:41 -0700 | [diff] [blame] | 72 | continue; |
Bjorn Helgaas | 11876e5 | 2009-09-14 16:35:30 -0600 | [diff] [blame] | 73 | pci_configure_slot(dev); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 76 | pci_bus_add_devices(parent); |
Yinghai Lu | 7d01f70 | 2012-05-17 18:58:41 -0700 | [diff] [blame] | 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 81 | int shpchp_unconfigure_device(struct slot *p_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
| 83 | int rc = 0; |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 84 | u8 bctl = 0; |
Kenji Kaneshige | e00e57e | 2005-11-25 12:21:25 +0900 | [diff] [blame] | 85 | struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate; |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 86 | struct pci_dev *dev, *temp; |
Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 87 | struct controller *ctrl = p_slot->ctrl; |
Kenji Kaneshige | e00e57e | 2005-11-25 12:21:25 +0900 | [diff] [blame] | 88 | |
Taku Izumi | be7bce2 | 2008-10-23 11:54:39 +0900 | [diff] [blame] | 89 | ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:%02x\n", |
| 90 | __func__, pci_domain_nr(parent), p_slot->bus, p_slot->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 92 | list_for_each_entry_safe(dev, temp, &parent->devices, bus_list) { |
| 93 | if (PCI_SLOT(dev->devfn) != p_slot->device) |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 94 | continue; |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 95 | |
| 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.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 99 | if (bctl & PCI_BRIDGE_CTL_VGA) { |
Taku Izumi | f98ca31 | 2008-10-23 11:52:12 +0900 | [diff] [blame] | 100 | ctrl_err(ctrl, |
| 101 | "Cannot remove display device %s\n", |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 102 | pci_name(dev)); |
| 103 | pci_dev_put(dev); |
Praveen Kalamegham | 0ba10bc | 2010-05-20 12:15:01 -0500 | [diff] [blame] | 104 | rc = -EINVAL; |
| 105 | break; |
rajesh.shah@intel.com | 2178bfa | 2005-10-13 12:05:41 -0700 | [diff] [blame] | 106 | } |
| 107 | } |
Yijing Wang | fcbed0b | 2013-01-15 11:12:22 +0800 | [diff] [blame] | 108 | pci_stop_and_remove_bus_device(dev); |
| 109 | pci_dev_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | return rc; |
| 112 | } |
| 113 | |