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
)
129 tempdword
= ctrl
->first_slot
;
131 number_of_slots
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) & 0x0F;
132 /* Loop through slots */
133 while (number_of_slots
) {
134 physical_slot
= tempdword
;
135 writeb(0, ctrl
->hpc_reg
+ SLOT_SERR
);
143 static int init_cpqhp_routing_table(void)
147 cpqhp_routing_table
= pcibios_get_irq_routing_table();
148 if (cpqhp_routing_table
== NULL
)
151 len
= cpqhp_routing_table_length();
153 kfree(cpqhp_routing_table
);
154 cpqhp_routing_table
= NULL
;
161 /* nice debugging output */
162 static void pci_print_IRQ_route(void)
166 u8 tbus
, tdevice
, tslot
;
168 len
= cpqhp_routing_table_length();
170 dbg("bus dev func slot\n");
171 for (loop
= 0; loop
< len
; ++loop
) {
172 tbus
= cpqhp_routing_table
->slots
[loop
].bus
;
173 tdevice
= cpqhp_routing_table
->slots
[loop
].devfn
;
174 tslot
= cpqhp_routing_table
->slots
[loop
].slot
;
175 dbg("%d %d %d %d\n", tbus
, tdevice
>> 3, tdevice
& 0x7, tslot
);
183 * get_subsequent_smbios_entry: get the next entry from bios table.
184 * @smbios_start: where to start in the SMBIOS table
185 * @smbios_table: location of the SMBIOS table
186 * @curr: %NULL or pointer to previously returned structure
188 * Gets the first entry if previous == NULL;
189 * otherwise, returns the next entry.
190 * Uses global SMBIOS Table pointer.
192 * Returns a pointer to an SMBIOS structure or NULL if none found.
194 static void __iomem
*get_subsequent_smbios_entry(void __iomem
*smbios_start
,
195 void __iomem
*smbios_table
,
199 u8 previous_byte
= 1;
200 void __iomem
*p_temp
;
203 if (!smbios_table
|| !curr
)
206 /* set p_max to the end of the table */
207 p_max
= smbios_start
+ readw(smbios_table
+ ST_LENGTH
);
210 p_temp
+= readb(curr
+ SMBIOS_GENERIC_LENGTH
);
212 while ((p_temp
< p_max
) && !bail
) {
213 /* Look for the double NULL terminator
214 * The first condition is the previous byte
215 * and the second is the curr
217 if (!previous_byte
&& !(readb(p_temp
)))
220 previous_byte
= readb(p_temp
);
232 * get_SMBIOS_entry - return the requested SMBIOS entry or %NULL
233 * @smbios_start: where to start in the SMBIOS table
234 * @smbios_table: location of the SMBIOS table
235 * @type: SMBIOS structure type to be returned
236 * @previous: %NULL or pointer to previously returned structure
238 * Gets the first entry of the specified type if previous == %NULL;
239 * Otherwise, returns the next entry of the given type.
240 * Uses global SMBIOS Table pointer.
241 * Uses get_subsequent_smbios_entry.
243 * Returns a pointer to an SMBIOS structure or %NULL if none found.
245 static void __iomem
*get_SMBIOS_entry(void __iomem
*smbios_start
,
246 void __iomem
*smbios_table
,
248 void __iomem
*previous
)
254 previous
= smbios_start
;
256 previous
= get_subsequent_smbios_entry(smbios_start
,
257 smbios_table
, previous
);
260 if (readb(previous
+ SMBIOS_GENERIC_TYPE
) != type
)
261 previous
= get_subsequent_smbios_entry(smbios_start
,
262 smbios_table
, previous
);
269 static void release_slot(struct hotplug_slot
*hotplug_slot
)
271 struct slot
*slot
= hotplug_slot
->private;
273 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
275 kfree(slot
->hotplug_slot
->info
);
276 kfree(slot
->hotplug_slot
);
280 static int ctrl_slot_cleanup(struct controller
*ctrl
)
282 struct slot
*old_slot
, *next_slot
;
284 old_slot
= ctrl
->slot
;
288 /* memory will be freed by the release_slot callback */
289 next_slot
= old_slot
->next
;
290 pci_hp_deregister(old_slot
->hotplug_slot
);
291 old_slot
= next_slot
;
294 cpqhp_remove_debugfs_files(ctrl
);
296 /* Free IRQ associated with hot plug device */
297 free_irq(ctrl
->interrupt
, ctrl
);
298 /* Unmap the memory */
299 iounmap(ctrl
->hpc_reg
);
300 /* Finally reclaim PCI mem */
301 release_mem_region(pci_resource_start(ctrl
->pci_dev
, 0),
302 pci_resource_len(ctrl
->pci_dev
, 0));
309 * get_slot_mapping - determine logical slot mapping for PCI device
311 * Won't work for more than one PCI-PCI bridge in a slot.
313 * @bus_num - bus number of PCI device
314 * @dev_num - device number of PCI device
315 * @slot - Pointer to u8 where slot number will be returned
317 * Output: SUCCESS or FAILURE
320 get_slot_mapping(struct pci_bus
*bus
, u8 bus_num
, u8 dev_num
, u8
*slot
)
326 u8 tbus
, tdevice
, tslot
, bridgeSlot
;
328 dbg("%s: %p, %d, %d, %p\n", __func__
, bus
, bus_num
, dev_num
, slot
);
332 len
= cpqhp_routing_table_length();
333 for (loop
= 0; loop
< len
; ++loop
) {
334 tbus
= cpqhp_routing_table
->slots
[loop
].bus
;
335 tdevice
= cpqhp_routing_table
->slots
[loop
].devfn
>> 3;
336 tslot
= cpqhp_routing_table
->slots
[loop
].slot
;
338 if ((tbus
== bus_num
) && (tdevice
== dev_num
)) {
342 /* Did not get a match on the target PCI device. Check
343 * if the current IRQ table entry is a PCI-to-PCI
344 * bridge device. If so, and it's secondary bus
345 * matches the bus number for the target device, I need
346 * to save the bridge's slot number. If I can not find
347 * an entry for the target device, I will have to
348 * assume it's on the other side of the bridge, and
349 * assign it the bridge's slot.
352 pci_bus_read_config_dword(bus
, PCI_DEVFN(tdevice
, 0),
353 PCI_CLASS_REVISION
, &work
);
355 if ((work
>> 8) == PCI_TO_PCI_BRIDGE_CLASS
) {
356 pci_bus_read_config_dword(bus
,
357 PCI_DEVFN(tdevice
, 0),
358 PCI_PRIMARY_BUS
, &work
);
359 // See if bridge's secondary bus matches target bus.
360 if (((work
>> 8) & 0x000000FF) == (long) bus_num
)
367 /* If we got here, we didn't find an entry in the IRQ mapping table for
368 * the target PCI device. If we did determine that the target device
369 * is on the other side of a PCI-to-PCI bridge, return the slot number
372 if (bridgeSlot
!= 0xFF) {
376 /* Couldn't find an entry in the routing table for this PCI device */
382 * cpqhp_set_attention_status - Turns the Amber LED for a slot on or off
383 * @ctrl: struct controller to use
384 * @func: PCI device/function info
385 * @status: LED control flag: 1 = LED on, 0 = LED off
388 cpqhp_set_attention_status(struct controller
*ctrl
, struct pci_func
*func
,
396 hp_slot
= func
->device
- ctrl
->slot_device_offset
;
398 /* Wait for exclusive access to hardware */
399 mutex_lock(&ctrl
->crit_sect
);
402 amber_LED_on(ctrl
, hp_slot
);
403 else if (status
== 0)
404 amber_LED_off(ctrl
, hp_slot
);
406 /* Done with exclusive hardware access */
407 mutex_unlock(&ctrl
->crit_sect
);
413 /* Wait for SOBS to be unset */
414 wait_for_ctrl_irq(ctrl
);
416 /* Done with exclusive hardware access */
417 mutex_unlock(&ctrl
->crit_sect
);
424 * set_attention_status - Turns the Amber LED for a slot on or off
425 * @hotplug_slot: slot to change LED on
426 * @status: LED control flag
428 static int set_attention_status(struct hotplug_slot
*hotplug_slot
, u8 status
)
430 struct pci_func
*slot_func
;
431 struct slot
*slot
= hotplug_slot
->private;
432 struct controller
*ctrl
= slot
->ctrl
;
438 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
440 if (cpqhp_get_bus_dev(ctrl
, &bus
, &devfn
, slot
->number
) == -1)
444 function
= devfn
& 0x7;
445 dbg("bus, dev, fn = %d, %d, %d\n", bus
, device
, function
);
447 slot_func
= cpqhp_slot_find(bus
, device
, function
);
451 return cpqhp_set_attention_status(ctrl
, slot_func
, status
);
455 static int process_SI(struct hotplug_slot
*hotplug_slot
)
457 struct pci_func
*slot_func
;
458 struct slot
*slot
= hotplug_slot
->private;
459 struct controller
*ctrl
= slot
->ctrl
;
465 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
467 if (cpqhp_get_bus_dev(ctrl
, &bus
, &devfn
, slot
->number
) == -1)
471 function
= devfn
& 0x7;
472 dbg("bus, dev, fn = %d, %d, %d\n", bus
, device
, function
);
474 slot_func
= cpqhp_slot_find(bus
, device
, function
);
478 slot_func
->bus
= bus
;
479 slot_func
->device
= device
;
480 slot_func
->function
= function
;
481 slot_func
->configured
= 0;
482 dbg("board_added(%p, %p)\n", slot_func
, ctrl
);
483 return cpqhp_process_SI(ctrl
, slot_func
);
487 static int process_SS(struct hotplug_slot
*hotplug_slot
)
489 struct pci_func
*slot_func
;
490 struct slot
*slot
= hotplug_slot
->private;
491 struct controller
*ctrl
= slot
->ctrl
;
497 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
499 if (cpqhp_get_bus_dev(ctrl
, &bus
, &devfn
, slot
->number
) == -1)
503 function
= devfn
& 0x7;
504 dbg("bus, dev, fn = %d, %d, %d\n", bus
, device
, function
);
506 slot_func
= cpqhp_slot_find(bus
, device
, function
);
510 dbg("In %s, slot_func = %p, ctrl = %p\n", __func__
, slot_func
, ctrl
);
511 return cpqhp_process_SS(ctrl
, slot_func
);
515 static int hardware_test(struct hotplug_slot
*hotplug_slot
, u32 value
)
517 struct slot
*slot
= hotplug_slot
->private;
518 struct controller
*ctrl
= slot
->ctrl
;
520 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
522 return cpqhp_hardware_test(ctrl
, value
);
526 static int get_power_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
528 struct slot
*slot
= hotplug_slot
->private;
529 struct controller
*ctrl
= slot
->ctrl
;
531 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
533 *value
= get_slot_enabled(ctrl
, slot
);
537 static int get_attention_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
539 struct slot
*slot
= hotplug_slot
->private;
540 struct controller
*ctrl
= slot
->ctrl
;
542 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
544 *value
= cpq_get_attention_status(ctrl
, slot
);
548 static int get_latch_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
550 struct slot
*slot
= hotplug_slot
->private;
551 struct controller
*ctrl
= slot
->ctrl
;
553 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
555 *value
= cpq_get_latch_status(ctrl
, slot
);
560 static int get_adapter_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
562 struct slot
*slot
= hotplug_slot
->private;
563 struct controller
*ctrl
= slot
->ctrl
;
565 dbg("%s - physical_slot = %s\n", __func__
, slot_name(slot
));
567 *value
= get_presence_status(ctrl
, slot
);
572 static struct hotplug_slot_ops cpqphp_hotplug_slot_ops
= {
573 .set_attention_status
= set_attention_status
,
574 .enable_slot
= process_SI
,
575 .disable_slot
= process_SS
,
576 .hardware_test
= hardware_test
,
577 .get_power_status
= get_power_status
,
578 .get_attention_status
= get_attention_status
,
579 .get_latch_status
= get_latch_status
,
580 .get_adapter_status
= get_adapter_status
,
583 #define SLOT_NAME_SIZE 10
585 static int ctrl_slot_setup(struct controller
*ctrl
,
586 void __iomem
*smbios_start
,
587 void __iomem
*smbios_table
)
590 struct hotplug_slot
*hotplug_slot
;
591 struct hotplug_slot_info
*hotplug_slot_info
;
592 struct pci_bus
*bus
= ctrl
->pci_bus
;
598 char name
[SLOT_NAME_SIZE
];
599 void __iomem
*slot_entry
= NULL
;
602 dbg("%s\n", __func__
);
604 tempdword
= readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
606 number_of_slots
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) & 0x0F;
607 slot_device
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4;
608 slot_number
= ctrl
->first_slot
;
610 while (number_of_slots
) {
611 slot
= kzalloc(sizeof(*slot
), GFP_KERNEL
);
617 slot
->hotplug_slot
= kzalloc(sizeof(*(slot
->hotplug_slot
)),
619 if (!slot
->hotplug_slot
) {
623 hotplug_slot
= slot
->hotplug_slot
;
625 hotplug_slot
->info
= kzalloc(sizeof(*(hotplug_slot
->info
)),
627 if (!hotplug_slot
->info
) {
631 hotplug_slot_info
= hotplug_slot
->info
;
634 slot
->bus
= ctrl
->bus
;
635 slot
->device
= slot_device
;
636 slot
->number
= slot_number
;
637 dbg("slot->number = %u\n", slot
->number
);
639 slot_entry
= get_SMBIOS_entry(smbios_start
, smbios_table
, 9,
642 while (slot_entry
&& (readw(slot_entry
+ SMBIOS_SLOT_NUMBER
) !=
644 slot_entry
= get_SMBIOS_entry(smbios_start
,
645 smbios_table
, 9, slot_entry
);
648 slot
->p_sm_slot
= slot_entry
;
650 timer_setup(&slot
->task_event
, cpqhp_pushbutton_thread
, 0);
651 slot
->task_event
.expires
= jiffies
+ 5 * HZ
;
653 /*FIXME: these capabilities aren't used but if they are
654 * they need to be correctly implemented
656 slot
->capabilities
|= PCISLOT_REPLACE_SUPPORTED
;
657 slot
->capabilities
|= PCISLOT_INTERLOCK_SUPPORTED
;
659 if (is_slot64bit(slot
))
660 slot
->capabilities
|= PCISLOT_64_BIT_SUPPORTED
;
661 if (is_slot66mhz(slot
))
662 slot
->capabilities
|= PCISLOT_66_MHZ_SUPPORTED
;
663 if (bus
->cur_bus_speed
== PCI_SPEED_66MHz
)
664 slot
->capabilities
|= PCISLOT_66_MHZ_OPERATION
;
667 slot_device
- (readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4);
670 slot
->capabilities
|=
671 ((((~tempdword
) >> 23) |
672 ((~tempdword
) >> 15)) >> ctrl_slot
) & 0x02;
673 /* Check the switch state */
674 slot
->capabilities
|=
675 ((~tempdword
& 0xFF) >> ctrl_slot
) & 0x01;
676 /* Check the slot enable */
677 slot
->capabilities
|=
678 ((read_slot_enable(ctrl
) << 2) >> ctrl_slot
) & 0x04;
680 /* register this slot with the hotplug pci core */
681 hotplug_slot
->release
= &release_slot
;
682 hotplug_slot
->private = slot
;
683 snprintf(name
, SLOT_NAME_SIZE
, "%u", slot
->number
);
684 hotplug_slot
->ops
= &cpqphp_hotplug_slot_ops
;
686 hotplug_slot_info
->power_status
= get_slot_enabled(ctrl
, slot
);
687 hotplug_slot_info
->attention_status
=
688 cpq_get_attention_status(ctrl
, slot
);
689 hotplug_slot_info
->latch_status
=
690 cpq_get_latch_status(ctrl
, slot
);
691 hotplug_slot_info
->adapter_status
=
692 get_presence_status(ctrl
, slot
);
694 dbg("registering bus %d, dev %d, number %d, ctrl->slot_device_offset %d, slot %d\n",
695 slot
->bus
, slot
->device
,
696 slot
->number
, ctrl
->slot_device_offset
,
698 result
= pci_hp_register(hotplug_slot
,
703 err("pci_hp_register failed with error %d\n", result
);
707 slot
->next
= ctrl
->slot
;
717 kfree(hotplug_slot_info
);
726 static int one_time_init(void)
736 retval
= init_cpqhp_routing_table();
741 pci_print_IRQ_route();
743 dbg("Initialize + Start the notification mechanism\n");
745 retval
= cpqhp_event_start_thread();
749 dbg("Initialize slot lists\n");
750 for (loop
= 0; loop
< 256; loop
++)
751 cpqhp_slot_list
[loop
] = NULL
;
753 /* FIXME: We also need to hook the NMI handler eventually.
754 * this also needs to be worked with Christoph
755 * register_NMI_handler();
757 /* Map rom address */
758 cpqhp_rom_start
= ioremap(ROM_PHY_ADDR
, ROM_PHY_LEN
);
759 if (!cpqhp_rom_start
) {
760 err("Could not ioremap memory region for ROM\n");
765 /* Now, map the int15 entry point if we are on compaq specific
768 compaq_nvram_init(cpqhp_rom_start
);
770 /* Map smbios table entry point structure */
771 smbios_table
= detect_SMBIOS_pointer(cpqhp_rom_start
,
772 cpqhp_rom_start
+ ROM_PHY_LEN
);
774 err("Could not find the SMBIOS pointer in memory\n");
776 goto error_rom_start
;
779 smbios_start
= ioremap(readl(smbios_table
+ ST_ADDRESS
),
780 readw(smbios_table
+ ST_LENGTH
));
782 err("Could not ioremap memory region taken from SMBIOS values\n");
784 goto error_smbios_start
;
792 iounmap(smbios_start
);
794 iounmap(cpqhp_rom_start
);
799 static int cpqhpc_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
808 u16 subsystem_deviceid
;
810 struct controller
*ctrl
;
811 struct pci_func
*func
;
815 err
= pci_enable_device(pdev
);
817 printk(KERN_ERR MY_NAME
": cannot enable PCI device %s (%d)\n",
818 pci_name(pdev
), err
);
822 bus
= pdev
->subordinate
;
824 pci_notice(pdev
, "the device is not a bridge, skipping\n");
826 goto err_disable_device
;
829 /* Need to read VID early b/c it's used to differentiate CPQ and INTC
832 vendor_id
= pdev
->vendor
;
833 if ((vendor_id
!= PCI_VENDOR_ID_COMPAQ
) &&
834 (vendor_id
!= PCI_VENDOR_ID_INTEL
)) {
835 err(msg_HPC_non_compaq_or_intel
);
837 goto err_disable_device
;
839 dbg("Vendor ID: %x\n", vendor_id
);
841 dbg("revision: %d\n", pdev
->revision
);
842 if ((vendor_id
== PCI_VENDOR_ID_COMPAQ
) && (!pdev
->revision
)) {
843 err(msg_HPC_rev_error
);
845 goto err_disable_device
;
848 /* Check for the proper subsystem IDs
849 * Intel uses a different SSID programming model than Compaq.
850 * For Intel, each SSID bit identifies a PHP capability.
851 * Also Intel HPCs may have RID=0.
853 if ((pdev
->revision
<= 2) && (vendor_id
!= PCI_VENDOR_ID_INTEL
)) {
854 err(msg_HPC_not_supported
);
856 goto err_disable_device
;
859 /* TODO: This code can be made to support non-Compaq or Intel
862 subsystem_vid
= pdev
->subsystem_vendor
;
863 dbg("Subsystem Vendor ID: %x\n", subsystem_vid
);
864 if ((subsystem_vid
!= PCI_VENDOR_ID_COMPAQ
) && (subsystem_vid
!= PCI_VENDOR_ID_INTEL
)) {
865 err(msg_HPC_non_compaq_or_intel
);
867 goto err_disable_device
;
870 ctrl
= kzalloc(sizeof(struct controller
), GFP_KERNEL
);
873 goto err_disable_device
;
876 subsystem_deviceid
= pdev
->subsystem_device
;
878 info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid
);
880 /* Set Vendor ID, so it can be accessed later from other
883 ctrl
->vendor_id
= vendor_id
;
885 switch (subsystem_vid
) {
886 case PCI_VENDOR_ID_COMPAQ
:
887 if (pdev
->revision
>= 0x13) { /* CIOBX */
889 ctrl
->slot_switch_type
= 1;
890 ctrl
->push_button
= 1;
891 ctrl
->pci_config_space
= 1;
892 ctrl
->defeature_PHP
= 1;
893 ctrl
->pcix_support
= 1;
894 ctrl
->pcix_speed_capability
= 1;
895 pci_read_config_byte(pdev
, 0x41, &bus_cap
);
896 if (bus_cap
& 0x80) {
897 dbg("bus max supports 133MHz PCI-X\n");
898 bus
->max_bus_speed
= PCI_SPEED_133MHz_PCIX
;
901 if (bus_cap
& 0x40) {
902 dbg("bus max supports 100MHz PCI-X\n");
903 bus
->max_bus_speed
= PCI_SPEED_100MHz_PCIX
;
906 if (bus_cap
& 0x20) {
907 dbg("bus max supports 66MHz PCI-X\n");
908 bus
->max_bus_speed
= PCI_SPEED_66MHz_PCIX
;
911 if (bus_cap
& 0x10) {
912 dbg("bus max supports 66MHz PCI\n");
913 bus
->max_bus_speed
= PCI_SPEED_66MHz
;
920 switch (subsystem_deviceid
) {
922 /* Original 6500/7000 implementation */
923 ctrl
->slot_switch_type
= 1;
924 bus
->max_bus_speed
= PCI_SPEED_33MHz
;
925 ctrl
->push_button
= 0;
926 ctrl
->pci_config_space
= 1;
927 ctrl
->defeature_PHP
= 1;
928 ctrl
->pcix_support
= 0;
929 ctrl
->pcix_speed_capability
= 0;
931 case PCI_SUB_HPC_ID2
:
932 /* First Pushbutton implementation */
934 ctrl
->slot_switch_type
= 1;
935 bus
->max_bus_speed
= PCI_SPEED_33MHz
;
936 ctrl
->push_button
= 1;
937 ctrl
->pci_config_space
= 1;
938 ctrl
->defeature_PHP
= 1;
939 ctrl
->pcix_support
= 0;
940 ctrl
->pcix_speed_capability
= 0;
942 case PCI_SUB_HPC_ID_INTC
:
943 /* Third party (6500/7000) */
944 ctrl
->slot_switch_type
= 1;
945 bus
->max_bus_speed
= PCI_SPEED_33MHz
;
946 ctrl
->push_button
= 0;
947 ctrl
->pci_config_space
= 1;
948 ctrl
->defeature_PHP
= 1;
949 ctrl
->pcix_support
= 0;
950 ctrl
->pcix_speed_capability
= 0;
952 case PCI_SUB_HPC_ID3
:
953 /* First 66 Mhz implementation */
955 ctrl
->slot_switch_type
= 1;
956 bus
->max_bus_speed
= PCI_SPEED_66MHz
;
957 ctrl
->push_button
= 1;
958 ctrl
->pci_config_space
= 1;
959 ctrl
->defeature_PHP
= 1;
960 ctrl
->pcix_support
= 0;
961 ctrl
->pcix_speed_capability
= 0;
963 case PCI_SUB_HPC_ID4
:
964 /* First PCI-X implementation, 100MHz */
966 ctrl
->slot_switch_type
= 1;
967 bus
->max_bus_speed
= PCI_SPEED_100MHz_PCIX
;
968 ctrl
->push_button
= 1;
969 ctrl
->pci_config_space
= 1;
970 ctrl
->defeature_PHP
= 1;
971 ctrl
->pcix_support
= 1;
972 ctrl
->pcix_speed_capability
= 0;
975 err(msg_HPC_not_supported
);
981 case PCI_VENDOR_ID_INTEL
:
982 /* Check for speed capability (0=33, 1=66) */
983 if (subsystem_deviceid
& 0x0001)
984 bus
->max_bus_speed
= PCI_SPEED_66MHz
;
986 bus
->max_bus_speed
= PCI_SPEED_33MHz
;
988 /* Check for push button */
989 if (subsystem_deviceid
& 0x0002)
990 ctrl
->push_button
= 0;
992 ctrl
->push_button
= 1;
994 /* Check for slot switch type (0=mechanical, 1=not mechanical) */
995 if (subsystem_deviceid
& 0x0004)
996 ctrl
->slot_switch_type
= 0;
998 ctrl
->slot_switch_type
= 1;
1000 /* PHP Status (0=De-feature PHP, 1=Normal operation) */
1001 if (subsystem_deviceid
& 0x0008)
1002 ctrl
->defeature_PHP
= 1; /* PHP supported */
1004 ctrl
->defeature_PHP
= 0; /* PHP not supported */
1006 /* Alternate Base Address Register Interface
1007 * (0=not supported, 1=supported)
1009 if (subsystem_deviceid
& 0x0010)
1010 ctrl
->alternate_base_address
= 1;
1012 ctrl
->alternate_base_address
= 0;
1014 /* PCI Config Space Index (0=not supported, 1=supported) */
1015 if (subsystem_deviceid
& 0x0020)
1016 ctrl
->pci_config_space
= 1;
1018 ctrl
->pci_config_space
= 0;
1021 if (subsystem_deviceid
& 0x0080) {
1022 ctrl
->pcix_support
= 1;
1023 if (subsystem_deviceid
& 0x0040)
1024 /* 133MHz PCI-X if bit 7 is 1 */
1025 ctrl
->pcix_speed_capability
= 1;
1027 /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
1028 /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
1029 ctrl
->pcix_speed_capability
= 0;
1031 /* Conventional PCI */
1032 ctrl
->pcix_support
= 0;
1033 ctrl
->pcix_speed_capability
= 0;
1038 err(msg_HPC_not_supported
);
1043 /* Tell the user that we found one. */
1044 info("Initializing the PCI hot plug controller residing on PCI bus %d\n",
1047 dbg("Hotplug controller capabilities:\n");
1048 dbg(" speed_capability %d\n", bus
->max_bus_speed
);
1049 dbg(" slot_switch_type %s\n", ctrl
->slot_switch_type
?
1050 "switch present" : "no switch");
1051 dbg(" defeature_PHP %s\n", ctrl
->defeature_PHP
?
1052 "PHP supported" : "PHP not supported");
1053 dbg(" alternate_base_address %s\n", ctrl
->alternate_base_address
?
1054 "supported" : "not supported");
1055 dbg(" pci_config_space %s\n", ctrl
->pci_config_space
?
1056 "supported" : "not supported");
1057 dbg(" pcix_speed_capability %s\n", ctrl
->pcix_speed_capability
?
1058 "supported" : "not supported");
1059 dbg(" pcix_support %s\n", ctrl
->pcix_support
?
1060 "supported" : "not supported");
1062 ctrl
->pci_dev
= pdev
;
1063 pci_set_drvdata(pdev
, ctrl
);
1065 /* make our own copy of the pci bus structure,
1066 * as we like tweaking it a lot */
1067 ctrl
->pci_bus
= kmemdup(pdev
->bus
, sizeof(*ctrl
->pci_bus
), GFP_KERNEL
);
1068 if (!ctrl
->pci_bus
) {
1069 err("out of memory\n");
1074 ctrl
->bus
= pdev
->bus
->number
;
1075 ctrl
->rev
= pdev
->revision
;
1076 dbg("bus device function rev: %d %d %d %d\n", ctrl
->bus
,
1077 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
), ctrl
->rev
);
1079 mutex_init(&ctrl
->crit_sect
);
1080 init_waitqueue_head(&ctrl
->queue
);
1082 /* initialize our threads if they haven't already been started up */
1083 rc
= one_time_init();
1087 dbg("pdev = %p\n", pdev
);
1088 dbg("pci resource start %llx\n", (unsigned long long)pci_resource_start(pdev
, 0));
1089 dbg("pci resource len %llx\n", (unsigned long long)pci_resource_len(pdev
, 0));
1091 if (!request_mem_region(pci_resource_start(pdev
, 0),
1092 pci_resource_len(pdev
, 0), MY_NAME
)) {
1093 err("cannot reserve MMIO region\n");
1098 ctrl
->hpc_reg
= ioremap(pci_resource_start(pdev
, 0),
1099 pci_resource_len(pdev
, 0));
1100 if (!ctrl
->hpc_reg
) {
1101 err("cannot remap MMIO region %llx @ %llx\n",
1102 (unsigned long long)pci_resource_len(pdev
, 0),
1103 (unsigned long long)pci_resource_start(pdev
, 0));
1105 goto err_free_mem_region
;
1108 /* Check for 66Mhz operation */
1109 bus
->cur_bus_speed
= get_controller_speed(ctrl
);
1112 /********************************************************
1114 * Save configuration headers for this and
1115 * subordinate PCI buses
1117 ********************************************************/
1119 /* find the physical slot number of the first hot plug slot */
1121 /* Get slot won't work for devices behind bridges, but
1122 * in this case it will always be called for the "base"
1123 * bus/dev/func of a slot.
1124 * CS: this is leveraging the PCIIRQ routing code from the kernel
1125 * (pci-pc.c: get_irq_routing_table) */
1126 rc
= get_slot_mapping(ctrl
->pci_bus
, pdev
->bus
->number
,
1127 (readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4),
1128 &(ctrl
->first_slot
));
1129 dbg("get_slot_mapping: first_slot = %d, returned = %d\n",
1130 ctrl
->first_slot
, rc
);
1132 err(msg_initialization_err
, rc
);
1136 /* Store PCI Config Space for all devices on this bus */
1137 rc
= cpqhp_save_config(ctrl
, ctrl
->bus
, readb(ctrl
->hpc_reg
+ SLOT_MASK
));
1139 err("%s: unable to save PCI configuration data, error %d\n",
1145 * Get IO, memory, and IRQ resources for new devices
1147 /* The next line is required for cpqhp_find_available_resources */
1148 ctrl
->interrupt
= pdev
->irq
;
1149 if (ctrl
->interrupt
< 0x10) {
1150 cpqhp_legacy_mode
= 1;
1151 dbg("System seems to be configured for Full Table Mapped MPS mode\n");
1154 ctrl
->cfgspc_irq
= 0;
1155 pci_read_config_byte(pdev
, PCI_INTERRUPT_LINE
, &ctrl
->cfgspc_irq
);
1157 rc
= cpqhp_find_available_resources(ctrl
, cpqhp_rom_start
);
1158 ctrl
->add_support
= !rc
;
1160 dbg("cpqhp_find_available_resources = 0x%x\n", rc
);
1161 err("unable to locate PCI configuration resources for hot plug add.\n");
1166 * Finish setting up the hot plug ctrl device
1168 ctrl
->slot_device_offset
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4;
1169 dbg("NumSlots %d\n", ctrl
->slot_device_offset
);
1171 ctrl
->next_event
= 0;
1173 /* Setup the slot information structures */
1174 rc
= ctrl_slot_setup(ctrl
, smbios_start
, smbios_table
);
1176 err(msg_initialization_err
, 6);
1177 err("%s: unable to save PCI configuration data, error %d\n",
1182 /* Mask all general input interrupts */
1183 writel(0xFFFFFFFFL
, ctrl
->hpc_reg
+ INT_MASK
);
1185 /* set up the interrupt */
1186 dbg("HPC interrupt = %d\n", ctrl
->interrupt
);
1187 if (request_irq(ctrl
->interrupt
, cpqhp_ctrl_intr
,
1188 IRQF_SHARED
, MY_NAME
, ctrl
)) {
1189 err("Can't get irq %d for the hotplug pci controller\n",
1195 /* Enable Shift Out interrupt and clear it, also enable SERR on power
1198 temp_word
= readw(ctrl
->hpc_reg
+ MISC
);
1199 temp_word
|= 0x4006;
1200 writew(temp_word
, ctrl
->hpc_reg
+ MISC
);
1202 /* Changed 05/05/97 to clear all interrupts at start */
1203 writel(0xFFFFFFFFL
, ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
1205 ctrl
->ctrl_int_comp
= readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
1207 writel(0x0L
, ctrl
->hpc_reg
+ INT_MASK
);
1209 if (!cpqhp_ctrl_list
) {
1210 cpqhp_ctrl_list
= ctrl
;
1213 ctrl
->next
= cpqhp_ctrl_list
;
1214 cpqhp_ctrl_list
= ctrl
;
1217 /* turn off empty slots here unless command line option "ON" set
1218 * Wait for exclusive access to hardware
1220 mutex_lock(&ctrl
->crit_sect
);
1222 num_of_slots
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) & 0x0F;
1224 /* find first device number for the ctrl */
1225 device
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4;
1227 while (num_of_slots
) {
1228 dbg("num_of_slots: %d\n", num_of_slots
);
1229 func
= cpqhp_slot_find(ctrl
->bus
, device
, 0);
1233 hp_slot
= func
->device
- ctrl
->slot_device_offset
;
1234 dbg("hp_slot: %d\n", hp_slot
);
1236 /* We have to save the presence info for these slots */
1237 temp_word
= ctrl
->ctrl_int_comp
>> 16;
1238 func
->presence_save
= (temp_word
>> hp_slot
) & 0x01;
1239 func
->presence_save
|= (temp_word
>> (hp_slot
+ 7)) & 0x02;
1241 if (ctrl
->ctrl_int_comp
& (0x1L
<< hp_slot
))
1242 func
->switch_save
= 0;
1244 func
->switch_save
= 0x10;
1247 if (!func
->is_a_board
) {
1248 green_LED_off(ctrl
, hp_slot
);
1249 slot_disable(ctrl
, hp_slot
);
1258 /* Wait for SOBS to be unset */
1259 wait_for_ctrl_irq(ctrl
);
1262 rc
= init_SERR(ctrl
);
1264 err("init_SERR failed\n");
1265 mutex_unlock(&ctrl
->crit_sect
);
1269 /* Done with exclusive hardware access */
1270 mutex_unlock(&ctrl
->crit_sect
);
1272 cpqhp_create_debugfs_files(ctrl
);
1277 free_irq(ctrl
->interrupt
, ctrl
);
1279 iounmap(ctrl
->hpc_reg
);
1280 err_free_mem_region
:
1281 release_mem_region(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
1283 kfree(ctrl
->pci_bus
);
1287 pci_disable_device(pdev
);
1291 static void __exit
unload_cpqphpd(void)
1293 struct pci_func
*next
;
1294 struct pci_func
*TempSlot
;
1297 struct controller
*ctrl
;
1298 struct controller
*tctrl
;
1299 struct pci_resource
*res
;
1300 struct pci_resource
*tres
;
1302 rc
= compaq_nvram_store(cpqhp_rom_start
);
1304 ctrl
= cpqhp_ctrl_list
;
1307 if (ctrl
->hpc_reg
) {
1309 rc
= read_slot_enable(ctrl
);
1311 writeb(0, ctrl
->hpc_reg
+ SLOT_SERR
);
1312 writel(0xFFFFFFC0L
| ~rc
, ctrl
->hpc_reg
+ INT_MASK
);
1314 misc
= readw(ctrl
->hpc_reg
+ MISC
);
1316 writew(misc
, ctrl
->hpc_reg
+ MISC
);
1319 ctrl_slot_cleanup(ctrl
);
1321 res
= ctrl
->io_head
;
1328 res
= ctrl
->mem_head
;
1335 res
= ctrl
->p_mem_head
;
1342 res
= ctrl
->bus_head
;
1349 kfree(ctrl
->pci_bus
);
1356 for (loop
= 0; loop
< 256; loop
++) {
1357 next
= cpqhp_slot_list
[loop
];
1358 while (next
!= NULL
) {
1359 res
= next
->io_head
;
1366 res
= next
->mem_head
;
1373 res
= next
->p_mem_head
;
1380 res
= next
->bus_head
;
1393 /* Stop the notification mechanism */
1395 cpqhp_event_stop_thread();
1397 /* unmap the rom address */
1398 if (cpqhp_rom_start
)
1399 iounmap(cpqhp_rom_start
);
1401 iounmap(smbios_start
);
1404 static const struct pci_device_id hpcd_pci_tbl
[] = {
1406 /* handle any PCI Hotplug controller */
1407 .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG
<< 8) | 0x00),
1410 /* no matter who makes it */
1411 .vendor
= PCI_ANY_ID
,
1412 .device
= PCI_ANY_ID
,
1413 .subvendor
= PCI_ANY_ID
,
1414 .subdevice
= PCI_ANY_ID
,
1416 }, { /* end: all zeroes */ }
1419 MODULE_DEVICE_TABLE(pci
, hpcd_pci_tbl
);
1421 static struct pci_driver cpqhpc_driver
= {
1422 .name
= "compaq_pci_hotplug",
1423 .id_table
= hpcd_pci_tbl
,
1424 .probe
= cpqhpc_probe
,
1425 /* remove: cpqhpc_remove_one, */
1428 static int __init
cpqhpc_init(void)
1432 cpqhp_debug
= debug
;
1434 info(DRIVER_DESC
" version: " DRIVER_VERSION
"\n");
1435 cpqhp_initialize_debugfs();
1436 result
= pci_register_driver(&cpqhpc_driver
);
1437 dbg("pci_register_driver = %d\n", result
);
1441 static void __exit
cpqhpc_cleanup(void)
1443 dbg("unload_cpqphpd()\n");
1446 dbg("pci_unregister_driver\n");
1447 pci_unregister_driver(&cpqhpc_driver
);
1448 cpqhp_shutdown_debugfs();
1451 module_init(cpqhpc_init
);
1452 module_exit(cpqhpc_cleanup
);