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/moduleparam.h>
35 #include <linux/kernel.h>
36 #include <linux/types.h>
37 #include <linux/proc_fs.h>
38 #include <linux/slab.h>
39 #include <linux/workqueue.h>
40 #include <linux/pci.h>
41 #include <linux/init.h>
42 #include <linux/interrupt.h>
44 #include <asm/uaccess.h>
47 #include "cpqphp_nvram.h"
48 #include "../../../arch/i386/pci/pci.h" /* horrible hack showing how processor dependent we are... */
51 /* Global variables */
53 int cpqhp_legacy_mode
;
54 struct controller
*cpqhp_ctrl_list
; /* = NULL */
55 struct pci_func
*cpqhp_slot_list
[256];
58 static void __iomem
*smbios_table
;
59 static void __iomem
*smbios_start
;
60 static void __iomem
*cpqhp_rom_start
;
61 static int power_mode
;
63 static int initialized
;
65 #define DRIVER_VERSION "0.9.8"
66 #define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>"
67 #define DRIVER_DESC "Compaq Hot Plug PCI Controller Driver"
69 MODULE_AUTHOR(DRIVER_AUTHOR
);
70 MODULE_DESCRIPTION(DRIVER_DESC
);
71 MODULE_LICENSE("GPL");
73 module_param(power_mode
, bool, 0644);
74 MODULE_PARM_DESC(power_mode
, "Power mode enabled or not");
76 module_param(debug
, bool, 0644);
77 MODULE_PARM_DESC(debug
, "Debugging mode enabled or not");
79 #define CPQHPC_MODULE_MINOR 208
81 static int one_time_init (void);
82 static int set_attention_status (struct hotplug_slot
*slot
, u8 value
);
83 static int process_SI (struct hotplug_slot
*slot
);
84 static int process_SS (struct hotplug_slot
*slot
);
85 static int hardware_test (struct hotplug_slot
*slot
, u32 value
);
86 static int get_power_status (struct hotplug_slot
*slot
, u8
*value
);
87 static int get_attention_status (struct hotplug_slot
*slot
, u8
*value
);
88 static int get_latch_status (struct hotplug_slot
*slot
, u8
*value
);
89 static int get_adapter_status (struct hotplug_slot
*slot
, u8
*value
);
90 static int get_max_bus_speed (struct hotplug_slot
*slot
, enum pci_bus_speed
*value
);
91 static int get_cur_bus_speed (struct hotplug_slot
*slot
, enum pci_bus_speed
*value
);
93 static struct hotplug_slot_ops cpqphp_hotplug_slot_ops
= {
95 .set_attention_status
= set_attention_status
,
96 .enable_slot
= process_SI
,
97 .disable_slot
= process_SS
,
98 .hardware_test
= hardware_test
,
99 .get_power_status
= get_power_status
,
100 .get_attention_status
= get_attention_status
,
101 .get_latch_status
= get_latch_status
,
102 .get_adapter_status
= get_adapter_status
,
103 .get_max_bus_speed
= get_max_bus_speed
,
104 .get_cur_bus_speed
= get_cur_bus_speed
,
108 static inline int is_slot64bit(struct slot
*slot
)
110 return (readb(slot
->p_sm_slot
+ SMBIOS_SLOT_WIDTH
) == 0x06) ? 1 : 0;
113 static inline int is_slot66mhz(struct slot
*slot
)
115 return (readb(slot
->p_sm_slot
+ SMBIOS_SLOT_TYPE
) == 0x0E) ? 1 : 0;
119 * detect_SMBIOS_pointer - find the System Management BIOS Table in mem region.
121 * @begin: begin pointer for region to be scanned.
122 * @end: end pointer for region to be scanned.
124 * Returns pointer to the head of the SMBIOS tables (or NULL)
127 static void __iomem
* detect_SMBIOS_pointer(void __iomem
*begin
, void __iomem
*end
)
131 u8 temp1
, temp2
, temp3
, temp4
;
134 endp
= (end
- sizeof(u32
) + 1);
136 for (fp
= begin
; fp
<= endp
; fp
+= 16) {
153 dbg("Discovered SMBIOS Entry point at %p\n", fp
);
159 * init_SERR - Initializes the per slot SERR generation.
161 * For unexpected switch opens
164 static int init_SERR(struct controller
* ctrl
)
173 tempdword
= ctrl
->first_slot
;
175 number_of_slots
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) & 0x0F;
176 // Loop through slots
177 while (number_of_slots
) {
178 physical_slot
= tempdword
;
179 writeb(0, ctrl
->hpc_reg
+ SLOT_SERR
);
188 /* nice debugging output */
189 static int pci_print_IRQ_route (void)
191 struct irq_routing_table
*routing_table
;
195 u8 tbus
, tdevice
, tslot
;
197 routing_table
= pcibios_get_irq_routing_table();
198 if (routing_table
== NULL
) {
199 err("No BIOS Routing Table??? Not good\n");
203 len
= (routing_table
->size
- sizeof(struct irq_routing_table
)) /
204 sizeof(struct irq_info
);
205 // Make sure I got at least one entry
207 kfree(routing_table
);
211 dbg("bus dev func slot\n");
213 for (loop
= 0; loop
< len
; ++loop
) {
214 tbus
= routing_table
->slots
[loop
].bus
;
215 tdevice
= routing_table
->slots
[loop
].devfn
;
216 tslot
= routing_table
->slots
[loop
].slot
;
217 dbg("%d %d %d %d\n", tbus
, tdevice
>> 3, tdevice
& 0x7, tslot
);
220 kfree(routing_table
);
226 * get_subsequent_smbios_entry: get the next entry from bios table.
228 * Gets the first entry if previous == NULL
229 * Otherwise, returns the next entry
230 * Uses global SMBIOS Table pointer
232 * @curr: %NULL or pointer to previously returned structure
234 * returns a pointer to an SMBIOS structure or NULL if none found
236 static void __iomem
*get_subsequent_smbios_entry(void __iomem
*smbios_start
,
237 void __iomem
*smbios_table
,
241 u8 previous_byte
= 1;
242 void __iomem
*p_temp
;
245 if (!smbios_table
|| !curr
)
248 // set p_max to the end of the table
249 p_max
= smbios_start
+ readw(smbios_table
+ ST_LENGTH
);
252 p_temp
+= readb(curr
+ SMBIOS_GENERIC_LENGTH
);
254 while ((p_temp
< p_max
) && !bail
) {
255 /* Look for the double NULL terminator
256 * The first condition is the previous byte
257 * and the second is the curr */
258 if (!previous_byte
&& !(readb(p_temp
))) {
262 previous_byte
= readb(p_temp
);
266 if (p_temp
< p_max
) {
277 * @type:SMBIOS structure type to be returned
278 * @previous: %NULL or pointer to previously returned structure
280 * Gets the first entry of the specified type if previous == NULL
281 * Otherwise, returns the next entry of the given type.
282 * Uses global SMBIOS Table pointer
283 * Uses get_subsequent_smbios_entry
285 * returns a pointer to an SMBIOS structure or %NULL if none found
287 static void __iomem
*get_SMBIOS_entry(void __iomem
*smbios_start
,
288 void __iomem
*smbios_table
,
290 void __iomem
*previous
)
296 previous
= smbios_start
;
298 previous
= get_subsequent_smbios_entry(smbios_start
,
299 smbios_table
, previous
);
303 if (readb(previous
+ SMBIOS_GENERIC_TYPE
) != type
) {
304 previous
= get_subsequent_smbios_entry(smbios_start
,
305 smbios_table
, previous
);
314 static void release_slot(struct hotplug_slot
*hotplug_slot
)
316 struct slot
*slot
= hotplug_slot
->private;
318 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
320 kfree(slot
->hotplug_slot
->info
);
321 kfree(slot
->hotplug_slot
->name
);
322 kfree(slot
->hotplug_slot
);
326 static int ctrl_slot_setup(struct controller
*ctrl
,
327 void __iomem
*smbios_start
,
328 void __iomem
*smbios_table
)
330 struct slot
*new_slot
;
336 void __iomem
*slot_entry
= NULL
;
337 int result
= -ENOMEM
;
339 dbg("%s\n", __FUNCTION__
);
341 tempdword
= readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
343 number_of_slots
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) & 0x0F;
344 slot_device
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4;
345 slot_number
= ctrl
->first_slot
;
347 while (number_of_slots
) {
348 new_slot
= kmalloc(sizeof(*new_slot
), GFP_KERNEL
);
352 memset(new_slot
, 0, sizeof(struct slot
));
353 new_slot
->hotplug_slot
= kmalloc(sizeof(*(new_slot
->hotplug_slot
)),
355 if (!new_slot
->hotplug_slot
)
357 memset(new_slot
->hotplug_slot
, 0, sizeof(struct hotplug_slot
));
359 new_slot
->hotplug_slot
->info
=
360 kmalloc(sizeof(*(new_slot
->hotplug_slot
->info
)),
362 if (!new_slot
->hotplug_slot
->info
)
364 memset(new_slot
->hotplug_slot
->info
, 0,
365 sizeof(struct hotplug_slot_info
));
366 new_slot
->hotplug_slot
->name
= kmalloc(SLOT_NAME_SIZE
, GFP_KERNEL
);
367 if (!new_slot
->hotplug_slot
->name
)
370 new_slot
->ctrl
= ctrl
;
371 new_slot
->bus
= ctrl
->bus
;
372 new_slot
->device
= slot_device
;
373 new_slot
->number
= slot_number
;
374 dbg("slot->number = %d\n",new_slot
->number
);
376 slot_entry
= get_SMBIOS_entry(smbios_start
, smbios_table
, 9,
379 while (slot_entry
&& (readw(slot_entry
+ SMBIOS_SLOT_NUMBER
) != new_slot
->number
)) {
380 slot_entry
= get_SMBIOS_entry(smbios_start
,
381 smbios_table
, 9, slot_entry
);
384 new_slot
->p_sm_slot
= slot_entry
;
386 init_timer(&new_slot
->task_event
);
387 new_slot
->task_event
.expires
= jiffies
+ 5 * HZ
;
388 new_slot
->task_event
.function
= cpqhp_pushbutton_thread
;
390 //FIXME: these capabilities aren't used but if they are
391 // they need to be correctly implemented
392 new_slot
->capabilities
|= PCISLOT_REPLACE_SUPPORTED
;
393 new_slot
->capabilities
|= PCISLOT_INTERLOCK_SUPPORTED
;
395 if (is_slot64bit(new_slot
))
396 new_slot
->capabilities
|= PCISLOT_64_BIT_SUPPORTED
;
397 if (is_slot66mhz(new_slot
))
398 new_slot
->capabilities
|= PCISLOT_66_MHZ_SUPPORTED
;
399 if (ctrl
->speed
== PCI_SPEED_66MHz
)
400 new_slot
->capabilities
|= PCISLOT_66_MHZ_OPERATION
;
402 ctrl_slot
= slot_device
- (readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4);
405 new_slot
->capabilities
|= ((((~tempdword
) >> 23) | ((~tempdword
) >> 15)) >> ctrl_slot
) & 0x02;
406 // Check the switch state
407 new_slot
->capabilities
|= ((~tempdword
& 0xFF) >> ctrl_slot
) & 0x01;
408 // Check the slot enable
409 new_slot
->capabilities
|= ((read_slot_enable(ctrl
) << 2) >> ctrl_slot
) & 0x04;
411 /* register this slot with the hotplug pci core */
412 new_slot
->hotplug_slot
->release
= &release_slot
;
413 new_slot
->hotplug_slot
->private = new_slot
;
414 make_slot_name(new_slot
->hotplug_slot
->name
, SLOT_NAME_SIZE
, new_slot
);
415 new_slot
->hotplug_slot
->ops
= &cpqphp_hotplug_slot_ops
;
417 new_slot
->hotplug_slot
->info
->power_status
= get_slot_enabled(ctrl
, new_slot
);
418 new_slot
->hotplug_slot
->info
->attention_status
= cpq_get_attention_status(ctrl
, new_slot
);
419 new_slot
->hotplug_slot
->info
->latch_status
= cpq_get_latch_status(ctrl
, new_slot
);
420 new_slot
->hotplug_slot
->info
->adapter_status
= get_presence_status(ctrl
, new_slot
);
422 dbg ("registering bus %d, dev %d, number %d, "
423 "ctrl->slot_device_offset %d, slot %d\n",
424 new_slot
->bus
, new_slot
->device
,
425 new_slot
->number
, ctrl
->slot_device_offset
,
427 result
= pci_hp_register (new_slot
->hotplug_slot
);
429 err ("pci_hp_register failed with error %d\n", result
);
433 new_slot
->next
= ctrl
->slot
;
434 ctrl
->slot
= new_slot
;
444 kfree(new_slot
->hotplug_slot
->name
);
446 kfree(new_slot
->hotplug_slot
->info
);
448 kfree(new_slot
->hotplug_slot
);
455 static int ctrl_slot_cleanup (struct controller
* ctrl
)
457 struct slot
*old_slot
, *next_slot
;
459 old_slot
= ctrl
->slot
;
463 /* memory will be freed by the release_slot callback */
464 next_slot
= old_slot
->next
;
465 pci_hp_deregister (old_slot
->hotplug_slot
);
466 old_slot
= next_slot
;
469 //Free IRQ associated with hot plug device
470 free_irq(ctrl
->interrupt
, ctrl
);
472 iounmap(ctrl
->hpc_reg
);
473 //Finally reclaim PCI mem
474 release_mem_region(pci_resource_start(ctrl
->pci_dev
, 0),
475 pci_resource_len(ctrl
->pci_dev
, 0));
481 //============================================================================
482 // function: get_slot_mapping
484 // Description: Attempts to determine a logical slot mapping for a PCI
485 // device. Won't work for more than one PCI-PCI bridge
488 // Input: u8 bus_num - bus number of PCI device
489 // u8 dev_num - device number of PCI device
490 // u8 *slot - Pointer to u8 where slot number will
493 // Output: SUCCESS or FAILURE
494 //=============================================================================
496 get_slot_mapping(struct pci_bus
*bus
, u8 bus_num
, u8 dev_num
, u8
*slot
)
498 struct irq_routing_table
*PCIIRQRoutingInfoLength
;
503 u8 tbus
, tdevice
, tslot
, bridgeSlot
;
505 dbg("%s: %p, %d, %d, %p\n", __FUNCTION__
, bus
, bus_num
, dev_num
, slot
);
509 PCIIRQRoutingInfoLength
= pcibios_get_irq_routing_table();
510 if (!PCIIRQRoutingInfoLength
)
513 len
= (PCIIRQRoutingInfoLength
->size
-
514 sizeof(struct irq_routing_table
)) / sizeof(struct irq_info
);
515 // Make sure I got at least one entry
517 kfree(PCIIRQRoutingInfoLength
);
521 for (loop
= 0; loop
< len
; ++loop
) {
522 tbus
= PCIIRQRoutingInfoLength
->slots
[loop
].bus
;
523 tdevice
= PCIIRQRoutingInfoLength
->slots
[loop
].devfn
>> 3;
524 tslot
= PCIIRQRoutingInfoLength
->slots
[loop
].slot
;
526 if ((tbus
== bus_num
) && (tdevice
== dev_num
)) {
528 kfree(PCIIRQRoutingInfoLength
);
531 /* Did not get a match on the target PCI device. Check
532 * if the current IRQ table entry is a PCI-to-PCI bridge
533 * device. If so, and it's secondary bus matches the
534 * bus number for the target device, I need to save the
535 * bridge's slot number. If I can not find an entry for
536 * the target device, I will have to assume it's on the
537 * other side of the bridge, and assign it the bridge's
540 pci_bus_read_config_dword(bus
, PCI_DEVFN(tdevice
, 0),
541 PCI_REVISION_ID
, &work
);
543 if ((work
>> 8) == PCI_TO_PCI_BRIDGE_CLASS
) {
544 pci_bus_read_config_dword(bus
,
545 PCI_DEVFN(tdevice
, 0),
546 PCI_PRIMARY_BUS
, &work
);
547 // See if bridge's secondary bus matches target bus.
548 if (((work
>> 8) & 0x000000FF) == (long) bus_num
) {
556 // If we got here, we didn't find an entry in the IRQ mapping table
557 // for the target PCI device. If we did determine that the target
558 // device is on the other side of a PCI-to-PCI bridge, return the
559 // slot number for the bridge.
560 if (bridgeSlot
!= 0xFF) {
562 kfree(PCIIRQRoutingInfoLength
);
565 kfree(PCIIRQRoutingInfoLength
);
566 // Couldn't find an entry in the routing table for this PCI device
572 * cpqhp_set_attention_status - Turns the Amber LED for a slot on or off
576 cpqhp_set_attention_status(struct controller
*ctrl
, struct pci_func
*func
,
584 hp_slot
= func
->device
- ctrl
->slot_device_offset
;
586 // Wait for exclusive access to hardware
587 down(&ctrl
->crit_sect
);
590 amber_LED_on (ctrl
, hp_slot
);
591 } else if (status
== 0) {
592 amber_LED_off (ctrl
, hp_slot
);
594 // Done with exclusive hardware access
595 up(&ctrl
->crit_sect
);
601 // Wait for SOBS to be unset
602 wait_for_ctrl_irq (ctrl
);
604 // Done with exclusive hardware access
605 up(&ctrl
->crit_sect
);
612 * set_attention_status - Turns the Amber LED for a slot on or off
615 static int set_attention_status (struct hotplug_slot
*hotplug_slot
, u8 status
)
617 struct pci_func
*slot_func
;
618 struct slot
*slot
= hotplug_slot
->private;
619 struct controller
*ctrl
= slot
->ctrl
;
625 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
627 if (cpqhp_get_bus_dev(ctrl
, &bus
, &devfn
, slot
->number
) == -1)
631 function
= devfn
& 0x7;
632 dbg("bus, dev, fn = %d, %d, %d\n", bus
, device
, function
);
634 slot_func
= cpqhp_slot_find(bus
, device
, function
);
638 return cpqhp_set_attention_status(ctrl
, slot_func
, status
);
642 static int process_SI(struct hotplug_slot
*hotplug_slot
)
644 struct pci_func
*slot_func
;
645 struct slot
*slot
= hotplug_slot
->private;
646 struct controller
*ctrl
= slot
->ctrl
;
652 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
654 if (cpqhp_get_bus_dev(ctrl
, &bus
, &devfn
, slot
->number
) == -1)
658 function
= devfn
& 0x7;
659 dbg("bus, dev, fn = %d, %d, %d\n", bus
, device
, function
);
661 slot_func
= cpqhp_slot_find(bus
, device
, function
);
665 slot_func
->bus
= bus
;
666 slot_func
->device
= device
;
667 slot_func
->function
= function
;
668 slot_func
->configured
= 0;
669 dbg("board_added(%p, %p)\n", slot_func
, ctrl
);
670 return cpqhp_process_SI(ctrl
, slot_func
);
674 static int process_SS(struct hotplug_slot
*hotplug_slot
)
676 struct pci_func
*slot_func
;
677 struct slot
*slot
= hotplug_slot
->private;
678 struct controller
*ctrl
= slot
->ctrl
;
684 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
686 if (cpqhp_get_bus_dev(ctrl
, &bus
, &devfn
, slot
->number
) == -1)
690 function
= devfn
& 0x7;
691 dbg("bus, dev, fn = %d, %d, %d\n", bus
, device
, function
);
693 slot_func
= cpqhp_slot_find(bus
, device
, function
);
697 dbg("In %s, slot_func = %p, ctrl = %p\n", __FUNCTION__
, slot_func
, ctrl
);
698 return cpqhp_process_SS(ctrl
, slot_func
);
702 static int hardware_test(struct hotplug_slot
*hotplug_slot
, u32 value
)
704 struct slot
*slot
= hotplug_slot
->private;
705 struct controller
*ctrl
= slot
->ctrl
;
707 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
709 return cpqhp_hardware_test(ctrl
, value
);
713 static int get_power_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
715 struct slot
*slot
= hotplug_slot
->private;
716 struct controller
*ctrl
= slot
->ctrl
;
718 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
720 *value
= get_slot_enabled(ctrl
, slot
);
724 static int get_attention_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
726 struct slot
*slot
= hotplug_slot
->private;
727 struct controller
*ctrl
= slot
->ctrl
;
729 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
731 *value
= cpq_get_attention_status(ctrl
, slot
);
735 static int get_latch_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
737 struct slot
*slot
= hotplug_slot
->private;
738 struct controller
*ctrl
= slot
->ctrl
;
740 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
742 *value
= cpq_get_latch_status(ctrl
, slot
);
747 static int get_adapter_status(struct hotplug_slot
*hotplug_slot
, u8
*value
)
749 struct slot
*slot
= hotplug_slot
->private;
750 struct controller
*ctrl
= slot
->ctrl
;
752 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
754 *value
= get_presence_status(ctrl
, slot
);
759 static int get_max_bus_speed (struct hotplug_slot
*hotplug_slot
, enum pci_bus_speed
*value
)
761 struct slot
*slot
= hotplug_slot
->private;
762 struct controller
*ctrl
= slot
->ctrl
;
764 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
766 *value
= ctrl
->speed_capability
;
771 static int get_cur_bus_speed (struct hotplug_slot
*hotplug_slot
, enum pci_bus_speed
*value
)
773 struct slot
*slot
= hotplug_slot
->private;
774 struct controller
*ctrl
= slot
->ctrl
;
776 dbg("%s - physical_slot = %s\n", __FUNCTION__
, hotplug_slot
->name
);
778 *value
= ctrl
->speed
;
783 static int cpqhpc_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
793 u16 subsystem_deviceid
;
795 struct controller
*ctrl
;
796 struct pci_func
*func
;
798 // Need to read VID early b/c it's used to differentiate CPQ and INTC discovery
799 rc
= pci_read_config_word(pdev
, PCI_VENDOR_ID
, &vendor_id
);
800 if (rc
|| ((vendor_id
!= PCI_VENDOR_ID_COMPAQ
) && (vendor_id
!= PCI_VENDOR_ID_INTEL
))) {
801 err(msg_HPC_non_compaq_or_intel
);
804 dbg("Vendor ID: %x\n", vendor_id
);
806 rc
= pci_read_config_byte(pdev
, PCI_REVISION_ID
, &rev
);
807 dbg("revision: %d\n", rev
);
808 if (rc
|| ((vendor_id
== PCI_VENDOR_ID_COMPAQ
) && (!rev
))) {
809 err(msg_HPC_rev_error
);
813 /* Check for the proper subsytem ID's
814 * Intel uses a different SSID programming model than Compaq.
815 * For Intel, each SSID bit identifies a PHP capability.
816 * Also Intel HPC's may have RID=0.
818 if ((rev
> 2) || (vendor_id
== PCI_VENDOR_ID_INTEL
)) {
819 // TODO: This code can be made to support non-Compaq or Intel subsystem IDs
820 rc
= pci_read_config_word(pdev
, PCI_SUBSYSTEM_VENDOR_ID
, &subsystem_vid
);
822 err("%s : pci_read_config_word failed\n", __FUNCTION__
);
825 dbg("Subsystem Vendor ID: %x\n", subsystem_vid
);
826 if ((subsystem_vid
!= PCI_VENDOR_ID_COMPAQ
) && (subsystem_vid
!= PCI_VENDOR_ID_INTEL
)) {
827 err(msg_HPC_non_compaq_or_intel
);
831 ctrl
= (struct controller
*) kmalloc(sizeof(struct controller
), GFP_KERNEL
);
833 err("%s : out of memory\n", __FUNCTION__
);
836 memset(ctrl
, 0, sizeof(struct controller
));
838 rc
= pci_read_config_word(pdev
, PCI_SUBSYSTEM_ID
, &subsystem_deviceid
);
840 err("%s : pci_read_config_word failed\n", __FUNCTION__
);
844 info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid
);
846 /* Set Vendor ID, so it can be accessed later from other functions */
847 ctrl
->vendor_id
= vendor_id
;
849 switch (subsystem_vid
) {
850 case PCI_VENDOR_ID_COMPAQ
:
851 if (rev
>= 0x13) { /* CIOBX */
853 ctrl
->slot_switch_type
= 1;
854 ctrl
->push_button
= 1;
855 ctrl
->pci_config_space
= 1;
856 ctrl
->defeature_PHP
= 1;
857 ctrl
->pcix_support
= 1;
858 ctrl
->pcix_speed_capability
= 1;
859 pci_read_config_byte(pdev
, 0x41, &bus_cap
);
860 if (bus_cap
& 0x80) {
861 dbg("bus max supports 133MHz PCI-X\n");
862 ctrl
->speed_capability
= PCI_SPEED_133MHz_PCIX
;
865 if (bus_cap
& 0x40) {
866 dbg("bus max supports 100MHz PCI-X\n");
867 ctrl
->speed_capability
= PCI_SPEED_100MHz_PCIX
;
871 dbg("bus max supports 66MHz PCI-X\n");
872 ctrl
->speed_capability
= PCI_SPEED_66MHz_PCIX
;
876 dbg("bus max supports 66MHz PCI\n");
877 ctrl
->speed_capability
= PCI_SPEED_66MHz
;
884 switch (subsystem_deviceid
) {
886 /* Original 6500/7000 implementation */
887 ctrl
->slot_switch_type
= 1;
888 ctrl
->speed_capability
= PCI_SPEED_33MHz
;
889 ctrl
->push_button
= 0;
890 ctrl
->pci_config_space
= 1;
891 ctrl
->defeature_PHP
= 1;
892 ctrl
->pcix_support
= 0;
893 ctrl
->pcix_speed_capability
= 0;
895 case PCI_SUB_HPC_ID2
:
896 /* First Pushbutton implementation */
898 ctrl
->slot_switch_type
= 1;
899 ctrl
->speed_capability
= PCI_SPEED_33MHz
;
900 ctrl
->push_button
= 1;
901 ctrl
->pci_config_space
= 1;
902 ctrl
->defeature_PHP
= 1;
903 ctrl
->pcix_support
= 0;
904 ctrl
->pcix_speed_capability
= 0;
906 case PCI_SUB_HPC_ID_INTC
:
907 /* Third party (6500/7000) */
908 ctrl
->slot_switch_type
= 1;
909 ctrl
->speed_capability
= PCI_SPEED_33MHz
;
910 ctrl
->push_button
= 0;
911 ctrl
->pci_config_space
= 1;
912 ctrl
->defeature_PHP
= 1;
913 ctrl
->pcix_support
= 0;
914 ctrl
->pcix_speed_capability
= 0;
916 case PCI_SUB_HPC_ID3
:
917 /* First 66 Mhz implementation */
919 ctrl
->slot_switch_type
= 1;
920 ctrl
->speed_capability
= PCI_SPEED_66MHz
;
921 ctrl
->push_button
= 1;
922 ctrl
->pci_config_space
= 1;
923 ctrl
->defeature_PHP
= 1;
924 ctrl
->pcix_support
= 0;
925 ctrl
->pcix_speed_capability
= 0;
927 case PCI_SUB_HPC_ID4
:
928 /* First PCI-X implementation, 100MHz */
930 ctrl
->slot_switch_type
= 1;
931 ctrl
->speed_capability
= PCI_SPEED_100MHz_PCIX
;
932 ctrl
->push_button
= 1;
933 ctrl
->pci_config_space
= 1;
934 ctrl
->defeature_PHP
= 1;
935 ctrl
->pcix_support
= 1;
936 ctrl
->pcix_speed_capability
= 0;
939 err(msg_HPC_not_supported
);
945 case PCI_VENDOR_ID_INTEL
:
946 /* Check for speed capability (0=33, 1=66) */
947 if (subsystem_deviceid
& 0x0001) {
948 ctrl
->speed_capability
= PCI_SPEED_66MHz
;
950 ctrl
->speed_capability
= PCI_SPEED_33MHz
;
953 /* Check for push button */
954 if (subsystem_deviceid
& 0x0002) {
956 ctrl
->push_button
= 0;
958 /* push button supported */
959 ctrl
->push_button
= 1;
962 /* Check for slot switch type (0=mechanical, 1=not mechanical) */
963 if (subsystem_deviceid
& 0x0004) {
965 ctrl
->slot_switch_type
= 0;
968 ctrl
->slot_switch_type
= 1;
971 /* PHP Status (0=De-feature PHP, 1=Normal operation) */
972 if (subsystem_deviceid
& 0x0008) {
973 ctrl
->defeature_PHP
= 1; // PHP supported
975 ctrl
->defeature_PHP
= 0; // PHP not supported
978 /* Alternate Base Address Register Interface (0=not supported, 1=supported) */
979 if (subsystem_deviceid
& 0x0010) {
980 ctrl
->alternate_base_address
= 1; // supported
982 ctrl
->alternate_base_address
= 0; // not supported
985 /* PCI Config Space Index (0=not supported, 1=supported) */
986 if (subsystem_deviceid
& 0x0020) {
987 ctrl
->pci_config_space
= 1; // supported
989 ctrl
->pci_config_space
= 0; // not supported
993 if (subsystem_deviceid
& 0x0080) {
995 ctrl
->pcix_support
= 1;
996 /* Frequency of operation in PCI-X mode */
997 if (subsystem_deviceid
& 0x0040) {
998 /* 133MHz PCI-X if bit 7 is 1 */
999 ctrl
->pcix_speed_capability
= 1;
1001 /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
1002 /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
1003 ctrl
->pcix_speed_capability
= 0;
1006 /* Conventional PCI */
1007 ctrl
->pcix_support
= 0;
1008 ctrl
->pcix_speed_capability
= 0;
1013 err(msg_HPC_not_supported
);
1019 err(msg_HPC_not_supported
);
1023 // Tell the user that we found one.
1024 info("Initializing the PCI hot plug controller residing on PCI bus %d\n",
1027 dbg("Hotplug controller capabilities:\n");
1028 dbg(" speed_capability %d\n", ctrl
->speed_capability
);
1029 dbg(" slot_switch_type %s\n", ctrl
->slot_switch_type
?
1030 "switch present" : "no switch");
1031 dbg(" defeature_PHP %s\n", ctrl
->defeature_PHP
?
1032 "PHP supported" : "PHP not supported");
1033 dbg(" alternate_base_address %s\n", ctrl
->alternate_base_address
?
1034 "supported" : "not supported");
1035 dbg(" pci_config_space %s\n", ctrl
->pci_config_space
?
1036 "supported" : "not supported");
1037 dbg(" pcix_speed_capability %s\n", ctrl
->pcix_speed_capability
?
1038 "supported" : "not supported");
1039 dbg(" pcix_support %s\n", ctrl
->pcix_support
?
1040 "supported" : "not supported");
1042 ctrl
->pci_dev
= pdev
;
1043 pci_set_drvdata(pdev
, ctrl
);
1045 /* make our own copy of the pci bus structure,
1046 * as we like tweaking it a lot */
1047 ctrl
->pci_bus
= kmalloc(sizeof(*ctrl
->pci_bus
), GFP_KERNEL
);
1048 if (!ctrl
->pci_bus
) {
1049 err("out of memory\n");
1053 memcpy(ctrl
->pci_bus
, pdev
->bus
, sizeof(*ctrl
->pci_bus
));
1055 ctrl
->bus
= pdev
->bus
->number
;
1057 dbg("bus device function rev: %d %d %d %d\n", ctrl
->bus
,
1058 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
), ctrl
->rev
);
1060 init_MUTEX(&ctrl
->crit_sect
);
1061 init_waitqueue_head(&ctrl
->queue
);
1063 /* initialize our threads if they haven't already been started up */
1064 rc
= one_time_init();
1069 dbg("pdev = %p\n", pdev
);
1070 dbg("pci resource start %lx\n", pci_resource_start(pdev
, 0));
1071 dbg("pci resource len %lx\n", pci_resource_len(pdev
, 0));
1073 if (!request_mem_region(pci_resource_start(pdev
, 0),
1074 pci_resource_len(pdev
, 0), MY_NAME
)) {
1075 err("cannot reserve MMIO region\n");
1080 ctrl
->hpc_reg
= ioremap(pci_resource_start(pdev
, 0),
1081 pci_resource_len(pdev
, 0));
1082 if (!ctrl
->hpc_reg
) {
1083 err("cannot remap MMIO region %lx @ %lx\n",
1084 pci_resource_len(pdev
, 0),
1085 pci_resource_start(pdev
, 0));
1087 goto err_free_mem_region
;
1090 // Check for 66Mhz operation
1091 ctrl
->speed
= get_controller_speed(ctrl
);
1094 /********************************************************
1096 * Save configuration headers for this and
1097 * subordinate PCI buses
1099 ********************************************************/
1101 // find the physical slot number of the first hot plug slot
1103 /* Get slot won't work for devices behind bridges, but
1104 * in this case it will always be called for the "base"
1105 * bus/dev/func of a slot.
1106 * CS: this is leveraging the PCIIRQ routing code from the kernel
1107 * (pci-pc.c: get_irq_routing_table) */
1108 rc
= get_slot_mapping(ctrl
->pci_bus
, pdev
->bus
->number
,
1109 (readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4),
1110 &(ctrl
->first_slot
));
1111 dbg("get_slot_mapping: first_slot = %d, returned = %d\n",
1112 ctrl
->first_slot
, rc
);
1114 err(msg_initialization_err
, rc
);
1118 // Store PCI Config Space for all devices on this bus
1119 rc
= cpqhp_save_config(ctrl
, ctrl
->bus
, readb(ctrl
->hpc_reg
+ SLOT_MASK
));
1121 err("%s: unable to save PCI configuration data, error %d\n",
1127 * Get IO, memory, and IRQ resources for new devices
1129 // The next line is required for cpqhp_find_available_resources
1130 ctrl
->interrupt
= pdev
->irq
;
1131 if (ctrl
->interrupt
< 0x10) {
1132 cpqhp_legacy_mode
= 1;
1133 dbg("System seems to be configured for Full Table Mapped MPS mode\n");
1136 ctrl
->cfgspc_irq
= 0;
1137 pci_read_config_byte(pdev
, PCI_INTERRUPT_LINE
, &ctrl
->cfgspc_irq
);
1139 rc
= cpqhp_find_available_resources(ctrl
, cpqhp_rom_start
);
1140 ctrl
->add_support
= !rc
;
1142 dbg("cpqhp_find_available_resources = 0x%x\n", rc
);
1143 err("unable to locate PCI configuration resources for hot plug add.\n");
1148 * Finish setting up the hot plug ctrl device
1150 ctrl
->slot_device_offset
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4;
1151 dbg("NumSlots %d \n", ctrl
->slot_device_offset
);
1153 ctrl
->next_event
= 0;
1155 /* Setup the slot information structures */
1156 rc
= ctrl_slot_setup(ctrl
, smbios_start
, smbios_table
);
1158 err(msg_initialization_err
, 6);
1159 err("%s: unable to save PCI configuration data, error %d\n",
1164 /* Mask all general input interrupts */
1165 writel(0xFFFFFFFFL
, ctrl
->hpc_reg
+ INT_MASK
);
1167 /* set up the interrupt */
1168 dbg("HPC interrupt = %d \n", ctrl
->interrupt
);
1169 if (request_irq(ctrl
->interrupt
, cpqhp_ctrl_intr
,
1170 SA_SHIRQ
, MY_NAME
, ctrl
)) {
1171 err("Can't get irq %d for the hotplug pci controller\n",
1177 /* Enable Shift Out interrupt and clear it, also enable SERR on power fault */
1178 temp_word
= readw(ctrl
->hpc_reg
+ MISC
);
1179 temp_word
|= 0x4006;
1180 writew(temp_word
, ctrl
->hpc_reg
+ MISC
);
1182 // Changed 05/05/97 to clear all interrupts at start
1183 writel(0xFFFFFFFFL
, ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
1185 ctrl
->ctrl_int_comp
= readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
1187 writel(0x0L
, ctrl
->hpc_reg
+ INT_MASK
);
1189 if (!cpqhp_ctrl_list
) {
1190 cpqhp_ctrl_list
= ctrl
;
1193 ctrl
->next
= cpqhp_ctrl_list
;
1194 cpqhp_ctrl_list
= ctrl
;
1197 // turn off empty slots here unless command line option "ON" set
1198 // Wait for exclusive access to hardware
1199 down(&ctrl
->crit_sect
);
1201 num_of_slots
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) & 0x0F;
1203 // find first device number for the ctrl
1204 device
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4;
1206 while (num_of_slots
) {
1207 dbg("num_of_slots: %d\n", num_of_slots
);
1208 func
= cpqhp_slot_find(ctrl
->bus
, device
, 0);
1212 hp_slot
= func
->device
- ctrl
->slot_device_offset
;
1213 dbg("hp_slot: %d\n", hp_slot
);
1215 // We have to save the presence info for these slots
1216 temp_word
= ctrl
->ctrl_int_comp
>> 16;
1217 func
->presence_save
= (temp_word
>> hp_slot
) & 0x01;
1218 func
->presence_save
|= (temp_word
>> (hp_slot
+ 7)) & 0x02;
1220 if (ctrl
->ctrl_int_comp
& (0x1L
<< hp_slot
)) {
1221 func
->switch_save
= 0;
1223 func
->switch_save
= 0x10;
1227 if (!func
->is_a_board
) {
1228 green_LED_off(ctrl
, hp_slot
);
1229 slot_disable(ctrl
, hp_slot
);
1239 // Wait for SOBS to be unset
1240 wait_for_ctrl_irq(ctrl
);
1243 rc
= init_SERR(ctrl
);
1245 err("init_SERR failed\n");
1246 up(&ctrl
->crit_sect
);
1250 // Done with exclusive hardware access
1251 up(&ctrl
->crit_sect
);
1253 cpqhp_create_ctrl_files(ctrl
);
1258 free_irq(ctrl
->interrupt
, ctrl
);
1260 iounmap(ctrl
->hpc_reg
);
1261 err_free_mem_region
:
1262 release_mem_region(pci_resource_start(pdev
, 0), pci_resource_len(pdev
, 0));
1264 kfree(ctrl
->pci_bus
);
1271 static int one_time_init(void)
1281 retval
= pci_print_IRQ_route();
1285 dbg("Initialize + Start the notification mechanism \n");
1287 retval
= cpqhp_event_start_thread();
1291 dbg("Initialize slot lists\n");
1292 for (loop
= 0; loop
< 256; loop
++) {
1293 cpqhp_slot_list
[loop
] = NULL
;
1296 // FIXME: We also need to hook the NMI handler eventually.
1297 // this also needs to be worked with Christoph
1298 // register_NMI_handler();
1301 cpqhp_rom_start
= ioremap(ROM_PHY_ADDR
, ROM_PHY_LEN
);
1302 if (!cpqhp_rom_start
) {
1303 err ("Could not ioremap memory region for ROM\n");
1308 /* Now, map the int15 entry point if we are on compaq specific hardware */
1309 compaq_nvram_init(cpqhp_rom_start
);
1311 /* Map smbios table entry point structure */
1312 smbios_table
= detect_SMBIOS_pointer(cpqhp_rom_start
,
1313 cpqhp_rom_start
+ ROM_PHY_LEN
);
1314 if (!smbios_table
) {
1315 err ("Could not find the SMBIOS pointer in memory\n");
1317 goto error_rom_start
;
1320 smbios_start
= ioremap(readl(smbios_table
+ ST_ADDRESS
),
1321 readw(smbios_table
+ ST_LENGTH
));
1322 if (!smbios_start
) {
1323 err ("Could not ioremap memory region taken from SMBIOS values\n");
1325 goto error_smbios_start
;
1333 iounmap(smbios_start
);
1335 iounmap(cpqhp_rom_start
);
1341 static void __exit
unload_cpqphpd(void)
1343 struct pci_func
*next
;
1344 struct pci_func
*TempSlot
;
1347 struct controller
*ctrl
;
1348 struct controller
*tctrl
;
1349 struct pci_resource
*res
;
1350 struct pci_resource
*tres
;
1352 rc
= compaq_nvram_store(cpqhp_rom_start
);
1354 ctrl
= cpqhp_ctrl_list
;
1357 if (ctrl
->hpc_reg
) {
1359 rc
= read_slot_enable (ctrl
);
1361 writeb(0, ctrl
->hpc_reg
+ SLOT_SERR
);
1362 writel(0xFFFFFFC0L
| ~rc
, ctrl
->hpc_reg
+ INT_MASK
);
1364 misc
= readw(ctrl
->hpc_reg
+ MISC
);
1366 writew(misc
, ctrl
->hpc_reg
+ MISC
);
1369 ctrl_slot_cleanup(ctrl
);
1371 res
= ctrl
->io_head
;
1378 res
= ctrl
->mem_head
;
1385 res
= ctrl
->p_mem_head
;
1392 res
= ctrl
->bus_head
;
1399 kfree (ctrl
->pci_bus
);
1406 for (loop
= 0; loop
< 256; loop
++) {
1407 next
= cpqhp_slot_list
[loop
];
1408 while (next
!= NULL
) {
1409 res
= next
->io_head
;
1416 res
= next
->mem_head
;
1423 res
= next
->p_mem_head
;
1430 res
= next
->bus_head
;
1443 // Stop the notification mechanism
1445 cpqhp_event_stop_thread();
1447 //unmap the rom address
1448 if (cpqhp_rom_start
)
1449 iounmap(cpqhp_rom_start
);
1451 iounmap(smbios_start
);
1456 static struct pci_device_id hpcd_pci_tbl
[] = {
1458 /* handle any PCI Hotplug controller */
1459 .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG
<< 8) | 0x00),
1462 /* no matter who makes it */
1463 .vendor
= PCI_ANY_ID
,
1464 .device
= PCI_ANY_ID
,
1465 .subvendor
= PCI_ANY_ID
,
1466 .subdevice
= PCI_ANY_ID
,
1468 }, { /* end: all zeroes */ }
1471 MODULE_DEVICE_TABLE(pci
, hpcd_pci_tbl
);
1475 static struct pci_driver cpqhpc_driver
= {
1476 .name
= "compaq_pci_hotplug",
1477 .id_table
= hpcd_pci_tbl
,
1478 .probe
= cpqhpc_probe
,
1479 /* remove: cpqhpc_remove_one, */
1484 static int __init
cpqhpc_init(void)
1488 cpqhp_debug
= debug
;
1490 info (DRIVER_DESC
" version: " DRIVER_VERSION
"\n");
1491 result
= pci_register_driver(&cpqhpc_driver
);
1492 dbg("pci_register_driver = %d\n", result
);
1497 static void __exit
cpqhpc_cleanup(void)
1499 dbg("unload_cpqphpd()\n");
1502 dbg("pci_unregister_driver\n");
1503 pci_unregister_driver(&cpqhpc_driver
);
1507 module_init(cpqhpc_init
);
1508 module_exit(cpqhpc_cleanup
);