blob: 9c2a22fed18b2b3a6d37e83278f8583d963f1bb5 [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 */
17#include <linux/init.h>
18#include <linux/pci.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080019#include <linux/string.h>
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/pci-bridge.h>
Ingo Molnar14cc3e22006-03-26 01:37:14 -080022#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/rtas.h>
John Rose5eeb8c62005-07-25 10:16:42 -050024#include <asm/vio.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "../pci.h"
27#include "rpaphp.h"
28#include "rpadlpar.h"
29
Ingo Molnar14cc3e22006-03-26 01:37:14 -080030static DEFINE_MUTEX(rpadlpar_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
John Rose56d84562005-07-25 10:17:03 -050032#define DLPAR_MODULE_NAME "rpadlpar_io"
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#define NODE_TYPE_VIO 1
35#define NODE_TYPE_SLOT 2
36#define NODE_TYPE_PHB 3
37
John Rose5eeb8c62005-07-25 10:16:42 -050038static struct device_node *find_vio_slot_node(char *drc_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 struct device_node *parent = of_find_node_by_name(NULL, "vdevice");
John Rose5eeb8c62005-07-25 10:16:42 -050041 struct device_node *dn = NULL;
42 char *name;
43 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 if (!parent)
46 return NULL;
47
John Rose5eeb8c62005-07-25 10:16:42 -050048 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 Torvalds1da177e2005-04-16 15:20:36 -070052 }
53
John Rose5eeb8c62005-07-25 10:16:42 -050054 return dn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
57/* Find dlpar-capable pci node that contains the specified name and type */
58static 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 Rosea57ed792006-11-13 15:12:52 -080066 while ((np = of_find_node_by_name(np, "pci"))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 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 Rose5eeb8c62005-07-25 10:16:42 -050076static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
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 Rose5eeb8c62005-07-25 10:16:42 -050092 dn = find_vio_slot_node(drc_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (dn) {
94 *node_type = NODE_TYPE_VIO;
95 return dn;
96 }
97
98 return NULL;
99}
100
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700101/**
102 * find_php_slot - return hotplug slot structure for device node
Randy Dunlap26e6c662007-11-28 09:04:30 -0800103 * @dn: target &device_node
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700104 *
105 * This routine will return the hotplug slot structure
106 * for a given device node. Note that built-in PCI slots
107 * may be dlpar-able, but not hot-pluggable, so this routine
108 * will return NULL for built-in PCI slots.
109 */
110static struct slot *find_php_slot(struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 struct list_head *tmp, *n;
113 struct slot *slot;
114
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600115 list_for_each_safe(tmp, n, &rpaphp_slot_head) {
116 slot = list_entry(tmp, struct slot, rpaphp_slot_list);
117 if (slot->dn == dn)
118 return slot;
119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600121 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
John Rose0945cd52005-07-25 10:16:53 -0500124static struct pci_dev *dlpar_find_new_dev(struct pci_bus *parent,
125 struct device_node *dev_dn)
126{
127 struct pci_dev *tmp = NULL;
128 struct device_node *child_dn;
129
130 list_for_each_entry(tmp, &parent->devices, bus_list) {
131 child_dn = pci_device_to_OF_node(tmp);
132 if (child_dn == dev_dn)
133 return tmp;
134 }
135 return NULL;
136}
137
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600138static void dlpar_pci_add_bus(struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600140 struct pci_dn *pdn = PCI_DN(dn);
John Rose5fa80fc2005-11-04 15:38:50 -0600141 struct pci_controller *phb = pdn->phb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 struct pci_dev *dev = NULL;
143
linas@austin.ibm.comd681db42005-12-01 18:56:14 -0600144 eeh_add_device_tree_early(dn);
145
John Rose5fa80fc2005-11-04 15:38:50 -0600146 /* Add EADS device to PHB bus, adding new entry to bus->devices */
147 dev = of_create_pci_dev(dn, phb->bus, pdn->devfn);
148 if (!dev) {
149 printk(KERN_ERR "%s: failed to create pci dev for %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800150 __func__, dn->full_name);
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600151 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }
153
John Rose5fa80fc2005-11-04 15:38:50 -0600154 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
155 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
156 of_scan_pci_bridge(dn, dev);
157
Benjamin Herrenschmidtbf5e2ba2007-12-20 14:54:51 +1100158 pcibios_fixup_new_pci_devices(dev->subordinate);
John Rose5fa80fc2005-11-04 15:38:50 -0600159
160 /* Claim new bus resources */
linas@austin.ibm.comcd5b50b2005-12-01 18:59:58 -0600161 pcibios_claim_one_bus(dev->bus);
John Rose5fa80fc2005-11-04 15:38:50 -0600162
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000163 /* Map IO space for child bus, which may or may not succeed */
164 pcibios_map_io_space(dev->subordinate);
John Rose5fa80fc2005-11-04 15:38:50 -0600165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 /* Add new devices to global lists. Register in proc, sysfs. */
John Rose5fa80fc2005-11-04 15:38:50 -0600167 pci_bus_add_devices(phb->bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
John Rose940903c2005-07-25 10:16:58 -0500170static int dlpar_add_pci_slot(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
172 struct pci_dev *dev;
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600173 struct pci_controller *phb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
linas@austin.ibm.com01657862006-01-12 18:18:26 -0600175 if (pcibios_find_pci_bus(dn))
John Rose56d84562005-07-25 10:17:03 -0500176 return -EINVAL;
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 /* Add pci bus */
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600179 dlpar_pci_add_bus(dn);
180
181 /* Confirm new bridge dev was created */
182 phb = PCI_DN(dn)->phb;
183 dev = dlpar_find_new_dev(phb->bus, dn);
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 if (!dev) {
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800186 printk(KERN_ERR "%s: unable to add bus %s\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 drc_name);
188 return -EIO;
189 }
190
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600191 if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
192 printk(KERN_ERR "%s: unexpected header type %d, unable to add bus %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800193 __func__, dev->hdr_type, drc_name);
linas@austin.ibm.com8737d6a2006-01-12 18:35:23 -0600194 return -EIO;
195 }
196
John Rose5eeb8c62005-07-25 10:16:42 -0500197 /* Add hotplug slot */
198 if (rpaphp_add_slot(dn)) {
199 printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800200 __func__, drc_name);
John Rose5eeb8c62005-07-25 10:16:42 -0500201 return -EIO;
202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 return 0;
204}
205
206static int dlpar_remove_root_bus(struct pci_controller *phb)
207{
208 struct pci_bus *phb_bus;
209 int rc;
210
211 phb_bus = phb->bus;
212 if (!(list_empty(&phb_bus->children) &&
213 list_empty(&phb_bus->devices))) {
214 return -EBUSY;
215 }
216
217 rc = pcibios_remove_root_bus(phb);
218 if (rc)
219 return -EIO;
220
221 device_unregister(phb_bus->bridge);
222 pci_remove_bus(phb_bus);
223
224 return 0;
225}
226
John Rose56d84562005-07-25 10:17:03 -0500227static int dlpar_remove_phb(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
John Rose56d84562005-07-25 10:17:03 -0500229 struct slot *slot;
Paul Mackerras16353172005-09-06 13:17:54 +1000230 struct pci_dn *pdn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 int rc = 0;
232
linas@austin.ibm.com01657862006-01-12 18:18:26 -0600233 if (!pcibios_find_pci_bus(dn))
John Rose56d84562005-07-25 10:17:03 -0500234 return -EINVAL;
235
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700236 /* If pci slot is hotplugable, use hotplug to remove it */
237 slot = find_php_slot(dn);
John Rose56d84562005-07-25 10:17:03 -0500238 if (slot) {
linas@austin.ibm.comf6afbad2006-01-12 18:31:01 -0600239 if (rpaphp_deregister_slot(slot)) {
John Rose56d84562005-07-25 10:17:03 -0500240 printk(KERN_ERR
241 "%s: unable to remove hotplug slot %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800242 __func__, drc_name);
John Rose56d84562005-07-25 10:17:03 -0500243 return -EIO;
244 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 }
246
Paul Mackerras16353172005-09-06 13:17:54 +1000247 pdn = dn->data;
248 BUG_ON(!pdn || !pdn->phb);
249 rc = dlpar_remove_root_bus(pdn->phb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 if (rc < 0)
251 return rc;
252
Paul Mackerras16353172005-09-06 13:17:54 +1000253 pdn->phb = NULL;
John Rose56d84562005-07-25 10:17:03 -0500254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return 0;
256}
257
John Rose5eeb8c62005-07-25 10:16:42 -0500258static int dlpar_add_phb(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
260 struct pci_controller *phb;
261
Linas Vepstasfe98aea2005-11-03 18:51:17 -0600262 if (PCI_DN(dn) && PCI_DN(dn)->phb) {
John Rose56d84562005-07-25 10:17:03 -0500263 /* PHB already exists */
264 return -EINVAL;
265 }
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 phb = init_phb_dynamic(dn);
268 if (!phb)
John Rose56d84562005-07-25 10:17:03 -0500269 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
John Rose5eeb8c62005-07-25 10:16:42 -0500271 if (rpaphp_add_slot(dn)) {
272 printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800273 __func__, drc_name);
John Rose5eeb8c62005-07-25 10:16:42 -0500274 return -EIO;
275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return 0;
277}
278
John Rose56d84562005-07-25 10:17:03 -0500279static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn)
280{
281 if (vio_find_node(dn))
282 return -EINVAL;
283
284 if (!vio_register_device_node(dn)) {
285 printk(KERN_ERR
286 "%s: failed to register vio node %s\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800287 __func__, drc_name);
John Rose56d84562005-07-25 10:17:03 -0500288 return -EIO;
289 }
290 return 0;
291}
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293/**
294 * dlpar_add_slot - DLPAR add an I/O Slot
295 * @drc_name: drc-name of newly added slot
296 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800297 * Make the hotplug module and the kernel aware of a newly added I/O Slot.
298 * Return Codes:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 * 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 */
305int dlpar_add_slot(char *drc_name)
306{
307 struct device_node *dn = NULL;
308 int node_type;
John Rose56d84562005-07-25 10:17:03 -0500309 int rc = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800311 if (mutex_lock_interruptible(&rpadlpar_mutex))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 return -ERESTARTSYS;
313
John Rose5eeb8c62005-07-25 10:16:42 -0500314 /* Find newly added node */
315 dn = find_dlpar_node(drc_name, &node_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 if (!dn) {
317 rc = -ENODEV;
318 goto exit;
319 }
320
321 switch (node_type) {
322 case NODE_TYPE_VIO:
John Rose56d84562005-07-25 10:17:03 -0500323 rc = dlpar_add_vio_slot(drc_name, dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 break;
325 case NODE_TYPE_SLOT:
326 rc = dlpar_add_pci_slot(drc_name, dn);
327 break;
328 case NODE_TYPE_PHB:
John Rose5eeb8c62005-07-25 10:16:42 -0500329 rc = dlpar_add_phb(drc_name, dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 }
332
John Rose56d84562005-07-25 10:17:03 -0500333 printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334exit:
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800335 mutex_unlock(&rpadlpar_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 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
Randy Dunlap26e6c662007-11-28 09:04:30 -0800342 * @dn: &device_node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800344 * Remove the kernel and hotplug representations of an I/O Slot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 * Return Codes:
346 * 0 Success
John Rose56d84562005-07-25 10:17:03 -0500347 * -EINVAL Vio dev doesn't exist
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 */
John Rose56d84562005-07-25 10:17:03 -0500349static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
John Rose5eeb8c62005-07-25 10:16:42 -0500351 struct vio_dev *vio_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
John Rose5eeb8c62005-07-25 10:16:42 -0500353 vio_dev = vio_find_node(dn);
John Rose56d84562005-07-25 10:17:03 -0500354 if (!vio_dev)
355 return -EINVAL;
John Rose5eeb8c62005-07-25 10:16:42 -0500356
357 vio_unregister_device(vio_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 return 0;
359}
360
361/**
Randy Dunlap26e6c662007-11-28 09:04:30 -0800362 * dlpar_remove_pci_slot - DLPAR remove a PCI I/O Slot
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 * @drc_name: drc-name of newly added slot
Randy Dunlap26e6c662007-11-28 09:04:30 -0800364 * @dn: &device_node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800366 * Remove the kernel and hotplug representations of a PCI I/O Slot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 * Return Codes:
368 * 0 Success
369 * -ENODEV Not a valid drc_name
370 * -EIO Internal PCI Error
371 */
John Rose56d84562005-07-25 10:17:03 -0500372int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
John Rose56d84562005-07-25 10:17:03 -0500374 struct pci_bus *bus;
375 struct slot *slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
linas@austin.ibm.com01657862006-01-12 18:18:26 -0600377 bus = pcibios_find_pci_bus(dn);
John Rose56d84562005-07-25 10:17:03 -0500378 if (!bus)
379 return -EINVAL;
380
Linas Vepstas8485d1a2007-04-13 15:34:21 -0700381 /* If pci slot is hotplugable, use hotplug to remove it */
382 slot = find_php_slot(dn);
John Rose56d84562005-07-25 10:17:03 -0500383 if (slot) {
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);
John Rose56d84562005-07-25 10:17:03 -0500388 return -EIO;
389 }
Linas Vepstasb5661472007-04-13 15:34:24 -0700390 } else
391 pcibios_remove_pci_devices(bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000393 if (pcibios_unmap_io_space(bus)) {
John Rose9c209c92005-07-25 11:13:38 -0500394 printk(KERN_ERR "%s: failed to unmap bus range\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800395 __func__);
John Rose9c209c92005-07-25 11:13:38 -0500396 return -ERANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 }
John Rose9c209c92005-07-25 11:13:38 -0500398
399 BUG_ON(!bus->self);
400 pci_remove_bus_device(bus->self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 return 0;
402}
403
404/**
405 * dlpar_remove_slot - DLPAR remove an I/O Slot
406 * @drc_name: drc-name of newly added slot
407 *
Randy Dunlap26e6c662007-11-28 09:04:30 -0800408 * Remove the kernel and hotplug representations of an I/O Slot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 * Return Codes:
410 * 0 Success
411 * -ENODEV Not a valid drc_name
412 * -EINVAL Slot already removed
413 * -ERESTARTSYS Signalled before obtaining lock
414 * -EIO Internal Error
415 */
416int dlpar_remove_slot(char *drc_name)
417{
John Rose5eeb8c62005-07-25 10:16:42 -0500418 struct device_node *dn;
John Rose5eeb8c62005-07-25 10:16:42 -0500419 int node_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 int rc = 0;
421
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800422 if (mutex_lock_interruptible(&rpadlpar_mutex))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 return -ERESTARTSYS;
424
John Rose5eeb8c62005-07-25 10:16:42 -0500425 dn = find_dlpar_node(drc_name, &node_type);
426 if (!dn) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 rc = -ENODEV;
428 goto exit;
429 }
430
John Rose56d84562005-07-25 10:17:03 -0500431 switch (node_type) {
432 case NODE_TYPE_VIO:
433 rc = dlpar_remove_vio_slot(drc_name, dn);
434 break;
435 case NODE_TYPE_PHB:
436 rc = dlpar_remove_phb(drc_name, dn);
437 break;
438 case NODE_TYPE_SLOT:
439 rc = dlpar_remove_pci_slot(drc_name, dn);
440 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 }
John Rose56d84562005-07-25 10:17:03 -0500442 printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443exit:
Ingo Molnar14cc3e22006-03-26 01:37:14 -0800444 mutex_unlock(&rpadlpar_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return rc;
446}
447
448static inline int is_dlpar_capable(void)
449{
450 int rc = rtas_token("ibm,configure-connector");
451
452 return (int) (rc != RTAS_UNKNOWN_SERVICE);
453}
454
455int __init rpadlpar_io_init(void)
456{
457 int rc = 0;
458
459 if (!is_dlpar_capable()) {
460 printk(KERN_WARNING "%s: partition not DLPAR capable\n",
Harvey Harrison66bef8c2008-03-03 19:09:46 -0800461 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 return -EPERM;
463 }
464
465 rc = dlpar_sysfs_init();
466 return rc;
467}
468
469void rpadlpar_io_exit(void)
470{
471 dlpar_sysfs_exit();
472 return;
473}
474
475module_init(rpadlpar_io_init);
476module_exit(rpadlpar_io_exit);
477MODULE_LICENSE("GPL");