2 * PCI Express 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.
7 * Copyright (C) 2003-2004 Intel Corporation
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Send feedback to <greg@kroah.com>, <dely.l.sy@intel.com>
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/slab.h>
35 #include <linux/workqueue.h>
36 #include <linux/interrupt.h>
37 #include <linux/delay.h>
38 #include <linux/wait.h>
39 #include <linux/smp_lock.h>
40 #include <linux/pci.h>
44 static u32 configure_new_device(struct controller *ctrl, struct pci_func *func,
45 u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev);
46 static int configure_new_function( struct controller *ctrl, struct pci_func *func,
47 u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev);
48 static void interrupt_event_handler(struct controller *ctrl);
50 static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
51 static struct semaphore event_exit; /* guard ensure thread has exited before calling it quits */
52 static int event_finished;
53 static unsigned long pushbutton_pending; /* = 0 */
55 u8 pciehp_handle_attention_button(u8 hp_slot, void *inst_id)
57 struct controller *ctrl = (struct controller *) inst_id;
61 struct pci_func *func;
62 struct event_info *taskInfo;
64 /* Attention Button Change */
65 dbg("pciehp: Attention button interrupt received.\n");
67 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
69 /* This is the structure that tells the worker thread what to do */
70 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
71 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
73 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
74 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
76 ctrl->next_event = (ctrl->next_event + 1) % 10;
77 taskInfo->hp_slot = hp_slot;
82 * Button pressed - See if need to TAKE ACTION!!!
84 info("Button pressed on Slot(%d)\n", ctrl->first_slot + hp_slot);
85 taskInfo->event_type = INT_BUTTON_PRESS;
87 if ((p_slot->state == BLINKINGON_STATE)
88 || (p_slot->state == BLINKINGOFF_STATE)) {
89 /* Cancel if we are still blinking; this means that we press the
90 * attention again before the 5 sec. limit expires to cancel hot-add
93 taskInfo->event_type = INT_BUTTON_CANCEL;
94 info("Button cancel on Slot(%d)\n", ctrl->first_slot + hp_slot);
95 } else if ((p_slot->state == POWERON_STATE)
96 || (p_slot->state == POWEROFF_STATE)) {
97 /* Ignore if the slot is on power-on or power-off state; this
98 * means that the previous attention button action to hot-add or
99 * hot-remove is undergoing
101 taskInfo->event_type = INT_BUTTON_IGNORE;
102 info("Button ignore on Slot(%d)\n", ctrl->first_slot + hp_slot);
106 up(&event_semaphore); /* signal event thread that new event is posted */
112 u8 pciehp_handle_switch_change(u8 hp_slot, void *inst_id)
114 struct controller *ctrl = (struct controller *) inst_id;
118 struct pci_func *func;
119 struct event_info *taskInfo;
122 dbg("pciehp: Switch interrupt received.\n");
124 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
126 /* This is the structure that tells the worker thread
129 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
130 ctrl->next_event = (ctrl->next_event + 1) % 10;
131 taskInfo->hp_slot = hp_slot;
134 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
135 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
136 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
142 info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot);
143 func->switch_save = 0;
144 taskInfo->event_type = INT_SWITCH_OPEN;
149 info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot);
150 func->switch_save = 0x10;
151 taskInfo->event_type = INT_SWITCH_CLOSE;
155 up(&event_semaphore); /* signal event thread that new event is posted */
160 u8 pciehp_handle_presence_change(u8 hp_slot, void *inst_id)
162 struct controller *ctrl = (struct controller *) inst_id;
165 struct pci_func *func;
166 struct event_info *taskInfo;
168 /* Presence Change */
169 dbg("pciehp: Presence/Notify input change.\n");
171 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
173 /* This is the structure that tells the worker thread
176 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
177 ctrl->next_event = (ctrl->next_event + 1) % 10;
178 taskInfo->hp_slot = hp_slot;
181 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
183 /* Switch is open, assume a presence change
184 * Save the presence state
186 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
187 if (func->presence_save) {
191 info("Card present on Slot(%d)\n", ctrl->first_slot + hp_slot);
192 taskInfo->event_type = INT_PRESENCE_ON;
197 info("Card not present on Slot(%d)\n", ctrl->first_slot + hp_slot);
198 taskInfo->event_type = INT_PRESENCE_OFF;
202 up(&event_semaphore); /* signal event thread that new event is posted */
207 u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id)
209 struct controller *ctrl = (struct controller *) inst_id;
212 struct pci_func *func;
213 struct event_info *taskInfo;
216 dbg("pciehp: Power fault interrupt received.\n");
218 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
220 /* this is the structure that tells the worker thread
223 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
224 ctrl->next_event = (ctrl->next_event + 1) % 10;
225 taskInfo->hp_slot = hp_slot;
228 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
230 if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) {
232 * power fault Cleared
234 info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot);
236 taskInfo->event_type = INT_POWER_FAULT_CLEAR;
241 info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot);
242 taskInfo->event_type = INT_POWER_FAULT;
243 /* set power fault status for this board */
245 info("power fault bit %x set\n", hp_slot);
248 up(&event_semaphore); /* signal event thread that new event is posted */
255 * sort_by_size: sort nodes by their length, smallest first.
257 * @head: list to sort
259 static int sort_by_size(struct pci_resource **head)
261 struct pci_resource *current_res;
262 struct pci_resource *next_res;
263 int out_of_order = 1;
268 if (!((*head)->next))
271 while (out_of_order) {
274 /* Special case for swapping list head */
275 if (((*head)->next) &&
276 ((*head)->length > (*head)->next->length)) {
279 *head = (*head)->next;
280 current_res->next = (*head)->next;
281 (*head)->next = current_res;
286 while (current_res->next && current_res->next->next) {
287 if (current_res->next->length > current_res->next->next->length) {
289 next_res = current_res->next;
290 current_res->next = current_res->next->next;
291 current_res = current_res->next;
292 next_res->next = current_res->next;
293 current_res->next = next_res;
295 current_res = current_res->next;
297 } /* End of out_of_order loop */
306 * Sorts nodes on the list by their length.
310 static int sort_by_max_size(struct pci_resource **head)
312 struct pci_resource *current_res;
313 struct pci_resource *next_res;
314 int out_of_order = 1;
319 if (!((*head)->next))
322 while (out_of_order) {
325 /* Special case for swapping list head */
326 if (((*head)->next) &&
327 ((*head)->length < (*head)->next->length)) {
330 *head = (*head)->next;
331 current_res->next = (*head)->next;
332 (*head)->next = current_res;
337 while (current_res->next && current_res->next->next) {
338 if (current_res->next->length < current_res->next->next->length) {
340 next_res = current_res->next;
341 current_res->next = current_res->next->next;
342 current_res = current_res->next;
343 next_res->next = current_res->next;
344 current_res->next = next_res;
346 current_res = current_res->next;
348 } /* End of out_of_order loop */
355 * do_pre_bridge_resource_split: return one unused resource node
356 * @head: list to scan
359 static struct pci_resource *
360 do_pre_bridge_resource_split(struct pci_resource **head,
361 struct pci_resource **orig_head, u32 alignment)
363 struct pci_resource *prevnode = NULL;
364 struct pci_resource *node;
365 struct pci_resource *split_node;
368 dbg("do_pre_bridge_resource_split\n");
370 if (!(*head) || !(*orig_head))
373 rc = pciehp_resource_sort_and_combine(head);
378 if ((*head)->base != (*orig_head)->base)
381 if ((*head)->length == (*orig_head)->length)
385 /* If we got here, there the bridge requires some of the resource, but
386 * we may be able to split some off of the front
390 if (node->length & (alignment -1)) {
391 /* this one isn't an aligned length, so we'll make a new entry
394 split_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
399 temp_dword = (node->length | (alignment-1)) + 1 - alignment;
401 split_node->base = node->base;
402 split_node->length = temp_dword;
404 node->length -= temp_dword;
405 node->base += split_node->length;
407 /* Put it in the list */
409 split_node->next = node;
412 if (node->length < alignment)
420 while (prevnode->next != node)
421 prevnode = prevnode->next;
423 prevnode->next = node->next;
432 * do_bridge_resource_split: return one unused resource node
433 * @head: list to scan
436 static struct pci_resource *
437 do_bridge_resource_split(struct pci_resource **head, u32 alignment)
439 struct pci_resource *prevnode = NULL;
440 struct pci_resource *node;
447 rc = pciehp_resource_sort_and_combine(head);
460 if (node->length < alignment) {
465 if (node->base & (alignment - 1)) {
466 /* Short circuit if adjusted size is too small */
467 temp_dword = (node->base | (alignment-1)) + 1;
468 if ((node->length - (temp_dword - node->base)) < alignment) {
473 node->length -= (temp_dword - node->base);
474 node->base = temp_dword;
477 if (node->length & (alignment - 1)) {
478 /* There's stuff in use after this node */
490 * this function sorts the resource list by size and then
491 * returns the first node of "size" length that is not in the
492 * ISA aliasing window. If it finds a node larger than "size"
493 * it will split it up.
495 * size must be a power of two.
497 static struct pci_resource *get_io_resource(struct pci_resource **head, u32 size)
499 struct pci_resource *prevnode;
500 struct pci_resource *node;
501 struct pci_resource *split_node = NULL;
507 if ( pciehp_resource_sort_and_combine(head) )
510 if ( sort_by_size(head) )
513 for (node = *head; node; node = node->next) {
514 if (node->length < size)
517 if (node->base & (size - 1)) {
518 /* this one isn't base aligned properly
519 so we'll make a new entry and split it up */
520 temp_dword = (node->base | (size-1)) + 1;
522 /*/ Short circuit if adjusted size is too small */
523 if ((node->length - (temp_dword - node->base)) < size)
526 split_node = kmalloc(sizeof(struct pci_resource),
532 split_node->base = node->base;
533 split_node->length = temp_dword - node->base;
534 node->base = temp_dword;
535 node->length -= split_node->length;
537 /* Put it in the list */
538 split_node->next = node->next;
539 node->next = split_node;
540 } /* End of non-aligned base */
542 /* Don't need to check if too small since we already did */
543 if (node->length > size) {
544 /* this one is longer than we need
545 so we'll make a new entry and split it up */
546 split_node = kmalloc(sizeof(struct pci_resource),
552 split_node->base = node->base + size;
553 split_node->length = node->length - size;
556 /* Put it in the list */
557 split_node->next = node->next;
558 node->next = split_node;
559 } /* End of too big on top end */
561 /* For IO make sure it's not in the ISA aliasing space */
562 if (node->base & 0x300L)
565 /* If we got here, then it is the right size
566 Now take it out of the list */
571 while (prevnode->next != node)
572 prevnode = prevnode->next;
574 prevnode->next = node->next;
588 * Gets the largest node that is at least "size" big from the
589 * list pointed to by head. It aligns the node on top and bottom
590 * to "size" alignment before returning it.
591 * J.I. modified to put max size limits of; 64M->32M->16M->8M->4M->1M
592 * This is needed to avoid allocating entire ACPI _CRS res to one child bridge/slot.
594 static struct pci_resource *get_max_resource(struct pci_resource **head, u32 size)
596 struct pci_resource *max;
597 struct pci_resource *temp;
598 struct pci_resource *split_node;
600 u32 max_size[] = { 0x4000000, 0x2000000, 0x1000000, 0x0800000, 0x0400000, 0x0200000, 0x0100000, 0x00 };
606 if (pciehp_resource_sort_and_combine(head))
609 if (sort_by_max_size(head))
612 for (max = *head;max; max = max->next) {
614 /* If not big enough we could probably just bail,
615 instead we'll continue to the next. */
616 if (max->length < size)
619 if (max->base & (size - 1)) {
620 /* this one isn't base aligned properly
621 so we'll make a new entry and split it up */
622 temp_dword = (max->base | (size-1)) + 1;
624 /* Short circuit if adjusted size is too small */
625 if ((max->length - (temp_dword - max->base)) < size)
628 split_node = kmalloc(sizeof(struct pci_resource),
634 split_node->base = max->base;
635 split_node->length = temp_dword - max->base;
636 max->base = temp_dword;
637 max->length -= split_node->length;
639 /* Put it next in the list */
640 split_node->next = max->next;
641 max->next = split_node;
644 if ((max->base + max->length) & (size - 1)) {
645 /* this one isn't end aligned properly at the top
646 so we'll make a new entry and split it up */
647 split_node = kmalloc(sizeof(struct pci_resource),
652 temp_dword = ((max->base + max->length) & ~(size - 1));
653 split_node->base = temp_dword;
654 split_node->length = max->length + max->base
656 max->length -= split_node->length;
658 /* Put it in the list */
659 split_node->next = max->next;
660 max->next = split_node;
663 /* Make sure it didn't shrink too much when we aligned it */
664 if (max->length < size)
667 for ( i = 0; max_size[i] > size; i++) {
668 if (max->length > max_size[i]) {
669 split_node = kmalloc(sizeof(struct pci_resource),
672 break; /* return NULL; */
673 split_node->base = max->base + max_size[i];
674 split_node->length = max->length - max_size[i];
675 max->length = max_size[i];
676 /* Put it next in the list */
677 split_node->next = max->next;
678 max->next = split_node;
683 /* Now take it out of the list */
684 temp = (struct pci_resource*) *head;
688 while (temp && temp->next != max) {
692 temp->next = max->next;
699 /* If we get here, we couldn't find one */
707 * this function sorts the resource list by size and then
708 * returns the first node of "size" length. If it finds a node
709 * larger than "size" it will split it up.
711 * size must be a power of two.
713 static struct pci_resource *get_resource(struct pci_resource **head, u32 size)
715 struct pci_resource *prevnode;
716 struct pci_resource *node;
717 struct pci_resource *split_node;
723 if ( pciehp_resource_sort_and_combine(head) )
726 if ( sort_by_size(head) )
729 for (node = *head; node; node = node->next) {
730 dbg("%s: req_size =0x%x node=%p, base=0x%x, length=0x%x\n",
731 __FUNCTION__, size, node, node->base, node->length);
732 if (node->length < size)
735 if (node->base & (size - 1)) {
736 dbg("%s: not aligned\n", __FUNCTION__);
737 /* this one isn't base aligned properly
738 so we'll make a new entry and split it up */
739 temp_dword = (node->base | (size-1)) + 1;
741 /* Short circuit if adjusted size is too small */
742 if ((node->length - (temp_dword - node->base)) < size)
745 split_node = kmalloc(sizeof(struct pci_resource),
751 split_node->base = node->base;
752 split_node->length = temp_dword - node->base;
753 node->base = temp_dword;
754 node->length -= split_node->length;
756 /* Put it in the list */
757 split_node->next = node->next;
758 node->next = split_node;
759 } /* End of non-aligned base */
761 /* Don't need to check if too small since we already did */
762 if (node->length > size) {
763 dbg("%s: too big\n", __FUNCTION__);
764 /* this one is longer than we need
765 so we'll make a new entry and split it up */
766 split_node = kmalloc(sizeof(struct pci_resource),
772 split_node->base = node->base + size;
773 split_node->length = node->length - size;
776 /* Put it in the list */
777 split_node->next = node->next;
778 node->next = split_node;
779 } /* End of too big on top end */
781 dbg("%s: got one!!!\n", __FUNCTION__);
782 /* If we got here, then it is the right size
783 Now take it out of the list */
788 while (prevnode->next != node)
789 prevnode = prevnode->next;
791 prevnode->next = node->next;
802 * pciehp_resource_sort_and_combine
804 * Sorts all of the nodes in the list in ascending order by
805 * their base addresses. Also does garbage collection by
806 * combining adjacent nodes.
808 * returns 0 if success
810 int pciehp_resource_sort_and_combine(struct pci_resource **head)
812 struct pci_resource *node1;
813 struct pci_resource *node2;
814 int out_of_order = 1;
816 dbg("%s: head = %p, *head = %p\n", __FUNCTION__, head, *head);
821 dbg("*head->next = %p\n",(*head)->next);
824 return 0; /* only one item on the list, already sorted! */
826 dbg("*head->base = 0x%x\n",(*head)->base);
827 dbg("*head->next->base = 0x%x\n",(*head)->next->base);
828 while (out_of_order) {
831 /* Special case for swapping list head */
832 if (((*head)->next) &&
833 ((*head)->base > (*head)->next->base)) {
835 (*head) = (*head)->next;
836 node1->next = (*head)->next;
837 (*head)->next = node1;
843 while (node1->next && node1->next->next) {
844 if (node1->next->base > node1->next->next->base) {
847 node1->next = node1->next->next;
849 node2->next = node1->next;
854 } /* End of out_of_order loop */
858 while (node1 && node1->next) {
859 if ((node1->base + node1->length) == node1->next->base) {
862 node1->length += node1->next->length;
864 node1->next = node1->next->next;
875 * pciehp_slot_create - Creates a node and adds it to the proper bus.
876 * @busnumber - bus where new node is to be located
878 * Returns pointer to the new node or NULL if unsuccessful
880 struct pci_func *pciehp_slot_create(u8 busnumber)
882 struct pci_func *new_slot;
883 struct pci_func *next;
884 dbg("%s: busnumber %x\n", __FUNCTION__, busnumber);
885 new_slot = kmalloc(sizeof(struct pci_func), GFP_KERNEL);
887 if (new_slot == NULL)
890 memset(new_slot, 0, sizeof(struct pci_func));
892 new_slot->next = NULL;
893 new_slot->configured = 1;
895 if (pciehp_slot_list[busnumber] == NULL) {
896 pciehp_slot_list[busnumber] = new_slot;
898 next = pciehp_slot_list[busnumber];
899 while (next->next != NULL)
901 next->next = new_slot;
908 * slot_remove - Removes a node from the linked list of slots.
909 * @old_slot: slot to remove
911 * Returns 0 if successful, !0 otherwise.
913 static int slot_remove(struct pci_func * old_slot)
915 struct pci_func *next;
917 if (old_slot == NULL)
920 next = pciehp_slot_list[old_slot->bus];
925 if (next == old_slot) {
926 pciehp_slot_list[old_slot->bus] = old_slot->next;
927 pciehp_destroy_board_resources(old_slot);
932 while ((next->next != old_slot) && (next->next != NULL)) {
936 if (next->next == old_slot) {
937 next->next = old_slot->next;
938 pciehp_destroy_board_resources(old_slot);
947 * bridge_slot_remove - Removes a node from the linked list of slots.
948 * @bridge: bridge to remove
950 * Returns 0 if successful, !0 otherwise.
952 static int bridge_slot_remove(struct pci_func *bridge)
954 u8 subordinateBus, secondaryBus;
956 struct pci_func *next;
961 secondaryBus = (bridge->config_space[0x06] >> 8) & 0xFF;
962 subordinateBus = (bridge->config_space[0x06] >> 16) & 0xFF;
964 for (tempBus = secondaryBus; tempBus <= subordinateBus; tempBus++) {
965 next = pciehp_slot_list[tempBus];
967 while (!slot_remove(next)) {
968 next = pciehp_slot_list[tempBus];
972 next = pciehp_slot_list[bridge->bus];
978 if (next == bridge) {
979 pciehp_slot_list[bridge->bus] = bridge->next;
984 while ((next->next != bridge) && (next->next != NULL)) {
988 if (next->next == bridge) {
989 next->next = bridge->next;
998 * pciehp_slot_find - Looks for a node by bus, and device, multiple functions accessed
1000 * @device: device to find
1001 * @index: is 0 for first function found, 1 for the second...
1003 * Returns pointer to the node if successful, %NULL otherwise.
1005 struct pci_func *pciehp_slot_find(u8 bus, u8 device, u8 index)
1008 struct pci_func *func;
1010 func = pciehp_slot_list[bus];
1011 dbg("%s: bus %x device %x index %x\n",
1012 __FUNCTION__, bus, device, index);
1014 dbg("%s: func-> bus %x device %x function %x pci_dev %p\n",
1015 __FUNCTION__, func->bus, func->device, func->function,
1018 dbg("%s: func == NULL\n", __FUNCTION__);
1020 if ((func == NULL) || ((func->device == device) && (index == 0)))
1023 if (func->device == device)
1026 while (func->next != NULL) {
1029 dbg("%s: In while loop, func-> bus %x device %x function %x pci_dev %p\n",
1030 __FUNCTION__, func->bus, func->device, func->function,
1032 if (func->device == device)
1034 dbg("%s: while loop, found %d, index %d\n", __FUNCTION__,
1037 if ((found == index) || (func->function == index)) {
1038 dbg("%s: Found bus %x dev %x func %x\n", __FUNCTION__,
1039 func->bus, func->device, func->function);
1047 static int is_bridge(struct pci_func * func)
1049 /* Check the header type */
1050 if (((func->config_space[0x03] >> 16) & 0xFF) == 0x01)
1057 /* The following routines constitute the bulk of the
1058 hotplug controller logic
1063 * board_added - Called after a board has been added to the system.
1065 * Turns power on for the board
1069 static u32 board_added(struct pci_func * func, struct controller * ctrl)
1073 u32 temp_register = 0xFFFFFFFF;
1075 struct pci_func *new_func = NULL;
1076 struct slot *p_slot;
1077 struct resource_lists res_lists;
1079 p_slot = pciehp_find_slot(ctrl, func->device);
1080 hp_slot = func->device - ctrl->slot_device_offset;
1082 dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n", __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot);
1084 /* Wait for exclusive access to hardware */
1085 down(&ctrl->crit_sect);
1088 rc = p_slot->hpc_ops->power_on_slot(p_slot);
1092 /* Wait for the command to complete */
1093 wait_for_ctrl_irq (ctrl);
1095 p_slot->hpc_ops->green_led_blink(p_slot);
1097 /* Wait for the command to complete */
1098 wait_for_ctrl_irq (ctrl);
1100 /* Done with exclusive hardware access */
1101 up(&ctrl->crit_sect);
1103 /* Wait for ~1 second */
1104 dbg("%s: before long_delay\n", __FUNCTION__);
1105 wait_for_ctrl_irq (ctrl);
1106 dbg("%s: afterlong_delay\n", __FUNCTION__);
1108 /* Make this to check for link training status */
1109 rc = p_slot->hpc_ops->check_lnk_status(ctrl);
1111 err("%s: Failed to check link status\n", __FUNCTION__);
1115 dbg("%s: func status = %x\n", __FUNCTION__, func->status);
1117 /* Check for a power fault */
1118 if (func->status == 0xFF) {
1119 /* power fault occurred, but it was benign */
1120 temp_register = 0xFFFFFFFF;
1121 dbg("%s: temp register set to %x by power fault\n", __FUNCTION__, temp_register);
1125 /* Get vendor/device ID u32 */
1126 rc = pci_bus_read_config_dword (ctrl->pci_dev->subordinate, PCI_DEVFN(func->device, func->function),
1127 PCI_VENDOR_ID, &temp_register);
1128 dbg("%s: pci_bus_read_config_dword returns %d\n", __FUNCTION__, rc);
1129 dbg("%s: temp_register is %x\n", __FUNCTION__, temp_register);
1132 /* Something's wrong here */
1133 temp_register = 0xFFFFFFFF;
1134 dbg("%s: temp register set to %x by error\n", __FUNCTION__, temp_register);
1136 /* Preset return code. It will be changed later if things go okay. */
1137 rc = NO_ADAPTER_PRESENT;
1140 /* All F's is an empty slot or an invalid board */
1141 if (temp_register != 0xFFFFFFFF) { /* Check for a board in the slot */
1142 res_lists.io_head = ctrl->io_head;
1143 res_lists.mem_head = ctrl->mem_head;
1144 res_lists.p_mem_head = ctrl->p_mem_head;
1145 res_lists.bus_head = ctrl->bus_head;
1146 res_lists.irqs = NULL;
1148 rc = configure_new_device(ctrl, func, 0, &res_lists, 0, 0);
1149 dbg("%s: back from configure_new_device\n", __FUNCTION__);
1151 ctrl->io_head = res_lists.io_head;
1152 ctrl->mem_head = res_lists.mem_head;
1153 ctrl->p_mem_head = res_lists.p_mem_head;
1154 ctrl->bus_head = res_lists.bus_head;
1156 pciehp_resource_sort_and_combine(&(ctrl->mem_head));
1157 pciehp_resource_sort_and_combine(&(ctrl->p_mem_head));
1158 pciehp_resource_sort_and_combine(&(ctrl->io_head));
1159 pciehp_resource_sort_and_combine(&(ctrl->bus_head));
1162 /* Wait for exclusive access to hardware */
1163 down(&ctrl->crit_sect);
1165 /* turn off slot, turn on Amber LED, turn off Green LED */
1166 retval = p_slot->hpc_ops->power_off_slot(p_slot);
1167 /* In PCI Express, just power off slot */
1169 err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);
1172 /* Wait for the command to complete */
1173 wait_for_ctrl_irq (ctrl);
1175 p_slot->hpc_ops->green_led_off(p_slot);
1177 /* Wait for the command to complete */
1178 wait_for_ctrl_irq (ctrl);
1180 /* turn on Amber LED */
1181 retval = p_slot->hpc_ops->set_attention_status(p_slot, 1);
1183 err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);
1186 /* Wait for the command to complete */
1187 wait_for_ctrl_irq (ctrl);
1189 /* Done with exclusive hardware access */
1190 up(&ctrl->crit_sect);
1194 pciehp_save_slot_config(ctrl, func);
1197 func->switch_save = 0x10;
1198 func->is_a_board = 0x01;
1200 /* next, we will instantiate the linux pci_dev structures
1201 * (with appropriate driver notification, if already present)
1205 new_func = pciehp_slot_find(ctrl->slot_bus, func->device, index++);
1206 if (new_func && !new_func->pci_dev) {
1207 dbg("%s:call pci_hp_configure_dev, func %x\n",
1208 __FUNCTION__, index);
1209 pciehp_configure_device(ctrl, new_func);
1213 /* Wait for exclusive access to hardware */
1214 down(&ctrl->crit_sect);
1216 p_slot->hpc_ops->green_led_on(p_slot);
1218 /* Wait for the command to complete */
1219 wait_for_ctrl_irq (ctrl);
1222 /* Done with exclusive hardware access */
1223 up(&ctrl->crit_sect);
1226 /* Wait for exclusive access to hardware */
1227 down(&ctrl->crit_sect);
1229 /* turn off slot, turn on Amber LED, turn off Green LED */
1230 retval = p_slot->hpc_ops->power_off_slot(p_slot);
1231 /* In PCI Express, just power off slot */
1233 err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);
1236 /* Wait for the command to complete */
1237 wait_for_ctrl_irq (ctrl);
1239 p_slot->hpc_ops->green_led_off(p_slot);
1241 /* Wait for the command to complete */
1242 wait_for_ctrl_irq (ctrl);
1244 /* turn on Amber LED */
1245 retval = p_slot->hpc_ops->set_attention_status(p_slot, 1);
1247 err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);
1250 /* Wait for the command to complete */
1251 wait_for_ctrl_irq (ctrl);
1253 /* Done with exclusive hardware access */
1254 up(&ctrl->crit_sect);
1263 * remove_board - Turns off slot and LED's
1266 static u32 remove_board(struct pci_func *func, struct controller *ctrl)
1273 struct resource_lists res_lists;
1274 struct pci_func *temp_func;
1275 struct slot *p_slot;
1280 if (pciehp_unconfigure_device(func))
1283 device = func->device;
1285 hp_slot = func->device - ctrl->slot_device_offset;
1286 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
1288 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
1290 if ((ctrl->add_support) &&
1291 !(func->bus_head || func->mem_head || func->p_mem_head || func->io_head)) {
1292 /* Here we check to see if we've saved any of the board's
1293 * resources already. If so, we'll skip the attempt to
1294 * determine what's being used.
1300 while ((temp_func = pciehp_slot_find(temp_func->bus, temp_func->device, index++))) {
1301 if (temp_func->bus_head || temp_func->mem_head
1302 || temp_func->p_mem_head || temp_func->io_head) {
1309 rc = pciehp_save_used_resources(ctrl, func, DISABLE_CARD);
1311 /* Change status to shutdown */
1312 if (func->is_a_board)
1313 func->status = 0x01;
1314 func->configured = 0;
1316 /* Wait for exclusive access to hardware */
1317 down(&ctrl->crit_sect);
1319 /* power off slot */
1320 rc = p_slot->hpc_ops->power_off_slot(p_slot);
1322 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
1325 /* Wait for the command to complete */
1326 wait_for_ctrl_irq (ctrl);
1328 /* turn off Green LED */
1329 p_slot->hpc_ops->green_led_off(p_slot);
1331 /* Wait for the command to complete */
1332 wait_for_ctrl_irq (ctrl);
1334 /* Done with exclusive hardware access */
1335 up(&ctrl->crit_sect);
1337 if (ctrl->add_support) {
1339 res_lists.io_head = ctrl->io_head;
1340 res_lists.mem_head = ctrl->mem_head;
1341 res_lists.p_mem_head = ctrl->p_mem_head;
1342 res_lists.bus_head = ctrl->bus_head;
1344 dbg("Returning resources to ctlr lists for (B/D/F) = (%#x/%#x/%#x)\n",
1345 func->bus, func->device, func->function);
1347 pciehp_return_board_resources(func, &res_lists);
1349 ctrl->io_head = res_lists.io_head;
1350 ctrl->mem_head = res_lists.mem_head;
1351 ctrl->p_mem_head = res_lists.p_mem_head;
1352 ctrl->bus_head = res_lists.bus_head;
1354 pciehp_resource_sort_and_combine(&(ctrl->mem_head));
1355 pciehp_resource_sort_and_combine(&(ctrl->p_mem_head));
1356 pciehp_resource_sort_and_combine(&(ctrl->io_head));
1357 pciehp_resource_sort_and_combine(&(ctrl->bus_head));
1359 if (is_bridge(func)) {
1360 dbg("PCI Bridge Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n",
1361 ctrl->seg, func->bus, func->device, func->function);
1362 bridge_slot_remove(func);
1364 dbg("PCI Function Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n",
1365 ctrl->seg, func->bus, func->device, func->function);
1368 func = pciehp_slot_find(ctrl->slot_bus, device, 0);
1371 /* Setup slot structure with entry for empty slot */
1372 func = pciehp_slot_create(ctrl->slot_bus);
1378 func->bus = ctrl->slot_bus;
1379 func->device = device;
1381 func->configured = 0;
1382 func->switch_save = 0x10;
1383 func->is_a_board = 0;
1390 static void pushbutton_helper_thread(unsigned long data)
1392 pushbutton_pending = data;
1394 up(&event_semaphore);
1399 * pciehp_pushbutton_thread
1401 * Scheduled procedure to handle blocking stuff for the pushbuttons
1402 * Handles all pending events and exits.
1405 static void pciehp_pushbutton_thread(unsigned long slot)
1407 struct slot *p_slot = (struct slot *) slot;
1411 pushbutton_pending = 0;
1414 dbg("%s: Error! slot NULL\n", __FUNCTION__);
1418 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1420 p_slot->state = POWEROFF_STATE;
1421 dbg("In power_down_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
1423 if (pciehp_disable_slot(p_slot)) {
1424 /* Wait for exclusive access to hardware */
1425 down(&p_slot->ctrl->crit_sect);
1427 /* Turn on the Attention LED */
1428 rc = p_slot->hpc_ops->set_attention_status(p_slot, 1);
1430 err("%s: Issue of Set Atten Indicator On command failed\n", __FUNCTION__);
1434 /* Wait for the command to complete */
1435 wait_for_ctrl_irq (p_slot->ctrl);
1437 /* Done with exclusive hardware access */
1438 up(&p_slot->ctrl->crit_sect);
1440 p_slot->state = STATIC_STATE;
1442 p_slot->state = POWERON_STATE;
1443 dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
1445 if (pciehp_enable_slot(p_slot)) {
1446 /* Wait for exclusive access to hardware */
1447 down(&p_slot->ctrl->crit_sect);
1449 /* Turn off the green LED */
1450 rc = p_slot->hpc_ops->set_attention_status(p_slot, 1);
1452 err("%s: Issue of Set Atten Indicator On command failed\n", __FUNCTION__);
1455 /* Wait for the command to complete */
1456 wait_for_ctrl_irq (p_slot->ctrl);
1458 p_slot->hpc_ops->green_led_off(p_slot);
1460 /* Wait for the command to complete */
1461 wait_for_ctrl_irq (p_slot->ctrl);
1463 /* Done with exclusive hardware access */
1464 up(&p_slot->ctrl->crit_sect);
1466 p_slot->state = STATIC_STATE;
1473 /* this is the main worker thread */
1474 static int event_thread(void* data)
1476 struct controller *ctrl;
1478 daemonize("pciehpd_event");
1483 dbg("!!!!event_thread sleeping\n");
1484 down_interruptible (&event_semaphore);
1485 dbg("event_thread woken finished = %d\n", event_finished);
1486 if (event_finished || signal_pending(current))
1489 if (pushbutton_pending)
1490 pciehp_pushbutton_thread(pushbutton_pending);
1492 for (ctrl = pciehp_ctrl_list; ctrl; ctrl=ctrl->next)
1493 interrupt_event_handler(ctrl);
1495 dbg("event_thread signals exit\n");
1500 int pciehp_event_start_thread(void)
1504 /* initialize our semaphores */
1505 init_MUTEX_LOCKED(&event_exit);
1508 init_MUTEX_LOCKED(&event_semaphore);
1509 pid = kernel_thread(event_thread, 0, 0);
1512 err ("Can't start up our event thread\n");
1515 dbg("Our event thread pid = %d\n", pid);
1520 void pciehp_event_stop_thread(void)
1523 dbg("event_thread finish command given\n");
1524 up(&event_semaphore);
1525 dbg("wait for event_thread to exit\n");
1530 static int update_slot_info(struct slot *slot)
1532 struct hotplug_slot_info *info;
1533 /* char buffer[SLOT_NAME_SIZE]; */
1536 info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
1540 /* make_slot_name (&buffer[0], SLOT_NAME_SIZE, slot); */
1542 slot->hpc_ops->get_power_status(slot, &(info->power_status));
1543 slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
1544 slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
1545 slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
1547 /* result = pci_hp_change_slot_info(buffer, info); */
1548 result = pci_hp_change_slot_info(slot->hotplug_slot, info);
1553 static void interrupt_event_handler(struct controller *ctrl)
1557 struct pci_func *func;
1560 struct slot *p_slot;
1565 for (loop = 0; loop < 10; loop++) {
1566 if (ctrl->event_queue[loop].event_type != 0) {
1567 hp_slot = ctrl->event_queue[loop].hp_slot;
1569 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
1571 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
1573 dbg("hp_slot %d, func %p, p_slot %p\n", hp_slot, func, p_slot);
1575 if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {
1576 dbg("button cancel\n");
1577 del_timer(&p_slot->task_event);
1579 switch (p_slot->state) {
1580 case BLINKINGOFF_STATE:
1581 /* Wait for exclusive access to hardware */
1582 down(&ctrl->crit_sect);
1584 p_slot->hpc_ops->green_led_on(p_slot);
1585 /* Wait for the command to complete */
1586 wait_for_ctrl_irq (ctrl);
1588 p_slot->hpc_ops->set_attention_status(p_slot, 0);
1590 /* Wait for the command to complete */
1591 wait_for_ctrl_irq (ctrl);
1593 /* Done with exclusive hardware access */
1594 up(&ctrl->crit_sect);
1596 case BLINKINGON_STATE:
1597 /* Wait for exclusive access to hardware */
1598 down(&ctrl->crit_sect);
1600 p_slot->hpc_ops->green_led_off(p_slot);
1601 /* Wait for the command to complete */
1602 wait_for_ctrl_irq (ctrl);
1604 p_slot->hpc_ops->set_attention_status(p_slot, 0);
1605 /* Wait for the command to complete */
1606 wait_for_ctrl_irq (ctrl);
1608 /* Done with exclusive hardware access */
1609 up(&ctrl->crit_sect);
1613 warn("Not a valid state\n");
1616 info(msg_button_cancel, p_slot->number);
1617 p_slot->state = STATIC_STATE;
1619 /* ***********Button Pressed (No action on 1st press...) */
1620 else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {
1621 dbg("Button pressed\n");
1623 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1626 dbg("slot is on\n");
1627 p_slot->state = BLINKINGOFF_STATE;
1628 info(msg_button_off, p_slot->number);
1631 dbg("slot is off\n");
1632 p_slot->state = BLINKINGON_STATE;
1633 info(msg_button_on, p_slot->number);
1636 /* Wait for exclusive access to hardware */
1637 down(&ctrl->crit_sect);
1639 /* blink green LED and turn off amber */
1640 p_slot->hpc_ops->green_led_blink(p_slot);
1641 /* Wait for the command to complete */
1642 wait_for_ctrl_irq (ctrl);
1644 p_slot->hpc_ops->set_attention_status(p_slot, 0);
1646 /* Wait for the command to complete */
1647 wait_for_ctrl_irq (ctrl);
1649 /* Done with exclusive hardware access */
1650 up(&ctrl->crit_sect);
1652 init_timer(&p_slot->task_event);
1653 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
1654 p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;
1655 p_slot->task_event.data = (unsigned long) p_slot;
1657 dbg("add_timer p_slot = %p\n", (void *) p_slot);
1658 add_timer(&p_slot->task_event);
1660 /***********POWER FAULT********************/
1661 else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
1662 dbg("power fault\n");
1663 /* Wait for exclusive access to hardware */
1664 down(&ctrl->crit_sect);
1666 p_slot->hpc_ops->set_attention_status(p_slot, 1);
1667 p_slot->hpc_ops->green_led_off(p_slot);
1669 /* Done with exclusive hardware access */
1670 up(&ctrl->crit_sect);
1672 /* refresh notification */
1674 update_slot_info(p_slot);
1677 ctrl->event_queue[loop].event_type = 0;
1681 } /* End of FOR loop */
1686 int pciehp_enable_slot(struct slot *p_slot)
1690 struct pci_func *func;
1692 func = pciehp_slot_find(p_slot->bus, p_slot->device, 0);
1694 dbg("%s: Error! slot NULL\n", __FUNCTION__);
1698 /* Check to see if (latch closed, card present, power off) */
1699 down(&p_slot->ctrl->crit_sect);
1700 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
1701 if (rc || !getstatus) {
1702 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
1703 up(&p_slot->ctrl->crit_sect);
1707 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1708 if (rc || getstatus) {
1709 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
1710 up(&p_slot->ctrl->crit_sect);
1714 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1715 if (rc || getstatus) {
1716 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
1717 up(&p_slot->ctrl->crit_sect);
1720 up(&p_slot->ctrl->crit_sect);
1724 func = pciehp_slot_create(p_slot->bus);
1728 func->bus = p_slot->bus;
1729 func->device = p_slot->device;
1731 func->configured = 0;
1732 func->is_a_board = 1;
1734 /* We have to save the presence info for these slots */
1735 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
1736 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1737 func->switch_save = !getstatus? 0x10:0;
1739 rc = board_added(func, p_slot->ctrl);
1741 if (is_bridge(func))
1742 bridge_slot_remove(func);
1746 /* Setup slot structure with entry for empty slot */
1747 func = pciehp_slot_create(p_slot->bus);
1749 return 1; /* Out of memory */
1751 func->bus = p_slot->bus;
1752 func->device = p_slot->device;
1754 func->configured = 0;
1755 func->is_a_board = 1;
1757 /* We have to save the presence info for these slots */
1758 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
1759 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1760 func->switch_save = !getstatus? 0x10:0;
1764 update_slot_info(p_slot);
1770 int pciehp_disable_slot(struct slot *p_slot)
1772 u8 class_code, header_type, BCR;
1778 struct pci_bus *pci_bus = p_slot->ctrl->pci_dev->subordinate;
1779 struct pci_func *func;
1784 /* Check to see if (latch closed, card present, power on) */
1785 down(&p_slot->ctrl->crit_sect);
1787 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
1788 if (ret || !getstatus) {
1789 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
1790 up(&p_slot->ctrl->crit_sect);
1794 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1795 if (ret || getstatus) {
1796 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
1797 up(&p_slot->ctrl->crit_sect);
1801 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1802 if (ret || !getstatus) {
1803 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
1804 up(&p_slot->ctrl->crit_sect);
1807 up(&p_slot->ctrl->crit_sect);
1809 func = pciehp_slot_find(p_slot->bus, p_slot->device, index++);
1811 /* Make sure there are no video controllers here
1812 * for all func of p_slot
1814 while (func && !rc) {
1815 pci_bus->number = func->bus;
1816 devfn = PCI_DEVFN(func->device, func->function);
1818 /* Check the Class Code */
1819 rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
1823 if (class_code == PCI_BASE_CLASS_DISPLAY) {
1824 /* Display/Video adapter (not supported) */
1825 rc = REMOVE_NOT_SUPPORTED;
1827 /* See if it's a bridge */
1828 rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &header_type);
1832 /* If it's a bridge, check the VGA Enable bit */
1833 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
1834 rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_BRIDGE_CONTROL, &BCR);
1838 /* If the VGA Enable bit is set, remove isn't supported */
1839 if (BCR & PCI_BRIDGE_CTL_VGA) {
1840 rc = REMOVE_NOT_SUPPORTED;
1845 func = pciehp_slot_find(p_slot->bus, p_slot->device, index++);
1848 func = pciehp_slot_find(p_slot->bus, p_slot->device, 0);
1849 if ((func != NULL) && !rc) {
1850 rc = remove_board(func, p_slot->ctrl);
1855 update_slot_info(p_slot);
1862 * configure_new_device - Configures the PCI header information of one board.
1864 * @ctrl: pointer to controller structure
1865 * @func: pointer to function structure
1866 * @behind_bridge: 1 if this is a recursive call, 0 if not
1867 * @resources: pointer to set of resource lists
1869 * Returns 0 if success
1872 static u32 configure_new_device(struct controller * ctrl, struct pci_func * func,
1873 u8 behind_bridge, struct resource_lists * resources, u8 bridge_bus, u8 bridge_dev)
1875 u8 temp_byte, function, max_functions, stop_it;
1878 struct pci_func *new_slot;
1879 struct pci_bus lpci_bus, *pci_bus;
1884 dbg("%s\n", __FUNCTION__);
1885 memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));
1886 pci_bus = &lpci_bus;
1887 pci_bus->number = func->bus;
1889 /* Check for Multi-function device */
1890 rc = pci_bus_read_config_byte(pci_bus, PCI_DEVFN(func->device, func->function), 0x0E, &temp_byte);
1892 dbg("%s: rc = %d\n", __FUNCTION__, rc);
1896 if (temp_byte & 0x80) /* Multi-function device */
1904 rc = configure_new_function(ctrl, new_slot, behind_bridge,
1905 resources, bridge_bus, bridge_dev);
1908 dbg("configure_new_function failed: %d\n", rc);
1912 new_slot = pciehp_slot_find(new_slot->bus,
1913 new_slot->device, index++);
1916 pciehp_return_board_resources(new_slot,
1927 /* The following loop skips to the next present function
1928 * and creates a board structure
1931 while ((function < max_functions) && (!stop_it)) {
1932 pci_bus_read_config_dword(pci_bus, PCI_DEVFN(func->device, function), 0x00, &ID);
1934 if (ID == 0xFFFFFFFF) { /* There's nothing there. */
1936 } else { /* There's something there */
1937 /* Setup slot structure. */
1938 new_slot = pciehp_slot_create(func->bus);
1940 if (new_slot == NULL) {
1945 new_slot->bus = func->bus;
1946 new_slot->device = func->device;
1947 new_slot->function = function;
1948 new_slot->is_a_board = 1;
1949 new_slot->status = 0;
1955 } while (function < max_functions);
1956 dbg("returning from %s\n", __FUNCTION__);
1962 * Configuration logic that involves the hotplug data structures and
1967 * configure_bridge: fill bridge's registers, either configure or disable it.
1970 configure_bridge(struct pci_bus *pci_bus, unsigned int devfn,
1971 struct pci_resource *mem_node,
1972 struct pci_resource **hold_mem_node,
1973 int base_addr, int limit_addr)
1979 memcpy(*hold_mem_node, mem_node, sizeof(struct pci_resource));
1980 mem_node->next = NULL;
1982 /* set Mem base and Limit registers */
1983 RES_CHECK(mem_node->base, 16);
1984 temp_word = (u16)(mem_node->base >> 16);
1985 rc = pci_bus_write_config_word(pci_bus, devfn, base_addr, temp_word);
1987 RES_CHECK(mem_node->base + mem_node->length - 1, 16);
1988 temp_word = (u16)((mem_node->base + mem_node->length - 1) >> 16);
1989 rc = pci_bus_write_config_word(pci_bus, devfn, limit_addr, temp_word);
1992 rc = pci_bus_write_config_word(pci_bus, devfn, base_addr, temp_word);
1995 rc = pci_bus_write_config_word(pci_bus, devfn, limit_addr, temp_word);
1997 kfree(*hold_mem_node);
1998 *hold_mem_node = NULL;
2004 configure_new_bridge(struct controller *ctrl, struct pci_func *func,
2005 u8 behind_bridge, struct resource_lists *resources,
2006 struct pci_bus *pci_bus)
2015 struct pci_resource *mem_node;
2016 struct pci_resource *p_mem_node;
2017 struct pci_resource *io_node;
2018 struct pci_resource *bus_node;
2019 struct pci_resource *hold_mem_node;
2020 struct pci_resource *hold_p_mem_node;
2021 struct pci_resource *hold_IO_node;
2022 struct pci_resource *hold_bus_node;
2023 struct irq_mapping irqs;
2024 struct pci_func *new_slot;
2025 struct resource_lists temp_resources;
2027 devfn = PCI_DEVFN(func->device, func->function);
2029 /* set Primary bus */
2030 dbg("set Primary bus = 0x%x\n", func->bus);
2031 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_PRIMARY_BUS, func->bus);
2035 /* find range of busses to use */
2036 bus_node = get_max_resource(&resources->bus_head, 1L);
2038 /* If we don't have any busses to allocate, we can't continue */
2040 err("Got NO bus resource to use\n");
2043 dbg("Got ranges of buses to use: base:len=0x%x:%x\n", bus_node->base, bus_node->length);
2045 /* set Secondary bus */
2046 temp_byte = (u8)bus_node->base;
2047 dbg("set Secondary bus = 0x%x\n", temp_byte);
2048 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SECONDARY_BUS, temp_byte);
2052 /* set subordinate bus */
2053 temp_byte = (u8)(bus_node->base + bus_node->length - 1);
2054 dbg("set subordinate bus = 0x%x\n", temp_byte);
2055 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);
2059 /* Set HP parameters (Cache Line Size, Latency Timer) */
2060 rc = pciehprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_BRIDGE);
2064 /* Setup the IO, memory, and prefetchable windows */
2066 io_node = get_max_resource(&(resources->io_head), 0x1000L);
2068 dbg("io_node(base, len, next) (%x, %x, %p)\n", io_node->base,
2069 io_node->length, io_node->next);
2072 mem_node = get_max_resource(&(resources->mem_head), 0x100000L);
2074 dbg("mem_node(base, len, next) (%x, %x, %p)\n", mem_node->base,
2075 mem_node->length, mem_node->next);
2078 if (resources->p_mem_head)
2079 p_mem_node = get_max_resource(&(resources->p_mem_head), 0x100000L);
2082 * In some platform implementation, MEM and PMEM are not
2083 * distinguished, and hence ACPI _CRS has only MEM entries
2084 * for both MEM and PMEM.
2086 dbg("using MEM for PMEM\n");
2087 p_mem_node = get_max_resource(&(resources->mem_head), 0x100000L);
2090 dbg("p_mem_node(base, len, next) (%x, %x, %p)\n", p_mem_node->base,
2091 p_mem_node->length, p_mem_node->next);
2094 /* set up the IRQ info */
2095 if (!resources->irqs) {
2096 irqs.barber_pole = 0;
2097 irqs.interrupt[0] = 0;
2098 irqs.interrupt[1] = 0;
2099 irqs.interrupt[2] = 0;
2100 irqs.interrupt[3] = 0;
2103 irqs.barber_pole = resources->irqs->barber_pole;
2104 irqs.interrupt[0] = resources->irqs->interrupt[0];
2105 irqs.interrupt[1] = resources->irqs->interrupt[1];
2106 irqs.interrupt[2] = resources->irqs->interrupt[2];
2107 irqs.interrupt[3] = resources->irqs->interrupt[3];
2108 irqs.valid_INT = resources->irqs->valid_INT;
2111 /* set up resource lists that are now aligned on top and bottom
2112 * for anything behind the bridge.
2114 temp_resources.bus_head = bus_node;
2115 temp_resources.io_head = io_node;
2116 temp_resources.mem_head = mem_node;
2117 temp_resources.p_mem_head = p_mem_node;
2118 temp_resources.irqs = &irqs;
2120 /* Make copies of the nodes we are going to pass down so that
2121 * if there is a problem,we can just use these to free resources
2123 hold_bus_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2124 hold_IO_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2125 hold_mem_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2126 hold_p_mem_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2128 if (!hold_bus_node || !hold_IO_node || !hold_mem_node || !hold_p_mem_node) {
2129 kfree(hold_bus_node);
2130 kfree(hold_IO_node);
2131 kfree(hold_mem_node);
2132 kfree(hold_p_mem_node);
2137 memcpy(hold_bus_node, bus_node, sizeof(struct pci_resource));
2139 bus_node->base += 1;
2140 bus_node->length -= 1;
2141 bus_node->next = NULL;
2143 /* If we have IO resources copy them and fill in the bridge's
2144 * IO range registers
2147 memcpy(hold_IO_node, io_node, sizeof(struct pci_resource));
2148 io_node->next = NULL;
2150 /* set IO base and Limit registers */
2151 RES_CHECK(io_node->base, 8);
2152 temp_byte = (u8)(io_node->base >> 8);
2153 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_BASE, temp_byte);
2155 RES_CHECK(io_node->base + io_node->length - 1, 8);
2156 temp_byte = (u8)((io_node->base + io_node->length - 1) >> 8);
2157 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2159 kfree(hold_IO_node);
2160 hold_IO_node = NULL;
2163 /* If we have memory resources copy them and fill in the bridge's
2164 * memory range registers. Otherwise, fill in the range
2165 * registers with values that disable them.
2167 rc = configure_bridge(pci_bus, devfn, mem_node, &hold_mem_node,
2168 PCI_MEMORY_BASE, PCI_MEMORY_LIMIT);
2170 /* If we have prefetchable memory resources copy them and
2171 * fill in the bridge's memory range registers. Otherwise,
2172 * fill in the range registers with values that disable them.
2174 rc = configure_bridge(pci_bus, devfn, p_mem_node, &hold_p_mem_node,
2175 PCI_PREF_MEMORY_BASE, PCI_PREF_MEMORY_LIMIT);
2177 /* Adjust this to compensate for extra adjustment in first loop */
2182 /* Here we actually find the devices and configure them */
2183 for (device = 0; (device <= 0x1F) && !rc; device++) {
2184 irqs.barber_pole = (irqs.barber_pole + 1) & 0x03;
2187 pci_bus->number = hold_bus_node->base;
2188 pci_bus_read_config_dword (pci_bus, PCI_DEVFN(device, 0), PCI_VENDOR_ID, &ID);
2189 pci_bus->number = func->bus;
2191 if (ID != 0xFFFFFFFF) { /* device Present */
2192 /* Setup slot structure. */
2193 new_slot = pciehp_slot_create(hold_bus_node->base);
2195 if (new_slot == NULL) {
2201 new_slot->bus = hold_bus_node->base;
2202 new_slot->device = device;
2203 new_slot->function = 0;
2204 new_slot->is_a_board = 1;
2205 new_slot->status = 0;
2207 rc = configure_new_device(ctrl, new_slot, 1,
2208 &temp_resources, func->bus,
2210 dbg("configure_new_device rc=0x%x\n",rc);
2211 } /* End of IF (device in slot?) */
2212 } /* End of FOR loop */
2215 pciehp_destroy_resource_list(&temp_resources);
2217 return_resource(&(resources->bus_head), hold_bus_node);
2218 return_resource(&(resources->io_head), hold_IO_node);
2219 return_resource(&(resources->mem_head), hold_mem_node);
2220 return_resource(&(resources->p_mem_head), hold_p_mem_node);
2224 /* save the interrupt routing information */
2225 if (resources->irqs) {
2226 resources->irqs->interrupt[0] = irqs.interrupt[0];
2227 resources->irqs->interrupt[1] = irqs.interrupt[1];
2228 resources->irqs->interrupt[2] = irqs.interrupt[2];
2229 resources->irqs->interrupt[3] = irqs.interrupt[3];
2230 resources->irqs->valid_INT = irqs.valid_INT;
2231 } else if (!behind_bridge) {
2232 /* We need to hook up the interrupts here */
2233 for (cloop = 0; cloop < 4; cloop++) {
2234 if (irqs.valid_INT & (0x01 << cloop)) {
2235 rc = pciehp_set_irq(func->bus, func->device,
2236 0x0A + cloop, irqs.interrupt[cloop]);
2238 pciehp_destroy_resource_list (&temp_resources);
2239 return_resource(&(resources->bus_head), hold_bus_node);
2240 return_resource(&(resources->io_head), hold_IO_node);
2241 return_resource(&(resources->mem_head), hold_mem_node);
2242 return_resource(&(resources->p_mem_head), hold_p_mem_node);
2246 } /* end of for loop */
2249 /* Return unused bus resources
2250 * First use the temporary node to store information for the board
2252 if (hold_bus_node && bus_node && temp_resources.bus_head) {
2253 hold_bus_node->length = bus_node->base - hold_bus_node->base;
2255 hold_bus_node->next = func->bus_head;
2256 func->bus_head = hold_bus_node;
2258 temp_byte = (u8)(temp_resources.bus_head->base - 1);
2260 /* set subordinate bus */
2261 dbg("re-set subordinate bus = 0x%x\n", temp_byte);
2262 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);
2264 if (temp_resources.bus_head->length == 0) {
2265 kfree(temp_resources.bus_head);
2266 temp_resources.bus_head = NULL;
2268 dbg("return bus res of b:d(0x%x:%x) base:len(0x%x:%x)\n",
2269 func->bus, func->device, temp_resources.bus_head->base, temp_resources.bus_head->length);
2270 return_resource(&(resources->bus_head), temp_resources.bus_head);
2274 /* If we have IO space available and there is some left,
2275 * return the unused portion
2277 if (hold_IO_node && temp_resources.io_head) {
2278 io_node = do_pre_bridge_resource_split(&(temp_resources.io_head),
2279 &hold_IO_node, 0x1000);
2281 /* Check if we were able to split something off */
2283 hold_IO_node->base = io_node->base + io_node->length;
2285 RES_CHECK(hold_IO_node->base, 8);
2286 temp_byte = (u8)((hold_IO_node->base) >> 8);
2287 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_BASE, temp_byte);
2289 return_resource(&(resources->io_head), io_node);
2292 io_node = do_bridge_resource_split(&(temp_resources.io_head), 0x1000);
2294 /* Check if we were able to split something off */
2296 /* First use the temporary node to store information for the board */
2297 hold_IO_node->length = io_node->base - hold_IO_node->base;
2299 /* If we used any, add it to the board's list */
2300 if (hold_IO_node->length) {
2301 hold_IO_node->next = func->io_head;
2302 func->io_head = hold_IO_node;
2304 RES_CHECK(io_node->base - 1, 8);
2305 temp_byte = (u8)((io_node->base - 1) >> 8);
2306 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2308 return_resource(&(resources->io_head), io_node);
2310 /* it doesn't need any IO */
2312 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2314 return_resource(&(resources->io_head), io_node);
2315 kfree(hold_IO_node);
2318 /* it used most of the range */
2319 hold_IO_node->next = func->io_head;
2320 func->io_head = hold_IO_node;
2322 } else if (hold_IO_node) {
2323 /* it used the whole range */
2324 hold_IO_node->next = func->io_head;
2325 func->io_head = hold_IO_node;
2328 /* If we have memory space available and there is some left,
2329 * return the unused portion
2331 if (hold_mem_node && temp_resources.mem_head) {
2332 mem_node = do_pre_bridge_resource_split(&(temp_resources.mem_head), &hold_mem_node, 0x100000L);
2334 /* Check if we were able to split something off */
2336 hold_mem_node->base = mem_node->base + mem_node->length;
2338 RES_CHECK(hold_mem_node->base, 16);
2339 temp_word = (u16)((hold_mem_node->base) >> 16);
2340 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_BASE, temp_word);
2342 return_resource(&(resources->mem_head), mem_node);
2345 mem_node = do_bridge_resource_split(&(temp_resources.mem_head), 0x100000L);
2347 /* Check if we were able to split something off */
2349 /* First use the temporary node to store information for the board */
2350 hold_mem_node->length = mem_node->base - hold_mem_node->base;
2352 if (hold_mem_node->length) {
2353 hold_mem_node->next = func->mem_head;
2354 func->mem_head = hold_mem_node;
2356 /* configure end address */
2357 RES_CHECK(mem_node->base - 1, 16);
2358 temp_word = (u16)((mem_node->base - 1) >> 16);
2359 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2361 /* Return unused resources to the pool */
2362 return_resource(&(resources->mem_head), mem_node);
2364 /* it doesn't need any Mem */
2366 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2368 return_resource(&(resources->mem_head), mem_node);
2369 kfree(hold_mem_node);
2372 /* it used most of the range */
2373 hold_mem_node->next = func->mem_head;
2374 func->mem_head = hold_mem_node;
2376 } else if (hold_mem_node) {
2377 /* it used the whole range */
2378 hold_mem_node->next = func->mem_head;
2379 func->mem_head = hold_mem_node;
2382 /* If we have prefetchable memory space available and there is some
2383 * left at the end, return the unused portion
2385 if (hold_p_mem_node && temp_resources.p_mem_head) {
2386 p_mem_node = do_pre_bridge_resource_split(&(temp_resources.p_mem_head),
2387 &hold_p_mem_node, 0x100000L);
2389 /* Check if we were able to split something off */
2391 hold_p_mem_node->base = p_mem_node->base + p_mem_node->length;
2393 RES_CHECK(hold_p_mem_node->base, 16);
2394 temp_word = (u16)((hold_p_mem_node->base) >> 16);
2395 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
2397 return_resource(&(resources->p_mem_head), p_mem_node);
2400 p_mem_node = do_bridge_resource_split(&(temp_resources.p_mem_head), 0x100000L);
2402 /* Check if we were able to split something off */
2404 /* First use the temporary node to store information for the board */
2405 hold_p_mem_node->length = p_mem_node->base - hold_p_mem_node->base;
2407 /* If we used any, add it to the board's list */
2408 if (hold_p_mem_node->length) {
2409 hold_p_mem_node->next = func->p_mem_head;
2410 func->p_mem_head = hold_p_mem_node;
2412 RES_CHECK(p_mem_node->base - 1, 16);
2413 temp_word = (u16)((p_mem_node->base - 1) >> 16);
2414 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2416 return_resource(&(resources->p_mem_head), p_mem_node);
2418 /* it doesn't need any PMem */
2420 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2422 return_resource(&(resources->p_mem_head), p_mem_node);
2423 kfree(hold_p_mem_node);
2426 /* it used the most of the range */
2427 hold_p_mem_node->next = func->p_mem_head;
2428 func->p_mem_head = hold_p_mem_node;
2430 } else if (hold_p_mem_node) {
2431 /* it used the whole range */
2432 hold_p_mem_node->next = func->p_mem_head;
2433 func->p_mem_head = hold_p_mem_node;
2436 /* We should be configuring an IRQ and the bridge's base address
2437 * registers if it needs them. Although we have never seen such
2441 pciehprm_enable_card(ctrl, func, PCI_HEADER_TYPE_BRIDGE);
2443 dbg("PCI Bridge Hot-Added s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, func->device, func->function);
2449 * configure_new_function - Configures the PCI header information of one device
2451 * @ctrl: pointer to controller structure
2452 * @func: pointer to function structure
2453 * @behind_bridge: 1 if this is a recursive call, 0 if not
2454 * @resources: pointer to set of resource lists
2456 * Calls itself recursively for bridged devices.
2457 * Returns 0 if success
2461 configure_new_function(struct controller *ctrl, struct pci_func *func,
2462 u8 behind_bridge, struct resource_lists *resources,
2463 u8 bridge_bus, u8 bridge_dev)
2473 struct pci_resource *mem_node;
2474 struct pci_resource *io_node;
2475 struct pci_bus lpci_bus, *pci_bus;
2477 memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));
2478 pci_bus = &lpci_bus;
2479 pci_bus->number = func->bus;
2480 devfn = PCI_DEVFN(func->device, func->function);
2482 /* Check for Bridge */
2483 rc = pci_bus_read_config_byte(pci_bus, devfn, PCI_HEADER_TYPE, &temp_byte);
2486 dbg("%s: bus %x dev %x func %x temp_byte = %x\n", __FUNCTION__,
2487 func->bus, func->device, func->function, temp_byte);
2489 if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { /* PCI-PCI Bridge */
2490 rc = configure_new_bridge(ctrl, func, behind_bridge, resources,
2495 } else if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_NORMAL) {
2496 /* Standard device */
2498 rc = pci_bus_read_config_byte(pci_bus, devfn, 0x0B, &class_code);
2500 if (class_code == PCI_BASE_CLASS_DISPLAY)
2501 return DEVICE_TYPE_NOT_SUPPORTED;
2503 /* Figure out IO and memory needs */
2504 for (cloop = PCI_BASE_ADDRESS_0; cloop <= PCI_BASE_ADDRESS_5; cloop += 4) {
2505 temp_register = 0xFFFFFFFF;
2507 rc = pci_bus_write_config_dword (pci_bus, devfn, cloop, temp_register);
2508 rc = pci_bus_read_config_dword(pci_bus, devfn, cloop, &temp_register);
2509 dbg("Bar[%x]=0x%x on bus:dev:func(0x%x:%x:%x)\n", cloop, temp_register,
2510 func->bus, func->device, func->function);
2516 if (temp_register & PCI_BASE_ADDRESS_SPACE_IO) {
2519 /* set base = amount of IO space */
2520 base = temp_register & 0xFFFFFFFC;
2523 dbg("NEED IO length(0x%x)\n", base);
2524 io_node = get_io_resource(&(resources->io_head),(ulong)base);
2526 /* allocate the resource to the board */
2528 dbg("Got IO base=0x%x(length=0x%x)\n", io_node->base, io_node->length);
2529 base = (u32)io_node->base;
2530 io_node->next = func->io_head;
2531 func->io_head = io_node;
2533 err("Got NO IO resource(length=0x%x)\n", base);
2536 } else { /* map MEM */
2537 int prefetchable = 1;
2538 struct pci_resource **res_node = &func->p_mem_head;
2539 char *res_type_str = "PMEM";
2542 if (!(temp_register & PCI_BASE_ADDRESS_MEM_PREFETCH)) {
2544 res_node = &func->mem_head;
2548 base = temp_register & 0xFFFFFFF0;
2551 switch (temp_register & PCI_BASE_ADDRESS_MEM_TYPE_MASK) {
2552 case PCI_BASE_ADDRESS_MEM_TYPE_32:
2553 dbg("NEED 32 %s bar=0x%x(length=0x%x)\n", res_type_str, temp_register, base);
2555 if (prefetchable && resources->p_mem_head)
2556 mem_node=get_resource(&(resources->p_mem_head), (ulong)base);
2559 dbg("using MEM for PMEM\n");
2560 mem_node = get_resource(&(resources->mem_head), (ulong)base);
2563 /* allocate the resource to the board */
2565 base = (u32)mem_node->base;
2566 mem_node->next = *res_node;
2567 *res_node = mem_node;
2568 dbg("Got 32 %s base=0x%x(length=0x%x)\n", res_type_str, mem_node->base,
2571 err("Got NO 32 %s resource(length=0x%x)\n", res_type_str, base);
2575 case PCI_BASE_ADDRESS_MEM_TYPE_64:
2576 rc = pci_bus_read_config_dword(pci_bus, devfn, cloop+4, &temp_register2);
2577 dbg("NEED 64 %s bar=0x%x:%x(length=0x%x)\n", res_type_str, temp_register2,
2578 temp_register, base);
2580 if (prefetchable && resources->p_mem_head)
2581 mem_node = get_resource(&(resources->p_mem_head), (ulong)base);
2584 dbg("using MEM for PMEM\n");
2585 mem_node = get_resource(&(resources->mem_head), (ulong)base);
2588 /* allocate the resource to the board */
2590 base64 = mem_node->base;
2591 mem_node->next = *res_node;
2592 *res_node = mem_node;
2593 dbg("Got 64 %s base=0x%x:%x(length=%x)\n", res_type_str, (u32)(base64 >> 32),
2594 (u32)base64, mem_node->length);
2596 err("Got NO 64 %s resource(length=0x%x)\n", res_type_str, base);
2601 dbg("reserved BAR type=0x%x\n", temp_register);
2608 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, (u32)base64);
2613 dbg("%s: high dword of base64(0x%x) set to 0\n", __FUNCTION__, (u32)base64);
2617 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, (u32)base64);
2619 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, base);
2621 } /* End of base register loop */
2623 /* disable ROM base Address */
2625 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_ROM_ADDRESS, temp_word);
2627 /* Set HP parameters (Cache Line Size, Latency Timer) */
2628 rc = pciehprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_NORMAL);
2632 pciehprm_enable_card(ctrl, func, PCI_HEADER_TYPE_NORMAL);
2634 dbg("PCI function Hot-Added s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, func->device,
2636 } /* End of Not-A-Bridge else */
2638 /* It's some strange type of PCI adapter (Cardbus?) */
2639 return DEVICE_TYPE_NOT_SUPPORTED;
2642 func->configured = 1;