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