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 */
257 * Sorts nodes on the list by their length.
261 static int sort_by_size(struct pci_resource **head)
263 struct pci_resource *current_res;
264 struct pci_resource *next_res;
265 int out_of_order = 1;
270 if (!((*head)->next))
273 while (out_of_order) {
276 /* Special case for swapping list head */
277 if (((*head)->next) &&
278 ((*head)->length > (*head)->next->length)) {
281 *head = (*head)->next;
282 current_res->next = (*head)->next;
283 (*head)->next = current_res;
288 while (current_res->next && current_res->next->next) {
289 if (current_res->next->length > current_res->next->next->length) {
291 next_res = current_res->next;
292 current_res->next = current_res->next->next;
293 current_res = current_res->next;
294 next_res->next = current_res->next;
295 current_res->next = next_res;
297 current_res = current_res->next;
299 } /* End of out_of_order loop */
308 * Sorts nodes on the list by their length.
312 static int sort_by_max_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 * do_pre_bridge_resource_split
359 * Returns zero or one node of resources that aren't in use
362 static struct pci_resource *do_pre_bridge_resource_split (struct pci_resource **head, struct pci_resource **orig_head, u32 alignment)
364 struct pci_resource *prevnode = NULL;
365 struct pci_resource *node;
366 struct pci_resource *split_node;
369 dbg("do_pre_bridge_resource_split\n");
371 if (!(*head) || !(*orig_head))
374 rc = pciehp_resource_sort_and_combine(head);
379 if ((*head)->base != (*orig_head)->base)
382 if ((*head)->length == (*orig_head)->length)
386 /* If we got here, there the bridge requires some of the resource, but
387 * we may be able to split some off of the front
391 if (node->length & (alignment -1)) {
392 /* this one isn't an aligned length, so we'll make a new entry
395 split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
400 temp_dword = (node->length | (alignment-1)) + 1 - alignment;
402 split_node->base = node->base;
403 split_node->length = temp_dword;
405 node->length -= temp_dword;
406 node->base += split_node->length;
408 /* Put it in the list */
410 split_node->next = node;
413 if (node->length < alignment) {
423 while (prevnode->next != node)
424 prevnode = prevnode->next;
426 prevnode->next = node->next;
435 * do_bridge_resource_split
437 * Returns zero or one node of resources that aren't in use
440 static struct pci_resource *do_bridge_resource_split (struct pci_resource **head, u32 alignment)
442 struct pci_resource *prevnode = NULL;
443 struct pci_resource *node;
450 rc = pciehp_resource_sort_and_combine(head);
463 if (node->length < alignment) {
468 if (node->base & (alignment - 1)) {
469 /* Short circuit if adjusted size is too small */
470 temp_dword = (node->base | (alignment-1)) + 1;
471 if ((node->length - (temp_dword - node->base)) < alignment) {
476 node->length -= (temp_dword - node->base);
477 node->base = temp_dword;
480 if (node->length & (alignment - 1)) {
481 /* There's stuff in use after this node */
493 * this function sorts the resource list by size and then
494 * returns the first node of "size" length that is not in the
495 * ISA aliasing window. If it finds a node larger than "size"
496 * it will split it up.
498 * size must be a power of two.
500 static struct pci_resource *get_io_resource (struct pci_resource **head, u32 size)
502 struct pci_resource *prevnode;
503 struct pci_resource *node;
504 struct pci_resource *split_node = NULL;
510 if ( pciehp_resource_sort_and_combine(head) )
513 if ( sort_by_size(head) )
516 for (node = *head; node; node = node->next) {
517 if (node->length < size)
520 if (node->base & (size - 1)) {
521 /* this one isn't base aligned properly
522 so we'll make a new entry and split it up */
523 temp_dword = (node->base | (size-1)) + 1;
525 /*/ Short circuit if adjusted size is too small */
526 if ((node->length - (temp_dword - node->base)) < size)
529 split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
534 split_node->base = node->base;
535 split_node->length = temp_dword - node->base;
536 node->base = temp_dword;
537 node->length -= split_node->length;
539 /* Put it in the list */
540 split_node->next = node->next;
541 node->next = split_node;
542 } /* End of non-aligned base */
544 /* Don't need to check if too small since we already did */
545 if (node->length > size) {
546 /* this one is longer than we need
547 so we'll make a new entry and split it up */
548 split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
553 split_node->base = node->base + size;
554 split_node->length = node->length - size;
557 /* Put it in the list */
558 split_node->next = node->next;
559 node->next = split_node;
560 } /* End of too big on top end */
562 /* For IO make sure it's not in the ISA aliasing space */
563 if (node->base & 0x300L)
566 /* If we got here, then it is the right size
567 Now take it out of the list */
572 while (prevnode->next != node)
573 prevnode = prevnode->next;
575 prevnode->next = node->next;
589 * Gets the largest node that is at least "size" big from the
590 * list pointed to by head. It aligns the node on top and bottom
591 * to "size" alignment before returning it.
592 * J.I. modified to put max size limits of; 64M->32M->16M->8M->4M->1M
593 * This is needed to avoid allocating entire ACPI _CRS res to one child bridge/slot.
595 static struct pci_resource *get_max_resource (struct pci_resource **head, u32 size)
597 struct pci_resource *max;
598 struct pci_resource *temp;
599 struct pci_resource *split_node;
601 u32 max_size[] = { 0x4000000, 0x2000000, 0x1000000, 0x0800000, 0x0400000, 0x0200000, 0x0100000, 0x00 };
607 if (pciehp_resource_sort_and_combine(head))
610 if (sort_by_max_size(head))
613 for (max = *head;max; max = max->next) {
615 /* If not big enough we could probably just bail,
616 instead we'll continue to the next. */
617 if (max->length < size)
620 if (max->base & (size - 1)) {
621 /* this one isn't base aligned properly
622 so we'll make a new entry and split it up */
623 temp_dword = (max->base | (size-1)) + 1;
625 /* Short circuit if adjusted size is too small */
626 if ((max->length - (temp_dword - max->base)) < size)
629 split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
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 = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
651 temp_dword = ((max->base + max->length) & ~(size - 1));
652 split_node->base = temp_dword;
653 split_node->length = max->length + max->base
655 max->length -= split_node->length;
657 /* Put it in the list */
658 split_node->next = max->next;
659 max->next = split_node;
662 /* Make sure it didn't shrink too much when we aligned it */
663 if (max->length < size)
666 for ( i = 0; max_size[i] > size; i++) {
667 if (max->length > max_size[i]) {
668 split_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
670 break; /* return (NULL); */
671 split_node->base = max->base + max_size[i];
672 split_node->length = max->length - max_size[i];
673 max->length = max_size[i];
674 /* Put it next in the list */
675 split_node->next = max->next;
676 max->next = split_node;
681 /* Now take it out of the list */
682 temp = (struct pci_resource*) *head;
686 while (temp && temp->next != max) {
690 temp->next = max->next;
697 /* If we get here, we couldn't find one */
705 * this function sorts the resource list by size and then
706 * returns the first node of "size" length. If it finds a node
707 * larger than "size" it will split it up.
709 * size must be a power of two.
711 static struct pci_resource *get_resource (struct pci_resource **head, u32 size)
713 struct pci_resource *prevnode;
714 struct pci_resource *node;
715 struct pci_resource *split_node;
721 if ( pciehp_resource_sort_and_combine(head) )
724 if ( sort_by_size(head) )
727 for (node = *head; node; node = node->next) {
728 dbg("%s: req_size =0x%x node=%p, base=0x%x, length=0x%x\n",
729 __FUNCTION__, size, node, node->base, node->length);
730 if (node->length < size)
733 if (node->base & (size - 1)) {
734 dbg("%s: not aligned\n", __FUNCTION__);
735 /* this one isn't base aligned properly
736 so we'll make a new entry and split it up */
737 temp_dword = (node->base | (size-1)) + 1;
739 /* Short circuit if adjusted size is too small */
740 if ((node->length - (temp_dword - node->base)) < size)
743 split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
748 split_node->base = node->base;
749 split_node->length = temp_dword - node->base;
750 node->base = temp_dword;
751 node->length -= split_node->length;
753 /* Put it in the list */
754 split_node->next = node->next;
755 node->next = split_node;
756 } /* End of non-aligned base */
758 /* Don't need to check if too small since we already did */
759 if (node->length > size) {
760 dbg("%s: too big\n", __FUNCTION__);
761 /* this one is longer than we need
762 so we'll make a new entry and split it up */
763 split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
768 split_node->base = node->base + size;
769 split_node->length = node->length - size;
772 /* Put it in the list */
773 split_node->next = node->next;
774 node->next = split_node;
775 } /* End of too big on top end */
777 dbg("%s: got one!!!\n", __FUNCTION__);
778 /* If we got here, then it is the right size
779 Now take it out of the list */
784 while (prevnode->next != node)
785 prevnode = prevnode->next;
787 prevnode->next = node->next;
798 * pciehp_resource_sort_and_combine
800 * Sorts all of the nodes in the list in ascending order by
801 * their base addresses. Also does garbage collection by
802 * combining adjacent nodes.
804 * returns 0 if success
806 int pciehp_resource_sort_and_combine(struct pci_resource **head)
808 struct pci_resource *node1;
809 struct pci_resource *node2;
810 int out_of_order = 1;
812 dbg("%s: head = %p, *head = %p\n", __FUNCTION__, head, *head);
817 dbg("*head->next = %p\n",(*head)->next);
820 return(0); /* only one item on the list, already sorted! */
822 dbg("*head->base = 0x%x\n",(*head)->base);
823 dbg("*head->next->base = 0x%x\n",(*head)->next->base);
824 while (out_of_order) {
827 /* Special case for swapping list head */
828 if (((*head)->next) &&
829 ((*head)->base > (*head)->next->base)) {
831 (*head) = (*head)->next;
832 node1->next = (*head)->next;
833 (*head)->next = node1;
839 while (node1->next && node1->next->next) {
840 if (node1->next->base > node1->next->next->base) {
843 node1->next = node1->next->next;
845 node2->next = node1->next;
850 } /* End of out_of_order loop */
854 while (node1 && node1->next) {
855 if ((node1->base + node1->length) == node1->next->base) {
858 node1->length += node1->next->length;
860 node1->next = node1->next->next;
871 * pciehp_slot_create - Creates a node and adds it to the proper bus.
872 * @busnumber - bus where new node is to be located
874 * Returns pointer to the new node or NULL if unsuccessful
876 struct pci_func *pciehp_slot_create(u8 busnumber)
878 struct pci_func *new_slot;
879 struct pci_func *next;
880 dbg("%s: busnumber %x\n", __FUNCTION__, busnumber);
881 new_slot = (struct pci_func *) kmalloc(sizeof(struct pci_func), GFP_KERNEL);
883 if (new_slot == NULL) {
887 memset(new_slot, 0, sizeof(struct pci_func));
889 new_slot->next = NULL;
890 new_slot->configured = 1;
892 if (pciehp_slot_list[busnumber] == NULL) {
893 pciehp_slot_list[busnumber] = new_slot;
895 next = pciehp_slot_list[busnumber];
896 while (next->next != NULL)
898 next->next = new_slot;
905 * slot_remove - Removes a node from the linked list of slots.
906 * @old_slot: slot to remove
908 * Returns 0 if successful, !0 otherwise.
910 static int slot_remove(struct pci_func * old_slot)
912 struct pci_func *next;
914 if (old_slot == NULL)
917 next = pciehp_slot_list[old_slot->bus];
923 if (next == old_slot) {
924 pciehp_slot_list[old_slot->bus] = old_slot->next;
925 pciehp_destroy_board_resources(old_slot);
930 while ((next->next != old_slot) && (next->next != NULL)) {
934 if (next->next == old_slot) {
935 next->next = old_slot->next;
936 pciehp_destroy_board_resources(old_slot);
945 * bridge_slot_remove - Removes a node from the linked list of slots.
946 * @bridge: bridge to remove
948 * Returns 0 if successful, !0 otherwise.
950 static int bridge_slot_remove(struct pci_func *bridge)
952 u8 subordinateBus, secondaryBus;
954 struct pci_func *next;
959 secondaryBus = (bridge->config_space[0x06] >> 8) & 0xFF;
960 subordinateBus = (bridge->config_space[0x06] >> 16) & 0xFF;
962 for (tempBus = secondaryBus; tempBus <= subordinateBus; tempBus++) {
963 next = pciehp_slot_list[tempBus];
965 while (!slot_remove(next)) {
966 next = pciehp_slot_list[tempBus];
970 next = pciehp_slot_list[bridge->bus];
976 if (next == bridge) {
977 pciehp_slot_list[bridge->bus] = bridge->next;
982 while ((next->next != bridge) && (next->next != NULL)) {
986 if (next->next == bridge) {
987 next->next = bridge->next;
996 * pciehp_slot_find - Looks for a node by bus, and device, multiple functions accessed
998 * @device: device to find
999 * @index: is 0 for first function found, 1 for the second...
1001 * Returns pointer to the node if successful, %NULL otherwise.
1003 struct pci_func *pciehp_slot_find(u8 bus, u8 device, u8 index)
1006 struct pci_func *func;
1008 func = pciehp_slot_list[bus];
1009 dbg("%s: bus %x device %x index %x\n",
1010 __FUNCTION__, bus, device, index);
1012 dbg("%s: func-> bus %x device %x function %x pci_dev %p\n",
1013 __FUNCTION__, func->bus, func->device, func->function,
1016 dbg("%s: func == NULL\n", __FUNCTION__);
1018 if ((func == NULL) || ((func->device == device) && (index == 0)))
1021 if (func->device == device)
1024 while (func->next != NULL) {
1027 dbg("%s: In while loop, func-> bus %x device %x function %x pci_dev %p\n",
1028 __FUNCTION__, func->bus, func->device, func->function,
1030 if (func->device == device)
1032 dbg("%s: while loop, found %d, index %d\n", __FUNCTION__,
1035 if ((found == index) || (func->function == index)) {
1036 dbg("%s: Found bus %x dev %x func %x\n", __FUNCTION__,
1037 func->bus, func->device, func->function);
1045 static int is_bridge(struct pci_func * func)
1047 /* Check the header type */
1048 if (((func->config_space[0x03] >> 16) & 0xFF) == 0x01)
1055 /* The following routines constitute the bulk of the
1056 hotplug controller logic
1061 * board_added - Called after a board has been added to the system.
1063 * Turns power on for the board
1067 static u32 board_added(struct pci_func * func, struct controller * ctrl)
1071 u32 temp_register = 0xFFFFFFFF;
1073 struct pci_func *new_func = NULL;
1074 struct slot *p_slot;
1075 struct resource_lists res_lists;
1077 p_slot = pciehp_find_slot(ctrl, func->device);
1078 hp_slot = func->device - ctrl->slot_device_offset;
1080 dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n", __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot);
1082 /* Wait for exclusive access to hardware */
1083 down(&ctrl->crit_sect);
1086 rc = p_slot->hpc_ops->power_on_slot(p_slot);
1090 /* Wait for the command to complete */
1091 wait_for_ctrl_irq (ctrl);
1093 p_slot->hpc_ops->green_led_blink(p_slot);
1095 /* Wait for the command to complete */
1096 wait_for_ctrl_irq (ctrl);
1098 /* Done with exclusive hardware access */
1099 up(&ctrl->crit_sect);
1101 /* Wait for ~1 second */
1102 dbg("%s: before long_delay\n", __FUNCTION__);
1103 wait_for_ctrl_irq (ctrl);
1104 dbg("%s: afterlong_delay\n", __FUNCTION__);
1106 /* Make this to check for link training status */
1107 rc = p_slot->hpc_ops->check_lnk_status(ctrl);
1109 err("%s: Failed to check link status\n", __FUNCTION__);
1113 dbg("%s: func status = %x\n", __FUNCTION__, func->status);
1115 /* Check for a power fault */
1116 if (func->status == 0xFF) {
1117 /* power fault occurred, but it was benign */
1118 temp_register = 0xFFFFFFFF;
1119 dbg("%s: temp register set to %x by power fault\n", __FUNCTION__, temp_register);
1123 /* Get vendor/device ID u32 */
1124 rc = pci_bus_read_config_dword (ctrl->pci_dev->subordinate, PCI_DEVFN(func->device, func->function),
1125 PCI_VENDOR_ID, &temp_register);
1126 dbg("%s: pci_bus_read_config_dword returns %d\n", __FUNCTION__, rc);
1127 dbg("%s: temp_register is %x\n", __FUNCTION__, temp_register);
1130 /* Something's wrong here */
1131 temp_register = 0xFFFFFFFF;
1132 dbg("%s: temp register set to %x by error\n", __FUNCTION__, temp_register);
1134 /* Preset return code. It will be changed later if things go okay. */
1135 rc = NO_ADAPTER_PRESENT;
1138 /* All F's is an empty slot or an invalid board */
1139 if (temp_register != 0xFFFFFFFF) { /* Check for a board in the slot */
1140 res_lists.io_head = ctrl->io_head;
1141 res_lists.mem_head = ctrl->mem_head;
1142 res_lists.p_mem_head = ctrl->p_mem_head;
1143 res_lists.bus_head = ctrl->bus_head;
1144 res_lists.irqs = NULL;
1146 rc = configure_new_device(ctrl, func, 0, &res_lists, 0, 0);
1147 dbg("%s: back from configure_new_device\n", __FUNCTION__);
1149 ctrl->io_head = res_lists.io_head;
1150 ctrl->mem_head = res_lists.mem_head;
1151 ctrl->p_mem_head = res_lists.p_mem_head;
1152 ctrl->bus_head = res_lists.bus_head;
1154 pciehp_resource_sort_and_combine(&(ctrl->mem_head));
1155 pciehp_resource_sort_and_combine(&(ctrl->p_mem_head));
1156 pciehp_resource_sort_and_combine(&(ctrl->io_head));
1157 pciehp_resource_sort_and_combine(&(ctrl->bus_head));
1160 /* Wait for exclusive access to hardware */
1161 down(&ctrl->crit_sect);
1163 /* turn off slot, turn on Amber LED, turn off Green LED */
1164 retval = p_slot->hpc_ops->power_off_slot(p_slot);
1165 /* In PCI Express, just power off slot */
1167 err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);
1170 /* Wait for the command to complete */
1171 wait_for_ctrl_irq (ctrl);
1173 p_slot->hpc_ops->green_led_off(p_slot);
1175 /* Wait for the command to complete */
1176 wait_for_ctrl_irq (ctrl);
1178 /* turn on Amber LED */
1179 retval = p_slot->hpc_ops->set_attention_status(p_slot, 1);
1181 err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);
1184 /* Wait for the command to complete */
1185 wait_for_ctrl_irq (ctrl);
1187 /* Done with exclusive hardware access */
1188 up(&ctrl->crit_sect);
1192 pciehp_save_slot_config(ctrl, func);
1195 func->switch_save = 0x10;
1196 func->is_a_board = 0x01;
1198 /* next, we will instantiate the linux pci_dev structures
1199 * (with appropriate driver notification, if already present)
1203 new_func = pciehp_slot_find(ctrl->slot_bus, func->device, index++);
1204 if (new_func && !new_func->pci_dev) {
1205 dbg("%s:call pci_hp_configure_dev, func %x\n",
1206 __FUNCTION__, index);
1207 pciehp_configure_device(ctrl, new_func);
1211 /* Wait for exclusive access to hardware */
1212 down(&ctrl->crit_sect);
1214 p_slot->hpc_ops->green_led_on(p_slot);
1216 /* Wait for the command to complete */
1217 wait_for_ctrl_irq (ctrl);
1220 /* Done with exclusive hardware access */
1221 up(&ctrl->crit_sect);
1224 /* Wait for exclusive access to hardware */
1225 down(&ctrl->crit_sect);
1227 /* turn off slot, turn on Amber LED, turn off Green LED */
1228 retval = p_slot->hpc_ops->power_off_slot(p_slot);
1229 /* In PCI Express, just power off slot */
1231 err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);
1234 /* Wait for the command to complete */
1235 wait_for_ctrl_irq (ctrl);
1237 p_slot->hpc_ops->green_led_off(p_slot);
1239 /* Wait for the command to complete */
1240 wait_for_ctrl_irq (ctrl);
1242 /* turn on Amber LED */
1243 retval = p_slot->hpc_ops->set_attention_status(p_slot, 1);
1245 err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);
1248 /* Wait for the command to complete */
1249 wait_for_ctrl_irq (ctrl);
1251 /* Done with exclusive hardware access */
1252 up(&ctrl->crit_sect);
1261 * remove_board - Turns off slot and LED's
1264 static u32 remove_board(struct pci_func *func, struct controller *ctrl)
1271 struct resource_lists res_lists;
1272 struct pci_func *temp_func;
1273 struct slot *p_slot;
1278 if (pciehp_unconfigure_device(func))
1281 device = func->device;
1283 hp_slot = func->device - ctrl->slot_device_offset;
1284 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
1286 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
1288 if ((ctrl->add_support) &&
1289 !(func->bus_head || func->mem_head || func->p_mem_head || func->io_head)) {
1290 /* Here we check to see if we've saved any of the board's
1291 * resources already. If so, we'll skip the attempt to
1292 * determine what's being used.
1298 while ((temp_func = pciehp_slot_find(temp_func->bus, temp_func->device, index++))) {
1299 if (temp_func->bus_head || temp_func->mem_head
1300 || temp_func->p_mem_head || temp_func->io_head) {
1307 rc = pciehp_save_used_resources(ctrl, func, DISABLE_CARD);
1309 /* Change status to shutdown */
1310 if (func->is_a_board)
1311 func->status = 0x01;
1312 func->configured = 0;
1314 /* Wait for exclusive access to hardware */
1315 down(&ctrl->crit_sect);
1317 /* power off slot */
1318 rc = p_slot->hpc_ops->power_off_slot(p_slot);
1320 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
1323 /* Wait for the command to complete */
1324 wait_for_ctrl_irq (ctrl);
1326 /* turn off Green LED */
1327 p_slot->hpc_ops->green_led_off(p_slot);
1329 /* Wait for the command to complete */
1330 wait_for_ctrl_irq (ctrl);
1332 /* Done with exclusive hardware access */
1333 up(&ctrl->crit_sect);
1335 if (ctrl->add_support) {
1337 res_lists.io_head = ctrl->io_head;
1338 res_lists.mem_head = ctrl->mem_head;
1339 res_lists.p_mem_head = ctrl->p_mem_head;
1340 res_lists.bus_head = ctrl->bus_head;
1342 dbg("Returning resources to ctlr lists for (B/D/F) = (%#x/%#x/%#x)\n",
1343 func->bus, func->device, func->function);
1345 pciehp_return_board_resources(func, &res_lists);
1347 ctrl->io_head = res_lists.io_head;
1348 ctrl->mem_head = res_lists.mem_head;
1349 ctrl->p_mem_head = res_lists.p_mem_head;
1350 ctrl->bus_head = res_lists.bus_head;
1352 pciehp_resource_sort_and_combine(&(ctrl->mem_head));
1353 pciehp_resource_sort_and_combine(&(ctrl->p_mem_head));
1354 pciehp_resource_sort_and_combine(&(ctrl->io_head));
1355 pciehp_resource_sort_and_combine(&(ctrl->bus_head));
1357 if (is_bridge(func)) {
1358 dbg("PCI Bridge Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n",
1359 ctrl->seg, func->bus, func->device, func->function);
1360 bridge_slot_remove(func);
1362 dbg("PCI Function Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n",
1363 ctrl->seg, func->bus, func->device, func->function);
1366 func = pciehp_slot_find(ctrl->slot_bus, device, 0);
1369 /* Setup slot structure with entry for empty slot */
1370 func = pciehp_slot_create(ctrl->slot_bus);
1376 func->bus = ctrl->slot_bus;
1377 func->device = device;
1379 func->configured = 0;
1380 func->switch_save = 0x10;
1381 func->is_a_board = 0;
1388 static void pushbutton_helper_thread (unsigned long data)
1390 pushbutton_pending = data;
1392 up(&event_semaphore);
1396 /* this is the main worker thread */
1397 static int event_thread(void* data)
1399 struct controller *ctrl;
1401 daemonize("pciehpd_event");
1406 dbg("!!!!event_thread sleeping\n");
1407 down_interruptible (&event_semaphore);
1408 dbg("event_thread woken finished = %d\n", event_finished);
1409 if (event_finished || signal_pending(current))
1412 if (pushbutton_pending)
1413 pciehp_pushbutton_thread(pushbutton_pending);
1415 for (ctrl = pciehp_ctrl_list; ctrl; ctrl=ctrl->next)
1416 interrupt_event_handler(ctrl);
1418 dbg("event_thread signals exit\n");
1423 int pciehp_event_start_thread (void)
1427 /* initialize our semaphores */
1428 init_MUTEX_LOCKED(&event_exit);
1431 init_MUTEX_LOCKED(&event_semaphore);
1432 pid = kernel_thread(event_thread, 0, 0);
1435 err ("Can't start up our event thread\n");
1438 dbg("Our event thread pid = %d\n", pid);
1443 void pciehp_event_stop_thread (void)
1446 dbg("event_thread finish command given\n");
1447 up(&event_semaphore);
1448 dbg("wait for event_thread to exit\n");
1453 static int update_slot_info (struct slot *slot)
1455 struct hotplug_slot_info *info;
1456 /* char buffer[SLOT_NAME_SIZE]; */
1459 info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL);
1463 /* make_slot_name (&buffer[0], SLOT_NAME_SIZE, slot); */
1465 slot->hpc_ops->get_power_status(slot, &(info->power_status));
1466 slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
1467 slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
1468 slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
1470 /* result = pci_hp_change_slot_info(buffer, info); */
1471 result = pci_hp_change_slot_info(slot->hotplug_slot, info);
1476 static void interrupt_event_handler(struct controller *ctrl)
1480 struct pci_func *func;
1483 struct slot *p_slot;
1488 for (loop = 0; loop < 10; loop++) {
1489 if (ctrl->event_queue[loop].event_type != 0) {
1490 hp_slot = ctrl->event_queue[loop].hp_slot;
1492 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
1494 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
1496 dbg("hp_slot %d, func %p, p_slot %p\n", hp_slot, func, p_slot);
1498 if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {
1499 dbg("button cancel\n");
1500 del_timer(&p_slot->task_event);
1502 switch (p_slot->state) {
1503 case BLINKINGOFF_STATE:
1504 /* Wait for exclusive access to hardware */
1505 down(&ctrl->crit_sect);
1507 p_slot->hpc_ops->green_led_on(p_slot);
1508 /* Wait for the command to complete */
1509 wait_for_ctrl_irq (ctrl);
1511 p_slot->hpc_ops->set_attention_status(p_slot, 0);
1513 /* Wait for the command to complete */
1514 wait_for_ctrl_irq (ctrl);
1516 /* Done with exclusive hardware access */
1517 up(&ctrl->crit_sect);
1519 case BLINKINGON_STATE:
1520 /* Wait for exclusive access to hardware */
1521 down(&ctrl->crit_sect);
1523 p_slot->hpc_ops->green_led_off(p_slot);
1524 /* Wait for the command to complete */
1525 wait_for_ctrl_irq (ctrl);
1527 p_slot->hpc_ops->set_attention_status(p_slot, 0);
1528 /* Wait for the command to complete */
1529 wait_for_ctrl_irq (ctrl);
1531 /* Done with exclusive hardware access */
1532 up(&ctrl->crit_sect);
1536 warn("Not a valid state\n");
1539 info(msg_button_cancel, p_slot->number);
1540 p_slot->state = STATIC_STATE;
1542 /* ***********Button Pressed (No action on 1st press...) */
1543 else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {
1544 dbg("Button pressed\n");
1546 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1549 dbg("slot is on\n");
1550 p_slot->state = BLINKINGOFF_STATE;
1551 info(msg_button_off, p_slot->number);
1554 dbg("slot is off\n");
1555 p_slot->state = BLINKINGON_STATE;
1556 info(msg_button_on, p_slot->number);
1559 /* Wait for exclusive access to hardware */
1560 down(&ctrl->crit_sect);
1562 /* blink green LED and turn off amber */
1563 p_slot->hpc_ops->green_led_blink(p_slot);
1564 /* Wait for the command to complete */
1565 wait_for_ctrl_irq (ctrl);
1567 p_slot->hpc_ops->set_attention_status(p_slot, 0);
1569 /* Wait for the command to complete */
1570 wait_for_ctrl_irq (ctrl);
1572 /* Done with exclusive hardware access */
1573 up(&ctrl->crit_sect);
1575 init_timer(&p_slot->task_event);
1576 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
1577 p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;
1578 p_slot->task_event.data = (unsigned long) p_slot;
1580 dbg("add_timer p_slot = %p\n", (void *) p_slot);
1581 add_timer(&p_slot->task_event);
1583 /***********POWER FAULT********************/
1584 else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
1585 dbg("power fault\n");
1586 /* Wait for exclusive access to hardware */
1587 down(&ctrl->crit_sect);
1589 p_slot->hpc_ops->set_attention_status(p_slot, 1);
1590 p_slot->hpc_ops->green_led_off(p_slot);
1592 /* Done with exclusive hardware access */
1593 up(&ctrl->crit_sect);
1595 /* refresh notification */
1597 update_slot_info(p_slot);
1600 ctrl->event_queue[loop].event_type = 0;
1604 } /* End of FOR loop */
1612 * pciehp_pushbutton_thread
1614 * Scheduled procedure to handle blocking stuff for the pushbuttons
1615 * Handles all pending events and exits.
1618 void pciehp_pushbutton_thread (unsigned long slot)
1620 struct slot *p_slot = (struct slot *) slot;
1624 pushbutton_pending = 0;
1627 dbg("%s: Error! slot NULL\n", __FUNCTION__);
1631 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1633 p_slot->state = POWEROFF_STATE;
1634 dbg("In power_down_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
1636 if (pciehp_disable_slot(p_slot)) {
1637 /* Wait for exclusive access to hardware */
1638 down(&p_slot->ctrl->crit_sect);
1640 /* Turn on the Attention LED */
1641 rc = p_slot->hpc_ops->set_attention_status(p_slot, 1);
1643 err("%s: Issue of Set Atten Indicator On command failed\n", __FUNCTION__);
1647 /* Wait for the command to complete */
1648 wait_for_ctrl_irq (p_slot->ctrl);
1650 /* Done with exclusive hardware access */
1651 up(&p_slot->ctrl->crit_sect);
1653 p_slot->state = STATIC_STATE;
1655 p_slot->state = POWERON_STATE;
1656 dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
1658 if (pciehp_enable_slot(p_slot)) {
1659 /* Wait for exclusive access to hardware */
1660 down(&p_slot->ctrl->crit_sect);
1662 /* Turn off the green LED */
1663 rc = p_slot->hpc_ops->set_attention_status(p_slot, 1);
1665 err("%s: Issue of Set Atten Indicator On command failed\n", __FUNCTION__);
1668 /* Wait for the command to complete */
1669 wait_for_ctrl_irq (p_slot->ctrl);
1671 p_slot->hpc_ops->green_led_off(p_slot);
1673 /* Wait for the command to complete */
1674 wait_for_ctrl_irq (p_slot->ctrl);
1676 /* Done with exclusive hardware access */
1677 up(&p_slot->ctrl->crit_sect);
1679 p_slot->state = STATIC_STATE;
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, resources, bridge_bus, bridge_dev);
1907 dbg("configure_new_function failed %d\n",rc);
1911 new_slot = pciehp_slot_find(new_slot->bus, new_slot->device, index++);
1914 pciehp_return_board_resources(new_slot, resources);
1924 /* The following loop skips to the next present function
1925 * and creates a board structure
1928 while ((function < max_functions) && (!stop_it)) {
1929 pci_bus_read_config_dword(pci_bus, PCI_DEVFN(func->device, function), 0x00, &ID);
1931 if (ID == 0xFFFFFFFF) { /* There's nothing there. */
1933 } else { /* There's something there */
1934 /* Setup slot structure. */
1935 new_slot = pciehp_slot_create(func->bus);
1937 if (new_slot == NULL) {
1942 new_slot->bus = func->bus;
1943 new_slot->device = func->device;
1944 new_slot->function = function;
1945 new_slot->is_a_board = 1;
1946 new_slot->status = 0;
1952 } while (function < max_functions);
1953 dbg("returning from configure_new_device\n");
1960 * Configuration logic that involves the hotplug data structures and
1966 * configure_new_function - Configures the PCI header information of one device
1968 * @ctrl: pointer to controller structure
1969 * @func: pointer to function structure
1970 * @behind_bridge: 1 if this is a recursive call, 0 if not
1971 * @resources: pointer to set of resource lists
1973 * Calls itself recursively for bridged devices.
1974 * Returns 0 if success
1977 static int configure_new_function (struct controller * ctrl, struct pci_func * func,
1978 u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev)
1990 struct pci_resource *mem_node;
1991 struct pci_resource *p_mem_node;
1992 struct pci_resource *io_node;
1993 struct pci_resource *bus_node;
1994 struct pci_resource *hold_mem_node;
1995 struct pci_resource *hold_p_mem_node;
1996 struct pci_resource *hold_IO_node;
1997 struct pci_resource *hold_bus_node;
1998 struct irq_mapping irqs;
1999 struct pci_func *new_slot;
2000 struct pci_bus lpci_bus, *pci_bus;
2001 struct resource_lists temp_resources;
2003 memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));
2004 pci_bus = &lpci_bus;
2005 pci_bus->number = func->bus;
2006 devfn = PCI_DEVFN(func->device, func->function);
2008 /* Check for Bridge */
2009 rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &temp_byte);
2012 dbg("%s: bus %x dev %x func %x temp_byte = %x\n", __FUNCTION__,
2013 func->bus, func->device, func->function, temp_byte);
2015 if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { /* PCI-PCI Bridge */
2016 /* set Primary bus */
2017 dbg("set Primary bus = 0x%x\n", func->bus);
2018 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_PRIMARY_BUS, func->bus);
2022 /* find range of busses to use */
2023 bus_node = get_max_resource(&resources->bus_head, 1L);
2025 /* If we don't have any busses to allocate, we can't continue */
2027 err("Got NO bus resource to use\n");
2030 dbg("Got ranges of buses to use: base:len=0x%x:%x\n", bus_node->base, bus_node->length);
2032 /* set Secondary bus */
2033 dbg("set Secondary bus = 0x%x\n", temp_byte);
2034 dbg("func->bus %x\n", func->bus);
2036 temp_byte = (u8)bus_node->base;
2037 dbg("set Secondary bus = 0x%x\n", temp_byte);
2038 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SECONDARY_BUS, temp_byte);
2042 /* set subordinate bus */
2043 temp_byte = (u8)(bus_node->base + bus_node->length - 1);
2044 dbg("set subordinate bus = 0x%x\n", temp_byte);
2045 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);
2049 /* Set HP parameters (Cache Line Size, Latency Timer) */
2050 rc = pciehprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_BRIDGE);
2054 /* Setup the IO, memory, and prefetchable windows */
2056 io_node = get_max_resource(&(resources->io_head), 0x1000L);
2058 dbg("io_node(base, len, next) (%x, %x, %p)\n", io_node->base, io_node->length, io_node->next);
2061 mem_node = get_max_resource(&(resources->mem_head), 0x100000L);
2063 dbg("mem_node(base, len, next) (%x, %x, %p)\n", mem_node->base, mem_node->length, mem_node->next);
2066 if (resources->p_mem_head)
2067 p_mem_node = get_max_resource(&(resources->p_mem_head), 0x100000L);
2070 * In some platform implementation, MEM and PMEM are not
2071 * distinguished, and hence ACPI _CRS has only MEM entries
2072 * for both MEM and PMEM.
2074 dbg("using MEM for PMEM\n");
2075 p_mem_node = get_max_resource(&(resources->mem_head), 0x100000L);
2078 dbg("p_mem_node(base, len, next) (%x, %x, %p)\n", p_mem_node->base, p_mem_node->length, p_mem_node->next);
2081 /* set up the IRQ info */
2082 if (!resources->irqs) {
2083 irqs.barber_pole = 0;
2084 irqs.interrupt[0] = 0;
2085 irqs.interrupt[1] = 0;
2086 irqs.interrupt[2] = 0;
2087 irqs.interrupt[3] = 0;
2090 irqs.barber_pole = resources->irqs->barber_pole;
2091 irqs.interrupt[0] = resources->irqs->interrupt[0];
2092 irqs.interrupt[1] = resources->irqs->interrupt[1];
2093 irqs.interrupt[2] = resources->irqs->interrupt[2];
2094 irqs.interrupt[3] = resources->irqs->interrupt[3];
2095 irqs.valid_INT = resources->irqs->valid_INT;
2098 /* set up resource lists that are now aligned on top and bottom
2099 * for anything behind the bridge.
2101 temp_resources.bus_head = bus_node;
2102 temp_resources.io_head = io_node;
2103 temp_resources.mem_head = mem_node;
2104 temp_resources.p_mem_head = p_mem_node;
2105 temp_resources.irqs = &irqs;
2107 /* Make copies of the nodes we are going to pass down so that
2108 * if there is a problem,we can just use these to free resources
2110 hold_bus_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2111 hold_IO_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2112 hold_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2113 hold_p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2115 if (!hold_bus_node || !hold_IO_node || !hold_mem_node || !hold_p_mem_node) {
2117 kfree(hold_bus_node);
2119 kfree(hold_IO_node);
2121 kfree(hold_mem_node);
2122 if (hold_p_mem_node)
2123 kfree(hold_p_mem_node);
2128 memcpy(hold_bus_node, bus_node, sizeof(struct pci_resource));
2130 bus_node->base += 1;
2131 bus_node->length -= 1;
2132 bus_node->next = NULL;
2134 /* If we have IO resources copy them and fill in the bridge's
2135 * IO range registers
2138 memcpy(hold_IO_node, io_node, sizeof(struct pci_resource));
2139 io_node->next = NULL;
2141 /* set IO base and Limit registers */
2142 RES_CHECK(io_node->base, 8);
2143 temp_byte = (u8)(io_node->base >> 8);
2144 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_BASE, temp_byte);
2146 RES_CHECK(io_node->base + io_node->length - 1, 8);
2147 temp_byte = (u8)((io_node->base + io_node->length - 1) >> 8);
2148 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2150 kfree(hold_IO_node);
2151 hold_IO_node = NULL;
2154 /* If we have memory resources copy them and fill in the bridge's
2155 * memory range registers. Otherwise, fill in the range
2156 * registers with values that disable them.
2159 memcpy(hold_mem_node, mem_node, sizeof(struct pci_resource));
2160 mem_node->next = NULL;
2162 /* set Mem base and Limit registers */
2163 RES_CHECK(mem_node->base, 16);
2164 temp_word = (u32)(mem_node->base >> 16);
2165 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_BASE, temp_word);
2167 RES_CHECK(mem_node->base + mem_node->length - 1, 16);
2168 temp_word = (u32)((mem_node->base + mem_node->length - 1) >> 16);
2169 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2172 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_BASE, temp_word);
2175 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2177 kfree(hold_mem_node);
2178 hold_mem_node = NULL;
2181 /* If we have prefetchable memory resources copy them and
2182 * fill in the bridge's memory range registers. Otherwise,
2183 * fill in the range registers with values that disable them.
2186 memcpy(hold_p_mem_node, p_mem_node, sizeof(struct pci_resource));
2187 p_mem_node->next = NULL;
2189 /* set Pre Mem base and Limit registers */
2190 RES_CHECK(p_mem_node->base, 16);
2191 temp_word = (u32)(p_mem_node->base >> 16);
2192 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
2194 RES_CHECK(p_mem_node->base + p_mem_node->length - 1, 16);
2195 temp_word = (u32)((p_mem_node->base + p_mem_node->length - 1) >> 16);
2196 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2199 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
2202 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2204 kfree(hold_p_mem_node);
2205 hold_p_mem_node = NULL;
2208 /* Adjust this to compensate for extra adjustment in first loop */
2213 /* Here we actually find the devices and configure them */
2214 for (device = 0; (device <= 0x1F) && !rc; device++) {
2215 irqs.barber_pole = (irqs.barber_pole + 1) & 0x03;
2218 pci_bus->number = hold_bus_node->base;
2219 pci_bus_read_config_dword (pci_bus, PCI_DEVFN(device, 0), PCI_VENDOR_ID, &ID);
2220 pci_bus->number = func->bus;
2222 if (ID != 0xFFFFFFFF) { /* device Present */
2223 /* Setup slot structure. */
2224 new_slot = pciehp_slot_create(hold_bus_node->base);
2226 if (new_slot == NULL) {
2232 new_slot->bus = hold_bus_node->base;
2233 new_slot->device = device;
2234 new_slot->function = 0;
2235 new_slot->is_a_board = 1;
2236 new_slot->status = 0;
2238 rc = configure_new_device(ctrl, new_slot, 1, &temp_resources, func->bus, func->device);
2239 dbg("configure_new_device rc=0x%x\n",rc);
2240 } /* End of IF (device in slot?) */
2241 } /* End of FOR loop */
2244 pciehp_destroy_resource_list(&temp_resources);
2246 return_resource(&(resources->bus_head), hold_bus_node);
2247 return_resource(&(resources->io_head), hold_IO_node);
2248 return_resource(&(resources->mem_head), hold_mem_node);
2249 return_resource(&(resources->p_mem_head), hold_p_mem_node);
2253 /* save the interrupt routing information */
2254 if (resources->irqs) {
2255 resources->irqs->interrupt[0] = irqs.interrupt[0];
2256 resources->irqs->interrupt[1] = irqs.interrupt[1];
2257 resources->irqs->interrupt[2] = irqs.interrupt[2];
2258 resources->irqs->interrupt[3] = irqs.interrupt[3];
2259 resources->irqs->valid_INT = irqs.valid_INT;
2260 } else if (!behind_bridge) {
2261 /* We need to hook up the interrupts here */
2262 for (cloop = 0; cloop < 4; cloop++) {
2263 if (irqs.valid_INT & (0x01 << cloop)) {
2264 rc = pciehp_set_irq(func->bus, func->device,
2265 0x0A + cloop, irqs.interrupt[cloop]);
2267 pciehp_destroy_resource_list (&temp_resources);
2268 return_resource(&(resources->bus_head), hold_bus_node);
2269 return_resource(&(resources->io_head), hold_IO_node);
2270 return_resource(&(resources->mem_head), hold_mem_node);
2271 return_resource(&(resources->p_mem_head), hold_p_mem_node);
2275 } /* end of for loop */
2278 /* Return unused bus resources
2279 * First use the temporary node to store information for the board
2281 if (hold_bus_node && bus_node && temp_resources.bus_head) {
2282 hold_bus_node->length = bus_node->base - hold_bus_node->base;
2284 hold_bus_node->next = func->bus_head;
2285 func->bus_head = hold_bus_node;
2287 temp_byte = (u8)(temp_resources.bus_head->base - 1);
2289 /* set subordinate bus */
2290 dbg("re-set subordinate bus = 0x%x\n", temp_byte);
2291 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);
2293 if (temp_resources.bus_head->length == 0) {
2294 kfree(temp_resources.bus_head);
2295 temp_resources.bus_head = NULL;
2297 dbg("return bus res of b:d(0x%x:%x) base:len(0x%x:%x)\n",
2298 func->bus, func->device, temp_resources.bus_head->base, temp_resources.bus_head->length);
2299 return_resource(&(resources->bus_head), temp_resources.bus_head);
2303 /* If we have IO space available and there is some left,
2304 * return the unused portion
2306 if (hold_IO_node && temp_resources.io_head) {
2307 io_node = do_pre_bridge_resource_split(&(temp_resources.io_head),
2308 &hold_IO_node, 0x1000);
2310 /* Check if we were able to split something off */
2312 hold_IO_node->base = io_node->base + io_node->length;
2314 RES_CHECK(hold_IO_node->base, 8);
2315 temp_byte = (u8)((hold_IO_node->base) >> 8);
2316 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_BASE, temp_byte);
2318 return_resource(&(resources->io_head), io_node);
2321 io_node = do_bridge_resource_split(&(temp_resources.io_head), 0x1000);
2323 /* Check if we were able to split something off */
2325 /* First use the temporary node to store information for the board */
2326 hold_IO_node->length = io_node->base - hold_IO_node->base;
2328 /* If we used any, add it to the board's list */
2329 if (hold_IO_node->length) {
2330 hold_IO_node->next = func->io_head;
2331 func->io_head = hold_IO_node;
2333 RES_CHECK(io_node->base - 1, 8);
2334 temp_byte = (u8)((io_node->base - 1) >> 8);
2335 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2337 return_resource(&(resources->io_head), io_node);
2339 /* it doesn't need any IO */
2341 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2343 return_resource(&(resources->io_head), io_node);
2344 kfree(hold_IO_node);
2347 /* it used most of the range */
2348 hold_IO_node->next = func->io_head;
2349 func->io_head = hold_IO_node;
2351 } else if (hold_IO_node) {
2352 /* it used the whole range */
2353 hold_IO_node->next = func->io_head;
2354 func->io_head = hold_IO_node;
2357 /* If we have memory space available and there is some left,
2358 * return the unused portion
2360 if (hold_mem_node && temp_resources.mem_head) {
2361 mem_node = do_pre_bridge_resource_split(&(temp_resources.mem_head), &hold_mem_node, 0x100000L);
2363 /* Check if we were able to split something off */
2365 hold_mem_node->base = mem_node->base + mem_node->length;
2367 RES_CHECK(hold_mem_node->base, 16);
2368 temp_word = (u32)((hold_mem_node->base) >> 16);
2369 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_BASE, temp_word);
2371 return_resource(&(resources->mem_head), mem_node);
2374 mem_node = do_bridge_resource_split(&(temp_resources.mem_head), 0x100000L);
2376 /* Check if we were able to split something off */
2378 /* First use the temporary node to store information for the board */
2379 hold_mem_node->length = mem_node->base - hold_mem_node->base;
2381 if (hold_mem_node->length) {
2382 hold_mem_node->next = func->mem_head;
2383 func->mem_head = hold_mem_node;
2385 /* configure end address */
2386 RES_CHECK(mem_node->base - 1, 16);
2387 temp_word = (u32)((mem_node->base - 1) >> 16);
2388 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2390 /* Return unused resources to the pool */
2391 return_resource(&(resources->mem_head), mem_node);
2393 /* it doesn't need any Mem */
2395 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2397 return_resource(&(resources->mem_head), mem_node);
2398 kfree(hold_mem_node);
2401 /* it used most of the range */
2402 hold_mem_node->next = func->mem_head;
2403 func->mem_head = hold_mem_node;
2405 } else if (hold_mem_node) {
2406 /* it used the whole range */
2407 hold_mem_node->next = func->mem_head;
2408 func->mem_head = hold_mem_node;
2411 /* If we have prefetchable memory space available and there is some
2412 * left at the end, return the unused portion
2414 if (hold_p_mem_node && temp_resources.p_mem_head) {
2415 p_mem_node = do_pre_bridge_resource_split(&(temp_resources.p_mem_head),
2416 &hold_p_mem_node, 0x100000L);
2418 /* Check if we were able to split something off */
2420 hold_p_mem_node->base = p_mem_node->base + p_mem_node->length;
2422 RES_CHECK(hold_p_mem_node->base, 16);
2423 temp_word = (u32)((hold_p_mem_node->base) >> 16);
2424 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
2426 return_resource(&(resources->p_mem_head), p_mem_node);
2429 p_mem_node = do_bridge_resource_split(&(temp_resources.p_mem_head), 0x100000L);
2431 /* Check if we were able to split something off */
2433 /* First use the temporary node to store information for the board */
2434 hold_p_mem_node->length = p_mem_node->base - hold_p_mem_node->base;
2436 /* If we used any, add it to the board's list */
2437 if (hold_p_mem_node->length) {
2438 hold_p_mem_node->next = func->p_mem_head;
2439 func->p_mem_head = hold_p_mem_node;
2441 RES_CHECK(p_mem_node->base - 1, 16);
2442 temp_word = (u32)((p_mem_node->base - 1) >> 16);
2443 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2445 return_resource(&(resources->p_mem_head), p_mem_node);
2447 /* it doesn't need any PMem */
2449 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2451 return_resource(&(resources->p_mem_head), p_mem_node);
2452 kfree(hold_p_mem_node);
2455 /* it used the most of the range */
2456 hold_p_mem_node->next = func->p_mem_head;
2457 func->p_mem_head = hold_p_mem_node;
2459 } else if (hold_p_mem_node) {
2460 /* it used the whole range */
2461 hold_p_mem_node->next = func->p_mem_head;
2462 func->p_mem_head = hold_p_mem_node;
2465 /* We should be configuring an IRQ and the bridge's base address
2466 * registers if it needs them. Although we have never seen such
2470 pciehprm_enable_card(ctrl, func, PCI_HEADER_TYPE_BRIDGE);
2472 dbg("PCI Bridge Hot-Added s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, func->device, func->function);
2473 } else if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_NORMAL) {
2474 /* Standard device */
2476 rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
2478 if (class_code == PCI_BASE_CLASS_DISPLAY)
2479 return (DEVICE_TYPE_NOT_SUPPORTED);
2481 /* Figure out IO and memory needs */
2482 for (cloop = PCI_BASE_ADDRESS_0; cloop <= PCI_BASE_ADDRESS_5; cloop += 4) {
2483 temp_register = 0xFFFFFFFF;
2485 rc = pci_bus_write_config_dword (pci_bus, devfn, cloop, temp_register);
2486 rc = pci_bus_read_config_dword(pci_bus, devfn, cloop, &temp_register);
2487 dbg("Bar[%x]=0x%x on bus:dev:func(0x%x:%x:%x)\n", cloop, temp_register,
2488 func->bus, func->device, func->function);
2494 if (temp_register & PCI_BASE_ADDRESS_SPACE_IO) {
2497 /* set base = amount of IO space */
2498 base = temp_register & 0xFFFFFFFC;
2501 dbg("NEED IO length(0x%x)\n", base);
2502 io_node = get_io_resource(&(resources->io_head),(ulong)base);
2504 /* allocate the resource to the board */
2506 dbg("Got IO base=0x%x(length=0x%x)\n", io_node->base, io_node->length);
2507 base = (u32)io_node->base;
2508 io_node->next = func->io_head;
2509 func->io_head = io_node;
2511 err("Got NO IO resource(length=0x%x)\n", base);
2514 } else { /* map MEM */
2515 int prefetchable = 1;
2516 struct pci_resource **res_node = &func->p_mem_head;
2517 char *res_type_str = "PMEM";
2520 if (!(temp_register & PCI_BASE_ADDRESS_MEM_PREFETCH)) {
2522 res_node = &func->mem_head;
2526 base = temp_register & 0xFFFFFFF0;
2529 switch (temp_register & PCI_BASE_ADDRESS_MEM_TYPE_MASK) {
2530 case PCI_BASE_ADDRESS_MEM_TYPE_32:
2531 dbg("NEED 32 %s bar=0x%x(length=0x%x)\n", res_type_str, temp_register, base);
2533 if (prefetchable && resources->p_mem_head)
2534 mem_node=get_resource(&(resources->p_mem_head), (ulong)base);
2537 dbg("using MEM for PMEM\n");
2538 mem_node=get_resource(&(resources->mem_head), (ulong)base);
2541 /* allocate the resource to the board */
2543 base = (u32)mem_node->base;
2544 mem_node->next = *res_node;
2545 *res_node = mem_node;
2546 dbg("Got 32 %s base=0x%x(length=0x%x)\n", res_type_str, mem_node->base,
2549 err("Got NO 32 %s resource(length=0x%x)\n", res_type_str, base);
2553 case PCI_BASE_ADDRESS_MEM_TYPE_64:
2554 rc = pci_bus_read_config_dword(pci_bus, devfn, cloop+4, &temp_register2);
2555 dbg("NEED 64 %s bar=0x%x:%x(length=0x%x)\n", res_type_str, temp_register2,
2556 temp_register, base);
2558 if (prefetchable && resources->p_mem_head)
2559 mem_node = get_resource(&(resources->p_mem_head), (ulong)base);
2562 dbg("using MEM for PMEM\n");
2563 mem_node = get_resource(&(resources->mem_head), (ulong)base);
2566 /* allocate the resource to the board */
2568 base64 = mem_node->base;
2569 mem_node->next = *res_node;
2570 *res_node = mem_node;
2571 dbg("Got 64 %s base=0x%x:%x(length=%x)\n", res_type_str, (u32)(base64 >> 32),
2572 (u32)base64, mem_node->length);
2574 err("Got NO 64 %s resource(length=0x%x)\n", res_type_str, base);
2579 dbg("reserved BAR type=0x%x\n", temp_register);
2586 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, (u32)base64);
2591 dbg("%s: high dword of base64(0x%x) set to 0\n", __FUNCTION__, (u32)base64);
2595 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, (u32)base64);
2597 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, base);
2599 } /* End of base register loop */
2601 /* disable ROM base Address */
2603 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_ROM_ADDRESS, temp_word);
2605 /* Set HP parameters (Cache Line Size, Latency Timer) */
2606 rc = pciehprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_NORMAL);
2610 pciehprm_enable_card(ctrl, func, PCI_HEADER_TYPE_NORMAL);
2612 dbg("PCI function Hot-Added s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, func->device,
2614 } /* End of Not-A-Bridge else */
2616 /* It's some strange type of PCI adapter (Cardbus?) */
2617 return(DEVICE_TYPE_NOT_SUPPORTED);
2620 func->configured = 1;