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