| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * This file is subject to the terms and conditions of the GNU General Public | 
|  | 3 | * License.  See the file "COPYING" in the main directory of this archive | 
|  | 4 | * for more details. | 
|  | 5 | * | 
| John Keller | 8e77af6 | 2006-03-08 13:21:34 -0600 | [diff] [blame] | 6 | * Copyright (C) 2005-2006 Silicon Graphics, Inc. All rights reserved. | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 7 | * | 
|  | 8 | * This work was based on the 2.4/2.6 kernel development by Dick Reigner. | 
|  | 9 | * Work to add BIOS PROM support was completed by Mike Habeck. | 
|  | 10 | */ | 
|  | 11 |  | 
|  | 12 | #include <linux/init.h> | 
|  | 13 | #include <linux/kernel.h> | 
|  | 14 | #include <linux/module.h> | 
|  | 15 | #include <linux/pci.h> | 
| Greg Kroah-Hartman | 7a54f25 | 2006-10-13 20:05:19 -0700 | [diff] [blame] | 16 | #include <linux/pci_hotplug.h> | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 17 | #include <linux/proc_fs.h> | 
|  | 18 | #include <linux/types.h> | 
| Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 19 | #include <linux/mutex.h> | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 20 |  | 
|  | 21 | #include <asm/sn/addrs.h> | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 22 | #include <asm/sn/geo.h> | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 23 | #include <asm/sn/l1.h> | 
|  | 24 | #include <asm/sn/module.h> | 
|  | 25 | #include <asm/sn/pcibr_provider.h> | 
|  | 26 | #include <asm/sn/pcibus_provider_defs.h> | 
|  | 27 | #include <asm/sn/pcidev.h> | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 28 | #include <asm/sn/sn_feature_sets.h> | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 29 | #include <asm/sn/sn_sal.h> | 
|  | 30 | #include <asm/sn/types.h> | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 31 | #include <linux/acpi.h> | 
|  | 32 | #include <asm/sn/acpi.h> | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 33 |  | 
|  | 34 | #include "../pci.h" | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 35 |  | 
|  | 36 | MODULE_LICENSE("GPL"); | 
|  | 37 | MODULE_AUTHOR("SGI (prarit@sgi.com, dickie@sgi.com, habeck@sgi.com)"); | 
|  | 38 | MODULE_DESCRIPTION("SGI Altix Hot Plug PCI Controller Driver"); | 
|  | 39 |  | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 40 |  | 
|  | 41 | /* SAL call error codes. Keep in sync with prom header io/include/pcibr.h */ | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 42 | #define PCI_SLOT_ALREADY_UP		2	/* slot already up */ | 
|  | 43 | #define PCI_SLOT_ALREADY_DOWN		3	/* slot already down */ | 
|  | 44 | #define PCI_L1_ERR			7	/* L1 console command error */ | 
|  | 45 | #define PCI_EMPTY_33MHZ			15	/* empty 33 MHz bus */ | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 46 |  | 
|  | 47 |  | 
|  | 48 | #define PCIIO_ASIC_TYPE_TIOCA		4 | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 49 | #define PCI_L1_QSIZE			128	/* our L1 message buffer size */ | 
|  | 50 | #define SN_MAX_HP_SLOTS			32	/* max hotplug slots */ | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 51 | #define SN_SLOT_NAME_SIZE		33	/* size of name string */ | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 52 |  | 
|  | 53 | /* internal list head */ | 
|  | 54 | static struct list_head sn_hp_list; | 
|  | 55 |  | 
|  | 56 | /* hotplug_slot struct's private pointer */ | 
|  | 57 | struct slot { | 
|  | 58 | int device_num; | 
|  | 59 | struct pci_bus *pci_bus; | 
|  | 60 | /* this struct for glue internal only */ | 
|  | 61 | struct hotplug_slot *hotplug_slot; | 
|  | 62 | struct list_head hp_list; | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 63 | char physical_path[SN_SLOT_NAME_SIZE]; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 64 | }; | 
|  | 65 |  | 
|  | 66 | struct pcibr_slot_enable_resp { | 
|  | 67 | int resp_sub_errno; | 
|  | 68 | char resp_l1_msg[PCI_L1_QSIZE + 1]; | 
|  | 69 | }; | 
|  | 70 |  | 
|  | 71 | struct pcibr_slot_disable_resp { | 
|  | 72 | int resp_sub_errno; | 
|  | 73 | char resp_l1_msg[PCI_L1_QSIZE + 1]; | 
|  | 74 | }; | 
|  | 75 |  | 
|  | 76 | enum sn_pci_req_e { | 
|  | 77 | PCI_REQ_SLOT_ELIGIBLE, | 
|  | 78 | PCI_REQ_SLOT_DISABLE | 
|  | 79 | }; | 
|  | 80 |  | 
|  | 81 | static int enable_slot(struct hotplug_slot *slot); | 
|  | 82 | static int disable_slot(struct hotplug_slot *slot); | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 83 | static inline int get_power_status(struct hotplug_slot *slot, u8 *value); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 84 |  | 
|  | 85 | static struct hotplug_slot_ops sn_hotplug_slot_ops = { | 
|  | 86 | .owner                  = THIS_MODULE, | 
|  | 87 | .enable_slot            = enable_slot, | 
|  | 88 | .disable_slot           = disable_slot, | 
|  | 89 | .get_power_status       = get_power_status, | 
|  | 90 | }; | 
|  | 91 |  | 
| Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 92 | static DEFINE_MUTEX(sn_hotplug_mutex); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 93 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 94 | static ssize_t path_show (struct hotplug_slot *bss_hotplug_slot, | 
|  | 95 | char *buf) | 
|  | 96 | { | 
|  | 97 | int retval = -ENOENT; | 
|  | 98 | struct slot *slot = bss_hotplug_slot->private; | 
|  | 99 |  | 
|  | 100 | if (!slot) | 
|  | 101 | return retval; | 
|  | 102 |  | 
|  | 103 | retval = sprintf (buf, "%s\n", slot->physical_path); | 
|  | 104 | return retval; | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | static struct hotplug_slot_attribute sn_slot_path_attr = __ATTR_RO(path); | 
|  | 108 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 109 | static int sn_pci_slot_valid(struct pci_bus *pci_bus, int device) | 
|  | 110 | { | 
|  | 111 | struct pcibus_info *pcibus_info; | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 112 | u16 busnum, segment, ioboard_type; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 113 |  | 
|  | 114 | pcibus_info = SN_PCIBUS_BUSSOFT_INFO(pci_bus); | 
|  | 115 |  | 
|  | 116 | /* Check to see if this is a valid slot on 'pci_bus' */ | 
|  | 117 | if (!(pcibus_info->pbi_valid_devices & (1 << device))) | 
|  | 118 | return -EPERM; | 
|  | 119 |  | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 120 | ioboard_type = sn_ioboard_to_pci_bus(pci_bus); | 
|  | 121 | busnum = pcibus_info->pbi_buscommon.bs_persist_busnum; | 
|  | 122 | segment = pci_domain_nr(pci_bus) & 0xf; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 123 |  | 
|  | 124 | /* Do not allow hotplug operations on base I/O cards */ | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 125 | if ((ioboard_type == L1_BRICKTYPE_IX || | 
|  | 126 | ioboard_type == L1_BRICKTYPE_IA) && | 
|  | 127 | (segment == 1 && busnum == 0 && device != 1)) | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 128 | return -EPERM; | 
|  | 129 |  | 
|  | 130 | return 1; | 
|  | 131 | } | 
|  | 132 |  | 
|  | 133 | static int sn_pci_bus_valid(struct pci_bus *pci_bus) | 
|  | 134 | { | 
|  | 135 | struct pcibus_info *pcibus_info; | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 136 | u32 asic_type; | 
|  | 137 | u16 ioboard_type; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 138 |  | 
|  | 139 | /* Don't register slots hanging off the TIOCA bus */ | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 140 | pcibus_info = SN_PCIBUS_BUSSOFT_INFO(pci_bus); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 141 | asic_type = pcibus_info->pbi_buscommon.bs_asic_type; | 
|  | 142 | if (asic_type == PCIIO_ASIC_TYPE_TIOCA) | 
|  | 143 | return -EPERM; | 
|  | 144 |  | 
|  | 145 | /* Only register slots in I/O Bricks that support hotplug */ | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 146 | ioboard_type = sn_ioboard_to_pci_bus(pci_bus); | 
|  | 147 | switch (ioboard_type) { | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 148 | case L1_BRICKTYPE_IX: | 
|  | 149 | case L1_BRICKTYPE_PX: | 
|  | 150 | case L1_BRICKTYPE_IA: | 
|  | 151 | case L1_BRICKTYPE_PA: | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 152 | case L1_BOARDTYPE_PCIX3SLOT: | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 153 | return 1; | 
|  | 154 | break; | 
|  | 155 | default: | 
|  | 156 | return -EPERM; | 
|  | 157 | break; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 158 | } | 
|  | 159 |  | 
|  | 160 | return -EIO; | 
|  | 161 | } | 
|  | 162 |  | 
|  | 163 | static int sn_hp_slot_private_alloc(struct hotplug_slot *bss_hotplug_slot, | 
| Alex Chiang | 85234ce | 2008-10-20 17:41:48 -0600 | [diff] [blame] | 164 | struct pci_bus *pci_bus, int device, | 
|  | 165 | char *name) | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 166 | { | 
|  | 167 | struct pcibus_info *pcibus_info; | 
|  | 168 | struct slot *slot; | 
|  | 169 |  | 
|  | 170 | pcibus_info = SN_PCIBUS_BUSSOFT_INFO(pci_bus); | 
|  | 171 |  | 
| Pekka Enberg | 656da9d | 2005-09-22 00:48:11 -0700 | [diff] [blame] | 172 | slot = kzalloc(sizeof(*slot), GFP_KERNEL); | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 173 | if (!slot) | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 174 | return -ENOMEM; | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 175 | bss_hotplug_slot->private = slot; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 176 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 177 | slot->device_num = device; | 
|  | 178 | slot->pci_bus = pci_bus; | 
| Alex Chiang | 85234ce | 2008-10-20 17:41:48 -0600 | [diff] [blame] | 179 | sprintf(name, "%04x:%02x:%02x", | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 180 | pci_domain_nr(pci_bus), | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 181 | ((u16)pcibus_info->pbi_buscommon.bs_persist_busnum), | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 182 | device + 1); | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 183 |  | 
|  | 184 | sn_generate_path(pci_bus, slot->physical_path); | 
|  | 185 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 186 | slot->hotplug_slot = bss_hotplug_slot; | 
|  | 187 | list_add(&slot->hp_list, &sn_hp_list); | 
|  | 188 |  | 
|  | 189 | return 0; | 
|  | 190 | } | 
|  | 191 |  | 
|  | 192 | static struct hotplug_slot * sn_hp_destroy(void) | 
|  | 193 | { | 
|  | 194 | struct slot *slot; | 
| Alex Chiang | f46753c | 2008-06-10 15:28:50 -0600 | [diff] [blame] | 195 | struct pci_slot *pci_slot; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 196 | struct hotplug_slot *bss_hotplug_slot = NULL; | 
|  | 197 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 198 | list_for_each_entry(slot, &sn_hp_list, hp_list) { | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 199 | bss_hotplug_slot = slot->hotplug_slot; | 
| Alex Chiang | f46753c | 2008-06-10 15:28:50 -0600 | [diff] [blame] | 200 | pci_slot = bss_hotplug_slot->pci_slot; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 201 | list_del(&((struct slot *)bss_hotplug_slot->private)-> | 
|  | 202 | hp_list); | 
| Alex Chiang | f46753c | 2008-06-10 15:28:50 -0600 | [diff] [blame] | 203 | sysfs_remove_file(&pci_slot->kobj, | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 204 | &sn_slot_path_attr.attr); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 205 | break; | 
|  | 206 | } | 
|  | 207 | return bss_hotplug_slot; | 
|  | 208 | } | 
|  | 209 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 210 | static void sn_bus_free_data(struct pci_dev *dev) | 
|  | 211 | { | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 212 | struct pci_bus *subordinate_bus; | 
|  | 213 | struct pci_dev *child; | 
|  | 214 |  | 
|  | 215 | /* Recursively clean up sn_irq_info structs */ | 
|  | 216 | if (dev->subordinate) { | 
|  | 217 | subordinate_bus = dev->subordinate; | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 218 | list_for_each_entry(child, &subordinate_bus->devices, bus_list) | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 219 | sn_bus_free_data(child); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 220 | } | 
| John Keller | 8e77af6 | 2006-03-08 13:21:34 -0600 | [diff] [blame] | 221 | /* | 
|  | 222 | * Some drivers may use dma accesses during the | 
|  | 223 | * driver remove function. We release the sysdata | 
|  | 224 | * areas after the driver remove functions have | 
|  | 225 | * been called. | 
|  | 226 | */ | 
|  | 227 | sn_bus_store_sysdata(dev); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 228 | sn_pci_unfixup_slot(dev); | 
|  | 229 | } | 
|  | 230 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 231 | static int sn_slot_enable(struct hotplug_slot *bss_hotplug_slot, | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 232 | int device_num, char **ssdt) | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 233 | { | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 234 | struct slot *slot = bss_hotplug_slot->private; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 235 | struct pcibus_info *pcibus_info; | 
|  | 236 | struct pcibr_slot_enable_resp resp; | 
|  | 237 | int rc; | 
|  | 238 |  | 
|  | 239 | pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus); | 
|  | 240 |  | 
|  | 241 | /* | 
|  | 242 | * Power-on and initialize the slot in the SN | 
|  | 243 | * PCI infrastructure. | 
|  | 244 | */ | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 245 | rc = sal_pcibr_slot_enable(pcibus_info, device_num, &resp, ssdt); | 
|  | 246 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 247 |  | 
|  | 248 | if (rc == PCI_SLOT_ALREADY_UP) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 249 | dev_dbg(&slot->pci_bus->self->dev, "is already active\n"); | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 250 | return 1; /* return 1 to user */ | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 251 | } | 
|  | 252 |  | 
|  | 253 | if (rc == PCI_L1_ERR) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 254 | dev_dbg(&slot->pci_bus->self->dev, | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 255 | "L1 failure %d with message: %s", | 
|  | 256 | resp.resp_sub_errno, resp.resp_l1_msg); | 
|  | 257 | return -EPERM; | 
|  | 258 | } | 
|  | 259 |  | 
|  | 260 | if (rc) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 261 | dev_dbg(&slot->pci_bus->self->dev, | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 262 | "insert failed with error %d sub-error %d\n", | 
|  | 263 | rc, resp.resp_sub_errno); | 
|  | 264 | return -EIO; | 
|  | 265 | } | 
|  | 266 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 267 | pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus); | 
|  | 268 | pcibus_info->pbi_enabled_devices |= (1 << device_num); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 269 |  | 
|  | 270 | return 0; | 
|  | 271 | } | 
|  | 272 |  | 
|  | 273 | static int sn_slot_disable(struct hotplug_slot *bss_hotplug_slot, | 
|  | 274 | int device_num, int action) | 
|  | 275 | { | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 276 | struct slot *slot = bss_hotplug_slot->private; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 277 | struct pcibus_info *pcibus_info; | 
|  | 278 | struct pcibr_slot_disable_resp resp; | 
|  | 279 | int rc; | 
|  | 280 |  | 
|  | 281 | pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus); | 
|  | 282 |  | 
|  | 283 | rc = sal_pcibr_slot_disable(pcibus_info, device_num, action, &resp); | 
|  | 284 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 285 | if ((action == PCI_REQ_SLOT_ELIGIBLE) && | 
|  | 286 | (rc == PCI_SLOT_ALREADY_DOWN)) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 287 | dev_dbg(&slot->pci_bus->self->dev, "Slot %s already inactive\n", slot->physical_path); | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 288 | return 1; /* return 1 to user */ | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 289 | } | 
|  | 290 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 291 | if ((action == PCI_REQ_SLOT_ELIGIBLE) && (rc == PCI_EMPTY_33MHZ)) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 292 | dev_dbg(&slot->pci_bus->self->dev, | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 293 | "Cannot remove last 33MHz card\n"); | 
|  | 294 | return -EPERM; | 
|  | 295 | } | 
|  | 296 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 297 | if ((action == PCI_REQ_SLOT_ELIGIBLE) && (rc == PCI_L1_ERR)) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 298 | dev_dbg(&slot->pci_bus->self->dev, | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 299 | "L1 failure %d with message \n%s\n", | 
|  | 300 | resp.resp_sub_errno, resp.resp_l1_msg); | 
|  | 301 | return -EPERM; | 
|  | 302 | } | 
|  | 303 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 304 | if ((action == PCI_REQ_SLOT_ELIGIBLE) && rc) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 305 | dev_dbg(&slot->pci_bus->self->dev, | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 306 | "remove failed with error %d sub-error %d\n", | 
|  | 307 | rc, resp.resp_sub_errno); | 
|  | 308 | return -EIO; | 
|  | 309 | } | 
|  | 310 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 311 | if ((action == PCI_REQ_SLOT_ELIGIBLE) && !rc) | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 312 | return 0; | 
|  | 313 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 314 | if ((action == PCI_REQ_SLOT_DISABLE) && !rc) { | 
|  | 315 | pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus); | 
|  | 316 | pcibus_info->pbi_enabled_devices &= ~(1 << device_num); | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 317 | dev_dbg(&slot->pci_bus->self->dev, "remove successful\n"); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 318 | return 0; | 
|  | 319 | } | 
|  | 320 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 321 | if ((action == PCI_REQ_SLOT_DISABLE) && rc) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 322 | dev_dbg(&slot->pci_bus->self->dev,"remove failed rc = %d\n", rc); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 323 | } | 
|  | 324 |  | 
|  | 325 | return rc; | 
|  | 326 | } | 
|  | 327 |  | 
| John Keller | 9f581f1 | 2006-10-04 16:49:35 -0500 | [diff] [blame] | 328 | /* | 
|  | 329 | * Power up and configure the slot via a SAL call to PROM. | 
|  | 330 | * Scan slot (and any children), do any platform specific fixup, | 
|  | 331 | * and find device driver. | 
|  | 332 | */ | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 333 | static int enable_slot(struct hotplug_slot *bss_hotplug_slot) | 
|  | 334 | { | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 335 | struct slot *slot = bss_hotplug_slot->private; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 336 | struct pci_bus *new_bus = NULL; | 
|  | 337 | struct pci_dev *dev; | 
|  | 338 | int func, num_funcs; | 
|  | 339 | int new_ppb = 0; | 
|  | 340 | int rc; | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 341 | char *ssdt = NULL; | 
| John Keller | 9f581f1 | 2006-10-04 16:49:35 -0500 | [diff] [blame] | 342 | void pcibios_fixup_device_resources(struct pci_dev *); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 343 |  | 
|  | 344 | /* Serialize the Linux PCI infrastructure */ | 
| Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 345 | mutex_lock(&sn_hotplug_mutex); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 346 |  | 
|  | 347 | /* | 
|  | 348 | * Power-on and initialize the slot in the SN | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 349 | * PCI infrastructure. Also, retrieve the ACPI SSDT | 
|  | 350 | * table for the slot (if ACPI capable PROM). | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 351 | */ | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 352 | rc = sn_slot_enable(bss_hotplug_slot, slot->device_num, &ssdt); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 353 | if (rc) { | 
| Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 354 | mutex_unlock(&sn_hotplug_mutex); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 355 | return rc; | 
|  | 356 | } | 
|  | 357 |  | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 358 | if (ssdt) | 
|  | 359 | ssdt = __va(ssdt); | 
|  | 360 | /* Add the new SSDT for the slot to the ACPI namespace */ | 
|  | 361 | if (SN_ACPI_BASE_SUPPORT() && ssdt) { | 
|  | 362 | acpi_status ret; | 
|  | 363 |  | 
|  | 364 | ret = acpi_load_table((struct acpi_table_header *)ssdt); | 
|  | 365 | if (ACPI_FAILURE(ret)) { | 
|  | 366 | printk(KERN_ERR "%s: acpi_load_table failed (0x%x)\n", | 
| Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 367 | __func__, ret); | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 368 | /* try to continue on */ | 
|  | 369 | } | 
|  | 370 | } | 
|  | 371 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 372 | num_funcs = pci_scan_slot(slot->pci_bus, | 
|  | 373 | PCI_DEVFN(slot->device_num + 1, 0)); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 374 | if (!num_funcs) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 375 | dev_dbg(&slot->pci_bus->self->dev, "no device in slot\n"); | 
| Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 376 | mutex_unlock(&sn_hotplug_mutex); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 377 | return -ENODEV; | 
|  | 378 | } | 
|  | 379 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 380 | /* | 
|  | 381 | * Map SN resources for all functions on the card | 
|  | 382 | * to the Linux PCI interface and tell the drivers | 
|  | 383 | * about them. | 
|  | 384 | */ | 
|  | 385 | for (func = 0; func < num_funcs;  func++) { | 
|  | 386 | dev = pci_get_slot(slot->pci_bus, | 
|  | 387 | PCI_DEVFN(slot->device_num + 1, | 
|  | 388 | PCI_FUNC(func))); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 389 | if (dev) { | 
| John Keller | 9f581f1 | 2006-10-04 16:49:35 -0500 | [diff] [blame] | 390 | /* Need to do slot fixup on PPB before fixup of children | 
|  | 391 | * (PPB's pcidev_info needs to be in pcidev_info list | 
|  | 392 | * before child's SN_PCIDEV_INFO() call to setup | 
|  | 393 | * pdi_host_pcidev_info). | 
|  | 394 | */ | 
|  | 395 | pcibios_fixup_device_resources(dev); | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 396 | if (SN_ACPI_BASE_SUPPORT()) | 
|  | 397 | sn_acpi_slot_fixup(dev); | 
|  | 398 | else | 
|  | 399 | sn_io_slot_fixup(dev); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 400 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { | 
|  | 401 | unsigned char sec_bus; | 
|  | 402 | pci_read_config_byte(dev, PCI_SECONDARY_BUS, | 
|  | 403 | &sec_bus); | 
|  | 404 | new_bus = pci_add_new_bus(dev->bus, dev, | 
|  | 405 | sec_bus); | 
|  | 406 | pci_scan_child_bus(new_bus); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 407 | new_ppb = 1; | 
|  | 408 | } | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 409 | pci_dev_put(dev); | 
|  | 410 | } | 
|  | 411 | } | 
|  | 412 |  | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 413 | /* | 
|  | 414 | * Add the slot's devices to the ACPI infrastructure */ | 
|  | 415 | if (SN_ACPI_BASE_SUPPORT() && ssdt) { | 
| Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 416 | unsigned long long adr; | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 417 | struct acpi_device *pdevice; | 
|  | 418 | struct acpi_device *device; | 
|  | 419 | acpi_handle phandle; | 
|  | 420 | acpi_handle chandle = NULL; | 
|  | 421 | acpi_handle rethandle; | 
|  | 422 | acpi_status ret; | 
|  | 423 |  | 
|  | 424 | phandle = PCI_CONTROLLER(slot->pci_bus)->acpi_handle; | 
|  | 425 |  | 
|  | 426 | if (acpi_bus_get_device(phandle, &pdevice)) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 427 | dev_dbg(&slot->pci_bus->self->dev, | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 428 | "no parent device, assuming NULL\n"); | 
|  | 429 | pdevice = NULL; | 
|  | 430 | } | 
|  | 431 |  | 
|  | 432 | /* | 
|  | 433 | * Walk the rootbus node's immediate children looking for | 
|  | 434 | * the slot's device node(s). There can be more than | 
|  | 435 | * one for multifunction devices. | 
|  | 436 | */ | 
|  | 437 | for (;;) { | 
|  | 438 | rethandle = NULL; | 
|  | 439 | ret = acpi_get_next_object(ACPI_TYPE_DEVICE, | 
|  | 440 | phandle, chandle, | 
|  | 441 | &rethandle); | 
|  | 442 |  | 
|  | 443 | if (ret == AE_NOT_FOUND || rethandle == NULL) | 
|  | 444 | break; | 
|  | 445 |  | 
|  | 446 | chandle = rethandle; | 
|  | 447 |  | 
|  | 448 | ret = acpi_evaluate_integer(chandle, METHOD_NAME__ADR, | 
|  | 449 | NULL, &adr); | 
|  | 450 |  | 
|  | 451 | if (ACPI_SUCCESS(ret) && | 
|  | 452 | (adr>>16) == (slot->device_num + 1)) { | 
|  | 453 |  | 
|  | 454 | ret = acpi_bus_add(&device, pdevice, chandle, | 
|  | 455 | ACPI_BUS_TYPE_DEVICE); | 
|  | 456 | if (ACPI_FAILURE(ret)) { | 
|  | 457 | printk(KERN_ERR "%s: acpi_bus_add " | 
|  | 458 | "failed (0x%x) for slot %d " | 
| Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 459 | "func %d\n", __func__, | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 460 | ret, (int)(adr>>16), | 
|  | 461 | (int)(adr&0xffff)); | 
|  | 462 | /* try to continue on */ | 
|  | 463 | } else { | 
|  | 464 | acpi_bus_start(device); | 
|  | 465 | } | 
|  | 466 | } | 
|  | 467 | } | 
|  | 468 | } | 
|  | 469 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 470 | /* Call the driver for the new device */ | 
|  | 471 | pci_bus_add_devices(slot->pci_bus); | 
|  | 472 | /* Call the drivers for the new devices subordinate to PPB */ | 
|  | 473 | if (new_ppb) | 
|  | 474 | pci_bus_add_devices(new_bus); | 
|  | 475 |  | 
| Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 476 | mutex_unlock(&sn_hotplug_mutex); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 477 |  | 
|  | 478 | if (rc == 0) | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 479 | dev_dbg(&slot->pci_bus->self->dev, | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 480 | "insert operation successful\n"); | 
|  | 481 | else | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 482 | dev_dbg(&slot->pci_bus->self->dev, | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 483 | "insert operation failed rc = %d\n", rc); | 
|  | 484 |  | 
|  | 485 | return rc; | 
|  | 486 | } | 
|  | 487 |  | 
|  | 488 | static int disable_slot(struct hotplug_slot *bss_hotplug_slot) | 
|  | 489 | { | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 490 | struct slot *slot = bss_hotplug_slot->private; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 491 | struct pci_dev *dev; | 
|  | 492 | int func; | 
|  | 493 | int rc; | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 494 | acpi_owner_id ssdt_id = 0; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 495 |  | 
|  | 496 | /* Acquire update access to the bus */ | 
| Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 497 | mutex_lock(&sn_hotplug_mutex); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 498 |  | 
|  | 499 | /* is it okay to bring this slot down? */ | 
|  | 500 | rc = sn_slot_disable(bss_hotplug_slot, slot->device_num, | 
|  | 501 | PCI_REQ_SLOT_ELIGIBLE); | 
|  | 502 | if (rc) | 
|  | 503 | goto leaving; | 
|  | 504 |  | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 505 | /* free the ACPI resources for the slot */ | 
|  | 506 | if (SN_ACPI_BASE_SUPPORT() && | 
|  | 507 | PCI_CONTROLLER(slot->pci_bus)->acpi_handle) { | 
| Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 508 | unsigned long long adr; | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 509 | struct acpi_device *device; | 
|  | 510 | acpi_handle phandle; | 
|  | 511 | acpi_handle chandle = NULL; | 
|  | 512 | acpi_handle rethandle; | 
|  | 513 | acpi_status ret; | 
|  | 514 |  | 
|  | 515 | /* Get the rootbus node pointer */ | 
|  | 516 | phandle = PCI_CONTROLLER(slot->pci_bus)->acpi_handle; | 
|  | 517 |  | 
|  | 518 | /* | 
|  | 519 | * Walk the rootbus node's immediate children looking for | 
|  | 520 | * the slot's device node(s). There can be more than | 
|  | 521 | * one for multifunction devices. | 
|  | 522 | */ | 
|  | 523 | for (;;) { | 
|  | 524 | rethandle = NULL; | 
|  | 525 | ret = acpi_get_next_object(ACPI_TYPE_DEVICE, | 
|  | 526 | phandle, chandle, | 
|  | 527 | &rethandle); | 
|  | 528 |  | 
|  | 529 | if (ret == AE_NOT_FOUND || rethandle == NULL) | 
|  | 530 | break; | 
|  | 531 |  | 
|  | 532 | chandle = rethandle; | 
|  | 533 |  | 
|  | 534 | ret = acpi_evaluate_integer(chandle, | 
|  | 535 | METHOD_NAME__ADR, | 
|  | 536 | NULL, &adr); | 
|  | 537 | if (ACPI_SUCCESS(ret) && | 
|  | 538 | (adr>>16) == (slot->device_num + 1)) { | 
|  | 539 | /* retain the owner id */ | 
|  | 540 | acpi_get_id(chandle, &ssdt_id); | 
|  | 541 |  | 
|  | 542 | ret = acpi_bus_get_device(chandle, | 
|  | 543 | &device); | 
|  | 544 | if (ACPI_SUCCESS(ret)) | 
|  | 545 | acpi_bus_trim(device, 1); | 
|  | 546 | } | 
|  | 547 | } | 
|  | 548 |  | 
|  | 549 | } | 
|  | 550 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 551 | /* Free the SN resources assigned to the Linux device.*/ | 
|  | 552 | for (func = 0; func < 8;  func++) { | 
|  | 553 | dev = pci_get_slot(slot->pci_bus, | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 554 | PCI_DEVFN(slot->device_num + 1, | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 555 | PCI_FUNC(func))); | 
|  | 556 | if (dev) { | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 557 | sn_bus_free_data(dev); | 
|  | 558 | pci_remove_bus_device(dev); | 
|  | 559 | pci_dev_put(dev); | 
|  | 560 | } | 
|  | 561 | } | 
|  | 562 |  | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 563 | /* Remove the SSDT for the slot from the ACPI namespace */ | 
|  | 564 | if (SN_ACPI_BASE_SUPPORT() && ssdt_id) { | 
|  | 565 | acpi_status ret; | 
|  | 566 | ret = acpi_unload_table_id(ssdt_id); | 
|  | 567 | if (ACPI_FAILURE(ret)) { | 
|  | 568 | printk(KERN_ERR "%s: acpi_unload_table_id " | 
|  | 569 | "failed (0x%x) for id %d\n", | 
| Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 570 | __func__, ret, ssdt_id); | 
| John Keller | 3e643e7 | 2007-01-30 01:18:38 -0500 | [diff] [blame] | 571 | /* try to continue on */ | 
|  | 572 | } | 
|  | 573 | } | 
|  | 574 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 575 | /* free the collected sysdata pointers */ | 
|  | 576 | sn_bus_free_sysdata(); | 
|  | 577 |  | 
|  | 578 | /* Deactivate slot */ | 
|  | 579 | rc = sn_slot_disable(bss_hotplug_slot, slot->device_num, | 
|  | 580 | PCI_REQ_SLOT_DISABLE); | 
|  | 581 | leaving: | 
|  | 582 | /* Release the bus lock */ | 
| Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 583 | mutex_unlock(&sn_hotplug_mutex); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 584 |  | 
|  | 585 | return rc; | 
|  | 586 | } | 
|  | 587 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 588 | static inline int get_power_status(struct hotplug_slot *bss_hotplug_slot, | 
|  | 589 | u8 *value) | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 590 | { | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 591 | struct slot *slot = bss_hotplug_slot->private; | 
|  | 592 | struct pcibus_info *pcibus_info; | 
| Mike Habeck | 466ee36 | 2006-05-06 09:01:59 -0500 | [diff] [blame] | 593 | u32 power; | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 594 |  | 
|  | 595 | pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus); | 
| Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 596 | mutex_lock(&sn_hotplug_mutex); | 
| Mike Habeck | 466ee36 | 2006-05-06 09:01:59 -0500 | [diff] [blame] | 597 | power = pcibus_info->pbi_enabled_devices & (1 << slot->device_num); | 
|  | 598 | *value = power ? 1 : 0; | 
| Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 599 | mutex_unlock(&sn_hotplug_mutex); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 600 | return 0; | 
|  | 601 | } | 
|  | 602 |  | 
|  | 603 | static void sn_release_slot(struct hotplug_slot *bss_hotplug_slot) | 
|  | 604 | { | 
|  | 605 | kfree(bss_hotplug_slot->info); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 606 | kfree(bss_hotplug_slot->private); | 
|  | 607 | kfree(bss_hotplug_slot); | 
|  | 608 | } | 
|  | 609 |  | 
|  | 610 | static int sn_hotplug_slot_register(struct pci_bus *pci_bus) | 
|  | 611 | { | 
|  | 612 | int device; | 
| Alex Chiang | f46753c | 2008-06-10 15:28:50 -0600 | [diff] [blame] | 613 | struct pci_slot *pci_slot; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 614 | struct hotplug_slot *bss_hotplug_slot; | 
| Alex Chiang | 85234ce | 2008-10-20 17:41:48 -0600 | [diff] [blame] | 615 | char name[SN_SLOT_NAME_SIZE]; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 616 | int rc = 0; | 
|  | 617 |  | 
|  | 618 | /* | 
|  | 619 | * Currently only four devices are supported, | 
|  | 620 | * in the future there maybe more -- up to 32. | 
|  | 621 | */ | 
|  | 622 |  | 
|  | 623 | for (device = 0; device < SN_MAX_HP_SLOTS ; device++) { | 
|  | 624 | if (sn_pci_slot_valid(pci_bus, device) != 1) | 
|  | 625 | continue; | 
|  | 626 |  | 
| Pekka Enberg | 656da9d | 2005-09-22 00:48:11 -0700 | [diff] [blame] | 627 | bss_hotplug_slot = kzalloc(sizeof(*bss_hotplug_slot), | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 628 | GFP_KERNEL); | 
|  | 629 | if (!bss_hotplug_slot) { | 
|  | 630 | rc = -ENOMEM; | 
|  | 631 | goto alloc_err; | 
|  | 632 | } | 
|  | 633 |  | 
|  | 634 | bss_hotplug_slot->info = | 
| Pekka Enberg | 656da9d | 2005-09-22 00:48:11 -0700 | [diff] [blame] | 635 | kzalloc(sizeof(struct hotplug_slot_info), | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 636 | GFP_KERNEL); | 
|  | 637 | if (!bss_hotplug_slot->info) { | 
|  | 638 | rc = -ENOMEM; | 
|  | 639 | goto alloc_err; | 
|  | 640 | } | 
|  | 641 |  | 
|  | 642 | if (sn_hp_slot_private_alloc(bss_hotplug_slot, | 
| Alex Chiang | 85234ce | 2008-10-20 17:41:48 -0600 | [diff] [blame] | 643 | pci_bus, device, name)) { | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 644 | rc = -ENOMEM; | 
|  | 645 | goto alloc_err; | 
|  | 646 | } | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 647 | bss_hotplug_slot->ops = &sn_hotplug_slot_ops; | 
|  | 648 | bss_hotplug_slot->release = &sn_release_slot; | 
|  | 649 |  | 
| Alex Chiang | 85234ce | 2008-10-20 17:41:48 -0600 | [diff] [blame] | 650 | rc = pci_hp_register(bss_hotplug_slot, pci_bus, device, name); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 651 | if (rc) | 
|  | 652 | goto register_err; | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 653 |  | 
| Alex Chiang | f46753c | 2008-06-10 15:28:50 -0600 | [diff] [blame] | 654 | pci_slot = bss_hotplug_slot->pci_slot; | 
|  | 655 | rc = sysfs_create_file(&pci_slot->kobj, | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 656 | &sn_slot_path_attr.attr); | 
|  | 657 | if (rc) | 
|  | 658 | goto register_err; | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 659 | } | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 660 | dev_dbg(&pci_bus->self->dev, "Registered bus with hotplug\n"); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 661 | return rc; | 
|  | 662 |  | 
|  | 663 | register_err: | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 664 | dev_dbg(&pci_bus->self->dev, "bus failed to register with err = %d\n", | 
| Alex Chiang | 8344b56 | 2008-06-10 15:30:42 -0600 | [diff] [blame] | 665 | rc); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 666 |  | 
|  | 667 | alloc_err: | 
|  | 668 | if (rc == -ENOMEM) | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 669 | dev_dbg(&pci_bus->self->dev, "Memory allocation error\n"); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 670 |  | 
|  | 671 | /* destroy THIS element */ | 
|  | 672 | if (bss_hotplug_slot) | 
|  | 673 | sn_release_slot(bss_hotplug_slot); | 
|  | 674 |  | 
|  | 675 | /* destroy anything else on the list */ | 
|  | 676 | while ((bss_hotplug_slot = sn_hp_destroy())) | 
|  | 677 | pci_hp_deregister(bss_hotplug_slot); | 
|  | 678 |  | 
|  | 679 | return rc; | 
|  | 680 | } | 
|  | 681 |  | 
| Peter Huewe | db5ed9b | 2009-06-06 14:58:56 +0200 | [diff] [blame] | 682 | static int __init sn_pci_hotplug_init(void) | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 683 | { | 
|  | 684 | struct pci_bus *pci_bus = NULL; | 
|  | 685 | int rc; | 
|  | 686 | int registered = 0; | 
|  | 687 |  | 
| Prarit Bhargava | e55dea5 | 2006-04-04 09:26:46 -0400 | [diff] [blame] | 688 | if (!sn_prom_feature_available(PRF_HOTPLUG_SUPPORT)) { | 
|  | 689 | printk(KERN_ERR "%s: PROM version does not support hotplug.\n", | 
| Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 690 | __func__); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 691 | return -EPERM; | 
|  | 692 | } | 
|  | 693 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 694 | INIT_LIST_HEAD(&sn_hp_list); | 
|  | 695 |  | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 696 | while ((pci_bus = pci_find_next_bus(pci_bus))) { | 
|  | 697 | if (!pci_bus->sysdata) | 
|  | 698 | continue; | 
|  | 699 |  | 
|  | 700 | rc = sn_pci_bus_valid(pci_bus); | 
|  | 701 | if (rc != 1) { | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 702 | dev_dbg(&pci_bus->self->dev, "not a valid hotplug bus\n"); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 703 | continue; | 
|  | 704 | } | 
| Tony Luck | 34ef30c | 2007-05-10 09:39:41 -0700 | [diff] [blame] | 705 | dev_dbg(&pci_bus->self->dev, "valid hotplug bus\n"); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 706 |  | 
|  | 707 | rc = sn_hotplug_slot_register(pci_bus); | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 708 | if (!rc) { | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 709 | registered = 1; | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 710 | } else { | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 711 | registered = 0; | 
|  | 712 | break; | 
|  | 713 | } | 
|  | 714 | } | 
|  | 715 |  | 
|  | 716 | return registered == 1 ? 0 : -ENODEV; | 
|  | 717 | } | 
|  | 718 |  | 
| Peter Huewe | db5ed9b | 2009-06-06 14:58:56 +0200 | [diff] [blame] | 719 | static void __exit sn_pci_hotplug_exit(void) | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 720 | { | 
|  | 721 | struct hotplug_slot *bss_hotplug_slot; | 
|  | 722 |  | 
| Prarit Bhargava | 1d2450a | 2005-08-12 10:13:34 -0400 | [diff] [blame] | 723 | while ((bss_hotplug_slot = sn_hp_destroy())) | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 724 | pci_hp_deregister(bss_hotplug_slot); | 
| Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 725 |  | 
|  | 726 | if (!list_empty(&sn_hp_list)) | 
|  | 727 | printk(KERN_ERR "%s: internal list is not empty\n", __FILE__); | 
|  | 728 | } | 
|  | 729 |  | 
|  | 730 | module_init(sn_pci_hotplug_init); | 
|  | 731 | module_exit(sn_pci_hotplug_exit); |