blob: c614ff7c3bc3f9b28a0c48cd4c1c236899477606 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +000017
18#undef DEBUG
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/init.h>
Paul Gortmakereefa9cf2011-05-27 09:42:30 -040021#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/pci.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080023#include <linux/string.h>
Benjamin Herrenschmidtb4a26be2010-04-06 15:03:40 +000024#include <linux/vmalloc.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/pci-bridge.h>
Ingo Molnar14cc3e22006-03-26 01:37:14 -080027#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/rtas.h>
John Rose5eeb8c62005-07-25 10:16:42 -050029#include <asm/vio.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "../pci.h"
32#include "rpaphp.h"
33#include "rpadlpar.h"
34
Ingo Molnar14cc3e22006-03-26 01:37:14 -080035static DEFINE_MUTEX(rpadlpar_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
John Rose56d84562005-07-25 10:17:03 -050037#define DLPAR_MODULE_NAME "rpadlpar_io"
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define NODE_TYPE_VIO 1
40#define NODE_TYPE_SLOT 2
41#define NODE_TYPE_PHB 3
42
John Rose5eeb8c62005-07-25 10:16:42 -050043static struct device_node *find_vio_slot_node(char *drc_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 struct device_node *parent = of_find_node_by_name(NULL, "vdevice");
John Rose5eeb8c62005-07-25 10:16:42 -050046 struct device_node *dn = NULL;
47 char *name;
48 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 if (!parent)
51 return NULL;
52
John Rose5eeb8c62005-07-25 10:16:42 -050053 while ((dn = of_get_next_child(parent, dn))) {
54 rc = rpaphp_get_drc_props(dn, NULL, &name, NULL, NULL);
55 if ((rc == 0) && (!strcmp(drc_name, name)))
56 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 }
58
John Rose5eeb8c62005-07-25 10:16:42 -050059 return dn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
62/* Find dlpar-capable pci node that contains the specified name and type */
63static struct device_node *find_php_slot_pci_node(char *drc_name,
64 char *drc_type)
65{
66 struct device_node *np = NULL;
67 char *name;
68 char *type;
69 int rc;
70
John Rosea57ed792006-11-13 15:12:52 -080071 while ((np = of_find_node_by_name(np, "pci"))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 rc = rpaphp_get_drc_props(np, NULL, &name, &type, NULL);
73 if (rc == 0)
74 if (!strcmp(drc_name, name) && !strcmp(drc_type, type))
75 break;
76 }
77
78 return np;
79}
80
John Rose5eeb8c62005-07-25 10:16:42 -050081static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
83 struct device_node *dn;
84
85 dn = find_php_slot_pci_node(drc_name, "SLOT");
86 if (dn) {
87 *node_type = NODE_TYPE_SLOT;
88 return dn;
89 }
90
91 dn = find_php_slot_pci_node(drc_name, "PHB");
92 if (dn) {
93 *node_type = NODE_TYPE_PHB;
94 return dn;
95 }
96
John Rose5eeb8c62005-07-25 10:16:42 -050097 dn = find_vio_slot_node(drc_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 if (dn) {
99 *node_type = NODE_TYPE_VIO;
100 return dn;
101 }
102
103 return NULL;
104}
105
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700106/**
107 * find_php_slot - return hotplug slot structure for device node
Randy Dunlap26e6c662007-11-28 09:04:30 -0800108 * @dn: target &device_node
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700109 *
110 * This routine will return the hotplug slot structure
111 * for a given device node. Note that built-in PCI slots
112 * may be dlpar-able, but not hot-pluggable, so this routine
113 * will return NULL for built-in PCI slots.
114 */
115static struct slot *find_php_slot(struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Geliang Tang2ac83cc2015-12-12 21:36:57 +0800117 struct slot *slot, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Geliang Tang2ac83cc2015-12-12 21:36:57 +0800119 list_for_each_entry_safe(slot, next, &rpaphp_slot_head,
120 rpaphp_slot_list) {
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600121 if (slot->dn == dn)
122 return slot;
123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600125 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
John Rose0945cd52005-07-25 10:16:53 -0500128static struct pci_dev *dlpar_find_new_dev(struct pci_bus *parent,
129 struct device_node *dev_dn)
130{
131 struct pci_dev *tmp = NULL;
132 struct device_node *child_dn;
133
134 list_for_each_entry(tmp, &parent->devices, bus_list) {
135 child_dn = pci_device_to_OF_node(tmp);
136 if (child_dn == dev_dn)
137 return tmp;
138 }
139 return NULL;
140}
141
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600142static void dlpar_pci_add_bus(struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600144 struct pci_dn *pdn = PCI_DN(dn);
John Rose5fa80fc2005-11-04 15:38:50 -0600145 struct pci_controller *phb = pdn->phb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 struct pci_dev *dev = NULL;
147
Gavin Shanff57b452015-03-17 16:15:06 +1100148 eeh_add_device_tree_early(pdn);
linas@austin.ibm.comd681db42005-12-01 18:56:14 -0600149
John Rose5fa80fc2005-11-04 15:38:50 -0600150 /* Add EADS device to PHB bus, adding new entry to bus->devices */
151 dev = of_create_pci_dev(dn, phb->bus, pdn->devfn);
152 if (!dev) {
153 printk(KERN_ERR "%s: failed to create pci dev for %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800154 __func__, dn->full_name);
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600155 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000158 /* Scan below the new bridge */
Yijing Wangf86e1f12014-05-04 12:23:43 +0800159 if (pci_is_bridge(dev))
Benjamin Herrenschmidt98d9f30c82011-04-11 11:37:07 +1000160 of_scan_pci_bridge(dev);
John Rose5fa80fc2005-11-04 15:38:50 -0600161
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000162 /* Map IO space for child bus, which may or may not succeed */
163 pcibios_map_io_space(dev->subordinate);
John Rose5fa80fc2005-11-04 15:38:50 -0600164
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000165 /* Finish adding it : resource allocation, adding devices, etc...
166 * Note that we need to perform the finish pass on the -parent-
167 * bus of the EADS bridge so the bridge device itself gets
168 * properly added
169 */
170 pcibios_finish_adding_to_bus(phb->bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
John Rose940903c2005-07-25 10:16:58 -0500173static int dlpar_add_pci_slot(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
175 struct pci_dev *dev;
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600176 struct pci_controller *phb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Gavin Shan3773dd22016-05-03 15:41:38 +1000178 if (pci_find_bus_by_node(dn))
John Rose56d84562005-07-25 10:17:03 -0500179 return -EINVAL;
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 /* Add pci bus */
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600182 dlpar_pci_add_bus(dn);
183
184 /* Confirm new bridge dev was created */
185 phb = PCI_DN(dn)->phb;
186 dev = dlpar_find_new_dev(phb->bus, dn);
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 if (!dev) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800189 printk(KERN_ERR "%s: unable to add bus %s\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 drc_name);
191 return -EIO;
192 }
193
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600194 if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
195 printk(KERN_ERR "%s: unexpected header type %d, unable to add bus %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800196 __func__, dev->hdr_type, drc_name);
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600197 return -EIO;
198 }
199
John Rose5eeb8c62005-07-25 10:16:42 -0500200 /* Add hotplug slot */
201 if (rpaphp_add_slot(dn)) {
202 printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800203 __func__, drc_name);
John Rose5eeb8c62005-07-25 10:16:42 -0500204 return -EIO;
205 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return 0;
207}
208
John Rose56d84562005-07-25 10:17:03 -0500209static int dlpar_remove_phb(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
John Rose56d84562005-07-25 10:17:03 -0500211 struct slot *slot;
Paul Mackerras16353172005-09-06 13:17:54 +1000212 struct pci_dn *pdn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 int rc = 0;
214
Gavin Shan3773dd22016-05-03 15:41:38 +1000215 if (!pci_find_bus_by_node(dn))
John Rose56d84562005-07-25 10:17:03 -0500216 return -EINVAL;
217
Bjorn Helgaasf7625982013-11-14 11:28:18 -0700218 /* If pci slot is hotpluggable, use hotplug to remove it */
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700219 slot = find_php_slot(dn);
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000220 if (slot && rpaphp_deregister_slot(slot)) {
221 printk(KERN_ERR "%s: unable to remove hotplug slot %s\n",
222 __func__, drc_name);
223 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225
Paul Mackerras16353172005-09-06 13:17:54 +1000226 pdn = dn->data;
227 BUG_ON(!pdn || !pdn->phb);
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000228 rc = remove_phb_dynamic(pdn->phb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if (rc < 0)
230 return rc;
231
Paul Mackerras16353172005-09-06 13:17:54 +1000232 pdn->phb = NULL;
John Rose56d84562005-07-25 10:17:03 -0500233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return 0;
235}
236
John Rose5eeb8c62005-07-25 10:16:42 -0500237static int dlpar_add_phb(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
239 struct pci_controller *phb;
240
Linas Vepstasfe98aea2005-11-03 18:51:17 -0600241 if (PCI_DN(dn) && PCI_DN(dn)->phb) {
John Rose56d84562005-07-25 10:17:03 -0500242 /* PHB already exists */
243 return -EINVAL;
244 }
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 phb = init_phb_dynamic(dn);
247 if (!phb)
John Rose56d84562005-07-25 10:17:03 -0500248 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
John Rose5eeb8c62005-07-25 10:16:42 -0500250 if (rpaphp_add_slot(dn)) {
251 printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800252 __func__, drc_name);
John Rose5eeb8c62005-07-25 10:16:42 -0500253 return -EIO;
254 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return 0;
256}
257
John Rose56d84562005-07-25 10:17:03 -0500258static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn)
259{
Johan Hovoldb3539f82016-11-01 16:26:03 +0100260 struct vio_dev *vio_dev;
261
262 vio_dev = vio_find_node(dn);
263 if (vio_dev) {
264 put_device(&vio_dev->dev);
John Rose56d84562005-07-25 10:17:03 -0500265 return -EINVAL;
Johan Hovoldb3539f82016-11-01 16:26:03 +0100266 }
John Rose56d84562005-07-25 10:17:03 -0500267
268 if (!vio_register_device_node(dn)) {
269 printk(KERN_ERR
270 "%s: failed to register vio node %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800271 __func__, drc_name);
John Rose56d84562005-07-25 10:17:03 -0500272 return -EIO;
273 }
274 return 0;
275}
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277/**
278 * dlpar_add_slot - DLPAR add an I/O Slot
279 * @drc_name: drc-name of newly added slot
280 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800281 * Make the hotplug module and the kernel aware of a newly added I/O Slot.
282 * Return Codes:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 * 0 Success
284 * -ENODEV Not a valid drc_name
285 * -EINVAL Slot already added
286 * -ERESTARTSYS Signalled before obtaining lock
287 * -EIO Internal PCI Error
288 */
289int dlpar_add_slot(char *drc_name)
290{
291 struct device_node *dn = NULL;
292 int node_type;
John Rose56d84562005-07-25 10:17:03 -0500293 int rc = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800295 if (mutex_lock_interruptible(&rpadlpar_mutex))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 return -ERESTARTSYS;
297
John Rose5eeb8c62005-07-25 10:16:42 -0500298 /* Find newly added node */
299 dn = find_dlpar_node(drc_name, &node_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 if (!dn) {
301 rc = -ENODEV;
302 goto exit;
303 }
304
305 switch (node_type) {
306 case NODE_TYPE_VIO:
John Rose56d84562005-07-25 10:17:03 -0500307 rc = dlpar_add_vio_slot(drc_name, dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 break;
309 case NODE_TYPE_SLOT:
310 rc = dlpar_add_pci_slot(drc_name, dn);
311 break;
312 case NODE_TYPE_PHB:
John Rose5eeb8c62005-07-25 10:16:42 -0500313 rc = dlpar_add_phb(drc_name, dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316
John Rose56d84562005-07-25 10:17:03 -0500317 printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318exit:
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800319 mutex_unlock(&rpadlpar_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 return rc;
321}
322
323/**
324 * dlpar_remove_vio_slot - DLPAR remove a virtual I/O Slot
325 * @drc_name: drc-name of newly added slot
Randy Dunlap26e6c662007-11-28 09:04:30 -0800326 * @dn: &device_node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800328 * Remove the kernel and hotplug representations of an I/O Slot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 * Return Codes:
330 * 0 Success
John Rose56d84562005-07-25 10:17:03 -0500331 * -EINVAL Vio dev doesn't exist
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 */
John Rose56d84562005-07-25 10:17:03 -0500333static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
John Rose5eeb8c62005-07-25 10:16:42 -0500335 struct vio_dev *vio_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
John Rose5eeb8c62005-07-25 10:16:42 -0500337 vio_dev = vio_find_node(dn);
John Rose56d84562005-07-25 10:17:03 -0500338 if (!vio_dev)
339 return -EINVAL;
John Rose5eeb8c62005-07-25 10:16:42 -0500340
341 vio_unregister_device(vio_dev);
Johan Hovoldb3539f82016-11-01 16:26:03 +0100342
343 put_device(&vio_dev->dev);
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 return 0;
346}
347
348/**
Randy Dunlap26e6c662007-11-28 09:04:30 -0800349 * dlpar_remove_pci_slot - DLPAR remove a PCI I/O Slot
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 * @drc_name: drc-name of newly added slot
Randy Dunlap26e6c662007-11-28 09:04:30 -0800351 * @dn: &device_node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800353 * Remove the kernel and hotplug representations of a PCI I/O Slot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 * Return Codes:
355 * 0 Success
356 * -ENODEV Not a valid drc_name
357 * -EIO Internal PCI Error
358 */
John Rose56d84562005-07-25 10:17:03 -0500359int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
John Rose56d84562005-07-25 10:17:03 -0500361 struct pci_bus *bus;
362 struct slot *slot;
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700363 int ret = 0;
364
365 pci_lock_rescan_remove();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Gavin Shan3773dd22016-05-03 15:41:38 +1000367 bus = pci_find_bus_by_node(dn);
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700368 if (!bus) {
369 ret = -EINVAL;
370 goto out;
371 }
John Rose56d84562005-07-25 10:17:03 -0500372
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000373 pr_debug("PCI: Removing PCI slot below EADS bridge %s\n",
374 bus->self ? pci_name(bus->self) : "<!PHB!>");
375
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700376 slot = find_php_slot(dn);
John Rose56d84562005-07-25 10:17:03 -0500377 if (slot) {
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000378 pr_debug("PCI: Removing hotplug slot for %04x:%02x...\n",
379 pci_domain_nr(bus), bus->number);
380
linas@austin.ibm.comf6afbad2006-01-12 18:31:01 -0600381 if (rpaphp_deregister_slot(slot)) {
John Rose56d84562005-07-25 10:17:03 -0500382 printk(KERN_ERR
383 "%s: unable to remove hotplug slot %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800384 __func__, drc_name);
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700385 ret = -EIO;
386 goto out;
John Rose56d84562005-07-25 10:17:03 -0500387 }
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000390 /* Remove all devices below slot */
Gavin Shanbd251b82016-05-03 15:41:37 +1000391 pci_hp_remove_devices(bus);
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000392
393 /* Unmap PCI IO space */
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000394 if (pcibios_unmap_io_space(bus)) {
John Rose9c209c92005-07-25 11:13:38 -0500395 printk(KERN_ERR "%s: failed to unmap bus range\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800396 __func__);
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700397 ret = -ERANGE;
398 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 }
John Rose9c209c92005-07-25 11:13:38 -0500400
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000401 /* Remove the EADS bridge device itself */
John Rose9c209c92005-07-25 11:13:38 -0500402 BUG_ON(!bus->self);
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000403 pr_debug("PCI: Now removing bridge device %s\n", pci_name(bus->self));
Yinghai Lu210647a2012-02-25 13:54:20 -0800404 pci_stop_and_remove_bus_device(bus->self);
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000405
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700406 out:
407 pci_unlock_rescan_remove();
408 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
411/**
412 * dlpar_remove_slot - DLPAR remove an I/O Slot
413 * @drc_name: drc-name of newly added slot
414 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800415 * Remove the kernel and hotplug representations of an I/O Slot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 * Return Codes:
417 * 0 Success
418 * -ENODEV Not a valid drc_name
419 * -EINVAL Slot already removed
420 * -ERESTARTSYS Signalled before obtaining lock
421 * -EIO Internal Error
422 */
423int dlpar_remove_slot(char *drc_name)
424{
John Rose5eeb8c62005-07-25 10:16:42 -0500425 struct device_node *dn;
John Rose5eeb8c62005-07-25 10:16:42 -0500426 int node_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 int rc = 0;
428
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800429 if (mutex_lock_interruptible(&rpadlpar_mutex))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 return -ERESTARTSYS;
431
John Rose5eeb8c62005-07-25 10:16:42 -0500432 dn = find_dlpar_node(drc_name, &node_type);
433 if (!dn) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 rc = -ENODEV;
435 goto exit;
436 }
437
John Rose56d84562005-07-25 10:17:03 -0500438 switch (node_type) {
439 case NODE_TYPE_VIO:
440 rc = dlpar_remove_vio_slot(drc_name, dn);
441 break;
442 case NODE_TYPE_PHB:
443 rc = dlpar_remove_phb(drc_name, dn);
444 break;
445 case NODE_TYPE_SLOT:
446 rc = dlpar_remove_pci_slot(drc_name, dn);
447 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 }
Benjamin Herrenschmidtb4a26be2010-04-06 15:03:40 +0000449 vm_unmap_aliases();
450
John Rose56d84562005-07-25 10:17:03 -0500451 printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452exit:
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800453 mutex_unlock(&rpadlpar_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 return rc;
455}
456
457static inline int is_dlpar_capable(void)
458{
459 int rc = rtas_token("ibm,configure-connector");
460
461 return (int) (rc != RTAS_UNKNOWN_SERVICE);
462}
463
464int __init rpadlpar_io_init(void)
465{
466 int rc = 0;
467
468 if (!is_dlpar_capable()) {
469 printk(KERN_WARNING "%s: partition not DLPAR capable\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800470 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return -EPERM;
472 }
473
474 rc = dlpar_sysfs_init();
475 return rc;
476}
477
478void rpadlpar_io_exit(void)
479{
480 dlpar_sysfs_exit();
481 return;
482}
483
484module_init(rpadlpar_io_init);
485module_exit(rpadlpar_io_exit);
486MODULE_LICENSE("GPL");