Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Interface for Dynamic Logical Partitioning of I/O Slots on |
| 3 | * RPA-compliant PPC64 platform. |
| 4 | * |
| 5 | * John Rose <johnrose@austin.ibm.com> |
| 6 | * Linda Xie <lxie@us.ibm.com> |
| 7 | * |
| 8 | * October 2003 |
| 9 | * |
| 10 | * Copyright (C) 2003 IBM. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version |
| 15 | * 2 of the License, or (at your option) any later version. |
| 16 | */ |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/pci.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 19 | #include <linux/string.h> |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/pci-bridge.h> |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 22 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/rtas.h> |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 24 | #include <asm/vio.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "../pci.h" |
| 27 | #include "rpaphp.h" |
| 28 | #include "rpadlpar.h" |
| 29 | |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 30 | static DEFINE_MUTEX(rpadlpar_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 32 | #define DLPAR_MODULE_NAME "rpadlpar_io" |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #define NODE_TYPE_VIO 1 |
| 35 | #define NODE_TYPE_SLOT 2 |
| 36 | #define NODE_TYPE_PHB 3 |
| 37 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 38 | static struct device_node *find_vio_slot_node(char *drc_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | struct device_node *parent = of_find_node_by_name(NULL, "vdevice"); |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 41 | struct device_node *dn = NULL; |
| 42 | char *name; |
| 43 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | if (!parent) |
| 46 | return NULL; |
| 47 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 48 | while ((dn = of_get_next_child(parent, dn))) { |
| 49 | rc = rpaphp_get_drc_props(dn, NULL, &name, NULL, NULL); |
| 50 | if ((rc == 0) && (!strcmp(drc_name, name))) |
| 51 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 54 | return dn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /* Find dlpar-capable pci node that contains the specified name and type */ |
| 58 | static struct device_node *find_php_slot_pci_node(char *drc_name, |
| 59 | char *drc_type) |
| 60 | { |
| 61 | struct device_node *np = NULL; |
| 62 | char *name; |
| 63 | char *type; |
| 64 | int rc; |
| 65 | |
John Rose | a57ed79 | 2006-11-13 15:12:52 -0800 | [diff] [blame] | 66 | while ((np = of_find_node_by_name(np, "pci"))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | rc = rpaphp_get_drc_props(np, NULL, &name, &type, NULL); |
| 68 | if (rc == 0) |
| 69 | if (!strcmp(drc_name, name) && !strcmp(drc_type, type)) |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | return np; |
| 74 | } |
| 75 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 76 | static struct device_node *find_dlpar_node(char *drc_name, int *node_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
| 78 | struct device_node *dn; |
| 79 | |
| 80 | dn = find_php_slot_pci_node(drc_name, "SLOT"); |
| 81 | if (dn) { |
| 82 | *node_type = NODE_TYPE_SLOT; |
| 83 | return dn; |
| 84 | } |
| 85 | |
| 86 | dn = find_php_slot_pci_node(drc_name, "PHB"); |
| 87 | if (dn) { |
| 88 | *node_type = NODE_TYPE_PHB; |
| 89 | return dn; |
| 90 | } |
| 91 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 92 | dn = find_vio_slot_node(drc_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | if (dn) { |
| 94 | *node_type = NODE_TYPE_VIO; |
| 95 | return dn; |
| 96 | } |
| 97 | |
| 98 | return NULL; |
| 99 | } |
| 100 | |
Linas Vepstas | 8485d1a | 2007-04-13 15:34:21 -0700 | [diff] [blame^] | 101 | /** |
| 102 | * find_php_slot - return hotplug slot structure for device node |
| 103 | * |
| 104 | * This routine will return the hotplug slot structure |
| 105 | * for a given device node. Note that built-in PCI slots |
| 106 | * may be dlpar-able, but not hot-pluggable, so this routine |
| 107 | * will return NULL for built-in PCI slots. |
| 108 | */ |
| 109 | static struct slot *find_php_slot(struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | struct list_head *tmp, *n; |
| 112 | struct slot *slot; |
| 113 | |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 114 | list_for_each_safe(tmp, n, &rpaphp_slot_head) { |
| 115 | slot = list_entry(tmp, struct slot, rpaphp_slot_list); |
| 116 | if (slot->dn == dn) |
| 117 | return slot; |
| 118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 120 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
| 122 | |
John Rose | 0945cd5 | 2005-07-25 10:16:53 -0500 | [diff] [blame] | 123 | static struct pci_dev *dlpar_find_new_dev(struct pci_bus *parent, |
| 124 | struct device_node *dev_dn) |
| 125 | { |
| 126 | struct pci_dev *tmp = NULL; |
| 127 | struct device_node *child_dn; |
| 128 | |
| 129 | list_for_each_entry(tmp, &parent->devices, bus_list) { |
| 130 | child_dn = pci_device_to_OF_node(tmp); |
| 131 | if (child_dn == dev_dn) |
| 132 | return tmp; |
| 133 | } |
| 134 | return NULL; |
| 135 | } |
| 136 | |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 137 | static void dlpar_pci_add_bus(struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 139 | struct pci_dn *pdn = PCI_DN(dn); |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 140 | struct pci_controller *phb = pdn->phb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | struct pci_dev *dev = NULL; |
| 142 | |
linas@austin.ibm.com | d681db4 | 2005-12-01 18:56:14 -0600 | [diff] [blame] | 143 | eeh_add_device_tree_early(dn); |
| 144 | |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 145 | /* Add EADS device to PHB bus, adding new entry to bus->devices */ |
| 146 | dev = of_create_pci_dev(dn, phb->bus, pdn->devfn); |
| 147 | if (!dev) { |
| 148 | printk(KERN_ERR "%s: failed to create pci dev for %s\n", |
| 149 | __FUNCTION__, dn->full_name); |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 150 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 153 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || |
| 154 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) |
| 155 | of_scan_pci_bridge(dn, dev); |
| 156 | |
linas@austin.ibm.com | eca845c | 2006-01-12 18:20:26 -0600 | [diff] [blame] | 157 | pcibios_fixup_new_pci_devices(dev->subordinate,0); |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 158 | |
| 159 | /* Claim new bus resources */ |
linas@austin.ibm.com | cd5b50b | 2005-12-01 18:59:58 -0600 | [diff] [blame] | 160 | pcibios_claim_one_bus(dev->bus); |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 161 | |
| 162 | /* ioremap() for child bus, which may or may not succeed */ |
linas | 3c0c644 | 2006-01-12 14:36:25 -0600 | [diff] [blame] | 163 | remap_bus_range(dev->subordinate); |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | /* Add new devices to global lists. Register in proc, sysfs. */ |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 166 | pci_bus_add_devices(phb->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
John Rose | 940903c | 2005-07-25 10:16:58 -0500 | [diff] [blame] | 169 | static int dlpar_add_pci_slot(char *drc_name, struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
| 171 | struct pci_dev *dev; |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 172 | struct pci_controller *phb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
linas@austin.ibm.com | 0165786 | 2006-01-12 18:18:26 -0600 | [diff] [blame] | 174 | if (pcibios_find_pci_bus(dn)) |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 175 | return -EINVAL; |
| 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | /* Add pci bus */ |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 178 | dlpar_pci_add_bus(dn); |
| 179 | |
| 180 | /* Confirm new bridge dev was created */ |
| 181 | phb = PCI_DN(dn)->phb; |
| 182 | dev = dlpar_find_new_dev(phb->bus, dn); |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | if (!dev) { |
| 185 | printk(KERN_ERR "%s: unable to add bus %s\n", __FUNCTION__, |
| 186 | drc_name); |
| 187 | return -EIO; |
| 188 | } |
| 189 | |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 190 | if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) { |
| 191 | printk(KERN_ERR "%s: unexpected header type %d, unable to add bus %s\n", |
| 192 | __FUNCTION__, dev->hdr_type, drc_name); |
| 193 | return -EIO; |
| 194 | } |
| 195 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 196 | /* Add hotplug slot */ |
| 197 | if (rpaphp_add_slot(dn)) { |
| 198 | printk(KERN_ERR "%s: unable to add hotplug slot %s\n", |
| 199 | __FUNCTION__, drc_name); |
| 200 | return -EIO; |
| 201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static int dlpar_remove_root_bus(struct pci_controller *phb) |
| 206 | { |
| 207 | struct pci_bus *phb_bus; |
| 208 | int rc; |
| 209 | |
| 210 | phb_bus = phb->bus; |
| 211 | if (!(list_empty(&phb_bus->children) && |
| 212 | list_empty(&phb_bus->devices))) { |
| 213 | return -EBUSY; |
| 214 | } |
| 215 | |
| 216 | rc = pcibios_remove_root_bus(phb); |
| 217 | if (rc) |
| 218 | return -EIO; |
| 219 | |
| 220 | device_unregister(phb_bus->bridge); |
| 221 | pci_remove_bus(phb_bus); |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 226 | static int dlpar_remove_phb(char *drc_name, struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 228 | struct slot *slot; |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 229 | struct pci_dn *pdn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | int rc = 0; |
| 231 | |
linas@austin.ibm.com | 0165786 | 2006-01-12 18:18:26 -0600 | [diff] [blame] | 232 | if (!pcibios_find_pci_bus(dn)) |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 233 | return -EINVAL; |
| 234 | |
Linas Vepstas | 8485d1a | 2007-04-13 15:34:21 -0700 | [diff] [blame^] | 235 | /* If pci slot is hotplugable, use hotplug to remove it */ |
| 236 | slot = find_php_slot(dn); |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 237 | if (slot) { |
linas@austin.ibm.com | f6afbad | 2006-01-12 18:31:01 -0600 | [diff] [blame] | 238 | if (rpaphp_deregister_slot(slot)) { |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 239 | printk(KERN_ERR |
| 240 | "%s: unable to remove hotplug slot %s\n", |
| 241 | __FUNCTION__, drc_name); |
| 242 | return -EIO; |
| 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 246 | pdn = dn->data; |
| 247 | BUG_ON(!pdn || !pdn->phb); |
| 248 | rc = dlpar_remove_root_bus(pdn->phb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | if (rc < 0) |
| 250 | return rc; |
| 251 | |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 252 | pdn->phb = NULL; |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return 0; |
| 255 | } |
| 256 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 257 | static int dlpar_add_phb(char *drc_name, struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
| 259 | struct pci_controller *phb; |
| 260 | |
Linas Vepstas | fe98aea | 2005-11-03 18:51:17 -0600 | [diff] [blame] | 261 | if (PCI_DN(dn) && PCI_DN(dn)->phb) { |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 262 | /* PHB already exists */ |
| 263 | return -EINVAL; |
| 264 | } |
| 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | phb = init_phb_dynamic(dn); |
| 267 | if (!phb) |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 268 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 270 | if (rpaphp_add_slot(dn)) { |
| 271 | printk(KERN_ERR "%s: unable to add hotplug slot %s\n", |
| 272 | __FUNCTION__, drc_name); |
| 273 | return -EIO; |
| 274 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | return 0; |
| 276 | } |
| 277 | |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 278 | static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn) |
| 279 | { |
| 280 | if (vio_find_node(dn)) |
| 281 | return -EINVAL; |
| 282 | |
| 283 | if (!vio_register_device_node(dn)) { |
| 284 | printk(KERN_ERR |
| 285 | "%s: failed to register vio node %s\n", |
| 286 | __FUNCTION__, drc_name); |
| 287 | return -EIO; |
| 288 | } |
| 289 | return 0; |
| 290 | } |
| 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | /** |
| 293 | * dlpar_add_slot - DLPAR add an I/O Slot |
| 294 | * @drc_name: drc-name of newly added slot |
| 295 | * |
| 296 | * Make the hotplug module and the kernel aware |
| 297 | * of a newly added I/O Slot. |
| 298 | * Return Codes - |
| 299 | * 0 Success |
| 300 | * -ENODEV Not a valid drc_name |
| 301 | * -EINVAL Slot already added |
| 302 | * -ERESTARTSYS Signalled before obtaining lock |
| 303 | * -EIO Internal PCI Error |
| 304 | */ |
| 305 | int dlpar_add_slot(char *drc_name) |
| 306 | { |
| 307 | struct device_node *dn = NULL; |
| 308 | int node_type; |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 309 | int rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 311 | if (mutex_lock_interruptible(&rpadlpar_mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | return -ERESTARTSYS; |
| 313 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 314 | /* Find newly added node */ |
| 315 | dn = find_dlpar_node(drc_name, &node_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | if (!dn) { |
| 317 | rc = -ENODEV; |
| 318 | goto exit; |
| 319 | } |
| 320 | |
| 321 | switch (node_type) { |
| 322 | case NODE_TYPE_VIO: |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 323 | rc = dlpar_add_vio_slot(drc_name, dn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | break; |
| 325 | case NODE_TYPE_SLOT: |
| 326 | rc = dlpar_add_pci_slot(drc_name, dn); |
| 327 | break; |
| 328 | case NODE_TYPE_PHB: |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 329 | rc = dlpar_add_phb(drc_name, dn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 333 | printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | exit: |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 335 | mutex_unlock(&rpadlpar_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | return rc; |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * dlpar_remove_vio_slot - DLPAR remove a virtual I/O Slot |
| 341 | * @drc_name: drc-name of newly added slot |
| 342 | * |
| 343 | * Remove the kernel and hotplug representations |
| 344 | * of an I/O Slot. |
| 345 | * Return Codes: |
| 346 | * 0 Success |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 347 | * -EINVAL Vio dev doesn't exist |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | */ |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 349 | static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 351 | struct vio_dev *vio_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 353 | vio_dev = vio_find_node(dn); |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 354 | if (!vio_dev) |
| 355 | return -EINVAL; |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 356 | |
| 357 | vio_unregister_device(vio_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * dlpar_remove_slot - DLPAR remove a PCI I/O Slot |
| 363 | * @drc_name: drc-name of newly added slot |
| 364 | * |
| 365 | * Remove the kernel and hotplug representations |
| 366 | * of a PCI I/O Slot. |
| 367 | * Return Codes: |
| 368 | * 0 Success |
| 369 | * -ENODEV Not a valid drc_name |
| 370 | * -EIO Internal PCI Error |
| 371 | */ |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 372 | int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 374 | struct pci_bus *bus; |
| 375 | struct slot *slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
linas@austin.ibm.com | 0165786 | 2006-01-12 18:18:26 -0600 | [diff] [blame] | 377 | bus = pcibios_find_pci_bus(dn); |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 378 | if (!bus) |
| 379 | return -EINVAL; |
| 380 | |
Linas Vepstas | 8485d1a | 2007-04-13 15:34:21 -0700 | [diff] [blame^] | 381 | /* If pci slot is hotplugable, use hotplug to remove it */ |
| 382 | slot = find_php_slot(dn); |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 383 | if (slot) { |
linas@austin.ibm.com | f6afbad | 2006-01-12 18:31:01 -0600 | [diff] [blame] | 384 | if (rpaphp_deregister_slot(slot)) { |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 385 | printk(KERN_ERR |
| 386 | "%s: unable to remove hotplug slot %s\n", |
| 387 | __FUNCTION__, drc_name); |
| 388 | return -EIO; |
| 389 | } |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 390 | } else { |
linas@austin.ibm.com | 8fe6439 | 2006-01-12 18:26:27 -0600 | [diff] [blame] | 391 | struct pci_dev *dev, *tmp; |
| 392 | list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) { |
| 393 | eeh_remove_bus_device(dev); |
| 394 | pci_remove_bus_device(dev); |
| 395 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
John Rose | 9c209c9 | 2005-07-25 11:13:38 -0500 | [diff] [blame] | 398 | if (unmap_bus_range(bus)) { |
| 399 | printk(KERN_ERR "%s: failed to unmap bus range\n", |
| 400 | __FUNCTION__); |
| 401 | return -ERANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
John Rose | 9c209c9 | 2005-07-25 11:13:38 -0500 | [diff] [blame] | 403 | |
| 404 | BUG_ON(!bus->self); |
| 405 | pci_remove_bus_device(bus->self); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * dlpar_remove_slot - DLPAR remove an I/O Slot |
| 411 | * @drc_name: drc-name of newly added slot |
| 412 | * |
| 413 | * Remove the kernel and hotplug representations |
| 414 | * of an I/O Slot. |
| 415 | * Return Codes: |
| 416 | * 0 Success |
| 417 | * -ENODEV Not a valid drc_name |
| 418 | * -EINVAL Slot already removed |
| 419 | * -ERESTARTSYS Signalled before obtaining lock |
| 420 | * -EIO Internal Error |
| 421 | */ |
| 422 | int dlpar_remove_slot(char *drc_name) |
| 423 | { |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 424 | struct device_node *dn; |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 425 | int node_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | int rc = 0; |
| 427 | |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 428 | if (mutex_lock_interruptible(&rpadlpar_mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | return -ERESTARTSYS; |
| 430 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 431 | dn = find_dlpar_node(drc_name, &node_type); |
| 432 | if (!dn) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | rc = -ENODEV; |
| 434 | goto exit; |
| 435 | } |
| 436 | |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 437 | switch (node_type) { |
| 438 | case NODE_TYPE_VIO: |
| 439 | rc = dlpar_remove_vio_slot(drc_name, dn); |
| 440 | break; |
| 441 | case NODE_TYPE_PHB: |
| 442 | rc = dlpar_remove_phb(drc_name, dn); |
| 443 | break; |
| 444 | case NODE_TYPE_SLOT: |
| 445 | rc = dlpar_remove_pci_slot(drc_name, dn); |
| 446 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | } |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 448 | printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | exit: |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 450 | mutex_unlock(&rpadlpar_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | return rc; |
| 452 | } |
| 453 | |
| 454 | static inline int is_dlpar_capable(void) |
| 455 | { |
| 456 | int rc = rtas_token("ibm,configure-connector"); |
| 457 | |
| 458 | return (int) (rc != RTAS_UNKNOWN_SERVICE); |
| 459 | } |
| 460 | |
| 461 | int __init rpadlpar_io_init(void) |
| 462 | { |
| 463 | int rc = 0; |
| 464 | |
| 465 | if (!is_dlpar_capable()) { |
| 466 | printk(KERN_WARNING "%s: partition not DLPAR capable\n", |
| 467 | __FUNCTION__); |
| 468 | return -EPERM; |
| 469 | } |
| 470 | |
| 471 | rc = dlpar_sysfs_init(); |
| 472 | return rc; |
| 473 | } |
| 474 | |
| 475 | void rpadlpar_io_exit(void) |
| 476 | { |
| 477 | dlpar_sysfs_exit(); |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | module_init(rpadlpar_io_init); |
| 482 | module_exit(rpadlpar_io_exit); |
| 483 | MODULE_LICENSE("GPL"); |