Loading...
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
18#undef DEBUG
19
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/pci.h>
23#include <linux/string.h>
24#include <linux/vmalloc.h>
25
26#include <asm/pci-bridge.h>
27#include <linux/mutex.h>
28#include <asm/rtas.h>
29#include <asm/vio.h>
30
31#include "../pci.h"
32#include "rpaphp.h"
33#include "rpadlpar.h"
34
35static DEFINE_MUTEX(rpadlpar_mutex);
36
37#define DLPAR_MODULE_NAME "rpadlpar_io"
38
39#define NODE_TYPE_VIO 1
40#define NODE_TYPE_SLOT 2
41#define NODE_TYPE_PHB 3
42
43static struct device_node *find_vio_slot_node(char *drc_name)
44{
45 struct device_node *parent = of_find_node_by_name(NULL, "vdevice");
46 struct device_node *dn = NULL;
47 char *name;
48 int rc;
49
50 if (!parent)
51 return NULL;
52
53 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;
57 }
58
59 return dn;
60}
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
71 while ((np = of_find_node_by_name(np, "pci"))) {
72 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
81static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
82{
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
97 dn = find_vio_slot_node(drc_name);
98 if (dn) {
99 *node_type = NODE_TYPE_VIO;
100 return dn;
101 }
102
103 return NULL;
104}
105
106/**
107 * find_php_slot - return hotplug slot structure for device node
108 * @dn: target &device_node
109 *
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)
116{
117 struct list_head *tmp, *n;
118 struct slot *slot;
119
120 list_for_each_safe(tmp, n, &rpaphp_slot_head) {
121 slot = list_entry(tmp, struct slot, rpaphp_slot_list);
122 if (slot->dn == dn)
123 return slot;
124 }
125
126 return NULL;
127}
128
129static struct pci_dev *dlpar_find_new_dev(struct pci_bus *parent,
130 struct device_node *dev_dn)
131{
132 struct pci_dev *tmp = NULL;
133 struct device_node *child_dn;
134
135 list_for_each_entry(tmp, &parent->devices, bus_list) {
136 child_dn = pci_device_to_OF_node(tmp);
137 if (child_dn == dev_dn)
138 return tmp;
139 }
140 return NULL;
141}
142
143static void dlpar_pci_add_bus(struct device_node *dn)
144{
145 struct pci_dn *pdn = PCI_DN(dn);
146 struct pci_controller *phb = pdn->phb;
147 struct pci_dev *dev = NULL;
148
149 eeh_add_device_tree_early(dn);
150
151 /* Add EADS device to PHB bus, adding new entry to bus->devices */
152 dev = of_create_pci_dev(dn, phb->bus, pdn->devfn);
153 if (!dev) {
154 printk(KERN_ERR "%s: failed to create pci dev for %s\n",
155 __func__, dn->full_name);
156 return;
157 }
158
159 /* Scan below the new bridge */
160 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
161 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
162 of_scan_pci_bridge(dev);
163
164 /* Map IO space for child bus, which may or may not succeed */
165 pcibios_map_io_space(dev->subordinate);
166
167 /* 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);
173}
174
175static int dlpar_add_pci_slot(char *drc_name, struct device_node *dn)
176{
177 struct pci_dev *dev;
178 struct pci_controller *phb;
179
180 if (pcibios_find_pci_bus(dn))
181 return -EINVAL;
182
183 /* Add pci bus */
184 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
190 if (!dev) {
191 printk(KERN_ERR "%s: unable to add bus %s\n", __func__,
192 drc_name);
193 return -EIO;
194 }
195
196 if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
197 printk(KERN_ERR "%s: unexpected header type %d, unable to add bus %s\n",
198 __func__, dev->hdr_type, drc_name);
199 return -EIO;
200 }
201
202 /* Add hotplug slot */
203 if (rpaphp_add_slot(dn)) {
204 printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
205 __func__, drc_name);
206 return -EIO;
207 }
208 return 0;
209}
210
211static int dlpar_remove_phb(char *drc_name, struct device_node *dn)
212{
213 struct slot *slot;
214 struct pci_dn *pdn;
215 int rc = 0;
216
217 if (!pcibios_find_pci_bus(dn))
218 return -EINVAL;
219
220 /* If pci slot is hotplugable, use hotplug to remove it */
221 slot = find_php_slot(dn);
222 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;
226 }
227
228 pdn = dn->data;
229 BUG_ON(!pdn || !pdn->phb);
230 rc = remove_phb_dynamic(pdn->phb);
231 if (rc < 0)
232 return rc;
233
234 pdn->phb = NULL;
235
236 return 0;
237}
238
239static int dlpar_add_phb(char *drc_name, struct device_node *dn)
240{
241 struct pci_controller *phb;
242
243 if (PCI_DN(dn) && PCI_DN(dn)->phb) {
244 /* PHB already exists */
245 return -EINVAL;
246 }
247
248 phb = init_phb_dynamic(dn);
249 if (!phb)
250 return -EIO;
251
252 if (rpaphp_add_slot(dn)) {
253 printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
254 __func__, drc_name);
255 return -EIO;
256 }
257 return 0;
258}
259
260static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn)
261{
262 if (vio_find_node(dn))
263 return -EINVAL;
264
265 if (!vio_register_device_node(dn)) {
266 printk(KERN_ERR
267 "%s: failed to register vio node %s\n",
268 __func__, drc_name);
269 return -EIO;
270 }
271 return 0;
272}
273
274/**
275 * dlpar_add_slot - DLPAR add an I/O Slot
276 * @drc_name: drc-name of newly added slot
277 *
278 * Make the hotplug module and the kernel aware of a newly added I/O Slot.
279 * Return Codes:
280 * 0 Success
281 * -ENODEV Not a valid drc_name
282 * -EINVAL Slot already added
283 * -ERESTARTSYS Signalled before obtaining lock
284 * -EIO Internal PCI Error
285 */
286int dlpar_add_slot(char *drc_name)
287{
288 struct device_node *dn = NULL;
289 int node_type;
290 int rc = -EIO;
291
292 if (mutex_lock_interruptible(&rpadlpar_mutex))
293 return -ERESTARTSYS;
294
295 /* Find newly added node */
296 dn = find_dlpar_node(drc_name, &node_type);
297 if (!dn) {
298 rc = -ENODEV;
299 goto exit;
300 }
301
302 switch (node_type) {
303 case NODE_TYPE_VIO:
304 rc = dlpar_add_vio_slot(drc_name, dn);
305 break;
306 case NODE_TYPE_SLOT:
307 rc = dlpar_add_pci_slot(drc_name, dn);
308 break;
309 case NODE_TYPE_PHB:
310 rc = dlpar_add_phb(drc_name, dn);
311 break;
312 }
313
314 printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name);
315exit:
316 mutex_unlock(&rpadlpar_mutex);
317 return rc;
318}
319
320/**
321 * dlpar_remove_vio_slot - DLPAR remove a virtual I/O Slot
322 * @drc_name: drc-name of newly added slot
323 * @dn: &device_node
324 *
325 * Remove the kernel and hotplug representations of an I/O Slot.
326 * Return Codes:
327 * 0 Success
328 * -EINVAL Vio dev doesn't exist
329 */
330static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn)
331{
332 struct vio_dev *vio_dev;
333
334 vio_dev = vio_find_node(dn);
335 if (!vio_dev)
336 return -EINVAL;
337
338 vio_unregister_device(vio_dev);
339 return 0;
340}
341
342/**
343 * dlpar_remove_pci_slot - DLPAR remove a PCI I/O Slot
344 * @drc_name: drc-name of newly added slot
345 * @dn: &device_node
346 *
347 * Remove the kernel and hotplug representations of a PCI I/O Slot.
348 * Return Codes:
349 * 0 Success
350 * -ENODEV Not a valid drc_name
351 * -EIO Internal PCI Error
352 */
353int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn)
354{
355 struct pci_bus *bus;
356 struct slot *slot;
357
358 bus = pcibios_find_pci_bus(dn);
359 if (!bus)
360 return -EINVAL;
361
362 pr_debug("PCI: Removing PCI slot below EADS bridge %s\n",
363 bus->self ? pci_name(bus->self) : "<!PHB!>");
364
365 slot = find_php_slot(dn);
366 if (slot) {
367 pr_debug("PCI: Removing hotplug slot for %04x:%02x...\n",
368 pci_domain_nr(bus), bus->number);
369
370 if (rpaphp_deregister_slot(slot)) {
371 printk(KERN_ERR
372 "%s: unable to remove hotplug slot %s\n",
373 __func__, drc_name);
374 return -EIO;
375 }
376 }
377
378 /* Remove all devices below slot */
379 pcibios_remove_pci_devices(bus);
380
381 /* Unmap PCI IO space */
382 if (pcibios_unmap_io_space(bus)) {
383 printk(KERN_ERR "%s: failed to unmap bus range\n",
384 __func__);
385 return -ERANGE;
386 }
387
388 /* Remove the EADS bridge device itself */
389 BUG_ON(!bus->self);
390 pr_debug("PCI: Now removing bridge device %s\n", pci_name(bus->self));
391 eeh_remove_bus_device(bus->self);
392 pci_stop_and_remove_bus_device(bus->self);
393
394 return 0;
395}
396
397/**
398 * dlpar_remove_slot - DLPAR remove an I/O Slot
399 * @drc_name: drc-name of newly added slot
400 *
401 * Remove the kernel and hotplug representations of an I/O Slot.
402 * Return Codes:
403 * 0 Success
404 * -ENODEV Not a valid drc_name
405 * -EINVAL Slot already removed
406 * -ERESTARTSYS Signalled before obtaining lock
407 * -EIO Internal Error
408 */
409int dlpar_remove_slot(char *drc_name)
410{
411 struct device_node *dn;
412 int node_type;
413 int rc = 0;
414
415 if (mutex_lock_interruptible(&rpadlpar_mutex))
416 return -ERESTARTSYS;
417
418 dn = find_dlpar_node(drc_name, &node_type);
419 if (!dn) {
420 rc = -ENODEV;
421 goto exit;
422 }
423
424 switch (node_type) {
425 case NODE_TYPE_VIO:
426 rc = dlpar_remove_vio_slot(drc_name, dn);
427 break;
428 case NODE_TYPE_PHB:
429 rc = dlpar_remove_phb(drc_name, dn);
430 break;
431 case NODE_TYPE_SLOT:
432 rc = dlpar_remove_pci_slot(drc_name, dn);
433 break;
434 }
435 vm_unmap_aliases();
436
437 printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name);
438exit:
439 mutex_unlock(&rpadlpar_mutex);
440 return rc;
441}
442
443static inline int is_dlpar_capable(void)
444{
445 int rc = rtas_token("ibm,configure-connector");
446
447 return (int) (rc != RTAS_UNKNOWN_SERVICE);
448}
449
450int __init rpadlpar_io_init(void)
451{
452 int rc = 0;
453
454 if (!is_dlpar_capable()) {
455 printk(KERN_WARNING "%s: partition not DLPAR capable\n",
456 __func__);
457 return -EPERM;
458 }
459
460 rc = dlpar_sysfs_init();
461 return rc;
462}
463
464void rpadlpar_io_exit(void)
465{
466 dlpar_sysfs_exit();
467 return;
468}
469
470module_init(rpadlpar_io_init);
471module_exit(rpadlpar_io_exit);
472MODULE_LICENSE("GPL");
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
18#undef DEBUG
19
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/pci.h>
23#include <linux/string.h>
24#include <linux/vmalloc.h>
25
26#include <asm/pci-bridge.h>
27#include <linux/mutex.h>
28#include <asm/rtas.h>
29#include <asm/vio.h>
30
31#include "../pci.h"
32#include "rpaphp.h"
33#include "rpadlpar.h"
34
35static DEFINE_MUTEX(rpadlpar_mutex);
36
37#define DLPAR_MODULE_NAME "rpadlpar_io"
38
39#define NODE_TYPE_VIO 1
40#define NODE_TYPE_SLOT 2
41#define NODE_TYPE_PHB 3
42
43static struct device_node *find_vio_slot_node(char *drc_name)
44{
45 struct device_node *parent = of_find_node_by_name(NULL, "vdevice");
46 struct device_node *dn = NULL;
47 char *name;
48 int rc;
49
50 if (!parent)
51 return NULL;
52
53 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;
57 }
58
59 return dn;
60}
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
71 while ((np = of_find_node_by_name(np, "pci"))) {
72 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
81static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
82{
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
97 dn = find_vio_slot_node(drc_name);
98 if (dn) {
99 *node_type = NODE_TYPE_VIO;
100 return dn;
101 }
102
103 return NULL;
104}
105
106/**
107 * find_php_slot - return hotplug slot structure for device node
108 * @dn: target &device_node
109 *
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)
116{
117 struct slot *slot, *next;
118
119 list_for_each_entry_safe(slot, next, &rpaphp_slot_head,
120 rpaphp_slot_list) {
121 if (slot->dn == dn)
122 return slot;
123 }
124
125 return NULL;
126}
127
128static 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
142static void dlpar_pci_add_bus(struct device_node *dn)
143{
144 struct pci_dn *pdn = PCI_DN(dn);
145 struct pci_controller *phb = pdn->phb;
146 struct pci_dev *dev = NULL;
147
148 eeh_add_device_tree_early(pdn);
149
150 /* 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",
154 __func__, dn->full_name);
155 return;
156 }
157
158 /* Scan below the new bridge */
159 if (pci_is_bridge(dev))
160 of_scan_pci_bridge(dev);
161
162 /* Map IO space for child bus, which may or may not succeed */
163 pcibios_map_io_space(dev->subordinate);
164
165 /* 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);
171}
172
173static int dlpar_add_pci_slot(char *drc_name, struct device_node *dn)
174{
175 struct pci_dev *dev;
176 struct pci_controller *phb;
177
178 if (pcibios_find_pci_bus(dn))
179 return -EINVAL;
180
181 /* Add pci bus */
182 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
188 if (!dev) {
189 printk(KERN_ERR "%s: unable to add bus %s\n", __func__,
190 drc_name);
191 return -EIO;
192 }
193
194 if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
195 printk(KERN_ERR "%s: unexpected header type %d, unable to add bus %s\n",
196 __func__, dev->hdr_type, drc_name);
197 return -EIO;
198 }
199
200 /* Add hotplug slot */
201 if (rpaphp_add_slot(dn)) {
202 printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
203 __func__, drc_name);
204 return -EIO;
205 }
206 return 0;
207}
208
209static int dlpar_remove_phb(char *drc_name, struct device_node *dn)
210{
211 struct slot *slot;
212 struct pci_dn *pdn;
213 int rc = 0;
214
215 if (!pcibios_find_pci_bus(dn))
216 return -EINVAL;
217
218 /* If pci slot is hotpluggable, use hotplug to remove it */
219 slot = find_php_slot(dn);
220 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;
224 }
225
226 pdn = dn->data;
227 BUG_ON(!pdn || !pdn->phb);
228 rc = remove_phb_dynamic(pdn->phb);
229 if (rc < 0)
230 return rc;
231
232 pdn->phb = NULL;
233
234 return 0;
235}
236
237static int dlpar_add_phb(char *drc_name, struct device_node *dn)
238{
239 struct pci_controller *phb;
240
241 if (PCI_DN(dn) && PCI_DN(dn)->phb) {
242 /* PHB already exists */
243 return -EINVAL;
244 }
245
246 phb = init_phb_dynamic(dn);
247 if (!phb)
248 return -EIO;
249
250 if (rpaphp_add_slot(dn)) {
251 printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
252 __func__, drc_name);
253 return -EIO;
254 }
255 return 0;
256}
257
258static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn)
259{
260 if (vio_find_node(dn))
261 return -EINVAL;
262
263 if (!vio_register_device_node(dn)) {
264 printk(KERN_ERR
265 "%s: failed to register vio node %s\n",
266 __func__, drc_name);
267 return -EIO;
268 }
269 return 0;
270}
271
272/**
273 * dlpar_add_slot - DLPAR add an I/O Slot
274 * @drc_name: drc-name of newly added slot
275 *
276 * Make the hotplug module and the kernel aware of a newly added I/O Slot.
277 * Return Codes:
278 * 0 Success
279 * -ENODEV Not a valid drc_name
280 * -EINVAL Slot already added
281 * -ERESTARTSYS Signalled before obtaining lock
282 * -EIO Internal PCI Error
283 */
284int dlpar_add_slot(char *drc_name)
285{
286 struct device_node *dn = NULL;
287 int node_type;
288 int rc = -EIO;
289
290 if (mutex_lock_interruptible(&rpadlpar_mutex))
291 return -ERESTARTSYS;
292
293 /* Find newly added node */
294 dn = find_dlpar_node(drc_name, &node_type);
295 if (!dn) {
296 rc = -ENODEV;
297 goto exit;
298 }
299
300 switch (node_type) {
301 case NODE_TYPE_VIO:
302 rc = dlpar_add_vio_slot(drc_name, dn);
303 break;
304 case NODE_TYPE_SLOT:
305 rc = dlpar_add_pci_slot(drc_name, dn);
306 break;
307 case NODE_TYPE_PHB:
308 rc = dlpar_add_phb(drc_name, dn);
309 break;
310 }
311
312 printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name);
313exit:
314 mutex_unlock(&rpadlpar_mutex);
315 return rc;
316}
317
318/**
319 * dlpar_remove_vio_slot - DLPAR remove a virtual I/O Slot
320 * @drc_name: drc-name of newly added slot
321 * @dn: &device_node
322 *
323 * Remove the kernel and hotplug representations of an I/O Slot.
324 * Return Codes:
325 * 0 Success
326 * -EINVAL Vio dev doesn't exist
327 */
328static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn)
329{
330 struct vio_dev *vio_dev;
331
332 vio_dev = vio_find_node(dn);
333 if (!vio_dev)
334 return -EINVAL;
335
336 vio_unregister_device(vio_dev);
337 return 0;
338}
339
340/**
341 * dlpar_remove_pci_slot - DLPAR remove a PCI I/O Slot
342 * @drc_name: drc-name of newly added slot
343 * @dn: &device_node
344 *
345 * Remove the kernel and hotplug representations of a PCI I/O Slot.
346 * Return Codes:
347 * 0 Success
348 * -ENODEV Not a valid drc_name
349 * -EIO Internal PCI Error
350 */
351int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn)
352{
353 struct pci_bus *bus;
354 struct slot *slot;
355 int ret = 0;
356
357 pci_lock_rescan_remove();
358
359 bus = pcibios_find_pci_bus(dn);
360 if (!bus) {
361 ret = -EINVAL;
362 goto out;
363 }
364
365 pr_debug("PCI: Removing PCI slot below EADS bridge %s\n",
366 bus->self ? pci_name(bus->self) : "<!PHB!>");
367
368 slot = find_php_slot(dn);
369 if (slot) {
370 pr_debug("PCI: Removing hotplug slot for %04x:%02x...\n",
371 pci_domain_nr(bus), bus->number);
372
373 if (rpaphp_deregister_slot(slot)) {
374 printk(KERN_ERR
375 "%s: unable to remove hotplug slot %s\n",
376 __func__, drc_name);
377 ret = -EIO;
378 goto out;
379 }
380 }
381
382 /* Remove all devices below slot */
383 pcibios_remove_pci_devices(bus);
384
385 /* Unmap PCI IO space */
386 if (pcibios_unmap_io_space(bus)) {
387 printk(KERN_ERR "%s: failed to unmap bus range\n",
388 __func__);
389 ret = -ERANGE;
390 goto out;
391 }
392
393 /* Remove the EADS bridge device itself */
394 BUG_ON(!bus->self);
395 pr_debug("PCI: Now removing bridge device %s\n", pci_name(bus->self));
396 pci_stop_and_remove_bus_device(bus->self);
397
398 out:
399 pci_unlock_rescan_remove();
400 return ret;
401}
402
403/**
404 * dlpar_remove_slot - DLPAR remove an I/O Slot
405 * @drc_name: drc-name of newly added slot
406 *
407 * Remove the kernel and hotplug representations of an I/O Slot.
408 * Return Codes:
409 * 0 Success
410 * -ENODEV Not a valid drc_name
411 * -EINVAL Slot already removed
412 * -ERESTARTSYS Signalled before obtaining lock
413 * -EIO Internal Error
414 */
415int dlpar_remove_slot(char *drc_name)
416{
417 struct device_node *dn;
418 int node_type;
419 int rc = 0;
420
421 if (mutex_lock_interruptible(&rpadlpar_mutex))
422 return -ERESTARTSYS;
423
424 dn = find_dlpar_node(drc_name, &node_type);
425 if (!dn) {
426 rc = -ENODEV;
427 goto exit;
428 }
429
430 switch (node_type) {
431 case NODE_TYPE_VIO:
432 rc = dlpar_remove_vio_slot(drc_name, dn);
433 break;
434 case NODE_TYPE_PHB:
435 rc = dlpar_remove_phb(drc_name, dn);
436 break;
437 case NODE_TYPE_SLOT:
438 rc = dlpar_remove_pci_slot(drc_name, dn);
439 break;
440 }
441 vm_unmap_aliases();
442
443 printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name);
444exit:
445 mutex_unlock(&rpadlpar_mutex);
446 return rc;
447}
448
449static inline int is_dlpar_capable(void)
450{
451 int rc = rtas_token("ibm,configure-connector");
452
453 return (int) (rc != RTAS_UNKNOWN_SERVICE);
454}
455
456int __init rpadlpar_io_init(void)
457{
458 int rc = 0;
459
460 if (!is_dlpar_capable()) {
461 printk(KERN_WARNING "%s: partition not DLPAR capable\n",
462 __func__);
463 return -EPERM;
464 }
465
466 rc = dlpar_sysfs_init();
467 return rc;
468}
469
470void rpadlpar_io_exit(void)
471{
472 dlpar_sysfs_exit();
473 return;
474}
475
476module_init(rpadlpar_io_init);
477module_exit(rpadlpar_io_exit);
478MODULE_LICENSE("GPL");