2 * PCI Hot Plug Controller Driver for RPA-compliant PPC64 platform.
3 * Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
15 * NON INFRINGEMENT. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Send feedback to <lxie@us.ibm.com>
25 #include <linux/config.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/moduleparam.h>
29 #include <linux/pci.h>
30 #include <linux/slab.h>
31 #include <linux/smp.h>
32 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <asm/eeh.h> /* for eeh_add_device() */
35 #include <asm/rtas.h> /* rtas_call */
36 #include <asm/pci-bridge.h> /* for pci_controller */
37 #include "../pci.h" /* for pci_add_new_bus */
38 /* and pci_do_scan_bus */
40 #include "pci_hotplug.h"
43 static struct semaphore rpaphp_sem;
44 LIST_HEAD(rpaphp_slot_head);
47 #define DRIVER_VERSION "0.1"
48 #define DRIVER_AUTHOR "Linda Xie <lxie@us.ibm.com>"
49 #define DRIVER_DESC "RPA HOT Plug PCI Controller Driver"
51 #define MAX_LOC_CODE 128
53 MODULE_AUTHOR(DRIVER_AUTHOR);
54 MODULE_DESCRIPTION(DRIVER_DESC);
55 MODULE_LICENSE("GPL");
57 module_param(debug, int, 0644);
59 static int enable_slot(struct hotplug_slot *slot);
60 static int disable_slot(struct hotplug_slot *slot);
61 static int set_attention_status(struct hotplug_slot *slot, u8 value);
62 static int get_power_status(struct hotplug_slot *slot, u8 * value);
63 static int get_attention_status(struct hotplug_slot *slot, u8 * value);
64 static int get_adapter_status(struct hotplug_slot *slot, u8 * value);
65 static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value);
66 static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value);
68 struct hotplug_slot_ops rpaphp_hotplug_slot_ops = {
70 .enable_slot = enable_slot,
71 .disable_slot = disable_slot,
72 .set_attention_status = set_attention_status,
73 .get_power_status = get_power_status,
74 .get_attention_status = get_attention_status,
75 .get_adapter_status = get_adapter_status,
76 .get_max_bus_speed = get_max_bus_speed,
77 .get_cur_bus_speed = get_cur_bus_speed,
80 static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function)
83 dbg("%s - hotplug_slot == NULL\n", function);
86 return (struct slot *)hotplug_slot->private;
89 static int rpaphp_get_attention_status(struct slot *slot)
91 return slot->hotplug_slot->info->attention_status;
95 * set_attention_status - set attention LED
96 * echo 0 > attention -- set LED OFF
97 * echo 1 > attention -- set LED ON
98 * echo 2 > attention -- set LED ID(identify, light is blinking)
101 static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value)
104 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
112 retval = rpaphp_set_attention_status(slot, LED_OFF);
113 hotplug_slot->info->attention_status = 0;
117 retval = rpaphp_set_attention_status(slot, LED_ON);
118 hotplug_slot->info->attention_status = 1;
121 retval = rpaphp_set_attention_status(slot, LED_ID);
122 hotplug_slot->info->attention_status = 2;
130 * get_power_status - get power status of a slot
131 * @hotplug_slot: slot to get status
132 * @value: pointer to store status
136 static int get_power_status(struct hotplug_slot *hotplug_slot, u8 * value)
139 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
145 retval = rpaphp_get_power_status(slot, value);
151 * get_attention_status - get attention LED status
155 static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 * value)
158 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
164 *value = rpaphp_get_attention_status(slot);
169 static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 * value)
171 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
177 /* have to go through this */
178 switch (slot->dev_type) {
180 retval = rpaphp_get_pci_adapter_status(slot, 0, value);
183 retval = rpaphp_get_vio_adapter_status(slot, 0, value);
192 static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
194 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
200 switch (slot->type) {
207 *value = PCI_SPEED_33MHz; /* speed for case 1-6 */
211 *value = PCI_SPEED_66MHz;
215 *value = PCI_SPEED_66MHz_PCIX;
219 *value = PCI_SPEED_100MHz_PCIX;
223 *value = PCI_SPEED_133MHz_PCIX;
226 *value = PCI_SPEED_UNKNOWN;
234 /* return dummy value because not sure if PRA provides any method... */
235 static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
237 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
242 *value = PCI_SPEED_UNKNOWN;
246 int rpaphp_remove_slot(struct slot *slot)
249 struct hotplug_slot *php_slot = slot->hotplug_slot;
251 list_del(&slot->rpaphp_slot_list);
253 /* remove "php_location" file */
254 rpaphp_sysfs_remove_attr_location(php_slot);
256 retval = pci_hp_deregister(php_slot);
258 err("Problem unregistering a slot %s\n", slot->name);
262 dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
266 static int is_php_dn(struct device_node *dn, int **indexes, int **names, int **types,
269 *indexes = (int *) get_property(dn, "ibm,drc-indexes", NULL);
272 /* &names[1] contains NULL terminated slot names */
273 *names = (int *) get_property(dn, "ibm,drc-names", NULL);
276 /* &types[1] contains NULL terminated slot types */
277 *types = (int *) get_property(dn, "ibm,drc-types", NULL);
280 /* power_domains[1...n] are the slot power domains */
281 *power_domains = (int *) get_property(dn,
282 "ibm,drc-power-domains", NULL);
285 if (strcmp(dn->name, "pci") == 0 &&
286 !get_property(dn, "ibm,fw-pci-hot-plug-ctrl", NULL))
291 static inline int is_vdevice_root(struct device_node *dn)
293 return !strcmp(dn->name, "vdevice");
296 /*************************************
297 * Add Hot Plug slot(s) to sysfs
299 ************************************/
300 int rpaphp_add_slot(struct device_node *dn)
305 int *indexes, *names, *types, *power_domains;
308 dbg("Entry %s: dn->full_name=%s\n", __FUNCTION__, dn->full_name);
310 if (dn->parent && is_vdevice_root(dn->parent)) {
311 /* register a VIO device */
312 retval = register_vio_slot(dn);
316 /* register PCI devices */
317 if (dn->name != 0 && strcmp(dn->name, "pci") == 0 &&
318 is_php_dn(dn, &indexes, &names, &types, &power_domains)) {
320 name = (char *) &names[1];
321 type = (char *) &types[1];
322 for (i = 0; i < indexes[0];
324 name += (strlen(name) + 1), type += (strlen(type) + 1)) {
325 if (!(slot = alloc_slot_struct(dn, indexes[i + 1], name,
326 power_domains[i + 1]))) {
330 slot->type = simple_strtoul(type, NULL, 10);
331 if (slot->type < 1 || slot->type > 16)
333 retval = register_pci_slot(slot);
336 } /* end of PCI device_node */
338 dbg("%s - Exit: num_slots=%d rc[%d]\n",
339 __FUNCTION__, num_slots, retval);
344 * init_slots - initialize 'struct slot' structures for each slot
347 static void init_slots(void)
349 struct device_node *dn;
351 for (dn = find_all_nodes(); dn; dn = dn->next)
355 static int init_rpa(void)
358 init_MUTEX(&rpaphp_sem);
360 /* initialize internal data structure etc. */
368 static void cleanup_slots(void)
370 struct list_head *tmp, *n;
374 * Unregister all of our slots with the pci_hotplug subsystem,
375 * and free up all memory that we had allocated.
376 * memory will be freed in release_slot callback.
379 list_for_each_safe(tmp, n, &rpaphp_slot_head) {
380 slot = list_entry(tmp, struct slot, rpaphp_slot_list);
381 list_del(&slot->rpaphp_slot_list);
382 pci_hp_deregister(slot->hotplug_slot);
387 static int __init rpaphp_init(void)
389 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
391 /* read all the PRA info from the system */
395 static void __exit rpaphp_exit(void)
400 static int enable_slot(struct hotplug_slot *hotplug_slot)
403 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
408 if (slot->state == CONFIGURED) {
409 dbg("%s: %s is already enabled\n", __FUNCTION__, slot->name);
413 dbg("ENABLING SLOT %s\n", slot->name);
415 switch (slot->dev_type) {
417 retval = rpaphp_enable_pci_slot(slot);
420 retval = rpaphp_enable_vio_slot(slot);
427 dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
431 static int disable_slot(struct hotplug_slot *hotplug_slot)
434 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
439 dbg("%s - Entry: slot[%s]\n", __FUNCTION__, slot->name);
441 if (slot->state == NOT_CONFIGURED) {
442 dbg("%s: %s is already disabled\n", __FUNCTION__, slot->name);
446 dbg("DISABLING SLOT %s\n", slot->name);
448 switch (slot->dev_type) {
450 rpaphp_set_attention_status(slot, LED_ID);
451 retval = rpaphp_unconfig_pci_adapter(slot);
452 rpaphp_set_attention_status(slot, LED_OFF);
455 retval = rpaphp_unconfig_vio_adapter(slot);
462 dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
466 module_init(rpaphp_init);
467 module_exit(rpaphp_exit);
469 EXPORT_SYMBOL_GPL(rpaphp_add_slot);
470 EXPORT_SYMBOL_GPL(rpaphp_remove_slot);
471 EXPORT_SYMBOL_GPL(rpaphp_slot_head);