13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/pci.h>
18 #include <linux/slab.h>
19 #include <linux/types.h>
22 #include <asm/sn/addrs.h>
31 #include <asm/sn/types.h>
43 #define PCI_SLOT_ALREADY_UP 2
44 #define PCI_SLOT_ALREADY_DOWN 3
46 #define PCI_EMPTY_33MHZ 15
49 #define PCIIO_ASIC_TYPE_TIOCA 4
50 #define PCI_L1_QSIZE 128
51 #define SN_MAX_HP_SLOTS 32
52 #define SN_SLOT_NAME_SIZE 33
82 static int enable_slot(
struct hotplug_slot *
slot);
83 static int disable_slot(
struct hotplug_slot *
slot);
84 static inline int get_power_status(
struct hotplug_slot *
slot,
u8 *
value);
126 (segment == 1 && busnum == 0 && device != 1))
132 static int sn_pci_bus_valid(
struct pci_bus *pci_bus)
134 struct pcibus_info *pcibus_info;
146 switch (ioboard_type) {
162 static int sn_hp_slot_private_alloc(
struct hotplug_slot *bss_hotplug_slot,
163 struct pci_bus *pci_bus,
int device,
166 struct pcibus_info *pcibus_info;
174 bss_hotplug_slot->private =
slot;
178 sprintf(name,
"%04x:%02x:%02x",
186 list_add(&slot->
hp_list, &sn_hp_list);
191 static struct hotplug_slot * sn_hp_destroy(
void)
195 struct hotplug_slot *bss_hotplug_slot =
NULL;
199 pci_slot = bss_hotplug_slot->pci_slot;
200 list_del(&((
struct slot *)bss_hotplug_slot->private)->
203 &sn_slot_path_attr.
attr);
206 return bss_hotplug_slot;
209 static void sn_bus_free_data(
struct pci_dev *
dev)
211 struct pci_bus *subordinate_bus;
218 sn_bus_free_data(child);
230 static
int sn_slot_enable(
struct hotplug_slot *bss_hotplug_slot,
231 int device_num,
char **ssdt)
233 struct slot *slot = bss_hotplug_slot->private;
234 struct pcibus_info *pcibus_info;
254 "L1 failure %d with message: %s",
255 resp.resp_sub_errno,
resp.resp_l1_msg);
261 "insert failed with error %d sub-error %d\n",
262 rc,
resp.resp_sub_errno);
272 static int sn_slot_disable(
struct hotplug_slot *bss_hotplug_slot,
273 int device_num,
int action)
275 struct slot *slot = bss_hotplug_slot->private;
276 struct pcibus_info *pcibus_info;
292 "Cannot remove last 33MHz card\n");
298 "L1 failure %d with message \n%s\n",
299 resp.resp_sub_errno,
resp.resp_l1_msg);
305 "remove failed with error %d sub-error %d\n",
306 rc,
resp.resp_sub_errno);
332 static int enable_slot(
struct hotplug_slot *bss_hotplug_slot)
334 struct slot *slot = bss_hotplug_slot->private;
335 struct pci_bus *new_bus =
NULL;
351 rc = sn_slot_enable(bss_hotplug_slot, slot->
device_num, &ssdt);
384 for (func = 0; func <
num_funcs; func++) {
413 unsigned long long adr;
414 struct acpi_device *pdevice;
415 struct acpi_device *device;
425 "no parent device, assuming NULL\n");
452 ACPI_BUS_TYPE_DEVICE);
455 "failed (0x%x) for slot %d "
456 "func %d\n", __func__,
477 "insert operation successful\n");
480 "insert operation failed rc = %d\n", rc);
485 static int disable_slot(
struct hotplug_slot *bss_hotplug_slot)
487 struct slot *slot = bss_hotplug_slot->private;
497 rc = sn_slot_disable(bss_hotplug_slot, slot->
device_num,
505 unsigned long long adr;
506 struct acpi_device *device;
549 for (func = 0; func < 8; func++) {
554 sn_bus_free_data(dev);
566 "failed (0x%x) for id %d\n",
567 __func__, ret, ssdt_id);
576 rc = sn_slot_disable(bss_hotplug_slot, slot->
device_num,
585 static inline int get_power_status(
struct hotplug_slot *bss_hotplug_slot,
588 struct slot *slot = bss_hotplug_slot->private;
589 struct pcibus_info *pcibus_info;
595 *value = power ? 1 : 0;
600 static void sn_release_slot(
struct hotplug_slot *bss_hotplug_slot)
602 kfree(bss_hotplug_slot->info);
603 kfree(bss_hotplug_slot->private);
604 kfree(bss_hotplug_slot);
607 static int sn_hotplug_slot_register(
struct pci_bus *pci_bus)
611 struct hotplug_slot *bss_hotplug_slot;
621 if (sn_pci_slot_valid(pci_bus, device) != 1)
624 bss_hotplug_slot = kzalloc(
sizeof(*bss_hotplug_slot),
626 if (!bss_hotplug_slot) {
631 bss_hotplug_slot->info =
634 if (!bss_hotplug_slot->info) {
639 if (sn_hp_slot_private_alloc(bss_hotplug_slot,
640 pci_bus, device, name)) {
644 bss_hotplug_slot->ops = &sn_hotplug_slot_ops;
645 bss_hotplug_slot->release = &sn_release_slot;
651 pci_slot = bss_hotplug_slot->pci_slot;
653 &sn_slot_path_attr.
attr);
657 dev_dbg(&pci_bus->
self->dev,
"Registered bus with hotplug\n");
661 dev_dbg(&pci_bus->
self->dev,
"bus failed to register with err = %d\n",
666 dev_dbg(&pci_bus->
self->dev,
"Memory allocation error\n");
669 if (bss_hotplug_slot)
670 sn_release_slot(bss_hotplug_slot);
673 while ((bss_hotplug_slot = sn_hp_destroy()))
679 static int __init sn_pci_hotplug_init(
void)
681 struct pci_bus *pci_bus =
NULL;
691 INIT_LIST_HEAD(&sn_hp_list);
697 rc = sn_pci_bus_valid(pci_bus);
699 dev_dbg(&pci_bus->
self->dev,
"not a valid hotplug bus\n");
702 dev_dbg(&pci_bus->
self->dev,
"valid hotplug bus\n");
704 rc = sn_hotplug_slot_register(pci_bus);
713 return registered == 1 ? 0 : -
ENODEV;
716 static void __exit sn_pci_hotplug_exit(
void)
718 struct hotplug_slot *bss_hotplug_slot;
720 while ((bss_hotplug_slot = sn_hp_destroy()))
723 if (!list_empty(&sn_hp_list))