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/miscdevice.h>
38 #include <linux/slab.h>
39 #include <linux/pci.h>
40 #include <linux/init.h>
41 #include <asm/uaccess.h>
43 #include "cpqphp_nvram.h"
44 #include "../../arch/i386/kernel/pci-i386.h" /* horrible hack showing how processor dependant we are... */
47 /* Global variables */
49 struct controller *cpqhp_ctrl_list; /* = NULL */
50 struct pci_func *cpqhp_slot_list[256];
53 static void *smbios_table;
54 static void *smbios_start;
55 static void *cpqhp_rom_start;
59 #define DRIVER_VERSION "0.9.7"
60 #define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>"
61 #define DRIVER_DESC "Compaq Hot Plug PCI Controller Driver"
63 MODULE_AUTHOR(DRIVER_AUTHOR);
64 MODULE_DESCRIPTION(DRIVER_DESC);
65 MODULE_LICENSE("GPL");
67 MODULE_PARM(power_mode, "b");
68 MODULE_PARM_DESC(power_mode, "Power mode enabled or not");
70 MODULE_PARM(debug, "i");
71 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
73 #define CPQHPC_MODULE_MINOR 208
75 static int one_time_init (void);
76 static int set_attention_status (struct hotplug_slot *slot, u8 value);
77 static int process_SI (struct hotplug_slot *slot);
78 static int process_SS (struct hotplug_slot *slot);
79 static int hardware_test (struct hotplug_slot *slot, u32 value);
80 static int get_power_status (struct hotplug_slot *slot, u8 *value);
81 static int get_attention_status (struct hotplug_slot *slot, u8 *value);
82 static int get_latch_status (struct hotplug_slot *slot, u8 *value);
83 static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
84 static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
85 static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
87 static struct hotplug_slot_ops cpqphp_hotplug_slot_ops = {
89 .set_attention_status = set_attention_status,
90 .enable_slot = process_SI,
91 .disable_slot = process_SS,
92 .hardware_test = hardware_test,
93 .get_power_status = get_power_status,
94 .get_attention_status = get_attention_status,
95 .get_latch_status = get_latch_status,
96 .get_adapter_status = get_adapter_status,
97 .get_max_bus_speed = get_max_bus_speed,
98 .get_cur_bus_speed = get_cur_bus_speed,
102 static inline int is_slot64bit (struct slot *slot)
104 if (!slot || !slot->p_sm_slot)
107 if (readb(slot->p_sm_slot + SMBIOS_SLOT_WIDTH) == 0x06)
113 static inline int is_slot66mhz (struct slot *slot)
115 if (!slot || !slot->p_sm_slot)
118 if (readb(slot->p_sm_slot + SMBIOS_SLOT_TYPE) == 0x0E)
125 * detect_SMBIOS_pointer - find the system Management BIOS Table in the specified region of memory.
127 * @begin: begin pointer for region to be scanned.
128 * @end: end pointer for region to be scanned.
130 * Returns pointer to the head of the SMBIOS tables (or NULL)
133 static void * detect_SMBIOS_pointer(void *begin, void *end)
137 u8 temp1, temp2, temp3, temp4;
140 endp = (end - sizeof(u32) + 1);
142 for (fp = begin; fp <= endp; fp += 16) {
159 dbg("Discovered SMBIOS Entry point at %p\n", fp);
165 * init_SERR - Initializes the per slot SERR generation.
167 * For unexpected switch opens
170 static int init_SERR(struct controller * ctrl)
179 tempdword = ctrl->first_slot;
181 number_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
182 // Loop through slots
183 while (number_of_slots) {
184 physical_slot = tempdword;
185 writeb(0, ctrl->hpc_reg + SLOT_SERR);
194 /* nice debugging output */
195 static int pci_print_IRQ_route (void)
197 struct irq_routing_table *routing_table;
201 u8 tbus, tdevice, tslot;
203 routing_table = pcibios_get_irq_routing_table();
204 if (routing_table == NULL) {
205 err("No BIOS Routing Table??? Not good\n");
209 len = (routing_table->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
210 // Make sure I got at least one entry
212 kfree(routing_table);
216 dbg("bus dev func slot\n");
218 for (loop = 0; loop < len; ++loop) {
219 tbus = routing_table->slots[loop].bus;
220 tdevice = routing_table->slots[loop].devfn;
221 tslot = routing_table->slots[loop].slot;
222 dbg("%d %d %d %d\n", tbus, tdevice >> 3, tdevice & 0x7, tslot);
225 kfree(routing_table);
231 * get_subsequent_smbios_entry
233 * Gets the first entry if previous == NULL
234 * Otherwise, returns the next entry
235 * Uses global SMBIOS Table pointer
237 * @curr: %NULL or pointer to previously returned structure
239 * returns a pointer to an SMBIOS structure or NULL if none found
241 static void * get_subsequent_smbios_entry(void *smbios_start, void *smbios_table, void *curr)
244 u8 previous_byte = 1;
248 if (!smbios_table || !curr)
251 // set p_max to the end of the table
252 p_max = smbios_start + readw(smbios_table + ST_LENGTH);
255 p_temp += readb(curr + SMBIOS_GENERIC_LENGTH);
257 while ((p_temp < p_max) && !bail) {
258 // Look for the double NULL terminator
259 // The first condition is the previous byte and the second is the curr
260 if (!previous_byte && !(readb(p_temp))) {
264 previous_byte = readb(p_temp);
268 if (p_temp < p_max) {
279 * @type:SMBIOS structure type to be returned
280 * @previous: %NULL or pointer to previously returned structure
282 * Gets the first entry of the specified type if previous == NULL
283 * Otherwise, returns the next entry of the given type.
284 * Uses global SMBIOS Table pointer
285 * Uses get_subsequent_smbios_entry
287 * returns a pointer to an SMBIOS structure or %NULL if none found
289 static void *get_SMBIOS_entry (void *smbios_start, void *smbios_table, u8 type, void * previous)
295 previous = smbios_start;
297 previous = get_subsequent_smbios_entry(smbios_start, smbios_table, previous);
301 if (readb(previous + SMBIOS_GENERIC_TYPE) != type) {
302 previous = get_subsequent_smbios_entry(smbios_start, smbios_table, previous);
312 static int ctrl_slot_setup (struct controller * ctrl, void *smbios_start, void *smbios_table)
314 struct slot *new_slot;
320 void *slot_entry= NULL;
323 dbg("%s\n", __FUNCTION__);
325 tempdword = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
327 number_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
328 slot_device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
329 slot_number = ctrl->first_slot;
331 while (number_of_slots) {
332 new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL);
336 memset(new_slot, 0, sizeof(struct slot));
337 new_slot->hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL);
338 if (!new_slot->hotplug_slot) {
342 memset(new_slot->hotplug_slot, 0, sizeof (struct hotplug_slot));
344 new_slot->hotplug_slot->info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL);
345 if (!new_slot->hotplug_slot->info) {
346 kfree (new_slot->hotplug_slot);
350 memset(new_slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info));
351 new_slot->hotplug_slot->name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL);
352 if (!new_slot->hotplug_slot->name) {
353 kfree (new_slot->hotplug_slot->info);
354 kfree (new_slot->hotplug_slot);
359 new_slot->magic = SLOT_MAGIC;
360 new_slot->ctrl = ctrl;
361 new_slot->bus = ctrl->bus;
362 new_slot->device = slot_device;
363 new_slot->number = slot_number;
364 dbg("slot->number = %d\n",new_slot->number);
366 slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9, slot_entry);
368 while (slot_entry && (readw(slot_entry + SMBIOS_SLOT_NUMBER) != new_slot->number)) {
369 slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9, slot_entry);
372 new_slot->p_sm_slot = slot_entry;
374 init_timer(&new_slot->task_event);
375 new_slot->task_event.expires = jiffies + 5 * HZ;
376 new_slot->task_event.function = cpqhp_pushbutton_thread;
378 //FIXME: these capabilities aren't used but if they are
379 // they need to be correctly implemented
380 new_slot->capabilities |= PCISLOT_REPLACE_SUPPORTED;
381 new_slot->capabilities |= PCISLOT_INTERLOCK_SUPPORTED;
383 if (is_slot64bit(new_slot))
384 new_slot->capabilities |= PCISLOT_64_BIT_SUPPORTED;
385 if (is_slot66mhz(new_slot))
386 new_slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED;
387 if (ctrl->speed == PCI_SPEED_66MHz)
388 new_slot->capabilities |= PCISLOT_66_MHZ_OPERATION;
390 ctrl_slot = slot_device - (readb(ctrl->hpc_reg + SLOT_MASK) >> 4);
393 new_slot->capabilities |= ((((~tempdword) >> 23) | ((~tempdword) >> 15)) >> ctrl_slot) & 0x02;
394 // Check the switch state
395 new_slot->capabilities |= ((~tempdword & 0xFF) >> ctrl_slot) & 0x01;
396 // Check the slot enable
397 new_slot->capabilities |= ((read_slot_enable(ctrl) << 2) >> ctrl_slot) & 0x04;
399 /* register this slot with the hotplug pci core */
400 new_slot->hotplug_slot->private = new_slot;
401 make_slot_name (new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot);
402 new_slot->hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
404 new_slot->hotplug_slot->info->power_status = get_slot_enabled(ctrl, new_slot);
405 new_slot->hotplug_slot->info->attention_status = cpq_get_attention_status(ctrl, new_slot);
406 new_slot->hotplug_slot->info->latch_status = cpq_get_latch_status(ctrl, new_slot);
407 new_slot->hotplug_slot->info->adapter_status = get_presence_status(ctrl, new_slot);
409 dbg ("registering bus %d, dev %d, number %d, ctrl->slot_device_offset %d, slot %d\n",
410 new_slot->bus, new_slot->device, new_slot->number, ctrl->slot_device_offset, slot_number);
411 result = pci_hp_register (new_slot->hotplug_slot);
413 err ("pci_hp_register failed with error %d\n", result);
414 kfree (new_slot->hotplug_slot->info);
415 kfree (new_slot->hotplug_slot->name);
416 kfree (new_slot->hotplug_slot);
421 new_slot->next = ctrl->slot;
422 ctrl->slot = new_slot;
433 static int ctrl_slot_cleanup (struct controller * ctrl)
435 struct slot *old_slot, *next_slot;
437 old_slot = ctrl->slot;
441 next_slot = old_slot->next;
442 pci_hp_deregister (old_slot->hotplug_slot);
443 kfree(old_slot->hotplug_slot->info);
444 kfree(old_slot->hotplug_slot->name);
445 kfree(old_slot->hotplug_slot);
447 old_slot = next_slot;
450 //Free IRQ associated with hot plug device
451 free_irq(ctrl->interrupt, ctrl);
453 iounmap(ctrl->hpc_reg);
454 //Finally reclaim PCI mem
455 release_mem_region(pci_resource_start(ctrl->pci_dev, 0),
456 pci_resource_len(ctrl->pci_dev, 0));
462 //============================================================================
463 // function: get_slot_mapping
465 // Description: Attempts to determine a logical slot mapping for a PCI
466 // device. Won't work for more than one PCI-PCI bridge
469 // Input: u8 bus_num - bus number of PCI device
470 // u8 dev_num - device number of PCI device
471 // u8 *slot - Pointer to u8 where slot number will
474 // Output: SUCCESS or FAILURE
475 //=============================================================================
476 static int get_slot_mapping (struct pci_ops *ops, u8 bus_num, u8 dev_num, u8 *slot)
478 struct irq_routing_table *PCIIRQRoutingInfoLength;
483 u8 tbus, tdevice, tslot, bridgeSlot;
485 dbg("%s %p, %d, %d, %p\n", __FUNCTION__, ops, bus_num, dev_num, slot);
489 PCIIRQRoutingInfoLength = pcibios_get_irq_routing_table();
491 len = (PCIIRQRoutingInfoLength->size -
492 sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
493 // Make sure I got at least one entry
495 if (PCIIRQRoutingInfoLength != NULL) kfree(PCIIRQRoutingInfoLength );
500 for (loop = 0; loop < len; ++loop) {
501 tbus = PCIIRQRoutingInfoLength->slots[loop].bus;
502 tdevice = PCIIRQRoutingInfoLength->slots[loop].devfn >> 3;
503 tslot = PCIIRQRoutingInfoLength->slots[loop].slot;
505 if ((tbus == bus_num) && (tdevice == dev_num)) {
508 if (PCIIRQRoutingInfoLength != NULL) kfree(PCIIRQRoutingInfoLength );
511 // Didn't get a match on the target PCI device. Check if the
512 // current IRQ table entry is a PCI-to-PCI bridge device. If so,
513 // and it's secondary bus matches the bus number for the target
514 // device, I need to save the bridge's slot number. If I can't
515 // find an entry for the target device, I will have to assume it's
516 // on the other side of the bridge, and assign it the bridge's slot.
517 pci_read_config_dword_nodev (ops, tbus, tdevice, 0, PCI_REVISION_ID, &work);
519 if ((work >> 8) == PCI_TO_PCI_BRIDGE_CLASS) {
520 pci_read_config_dword_nodev (ops, tbus, tdevice, 0, PCI_PRIMARY_BUS, &work);
521 // See if bridge's secondary bus matches target bus.
522 if (((work >> 8) & 0x000000FF) == (long) bus_num) {
531 // If we got here, we didn't find an entry in the IRQ mapping table
532 // for the target PCI device. If we did determine that the target
533 // device is on the other side of a PCI-to-PCI bridge, return the
534 // slot number for the bridge.
535 if (bridgeSlot != 0xFF) {
537 if (PCIIRQRoutingInfoLength != NULL) kfree(PCIIRQRoutingInfoLength );
540 if (PCIIRQRoutingInfoLength != NULL) kfree(PCIIRQRoutingInfoLength );
541 // Couldn't find an entry in the routing table for this PCI device
547 * cpqhp_set_attention_status - Turns the Amber LED for a slot on or off
550 static int cpqhp_set_attention_status (struct controller *ctrl, struct pci_func *func, u32 status)
554 hp_slot = func->device - ctrl->slot_device_offset;
559 // Wait for exclusive access to hardware
560 down(&ctrl->crit_sect);
563 amber_LED_on (ctrl, hp_slot);
564 } else if (status == 0) {
565 amber_LED_off (ctrl, hp_slot);
567 // Done with exclusive hardware access
568 up(&ctrl->crit_sect);
574 // Wait for SOBS to be unset
575 wait_for_ctrl_irq (ctrl);
577 // Done with exclusive hardware access
578 up(&ctrl->crit_sect);
585 * set_attention_status - Turns the Amber LED for a slot on or off
588 static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
590 struct pci_func *slot_func;
591 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
592 struct controller *ctrl;
601 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
607 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
611 function = devfn & 0x7;
612 dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
614 slot_func = cpqhp_slot_find(bus, device, function);
619 return cpqhp_set_attention_status(ctrl, slot_func, status);
623 static int process_SI (struct hotplug_slot *hotplug_slot)
625 struct pci_func *slot_func;
626 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
627 struct controller *ctrl;
636 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
642 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
646 function = devfn & 0x7;
647 dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
649 slot_func = cpqhp_slot_find(bus, device, function);
654 slot_func->bus = bus;
655 slot_func->device = device;
656 slot_func->function = function;
657 slot_func->configured = 0;
658 dbg("board_added(%p, %p)\n", slot_func, ctrl);
659 return cpqhp_process_SI(ctrl, slot_func);
663 static int process_SS (struct hotplug_slot *hotplug_slot)
665 struct pci_func *slot_func;
666 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
667 struct controller *ctrl;
676 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
682 if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
686 function = devfn & 0x7;
687 dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
689 slot_func = cpqhp_slot_find(bus, device, function);
694 dbg("In power_down_board, slot_func = %p, ctrl = %p\n", slot_func, ctrl);
695 return cpqhp_process_SS(ctrl, slot_func);
699 static int hardware_test (struct hotplug_slot *hotplug_slot, u32 value)
701 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
702 struct controller *ctrl;
704 dbg("%s\n", __FUNCTION__);
713 return cpqhp_hardware_test (ctrl, value);
717 static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
719 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
720 struct controller *ctrl;
725 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
731 *value = get_slot_enabled(ctrl, slot);
735 static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
737 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
738 struct controller *ctrl;
743 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
749 *value = cpq_get_attention_status(ctrl, slot);
753 static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
755 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
756 struct controller *ctrl;
761 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
767 *value = cpq_get_latch_status (ctrl, slot);
772 static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
774 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
775 struct controller *ctrl;
780 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
786 *value = get_presence_status (ctrl, slot);
791 static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
793 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
794 struct controller *ctrl;
799 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
805 *value = ctrl->speed_capability;
810 static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
812 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
813 struct controller *ctrl;
818 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
824 *value = ctrl->speed;
829 static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
839 u16 subsystem_deviceid;
841 struct controller *ctrl;
842 struct pci_func *func;
844 // Need to read VID early b/c it's used to differentiate CPQ and INTC discovery
845 rc = pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor_id);
846 if (rc || ((vendor_id != PCI_VENDOR_ID_COMPAQ) && (vendor_id != PCI_VENDOR_ID_INTEL))) {
847 err(msg_HPC_non_compaq_or_intel);
850 dbg("Vendor ID: %x\n", vendor_id);
852 rc = pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
853 dbg("revision: %d\n", rev);
854 if (rc || ((vendor_id == PCI_VENDOR_ID_COMPAQ) && (!rev))) {
855 err(msg_HPC_rev_error);
859 /* Check for the proper subsytem ID's
860 * Intel uses a different SSID programming model than Compaq.
861 * For Intel, each SSID bit identifies a PHP capability.
862 * Also Intel HPC's may have RID=0.
864 if ((rev > 2) || (vendor_id == PCI_VENDOR_ID_INTEL)) {
865 // TODO: This code can be made to support non-Compaq or Intel subsystem IDs
866 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vid);
868 err("%s : pci_read_config_word failed\n", __FUNCTION__);
871 dbg("Subsystem Vendor ID: %x\n", subsystem_vid);
872 if ((subsystem_vid != PCI_VENDOR_ID_COMPAQ) && (subsystem_vid != PCI_VENDOR_ID_INTEL)) {
873 err(msg_HPC_non_compaq_or_intel);
877 ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL);
879 err("%s : out of memory\n", __FUNCTION__);
882 memset(ctrl, 0, sizeof(struct controller));
884 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsystem_deviceid);
886 err("%s : pci_read_config_word failed\n", __FUNCTION__);
890 info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid);
892 /* Set Vendor ID, so it can be accessed later from other functions */
893 ctrl->vendor_id = vendor_id;
895 switch (subsystem_vid) {
896 case PCI_VENDOR_ID_COMPAQ:
897 if (rev >= 0x13) { /* CIOBX */
899 ctrl->slot_switch_type = 1; // Switch is present
900 ctrl->push_button = 1; // Pushbutton is present
901 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
902 ctrl->defeature_PHP = 1; // PHP is supported
903 ctrl->pcix_support = 1; // PCI-X supported
904 ctrl->pcix_speed_capability = 1;
905 pci_read_config_byte(pdev, 0x41, &bus_cap);
906 if (bus_cap & 0x80) {
907 dbg("bus max supports 133MHz PCI-X\n");
908 ctrl->speed_capability = PCI_SPEED_133MHz_PCIX;
911 if (bus_cap & 0x40) {
912 dbg("bus max supports 100MHz PCI-X\n");
913 ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
917 dbg("bus max supports 66MHz PCI-X\n");
918 ctrl->speed_capability = PCI_SPEED_66MHz_PCIX;
922 dbg("bus max supports 66MHz PCI\n");
923 ctrl->speed_capability = PCI_SPEED_66MHz;
930 switch (subsystem_deviceid) {
932 /* Original 6500/7000 implementation */
933 ctrl->slot_switch_type = 1; // Switch is present
934 ctrl->speed_capability = PCI_SPEED_33MHz;
935 ctrl->push_button = 0; // No pushbutton
936 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
937 ctrl->defeature_PHP = 1; // PHP is supported
938 ctrl->pcix_support = 0; // PCI-X not supported
939 ctrl->pcix_speed_capability = 0; // N/A since PCI-X not supported
941 case PCI_SUB_HPC_ID2:
942 /* First Pushbutton implementation */
944 ctrl->slot_switch_type = 1; // Switch is present
945 ctrl->speed_capability = PCI_SPEED_33MHz;
946 ctrl->push_button = 1; // Pushbutton is present
947 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
948 ctrl->defeature_PHP = 1; // PHP is supported
949 ctrl->pcix_support = 0; // PCI-X not supported
950 ctrl->pcix_speed_capability = 0; // N/A since PCI-X not supported
952 case PCI_SUB_HPC_ID_INTC:
953 /* Third party (6500/7000) */
954 ctrl->slot_switch_type = 1; // Switch is present
955 ctrl->speed_capability = PCI_SPEED_33MHz;
956 ctrl->push_button = 0; // No pushbutton
957 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
958 ctrl->defeature_PHP = 1; // PHP is supported
959 ctrl->pcix_support = 0; // PCI-X not supported
960 ctrl->pcix_speed_capability = 0; // N/A since PCI-X not supported
962 case PCI_SUB_HPC_ID3:
963 /* First 66 Mhz implementation */
965 ctrl->slot_switch_type = 1; // Switch is present
966 ctrl->speed_capability = PCI_SPEED_66MHz;
967 ctrl->push_button = 1; // Pushbutton is present
968 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
969 ctrl->defeature_PHP = 1; // PHP is supported
970 ctrl->pcix_support = 0; // PCI-X not supported
971 ctrl->pcix_speed_capability = 0; // N/A since PCI-X not supported
973 case PCI_SUB_HPC_ID4:
974 /* First PCI-X implementation, 100MHz */
976 ctrl->slot_switch_type = 1; // Switch is present
977 ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
978 ctrl->push_button = 1; // Pushbutton is present
979 ctrl->pci_config_space = 1; // Index/data access to working registers 0 = not supported, 1 = supported
980 ctrl->defeature_PHP = 1; // PHP is supported
981 ctrl->pcix_support = 1; // PCI-X supported
982 ctrl->pcix_speed_capability = 0;
985 err(msg_HPC_not_supported);
991 case PCI_VENDOR_ID_INTEL:
992 /* Check for speed capability (0=33, 1=66) */
993 if (subsystem_deviceid & 0x0001) {
994 ctrl->speed_capability = PCI_SPEED_66MHz;
996 ctrl->speed_capability = PCI_SPEED_33MHz;
999 /* Check for push button */
1000 if (subsystem_deviceid & 0x0002) {
1001 /* no push button */
1002 ctrl->push_button = 0;
1004 /* push button supported */
1005 ctrl->push_button = 1;
1008 /* Check for slot switch type (0=mechanical, 1=not mechanical) */
1009 if (subsystem_deviceid & 0x0004) {
1011 ctrl->slot_switch_type = 0;
1014 ctrl->slot_switch_type = 1;
1017 /* PHP Status (0=De-feature PHP, 1=Normal operation) */
1018 if (subsystem_deviceid & 0x0008) {
1019 ctrl->defeature_PHP = 1; // PHP supported
1021 ctrl->defeature_PHP = 0; // PHP not supported
1024 /* Alternate Base Address Register Interface (0=not supported, 1=supported) */
1025 if (subsystem_deviceid & 0x0010) {
1026 ctrl->alternate_base_address = 1; // supported
1028 ctrl->alternate_base_address = 0; // not supported
1031 /* PCI Config Space Index (0=not supported, 1=supported) */
1032 if (subsystem_deviceid & 0x0020) {
1033 ctrl->pci_config_space = 1; // supported
1035 ctrl->pci_config_space = 0; // not supported
1039 if (subsystem_deviceid & 0x0080) {
1041 ctrl->pcix_support = 1;
1042 /* Frequency of operation in PCI-X mode */
1043 if (subsystem_deviceid & 0x0040) {
1044 /* 133MHz PCI-X if bit 7 is 1 */
1045 ctrl->pcix_speed_capability = 1;
1047 /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
1048 /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
1049 ctrl->pcix_speed_capability = 0;
1052 /* Conventional PCI */
1053 ctrl->pcix_support = 0;
1054 ctrl->pcix_speed_capability = 0;
1059 err(msg_HPC_not_supported);
1065 err(msg_HPC_not_supported);
1069 // Tell the user that we found one.
1070 info("Initializing the PCI hot plug controller residing on PCI bus %d\n", pdev->bus->number);
1072 dbg ("Hotplug controller capabilities:\n");
1073 dbg (" speed_capability %d\n", ctrl->speed_capability);
1074 dbg (" slot_switch_type %s\n", ctrl->slot_switch_type == 0 ? "no switch" : "switch present");
1075 dbg (" defeature_PHP %s\n", ctrl->defeature_PHP == 0 ? "PHP not supported" : "PHP supported");
1076 dbg (" alternate_base_address %s\n", ctrl->alternate_base_address == 0 ? "not supported" : "supported");
1077 dbg (" pci_config_space %s\n", ctrl->pci_config_space == 0 ? "not supported" : "supported");
1078 dbg (" pcix_speed_capability %s\n", ctrl->pcix_speed_capability == 0 ? "not supported" : "supported");
1079 dbg (" pcix_support %s\n", ctrl->pcix_support == 0 ? "not supported" : "supported");
1081 ctrl->pci_dev = pdev;
1082 ctrl->pci_ops = pdev->bus->ops;
1083 ctrl->bus = pdev->bus->number;
1084 ctrl->device = PCI_SLOT(pdev->devfn);
1085 ctrl->function = PCI_FUNC(pdev->devfn);
1087 dbg("bus device function rev: %d %d %d %d\n", ctrl->bus, ctrl->device, ctrl->function, ctrl->rev);
1089 init_MUTEX(&ctrl->crit_sect);
1090 init_waitqueue_head(&ctrl->queue);
1092 /* initialize our threads if they haven't already been started up */
1093 rc = one_time_init();
1098 dbg("pdev = %p\n", pdev);
1099 dbg("pci resource start %lx\n", pci_resource_start(pdev, 0));
1100 dbg("pci resource len %lx\n", pci_resource_len(pdev, 0));
1102 if (!request_mem_region(pci_resource_start(pdev, 0),
1103 pci_resource_len(pdev, 0), MY_NAME)) {
1104 err("cannot reserve MMIO region\n");
1109 ctrl->hpc_reg = ioremap(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
1110 if (!ctrl->hpc_reg) {
1111 err("cannot remap MMIO region %lx @ %lx\n", pci_resource_len(pdev, 0), pci_resource_start(pdev, 0));
1113 goto err_free_mem_region;
1116 // Check for 66Mhz and/or PCI-X operation
1117 ctrl->speed = get_controller_speed(ctrl);
1119 //**************************************************
1121 // Save configuration headers for this and
1122 // subordinate PCI buses
1124 //**************************************************
1126 // find the physical slot number of the first hot plug slot
1128 // Get slot won't work for devices behind bridges, but
1129 // in this case it will always be called for the "base"
1130 // bus/dev/func of a slot.
1131 // CS: this is leveraging the PCIIRQ routing code from the kernel (pci-pc.c: get_irq_routing_table)
1132 rc = get_slot_mapping(ctrl->pci_ops, pdev->bus->number, (readb(ctrl->hpc_reg + SLOT_MASK) >> 4), &(ctrl->first_slot));
1133 dbg("get_slot_mapping: first_slot = %d, returned = %d\n", ctrl->first_slot, rc);
1135 err(msg_initialization_err, rc);
1139 // Store PCI Config Space for all devices on this bus
1140 rc = cpqhp_save_config(ctrl, ctrl->bus, readb(ctrl->hpc_reg + SLOT_MASK));
1142 err("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc);
1147 * Get IO, memory, and IRQ resources for new devices
1149 // The next line is required for cpqhp_find_available_resources
1150 ctrl->interrupt = pdev->irq;
1152 rc = cpqhp_find_available_resources(ctrl, cpqhp_rom_start);
1153 ctrl->add_support = !rc;
1155 dbg("cpqhp_find_available_resources = 0x%x\n", rc);
1156 err("unable to locate PCI configuration resources for hot plug add.\n");
1161 * Finish setting up the hot plug ctrl device
1163 ctrl->slot_device_offset = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
1164 dbg("NumSlots %d \n", ctrl->slot_device_offset);
1166 ctrl->next_event = 0;
1168 /* Setup the slot information structures */
1169 rc = ctrl_slot_setup(ctrl, smbios_start, smbios_table);
1171 err(msg_initialization_err, 6);
1172 err("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc);
1176 /* Mask all general input interrupts */
1177 writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_MASK);
1179 /* set up the interrupt */
1180 dbg("HPC interrupt = %d \n", ctrl->interrupt);
1181 if (request_irq(ctrl->interrupt,
1182 (void (*)(int, void *, struct pt_regs *)) &cpqhp_ctrl_intr,
1183 SA_SHIRQ, MY_NAME, ctrl)) {
1184 err("Can't get irq %d for the hotplug pci controller\n", ctrl->interrupt);
1189 /* Enable Shift Out interrupt and clear it, also enable SERR on power fault */
1190 temp_word = readw(ctrl->hpc_reg + MISC);
1191 temp_word |= 0x4006;
1192 writew(temp_word, ctrl->hpc_reg + MISC);
1194 // Changed 05/05/97 to clear all interrupts at start
1195 writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_INPUT_CLEAR);
1197 ctrl->ctrl_int_comp = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
1199 writel(0x0L, ctrl->hpc_reg + INT_MASK);
1201 if (!cpqhp_ctrl_list) {
1202 cpqhp_ctrl_list = ctrl;
1205 ctrl->next = cpqhp_ctrl_list;
1206 cpqhp_ctrl_list = ctrl;
1209 // turn off empty slots here unless command line option "ON" set
1210 // Wait for exclusive access to hardware
1211 down(&ctrl->crit_sect);
1213 num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
1215 // find first device number for the ctrl
1216 device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
1218 while (num_of_slots) {
1219 dbg("num_of_slots: %d\n", num_of_slots);
1220 func = cpqhp_slot_find(ctrl->bus, device, 0);
1224 hp_slot = func->device - ctrl->slot_device_offset;
1225 dbg("hp_slot: %d\n", hp_slot);
1227 // We have to save the presence info for these slots
1228 temp_word = ctrl->ctrl_int_comp >> 16;
1229 func->presence_save = (temp_word >> hp_slot) & 0x01;
1230 func->presence_save |= (temp_word >> (hp_slot + 7)) & 0x02;
1232 if (ctrl->ctrl_int_comp & (0x1L << hp_slot)) {
1233 func->switch_save = 0;
1235 func->switch_save = 0x10;
1239 if (!func->is_a_board) {
1240 green_LED_off (ctrl, hp_slot);
1241 slot_disable (ctrl, hp_slot);
1251 // Wait for SOBS to be unset
1252 wait_for_ctrl_irq (ctrl);
1255 rc = init_SERR(ctrl);
1257 err("init_SERR failed\n");
1258 up(&ctrl->crit_sect);
1262 // Done with exclusive hardware access
1263 up(&ctrl->crit_sect);
1265 rc = cpqhp_proc_create_ctrl (ctrl);
1267 err("cpqhp_proc_create_ctrl failed\n");
1274 free_irq(ctrl->interrupt, ctrl);
1276 iounmap(ctrl->hpc_reg);
1277 err_free_mem_region:
1278 release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
1285 static int one_time_init(void)
1289 static int initialized = 0;
1296 retval = pci_print_IRQ_route();
1300 dbg("Initialize + Start the notification mechanism \n");
1302 retval = cpqhp_event_start_thread();
1306 dbg("Initialize slot lists\n");
1307 for (loop = 0; loop < 256; loop++) {
1308 cpqhp_slot_list[loop] = NULL;
1311 // FIXME: We also need to hook the NMI handler eventually.
1312 // this also needs to be worked with Christoph
1313 // register_NMI_handler();
1316 cpqhp_rom_start = ioremap(ROM_PHY_ADDR, ROM_PHY_LEN);
1317 if (!cpqhp_rom_start) {
1318 err ("Could not ioremap memory region for ROM\n");
1323 /* Now, map the int15 entry point if we are on compaq specific hardware */
1324 compaq_nvram_init(cpqhp_rom_start);
1326 /* Map smbios table entry point structure */
1327 smbios_table = detect_SMBIOS_pointer(cpqhp_rom_start, cpqhp_rom_start + ROM_PHY_LEN);
1328 if (!smbios_table) {
1329 err ("Could not find the SMBIOS pointer in memory\n");
1334 smbios_start = ioremap(readl(smbios_table + ST_ADDRESS), readw(smbios_table + ST_LENGTH));
1335 if (!smbios_start) {
1336 err ("Could not ioremap memory region taken from SMBIOS values\n");
1341 retval = cpqhp_proc_init_ctrl();
1350 if (cpqhp_rom_start)
1351 iounmap(cpqhp_rom_start);
1353 iounmap(smbios_start);
1359 static void unload_cpqphpd(void)
1361 struct pci_func *next;
1362 struct pci_func *TempSlot;
1365 struct controller *ctrl;
1366 struct controller *tctrl;
1367 struct pci_resource *res;
1368 struct pci_resource *tres;
1370 rc = compaq_nvram_store(cpqhp_rom_start);
1372 ctrl = cpqhp_ctrl_list;
1375 cpqhp_proc_remove_ctrl (ctrl);
1377 if (ctrl->hpc_reg) {
1379 rc = read_slot_enable (ctrl);
1381 writeb(0, ctrl->hpc_reg + SLOT_SERR);
1382 writel(0xFFFFFFC0L | ~rc, ctrl->hpc_reg + INT_MASK);
1384 misc = readw(ctrl->hpc_reg + MISC);
1386 writew(misc, ctrl->hpc_reg + MISC);
1389 ctrl_slot_cleanup(ctrl);
1391 res = ctrl->io_head;
1398 res = ctrl->mem_head;
1405 res = ctrl->p_mem_head;
1412 res = ctrl->bus_head;
1424 for (loop = 0; loop < 256; loop++) {
1425 next = cpqhp_slot_list[loop];
1426 while (next != NULL) {
1427 res = next->io_head;
1434 res = next->mem_head;
1441 res = next->p_mem_head;
1448 res = next->bus_head;
1461 remove_proc_entry("hpc", 0);
1463 // Stop the notification mechanism
1464 cpqhp_event_stop_thread();
1466 //unmap the rom address
1467 if (cpqhp_rom_start)
1468 iounmap(cpqhp_rom_start);
1470 iounmap(smbios_start);
1475 static struct pci_device_id hpcd_pci_tbl[] __devinitdata = {
1477 /* handle any PCI Hotplug controller */
1478 class: ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00),
1481 /* no matter who makes it */
1484 subvendor: PCI_ANY_ID,
1485 subdevice: PCI_ANY_ID,
1487 }, { /* end: all zeroes */ }
1490 MODULE_DEVICE_TABLE(pci, hpcd_pci_tbl);
1494 static struct pci_driver cpqhpc_driver = {
1495 name: "pci_hotplug",
1496 id_table: hpcd_pci_tbl,
1497 probe: cpqhpc_probe,
1498 /* remove: cpqhpc_remove_one, */
1503 static int __init cpqhpc_init(void)
1507 cpqhp_debug = debug;
1509 result = pci_module_init(&cpqhpc_driver);
1510 dbg("pci_module_init = %d\n", result);
1513 info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
1518 static void __exit cpqhpc_cleanup(void)
1520 dbg("cleaning up proc entries\n");
1521 cpqhp_proc_destroy_ctrl();
1523 dbg("unload_cpqphpd()\n");
1526 dbg("pci_unregister_driver\n");
1527 pci_unregister_driver(&cpqhpc_driver);
1531 module_init(cpqhpc_init);
1532 module_exit(cpqhpc_cleanup);