blob: d3562df64456a6699fbc73bd2c745e303f3fc64d [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 }
Tyrel Datwyler8b19d722019-03-22 13:27:21 -050058 of_node_put(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
John Rose5eeb8c62005-07-25 10:16:42 -050060 return dn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
63/* Find dlpar-capable pci node that contains the specified name and type */
64static struct device_node *find_php_slot_pci_node(char *drc_name,
65 char *drc_type)
66{
67 struct device_node *np = NULL;
68 char *name;
69 char *type;
70 int rc;
71
John Rosea57ed792006-11-13 15:12:52 -080072 while ((np = of_find_node_by_name(np, "pci"))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 rc = rpaphp_get_drc_props(np, NULL, &name, &type, NULL);
74 if (rc == 0)
75 if (!strcmp(drc_name, name) && !strcmp(drc_type, type))
76 break;
77 }
78
79 return np;
80}
81
Tyrel Datwyler8b19d722019-03-22 13:27:21 -050082/* Returns a device_node with its reference count incremented */
John Rose5eeb8c62005-07-25 10:16:42 -050083static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 struct device_node *dn;
86
87 dn = find_php_slot_pci_node(drc_name, "SLOT");
88 if (dn) {
89 *node_type = NODE_TYPE_SLOT;
90 return dn;
91 }
92
93 dn = find_php_slot_pci_node(drc_name, "PHB");
94 if (dn) {
95 *node_type = NODE_TYPE_PHB;
96 return dn;
97 }
98
John Rose5eeb8c62005-07-25 10:16:42 -050099 dn = find_vio_slot_node(drc_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 if (dn) {
101 *node_type = NODE_TYPE_VIO;
102 return dn;
103 }
104
105 return NULL;
106}
107
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700108/**
109 * find_php_slot - return hotplug slot structure for device node
Randy Dunlap26e6c662007-11-28 09:04:30 -0800110 * @dn: target &device_node
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700111 *
112 * This routine will return the hotplug slot structure
113 * for a given device node. Note that built-in PCI slots
114 * may be dlpar-able, but not hot-pluggable, so this routine
115 * will return NULL for built-in PCI slots.
116 */
117static struct slot *find_php_slot(struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Geliang Tang2ac83cc2015-12-12 21:36:57 +0800119 struct slot *slot, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Geliang Tang2ac83cc2015-12-12 21:36:57 +0800121 list_for_each_entry_safe(slot, next, &rpaphp_slot_head,
122 rpaphp_slot_list) {
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600123 if (slot->dn == dn)
124 return slot;
125 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600127 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
John Rose0945cd52005-07-25 10:16:53 -0500130static struct pci_dev *dlpar_find_new_dev(struct pci_bus *parent,
131 struct device_node *dev_dn)
132{
133 struct pci_dev *tmp = NULL;
134 struct device_node *child_dn;
135
136 list_for_each_entry(tmp, &parent->devices, bus_list) {
137 child_dn = pci_device_to_OF_node(tmp);
138 if (child_dn == dev_dn)
139 return tmp;
140 }
141 return NULL;
142}
143
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600144static void dlpar_pci_add_bus(struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600146 struct pci_dn *pdn = PCI_DN(dn);
John Rose5fa80fc2005-11-04 15:38:50 -0600147 struct pci_controller *phb = pdn->phb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 struct pci_dev *dev = NULL;
149
Gavin Shanff57b452015-03-17 16:15:06 +1100150 eeh_add_device_tree_early(pdn);
linas@austin.ibm.comd681db42005-12-01 18:56:14 -0600151
John Rose5fa80fc2005-11-04 15:38:50 -0600152 /* Add EADS device to PHB bus, adding new entry to bus->devices */
153 dev = of_create_pci_dev(dn, phb->bus, pdn->devfn);
154 if (!dev) {
155 printk(KERN_ERR "%s: failed to create pci dev for %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800156 __func__, dn->full_name);
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600157 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000160 /* Scan below the new bridge */
Yijing Wangf86e1f12014-05-04 12:23:43 +0800161 if (pci_is_bridge(dev))
Benjamin Herrenschmidt98d9f30c82011-04-11 11:37:07 +1000162 of_scan_pci_bridge(dev);
John Rose5fa80fc2005-11-04 15:38:50 -0600163
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000164 /* Map IO space for child bus, which may or may not succeed */
165 pcibios_map_io_space(dev->subordinate);
John Rose5fa80fc2005-11-04 15:38:50 -0600166
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000167 /* Finish adding it : resource allocation, adding devices, etc...
168 * Note that we need to perform the finish pass on the -parent-
169 * bus of the EADS bridge so the bridge device itself gets
170 * properly added
171 */
172 pcibios_finish_adding_to_bus(phb->bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
John Rose940903c2005-07-25 10:16:58 -0500175static int dlpar_add_pci_slot(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
177 struct pci_dev *dev;
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600178 struct pci_controller *phb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Gavin Shan3773dd22016-05-03 15:41:38 +1000180 if (pci_find_bus_by_node(dn))
John Rose56d84562005-07-25 10:17:03 -0500181 return -EINVAL;
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 /* Add pci bus */
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600184 dlpar_pci_add_bus(dn);
185
186 /* Confirm new bridge dev was created */
187 phb = PCI_DN(dn)->phb;
188 dev = dlpar_find_new_dev(phb->bus, dn);
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 if (!dev) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800191 printk(KERN_ERR "%s: unable to add bus %s\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 drc_name);
193 return -EIO;
194 }
195
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600196 if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
197 printk(KERN_ERR "%s: unexpected header type %d, unable to add bus %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800198 __func__, dev->hdr_type, drc_name);
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600199 return -EIO;
200 }
201
John Rose5eeb8c62005-07-25 10:16:42 -0500202 /* Add hotplug slot */
203 if (rpaphp_add_slot(dn)) {
204 printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800205 __func__, drc_name);
John Rose5eeb8c62005-07-25 10:16:42 -0500206 return -EIO;
207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return 0;
209}
210
John Rose56d84562005-07-25 10:17:03 -0500211static int dlpar_remove_phb(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
John Rose56d84562005-07-25 10:17:03 -0500213 struct slot *slot;
Paul Mackerras16353172005-09-06 13:17:54 +1000214 struct pci_dn *pdn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 int rc = 0;
216
Gavin Shan3773dd22016-05-03 15:41:38 +1000217 if (!pci_find_bus_by_node(dn))
John Rose56d84562005-07-25 10:17:03 -0500218 return -EINVAL;
219
Bjorn Helgaasf7625982013-11-14 11:28:18 -0700220 /* If pci slot is hotpluggable, use hotplug to remove it */
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700221 slot = find_php_slot(dn);
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000222 if (slot && rpaphp_deregister_slot(slot)) {
223 printk(KERN_ERR "%s: unable to remove hotplug slot %s\n",
224 __func__, drc_name);
225 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227
Paul Mackerras16353172005-09-06 13:17:54 +1000228 pdn = dn->data;
229 BUG_ON(!pdn || !pdn->phb);
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000230 rc = remove_phb_dynamic(pdn->phb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 if (rc < 0)
232 return rc;
233
Paul Mackerras16353172005-09-06 13:17:54 +1000234 pdn->phb = NULL;
John Rose56d84562005-07-25 10:17:03 -0500235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return 0;
237}
238
John Rose5eeb8c62005-07-25 10:16:42 -0500239static int dlpar_add_phb(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 struct pci_controller *phb;
242
Linas Vepstasfe98aea2005-11-03 18:51:17 -0600243 if (PCI_DN(dn) && PCI_DN(dn)->phb) {
John Rose56d84562005-07-25 10:17:03 -0500244 /* PHB already exists */
245 return -EINVAL;
246 }
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 phb = init_phb_dynamic(dn);
249 if (!phb)
John Rose56d84562005-07-25 10:17:03 -0500250 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
John Rose5eeb8c62005-07-25 10:16:42 -0500252 if (rpaphp_add_slot(dn)) {
253 printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800254 __func__, drc_name);
John Rose5eeb8c62005-07-25 10:16:42 -0500255 return -EIO;
256 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 return 0;
258}
259
John Rose56d84562005-07-25 10:17:03 -0500260static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn)
261{
Johan Hovoldb3539f82016-11-01 16:26:03 +0100262 struct vio_dev *vio_dev;
263
264 vio_dev = vio_find_node(dn);
265 if (vio_dev) {
266 put_device(&vio_dev->dev);
John Rose56d84562005-07-25 10:17:03 -0500267 return -EINVAL;
Johan Hovoldb3539f82016-11-01 16:26:03 +0100268 }
John Rose56d84562005-07-25 10:17:03 -0500269
270 if (!vio_register_device_node(dn)) {
271 printk(KERN_ERR
272 "%s: failed to register vio node %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800273 __func__, drc_name);
John Rose56d84562005-07-25 10:17:03 -0500274 return -EIO;
275 }
276 return 0;
277}
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279/**
280 * dlpar_add_slot - DLPAR add an I/O Slot
281 * @drc_name: drc-name of newly added slot
282 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800283 * Make the hotplug module and the kernel aware of a newly added I/O Slot.
284 * Return Codes:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 * 0 Success
286 * -ENODEV Not a valid drc_name
287 * -EINVAL Slot already added
288 * -ERESTARTSYS Signalled before obtaining lock
289 * -EIO Internal PCI Error
290 */
291int dlpar_add_slot(char *drc_name)
292{
293 struct device_node *dn = NULL;
294 int node_type;
John Rose56d84562005-07-25 10:17:03 -0500295 int rc = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800297 if (mutex_lock_interruptible(&rpadlpar_mutex))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 return -ERESTARTSYS;
299
John Rose5eeb8c62005-07-25 10:16:42 -0500300 /* Find newly added node */
301 dn = find_dlpar_node(drc_name, &node_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 if (!dn) {
303 rc = -ENODEV;
304 goto exit;
305 }
306
307 switch (node_type) {
308 case NODE_TYPE_VIO:
John Rose56d84562005-07-25 10:17:03 -0500309 rc = dlpar_add_vio_slot(drc_name, dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 break;
311 case NODE_TYPE_SLOT:
312 rc = dlpar_add_pci_slot(drc_name, dn);
313 break;
314 case NODE_TYPE_PHB:
John Rose5eeb8c62005-07-25 10:16:42 -0500315 rc = dlpar_add_phb(drc_name, dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 }
Tyrel Datwyler8b19d722019-03-22 13:27:21 -0500318 of_node_put(dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
John Rose56d84562005-07-25 10:17:03 -0500320 printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321exit:
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800322 mutex_unlock(&rpadlpar_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 return rc;
324}
325
326/**
327 * dlpar_remove_vio_slot - DLPAR remove a virtual I/O Slot
328 * @drc_name: drc-name of newly added slot
Randy Dunlap26e6c662007-11-28 09:04:30 -0800329 * @dn: &device_node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800331 * Remove the kernel and hotplug representations of an I/O Slot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 * Return Codes:
333 * 0 Success
John Rose56d84562005-07-25 10:17:03 -0500334 * -EINVAL Vio dev doesn't exist
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 */
John Rose56d84562005-07-25 10:17:03 -0500336static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
John Rose5eeb8c62005-07-25 10:16:42 -0500338 struct vio_dev *vio_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
John Rose5eeb8c62005-07-25 10:16:42 -0500340 vio_dev = vio_find_node(dn);
John Rose56d84562005-07-25 10:17:03 -0500341 if (!vio_dev)
342 return -EINVAL;
John Rose5eeb8c62005-07-25 10:16:42 -0500343
344 vio_unregister_device(vio_dev);
Johan Hovoldb3539f82016-11-01 16:26:03 +0100345
346 put_device(&vio_dev->dev);
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return 0;
349}
350
351/**
Randy Dunlap26e6c662007-11-28 09:04:30 -0800352 * dlpar_remove_pci_slot - DLPAR remove a PCI I/O Slot
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 * @drc_name: drc-name of newly added slot
Randy Dunlap26e6c662007-11-28 09:04:30 -0800354 * @dn: &device_node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800356 * Remove the kernel and hotplug representations of a PCI I/O Slot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 * Return Codes:
358 * 0 Success
359 * -ENODEV Not a valid drc_name
360 * -EIO Internal PCI Error
361 */
John Rose56d84562005-07-25 10:17:03 -0500362int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
John Rose56d84562005-07-25 10:17:03 -0500364 struct pci_bus *bus;
365 struct slot *slot;
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700366 int ret = 0;
367
368 pci_lock_rescan_remove();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Gavin Shan3773dd22016-05-03 15:41:38 +1000370 bus = pci_find_bus_by_node(dn);
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700371 if (!bus) {
372 ret = -EINVAL;
373 goto out;
374 }
John Rose56d84562005-07-25 10:17:03 -0500375
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000376 pr_debug("PCI: Removing PCI slot below EADS bridge %s\n",
377 bus->self ? pci_name(bus->self) : "<!PHB!>");
378
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700379 slot = find_php_slot(dn);
John Rose56d84562005-07-25 10:17:03 -0500380 if (slot) {
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000381 pr_debug("PCI: Removing hotplug slot for %04x:%02x...\n",
382 pci_domain_nr(bus), bus->number);
383
linas@austin.ibm.comf6afbad2006-01-12 18:31:01 -0600384 if (rpaphp_deregister_slot(slot)) {
John Rose56d84562005-07-25 10:17:03 -0500385 printk(KERN_ERR
386 "%s: unable to remove hotplug slot %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800387 __func__, drc_name);
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700388 ret = -EIO;
389 goto out;
John Rose56d84562005-07-25 10:17:03 -0500390 }
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000393 /* Remove all devices below slot */
Gavin Shanbd251b82016-05-03 15:41:37 +1000394 pci_hp_remove_devices(bus);
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000395
396 /* Unmap PCI IO space */
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000397 if (pcibios_unmap_io_space(bus)) {
John Rose9c209c92005-07-25 11:13:38 -0500398 printk(KERN_ERR "%s: failed to unmap bus range\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800399 __func__);
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700400 ret = -ERANGE;
401 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
John Rose9c209c92005-07-25 11:13:38 -0500403
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000404 /* Remove the EADS bridge device itself */
John Rose9c209c92005-07-25 11:13:38 -0500405 BUG_ON(!bus->self);
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000406 pr_debug("PCI: Now removing bridge device %s\n", pci_name(bus->self));
Yinghai Lu210647a2012-02-25 13:54:20 -0800407 pci_stop_and_remove_bus_device(bus->self);
Benjamin Herrenschmidtfd6852c2008-10-27 19:48:52 +0000408
Rafael J. Wysockic4ec84c2014-01-14 12:03:14 -0700409 out:
410 pci_unlock_rescan_remove();
411 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414/**
415 * dlpar_remove_slot - DLPAR remove an I/O Slot
416 * @drc_name: drc-name of newly added slot
417 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800418 * Remove the kernel and hotplug representations of an I/O Slot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 * Return Codes:
420 * 0 Success
421 * -ENODEV Not a valid drc_name
422 * -EINVAL Slot already removed
423 * -ERESTARTSYS Signalled before obtaining lock
424 * -EIO Internal Error
425 */
426int dlpar_remove_slot(char *drc_name)
427{
John Rose5eeb8c62005-07-25 10:16:42 -0500428 struct device_node *dn;
John Rose5eeb8c62005-07-25 10:16:42 -0500429 int node_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 int rc = 0;
431
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800432 if (mutex_lock_interruptible(&rpadlpar_mutex))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 return -ERESTARTSYS;
434
John Rose5eeb8c62005-07-25 10:16:42 -0500435 dn = find_dlpar_node(drc_name, &node_type);
436 if (!dn) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 rc = -ENODEV;
438 goto exit;
439 }
440
John Rose56d84562005-07-25 10:17:03 -0500441 switch (node_type) {
442 case NODE_TYPE_VIO:
443 rc = dlpar_remove_vio_slot(drc_name, dn);
444 break;
445 case NODE_TYPE_PHB:
446 rc = dlpar_remove_phb(drc_name, dn);
447 break;
448 case NODE_TYPE_SLOT:
449 rc = dlpar_remove_pci_slot(drc_name, dn);
450 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
Tyrel Datwyler8b19d722019-03-22 13:27:21 -0500452 of_node_put(dn);
Benjamin Herrenschmidtb4a26be2010-04-06 15:03:40 +0000453 vm_unmap_aliases();
454
John Rose56d84562005-07-25 10:17:03 -0500455 printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456exit:
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800457 mutex_unlock(&rpadlpar_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return rc;
459}
460
461static inline int is_dlpar_capable(void)
462{
463 int rc = rtas_token("ibm,configure-connector");
464
465 return (int) (rc != RTAS_UNKNOWN_SERVICE);
466}
467
468int __init rpadlpar_io_init(void)
469{
470 int rc = 0;
471
472 if (!is_dlpar_capable()) {
473 printk(KERN_WARNING "%s: partition not DLPAR capable\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800474 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 return -EPERM;
476 }
477
478 rc = dlpar_sysfs_init();
479 return rc;
480}
481
482void rpadlpar_io_exit(void)
483{
484 dlpar_sysfs_exit();
485 return;
486}
487
488module_init(rpadlpar_io_init);
489module_exit(rpadlpar_io_exit);
490MODULE_LICENSE("GPL");