2 * Compaq Hot Plug Controller Driver
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18 * NON INFRINGEMENT. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * Send feedback to <greg@kroah.com>
27 * Jan 12, 2003 - Added 66/100/133MHz PCI-X support,
28 * Torben Mathiasen <torben.mathiasen@hp.com>
32 #include <linux/config.h>
33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/types.h>
36 #include <linux/proc_fs.h>
37 #include <linux/slab.h>
38 #include <linux/workqueue.h>
39 #include <linux/pci.h>
40 #include <linux/init.h>
41 #include <linux/interrupt.h>
43 #include <asm/uaccess.h>
46 #include "cpqphp_nvram.h"
47 #include "../../../arch/i386/pci/pci.h" /* horrible hack showing how processor dependent we are... */
50 /* Global variables */
52 int cpqhp_legacy_mode;
53 struct controller *cpqhp_ctrl_list; /* = NULL */
54 struct pci_func *cpqhp_slot_list[256];
57 static void *smbios_table;
58 static void *smbios_start;
59 static void *cpqhp_rom_start;
63 #define DRIVER_VERSION "0.9.7"
64 #define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>"
65 #define DRIVER_DESC "Compaq Hot Plug PCI Controller Driver"
67 MODULE_AUTHOR(DRIVER_AUTHOR);
68 MODULE_DESCRIPTION(DRIVER_DESC);
69 MODULE_LICENSE("GPL");
71 MODULE_PARM(power_mode, "b");
72 MODULE_PARM_DESC(power_mode, "Power mode enabled or not");
74 MODULE_PARM(debug, "i");
75 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
77 #define CPQHPC_MODULE_MINOR 208
79 static int one_time_init (void);
80 static int set_attention_status (struct hotplug_slot *slot, u8 value);
81 static int process_SI (struct hotplug_slot *slot);
82 static int process_SS (struct hotplug_slot *slot);
83 static int hardware_test (struct hotplug_slot *slot, u32 value);
84 static int get_power_status (struct hotplug_slot *slot, u8 *value);
85 static int get_attention_status (struct hotplug_slot *slot, u8 *value);
86 static int get_latch_status (struct hotplug_slot *slot, u8 *value);
87 static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
88 static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
89 static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
91 static struct hotplug_slot_ops cpqphp_hotplug_slot_ops = {
93 .set_attention_status = set_attention_status,
94 .enable_slot = process_SI,
95 .disable_slot = process_SS,
96 .hardware_test = hardware_test,
97 .get_power_status = get_power_status,
98 .get_attention_status = get_attention_status,
99 .get_latch_status = get_latch_status,
100 .get_adapter_status = get_adapter_status,
101 .get_max_bus_speed = get_max_bus_speed,
102 .get_cur_bus_speed = get_cur_bus_speed,
106 static inline int is_slot64bit (struct slot *slot)
108 if (!slot || !slot->p_sm_slot)
111 if (readb(slot->p_sm_slot + SMBIOS_SLOT_WIDTH) == 0x06)
117 static inline int is_slot66mhz (struct slot *slot)
119 if (!slot || !slot->p_sm_slot)
122 if (readb(slot->p_sm_slot + SMBIOS_SLOT_TYPE) == 0x0E)
129 * detect_SMBIOS_pointer - find the system Management BIOS Table in the specified region of memory.
131 * @begin: begin pointer for region to be scanned.
132 * @end: end pointer for region to be scanned.
134 * Returns pointer to the head of the SMBIOS tables (or NULL)
137 static void * detect_SMBIOS_pointer(void *begin, void *end)
141 u8 temp1, temp2, temp3, temp4;
144 endp = (end - sizeof(u32) + 1);
146 for (fp = begin; fp <= endp; fp += 16) {
163 dbg("Discovered SMBIOS Entry point at %p\n", fp);
169 * init_SERR - Initializes the per slot SERR generation.
171 * For unexpected switch opens
174 static int init_SERR(struct controller * ctrl)
183 tempdword = ctrl->first_slot;
185 number_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
186 // Loop through slots
187 while (number_of_slots) {
188 physical_slot = tempdword;
189 writeb(0, ctrl->hpc_reg + SLOT_SERR);
198 /* nice debugging output */
199 static int pci_print_IRQ_route (void)
201 struct irq_routing_table *routing_table;
205 u8 tbus, tdevice, tslot;
207 routing_table = pcibios_get_irq_routing_table();
208 if (routing_table == NULL) {
209 err("No BIOS Routing Table??? Not good\n");
213 len = (routing_table->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
214 // Make sure I got at least one entry
216 kfree(routing_table);
220 dbg("bus dev func slot\n");
222 for (loop = 0; loop < len; ++loop) {
223 tbus = routing_table->slots[loop].bus;
224 tdevice = routing_table->slots[loop].devfn;
225 tslot = routing_table->slots[loop].slot;
226 dbg("%d %d %d %d\n", tbus, tdevice >> 3, tdevice & 0x7, tslot);
229 kfree(routing_table);
235 * get_subsequent_smbios_entry
237 * Gets the first entry if previous == NULL
238 * Otherwise, returns the next entry
239 * Uses global SMBIOS Table pointer
241 * @curr: %NULL or pointer to previously returned structure
243 * returns a pointer to an SMBIOS structure or NULL if none found
245 static void * get_subsequent_smbios_entry(void *smbios_start, void *smbios_table, void *curr)
248 u8 previous_byte = 1;
252 if (!smbios_table || !curr)
255 // set p_max to the end of the table
256 p_max = smbios_start + readw(smbios_table + ST_LENGTH);
259 p_temp += readb(curr + SMBIOS_GENERIC_LENGTH);
261 while ((p_temp < p_max) && !bail) {
262 // Look for the double NULL terminator
263 // The first condition is the previous byte and the second is the curr
264 if (!previous_byte && !(readb(p_temp))) {
268 previous_byte = readb(p_temp);
272 if (p_temp < p_max) {
283 * @type:SMBIOS structure type to be returned
284 * @previous: %NULL or pointer to previously returned structure
286 * Gets the first entry of the specified type if previous == NULL
287 * Otherwise, returns the next entry of the given type.
288 * Uses global SMBIOS Table pointer
289 * Uses get_subsequent_smbios_entry
291 * returns a pointer to an SMBIOS structure or %NULL if none found
293 static void *get_SMBIOS_entry (void *smbios_start, void *smbios_table, u8 type, void * previous)
299 previous = smbios_start;
301 previous = get_subsequent_smbios_entry(smbios_start, smbios_table, previous);
305 if (readb(previous + SMBIOS_GENERIC_TYPE) != type) {
306 previous = get_subsequent_smbios_entry(smbios_start, smbios_table, previous);
315 static void release_slot(struct hotplug_slot *hotplug_slot)
317 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
322 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
324 kfree(slot->hotplug_slot->info);
325 kfree(slot->hotplug_slot->name);
326 kfree(slot->hotplug_slot);
330 static int ctrl_slot_setup (struct controller * ctrl, void *smbios_start, void *smbios_table)
332 struct slot *new_slot;
338 void *slot_entry= NULL;
341 dbg("%s\n", __FUNCTION__);
343 tempdword = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
345 number_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
346 slot_device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
347 slot_number = ctrl->first_slot;
349 while (number_of_slots) {
350 new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL);
354 memset(new_slot, 0, sizeof(struct slot));
355 new_slot->hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL);
356 if (!new_slot->hotplug_slot) {
360 memset(new_slot->hotplug_slot, 0, sizeof (struct hotplug_slot));
362 new_slot->hotplug_slot->info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL);
363 if (!new_slot->hotplug_slot->info) {
364 kfree (new_slot->hotplug_slot);
368 memset(new_slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info));
369 new_slot->hotplug_slot->name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL);
370 if (!new_slot->hotplug_slot->name) {
371 kfree (new_slot->hotplug_slot->info);
372 kfree (new_slot->hotplug_slot);
377 new_slot->magic = SLOT_MAGIC;
378 new_slot->ctrl = ctrl;
379 new_slot->bus = ctrl->bus;
380 new_slot->device = slot_device;
381 new_slot->number = slot_number;
382 dbg("slot->number = %d\n",new_slot->number);
384 slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9, slot_entry);
386 while (slot_entry && (readw(slot_entry + SMBIOS_SLOT_NUMBER) != new_slot->number)) {
387 slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9, slot_entry);
390 new_slot->p_sm_slot = slot_entry;
392 init_timer(&new_slot->task_event);
393 new_slot->task_event.expires = jiffies + 5 * HZ;
394 new_slot->task_event.function = cpqhp_pushbutton_thread;
396 //FIXME: these capabilities aren't used but if they are
397 // they need to be correctly implemented
398 new_slot->capabilities |= PCISLOT_REPLACE_SUPPORTED;
399 new_slot->capabilities |= PCISLOT_INTERLOCK_SUPPORTED;
401 if (is_slot64bit(new_slot))
402 new_slot->capabilities |= PCISLOT_64_BIT_SUPPORTED;
403 if (is_slot66mhz(new_slot))
404 new_slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED;
405 if (ctrl->speed == PCI_SPEED_66MHz)
406 new_slot->capabilities |= PCISLOT_66_MHZ_OPERATION;
408 ctrl_slot = slot_device - (readb(ctrl->hpc_reg + SLOT_MASK) >> 4);
411 new_slot->capabilities |= ((((~tempdword) >> 23) | ((~tempdword) >> 15)) >> ctrl_slot) & 0x02;
412 // Check the switch state
413 new_slot->capabilities |= ((~tempdword & 0xFF) >> ctrl_slot) & 0x01;
414 // Check the slot enable
415 new_slot->capabilities |= ((read_slot_enable(ctrl) << 2) >> ctrl_slot) & 0x04;
417 /* register this slot with the hotplug pci core */
418 new_slot->hotplug_slot->release = &release_slot;
419 new_slot->hotplug_slot->private = new_slot;
420 make_slot_name (new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot);
421 new_slot->hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
423 new_slot->hotplug_slot->info->power_status = get_slot_enabled(ctrl, new_slot);
424 new_slot->hotplug_slot->info->attention_status = cpq_get_attention_status(ctrl, new_slot);
425 new_slot->hotplug_slot->info->latch_status = cpq_get_latch_status(ctrl, new_slot);
426 new_slot->hotplug_slot->info->adapter_status = get_presence_status(ctrl, new_slot);
428 dbg ("registering bus %d, dev %d, number %d, ctrl->slot_device_offset %d, slot %d\n",
429 new_slot->bus, new_slot->device, new_slot->number, ctrl->slot_device_offset, slot_number);
430 result = pci_hp_register (new_slot->hotplug_slot);
432 err ("pci_hp_register failed with error %d\n", result);
433 release_slot(new_slot->hotplug_slot);
437 new_slot->next = ctrl->slot;
438 ctrl->slot = new_slot;
448 static int ctrl_slot_cleanup (struct controller * ctrl)
450 struct slot *old_slot, *next_slot;
452 old_slot = ctrl->slot;
456 /* memory will be freed by the release_slot callback */
457 next_slot = old_slot->next;
458 pci_hp_deregister (old_slot->hotplug_slot);
459 old_slot = next_slot;
462 //Free IRQ associated with hot plug device
463 free_irq(ctrl->interrupt, ctrl);
465 iounmap(ctrl->hpc_reg);
466 //Finally reclaim PCI mem
467 release_mem_region(pci_resource_start(ctrl->pci_dev, 0),
468 pci_resource_len(ctrl->pci_dev, 0));
474 //============================================================================
475 // function: get_slot_mapping
477 // Description: Attempts to determine a logical slot mapping for a PCI
478 // device. Won't work for more than one PCI-PCI bridge
481 // Input: u8 bus_num - bus number of PCI device
482 // u8 dev_num - device number of PCI device
483 // u8 *slot - Pointer to u8 where slot number will
486 // Output: SUCCESS or FAILURE
487 //=============================================================================
488 static int get_slot_mapping (struct pci_bus *bus, u8 bus_num, u8 dev_num, u8 *slot)
490 struct irq_routing_table *PCIIRQRoutingInfoLength;
495 u8 tbus, tdevice, tslot, bridgeSlot;
497 dbg("%s: %p, %d, %d, %p\n", __FUNCTION__, bus, bus_num, dev_num, slot);
501 PCIIRQRoutingInfoLength = pcibios_get_irq_routing_table();
502 if (!PCIIRQRoutingInfoLength)
505 len = (PCIIRQRoutingInfoLength->size -
506 sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
507 // Make sure I got at least one entry
509 kfree(PCIIRQRoutingInfoLength);
513 for (loop = 0; loop < len; ++loop) {
514 tbus = PCIIRQRoutingInfoLength->slots[loop].bus;
515 tdevice = PCIIRQRoutingInfoLength->slots[loop].devfn >> 3;
516 tslot = PCIIRQRoutingInfoLength->slots[loop].slot;
518 if ((tbus == bus_num) && (tdevice == dev_num)) {
520 kfree(PCIIRQRoutingInfoLength);
523 // Didn't get a match on the target PCI device. Check if the
524 // current IRQ table entry is a PCI-to-PCI bridge device. If so,
525 // and it's secondary bus matches the bus number for the target
526 // device, I need to save the bridge's slot number. If I can't
527 // find an entry for the target device, I will have to assume it's
528 // on the other side of the bridge, and assign it the bridge's slot.
530 pci_bus_read_config_dword (bus, PCI_DEVFN(tdevice, 0), PCI_REVISION_ID, &work);
532 if ((work >> 8) == PCI_TO_PCI_BRIDGE_CLASS) {
533 pci_bus_read_config_dword (bus, PCI_DEVFN(tdevice, 0), PCI_PRIMARY_BUS, &work);
534 // See if bridge's secondary bus matches target bus.
535 if (((work >> 8) & 0x000000FF) == (long) bus_num) {
543 // If we got here, we didn't find an entry in the IRQ mapping table
544 // for the target PCI device. If we did determine that the target
545 // device is on the other side of a PCI-to-PCI bridge, return the
546 // slot number for the bridge.
547 if (bridgeSlot != 0xFF) {
549 kfree(PCIIRQRoutingInfoLength);
552 kfree(PCIIRQRoutingInfoLength);
553 // Couldn't find an entry in the routing table for this PCI device
559 * cpqhp_set_attention_status - Turns the Amber LED for a slot on or off
562 static int cpqhp_set_attention_status (struct controller *ctrl, struct pci_func *func, u32 status)
566 hp_slot = func->device - ctrl->slot_device_offset;
571 // Wait for exclusive access to hardware
572 down(&ctrl->crit_sect);
575 amber_LED_on (ctrl, hp_slot);
576 } else if (status == 0) {
577 amber_LED_off (ctrl, hp_slot);
579 // Done with exclusive hardware access
580 up(&ctrl->crit_sect);
586 // Wait for SOBS to be unset
587 wait_for_ctrl_irq (ctrl);
589 // Done with exclusive hardware access
590 up(&ctrl->crit_sect);
597 * set_attention_status - Turns the Amber LED for a slot on or off
600 static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
602 struct pci_func *slot_func;
603 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
604 struct controller *ctrl;
613 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
619 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
623 function = devfn & 0x7;
624 dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
626 slot_func = cpqhp_slot_find(bus, device, function);
631 return cpqhp_set_attention_status(ctrl, slot_func, status);
635 static int process_SI (struct hotplug_slot *hotplug_slot)
637 struct pci_func *slot_func;
638 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
639 struct controller *ctrl;
648 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
654 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
658 function = devfn & 0x7;
659 dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
661 slot_func = cpqhp_slot_find(bus, device, function);
666 slot_func->bus = bus;
667 slot_func->device = device;
668 slot_func->function = function;
669 slot_func->configured = 0;
670 dbg("board_added(%p, %p)\n", slot_func, ctrl);
671 return cpqhp_process_SI(ctrl, slot_func);
675 static int process_SS (struct hotplug_slot *hotplug_slot)
677 struct pci_func *slot_func;
678 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
679 struct controller *ctrl;
688 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
694 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
698 function = devfn & 0x7;
699 dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
701 slot_func = cpqhp_slot_find(bus, device, function);
706 dbg("In power_down_board, slot_func = %p, ctrl = %p\n", slot_func, ctrl);
707 return cpqhp_process_SS(ctrl, slot_func);
711 static int hardware_test (struct hotplug_slot *hotplug_slot, u32 value)
713 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
714 struct controller *ctrl;
716 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
725 return cpqhp_hardware_test (ctrl, value);
729 static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
731 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
732 struct controller *ctrl;
737 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
743 *value = get_slot_enabled(ctrl, slot);
747 static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
749 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
750 struct controller *ctrl;
755 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
761 *value = cpq_get_attention_status(ctrl, slot);
765 static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
767 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
768 struct controller *ctrl;
773 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
779 *value = cpq_get_latch_status (ctrl, slot);
784 static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
786 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
787 struct controller *ctrl;
792 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
798 *value = get_presence_status (ctrl, slot);
803 static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
805 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
806 struct controller *ctrl;
811 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
817 *value = ctrl->speed_capability;
822 static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
824 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
825 struct controller *ctrl;
830 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
836 *value = ctrl->speed;
841 static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
851 u16 subsystem_deviceid;
853 struct controller *ctrl;
854 struct pci_func *func;
856 // Need to read VID early b/c it's used to differentiate CPQ and INTC discovery
857 rc = pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor_id);
858 if (rc || ((vendor_id != PCI_VENDOR_ID_COMPAQ) && (vendor_id != PCI_VENDOR_ID_INTEL))) {
859 err(msg_HPC_non_compaq_or_intel);
862 dbg("Vendor ID: %x\n", vendor_id);
864 rc = pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
865 dbg("revision: %d\n", rev);
866 if (rc || ((vendor_id == PCI_VENDOR_ID_COMPAQ) && (!rev))) {
867 err(msg_HPC_rev_error);
871 /* Check for the proper subsytem ID's
872 * Intel uses a different SSID programming model than Compaq.
873 * For Intel, each SSID bit identifies a PHP capability.
874 * Also Intel HPC's may have RID=0.
876 if ((rev > 2) || (vendor_id == PCI_VENDOR_ID_INTEL)) {
877 // TODO: This code can be made to support non-Compaq or Intel subsystem IDs
878 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vid);
880 err("%s : pci_read_config_word failed\n", __FUNCTION__);
883 dbg("Subsystem Vendor ID: %x\n", subsystem_vid);
884 if ((subsystem_vid != PCI_VENDOR_ID_COMPAQ) && (subsystem_vid != PCI_VENDOR_ID_INTEL)) {
885 err(msg_HPC_non_compaq_or_intel);
889 ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL);
891 err("%s : out of memory\n", __FUNCTION__);
894 memset(ctrl, 0, sizeof(struct controller));
896 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsystem_deviceid);
898 err("%s : pci_read_config_word failed\n", __FUNCTION__);
902 info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid);
904 /* Set Vendor ID, so it can be accessed later from other functions */
905 ctrl->vendor_id = vendor_id;
907 switch (subsystem_vid) {
908 case PCI_VENDOR_ID_COMPAQ:
909 if (rev >= 0x13) { /* CIOBX */
911 ctrl->slot_switch_type = 1; // Switch is present
912 ctrl->push_button = 1; // Pushbutton is present
913 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
914 ctrl->defeature_PHP = 1; // PHP is supported
915 ctrl->pcix_support = 1; // PCI-X supported
916 ctrl->pcix_speed_capability = 1;
917 pci_read_config_byte(pdev, 0x41, &bus_cap);
918 if (bus_cap & 0x80) {
919 dbg("bus max supports 133MHz PCI-X\n");
920 ctrl->speed_capability = PCI_SPEED_133MHz_PCIX;
923 if (bus_cap & 0x40) {
924 dbg("bus max supports 100MHz PCI-X\n");
925 ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
929 dbg("bus max supports 66MHz PCI-X\n");
930 ctrl->speed_capability = PCI_SPEED_66MHz_PCIX;
934 dbg("bus max supports 66MHz PCI\n");
935 ctrl->speed_capability = PCI_SPEED_66MHz;
942 switch (subsystem_deviceid) {
944 /* Original 6500/7000 implementation */
945 ctrl->slot_switch_type = 1; // Switch is present
946 ctrl->speed_capability = PCI_SPEED_33MHz;
947 ctrl->push_button = 0; // No pushbutton
948 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
949 ctrl->defeature_PHP = 1; // PHP is supported
950 ctrl->pcix_support = 0; // PCI-X not supported
951 ctrl->pcix_speed_capability = 0; // N/A since PCI-X not supported
953 case PCI_SUB_HPC_ID2:
954 /* First Pushbutton implementation */
956 ctrl->slot_switch_type = 1; // Switch is present
957 ctrl->speed_capability = PCI_SPEED_33MHz;
958 ctrl->push_button = 1; // Pushbutton is present
959 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
960 ctrl->defeature_PHP = 1; // PHP is supported
961 ctrl->pcix_support = 0; // PCI-X not supported
962 ctrl->pcix_speed_capability = 0; // N/A since PCI-X not supported
964 case PCI_SUB_HPC_ID_INTC:
965 /* Third party (6500/7000) */
966 ctrl->slot_switch_type = 1; // Switch is present
967 ctrl->speed_capability = PCI_SPEED_33MHz;
968 ctrl->push_button = 0; // No pushbutton
969 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
970 ctrl->defeature_PHP = 1; // PHP is supported
971 ctrl->pcix_support = 0; // PCI-X not supported
972 ctrl->pcix_speed_capability = 0; // N/A since PCI-X not supported
974 case PCI_SUB_HPC_ID3:
975 /* First 66 Mhz implementation */
977 ctrl->slot_switch_type = 1; // Switch is present
978 ctrl->speed_capability = PCI_SPEED_66MHz;
979 ctrl->push_button = 1; // Pushbutton is present
980 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
981 ctrl->defeature_PHP = 1; // PHP is supported
982 ctrl->pcix_support = 0; // PCI-X not supported
983 ctrl->pcix_speed_capability = 0; // N/A since PCI-X not supported
985 case PCI_SUB_HPC_ID4:
986 /* First PCI-X implementation, 100MHz */
988 ctrl->slot_switch_type = 1; // Switch is present
989 ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
990 ctrl->push_button = 1; // Pushbutton is present
991 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
992 ctrl->defeature_PHP = 1; // PHP is supported
993 ctrl->pcix_support = 1; // PCI-X supported
994 ctrl->pcix_speed_capability = 0;
997 err(msg_HPC_not_supported);
1003 case PCI_VENDOR_ID_INTEL:
1004 /* Check for speed capability (0=33, 1=66) */
1005 if (subsystem_deviceid & 0x0001) {
1006 ctrl->speed_capability = PCI_SPEED_66MHz;
1008 ctrl->speed_capability = PCI_SPEED_33MHz;
1011 /* Check for push button */
1012 if (subsystem_deviceid & 0x0002) {
1013 /* no push button */
1014 ctrl->push_button = 0;
1016 /* push button supported */
1017 ctrl->push_button = 1;
1020 /* Check for slot switch type (0=mechanical, 1=not mechanical) */
1021 if (subsystem_deviceid & 0x0004) {
1023 ctrl->slot_switch_type = 0;
1026 ctrl->slot_switch_type = 1;
1029 /* PHP Status (0=De-feature PHP, 1=Normal operation) */
1030 if (subsystem_deviceid & 0x0008) {
1031 ctrl->defeature_PHP = 1; // PHP supported
1033 ctrl->defeature_PHP = 0; // PHP not supported
1036 /* Alternate Base Address Register Interface (0=not supported, 1=supported) */
1037 if (subsystem_deviceid & 0x0010) {
1038 ctrl->alternate_base_address = 1; // supported
1040 ctrl->alternate_base_address = 0; // not supported
1043 /* PCI Config Space Index (0=not supported, 1=supported) */
1044 if (subsystem_deviceid & 0x0020) {
1045 ctrl->pci_config_space = 1; // supported
1047 ctrl->pci_config_space = 0; // not supported
1051 if (subsystem_deviceid & 0x0080) {
1053 ctrl->pcix_support = 1;
1054 /* Frequency of operation in PCI-X mode */
1055 if (subsystem_deviceid & 0x0040) {
1056 /* 133MHz PCI-X if bit 7 is 1 */
1057 ctrl->pcix_speed_capability = 1;
1059 /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
1060 /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
1061 ctrl->pcix_speed_capability = 0;
1064 /* Conventional PCI */
1065 ctrl->pcix_support = 0;
1066 ctrl->pcix_speed_capability = 0;
1071 err(msg_HPC_not_supported);
1077 err(msg_HPC_not_supported);
1081 // Tell the user that we found one.
1082 info("Initializing the PCI hot plug controller residing on PCI bus %d\n", pdev->bus->number);
1084 dbg ("Hotplug controller capabilities:\n");
1085 dbg (" speed_capability %d\n", ctrl->speed_capability);
1086 dbg (" slot_switch_type %s\n", ctrl->slot_switch_type == 0 ? "no switch" : "switch present");
1087 dbg (" defeature_PHP %s\n", ctrl->defeature_PHP == 0 ? "PHP not supported" : "PHP supported");
1088 dbg (" alternate_base_address %s\n", ctrl->alternate_base_address == 0 ? "not supported" : "supported");
1089 dbg (" pci_config_space %s\n", ctrl->pci_config_space == 0 ? "not supported" : "supported");
1090 dbg (" pcix_speed_capability %s\n", ctrl->pcix_speed_capability == 0 ? "not supported" : "supported");
1091 dbg (" pcix_support %s\n", ctrl->pcix_support == 0 ? "not supported" : "supported");
1093 ctrl->pci_dev = pdev;
1094 pci_set_drvdata(pdev, ctrl);
1096 /* make our own copy of the pci bus structure, as we like tweaking it a lot */
1097 ctrl->pci_bus = kmalloc (sizeof (*ctrl->pci_bus), GFP_KERNEL);
1098 if (!ctrl->pci_bus) {
1099 err("out of memory\n");
1103 memcpy (ctrl->pci_bus, pdev->bus, sizeof (*ctrl->pci_bus));
1105 ctrl->bus = pdev->bus->number;
1107 dbg("bus device function rev: %d %d %d %d\n", ctrl->bus,
1108 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), ctrl->rev);
1110 init_MUTEX(&ctrl->crit_sect);
1111 init_waitqueue_head(&ctrl->queue);
1113 /* initialize our threads if they haven't already been started up */
1114 rc = one_time_init();
1119 dbg("pdev = %p\n", pdev);
1120 dbg("pci resource start %lx\n", pci_resource_start(pdev, 0));
1121 dbg("pci resource len %lx\n", pci_resource_len(pdev, 0));
1123 if (!request_mem_region(pci_resource_start(pdev, 0),
1124 pci_resource_len(pdev, 0), MY_NAME)) {
1125 err("cannot reserve MMIO region\n");
1130 ctrl->hpc_reg = ioremap(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
1131 if (!ctrl->hpc_reg) {
1132 err("cannot remap MMIO region %lx @ %lx\n", pci_resource_len(pdev, 0), pci_resource_start(pdev, 0));
1134 goto err_free_mem_region;
1137 // Check for 66Mhz operation
1138 ctrl->speed = get_controller_speed(ctrl);
1141 //**************************************************
1143 // Save configuration headers for this and
1144 // subordinate PCI buses
1146 //**************************************************
1148 // find the physical slot number of the first hot plug slot
1150 // Get slot won't work for devices behind bridges, but
1151 // in this case it will always be called for the "base"
1152 // bus/dev/func of a slot.
1153 // CS: this is leveraging the PCIIRQ routing code from the kernel (pci-pc.c: get_irq_routing_table)
1154 rc = get_slot_mapping(ctrl->pci_bus, pdev->bus->number, (readb(ctrl->hpc_reg + SLOT_MASK) >> 4), &(ctrl->first_slot));
1155 dbg("get_slot_mapping: first_slot = %d, returned = %d\n", ctrl->first_slot, rc);
1157 err(msg_initialization_err, rc);
1161 // Store PCI Config Space for all devices on this bus
1162 rc = cpqhp_save_config(ctrl, ctrl->bus, readb(ctrl->hpc_reg + SLOT_MASK));
1164 err("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc);
1169 * Get IO, memory, and IRQ resources for new devices
1171 // The next line is required for cpqhp_find_available_resources
1172 ctrl->interrupt = pdev->irq;
1173 if (ctrl->interrupt < 0x10) {
1174 cpqhp_legacy_mode = 1;
1175 dbg("System seems to be configured for Full Table Mapped MPS mode\n");
1178 ctrl->cfgspc_irq = 0;
1179 pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &ctrl->cfgspc_irq);
1181 rc = cpqhp_find_available_resources(ctrl, cpqhp_rom_start);
1182 ctrl->add_support = !rc;
1184 dbg("cpqhp_find_available_resources = 0x%x\n", rc);
1185 err("unable to locate PCI configuration resources for hot plug add.\n");
1190 * Finish setting up the hot plug ctrl device
1192 ctrl->slot_device_offset = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
1193 dbg("NumSlots %d \n", ctrl->slot_device_offset);
1195 ctrl->next_event = 0;
1197 /* Setup the slot information structures */
1198 rc = ctrl_slot_setup(ctrl, smbios_start, smbios_table);
1200 err(msg_initialization_err, 6);
1201 err("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc);
1205 /* Mask all general input interrupts */
1206 writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_MASK);
1208 /* set up the interrupt */
1209 dbg("HPC interrupt = %d \n", ctrl->interrupt);
1210 if (request_irq(ctrl->interrupt, cpqhp_ctrl_intr,
1211 SA_SHIRQ, MY_NAME, ctrl)) {
1212 err("Can't get irq %d for the hotplug pci controller\n", ctrl->interrupt);
1217 /* Enable Shift Out interrupt and clear it, also enable SERR on power fault */
1218 temp_word = readw(ctrl->hpc_reg + MISC);
1219 temp_word |= 0x4006;
1220 writew(temp_word, ctrl->hpc_reg + MISC);
1222 // Changed 05/05/97 to clear all interrupts at start
1223 writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_INPUT_CLEAR);
1225 ctrl->ctrl_int_comp = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
1227 writel(0x0L, ctrl->hpc_reg + INT_MASK);
1229 if (!cpqhp_ctrl_list) {
1230 cpqhp_ctrl_list = ctrl;
1233 ctrl->next = cpqhp_ctrl_list;
1234 cpqhp_ctrl_list = ctrl;
1237 // turn off empty slots here unless command line option "ON" set
1238 // Wait for exclusive access to hardware
1239 down(&ctrl->crit_sect);
1241 num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
1243 // find first device number for the ctrl
1244 device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
1246 while (num_of_slots) {
1247 dbg("num_of_slots: %d\n", num_of_slots);
1248 func = cpqhp_slot_find(ctrl->bus, device, 0);
1252 hp_slot = func->device - ctrl->slot_device_offset;
1253 dbg("hp_slot: %d\n", hp_slot);
1255 // We have to save the presence info for these slots
1256 temp_word = ctrl->ctrl_int_comp >> 16;
1257 func->presence_save = (temp_word >> hp_slot) & 0x01;
1258 func->presence_save |= (temp_word >> (hp_slot + 7)) & 0x02;
1260 if (ctrl->ctrl_int_comp & (0x1L << hp_slot)) {
1261 func->switch_save = 0;
1263 func->switch_save = 0x10;
1267 if (!func->is_a_board) {
1268 green_LED_off (ctrl, hp_slot);
1269 slot_disable (ctrl, hp_slot);
1279 // Wait for SOBS to be unset
1280 wait_for_ctrl_irq (ctrl);
1283 rc = init_SERR(ctrl);
1285 err("init_SERR failed\n");
1286 up(&ctrl->crit_sect);
1290 // Done with exclusive hardware access
1291 up(&ctrl->crit_sect);
1293 cpqhp_create_ctrl_files (ctrl);
1298 free_irq(ctrl->interrupt, ctrl);
1300 iounmap(ctrl->hpc_reg);
1301 err_free_mem_region:
1302 release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
1304 kfree(ctrl->pci_bus);
1311 static int one_time_init(void)
1315 static int initialized = 0;
1322 retval = pci_print_IRQ_route();
1326 dbg("Initialize + Start the notification mechanism \n");
1328 retval = cpqhp_event_start_thread();
1332 dbg("Initialize slot lists\n");
1333 for (loop = 0; loop < 256; loop++) {
1334 cpqhp_slot_list[loop] = NULL;
1337 // FIXME: We also need to hook the NMI handler eventually.
1338 // this also needs to be worked with Christoph
1339 // register_NMI_handler();
1342 cpqhp_rom_start = ioremap(ROM_PHY_ADDR, ROM_PHY_LEN);
1343 if (!cpqhp_rom_start) {
1344 err ("Could not ioremap memory region for ROM\n");
1349 /* Now, map the int15 entry point if we are on compaq specific hardware */
1350 compaq_nvram_init(cpqhp_rom_start);
1352 /* Map smbios table entry point structure */
1353 smbios_table = detect_SMBIOS_pointer(cpqhp_rom_start, cpqhp_rom_start + ROM_PHY_LEN);
1354 if (!smbios_table) {
1355 err ("Could not find the SMBIOS pointer in memory\n");
1360 smbios_start = ioremap(readl(smbios_table + ST_ADDRESS), readw(smbios_table + ST_LENGTH));
1361 if (!smbios_start) {
1362 err ("Could not ioremap memory region taken from SMBIOS values\n");
1372 if (cpqhp_rom_start)
1373 iounmap(cpqhp_rom_start);
1375 iounmap(smbios_start);
1381 static void unload_cpqphpd(void)
1383 struct pci_func *next;
1384 struct pci_func *TempSlot;
1387 struct controller *ctrl;
1388 struct controller *tctrl;
1389 struct pci_resource *res;
1390 struct pci_resource *tres;
1392 rc = compaq_nvram_store(cpqhp_rom_start);
1394 ctrl = cpqhp_ctrl_list;
1397 if (ctrl->hpc_reg) {
1399 rc = read_slot_enable (ctrl);
1401 writeb(0, ctrl->hpc_reg + SLOT_SERR);
1402 writel(0xFFFFFFC0L | ~rc, ctrl->hpc_reg + INT_MASK);
1404 misc = readw(ctrl->hpc_reg + MISC);
1406 writew(misc, ctrl->hpc_reg + MISC);
1409 ctrl_slot_cleanup(ctrl);
1411 res = ctrl->io_head;
1418 res = ctrl->mem_head;
1425 res = ctrl->p_mem_head;
1432 res = ctrl->bus_head;
1439 kfree (ctrl->pci_bus);
1446 for (loop = 0; loop < 256; loop++) {
1447 next = cpqhp_slot_list[loop];
1448 while (next != NULL) {
1449 res = next->io_head;
1456 res = next->mem_head;
1463 res = next->p_mem_head;
1470 res = next->bus_head;
1483 // Stop the notification mechanism
1484 cpqhp_event_stop_thread();
1486 //unmap the rom address
1487 if (cpqhp_rom_start)
1488 iounmap(cpqhp_rom_start);
1490 iounmap(smbios_start);
1495 static struct pci_device_id hpcd_pci_tbl[] = {
1497 /* handle any PCI Hotplug controller */
1498 .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00),
1501 /* no matter who makes it */
1502 .vendor = PCI_ANY_ID,
1503 .device = PCI_ANY_ID,
1504 .subvendor = PCI_ANY_ID,
1505 .subdevice = PCI_ANY_ID,
1507 }, { /* end: all zeroes */ }
1510 MODULE_DEVICE_TABLE(pci, hpcd_pci_tbl);
1514 static struct pci_driver cpqhpc_driver = {
1515 .name = "pci_hotplug",
1516 .id_table = hpcd_pci_tbl,
1517 .probe = cpqhpc_probe,
1518 /* remove: cpqhpc_remove_one, */
1523 static int __init cpqhpc_init(void)
1527 cpqhp_debug = debug;
1529 result = pci_module_init(&cpqhpc_driver);
1530 dbg("pci_module_init = %d\n", result);
1533 info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
1538 static void __exit cpqhpc_cleanup(void)
1540 dbg("unload_cpqphpd()\n");
1543 dbg("pci_unregister_driver\n");
1544 pci_unregister_driver(&cpqhpc_driver);
1548 module_init(cpqhpc_init);
1549 module_exit(cpqhpc_cleanup);