2 * Interface for Dynamic Logical Partitioning of I/O Slots on
3 * RPA-compliant PPC64 platform.
5 * John Rose <johnrose@austin.ibm.com>
6 * Linda Xie <lxie@us.ibm.com>
10 * Copyright (C) 2003 IBM.
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.
17 #include <linux/init.h>
18 #include <linux/pci.h>
19 #include <asm/pci-bridge.h>
20 #include <asm/semaphore.h>
27 static DECLARE_MUTEX(rpadlpar_sem
);
29 #define DLPAR_MODULE_NAME "rpadlpar_io"
31 #define NODE_TYPE_VIO 1
32 #define NODE_TYPE_SLOT 2
33 #define NODE_TYPE_PHB 3
35 static struct device_node
*find_vio_slot_node(char *drc_name
)
37 struct device_node
*parent
= of_find_node_by_name(NULL
, "vdevice");
38 struct device_node
*dn
= NULL
;
45 while ((dn
= of_get_next_child(parent
, dn
))) {
46 rc
= rpaphp_get_drc_props(dn
, NULL
, &name
, NULL
, NULL
);
47 if ((rc
== 0) && (!strcmp(drc_name
, name
)))
54 /* Find dlpar-capable pci node that contains the specified name and type */
55 static struct device_node
*find_php_slot_pci_node(char *drc_name
,
58 struct device_node
*np
= NULL
;
63 while ((np
= of_find_node_by_type(np
, "pci"))) {
64 rc
= rpaphp_get_drc_props(np
, NULL
, &name
, &type
, NULL
);
66 if (!strcmp(drc_name
, name
) && !strcmp(drc_type
, type
))
73 static struct device_node
*find_dlpar_node(char *drc_name
, int *node_type
)
75 struct device_node
*dn
;
77 dn
= find_php_slot_pci_node(drc_name
, "SLOT");
79 *node_type
= NODE_TYPE_SLOT
;
83 dn
= find_php_slot_pci_node(drc_name
, "PHB");
85 *node_type
= NODE_TYPE_PHB
;
89 dn
= find_vio_slot_node(drc_name
);
91 *node_type
= NODE_TYPE_VIO
;
98 static struct slot
*find_slot(struct device_node
*dn
)
100 struct list_head
*tmp
, *n
;
103 list_for_each_safe(tmp
, n
, &rpaphp_slot_head
) {
104 slot
= list_entry(tmp
, struct slot
, rpaphp_slot_list
);
112 static void rpadlpar_claim_one_bus(struct pci_bus
*b
)
114 struct list_head
*ld
;
115 struct pci_bus
*child_bus
;
117 for (ld
= b
->devices
.next
; ld
!= &b
->devices
; ld
= ld
->next
) {
118 struct pci_dev
*dev
= pci_dev_b(ld
);
121 for (i
= 0; i
< PCI_NUM_RESOURCES
; i
++) {
122 struct resource
*r
= &dev
->resource
[i
];
124 if (r
->parent
|| !r
->start
|| !r
->flags
)
126 rpaphp_claim_resource(dev
, i
);
130 list_for_each_entry(child_bus
, &b
->children
, node
)
131 rpadlpar_claim_one_bus(child_bus
);
134 static int pci_add_secondary_bus(struct device_node
*dn
,
135 struct pci_dev
*bridge_dev
)
137 struct pci_controller
*hose
= dn
->phb
;
138 struct pci_bus
*child
;
141 /* Get busno of downstream bus */
142 pci_read_config_byte(bridge_dev
, PCI_SECONDARY_BUS
, &sec_busno
);
144 /* Allocate and add to children of bridge_dev->bus */
145 child
= pci_add_new_bus(bridge_dev
->bus
, bridge_dev
, sec_busno
);
147 printk(KERN_ERR
"%s: could not add secondary bus\n", __FUNCTION__
);
151 sprintf(child
->name
, "PCI Bus #%02x", child
->number
);
153 /* Fixup subordinate bridge bases and resources */
154 pcibios_fixup_bus(child
);
156 /* Claim new bus resources */
157 rpadlpar_claim_one_bus(bridge_dev
->bus
);
159 if (hose
->last_busno
< child
->number
)
160 hose
->last_busno
= child
->number
;
162 dn
->bussubno
= child
->number
;
164 /* ioremap() for child bus, which may or may not succeed */
165 remap_bus_range(child
);
170 static struct pci_dev
*dlpar_find_new_dev(struct pci_bus
*parent
,
171 struct device_node
*dev_dn
)
173 struct pci_dev
*tmp
= NULL
;
174 struct device_node
*child_dn
;
176 list_for_each_entry(tmp
, &parent
->devices
, bus_list
) {
177 child_dn
= pci_device_to_OF_node(tmp
);
178 if (child_dn
== dev_dn
)
184 static struct pci_dev
*dlpar_pci_add_bus(struct device_node
*dn
)
186 struct pci_controller
*hose
= dn
->phb
;
187 struct pci_dev
*dev
= NULL
;
189 /* Scan phb bus for EADS device, adding new one to bus->devices */
190 if (!pci_scan_single_device(hose
->bus
, dn
->devfn
)) {
191 printk(KERN_ERR
"%s: found no device on bus\n", __FUNCTION__
);
195 /* Add new devices to global lists. Register in proc, sysfs. */
196 pci_bus_add_devices(hose
->bus
);
198 /* Confirm new bridge dev was created */
199 dev
= dlpar_find_new_dev(hose
->bus
, dn
);
201 if (dev
->hdr_type
!= PCI_HEADER_TYPE_BRIDGE
) {
202 printk(KERN_ERR
"%s: unexpected header type %d\n",
203 __FUNCTION__
, dev
->hdr_type
);
207 if (pci_add_secondary_bus(dn
, dev
))
214 static int dlpar_add_pci_slot(char *drc_name
, struct device_node
*dn
)
219 if (rpaphp_find_pci_bus(dn
))
223 dev
= dlpar_pci_add_bus(dn
);
225 printk(KERN_ERR
"%s: unable to add bus %s\n", __FUNCTION__
,
231 rc
= rpaphp_config_pci_adapter(dev
->subordinate
);
233 printk(KERN_ERR
"%s: unable to enable slot %s\n",
234 __FUNCTION__
, drc_name
);
239 /* Add hotplug slot */
240 if (rpaphp_add_slot(dn
)) {
241 printk(KERN_ERR
"%s: unable to add hotplug slot %s\n",
242 __FUNCTION__
, drc_name
);
248 static int dlpar_remove_root_bus(struct pci_controller
*phb
)
250 struct pci_bus
*phb_bus
;
254 if (!(list_empty(&phb_bus
->children
) &&
255 list_empty(&phb_bus
->devices
))) {
259 rc
= pcibios_remove_root_bus(phb
);
263 device_unregister(phb_bus
->bridge
);
264 pci_remove_bus(phb_bus
);
269 static int dlpar_remove_phb(char *drc_name
, struct device_node
*dn
)
274 if (!rpaphp_find_pci_bus(dn
))
277 slot
= find_slot(dn
);
279 /* Remove hotplug slot */
280 if (rpaphp_remove_slot(slot
)) {
282 "%s: unable to remove hotplug slot %s\n",
283 __FUNCTION__
, drc_name
);
289 rc
= dlpar_remove_root_bus(dn
->phb
);
298 static int dlpar_add_phb(char *drc_name
, struct device_node
*dn
)
300 struct pci_controller
*phb
;
303 /* PHB already exists */
307 phb
= init_phb_dynamic(dn
);
311 if (rpaphp_add_slot(dn
)) {
312 printk(KERN_ERR
"%s: unable to add hotplug slot %s\n",
313 __FUNCTION__
, drc_name
);
319 static int dlpar_add_vio_slot(char *drc_name
, struct device_node
*dn
)
321 if (vio_find_node(dn
))
324 if (!vio_register_device_node(dn
)) {
326 "%s: failed to register vio node %s\n",
327 __FUNCTION__
, drc_name
);
334 * dlpar_add_slot - DLPAR add an I/O Slot
335 * @drc_name: drc-name of newly added slot
337 * Make the hotplug module and the kernel aware
338 * of a newly added I/O Slot.
341 * -ENODEV Not a valid drc_name
342 * -EINVAL Slot already added
343 * -ERESTARTSYS Signalled before obtaining lock
344 * -EIO Internal PCI Error
346 int dlpar_add_slot(char *drc_name
)
348 struct device_node
*dn
= NULL
;
352 if (down_interruptible(&rpadlpar_sem
))
355 /* Find newly added node */
356 dn
= find_dlpar_node(drc_name
, &node_type
);
364 rc
= dlpar_add_vio_slot(drc_name
, dn
);
367 rc
= dlpar_add_pci_slot(drc_name
, dn
);
370 rc
= dlpar_add_phb(drc_name
, dn
);
374 printk(KERN_INFO
"%s: slot %s added\n", DLPAR_MODULE_NAME
, drc_name
);
381 * dlpar_remove_vio_slot - DLPAR remove a virtual I/O Slot
382 * @drc_name: drc-name of newly added slot
384 * Remove the kernel and hotplug representations
388 * -EINVAL Vio dev doesn't exist
390 static int dlpar_remove_vio_slot(char *drc_name
, struct device_node
*dn
)
392 struct vio_dev
*vio_dev
;
394 vio_dev
= vio_find_node(dn
);
398 vio_unregister_device(vio_dev
);
403 * dlpar_remove_slot - DLPAR remove a PCI I/O Slot
404 * @drc_name: drc-name of newly added slot
406 * Remove the kernel and hotplug representations
410 * -ENODEV Not a valid drc_name
411 * -EIO Internal PCI Error
413 int dlpar_remove_pci_slot(char *drc_name
, struct device_node
*dn
)
418 bus
= rpaphp_find_pci_bus(dn
);
422 slot
= find_slot(dn
);
424 /* Remove hotplug slot */
425 if (rpaphp_remove_slot(slot
)) {
427 "%s: unable to remove hotplug slot %s\n",
428 __FUNCTION__
, drc_name
);
433 if (unmap_bus_range(bus
)) {
434 printk(KERN_ERR
"%s: failed to unmap bus range\n",
440 pci_remove_bus_device(bus
->self
);
445 * dlpar_remove_slot - DLPAR remove an I/O Slot
446 * @drc_name: drc-name of newly added slot
448 * Remove the kernel and hotplug representations
452 * -ENODEV Not a valid drc_name
453 * -EINVAL Slot already removed
454 * -ERESTARTSYS Signalled before obtaining lock
455 * -EIO Internal Error
457 int dlpar_remove_slot(char *drc_name
)
459 struct device_node
*dn
;
463 if (down_interruptible(&rpadlpar_sem
))
466 dn
= find_dlpar_node(drc_name
, &node_type
);
474 rc
= dlpar_remove_vio_slot(drc_name
, dn
);
477 rc
= dlpar_remove_phb(drc_name
, dn
);
480 rc
= dlpar_remove_pci_slot(drc_name
, dn
);
483 printk(KERN_INFO
"%s: slot %s removed\n", DLPAR_MODULE_NAME
, drc_name
);
489 static inline int is_dlpar_capable(void)
491 int rc
= rtas_token("ibm,configure-connector");
493 return (int) (rc
!= RTAS_UNKNOWN_SERVICE
);
496 int __init
rpadlpar_io_init(void)
500 if (!is_dlpar_capable()) {
501 printk(KERN_WARNING
"%s: partition not DLPAR capable\n",
506 rc
= dlpar_sysfs_init();
510 void rpadlpar_io_exit(void)
516 module_init(rpadlpar_io_init
);
517 module_exit(rpadlpar_io_exit
);
518 MODULE_LICENSE("GPL");
This page took 0.040601 seconds and 6 git commands to generate.