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>
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/slab.h>
33 #include <linux/workqueue.h>
34 #include <linux/interrupt.h>
35 #include <linux/delay.h>
36 #include <linux/wait.h>
37 #include <linux/pci.h>
38 #include <linux/pci_hotplug.h>
39 #include <linux/kthread.h>
42 static u32
configure_new_device(struct controller
* ctrl
, struct pci_func
*func
,
43 u8 behind_bridge
, struct resource_lists
*resources
);
44 static int configure_new_function(struct controller
* ctrl
, struct pci_func
*func
,
45 u8 behind_bridge
, struct resource_lists
*resources
);
46 static void interrupt_event_handler(struct controller
*ctrl
);
49 static struct task_struct
*cpqhp_event_thread
;
50 static unsigned long pushbutton_pending
; /* = 0 */
52 /* delay is in jiffies to wait for */
53 static void long_delay(int delay
)
56 * XXX(hch): if someone is bored please convert all callers
57 * to call msleep_interruptible directly. They really want
58 * to specify timeouts in natural units and spend a lot of
59 * effort converting them to jiffies..
61 msleep_interruptible(jiffies_to_msecs(delay
));
65 /* FIXME: The following line needs to be somewhere else... */
66 #define WRONG_BUS_FREQUENCY 0x07
67 static u8
handle_switch_change(u8 change
, struct controller
* ctrl
)
72 struct pci_func
*func
;
73 struct event_info
*taskInfo
;
79 dbg("cpqsbd: Switch interrupt received.\n");
81 for (hp_slot
= 0; hp_slot
< 6; hp_slot
++) {
82 if (change
& (0x1L
<< hp_slot
)) {
86 func
= cpqhp_slot_find(ctrl
->bus
,
87 (hp_slot
+ ctrl
->slot_device_offset
), 0);
89 /* this is the structure that tells the worker thread
92 taskInfo
= &(ctrl
->event_queue
[ctrl
->next_event
]);
93 ctrl
->next_event
= (ctrl
->next_event
+ 1) % 10;
94 taskInfo
->hp_slot
= hp_slot
;
98 temp_word
= ctrl
->ctrl_int_comp
>> 16;
99 func
->presence_save
= (temp_word
>> hp_slot
) & 0x01;
100 func
->presence_save
|= (temp_word
>> (hp_slot
+ 7)) & 0x02;
102 if (ctrl
->ctrl_int_comp
& (0x1L
<< hp_slot
)) {
107 func
->switch_save
= 0;
109 taskInfo
->event_type
= INT_SWITCH_OPEN
;
115 func
->switch_save
= 0x10;
117 taskInfo
->event_type
= INT_SWITCH_CLOSE
;
126 * cpqhp_find_slot - find the struct slot of given device
127 * @ctrl: scan lots of this controller
128 * @device: the device id to find
130 static struct slot
*cpqhp_find_slot(struct controller
*ctrl
, u8 device
)
132 struct slot
*slot
= ctrl
->slot
;
134 while (slot
&& (slot
->device
!= device
))
141 static u8
handle_presence_change(u16 change
, struct controller
* ctrl
)
147 struct pci_func
*func
;
148 struct event_info
*taskInfo
;
157 dbg("cpqsbd: Presence/Notify input change.\n");
158 dbg(" Changed bits are 0x%4.4x\n", change
);
160 for (hp_slot
= 0; hp_slot
< 6; hp_slot
++) {
161 if (change
& (0x0101 << hp_slot
)) {
165 func
= cpqhp_slot_find(ctrl
->bus
,
166 (hp_slot
+ ctrl
->slot_device_offset
), 0);
168 taskInfo
= &(ctrl
->event_queue
[ctrl
->next_event
]);
169 ctrl
->next_event
= (ctrl
->next_event
+ 1) % 10;
170 taskInfo
->hp_slot
= hp_slot
;
174 p_slot
= cpqhp_find_slot(ctrl
, hp_slot
+ (readb(ctrl
->hpc_reg
+ SLOT_MASK
) >> 4));
178 /* If the switch closed, must be a button
179 * If not in button mode, nevermind
181 if (func
->switch_save
&& (ctrl
->push_button
== 1)) {
182 temp_word
= ctrl
->ctrl_int_comp
>> 16;
183 temp_byte
= (temp_word
>> hp_slot
) & 0x01;
184 temp_byte
|= (temp_word
>> (hp_slot
+ 7)) & 0x02;
186 if (temp_byte
!= func
->presence_save
) {
188 * button Pressed (doesn't do anything)
190 dbg("hp_slot %d button pressed\n", hp_slot
);
191 taskInfo
->event_type
= INT_BUTTON_PRESS
;
194 * button Released - TAKE ACTION!!!!
196 dbg("hp_slot %d button released\n", hp_slot
);
197 taskInfo
->event_type
= INT_BUTTON_RELEASE
;
199 /* Cancel if we are still blinking */
200 if ((p_slot
->state
== BLINKINGON_STATE
)
201 || (p_slot
->state
== BLINKINGOFF_STATE
)) {
202 taskInfo
->event_type
= INT_BUTTON_CANCEL
;
203 dbg("hp_slot %d button cancel\n", hp_slot
);
204 } else if ((p_slot
->state
== POWERON_STATE
)
205 || (p_slot
->state
== POWEROFF_STATE
)) {
206 /* info(msg_button_ignore, p_slot->number); */
207 taskInfo
->event_type
= INT_BUTTON_IGNORE
;
208 dbg("hp_slot %d button ignore\n", hp_slot
);
212 /* Switch is open, assume a presence change
213 * Save the presence state
215 temp_word
= ctrl
->ctrl_int_comp
>> 16;
216 func
->presence_save
= (temp_word
>> hp_slot
) & 0x01;
217 func
->presence_save
|= (temp_word
>> (hp_slot
+ 7)) & 0x02;
219 if ((!(ctrl
->ctrl_int_comp
& (0x010000 << hp_slot
))) ||
220 (!(ctrl
->ctrl_int_comp
& (0x01000000 << hp_slot
)))) {
222 taskInfo
->event_type
= INT_PRESENCE_ON
;
225 taskInfo
->event_type
= INT_PRESENCE_OFF
;
235 static u8
handle_power_fault(u8 change
, struct controller
* ctrl
)
239 struct pci_func
*func
;
240 struct event_info
*taskInfo
;
249 info("power fault interrupt\n");
251 for (hp_slot
= 0; hp_slot
< 6; hp_slot
++) {
252 if (change
& (0x01 << hp_slot
)) {
256 func
= cpqhp_slot_find(ctrl
->bus
,
257 (hp_slot
+ ctrl
->slot_device_offset
), 0);
259 taskInfo
= &(ctrl
->event_queue
[ctrl
->next_event
]);
260 ctrl
->next_event
= (ctrl
->next_event
+ 1) % 10;
261 taskInfo
->hp_slot
= hp_slot
;
265 if (ctrl
->ctrl_int_comp
& (0x00000100 << hp_slot
)) {
267 * power fault Cleared
271 taskInfo
->event_type
= INT_POWER_FAULT_CLEAR
;
276 taskInfo
->event_type
= INT_POWER_FAULT
;
279 amber_LED_on (ctrl
, hp_slot
);
280 green_LED_off (ctrl
, hp_slot
);
283 /* this is a fatal condition, we want
284 * to crash the machine to protect from
285 * data corruption. simulated_NMI
286 * shouldn't ever return */
288 simulated_NMI(hp_slot, ctrl); */
290 /* The following code causes a software
291 * crash just in case simulated_NMI did
294 panic(msg_power_fault); */
296 /* set power fault status for this board */
298 info("power fault bit %x set\n", hp_slot
);
309 * sort_by_size - sort nodes on the list by their length, smallest first.
310 * @head: list to sort
312 static int sort_by_size(struct pci_resource
**head
)
314 struct pci_resource
*current_res
;
315 struct pci_resource
*next_res
;
316 int out_of_order
= 1;
321 if (!((*head
)->next
))
324 while (out_of_order
) {
327 /* Special case for swapping list head */
328 if (((*head
)->next
) &&
329 ((*head
)->length
> (*head
)->next
->length
)) {
332 *head
= (*head
)->next
;
333 current_res
->next
= (*head
)->next
;
334 (*head
)->next
= current_res
;
339 while (current_res
->next
&& current_res
->next
->next
) {
340 if (current_res
->next
->length
> current_res
->next
->next
->length
) {
342 next_res
= current_res
->next
;
343 current_res
->next
= current_res
->next
->next
;
344 current_res
= current_res
->next
;
345 next_res
->next
= current_res
->next
;
346 current_res
->next
= next_res
;
348 current_res
= current_res
->next
;
350 } /* End of out_of_order loop */
357 * sort_by_max_size - sort nodes on the list by their length, largest first.
358 * @head: list to sort
360 static int sort_by_max_size(struct pci_resource
**head
)
362 struct pci_resource
*current_res
;
363 struct pci_resource
*next_res
;
364 int out_of_order
= 1;
369 if (!((*head
)->next
))
372 while (out_of_order
) {
375 /* Special case for swapping list head */
376 if (((*head
)->next
) &&
377 ((*head
)->length
< (*head
)->next
->length
)) {
380 *head
= (*head
)->next
;
381 current_res
->next
= (*head
)->next
;
382 (*head
)->next
= current_res
;
387 while (current_res
->next
&& current_res
->next
->next
) {
388 if (current_res
->next
->length
< current_res
->next
->next
->length
) {
390 next_res
= current_res
->next
;
391 current_res
->next
= current_res
->next
->next
;
392 current_res
= current_res
->next
;
393 next_res
->next
= current_res
->next
;
394 current_res
->next
= next_res
;
396 current_res
= current_res
->next
;
398 } /* End of out_of_order loop */
405 * do_pre_bridge_resource_split - find node of resources that are unused
406 * @head: new list head
407 * @orig_head: original list head
408 * @alignment: max node size (?)
410 static struct pci_resource
*do_pre_bridge_resource_split(struct pci_resource
**head
,
411 struct pci_resource
**orig_head
, u32 alignment
)
413 struct pci_resource
*prevnode
= NULL
;
414 struct pci_resource
*node
;
415 struct pci_resource
*split_node
;
418 dbg("do_pre_bridge_resource_split\n");
420 if (!(*head
) || !(*orig_head
))
423 rc
= cpqhp_resource_sort_and_combine(head
);
428 if ((*head
)->base
!= (*orig_head
)->base
)
431 if ((*head
)->length
== (*orig_head
)->length
)
435 /* If we got here, there the bridge requires some of the resource, but
436 * we may be able to split some off of the front
441 if (node
->length
& (alignment
-1)) {
442 /* this one isn't an aligned length, so we'll make a new entry
445 split_node
= kmalloc(sizeof(*split_node
), GFP_KERNEL
);
450 temp_dword
= (node
->length
| (alignment
-1)) + 1 - alignment
;
452 split_node
->base
= node
->base
;
453 split_node
->length
= temp_dword
;
455 node
->length
-= temp_dword
;
456 node
->base
+= split_node
->length
;
458 /* Put it in the list */
460 split_node
->next
= node
;
463 if (node
->length
< alignment
)
471 while (prevnode
->next
!= node
)
472 prevnode
= prevnode
->next
;
474 prevnode
->next
= node
->next
;
483 * do_bridge_resource_split - find one node of resources that aren't in use
485 * @alignment: max node size (?)
487 static struct pci_resource
*do_bridge_resource_split(struct pci_resource
**head
, u32 alignment
)
489 struct pci_resource
*prevnode
= NULL
;
490 struct pci_resource
*node
;
494 rc
= cpqhp_resource_sort_and_combine(head
);
507 if (node
->length
< alignment
)
510 if (node
->base
& (alignment
- 1)) {
511 /* Short circuit if adjusted size is too small */
512 temp_dword
= (node
->base
| (alignment
-1)) + 1;
513 if ((node
->length
- (temp_dword
- node
->base
)) < alignment
)
516 node
->length
-= (temp_dword
- node
->base
);
517 node
->base
= temp_dword
;
520 if (node
->length
& (alignment
- 1))
521 /* There's stuff in use after this node */
532 * get_io_resource - find first node of given size not in ISA aliasing window.
533 * @head: list to search
534 * @size: size of node to find, must be a power of two.
536 * Description: This function sorts the resource list by size and then returns
537 * returns the first node of "size" length that is not in the ISA aliasing
538 * window. If it finds a node larger than "size" it will split it up.
540 static struct pci_resource
*get_io_resource(struct pci_resource
**head
, u32 size
)
542 struct pci_resource
*prevnode
;
543 struct pci_resource
*node
;
544 struct pci_resource
*split_node
;
550 if (cpqhp_resource_sort_and_combine(head
))
553 if (sort_by_size(head
))
556 for (node
= *head
; node
; node
= node
->next
) {
557 if (node
->length
< size
)
560 if (node
->base
& (size
- 1)) {
561 /* this one isn't base aligned properly
562 * so we'll make a new entry and split it up
564 temp_dword
= (node
->base
| (size
-1)) + 1;
566 /* Short circuit if adjusted size is too small */
567 if ((node
->length
- (temp_dword
- node
->base
)) < size
)
570 split_node
= kmalloc(sizeof(*split_node
), GFP_KERNEL
);
575 split_node
->base
= node
->base
;
576 split_node
->length
= temp_dword
- node
->base
;
577 node
->base
= temp_dword
;
578 node
->length
-= split_node
->length
;
580 /* Put it in the list */
581 split_node
->next
= node
->next
;
582 node
->next
= split_node
;
583 } /* End of non-aligned base */
585 /* Don't need to check if too small since we already did */
586 if (node
->length
> size
) {
587 /* this one is longer than we need
588 * so we'll make a new entry and split it up
590 split_node
= kmalloc(sizeof(*split_node
), GFP_KERNEL
);
595 split_node
->base
= node
->base
+ size
;
596 split_node
->length
= node
->length
- size
;
599 /* Put it in the list */
600 split_node
->next
= node
->next
;
601 node
->next
= split_node
;
602 } /* End of too big on top end */
604 /* For IO make sure it's not in the ISA aliasing space */
605 if (node
->base
& 0x300L
)
608 /* If we got here, then it is the right size
609 * Now take it out of the list and break
615 while (prevnode
->next
!= node
)
616 prevnode
= prevnode
->next
;
618 prevnode
->next
= node
->next
;
629 * get_max_resource - get largest node which has at least the given size.
630 * @head: the list to search the node in
631 * @size: the minimum size of the node to find
633 * Description: Gets the largest node that is at least "size" big from the
634 * list pointed to by head. It aligns the node on top and bottom
635 * to "size" alignment before returning it.
637 static struct pci_resource
*get_max_resource(struct pci_resource
**head
, u32 size
)
639 struct pci_resource
*max
;
640 struct pci_resource
*temp
;
641 struct pci_resource
*split_node
;
644 if (cpqhp_resource_sort_and_combine(head
))
647 if (sort_by_max_size(head
))
650 for (max
= *head
; max
; max
= max
->next
) {
651 /* If not big enough we could probably just bail,
652 * instead we'll continue to the next.
654 if (max
->length
< size
)
657 if (max
->base
& (size
- 1)) {
658 /* this one isn't base aligned properly
659 * so we'll make a new entry and split it up
661 temp_dword
= (max
->base
| (size
-1)) + 1;
663 /* Short circuit if adjusted size is too small */
664 if ((max
->length
- (temp_dword
- max
->base
)) < size
)
667 split_node
= kmalloc(sizeof(*split_node
), GFP_KERNEL
);
672 split_node
->base
= max
->base
;
673 split_node
->length
= temp_dword
- max
->base
;
674 max
->base
= temp_dword
;
675 max
->length
-= split_node
->length
;
677 split_node
->next
= max
->next
;
678 max
->next
= split_node
;
681 if ((max
->base
+ max
->length
) & (size
- 1)) {
682 /* this one isn't end aligned properly at the top
683 * so we'll make a new entry and split it up
685 split_node
= kmalloc(sizeof(*split_node
), GFP_KERNEL
);
689 temp_dword
= ((max
->base
+ max
->length
) & ~(size
- 1));
690 split_node
->base
= temp_dword
;
691 split_node
->length
= max
->length
+ max
->base
693 max
->length
-= split_node
->length
;
695 split_node
->next
= max
->next
;
696 max
->next
= split_node
;
699 /* Make sure it didn't shrink too much when we aligned it */
700 if (max
->length
< size
)
703 /* Now take it out of the list */
708 while (temp
&& temp
->next
!= max
) {
712 temp
->next
= max
->next
;
724 * get_resource - find resource of given size and split up larger ones.
725 * @head: the list to search for resources
726 * @size: the size limit to use
728 * Description: This function sorts the resource list by size and then
729 * returns the first node of "size" length. If it finds a node
730 * larger than "size" it will split it up.
732 * size must be a power of two.
734 static struct pci_resource
*get_resource(struct pci_resource
**head
, u32 size
)
736 struct pci_resource
*prevnode
;
737 struct pci_resource
*node
;
738 struct pci_resource
*split_node
;
741 if (cpqhp_resource_sort_and_combine(head
))
744 if (sort_by_size(head
))
747 for (node
= *head
; node
; node
= node
->next
) {
748 dbg("%s: req_size =%x node=%p, base=%x, length=%x\n",
749 __func__
, size
, node
, node
->base
, node
->length
);
750 if (node
->length
< size
)
753 if (node
->base
& (size
- 1)) {
754 dbg("%s: not aligned\n", __func__
);
755 /* this one isn't base aligned properly
756 * so we'll make a new entry and split it up
758 temp_dword
= (node
->base
| (size
-1)) + 1;
760 /* Short circuit if adjusted size is too small */
761 if ((node
->length
- (temp_dword
- node
->base
)) < size
)
764 split_node
= kmalloc(sizeof(*split_node
), GFP_KERNEL
);
769 split_node
->base
= node
->base
;
770 split_node
->length
= temp_dword
- node
->base
;
771 node
->base
= temp_dword
;
772 node
->length
-= split_node
->length
;
774 split_node
->next
= node
->next
;
775 node
->next
= split_node
;
776 } /* End of non-aligned base */
778 /* Don't need to check if too small since we already did */
779 if (node
->length
> size
) {
780 dbg("%s: too big\n", __func__
);
781 /* this one is longer than we need
782 * so we'll make a new entry and split it up
784 split_node
= kmalloc(sizeof(*split_node
), GFP_KERNEL
);
789 split_node
->base
= node
->base
+ size
;
790 split_node
->length
= node
->length
- size
;
793 /* Put it in the list */
794 split_node
->next
= node
->next
;
795 node
->next
= split_node
;
796 } /* End of too big on top end */
798 dbg("%s: got one!!!\n", __func__
);
799 /* If we got here, then it is the right size
800 * Now take it out of the list */
805 while (prevnode
->next
!= node
)
806 prevnode
= prevnode
->next
;
808 prevnode
->next
= node
->next
;
818 * cpqhp_resource_sort_and_combine - sort nodes by base addresses and clean up
819 * @head: the list to sort and clean up
821 * Description: Sorts all of the nodes in the list in ascending order by
822 * their base addresses. Also does garbage collection by
823 * combining adjacent nodes.
825 * Returns %0 if success.
827 int cpqhp_resource_sort_and_combine(struct pci_resource
**head
)
829 struct pci_resource
*node1
;
830 struct pci_resource
*node2
;
831 int out_of_order
= 1;
833 dbg("%s: head = %p, *head = %p\n", __func__
, head
, *head
);
838 dbg("*head->next = %p\n",(*head
)->next
);
841 return 0; /* only one item on the list, already sorted! */
843 dbg("*head->base = 0x%x\n",(*head
)->base
);
844 dbg("*head->next->base = 0x%x\n",(*head
)->next
->base
);
845 while (out_of_order
) {
848 /* Special case for swapping list head */
849 if (((*head
)->next
) &&
850 ((*head
)->base
> (*head
)->next
->base
)) {
852 (*head
) = (*head
)->next
;
853 node1
->next
= (*head
)->next
;
854 (*head
)->next
= node1
;
860 while (node1
->next
&& node1
->next
->next
) {
861 if (node1
->next
->base
> node1
->next
->next
->base
) {
864 node1
->next
= node1
->next
->next
;
866 node2
->next
= node1
->next
;
871 } /* End of out_of_order loop */
875 while (node1
&& node1
->next
) {
876 if ((node1
->base
+ node1
->length
) == node1
->next
->base
) {
879 node1
->length
+= node1
->next
->length
;
881 node1
->next
= node1
->next
->next
;
891 irqreturn_t
cpqhp_ctrl_intr(int IRQ
, void *data
)
893 struct controller
*ctrl
= data
;
894 u8 schedule_flag
= 0;
901 misc
= readw(ctrl
->hpc_reg
+ MISC
);
903 * Check to see if it was our interrupt
905 if (!(misc
& 0x000C)) {
911 * Serial Output interrupt Pending
914 /* Clear the interrupt */
916 writew(misc
, ctrl
->hpc_reg
+ MISC
);
918 /* Read to clear posted writes */
919 misc
= readw(ctrl
->hpc_reg
+ MISC
);
921 dbg ("%s - waking up\n", __func__
);
922 wake_up_interruptible(&ctrl
->queue
);
926 /* General-interrupt-input interrupt Pending */
927 Diff
= readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
) ^ ctrl
->ctrl_int_comp
;
929 ctrl
->ctrl_int_comp
= readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
931 /* Clear the interrupt */
932 writel(Diff
, ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
934 /* Read it back to clear any posted writes */
935 temp_dword
= readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
938 /* Clear all interrupts */
939 writel(0xFFFFFFFF, ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
941 schedule_flag
+= handle_switch_change((u8
)(Diff
& 0xFFL
), ctrl
);
942 schedule_flag
+= handle_presence_change((u16
)((Diff
& 0xFFFF0000L
) >> 16), ctrl
);
943 schedule_flag
+= handle_power_fault((u8
)((Diff
& 0xFF00L
) >> 8), ctrl
);
946 reset
= readb(ctrl
->hpc_reg
+ RESET_FREQ_MODE
);
948 /* Bus reset has completed */
950 writeb(reset
, ctrl
->hpc_reg
+ RESET_FREQ_MODE
);
951 reset
= readb(ctrl
->hpc_reg
+ RESET_FREQ_MODE
);
952 wake_up_interruptible(&ctrl
->queue
);
956 wake_up_process(cpqhp_event_thread
);
957 dbg("Waking even thread");
964 * cpqhp_slot_create - Creates a node and adds it to the proper bus.
965 * @busnumber: bus where new node is to be located
967 * Returns pointer to the new node or %NULL if unsuccessful.
969 struct pci_func
*cpqhp_slot_create(u8 busnumber
)
971 struct pci_func
*new_slot
;
972 struct pci_func
*next
;
974 new_slot
= kzalloc(sizeof(*new_slot
), GFP_KERNEL
);
975 if (new_slot
== NULL
)
978 new_slot
->next
= NULL
;
979 new_slot
->configured
= 1;
981 if (cpqhp_slot_list
[busnumber
] == NULL
) {
982 cpqhp_slot_list
[busnumber
] = new_slot
;
984 next
= cpqhp_slot_list
[busnumber
];
985 while (next
->next
!= NULL
)
987 next
->next
= new_slot
;
994 * slot_remove - Removes a node from the linked list of slots.
995 * @old_slot: slot to remove
997 * Returns %0 if successful, !0 otherwise.
999 static int slot_remove(struct pci_func
* old_slot
)
1001 struct pci_func
*next
;
1003 if (old_slot
== NULL
)
1006 next
= cpqhp_slot_list
[old_slot
->bus
];
1010 if (next
== old_slot
) {
1011 cpqhp_slot_list
[old_slot
->bus
] = old_slot
->next
;
1012 cpqhp_destroy_board_resources(old_slot
);
1017 while ((next
->next
!= old_slot
) && (next
->next
!= NULL
))
1020 if (next
->next
== old_slot
) {
1021 next
->next
= old_slot
->next
;
1022 cpqhp_destroy_board_resources(old_slot
);
1031 * bridge_slot_remove - Removes a node from the linked list of slots.
1032 * @bridge: bridge to remove
1034 * Returns %0 if successful, !0 otherwise.
1036 static int bridge_slot_remove(struct pci_func
*bridge
)
1038 u8 subordinateBus
, secondaryBus
;
1040 struct pci_func
*next
;
1042 secondaryBus
= (bridge
->config_space
[0x06] >> 8) & 0xFF;
1043 subordinateBus
= (bridge
->config_space
[0x06] >> 16) & 0xFF;
1045 for (tempBus
= secondaryBus
; tempBus
<= subordinateBus
; tempBus
++) {
1046 next
= cpqhp_slot_list
[tempBus
];
1048 while (!slot_remove(next
))
1049 next
= cpqhp_slot_list
[tempBus
];
1052 next
= cpqhp_slot_list
[bridge
->bus
];
1057 if (next
== bridge
) {
1058 cpqhp_slot_list
[bridge
->bus
] = bridge
->next
;
1062 while ((next
->next
!= bridge
) && (next
->next
!= NULL
))
1065 if (next
->next
!= bridge
)
1067 next
->next
= bridge
->next
;
1075 * cpqhp_slot_find - Looks for a node by bus, and device, multiple functions accessed
1077 * @device: device to find
1078 * @index: is %0 for first function found, %1 for the second...
1080 * Returns pointer to the node if successful, %NULL otherwise.
1082 struct pci_func
*cpqhp_slot_find(u8 bus
, u8 device
, u8 index
)
1085 struct pci_func
*func
;
1087 func
= cpqhp_slot_list
[bus
];
1089 if ((func
== NULL
) || ((func
->device
== device
) && (index
== 0)))
1092 if (func
->device
== device
)
1095 while (func
->next
!= NULL
) {
1098 if (func
->device
== device
)
1109 /* DJZ: I don't think is_bridge will work as is.
1111 static int is_bridge(struct pci_func
* func
)
1113 /* Check the header type */
1114 if (((func
->config_space
[0x03] >> 16) & 0xFF) == 0x01)
1122 * set_controller_speed - set the frequency and/or mode of a specific controller segment.
1123 * @ctrl: controller to change frequency/mode for.
1124 * @adapter_speed: the speed of the adapter we want to match.
1125 * @hp_slot: the slot number where the adapter is installed.
1127 * Returns %0 if we successfully change frequency and/or mode to match the
1130 static u8
set_controller_speed(struct controller
*ctrl
, u8 adapter_speed
, u8 hp_slot
)
1134 u8 slot_power
= readb(ctrl
->hpc_reg
+ SLOT_POWER
);
1136 u32 leds
= readl(ctrl
->hpc_reg
+ LED_CONTROL
);
1138 if (ctrl
->speed
== adapter_speed
)
1141 /* We don't allow freq/mode changes if we find another adapter running
1142 * in another slot on this controller
1144 for(slot
= ctrl
->slot
; slot
; slot
= slot
->next
) {
1145 if (slot
->device
== (hp_slot
+ ctrl
->slot_device_offset
))
1147 if (!slot
->hotplug_slot
|| !slot
->hotplug_slot
->info
)
1149 if (slot
->hotplug_slot
->info
->adapter_status
== 0)
1151 /* If another adapter is running on the same segment but at a
1152 * lower speed/mode, we allow the new adapter to function at
1153 * this rate if supported
1155 if (ctrl
->speed
< adapter_speed
)
1161 /* If the controller doesn't support freq/mode changes and the
1162 * controller is running at a higher mode, we bail
1164 if ((ctrl
->speed
> adapter_speed
) && (!ctrl
->pcix_speed_capability
))
1167 /* But we allow the adapter to run at a lower rate if possible */
1168 if ((ctrl
->speed
< adapter_speed
) && (!ctrl
->pcix_speed_capability
))
1171 /* We try to set the max speed supported by both the adapter and
1174 if (ctrl
->speed_capability
< adapter_speed
) {
1175 if (ctrl
->speed
== ctrl
->speed_capability
)
1177 adapter_speed
= ctrl
->speed_capability
;
1180 writel(0x0L
, ctrl
->hpc_reg
+ LED_CONTROL
);
1181 writeb(0x00, ctrl
->hpc_reg
+ SLOT_ENABLE
);
1184 wait_for_ctrl_irq(ctrl
);
1186 if (adapter_speed
!= PCI_SPEED_133MHz_PCIX
)
1190 pci_write_config_byte(ctrl
->pci_dev
, 0x41, reg
);
1192 reg16
= readw(ctrl
->hpc_reg
+ NEXT_CURR_FREQ
);
1194 switch(adapter_speed
) {
1195 case(PCI_SPEED_133MHz_PCIX
):
1199 case(PCI_SPEED_100MHz_PCIX
):
1203 case(PCI_SPEED_66MHz_PCIX
):
1207 case(PCI_SPEED_66MHz
):
1211 default: /* 33MHz PCI 2.2 */
1217 writew(reg16
, ctrl
->hpc_reg
+ NEXT_CURR_FREQ
);
1221 /* Reenable interrupts */
1222 writel(0, ctrl
->hpc_reg
+ INT_MASK
);
1224 pci_write_config_byte(ctrl
->pci_dev
, 0x41, reg
);
1226 /* Restart state machine */
1228 pci_read_config_byte(ctrl
->pci_dev
, 0x43, ®
);
1229 pci_write_config_byte(ctrl
->pci_dev
, 0x43, reg
);
1231 /* Only if mode change...*/
1232 if (((ctrl
->speed
== PCI_SPEED_66MHz
) && (adapter_speed
== PCI_SPEED_66MHz_PCIX
)) ||
1233 ((ctrl
->speed
== PCI_SPEED_66MHz_PCIX
) && (adapter_speed
== PCI_SPEED_66MHz
)))
1236 wait_for_ctrl_irq(ctrl
);
1239 /* Restore LED/Slot state */
1240 writel(leds
, ctrl
->hpc_reg
+ LED_CONTROL
);
1241 writeb(slot_power
, ctrl
->hpc_reg
+ SLOT_ENABLE
);
1244 wait_for_ctrl_irq(ctrl
);
1246 ctrl
->speed
= adapter_speed
;
1247 slot
= cpqhp_find_slot(ctrl
, hp_slot
+ ctrl
->slot_device_offset
);
1249 info("Successfully changed frequency/mode for adapter in slot %d\n",
1254 /* the following routines constitute the bulk of the
1255 * hotplug controller logic
1260 * board_replaced - Called after a board has been replaced in the system.
1261 * @func: PCI device/function information
1262 * @ctrl: hotplug controller
1264 * This is only used if we don't have resources for hot add.
1265 * Turns power on for the board.
1266 * Checks to see if board is the same.
1267 * If board is same, reconfigures it.
1268 * If board isn't same, turns it back off.
1270 static u32
board_replaced(struct pci_func
*func
, struct controller
*ctrl
)
1277 hp_slot
= func
->device
- ctrl
->slot_device_offset
;
1280 * The switch is open.
1282 if (readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
) & (0x01L
<< hp_slot
))
1283 rc
= INTERLOCK_OPEN
;
1285 * The board is already on
1287 else if (is_slot_enabled (ctrl
, hp_slot
))
1288 rc
= CARD_FUNCTIONING
;
1290 mutex_lock(&ctrl
->crit_sect
);
1292 /* turn on board without attaching to the bus */
1293 enable_slot_power (ctrl
, hp_slot
);
1297 /* Wait for SOBS to be unset */
1298 wait_for_ctrl_irq (ctrl
);
1300 /* Change bits in slot power register to force another shift out
1301 * NOTE: this is to work around the timer bug */
1302 temp_byte
= readb(ctrl
->hpc_reg
+ SLOT_POWER
);
1303 writeb(0x00, ctrl
->hpc_reg
+ SLOT_POWER
);
1304 writeb(temp_byte
, ctrl
->hpc_reg
+ SLOT_POWER
);
1308 /* Wait for SOBS to be unset */
1309 wait_for_ctrl_irq (ctrl
);
1311 adapter_speed
= get_adapter_speed(ctrl
, hp_slot
);
1312 if (ctrl
->speed
!= adapter_speed
)
1313 if (set_controller_speed(ctrl
, adapter_speed
, hp_slot
))
1314 rc
= WRONG_BUS_FREQUENCY
;
1316 /* turn off board without attaching to the bus */
1317 disable_slot_power (ctrl
, hp_slot
);
1321 /* Wait for SOBS to be unset */
1322 wait_for_ctrl_irq (ctrl
);
1324 mutex_unlock(&ctrl
->crit_sect
);
1329 mutex_lock(&ctrl
->crit_sect
);
1331 slot_enable (ctrl
, hp_slot
);
1332 green_LED_blink (ctrl
, hp_slot
);
1334 amber_LED_off (ctrl
, hp_slot
);
1338 /* Wait for SOBS to be unset */
1339 wait_for_ctrl_irq (ctrl
);
1341 mutex_unlock(&ctrl
->crit_sect
);
1343 /* Wait for ~1 second because of hot plug spec */
1346 /* Check for a power fault */
1347 if (func
->status
== 0xFF) {
1348 /* power fault occurred, but it was benign */
1352 rc
= cpqhp_valid_replace(ctrl
, func
);
1355 /* It must be the same board */
1357 rc
= cpqhp_configure_board(ctrl
, func
);
1359 /* If configuration fails, turn it off
1360 * Get slot won't work for devices behind
1361 * bridges, but in this case it will always be
1362 * called for the "base" bus/dev/func of an
1366 mutex_lock(&ctrl
->crit_sect
);
1368 amber_LED_on (ctrl
, hp_slot
);
1369 green_LED_off (ctrl
, hp_slot
);
1370 slot_disable (ctrl
, hp_slot
);
1374 /* Wait for SOBS to be unset */
1375 wait_for_ctrl_irq (ctrl
);
1377 mutex_unlock(&ctrl
->crit_sect
);
1385 /* Something is wrong
1387 * Get slot won't work for devices behind bridges, but
1388 * in this case it will always be called for the "base"
1389 * bus/dev/func of an adapter.
1392 mutex_lock(&ctrl
->crit_sect
);
1394 amber_LED_on (ctrl
, hp_slot
);
1395 green_LED_off (ctrl
, hp_slot
);
1396 slot_disable (ctrl
, hp_slot
);
1400 /* Wait for SOBS to be unset */
1401 wait_for_ctrl_irq (ctrl
);
1403 mutex_unlock(&ctrl
->crit_sect
);
1413 * board_added - Called after a board has been added to the system.
1414 * @func: PCI device/function info
1415 * @ctrl: hotplug controller
1417 * Turns power on for the board.
1420 static u32
board_added(struct pci_func
*func
, struct controller
*ctrl
)
1426 u32 temp_register
= 0xFFFFFFFF;
1428 struct pci_func
*new_slot
= NULL
;
1429 struct slot
*p_slot
;
1430 struct resource_lists res_lists
;
1432 hp_slot
= func
->device
- ctrl
->slot_device_offset
;
1433 dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n",
1434 __func__
, func
->device
, ctrl
->slot_device_offset
, hp_slot
);
1436 mutex_lock(&ctrl
->crit_sect
);
1438 /* turn on board without attaching to the bus */
1439 enable_slot_power(ctrl
, hp_slot
);
1443 /* Wait for SOBS to be unset */
1444 wait_for_ctrl_irq (ctrl
);
1446 /* Change bits in slot power register to force another shift out
1447 * NOTE: this is to work around the timer bug
1449 temp_byte
= readb(ctrl
->hpc_reg
+ SLOT_POWER
);
1450 writeb(0x00, ctrl
->hpc_reg
+ SLOT_POWER
);
1451 writeb(temp_byte
, ctrl
->hpc_reg
+ SLOT_POWER
);
1455 /* Wait for SOBS to be unset */
1456 wait_for_ctrl_irq (ctrl
);
1458 adapter_speed
= get_adapter_speed(ctrl
, hp_slot
);
1459 if (ctrl
->speed
!= adapter_speed
)
1460 if (set_controller_speed(ctrl
, adapter_speed
, hp_slot
))
1461 rc
= WRONG_BUS_FREQUENCY
;
1463 /* turn off board without attaching to the bus */
1464 disable_slot_power (ctrl
, hp_slot
);
1468 /* Wait for SOBS to be unset */
1469 wait_for_ctrl_irq(ctrl
);
1471 mutex_unlock(&ctrl
->crit_sect
);
1476 p_slot
= cpqhp_find_slot(ctrl
, hp_slot
+ ctrl
->slot_device_offset
);
1478 /* turn on board and blink green LED */
1480 dbg("%s: before down\n", __func__
);
1481 mutex_lock(&ctrl
->crit_sect
);
1482 dbg("%s: after down\n", __func__
);
1484 dbg("%s: before slot_enable\n", __func__
);
1485 slot_enable (ctrl
, hp_slot
);
1487 dbg("%s: before green_LED_blink\n", __func__
);
1488 green_LED_blink (ctrl
, hp_slot
);
1490 dbg("%s: before amber_LED_blink\n", __func__
);
1491 amber_LED_off (ctrl
, hp_slot
);
1493 dbg("%s: before set_SOGO\n", __func__
);
1496 /* Wait for SOBS to be unset */
1497 dbg("%s: before wait_for_ctrl_irq\n", __func__
);
1498 wait_for_ctrl_irq (ctrl
);
1499 dbg("%s: after wait_for_ctrl_irq\n", __func__
);
1501 dbg("%s: before up\n", __func__
);
1502 mutex_unlock(&ctrl
->crit_sect
);
1503 dbg("%s: after up\n", __func__
);
1505 /* Wait for ~1 second because of hot plug spec */
1506 dbg("%s: before long_delay\n", __func__
);
1508 dbg("%s: after long_delay\n", __func__
);
1510 dbg("%s: func status = %x\n", __func__
, func
->status
);
1511 /* Check for a power fault */
1512 if (func
->status
== 0xFF) {
1513 /* power fault occurred, but it was benign */
1514 temp_register
= 0xFFFFFFFF;
1515 dbg("%s: temp register set to %x by power fault\n", __func__
, temp_register
);
1519 /* Get vendor/device ID u32 */
1520 ctrl
->pci_bus
->number
= func
->bus
;
1521 rc
= pci_bus_read_config_dword (ctrl
->pci_bus
, PCI_DEVFN(func
->device
, func
->function
), PCI_VENDOR_ID
, &temp_register
);
1522 dbg("%s: pci_read_config_dword returns %d\n", __func__
, rc
);
1523 dbg("%s: temp_register is %x\n", __func__
, temp_register
);
1526 /* Something's wrong here */
1527 temp_register
= 0xFFFFFFFF;
1528 dbg("%s: temp register set to %x by error\n", __func__
, temp_register
);
1530 /* Preset return code. It will be changed later if things go okay. */
1531 rc
= NO_ADAPTER_PRESENT
;
1534 /* All F's is an empty slot or an invalid board */
1535 if (temp_register
!= 0xFFFFFFFF) {
1536 res_lists
.io_head
= ctrl
->io_head
;
1537 res_lists
.mem_head
= ctrl
->mem_head
;
1538 res_lists
.p_mem_head
= ctrl
->p_mem_head
;
1539 res_lists
.bus_head
= ctrl
->bus_head
;
1540 res_lists
.irqs
= NULL
;
1542 rc
= configure_new_device(ctrl
, func
, 0, &res_lists
);
1544 dbg("%s: back from configure_new_device\n", __func__
);
1545 ctrl
->io_head
= res_lists
.io_head
;
1546 ctrl
->mem_head
= res_lists
.mem_head
;
1547 ctrl
->p_mem_head
= res_lists
.p_mem_head
;
1548 ctrl
->bus_head
= res_lists
.bus_head
;
1550 cpqhp_resource_sort_and_combine(&(ctrl
->mem_head
));
1551 cpqhp_resource_sort_and_combine(&(ctrl
->p_mem_head
));
1552 cpqhp_resource_sort_and_combine(&(ctrl
->io_head
));
1553 cpqhp_resource_sort_and_combine(&(ctrl
->bus_head
));
1556 mutex_lock(&ctrl
->crit_sect
);
1558 amber_LED_on (ctrl
, hp_slot
);
1559 green_LED_off (ctrl
, hp_slot
);
1560 slot_disable (ctrl
, hp_slot
);
1564 /* Wait for SOBS to be unset */
1565 wait_for_ctrl_irq (ctrl
);
1567 mutex_unlock(&ctrl
->crit_sect
);
1570 cpqhp_save_slot_config(ctrl
, func
);
1575 func
->switch_save
= 0x10;
1576 func
->is_a_board
= 0x01;
1578 /* next, we will instantiate the linux pci_dev structures (with
1579 * appropriate driver notification, if already present) */
1580 dbg("%s: configure linux pci_dev structure\n", __func__
);
1583 new_slot
= cpqhp_slot_find(ctrl
->bus
, func
->device
, index
++);
1584 if (new_slot
&& !new_slot
->pci_dev
)
1585 cpqhp_configure_device(ctrl
, new_slot
);
1588 mutex_lock(&ctrl
->crit_sect
);
1590 green_LED_on (ctrl
, hp_slot
);
1594 /* Wait for SOBS to be unset */
1595 wait_for_ctrl_irq (ctrl
);
1597 mutex_unlock(&ctrl
->crit_sect
);
1599 mutex_lock(&ctrl
->crit_sect
);
1601 amber_LED_on (ctrl
, hp_slot
);
1602 green_LED_off (ctrl
, hp_slot
);
1603 slot_disable (ctrl
, hp_slot
);
1607 /* Wait for SOBS to be unset */
1608 wait_for_ctrl_irq (ctrl
);
1610 mutex_unlock(&ctrl
->crit_sect
);
1619 * remove_board - Turns off slot and LEDs
1620 * @func: PCI device/function info
1621 * @replace_flag: whether replacing or adding a new device
1622 * @ctrl: target controller
1624 static u32
remove_board(struct pci_func
* func
, u32 replace_flag
, struct controller
* ctrl
)
1632 struct resource_lists res_lists
;
1633 struct pci_func
*temp_func
;
1635 if (cpqhp_unconfigure_device(func
))
1638 device
= func
->device
;
1640 hp_slot
= func
->device
- ctrl
->slot_device_offset
;
1641 dbg("In %s, hp_slot = %d\n", __func__
, hp_slot
);
1643 /* When we get here, it is safe to change base address registers.
1644 * We will attempt to save the base address register lengths */
1645 if (replace_flag
|| !ctrl
->add_support
)
1646 rc
= cpqhp_save_base_addr_length(ctrl
, func
);
1647 else if (!func
->bus_head
&& !func
->mem_head
&&
1648 !func
->p_mem_head
&& !func
->io_head
) {
1649 /* Here we check to see if we've saved any of the board's
1650 * resources already. If so, we'll skip the attempt to
1651 * determine what's being used. */
1653 temp_func
= cpqhp_slot_find(func
->bus
, func
->device
, index
++);
1655 if (temp_func
->bus_head
|| temp_func
->mem_head
1656 || temp_func
->p_mem_head
|| temp_func
->io_head
) {
1660 temp_func
= cpqhp_slot_find(temp_func
->bus
, temp_func
->device
, index
++);
1664 rc
= cpqhp_save_used_resources(ctrl
, func
);
1666 /* Change status to shutdown */
1667 if (func
->is_a_board
)
1668 func
->status
= 0x01;
1669 func
->configured
= 0;
1671 mutex_lock(&ctrl
->crit_sect
);
1673 green_LED_off (ctrl
, hp_slot
);
1674 slot_disable (ctrl
, hp_slot
);
1678 /* turn off SERR for slot */
1679 temp_byte
= readb(ctrl
->hpc_reg
+ SLOT_SERR
);
1680 temp_byte
&= ~(0x01 << hp_slot
);
1681 writeb(temp_byte
, ctrl
->hpc_reg
+ SLOT_SERR
);
1683 /* Wait for SOBS to be unset */
1684 wait_for_ctrl_irq (ctrl
);
1686 mutex_unlock(&ctrl
->crit_sect
);
1688 if (!replace_flag
&& ctrl
->add_support
) {
1690 res_lists
.io_head
= ctrl
->io_head
;
1691 res_lists
.mem_head
= ctrl
->mem_head
;
1692 res_lists
.p_mem_head
= ctrl
->p_mem_head
;
1693 res_lists
.bus_head
= ctrl
->bus_head
;
1695 cpqhp_return_board_resources(func
, &res_lists
);
1697 ctrl
->io_head
= res_lists
.io_head
;
1698 ctrl
->mem_head
= res_lists
.mem_head
;
1699 ctrl
->p_mem_head
= res_lists
.p_mem_head
;
1700 ctrl
->bus_head
= res_lists
.bus_head
;
1702 cpqhp_resource_sort_and_combine(&(ctrl
->mem_head
));
1703 cpqhp_resource_sort_and_combine(&(ctrl
->p_mem_head
));
1704 cpqhp_resource_sort_and_combine(&(ctrl
->io_head
));
1705 cpqhp_resource_sort_and_combine(&(ctrl
->bus_head
));
1707 if (is_bridge(func
)) {
1708 bridge_slot_remove(func
);
1712 func
= cpqhp_slot_find(ctrl
->bus
, device
, 0);
1715 /* Setup slot structure with entry for empty slot */
1716 func
= cpqhp_slot_create(ctrl
->bus
);
1721 func
->bus
= ctrl
->bus
;
1722 func
->device
= device
;
1724 func
->configured
= 0;
1725 func
->switch_save
= 0x10;
1726 func
->is_a_board
= 0;
1727 func
->p_task_event
= NULL
;
1733 static void pushbutton_helper_thread(unsigned long data
)
1735 pushbutton_pending
= data
;
1736 wake_up_process(cpqhp_event_thread
);
1740 /* this is the main worker thread */
1741 static int event_thread(void* data
)
1743 struct controller
*ctrl
;
1746 dbg("!!!!event_thread sleeping\n");
1747 set_current_state(TASK_INTERRUPTIBLE
);
1750 if (kthread_should_stop())
1753 if (pushbutton_pending
)
1754 cpqhp_pushbutton_thread(pushbutton_pending
);
1756 for (ctrl
= cpqhp_ctrl_list
; ctrl
; ctrl
=ctrl
->next
)
1757 interrupt_event_handler(ctrl
);
1759 dbg("event_thread signals exit\n");
1763 int cpqhp_event_start_thread(void)
1765 cpqhp_event_thread
= kthread_run(event_thread
, NULL
, "phpd_event");
1766 if (IS_ERR(cpqhp_event_thread
)) {
1767 err ("Can't start up our event thread\n");
1768 return PTR_ERR(cpqhp_event_thread
);
1775 void cpqhp_event_stop_thread(void)
1777 kthread_stop(cpqhp_event_thread
);
1781 static int update_slot_info(struct controller
*ctrl
, struct slot
*slot
)
1783 struct hotplug_slot_info
*info
;
1786 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
1790 info
->power_status
= get_slot_enabled(ctrl
, slot
);
1791 info
->attention_status
= cpq_get_attention_status(ctrl
, slot
);
1792 info
->latch_status
= cpq_get_latch_status(ctrl
, slot
);
1793 info
->adapter_status
= get_presence_status(ctrl
, slot
);
1794 result
= pci_hp_change_slot_info(slot
->hotplug_slot
, info
);
1799 static void interrupt_event_handler(struct controller
*ctrl
)
1803 struct pci_func
*func
;
1805 struct slot
*p_slot
;
1810 for (loop
= 0; loop
< 10; loop
++) {
1811 /* dbg("loop %d\n", loop); */
1812 if (ctrl
->event_queue
[loop
].event_type
!= 0) {
1813 hp_slot
= ctrl
->event_queue
[loop
].hp_slot
;
1815 func
= cpqhp_slot_find(ctrl
->bus
, (hp_slot
+ ctrl
->slot_device_offset
), 0);
1819 p_slot
= cpqhp_find_slot(ctrl
, hp_slot
+ ctrl
->slot_device_offset
);
1823 dbg("hp_slot %d, func %p, p_slot %p\n",
1824 hp_slot
, func
, p_slot
);
1826 if (ctrl
->event_queue
[loop
].event_type
== INT_BUTTON_PRESS
) {
1827 dbg("button pressed\n");
1828 } else if (ctrl
->event_queue
[loop
].event_type
==
1829 INT_BUTTON_CANCEL
) {
1830 dbg("button cancel\n");
1831 del_timer(&p_slot
->task_event
);
1833 mutex_lock(&ctrl
->crit_sect
);
1835 if (p_slot
->state
== BLINKINGOFF_STATE
) {
1837 dbg("turn on green LED\n");
1838 green_LED_on (ctrl
, hp_slot
);
1839 } else if (p_slot
->state
== BLINKINGON_STATE
) {
1841 dbg("turn off green LED\n");
1842 green_LED_off (ctrl
, hp_slot
);
1845 info(msg_button_cancel
, p_slot
->number
);
1847 p_slot
->state
= STATIC_STATE
;
1849 amber_LED_off (ctrl
, hp_slot
);
1853 /* Wait for SOBS to be unset */
1854 wait_for_ctrl_irq (ctrl
);
1856 mutex_unlock(&ctrl
->crit_sect
);
1858 /*** button Released (No action on press...) */
1859 else if (ctrl
->event_queue
[loop
].event_type
== INT_BUTTON_RELEASE
) {
1860 dbg("button release\n");
1862 if (is_slot_enabled (ctrl
, hp_slot
)) {
1863 dbg("slot is on\n");
1864 p_slot
->state
= BLINKINGOFF_STATE
;
1865 info(msg_button_off
, p_slot
->number
);
1867 dbg("slot is off\n");
1868 p_slot
->state
= BLINKINGON_STATE
;
1869 info(msg_button_on
, p_slot
->number
);
1871 mutex_lock(&ctrl
->crit_sect
);
1873 dbg("blink green LED and turn off amber\n");
1875 amber_LED_off (ctrl
, hp_slot
);
1876 green_LED_blink (ctrl
, hp_slot
);
1880 /* Wait for SOBS to be unset */
1881 wait_for_ctrl_irq (ctrl
);
1883 mutex_unlock(&ctrl
->crit_sect
);
1884 init_timer(&p_slot
->task_event
);
1885 p_slot
->hp_slot
= hp_slot
;
1886 p_slot
->ctrl
= ctrl
;
1887 /* p_slot->physical_slot = physical_slot; */
1888 p_slot
->task_event
.expires
= jiffies
+ 5 * HZ
; /* 5 second delay */
1889 p_slot
->task_event
.function
= pushbutton_helper_thread
;
1890 p_slot
->task_event
.data
= (u32
) p_slot
;
1892 dbg("add_timer p_slot = %p\n", p_slot
);
1893 add_timer(&p_slot
->task_event
);
1895 /***********POWER FAULT */
1896 else if (ctrl
->event_queue
[loop
].event_type
== INT_POWER_FAULT
) {
1897 dbg("power fault\n");
1899 /* refresh notification */
1901 update_slot_info(ctrl
, p_slot
);
1904 ctrl
->event_queue
[loop
].event_type
= 0;
1908 } /* End of FOR loop */
1916 * cpqhp_pushbutton_thread - handle pushbutton events
1917 * @slot: target slot (struct)
1919 * Scheduled procedure to handle blocking stuff for the pushbuttons.
1920 * Handles all pending events and exits.
1922 void cpqhp_pushbutton_thread(unsigned long slot
)
1926 struct pci_func
*func
;
1927 struct slot
*p_slot
= (struct slot
*) slot
;
1928 struct controller
*ctrl
= (struct controller
*) p_slot
->ctrl
;
1930 pushbutton_pending
= 0;
1931 hp_slot
= p_slot
->hp_slot
;
1933 device
= p_slot
->device
;
1935 if (is_slot_enabled(ctrl
, hp_slot
)) {
1936 p_slot
->state
= POWEROFF_STATE
;
1937 /* power Down board */
1938 func
= cpqhp_slot_find(p_slot
->bus
, p_slot
->device
, 0);
1939 dbg("In power_down_board, func = %p, ctrl = %p\n", func
, ctrl
);
1941 dbg("Error! func NULL in %s\n", __func__
);
1945 if (cpqhp_process_SS(ctrl
, func
) != 0) {
1946 amber_LED_on(ctrl
, hp_slot
);
1947 green_LED_on(ctrl
, hp_slot
);
1951 /* Wait for SOBS to be unset */
1952 wait_for_ctrl_irq(ctrl
);
1955 p_slot
->state
= STATIC_STATE
;
1957 p_slot
->state
= POWERON_STATE
;
1960 func
= cpqhp_slot_find(p_slot
->bus
, p_slot
->device
, 0);
1961 dbg("In add_board, func = %p, ctrl = %p\n", func
, ctrl
);
1963 dbg("Error! func NULL in %s\n", __func__
);
1968 if (cpqhp_process_SI(ctrl
, func
) != 0) {
1969 amber_LED_on(ctrl
, hp_slot
);
1970 green_LED_off(ctrl
, hp_slot
);
1974 /* Wait for SOBS to be unset */
1975 wait_for_ctrl_irq (ctrl
);
1979 p_slot
->state
= STATIC_STATE
;
1986 int cpqhp_process_SI(struct controller
*ctrl
, struct pci_func
*func
)
1992 struct slot
* p_slot
;
1993 int physical_slot
= 0;
1997 device
= func
->device
;
1998 hp_slot
= device
- ctrl
->slot_device_offset
;
1999 p_slot
= cpqhp_find_slot(ctrl
, device
);
2001 physical_slot
= p_slot
->number
;
2003 /* Check to see if the interlock is closed */
2004 tempdword
= readl(ctrl
->hpc_reg
+ INT_INPUT_CLEAR
);
2006 if (tempdword
& (0x01 << hp_slot
)) {
2010 if (func
->is_a_board
) {
2011 rc
= board_replaced(func
, ctrl
);
2016 func
= cpqhp_slot_create(ctrl
->bus
);
2020 func
->bus
= ctrl
->bus
;
2021 func
->device
= device
;
2023 func
->configured
= 0;
2024 func
->is_a_board
= 1;
2026 /* We have to save the presence info for these slots */
2027 temp_word
= ctrl
->ctrl_int_comp
>> 16;
2028 func
->presence_save
= (temp_word
>> hp_slot
) & 0x01;
2029 func
->presence_save
|= (temp_word
>> (hp_slot
+ 7)) & 0x02;
2031 if (ctrl
->ctrl_int_comp
& (0x1L
<< hp_slot
)) {
2032 func
->switch_save
= 0;
2034 func
->switch_save
= 0x10;
2037 rc
= board_added(func
, ctrl
);
2039 if (is_bridge(func
)) {
2040 bridge_slot_remove(func
);
2044 /* Setup slot structure with entry for empty slot */
2045 func
= cpqhp_slot_create(ctrl
->bus
);
2050 func
->bus
= ctrl
->bus
;
2051 func
->device
= device
;
2053 func
->configured
= 0;
2054 func
->is_a_board
= 0;
2056 /* We have to save the presence info for these slots */
2057 temp_word
= ctrl
->ctrl_int_comp
>> 16;
2058 func
->presence_save
= (temp_word
>> hp_slot
) & 0x01;
2059 func
->presence_save
|=
2060 (temp_word
>> (hp_slot
+ 7)) & 0x02;
2062 if (ctrl
->ctrl_int_comp
& (0x1L
<< hp_slot
)) {
2063 func
->switch_save
= 0;
2065 func
->switch_save
= 0x10;
2071 dbg("%s: rc = %d\n", __func__
, rc
);
2075 update_slot_info(ctrl
, p_slot
);
2081 int cpqhp_process_SS(struct controller
*ctrl
, struct pci_func
*func
)
2083 u8 device
, class_code
, header_type
, BCR
;
2088 struct slot
* p_slot
;
2089 struct pci_bus
*pci_bus
= ctrl
->pci_bus
;
2090 int physical_slot
=0;
2092 device
= func
->device
;
2093 func
= cpqhp_slot_find(ctrl
->bus
, device
, index
++);
2094 p_slot
= cpqhp_find_slot(ctrl
, device
);
2096 physical_slot
= p_slot
->number
;
2099 /* Make sure there are no video controllers here */
2100 while (func
&& !rc
) {
2101 pci_bus
->number
= func
->bus
;
2102 devfn
= PCI_DEVFN(func
->device
, func
->function
);
2104 /* Check the Class Code */
2105 rc
= pci_bus_read_config_byte (pci_bus
, devfn
, 0x0B, &class_code
);
2109 if (class_code
== PCI_BASE_CLASS_DISPLAY
) {
2110 /* Display/Video adapter (not supported) */
2111 rc
= REMOVE_NOT_SUPPORTED
;
2113 /* See if it's a bridge */
2114 rc
= pci_bus_read_config_byte (pci_bus
, devfn
, PCI_HEADER_TYPE
, &header_type
);
2118 /* If it's a bridge, check the VGA Enable bit */
2119 if ((header_type
& 0x7F) == PCI_HEADER_TYPE_BRIDGE
) {
2120 rc
= pci_bus_read_config_byte (pci_bus
, devfn
, PCI_BRIDGE_CONTROL
, &BCR
);
2124 /* If the VGA Enable bit is set, remove isn't
2126 if (BCR
& PCI_BRIDGE_CTL_VGA
)
2127 rc
= REMOVE_NOT_SUPPORTED
;
2131 func
= cpqhp_slot_find(ctrl
->bus
, device
, index
++);
2134 func
= cpqhp_slot_find(ctrl
->bus
, device
, 0);
2135 if ((func
!= NULL
) && !rc
) {
2136 /* FIXME: Replace flag should be passed into process_SS */
2137 replace_flag
= !(ctrl
->add_support
);
2138 rc
= remove_board(func
, replace_flag
, ctrl
);
2144 update_slot_info(ctrl
, p_slot
);
2150 * switch_leds - switch the leds, go from one site to the other.
2151 * @ctrl: controller to use
2152 * @num_of_slots: number of slots to use
2153 * @work_LED: LED control value
2154 * @direction: 1 to start from the left side, 0 to start right.
2156 static void switch_leds(struct controller
*ctrl
, const int num_of_slots
,
2157 u32
*work_LED
, const int direction
)
2161 for (loop
= 0; loop
< num_of_slots
; loop
++) {
2163 *work_LED
= *work_LED
>> 1;
2165 *work_LED
= *work_LED
<< 1;
2166 writel(*work_LED
, ctrl
->hpc_reg
+ LED_CONTROL
);
2170 /* Wait for SOGO interrupt */
2171 wait_for_ctrl_irq(ctrl
);
2173 /* Get ready for next iteration */
2174 long_delay((2*HZ
)/10);
2179 * cpqhp_hardware_test - runs hardware tests
2180 * @ctrl: target controller
2181 * @test_num: the number written to the "test" file in sysfs.
2183 * For hot plug ctrl folks to play with.
2185 int cpqhp_hardware_test(struct controller
*ctrl
, int test_num
)
2192 num_of_slots
= readb(ctrl
->hpc_reg
+ SLOT_MASK
) & 0x0f;
2196 /* Do stuff here! */
2198 /* Do that funky LED thing */
2199 /* so we can restore them later */
2200 save_LED
= readl(ctrl
->hpc_reg
+ LED_CONTROL
);
2201 work_LED
= 0x01010101;
2202 switch_leds(ctrl
, num_of_slots
, &work_LED
, 0);
2203 switch_leds(ctrl
, num_of_slots
, &work_LED
, 1);
2204 switch_leds(ctrl
, num_of_slots
, &work_LED
, 0);
2205 switch_leds(ctrl
, num_of_slots
, &work_LED
, 1);
2207 work_LED
= 0x01010000;
2208 writel(work_LED
, ctrl
->hpc_reg
+ LED_CONTROL
);
2209 switch_leds(ctrl
, num_of_slots
, &work_LED
, 0);
2210 switch_leds(ctrl
, num_of_slots
, &work_LED
, 1);
2211 work_LED
= 0x00000101;
2212 writel(work_LED
, ctrl
->hpc_reg
+ LED_CONTROL
);
2213 switch_leds(ctrl
, num_of_slots
, &work_LED
, 0);
2214 switch_leds(ctrl
, num_of_slots
, &work_LED
, 1);
2216 work_LED
= 0x01010000;
2217 writel(work_LED
, ctrl
->hpc_reg
+ LED_CONTROL
);
2218 for (loop
= 0; loop
< num_of_slots
; loop
++) {
2221 /* Wait for SOGO interrupt */
2222 wait_for_ctrl_irq (ctrl
);
2224 /* Get ready for next iteration */
2225 long_delay((3*HZ
)/10);
2226 work_LED
= work_LED
>> 16;
2227 writel(work_LED
, ctrl
->hpc_reg
+ LED_CONTROL
);
2231 /* Wait for SOGO interrupt */
2232 wait_for_ctrl_irq (ctrl
);
2234 /* Get ready for next iteration */
2235 long_delay((3*HZ
)/10);
2236 work_LED
= work_LED
<< 16;
2237 writel(work_LED
, ctrl
->hpc_reg
+ LED_CONTROL
);
2238 work_LED
= work_LED
<< 1;
2239 writel(work_LED
, ctrl
->hpc_reg
+ LED_CONTROL
);
2242 /* put it back the way it was */
2243 writel(save_LED
, ctrl
->hpc_reg
+ LED_CONTROL
);
2247 /* Wait for SOBS to be unset */
2248 wait_for_ctrl_irq (ctrl
);
2251 /* Do other stuff here! */
2262 * configure_new_device - Configures the PCI header information of one board.
2263 * @ctrl: pointer to controller structure
2264 * @func: pointer to function structure
2265 * @behind_bridge: 1 if this is a recursive call, 0 if not
2266 * @resources: pointer to set of resource lists
2268 * Returns 0 if success.
2270 static u32
configure_new_device(struct controller
* ctrl
, struct pci_func
* func
,
2271 u8 behind_bridge
, struct resource_lists
* resources
)
2273 u8 temp_byte
, function
, max_functions
, stop_it
;
2276 struct pci_func
*new_slot
;
2281 dbg("%s\n", __func__
);
2282 /* Check for Multi-function device */
2283 ctrl
->pci_bus
->number
= func
->bus
;
2284 rc
= pci_bus_read_config_byte (ctrl
->pci_bus
, PCI_DEVFN(func
->device
, func
->function
), 0x0E, &temp_byte
);
2286 dbg("%s: rc = %d\n", __func__
, rc
);
2290 if (temp_byte
& 0x80) /* Multi-function device */
2298 rc
= configure_new_function(ctrl
, new_slot
, behind_bridge
, resources
);
2301 dbg("configure_new_function failed %d\n",rc
);
2305 new_slot
= cpqhp_slot_find(new_slot
->bus
, new_slot
->device
, index
++);
2308 cpqhp_return_board_resources(new_slot
, resources
);
2318 /* The following loop skips to the next present function
2319 * and creates a board structure */
2321 while ((function
< max_functions
) && (!stop_it
)) {
2322 pci_bus_read_config_dword (ctrl
->pci_bus
, PCI_DEVFN(func
->device
, function
), 0x00, &ID
);
2324 if (ID
== 0xFFFFFFFF) {
2327 /* Setup slot structure. */
2328 new_slot
= cpqhp_slot_create(func
->bus
);
2330 if (new_slot
== NULL
)
2333 new_slot
->bus
= func
->bus
;
2334 new_slot
->device
= func
->device
;
2335 new_slot
->function
= function
;
2336 new_slot
->is_a_board
= 1;
2337 new_slot
->status
= 0;
2343 } while (function
< max_functions
);
2344 dbg("returning from configure_new_device\n");
2351 * Configuration logic that involves the hotplug data structures and
2357 * configure_new_function - Configures the PCI header information of one device
2358 * @ctrl: pointer to controller structure
2359 * @func: pointer to function structure
2360 * @behind_bridge: 1 if this is a recursive call, 0 if not
2361 * @resources: pointer to set of resource lists
2363 * Calls itself recursively for bridged devices.
2364 * Returns 0 if success.
2366 static int configure_new_function(struct controller
*ctrl
, struct pci_func
*func
,
2368 struct resource_lists
*resources
)
2383 struct pci_resource
*mem_node
;
2384 struct pci_resource
*p_mem_node
;
2385 struct pci_resource
*io_node
;
2386 struct pci_resource
*bus_node
;
2387 struct pci_resource
*hold_mem_node
;
2388 struct pci_resource
*hold_p_mem_node
;
2389 struct pci_resource
*hold_IO_node
;
2390 struct pci_resource
*hold_bus_node
;
2391 struct irq_mapping irqs
;
2392 struct pci_func
*new_slot
;
2393 struct pci_bus
*pci_bus
;
2394 struct resource_lists temp_resources
;
2396 pci_bus
= ctrl
->pci_bus
;
2397 pci_bus
->number
= func
->bus
;
2398 devfn
= PCI_DEVFN(func
->device
, func
->function
);
2400 /* Check for Bridge */
2401 rc
= pci_bus_read_config_byte(pci_bus
, devfn
, PCI_HEADER_TYPE
, &temp_byte
);
2405 if ((temp_byte
& 0x7F) == PCI_HEADER_TYPE_BRIDGE
) {
2406 /* set Primary bus */
2407 dbg("set Primary bus = %d\n", func
->bus
);
2408 rc
= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_PRIMARY_BUS
, func
->bus
);
2412 /* find range of busses to use */
2413 dbg("find ranges of buses to use\n");
2414 bus_node
= get_max_resource(&(resources
->bus_head
), 1);
2416 /* If we don't have any busses to allocate, we can't continue */
2420 /* set Secondary bus */
2421 temp_byte
= bus_node
->base
;
2422 dbg("set Secondary bus = %d\n", bus_node
->base
);
2423 rc
= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_SECONDARY_BUS
, temp_byte
);
2427 /* set subordinate bus */
2428 temp_byte
= bus_node
->base
+ bus_node
->length
- 1;
2429 dbg("set subordinate bus = %d\n", bus_node
->base
+ bus_node
->length
- 1);
2430 rc
= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_SUBORDINATE_BUS
, temp_byte
);
2434 /* set subordinate Latency Timer and base Latency Timer */
2436 rc
= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_SEC_LATENCY_TIMER
, temp_byte
);
2439 rc
= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_LATENCY_TIMER
, temp_byte
);
2443 /* set Cache Line size */
2445 rc
= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_CACHE_LINE_SIZE
, temp_byte
);
2449 /* Setup the IO, memory, and prefetchable windows */
2450 io_node
= get_max_resource(&(resources
->io_head
), 0x1000);
2453 mem_node
= get_max_resource(&(resources
->mem_head
), 0x100000);
2456 p_mem_node
= get_max_resource(&(resources
->p_mem_head
), 0x100000);
2459 dbg("Setup the IO, memory, and prefetchable windows\n");
2461 dbg("(base, len, next) (%x, %x, %p)\n", io_node
->base
,
2462 io_node
->length
, io_node
->next
);
2464 dbg("(base, len, next) (%x, %x, %p)\n", mem_node
->base
,
2465 mem_node
->length
, mem_node
->next
);
2466 dbg("p_mem_node\n");
2467 dbg("(base, len, next) (%x, %x, %p)\n", p_mem_node
->base
,
2468 p_mem_node
->length
, p_mem_node
->next
);
2470 /* set up the IRQ info */
2471 if (!resources
->irqs
) {
2472 irqs
.barber_pole
= 0;
2473 irqs
.interrupt
[0] = 0;
2474 irqs
.interrupt
[1] = 0;
2475 irqs
.interrupt
[2] = 0;
2476 irqs
.interrupt
[3] = 0;
2479 irqs
.barber_pole
= resources
->irqs
->barber_pole
;
2480 irqs
.interrupt
[0] = resources
->irqs
->interrupt
[0];
2481 irqs
.interrupt
[1] = resources
->irqs
->interrupt
[1];
2482 irqs
.interrupt
[2] = resources
->irqs
->interrupt
[2];
2483 irqs
.interrupt
[3] = resources
->irqs
->interrupt
[3];
2484 irqs
.valid_INT
= resources
->irqs
->valid_INT
;
2487 /* set up resource lists that are now aligned on top and bottom
2488 * for anything behind the bridge. */
2489 temp_resources
.bus_head
= bus_node
;
2490 temp_resources
.io_head
= io_node
;
2491 temp_resources
.mem_head
= mem_node
;
2492 temp_resources
.p_mem_head
= p_mem_node
;
2493 temp_resources
.irqs
= &irqs
;
2495 /* Make copies of the nodes we are going to pass down so that
2496 * if there is a problem,we can just use these to free resources
2498 hold_bus_node
= kmalloc(sizeof(*hold_bus_node
), GFP_KERNEL
);
2499 hold_IO_node
= kmalloc(sizeof(*hold_IO_node
), GFP_KERNEL
);
2500 hold_mem_node
= kmalloc(sizeof(*hold_mem_node
), GFP_KERNEL
);
2501 hold_p_mem_node
= kmalloc(sizeof(*hold_p_mem_node
), GFP_KERNEL
);
2503 if (!hold_bus_node
|| !hold_IO_node
|| !hold_mem_node
|| !hold_p_mem_node
) {
2504 kfree(hold_bus_node
);
2505 kfree(hold_IO_node
);
2506 kfree(hold_mem_node
);
2507 kfree(hold_p_mem_node
);
2512 memcpy(hold_bus_node
, bus_node
, sizeof(struct pci_resource
));
2514 bus_node
->base
+= 1;
2515 bus_node
->length
-= 1;
2516 bus_node
->next
= NULL
;
2518 /* If we have IO resources copy them and fill in the bridge's
2519 * IO range registers */
2521 memcpy(hold_IO_node
, io_node
, sizeof(struct pci_resource
));
2522 io_node
->next
= NULL
;
2524 /* set IO base and Limit registers */
2525 temp_byte
= io_node
->base
>> 8;
2526 rc
= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_IO_BASE
, temp_byte
);
2528 temp_byte
= (io_node
->base
+ io_node
->length
- 1) >> 8;
2529 rc
= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_IO_LIMIT
, temp_byte
);
2531 kfree(hold_IO_node
);
2532 hold_IO_node
= NULL
;
2535 /* If we have memory resources copy them and fill in the
2536 * bridge's memory range registers. Otherwise, fill in the
2537 * range registers with values that disable them. */
2539 memcpy(hold_mem_node
, mem_node
, sizeof(struct pci_resource
));
2540 mem_node
->next
= NULL
;
2542 /* set Mem base and Limit registers */
2543 temp_word
= mem_node
->base
>> 16;
2544 rc
= pci_bus_write_config_word(pci_bus
, devfn
, PCI_MEMORY_BASE
, temp_word
);
2546 temp_word
= (mem_node
->base
+ mem_node
->length
- 1) >> 16;
2547 rc
= pci_bus_write_config_word(pci_bus
, devfn
, PCI_MEMORY_LIMIT
, temp_word
);
2550 rc
= pci_bus_write_config_word(pci_bus
, devfn
, PCI_MEMORY_BASE
, temp_word
);
2553 rc
= pci_bus_write_config_word(pci_bus
, devfn
, PCI_MEMORY_LIMIT
, temp_word
);
2555 kfree(hold_mem_node
);
2556 hold_mem_node
= NULL
;
2559 memcpy(hold_p_mem_node
, p_mem_node
, sizeof(struct pci_resource
));
2560 p_mem_node
->next
= NULL
;
2562 /* set Pre Mem base and Limit registers */
2563 temp_word
= p_mem_node
->base
>> 16;
2564 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_PREF_MEMORY_BASE
, temp_word
);
2566 temp_word
= (p_mem_node
->base
+ p_mem_node
->length
- 1) >> 16;
2567 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_PREF_MEMORY_LIMIT
, temp_word
);
2569 /* Adjust this to compensate for extra adjustment in first loop
2575 /* Here we actually find the devices and configure them */
2576 for (device
= 0; (device
<= 0x1F) && !rc
; device
++) {
2577 irqs
.barber_pole
= (irqs
.barber_pole
+ 1) & 0x03;
2580 pci_bus
->number
= hold_bus_node
->base
;
2581 pci_bus_read_config_dword (pci_bus
, PCI_DEVFN(device
, 0), 0x00, &ID
);
2582 pci_bus
->number
= func
->bus
;
2584 if (ID
!= 0xFFFFFFFF) { /* device present */
2585 /* Setup slot structure. */
2586 new_slot
= cpqhp_slot_create(hold_bus_node
->base
);
2588 if (new_slot
== NULL
) {
2593 new_slot
->bus
= hold_bus_node
->base
;
2594 new_slot
->device
= device
;
2595 new_slot
->function
= 0;
2596 new_slot
->is_a_board
= 1;
2597 new_slot
->status
= 0;
2599 rc
= configure_new_device(ctrl
, new_slot
, 1, &temp_resources
);
2600 dbg("configure_new_device rc=0x%x\n",rc
);
2601 } /* End of IF (device in slot?) */
2602 } /* End of FOR loop */
2606 /* save the interrupt routing information */
2607 if (resources
->irqs
) {
2608 resources
->irqs
->interrupt
[0] = irqs
.interrupt
[0];
2609 resources
->irqs
->interrupt
[1] = irqs
.interrupt
[1];
2610 resources
->irqs
->interrupt
[2] = irqs
.interrupt
[2];
2611 resources
->irqs
->interrupt
[3] = irqs
.interrupt
[3];
2612 resources
->irqs
->valid_INT
= irqs
.valid_INT
;
2613 } else if (!behind_bridge
) {
2614 /* We need to hook up the interrupts here */
2615 for (cloop
= 0; cloop
< 4; cloop
++) {
2616 if (irqs
.valid_INT
& (0x01 << cloop
)) {
2617 rc
= cpqhp_set_irq(func
->bus
, func
->device
,
2618 cloop
+ 1, irqs
.interrupt
[cloop
]);
2622 } /* end of for loop */
2624 /* Return unused bus resources
2625 * First use the temporary node to store information for
2627 if (hold_bus_node
&& bus_node
&& temp_resources
.bus_head
) {
2628 hold_bus_node
->length
= bus_node
->base
- hold_bus_node
->base
;
2630 hold_bus_node
->next
= func
->bus_head
;
2631 func
->bus_head
= hold_bus_node
;
2633 temp_byte
= temp_resources
.bus_head
->base
- 1;
2635 /* set subordinate bus */
2636 rc
= pci_bus_write_config_byte (pci_bus
, devfn
, PCI_SUBORDINATE_BUS
, temp_byte
);
2638 if (temp_resources
.bus_head
->length
== 0) {
2639 kfree(temp_resources
.bus_head
);
2640 temp_resources
.bus_head
= NULL
;
2642 return_resource(&(resources
->bus_head
), temp_resources
.bus_head
);
2646 /* If we have IO space available and there is some left,
2647 * return the unused portion */
2648 if (hold_IO_node
&& temp_resources
.io_head
) {
2649 io_node
= do_pre_bridge_resource_split(&(temp_resources
.io_head
),
2650 &hold_IO_node
, 0x1000);
2652 /* Check if we were able to split something off */
2654 hold_IO_node
->base
= io_node
->base
+ io_node
->length
;
2656 temp_byte
= (hold_IO_node
->base
) >> 8;
2657 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_IO_BASE
, temp_byte
);
2659 return_resource(&(resources
->io_head
), io_node
);
2662 io_node
= do_bridge_resource_split(&(temp_resources
.io_head
), 0x1000);
2664 /* Check if we were able to split something off */
2666 /* First use the temporary node to store
2667 * information for the board */
2668 hold_IO_node
->length
= io_node
->base
- hold_IO_node
->base
;
2670 /* If we used any, add it to the board's list */
2671 if (hold_IO_node
->length
) {
2672 hold_IO_node
->next
= func
->io_head
;
2673 func
->io_head
= hold_IO_node
;
2675 temp_byte
= (io_node
->base
- 1) >> 8;
2676 rc
= pci_bus_write_config_byte (pci_bus
, devfn
, PCI_IO_LIMIT
, temp_byte
);
2678 return_resource(&(resources
->io_head
), io_node
);
2680 /* it doesn't need any IO */
2682 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_IO_LIMIT
, temp_word
);
2684 return_resource(&(resources
->io_head
), io_node
);
2685 kfree(hold_IO_node
);
2688 /* it used most of the range */
2689 hold_IO_node
->next
= func
->io_head
;
2690 func
->io_head
= hold_IO_node
;
2692 } else if (hold_IO_node
) {
2693 /* it used the whole range */
2694 hold_IO_node
->next
= func
->io_head
;
2695 func
->io_head
= hold_IO_node
;
2697 /* If we have memory space available and there is some left,
2698 * return the unused portion */
2699 if (hold_mem_node
&& temp_resources
.mem_head
) {
2700 mem_node
= do_pre_bridge_resource_split(&(temp_resources
. mem_head
),
2701 &hold_mem_node
, 0x100000);
2703 /* Check if we were able to split something off */
2705 hold_mem_node
->base
= mem_node
->base
+ mem_node
->length
;
2707 temp_word
= (hold_mem_node
->base
) >> 16;
2708 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_MEMORY_BASE
, temp_word
);
2710 return_resource(&(resources
->mem_head
), mem_node
);
2713 mem_node
= do_bridge_resource_split(&(temp_resources
.mem_head
), 0x100000);
2715 /* Check if we were able to split something off */
2717 /* First use the temporary node to store
2718 * information for the board */
2719 hold_mem_node
->length
= mem_node
->base
- hold_mem_node
->base
;
2721 if (hold_mem_node
->length
) {
2722 hold_mem_node
->next
= func
->mem_head
;
2723 func
->mem_head
= hold_mem_node
;
2725 /* configure end address */
2726 temp_word
= (mem_node
->base
- 1) >> 16;
2727 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_MEMORY_LIMIT
, temp_word
);
2729 /* Return unused resources to the pool */
2730 return_resource(&(resources
->mem_head
), mem_node
);
2732 /* it doesn't need any Mem */
2734 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_MEMORY_LIMIT
, temp_word
);
2736 return_resource(&(resources
->mem_head
), mem_node
);
2737 kfree(hold_mem_node
);
2740 /* it used most of the range */
2741 hold_mem_node
->next
= func
->mem_head
;
2742 func
->mem_head
= hold_mem_node
;
2744 } else if (hold_mem_node
) {
2745 /* it used the whole range */
2746 hold_mem_node
->next
= func
->mem_head
;
2747 func
->mem_head
= hold_mem_node
;
2749 /* If we have prefetchable memory space available and there
2750 * is some left at the end, return the unused portion */
2751 if (hold_p_mem_node
&& temp_resources
.p_mem_head
) {
2752 p_mem_node
= do_pre_bridge_resource_split(&(temp_resources
.p_mem_head
),
2753 &hold_p_mem_node
, 0x100000);
2755 /* Check if we were able to split something off */
2757 hold_p_mem_node
->base
= p_mem_node
->base
+ p_mem_node
->length
;
2759 temp_word
= (hold_p_mem_node
->base
) >> 16;
2760 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_PREF_MEMORY_BASE
, temp_word
);
2762 return_resource(&(resources
->p_mem_head
), p_mem_node
);
2765 p_mem_node
= do_bridge_resource_split(&(temp_resources
.p_mem_head
), 0x100000);
2767 /* Check if we were able to split something off */
2769 /* First use the temporary node to store
2770 * information for the board */
2771 hold_p_mem_node
->length
= p_mem_node
->base
- hold_p_mem_node
->base
;
2773 /* If we used any, add it to the board's list */
2774 if (hold_p_mem_node
->length
) {
2775 hold_p_mem_node
->next
= func
->p_mem_head
;
2776 func
->p_mem_head
= hold_p_mem_node
;
2778 temp_word
= (p_mem_node
->base
- 1) >> 16;
2779 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_PREF_MEMORY_LIMIT
, temp_word
);
2781 return_resource(&(resources
->p_mem_head
), p_mem_node
);
2783 /* it doesn't need any PMem */
2785 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_PREF_MEMORY_LIMIT
, temp_word
);
2787 return_resource(&(resources
->p_mem_head
), p_mem_node
);
2788 kfree(hold_p_mem_node
);
2791 /* it used the most of the range */
2792 hold_p_mem_node
->next
= func
->p_mem_head
;
2793 func
->p_mem_head
= hold_p_mem_node
;
2795 } else if (hold_p_mem_node
) {
2796 /* it used the whole range */
2797 hold_p_mem_node
->next
= func
->p_mem_head
;
2798 func
->p_mem_head
= hold_p_mem_node
;
2800 /* We should be configuring an IRQ and the bridge's base address
2801 * registers if it needs them. Although we have never seen such
2805 command
= 0x0157; /* = PCI_COMMAND_IO |
2806 * PCI_COMMAND_MEMORY |
2807 * PCI_COMMAND_MASTER |
2808 * PCI_COMMAND_INVALIDATE |
2809 * PCI_COMMAND_PARITY |
2810 * PCI_COMMAND_SERR */
2811 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_COMMAND
, command
);
2813 /* set Bridge Control Register */
2814 command
= 0x07; /* = PCI_BRIDGE_CTL_PARITY |
2815 * PCI_BRIDGE_CTL_SERR |
2816 * PCI_BRIDGE_CTL_NO_ISA */
2817 rc
= pci_bus_write_config_word (pci_bus
, devfn
, PCI_BRIDGE_CONTROL
, command
);
2818 } else if ((temp_byte
& 0x7F) == PCI_HEADER_TYPE_NORMAL
) {
2819 /* Standard device */
2820 rc
= pci_bus_read_config_byte (pci_bus
, devfn
, 0x0B, &class_code
);
2822 if (class_code
== PCI_BASE_CLASS_DISPLAY
) {
2823 /* Display (video) adapter (not supported) */
2824 return DEVICE_TYPE_NOT_SUPPORTED
;
2826 /* Figure out IO and memory needs */
2827 for (cloop
= 0x10; cloop
<= 0x24; cloop
+= 4) {
2828 temp_register
= 0xFFFFFFFF;
2830 dbg("CND: bus=%d, devfn=%d, offset=%d\n", pci_bus
->number
, devfn
, cloop
);
2831 rc
= pci_bus_write_config_dword (pci_bus
, devfn
, cloop
, temp_register
);
2833 rc
= pci_bus_read_config_dword (pci_bus
, devfn
, cloop
, &temp_register
);
2834 dbg("CND: base = 0x%x\n", temp_register
);
2836 if (temp_register
) { /* If this register is implemented */
2837 if ((temp_register
& 0x03L
) == 0x01) {
2840 /* set base = amount of IO space */
2841 base
= temp_register
& 0xFFFFFFFC;
2844 dbg("CND: length = 0x%x\n", base
);
2845 io_node
= get_io_resource(&(resources
->io_head
), base
);
2846 dbg("Got io_node start = %8.8x, length = %8.8x next (%p)\n",
2847 io_node
->base
, io_node
->length
, io_node
->next
);
2848 dbg("func (%p) io_head (%p)\n", func
, func
->io_head
);
2850 /* allocate the resource to the board */
2852 base
= io_node
->base
;
2854 io_node
->next
= func
->io_head
;
2855 func
->io_head
= io_node
;
2858 } else if ((temp_register
& 0x0BL
) == 0x08) {
2859 /* Map prefetchable memory */
2860 base
= temp_register
& 0xFFFFFFF0;
2863 dbg("CND: length = 0x%x\n", base
);
2864 p_mem_node
= get_resource(&(resources
->p_mem_head
), base
);
2866 /* allocate the resource to the board */
2868 base
= p_mem_node
->base
;
2870 p_mem_node
->next
= func
->p_mem_head
;
2871 func
->p_mem_head
= p_mem_node
;
2874 } else if ((temp_register
& 0x0BL
) == 0x00) {
2876 base
= temp_register
& 0xFFFFFFF0;
2879 dbg("CND: length = 0x%x\n", base
);
2880 mem_node
= get_resource(&(resources
->mem_head
), base
);
2882 /* allocate the resource to the board */
2884 base
= mem_node
->base
;
2886 mem_node
->next
= func
->mem_head
;
2887 func
->mem_head
= mem_node
;
2890 } else if ((temp_register
& 0x0BL
) == 0x04) {
2892 base
= temp_register
& 0xFFFFFFF0;
2895 dbg("CND: length = 0x%x\n", base
);
2896 mem_node
= get_resource(&(resources
->mem_head
), base
);
2898 /* allocate the resource to the board */
2900 base
= mem_node
->base
;
2902 mem_node
->next
= func
->mem_head
;
2903 func
->mem_head
= mem_node
;
2906 } else if ((temp_register
& 0x0BL
) == 0x06) {
2907 /* Those bits are reserved, we can't handle this */
2910 /* Requesting space below 1M */
2911 return NOT_ENOUGH_RESOURCES
;
2914 rc
= pci_bus_write_config_dword(pci_bus
, devfn
, cloop
, base
);
2916 /* Check for 64-bit base */
2917 if ((temp_register
& 0x07L
) == 0x04) {
2920 /* Upper 32 bits of address always zero
2921 * on today's systems */
2922 /* FIXME this is probably not true on
2923 * Alpha and ia64??? */
2925 rc
= pci_bus_write_config_dword(pci_bus
, devfn
, cloop
, base
);
2928 } /* End of base register loop */
2929 if (cpqhp_legacy_mode
) {
2930 /* Figure out which interrupt pin this function uses */
2931 rc
= pci_bus_read_config_byte (pci_bus
, devfn
,
2932 PCI_INTERRUPT_PIN
, &temp_byte
);
2934 /* If this function needs an interrupt and we are behind
2935 * a bridge and the pin is tied to something that's
2936 * alread mapped, set this one the same */
2937 if (temp_byte
&& resources
->irqs
&&
2938 (resources
->irqs
->valid_INT
&
2939 (0x01 << ((temp_byte
+ resources
->irqs
->barber_pole
- 1) & 0x03)))) {
2940 /* We have to share with something already set up */
2941 IRQ
= resources
->irqs
->interrupt
[(temp_byte
+
2942 resources
->irqs
->barber_pole
- 1) & 0x03];
2944 /* Program IRQ based on card type */
2945 rc
= pci_bus_read_config_byte (pci_bus
, devfn
, 0x0B, &class_code
);
2947 if (class_code
== PCI_BASE_CLASS_STORAGE
)
2948 IRQ
= cpqhp_disk_irq
;
2950 IRQ
= cpqhp_nic_irq
;
2954 rc
= pci_bus_write_config_byte (pci_bus
, devfn
, PCI_INTERRUPT_LINE
, IRQ
);
2957 if (!behind_bridge
) {
2958 rc
= cpqhp_set_irq(func
->bus
, func
->device
, temp_byte
, IRQ
);
2962 /* TBD - this code may also belong in the other clause
2963 * of this If statement */
2964 resources
->irqs
->interrupt
[(temp_byte
+ resources
->irqs
->barber_pole
- 1) & 0x03] = IRQ
;
2965 resources
->irqs
->valid_INT
|= 0x01 << (temp_byte
+ resources
->irqs
->barber_pole
- 1) & 0x03;
2970 rc
= pci_bus_write_config_byte(pci_bus
, devfn
,
2971 PCI_LATENCY_TIMER
, temp_byte
);
2973 /* Cache Line size */
2975 rc
= pci_bus_write_config_byte(pci_bus
, devfn
,
2976 PCI_CACHE_LINE_SIZE
, temp_byte
);
2978 /* disable ROM base Address */
2980 rc
= pci_bus_write_config_word(pci_bus
, devfn
,
2981 PCI_ROM_ADDRESS
, temp_dword
);
2984 temp_word
= 0x0157; /* = PCI_COMMAND_IO |
2985 * PCI_COMMAND_MEMORY |
2986 * PCI_COMMAND_MASTER |
2987 * PCI_COMMAND_INVALIDATE |
2988 * PCI_COMMAND_PARITY |
2989 * PCI_COMMAND_SERR */
2990 rc
= pci_bus_write_config_word (pci_bus
, devfn
,
2991 PCI_COMMAND
, temp_word
);
2992 } else { /* End of Not-A-Bridge else */
2993 /* It's some strange type of PCI adapter (Cardbus?) */
2994 return DEVICE_TYPE_NOT_SUPPORTED
;
2997 func
->configured
= 1;
3001 cpqhp_destroy_resource_list (&temp_resources
);
3003 return_resource(&(resources
-> bus_head
), hold_bus_node
);
3004 return_resource(&(resources
-> io_head
), hold_IO_node
);
3005 return_resource(&(resources
-> mem_head
), hold_mem_node
);
3006 return_resource(&(resources
-> p_mem_head
), hold_p_mem_node
);