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 | |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 101 | static struct slot *find_slot(struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | struct list_head *tmp, *n; |
| 104 | struct slot *slot; |
| 105 | |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 106 | list_for_each_safe(tmp, n, &rpaphp_slot_head) { |
| 107 | slot = list_entry(tmp, struct slot, rpaphp_slot_list); |
| 108 | if (slot->dn == dn) |
| 109 | return slot; |
| 110 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 112 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
John Rose | 0945cd5 | 2005-07-25 10:16:53 -0500 | [diff] [blame] | 115 | static struct pci_dev *dlpar_find_new_dev(struct pci_bus *parent, |
| 116 | struct device_node *dev_dn) |
| 117 | { |
| 118 | struct pci_dev *tmp = NULL; |
| 119 | struct device_node *child_dn; |
| 120 | |
| 121 | list_for_each_entry(tmp, &parent->devices, bus_list) { |
| 122 | child_dn = pci_device_to_OF_node(tmp); |
| 123 | if (child_dn == dev_dn) |
| 124 | return tmp; |
| 125 | } |
| 126 | return NULL; |
| 127 | } |
| 128 | |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 129 | static void dlpar_pci_add_bus(struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 131 | struct pci_dn *pdn = PCI_DN(dn); |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 132 | struct pci_controller *phb = pdn->phb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | struct pci_dev *dev = NULL; |
| 134 | |
linas@austin.ibm.com | d681db4 | 2005-12-01 18:56:14 -0600 | [diff] [blame] | 135 | eeh_add_device_tree_early(dn); |
| 136 | |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 137 | /* Add EADS device to PHB bus, adding new entry to bus->devices */ |
| 138 | dev = of_create_pci_dev(dn, phb->bus, pdn->devfn); |
| 139 | if (!dev) { |
| 140 | printk(KERN_ERR "%s: failed to create pci dev for %s\n", |
| 141 | __FUNCTION__, dn->full_name); |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 142 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 145 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || |
| 146 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) |
| 147 | of_scan_pci_bridge(dn, dev); |
| 148 | |
linas@austin.ibm.com | eca845c | 2006-01-12 18:20:26 -0600 | [diff] [blame] | 149 | pcibios_fixup_new_pci_devices(dev->subordinate,0); |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 150 | |
| 151 | /* Claim new bus resources */ |
linas@austin.ibm.com | cd5b50b | 2005-12-01 18:59:58 -0600 | [diff] [blame] | 152 | pcibios_claim_one_bus(dev->bus); |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 153 | |
| 154 | /* ioremap() for child bus, which may or may not succeed */ |
linas | 3c0c644 | 2006-01-12 14:36:25 -0600 | [diff] [blame] | 155 | remap_bus_range(dev->subordinate); |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* Add new devices to global lists. Register in proc, sysfs. */ |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 158 | pci_bus_add_devices(phb->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | |
John Rose | 940903c | 2005-07-25 10:16:58 -0500 | [diff] [blame] | 161 | 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] | 162 | { |
| 163 | struct pci_dev *dev; |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 164 | struct pci_controller *phb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
linas@austin.ibm.com | 0165786 | 2006-01-12 18:18:26 -0600 | [diff] [blame] | 166 | if (pcibios_find_pci_bus(dn)) |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 167 | return -EINVAL; |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | /* Add pci bus */ |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 170 | dlpar_pci_add_bus(dn); |
| 171 | |
| 172 | /* Confirm new bridge dev was created */ |
| 173 | phb = PCI_DN(dn)->phb; |
| 174 | dev = dlpar_find_new_dev(phb->bus, dn); |
| 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | if (!dev) { |
| 177 | printk(KERN_ERR "%s: unable to add bus %s\n", __FUNCTION__, |
| 178 | drc_name); |
| 179 | return -EIO; |
| 180 | } |
| 181 | |
linas@austin.ibm.com | 8737d6a | 2006-01-12 18:35:23 -0600 | [diff] [blame] | 182 | if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) { |
| 183 | printk(KERN_ERR "%s: unexpected header type %d, unable to add bus %s\n", |
| 184 | __FUNCTION__, dev->hdr_type, drc_name); |
| 185 | return -EIO; |
| 186 | } |
| 187 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 188 | /* Add hotplug slot */ |
| 189 | if (rpaphp_add_slot(dn)) { |
| 190 | printk(KERN_ERR "%s: unable to add hotplug slot %s\n", |
| 191 | __FUNCTION__, drc_name); |
| 192 | return -EIO; |
| 193 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static int dlpar_remove_root_bus(struct pci_controller *phb) |
| 198 | { |
| 199 | struct pci_bus *phb_bus; |
| 200 | int rc; |
| 201 | |
| 202 | phb_bus = phb->bus; |
| 203 | if (!(list_empty(&phb_bus->children) && |
| 204 | list_empty(&phb_bus->devices))) { |
| 205 | return -EBUSY; |
| 206 | } |
| 207 | |
| 208 | rc = pcibios_remove_root_bus(phb); |
| 209 | if (rc) |
| 210 | return -EIO; |
| 211 | |
| 212 | device_unregister(phb_bus->bridge); |
| 213 | pci_remove_bus(phb_bus); |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 218 | static int dlpar_remove_phb(char *drc_name, struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 220 | struct slot *slot; |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 221 | struct pci_dn *pdn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | int rc = 0; |
| 223 | |
linas@austin.ibm.com | 0165786 | 2006-01-12 18:18:26 -0600 | [diff] [blame] | 224 | if (!pcibios_find_pci_bus(dn)) |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 225 | return -EINVAL; |
| 226 | |
| 227 | slot = find_slot(dn); |
| 228 | if (slot) { |
| 229 | /* Remove hotplug slot */ |
linas@austin.ibm.com | f6afbad | 2006-01-12 18:31:01 -0600 | [diff] [blame] | 230 | if (rpaphp_deregister_slot(slot)) { |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 231 | printk(KERN_ERR |
| 232 | "%s: unable to remove hotplug slot %s\n", |
| 233 | __FUNCTION__, drc_name); |
| 234 | return -EIO; |
| 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 238 | pdn = dn->data; |
| 239 | BUG_ON(!pdn || !pdn->phb); |
| 240 | rc = dlpar_remove_root_bus(pdn->phb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | if (rc < 0) |
| 242 | return rc; |
| 243 | |
Paul Mackerras | 1635317 | 2005-09-06 13:17:54 +1000 | [diff] [blame] | 244 | pdn->phb = NULL; |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | return 0; |
| 247 | } |
| 248 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 249 | static int dlpar_add_phb(char *drc_name, struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
| 251 | struct pci_controller *phb; |
| 252 | |
Linas Vepstas | fe98aea | 2005-11-03 18:51:17 -0600 | [diff] [blame] | 253 | if (PCI_DN(dn) && PCI_DN(dn)->phb) { |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 254 | /* PHB already exists */ |
| 255 | return -EINVAL; |
| 256 | } |
| 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | phb = init_phb_dynamic(dn); |
| 259 | if (!phb) |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 260 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 262 | if (rpaphp_add_slot(dn)) { |
| 263 | printk(KERN_ERR "%s: unable to add hotplug slot %s\n", |
| 264 | __FUNCTION__, drc_name); |
| 265 | return -EIO; |
| 266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | return 0; |
| 268 | } |
| 269 | |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 270 | static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn) |
| 271 | { |
| 272 | if (vio_find_node(dn)) |
| 273 | return -EINVAL; |
| 274 | |
| 275 | if (!vio_register_device_node(dn)) { |
| 276 | printk(KERN_ERR |
| 277 | "%s: failed to register vio node %s\n", |
| 278 | __FUNCTION__, drc_name); |
| 279 | return -EIO; |
| 280 | } |
| 281 | return 0; |
| 282 | } |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /** |
| 285 | * dlpar_add_slot - DLPAR add an I/O Slot |
| 286 | * @drc_name: drc-name of newly added slot |
| 287 | * |
| 288 | * Make the hotplug module and the kernel aware |
| 289 | * of a newly added I/O Slot. |
| 290 | * Return Codes - |
| 291 | * 0 Success |
| 292 | * -ENODEV Not a valid drc_name |
| 293 | * -EINVAL Slot already added |
| 294 | * -ERESTARTSYS Signalled before obtaining lock |
| 295 | * -EIO Internal PCI Error |
| 296 | */ |
| 297 | int dlpar_add_slot(char *drc_name) |
| 298 | { |
| 299 | struct device_node *dn = NULL; |
| 300 | int node_type; |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 301 | int rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 303 | if (mutex_lock_interruptible(&rpadlpar_mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return -ERESTARTSYS; |
| 305 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 306 | /* Find newly added node */ |
| 307 | dn = find_dlpar_node(drc_name, &node_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | if (!dn) { |
| 309 | rc = -ENODEV; |
| 310 | goto exit; |
| 311 | } |
| 312 | |
| 313 | switch (node_type) { |
| 314 | case NODE_TYPE_VIO: |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 315 | rc = dlpar_add_vio_slot(drc_name, dn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | break; |
| 317 | case NODE_TYPE_SLOT: |
| 318 | rc = dlpar_add_pci_slot(drc_name, dn); |
| 319 | break; |
| 320 | case NODE_TYPE_PHB: |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 321 | rc = dlpar_add_phb(drc_name, dn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 325 | 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] | 326 | exit: |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 327 | mutex_unlock(&rpadlpar_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return rc; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * dlpar_remove_vio_slot - DLPAR remove a virtual I/O Slot |
| 333 | * @drc_name: drc-name of newly added slot |
| 334 | * |
| 335 | * Remove the kernel and hotplug representations |
| 336 | * of an I/O Slot. |
| 337 | * Return Codes: |
| 338 | * 0 Success |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 339 | * -EINVAL Vio dev doesn't exist |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | */ |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 341 | 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] | 342 | { |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 343 | struct vio_dev *vio_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 345 | vio_dev = vio_find_node(dn); |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 346 | if (!vio_dev) |
| 347 | return -EINVAL; |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 348 | |
| 349 | vio_unregister_device(vio_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * dlpar_remove_slot - DLPAR remove a PCI I/O Slot |
| 355 | * @drc_name: drc-name of newly added slot |
| 356 | * |
| 357 | * Remove the kernel and hotplug representations |
| 358 | * of a PCI I/O Slot. |
| 359 | * Return Codes: |
| 360 | * 0 Success |
| 361 | * -ENODEV Not a valid drc_name |
| 362 | * -EIO Internal PCI Error |
| 363 | */ |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 364 | int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 366 | struct pci_bus *bus; |
| 367 | struct slot *slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
linas@austin.ibm.com | 0165786 | 2006-01-12 18:18:26 -0600 | [diff] [blame] | 369 | bus = pcibios_find_pci_bus(dn); |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 370 | if (!bus) |
| 371 | return -EINVAL; |
| 372 | |
| 373 | slot = find_slot(dn); |
| 374 | if (slot) { |
| 375 | /* Remove hotplug slot */ |
linas@austin.ibm.com | f6afbad | 2006-01-12 18:31:01 -0600 | [diff] [blame] | 376 | if (rpaphp_deregister_slot(slot)) { |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 377 | printk(KERN_ERR |
| 378 | "%s: unable to remove hotplug slot %s\n", |
| 379 | __FUNCTION__, drc_name); |
| 380 | return -EIO; |
| 381 | } |
John Rose | 5fa80fc | 2005-11-04 15:38:50 -0600 | [diff] [blame] | 382 | } else { |
linas@austin.ibm.com | 8fe6439 | 2006-01-12 18:26:27 -0600 | [diff] [blame] | 383 | struct pci_dev *dev, *tmp; |
| 384 | list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) { |
| 385 | eeh_remove_bus_device(dev); |
| 386 | pci_remove_bus_device(dev); |
| 387 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
| 389 | |
John Rose | 9c209c9 | 2005-07-25 11:13:38 -0500 | [diff] [blame] | 390 | if (unmap_bus_range(bus)) { |
| 391 | printk(KERN_ERR "%s: failed to unmap bus range\n", |
| 392 | __FUNCTION__); |
| 393 | return -ERANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
John Rose | 9c209c9 | 2005-07-25 11:13:38 -0500 | [diff] [blame] | 395 | |
| 396 | BUG_ON(!bus->self); |
| 397 | pci_remove_bus_device(bus->self); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * dlpar_remove_slot - DLPAR remove an I/O Slot |
| 403 | * @drc_name: drc-name of newly added slot |
| 404 | * |
| 405 | * Remove the kernel and hotplug representations |
| 406 | * of an I/O Slot. |
| 407 | * Return Codes: |
| 408 | * 0 Success |
| 409 | * -ENODEV Not a valid drc_name |
| 410 | * -EINVAL Slot already removed |
| 411 | * -ERESTARTSYS Signalled before obtaining lock |
| 412 | * -EIO Internal Error |
| 413 | */ |
| 414 | int dlpar_remove_slot(char *drc_name) |
| 415 | { |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 416 | struct device_node *dn; |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 417 | int node_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | int rc = 0; |
| 419 | |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 420 | if (mutex_lock_interruptible(&rpadlpar_mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | return -ERESTARTSYS; |
| 422 | |
John Rose | 5eeb8c6 | 2005-07-25 10:16:42 -0500 | [diff] [blame] | 423 | dn = find_dlpar_node(drc_name, &node_type); |
| 424 | if (!dn) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | rc = -ENODEV; |
| 426 | goto exit; |
| 427 | } |
| 428 | |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 429 | switch (node_type) { |
| 430 | case NODE_TYPE_VIO: |
| 431 | rc = dlpar_remove_vio_slot(drc_name, dn); |
| 432 | break; |
| 433 | case NODE_TYPE_PHB: |
| 434 | rc = dlpar_remove_phb(drc_name, dn); |
| 435 | break; |
| 436 | case NODE_TYPE_SLOT: |
| 437 | rc = dlpar_remove_pci_slot(drc_name, dn); |
| 438 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
John Rose | 56d8456 | 2005-07-25 10:17:03 -0500 | [diff] [blame] | 440 | 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] | 441 | exit: |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 442 | mutex_unlock(&rpadlpar_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | return rc; |
| 444 | } |
| 445 | |
| 446 | static inline int is_dlpar_capable(void) |
| 447 | { |
| 448 | int rc = rtas_token("ibm,configure-connector"); |
| 449 | |
| 450 | return (int) (rc != RTAS_UNKNOWN_SERVICE); |
| 451 | } |
| 452 | |
| 453 | int __init rpadlpar_io_init(void) |
| 454 | { |
| 455 | int rc = 0; |
| 456 | |
| 457 | if (!is_dlpar_capable()) { |
| 458 | printk(KERN_WARNING "%s: partition not DLPAR capable\n", |
| 459 | __FUNCTION__); |
| 460 | return -EPERM; |
| 461 | } |
| 462 | |
| 463 | rc = dlpar_sysfs_init(); |
| 464 | return rc; |
| 465 | } |
| 466 | |
| 467 | void rpadlpar_io_exit(void) |
| 468 | { |
| 469 | dlpar_sysfs_exit(); |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | module_init(rpadlpar_io_init); |
| 474 | module_exit(rpadlpar_io_exit); |
| 475 | MODULE_LICENSE("GPL"); |