1 // SPDX-License-Identifier: GPL-2.0+
3 * Compaq Hot Plug Controller Driver
5 * Copyright (C) 1995,2001 Compaq Computer Corporation
6 * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
7 * Copyright (C) 2001 IBM Corp.
11 * Send feedback to <greg@kroah.com>
13 * Jan 12, 2003 - Added 66/100/133MHz PCI-X support,
14 * Torben Mathiasen <torben.mathiasen@hp.com>
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <linux/kernel.h>
20 #include <linux/types.h>
21 #include <linux/proc_fs.h>
22 #include <linux/slab.h>
23 #include <linux/workqueue.h>
24 #include <linux/pci.h>
25 #include <linux/pci_hotplug.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
29 #include <linux/uaccess.h>
32 #include "cpqphp_nvram.h"
35 /* Global variables */
37 int cpqhp_legacy_mode
;
38 struct controller
*cpqhp_ctrl_list
; /* = NULL */
39 struct pci_func
*cpqhp_slot_list
[256];
40 struct irq_routing_table
*cpqhp_routing_table
;
43 static void __iomem
*smbios_table
;
44 static void __iomem
*smbios_start
;
45 static void __iomem
*cpqhp_rom_start
;
46 static bool power_mode
;
48 static int initialized
;
50 #define DRIVER_VERSION "0.9.8"
51 #define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>"
52 #define DRIVER_DESC "Compaq Hot Plug PCI Controller Driver"
54 MODULE_AUTHOR(DRIVER_AUTHOR
);
55 MODULE_DESCRIPTION(DRIVER_DESC
);
56 MODULE_LICENSE("GPL");
58 module_param(power_mode
, bool, 0644);
59 MODULE_PARM_DESC(power_mode
, "Power mode enabled or not");
61 module_param(debug
, bool, 0644);
62 MODULE_PARM_DESC(debug
, "Debugging mode enabled or not");
64 #define CPQHPC_MODULE_MINOR 208
66 static inline int is_slot64bit(struct slot
*slot
)
68 return (readb(slot
->p_sm_slot
+ SMBIOS_SLOT_WIDTH
) == 0x06) ? 1 : 0;
71 static inline int is_slot66mhz(struct slot
*slot
)
73 return (readb(slot
->p_sm_slot
+ SMBIOS_SLOT_TYPE
) == 0x0E) ? 1 : 0;
77 * detect_SMBIOS_pointer - find the System Management BIOS Table in mem region.
78 * @begin: begin pointer for region to be scanned.
79 * @end: end pointer for region to be scanned.
81 * Returns pointer to the head of the SMBIOS tables (or %NULL).
83 static void __iomem
*detect_SMBIOS_pointer(void __iomem
*begin
, void __iomem
*end
)
87 u8 temp1
, temp2
, temp3
, temp4
;
90 endp
= (end
- sizeof(u32
) + 1);
92 for (fp
= begin
; fp
<= endp
; fp
+= 16) {
109 dbg("Discovered SMBIOS Entry point at %p\n", fp
);
115 * init_SERR - Initializes the per slot SERR generation.
116 * @ctrl: controller to use
118 * For unexpected switch opens
120 static int init_SERR(struct controller
*ctrl
)
128 tempdword
= ctrl
->first_slot
;
130 number_of_slots
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) & 0x0F;
131 /* Loop through slots */
132 while (number_of_slots
) {
133 writeb(0, ctrl
->hpc_reg
+ SLOT_SERR
);
141 static int init_cpqhp_routing_table(void)
145 cpqhp_routing_table
= pcibios_get_irq_routing_table();
146 if (cpqhp_routing_table
== NULL
)
149 len
= cpqhp_routing_table_length();
151 kfree(cpqhp_routing_table
);
152 cpqhp_routing_table
= NULL
;
159 /* nice debugging output */
160 static void pci_print_IRQ_route(void)
164 u8 tbus
, tdevice
, tslot
;
166 len
= cpqhp_routing_table_length();
168 dbg("bus dev func slot\n");
169 for (loop
= 0; loop
< len
; ++loop
) {
170 tbus
= cpqhp_routing_table
->slots
[loop
].bus
;
171 tdevice
= cpqhp_routing_table
->slots
[loop
].devfn
;
172 tslot
= cpqhp_routing_table
->slots
[loop
].slot
;
173 dbg("%d %d %d %d\n", tbus
, tdevice
>> 3, tdevice
& 0x7, tslot
);
181 * get_subsequent_smbios_entry: get the next entry from bios table.
182 * @smbios_start: where to start in the SMBIOS table
183 * @smbios_table: location of the SMBIOS table
184 * @curr: %NULL or pointer to previously returned structure
186 * Gets the first entry if previous == NULL;
187 * otherwise, returns the next entry.
188 * Uses global SMBIOS Table pointer.
190 * Returns a pointer to an SMBIOS structure or NULL if none found.
192 static void __iomem
*get_subsequent_smbios_entry(void __iomem
*smbios_start
,
193 void __iomem
*smbios_table
,
197 u8 previous_byte
= 1;
198 void __iomem
*p_temp
;
201 if (!smbios_table
|| !curr
)
204 /* set p_max to the end of the table */
205 p_max
= smbios_start
+ readw(smbios_table
+ ST_LENGTH
);
208 p_temp
+= readb(curr
+ SMBIOS_GENERIC_LENGTH
);
210 while ((p_temp
< p_max
) && !bail
) {
211 /* Look for the double NULL terminator
212 * The first condition is the previous byte
213 * and the second is the curr
215 if (!previous_byte
&& !(readb(p_temp
)))
218 previous_byte
= readb(p_temp
);
230 * get_SMBIOS_entry - return the requested SMBIOS entry or %NULL
231 * @smbios_start: where to start in the SMBIOS table
232 * @smbios_table: location of the SMBIOS table
233 * @type: SMBIOS structure type to be returned
234 * @previous: %NULL or pointer to previously returned structure
236 * Gets the first entry of the specified type if previous == %NULL;
237 * Otherwise, returns the next entry of the given type.
238 * Uses global SMBIOS Table pointer.
239 * Uses get_subsequent_smbios_entry.
241 * Returns a pointer to an SMBIOS structure or %NULL if none found.
243 static void __iomem
*get_SMBIOS_entry(void __iomem
*smbios_start
,
244 void __iomem
*smbios_table
,
246 void __iomem
*previous
)
252 previous
= smbios_start
;
254 previous
= get_subsequent_smbios_entry(smbios_start
,
255 smbios_table
, previous
);
258 if (readb(previous
+ SMBIOS_GENERIC_TYPE
) != type
)
259 previous
= get_subsequent_smbios_entry(smbios_start
,
260 smbios_table
, previous
);
267 static int ctrl_slot_cleanup(struct controller
*ctrl
)
269 struct slot
*old_slot
, *next_slot
;
271 old_slot
= ctrl
->slot
;
275 next_slot
= old_slot
->next
;
276 pci_hp_deregister(&old_slot
->hotplug_slot
);
278 old_slot
= next_slot
;
281 cpqhp_remove_debugfs_files(ctrl
);
283 /* Free IRQ associated with hot plug device */
284 free_irq(ctrl
->interrupt
, ctrl
);
285 /* Unmap the memory */
286 iounmap(ctrl
->hpc_reg
);
287 /* Finally reclaim PCI mem */
288 release_mem_region(pci_resource_start(ctrl
->pci_dev
, 0),
289 pci_resource_len(ctrl
->pci_dev
, 0));
296 * get_slot_mapping - determine logical slot mapping for PCI device
298 * Won't work for more than one PCI-PCI bridge in a slot.
300 * @bus_num - bus number of PCI device
301 * @dev_num - device number of PCI device
302 * @slot - Pointer to u8 where slot number will be returned
304 * Output: SUCCESS or FAILURE
307 get_slot_mapping(struct pci_bus
*bus
, u8 bus_num
, u8 dev_num
, u8
*slot
)
313 u8 tbus
, tdevice
, tslot
, bridgeSlot
;
315 dbg("%s: %p, %d, %d, %p\n", __func__
, bus
, bus_num
, dev_num
, slot
);
319 len
= cpqhp_routing_table_length();
320 for (loop
= 0; loop
< len
; ++loop
) {
321 tbus
= cpqhp_routing_table
->slots
[loop
].bus
;
322 tdevice
= cpqhp_routing_table
->slots
[loop
].devfn
>> 3;
323 tslot
= cpqhp_routing_table
->slots
[loop
].slot
;
325 if ((tbus
== bus_num
) && (tdevice
== dev_num
)) {
329 /* Did not get a match on the target PCI device. Check
330 * if the current IRQ table entry is a PCI-to-PCI
331 * bridge device. If so, and it's secondary bus
332 * matches the bus number for the target device, I need
333 * to save the bridge's slot number. If I can not find
334 * an entry for the target device, I will have to
335 * assume it's on the other side of the bridge, and
336 * assign it the bridge's slot.
339 pci_bus_read_config_dword(bus
, PCI_DEVFN(tdevice
, 0),
340 PCI_CLASS_REVISION
, &work
);
342 if ((work
>> 8) == PCI_TO_PCI_BRIDGE_CLASS
) {
343 pci_bus_read_config_dword(bus
,
344 PCI_DEVFN(tdevice
, 0),
345 PCI_PRIMARY_BUS
, &work
);
346 // See if bridge's secondary bus matches target bus.
347 if (((work
>> 8) & 0x000000FF) == (long) bus_num
)
354 /* If we got here, we didn't find an entry in the IRQ mapping table for
355 * the target PCI device. If we did determine that the target device
356 * is on the other side of a PCI-to-PCI bridge, return the slot number
359 if (bridgeSlot
!= 0xFF) {
363 /* Couldn't find an entry in the routing table for this PCI device */
369 * cpqhp_set_attention_status - Turns the Amber LED for a slot on or off
370 * @ctrl: struct controller to use
371 * @func: PCI device/function info
372 * @status: LED control flag: 1 = LED on, 0 = LED off
375 cpqhp_set_attention_status(struct controller
*ctrl
, struct pci_func
*func
,
383 hp_slot
= func
->device
- ctrl
->slot_device_offset
;
385 /* Wait for exclusive access to hardware */
386 mutex_lock(&ctrl
->crit_sect
);
389 amber_LED_on(ctrl
, hp_slot
);
390 else if (status
== 0)
391 amber_LED_off(ctrl
, hp_slot
);
393 /* Done with exclusive hardware access */
394 mutex_unlock(&ctrl
->crit_sect
);
400 /* Wait for SOBS to be unset */
401 wait_for_ctrl_irq(ctrl
);
403 /* Done with exclusive hardware access */
404 mutex_unlock(&ctrl
->crit_sect
);
411 * set_attention_status - Turns the Amber LED for a slot on or off
412 * @hotplug_slot: slot to change LED on
413 * @status: LED control flag
415 static int set_attention_status(struct hotplug_slot
*hotplug_slot
, u8 status
)
417 struct pci_func
*slot_func
;
418 struct slot
*slot
= to_slot(hotplug_slot
);
419 struct controller
*ctrl
= slot
->ctrl
;
425 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
427 if (cpqhp_get_bus_dev(ctrl
, &bus
, &devfn
, slot
->number
) == -1)
431 function
= devfn
& 0x7;
432 dbg("bus, dev, fn = %d, %d, %d\n", bus
, device
, function
);
434 slot_func
= cpqhp_slot_find(bus
, device
, function
);
438 return cpqhp_set_attention_status(ctrl
, slot_func
, status
);
442 static int process_SI(struct hotplug_slot
*hotplug_slot
)
444 struct pci_func
*slot_func
;
445 struct slot
*slot
= to_slot(hotplug_slot
);
446 struct controller
*ctrl
= slot
->ctrl
;
452 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
454 if (cpqhp_get_bus_dev(ctrl
, &bus
, &devfn
, slot
->number
) == -1)
458 function
= devfn
& 0x7;
459 dbg("bus, dev, fn = %d, %d, %d\n", bus
, device
, function
);
461 slot_func
= cpqhp_slot_find(bus
, device
, function
);
465 slot_func
->bus
= bus
;
466 slot_func
->device
= device
;
467 slot_func
->function
= function
;
468 slot_func
->configured
= 0;
469 dbg("board_added(%p, %p)\n", slot_func
, ctrl
);
470 return cpqhp_process_SI(ctrl
, slot_func
);
474 static int process_SS(struct hotplug_slot
*hotplug_slot
)
476 struct pci_func
*slot_func
;
477 struct slot
*slot
= to_slot(hotplug_slot
);
478 struct controller
*ctrl
= slot
->ctrl
;
484 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
486 if (cpqhp_get_bus_dev(ctrl
, &bus
, &devfn
, slot
->number
) == -1)
490 function
= devfn
& 0x7;
491 dbg("bus, dev, fn = %d, %d, %d\n", bus
, device
, function
);
493 slot_func
= cpqhp_slot_find(bus
, device
, function
);
497 dbg("In %s, slot_func = %p, ctrl = %p\n", __func__
, slot_func
, ctrl
);
498 return cpqhp_process_SS(ctrl
, slot_func
);
502 static int hardware_test(struct hotplug_slot
*hotplug_slot
, u32 value
)
504 struct slot
*slot
= to_slot(hotplug_slot
);
505 struct controller
*ctrl
= slot
->ctrl
;
507 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
509 return cpqhp_hardware_test(ctrl
, value
);
513 static int get_power_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
515 struct slot
*slot
= to_slot(hotplug_slot
);
516 struct controller
*ctrl
= slot
->ctrl
;
518 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
520 *value
= get_slot_enabled(ctrl
, slot
);
524 static int get_attention_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
526 struct slot
*slot
= to_slot(hotplug_slot
);
527 struct controller
*ctrl
= slot
->ctrl
;
529 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
531 *value
= cpq_get_attention_status(ctrl
, slot
);
535 static int get_latch_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
537 struct slot
*slot
= to_slot(hotplug_slot
);
538 struct controller
*ctrl
= slot
->ctrl
;
540 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
542 *value
= cpq_get_latch_status(ctrl
, slot
);
547 static int get_adapter_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
549 struct slot
*slot
= to_slot(hotplug_slot
);
550 struct controller
*ctrl
= slot
->ctrl
;
552 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
554 *value
= get_presence_status(ctrl
, slot
);
559 static const struct hotplug_slot_ops cpqphp_hotplug_slot_ops
= {
560 .set_attention_status
= set_attention_status
,
561 .enable_slot
= process_SI
,
562 .disable_slot
= process_SS
,
563 .hardware_test
= hardware_test
,
564 .get_power_status
= get_power_status
,
565 .get_attention_status
= get_attention_status
,
566 .get_latch_status
= get_latch_status
,
567 .get_adapter_status
= get_adapter_status
,
570 #define SLOT_NAME_SIZE 10
572 static int ctrl_slot_setup(struct controller
*ctrl
,
573 void __iomem
*smbios_start
,
574 void __iomem
*smbios_table
)
577 struct pci_bus
*bus
= ctrl
->pci_bus
;
583 char name
[SLOT_NAME_SIZE
];
584 void __iomem
*slot_entry
= NULL
;
587 dbg("%s\n", __func__
);
589 tempdword
= readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
591 number_of_slots
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) & 0x0F;
592 slot_device
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4;
593 slot_number
= ctrl
->first_slot
;
595 while (number_of_slots
) {
596 slot
= kzalloc(sizeof(*slot
), GFP_KERNEL
);
603 slot
->bus
= ctrl
->bus
;
604 slot
->device
= slot_device
;
605 slot
->number
= slot_number
;
606 dbg("slot->number = %u\n", slot
->number
);
608 slot_entry
= get_SMBIOS_entry(smbios_start
, smbios_table
, 9,
611 while (slot_entry
&& (readw(slot_entry
+ SMBIOS_SLOT_NUMBER
) !=
613 slot_entry
= get_SMBIOS_entry(smbios_start
,
614 smbios_table
, 9, slot_entry
);
617 slot
->p_sm_slot
= slot_entry
;
619 timer_setup(&slot
->task_event
, cpqhp_pushbutton_thread
, 0);
620 slot
->task_event
.expires
= jiffies
+ 5 * HZ
;
622 /*FIXME: these capabilities aren't used but if they are
623 * they need to be correctly implemented
625 slot
->capabilities
|= PCISLOT_REPLACE_SUPPORTED
;
626 slot
->capabilities
|= PCISLOT_INTERLOCK_SUPPORTED
;
628 if (is_slot64bit(slot
))
629 slot
->capabilities
|= PCISLOT_64_BIT_SUPPORTED
;
630 if (is_slot66mhz(slot
))
631 slot
->capabilities
|= PCISLOT_66_MHZ_SUPPORTED
;
632 if (bus
->cur_bus_speed
== PCI_SPEED_66MHz
)
633 slot
->capabilities
|= PCISLOT_66_MHZ_OPERATION
;
636 slot_device
- (readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4);
639 slot
->capabilities
|=
640 ((((~tempdword
) >> 23) |
641 ((~tempdword
) >> 15)) >> ctrl_slot
) & 0x02;
642 /* Check the switch state */
643 slot
->capabilities
|=
644 ((~tempdword
& 0xFF) >> ctrl_slot
) & 0x01;
645 /* Check the slot enable */
646 slot
->capabilities
|=
647 ((read_slot_enable(ctrl
) << 2) >> ctrl_slot
) & 0x04;
649 /* register this slot with the hotplug pci core */
650 snprintf(name
, SLOT_NAME_SIZE
, "%u", slot
->number
);
651 slot
->hotplug_slot
.ops
= &cpqphp_hotplug_slot_ops
;
653 dbg("registering bus %d, dev %d, number %d, ctrl->slot_device_offset %d, slot %d\n",
654 slot
->bus
, slot
->device
,
655 slot
->number
, ctrl
->slot_device_offset
,
657 result
= pci_hp_register(&slot
->hotplug_slot
,
662 err("pci_hp_register failed with error %d\n", result
);
666 slot
->next
= ctrl
->slot
;
681 static int one_time_init(void)
691 retval
= init_cpqhp_routing_table();
696 pci_print_IRQ_route();
698 dbg("Initialize + Start the notification mechanism\n");
700 retval
= cpqhp_event_start_thread();
704 dbg("Initialize slot lists\n");
705 for (loop
= 0; loop
< 256; loop
++)
706 cpqhp_slot_list
[loop
] = NULL
;
708 /* FIXME: We also need to hook the NMI handler eventually.
709 * this also needs to be worked with Christoph
710 * register_NMI_handler();
712 /* Map rom address */
713 cpqhp_rom_start
= ioremap(ROM_PHY_ADDR
, ROM_PHY_LEN
);
714 if (!cpqhp_rom_start
) {
715 err("Could not ioremap memory region for ROM\n");
720 /* Now, map the int15 entry point if we are on compaq specific
723 compaq_nvram_init(cpqhp_rom_start
);
725 /* Map smbios table entry point structure */
726 smbios_table
= detect_SMBIOS_pointer(cpqhp_rom_start
,
727 cpqhp_rom_start
+ ROM_PHY_LEN
);
729 err("Could not find the SMBIOS pointer in memory\n");
731 goto error_rom_start
;
734 smbios_start
= ioremap(readl(smbios_table
+ ST_ADDRESS
),
735 readw(smbios_table
+ ST_LENGTH
));
737 err("Could not ioremap memory region taken from SMBIOS values\n");
739 goto error_smbios_start
;
747 iounmap(smbios_start
);
749 iounmap(cpqhp_rom_start
);
754 static int cpqhpc_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
763 u16 subsystem_deviceid
;
765 struct controller
*ctrl
;
766 struct pci_func
*func
;
770 err
= pci_enable_device(pdev
);
772 printk(KERN_ERR MY_NAME
": cannot enable PCI device %s (%d)\n",
773 pci_name(pdev
), err
);
777 bus
= pdev
->subordinate
;
779 pci_notice(pdev
, "the device is not a bridge, skipping\n");
781 goto err_disable_device
;
784 /* Need to read VID early b/c it's used to differentiate CPQ and INTC
787 vendor_id
= pdev
->vendor
;
788 if ((vendor_id
!= PCI_VENDOR_ID_COMPAQ
) &&
789 (vendor_id
!= PCI_VENDOR_ID_INTEL
)) {
790 err(msg_HPC_non_compaq_or_intel
);
792 goto err_disable_device
;
794 dbg("Vendor ID: %x\n", vendor_id
);
796 dbg("revision: %d\n", pdev
->revision
);
797 if ((vendor_id
== PCI_VENDOR_ID_COMPAQ
) && (!pdev
->revision
)) {
798 err(msg_HPC_rev_error
);
800 goto err_disable_device
;
803 /* Check for the proper subsystem IDs
804 * Intel uses a different SSID programming model than Compaq.
805 * For Intel, each SSID bit identifies a PHP capability.
806 * Also Intel HPCs may have RID=0.
808 if ((pdev
->revision
<= 2) && (vendor_id
!= PCI_VENDOR_ID_INTEL
)) {
809 err(msg_HPC_not_supported
);
811 goto err_disable_device
;
814 /* TODO: This code can be made to support non-Compaq or Intel
817 subsystem_vid
= pdev
->subsystem_vendor
;
818 dbg("Subsystem Vendor ID: %x\n", subsystem_vid
);
819 if ((subsystem_vid
!= PCI_VENDOR_ID_COMPAQ
) && (subsystem_vid
!= PCI_VENDOR_ID_INTEL
)) {
820 err(msg_HPC_non_compaq_or_intel
);
822 goto err_disable_device
;
825 ctrl
= kzalloc(sizeof(struct controller
), GFP_KERNEL
);
828 goto err_disable_device
;
831 subsystem_deviceid
= pdev
->subsystem_device
;
833 info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid
);
835 /* Set Vendor ID, so it can be accessed later from other
838 ctrl
->vendor_id
= vendor_id
;
840 switch (subsystem_vid
) {
841 case PCI_VENDOR_ID_COMPAQ
:
842 if (pdev
->revision
>= 0x13) { /* CIOBX */
844 ctrl
->slot_switch_type
= 1;
845 ctrl
->push_button
= 1;
846 ctrl
->pci_config_space
= 1;
847 ctrl
->defeature_PHP
= 1;
848 ctrl
->pcix_support
= 1;
849 ctrl
->pcix_speed_capability
= 1;
850 pci_read_config_byte(pdev
, 0x41, &bus_cap
);
851 if (bus_cap
& 0x80) {
852 dbg("bus max supports 133MHz PCI-X\n");
853 bus
->max_bus_speed
= PCI_SPEED_133MHz_PCIX
;
856 if (bus_cap
& 0x40) {
857 dbg("bus max supports 100MHz PCI-X\n");
858 bus
->max_bus_speed
= PCI_SPEED_100MHz_PCIX
;
861 if (bus_cap
& 0x20) {
862 dbg("bus max supports 66MHz PCI-X\n");
863 bus
->max_bus_speed
= PCI_SPEED_66MHz_PCIX
;
866 if (bus_cap
& 0x10) {
867 dbg("bus max supports 66MHz PCI\n");
868 bus
->max_bus_speed
= PCI_SPEED_66MHz
;
875 switch (subsystem_deviceid
) {
877 /* Original 6500/7000 implementation */
878 ctrl
->slot_switch_type
= 1;
879 bus
->max_bus_speed
= PCI_SPEED_33MHz
;
880 ctrl
->push_button
= 0;
881 ctrl
->pci_config_space
= 1;
882 ctrl
->defeature_PHP
= 1;
883 ctrl
->pcix_support
= 0;
884 ctrl
->pcix_speed_capability
= 0;
886 case PCI_SUB_HPC_ID2
:
887 /* First Pushbutton implementation */
889 ctrl
->slot_switch_type
= 1;
890 bus
->max_bus_speed
= PCI_SPEED_33MHz
;
891 ctrl
->push_button
= 1;
892 ctrl
->pci_config_space
= 1;
893 ctrl
->defeature_PHP
= 1;
894 ctrl
->pcix_support
= 0;
895 ctrl
->pcix_speed_capability
= 0;
897 case PCI_SUB_HPC_ID_INTC
:
898 /* Third party (6500/7000) */
899 ctrl
->slot_switch_type
= 1;
900 bus
->max_bus_speed
= PCI_SPEED_33MHz
;
901 ctrl
->push_button
= 0;
902 ctrl
->pci_config_space
= 1;
903 ctrl
->defeature_PHP
= 1;
904 ctrl
->pcix_support
= 0;
905 ctrl
->pcix_speed_capability
= 0;
907 case PCI_SUB_HPC_ID3
:
908 /* First 66 Mhz implementation */
910 ctrl
->slot_switch_type
= 1;
911 bus
->max_bus_speed
= PCI_SPEED_66MHz
;
912 ctrl
->push_button
= 1;
913 ctrl
->pci_config_space
= 1;
914 ctrl
->defeature_PHP
= 1;
915 ctrl
->pcix_support
= 0;
916 ctrl
->pcix_speed_capability
= 0;
918 case PCI_SUB_HPC_ID4
:
919 /* First PCI-X implementation, 100MHz */
921 ctrl
->slot_switch_type
= 1;
922 bus
->max_bus_speed
= PCI_SPEED_100MHz_PCIX
;
923 ctrl
->push_button
= 1;
924 ctrl
->pci_config_space
= 1;
925 ctrl
->defeature_PHP
= 1;
926 ctrl
->pcix_support
= 1;
927 ctrl
->pcix_speed_capability
= 0;
930 err(msg_HPC_not_supported
);
936 case PCI_VENDOR_ID_INTEL
:
937 /* Check for speed capability (0=33, 1=66) */
938 if (subsystem_deviceid
& 0x0001)
939 bus
->max_bus_speed
= PCI_SPEED_66MHz
;
941 bus
->max_bus_speed
= PCI_SPEED_33MHz
;
943 /* Check for push button */
944 if (subsystem_deviceid
& 0x0002)
945 ctrl
->push_button
= 0;
947 ctrl
->push_button
= 1;
949 /* Check for slot switch type (0=mechanical, 1=not mechanical) */
950 if (subsystem_deviceid
& 0x0004)
951 ctrl
->slot_switch_type
= 0;
953 ctrl
->slot_switch_type
= 1;
955 /* PHP Status (0=De-feature PHP, 1=Normal operation) */
956 if (subsystem_deviceid
& 0x0008)
957 ctrl
->defeature_PHP
= 1; /* PHP supported */
959 ctrl
->defeature_PHP
= 0; /* PHP not supported */
961 /* Alternate Base Address Register Interface
962 * (0=not supported, 1=supported)
964 if (subsystem_deviceid
& 0x0010)
965 ctrl
->alternate_base_address
= 1;
967 ctrl
->alternate_base_address
= 0;
969 /* PCI Config Space Index (0=not supported, 1=supported) */
970 if (subsystem_deviceid
& 0x0020)
971 ctrl
->pci_config_space
= 1;
973 ctrl
->pci_config_space
= 0;
976 if (subsystem_deviceid
& 0x0080) {
977 ctrl
->pcix_support
= 1;
978 if (subsystem_deviceid
& 0x0040)
979 /* 133MHz PCI-X if bit 7 is 1 */
980 ctrl
->pcix_speed_capability
= 1;
982 /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
983 /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
984 ctrl
->pcix_speed_capability
= 0;
986 /* Conventional PCI */
987 ctrl
->pcix_support
= 0;
988 ctrl
->pcix_speed_capability
= 0;
993 err(msg_HPC_not_supported
);
998 /* Tell the user that we found one. */
999 info("Initializing the PCI hot plug controller residing on PCI bus %d\n",
1002 dbg("Hotplug controller capabilities:\n");
1003 dbg(" speed_capability %d\n", bus
->max_bus_speed
);
1004 dbg(" slot_switch_type %s\n", ctrl
->slot_switch_type
?
1005 "switch present" : "no switch");
1006 dbg(" defeature_PHP %s\n", ctrl
->defeature_PHP
?
1007 "PHP supported" : "PHP not supported");
1008 dbg(" alternate_base_address %s\n", ctrl
->alternate_base_address
?
1009 "supported" : "not supported");
1010 dbg(" pci_config_space %s\n", ctrl
->pci_config_space
?
1011 "supported" : "not supported");
1012 dbg(" pcix_speed_capability %s\n", ctrl
->pcix_speed_capability
?
1013 "supported" : "not supported");
1014 dbg(" pcix_support %s\n", ctrl
->pcix_support
?
1015 "supported" : "not supported");
1017 ctrl
->pci_dev
= pdev
;
1018 pci_set_drvdata(pdev
, ctrl
);
1020 /* make our own copy of the pci bus structure,
1021 * as we like tweaking it a lot */
1022 ctrl
->pci_bus
= kmemdup(pdev
->bus
, sizeof(*ctrl
->pci_bus
), GFP_KERNEL
);
1023 if (!ctrl
->pci_bus
) {
1024 err("out of memory\n");
1029 ctrl
->bus
= pdev
->bus
->number
;
1030 ctrl
->rev
= pdev
->revision
;
1031 dbg("bus device function rev: %d %d %d %d\n", ctrl
->bus
,
1032 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
), ctrl
->rev
);
1034 mutex_init(&ctrl
->crit_sect
);
1035 init_waitqueue_head(&ctrl
->queue
);
1037 /* initialize our threads if they haven't already been started up */
1038 rc
= one_time_init();
1042 dbg("pdev = %p\n", pdev
);
1043 dbg("pci resource start %llx\n", (unsigned long long)pci_resource_start(pdev
, 0));
1044 dbg("pci resource len %llx\n", (unsigned long long)pci_resource_len(pdev
, 0));
1046 if (!request_mem_region(pci_resource_start(pdev
, 0),
1047 pci_resource_len(pdev
, 0), MY_NAME
)) {
1048 err("cannot reserve MMIO region\n");
1053 ctrl
->hpc_reg
= ioremap(pci_resource_start(pdev
, 0),
1054 pci_resource_len(pdev
, 0));
1055 if (!ctrl
->hpc_reg
) {
1056 err("cannot remap MMIO region %llx @ %llx\n",
1057 (unsigned long long)pci_resource_len(pdev
, 0),
1058 (unsigned long long)pci_resource_start(pdev
, 0));
1060 goto err_free_mem_region
;
1063 /* Check for 66Mhz operation */
1064 bus
->cur_bus_speed
= get_controller_speed(ctrl
);
1067 /********************************************************
1069 * Save configuration headers for this and
1070 * subordinate PCI buses
1072 ********************************************************/
1074 /* find the physical slot number of the first hot plug slot */
1076 /* Get slot won't work for devices behind bridges, but
1077 * in this case it will always be called for the "base"
1078 * bus/dev/func of a slot.
1079 * CS: this is leveraging the PCIIRQ routing code from the kernel
1080 * (pci-pc.c: get_irq_routing_table) */
1081 rc
= get_slot_mapping(ctrl
->pci_bus
, pdev
->bus
->number
,
1082 (readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4),
1083 &(ctrl
->first_slot
));
1084 dbg("get_slot_mapping: first_slot = %d, returned = %d\n",
1085 ctrl
->first_slot
, rc
);
1087 err(msg_initialization_err
, rc
);
1091 /* Store PCI Config Space for all devices on this bus */
1092 rc
= cpqhp_save_config(ctrl
, ctrl
->bus
, readb(ctrl
->hpc_reg
+ SLOT_MASK
));
1094 err("%s: unable to save PCI configuration data, error %d\n",
1100 * Get IO, memory, and IRQ resources for new devices
1102 /* The next line is required for cpqhp_find_available_resources */
1103 ctrl
->interrupt
= pdev
->irq
;
1104 if (ctrl
->interrupt
< 0x10) {
1105 cpqhp_legacy_mode
= 1;
1106 dbg("System seems to be configured for Full Table Mapped MPS mode\n");
1109 ctrl
->cfgspc_irq
= 0;
1110 pci_read_config_byte(pdev
, PCI_INTERRUPT_LINE
, &ctrl
->cfgspc_irq
);
1112 rc
= cpqhp_find_available_resources(ctrl
, cpqhp_rom_start
);
1113 ctrl
->add_support
= !rc
;
1115 dbg("cpqhp_find_available_resources = 0x%x\n", rc
);
1116 err("unable to locate PCI configuration resources for hot plug add.\n");
1121 * Finish setting up the hot plug ctrl device
1123 ctrl
->slot_device_offset
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4;
1124 dbg("NumSlots %d\n", ctrl
->slot_device_offset
);
1126 ctrl
->next_event
= 0;
1128 /* Setup the slot information structures */
1129 rc
= ctrl_slot_setup(ctrl
, smbios_start
, smbios_table
);
1131 err(msg_initialization_err
, 6);
1132 err("%s: unable to save PCI configuration data, error %d\n",
1137 /* Mask all general input interrupts */
1138 writel(0xFFFFFFFFL
, ctrl
->hpc_reg
+ INT_MASK
);
1140 /* set up the interrupt */
1141 dbg("HPC interrupt = %d\n", ctrl
->interrupt
);
1142 if (request_irq(ctrl
->interrupt
, cpqhp_ctrl_intr
,
1143 IRQF_SHARED
, MY_NAME
, ctrl
)) {
1144 err("Can't get irq %d for the hotplug pci controller\n",
1150 /* Enable Shift Out interrupt and clear it, also enable SERR on power
1153 temp_word
= readw(ctrl
->hpc_reg
+ MISC
);
1154 temp_word
|= 0x4006;
1155 writew(temp_word
, ctrl
->hpc_reg
+ MISC
);
1157 /* Changed 05/05/97 to clear all interrupts at start */
1158 writel(0xFFFFFFFFL
, ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
1160 ctrl
->ctrl_int_comp
= readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
1162 writel(0x0L
, ctrl
->hpc_reg
+ INT_MASK
);
1164 if (!cpqhp_ctrl_list
) {
1165 cpqhp_ctrl_list
= ctrl
;
1168 ctrl
->next
= cpqhp_ctrl_list
;
1169 cpqhp_ctrl_list
= ctrl
;
1172 /* turn off empty slots here unless command line option "ON" set
1173 * Wait for exclusive access to hardware
1175 mutex_lock(&ctrl
->crit_sect
);
1177 num_of_slots
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) & 0x0F;
1179 /* find first device number for the ctrl */
1180 device
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4;
1182 while (num_of_slots
) {
1183 dbg("num_of_slots: %d\n", num_of_slots
);
1184 func
= cpqhp_slot_find(ctrl
->bus
, device
, 0);
1188 hp_slot
= func
->device
- ctrl
->slot_device_offset
;
1189 dbg("hp_slot: %d\n", hp_slot
);
1191 /* We have to save the presence info for these slots */
1192 temp_word
= ctrl
->ctrl_int_comp
>> 16;
1193 func
->presence_save
= (temp_word
>> hp_slot
) & 0x01;
1194 func
->presence_save
|= (temp_word
>> (hp_slot
+ 7)) & 0x02;
1196 if (ctrl
->ctrl_int_comp
& (0x1L
<< hp_slot
))
1197 func
->switch_save
= 0;
1199 func
->switch_save
= 0x10;
1202 if (!func
->is_a_board
) {
1203 green_LED_off(ctrl
, hp_slot
);
1204 slot_disable(ctrl
, hp_slot
);
1213 /* Wait for SOBS to be unset */
1214 wait_for_ctrl_irq(ctrl
);
1217 rc
= init_SERR(ctrl
);
1219 err("init_SERR failed\n");
1220 mutex_unlock(&ctrl
->crit_sect
);
1224 /* Done with exclusive hardware access */
1225 mutex_unlock(&ctrl
->crit_sect
);
1227 cpqhp_create_debugfs_files(ctrl
);
1232 free_irq(ctrl
->interrupt
, ctrl
);
1234 iounmap(ctrl
->hpc_reg
);
1235 err_free_mem_region
:
1236 release_mem_region(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
1238 kfree(ctrl
->pci_bus
);
1242 pci_disable_device(pdev
);
1246 static void __exit
unload_cpqphpd(void)
1248 struct pci_func
*next
;
1249 struct pci_func
*TempSlot
;
1252 struct controller
*ctrl
;
1253 struct controller
*tctrl
;
1254 struct pci_resource
*res
;
1255 struct pci_resource
*tres
;
1257 rc
= compaq_nvram_store(cpqhp_rom_start
);
1259 ctrl
= cpqhp_ctrl_list
;
1262 if (ctrl
->hpc_reg
) {
1264 rc
= read_slot_enable(ctrl
);
1266 writeb(0, ctrl
->hpc_reg
+ SLOT_SERR
);
1267 writel(0xFFFFFFC0L
| ~rc
, ctrl
->hpc_reg
+ INT_MASK
);
1269 misc
= readw(ctrl
->hpc_reg
+ MISC
);
1271 writew(misc
, ctrl
->hpc_reg
+ MISC
);
1274 ctrl_slot_cleanup(ctrl
);
1276 res
= ctrl
->io_head
;
1283 res
= ctrl
->mem_head
;
1290 res
= ctrl
->p_mem_head
;
1297 res
= ctrl
->bus_head
;
1304 kfree(ctrl
->pci_bus
);
1311 for (loop
= 0; loop
< 256; loop
++) {
1312 next
= cpqhp_slot_list
[loop
];
1313 while (next
!= NULL
) {
1314 res
= next
->io_head
;
1321 res
= next
->mem_head
;
1328 res
= next
->p_mem_head
;
1335 res
= next
->bus_head
;
1348 /* Stop the notification mechanism */
1350 cpqhp_event_stop_thread();
1352 /* unmap the rom address */
1353 if (cpqhp_rom_start
)
1354 iounmap(cpqhp_rom_start
);
1356 iounmap(smbios_start
);
1359 static const struct pci_device_id hpcd_pci_tbl
[] = {
1361 /* handle any PCI Hotplug controller */
1362 .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG
<< 8) | 0x00),
1365 /* no matter who makes it */
1366 .vendor
= PCI_ANY_ID
,
1367 .device
= PCI_ANY_ID
,
1368 .subvendor
= PCI_ANY_ID
,
1369 .subdevice
= PCI_ANY_ID
,
1371 }, { /* end: all zeroes */ }
1374 MODULE_DEVICE_TABLE(pci
, hpcd_pci_tbl
);
1376 static struct pci_driver cpqhpc_driver
= {
1377 .name
= "compaq_pci_hotplug",
1378 .id_table
= hpcd_pci_tbl
,
1379 .probe
= cpqhpc_probe
,
1380 /* remove: cpqhpc_remove_one, */
1383 static int __init
cpqhpc_init(void)
1387 cpqhp_debug
= debug
;
1389 info(DRIVER_DESC
" version: " DRIVER_VERSION
"\n");
1390 cpqhp_initialize_debugfs();
1391 result
= pci_register_driver(&cpqhpc_driver
);
1392 dbg("pci_register_driver = %d\n", result
);
1396 static void __exit
cpqhpc_cleanup(void)
1398 dbg("unload_cpqphpd()\n");
1401 dbg("pci_unregister_driver\n");
1402 pci_unregister_driver(&cpqhpc_driver
);
1403 cpqhp_shutdown_debugfs();
1406 module_init(cpqhpc_init
);
1407 module_exit(cpqhpc_cleanup
);