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>
45 static u32 configure_new_device(struct controller *ctrl, struct pci_func *func,
46 u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev);
47 static int configure_new_function( struct controller *ctrl, struct pci_func *func,
48 u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev);
49 static void interrupt_event_handler(struct controller *ctrl);
51 static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
52 static struct semaphore event_exit; /* guard ensure thread has exited before calling it quits */
53 static int event_finished;
54 static unsigned long pushbutton_pending; /* = 0 */
55 static unsigned long surprise_rm_pending; /* = 0 */
57 u8 pciehp_handle_attention_button(u8 hp_slot, void *inst_id)
59 struct controller *ctrl = (struct controller *) inst_id;
63 struct pci_func *func;
64 struct event_info *taskInfo;
66 /* Attention Button Change */
67 dbg("pciehp: Attention button interrupt received.\n");
69 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
71 /* This is the structure that tells the worker thread what to do */
72 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
73 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
75 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
76 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
78 ctrl->next_event = (ctrl->next_event + 1) % 10;
79 taskInfo->hp_slot = hp_slot;
84 * Button pressed - See if need to TAKE ACTION!!!
86 info("Button pressed on Slot(%d)\n", ctrl->first_slot + hp_slot);
87 taskInfo->event_type = INT_BUTTON_PRESS;
89 if ((p_slot->state == BLINKINGON_STATE)
90 || (p_slot->state == BLINKINGOFF_STATE)) {
91 /* Cancel if we are still blinking; this means that we press the
92 * attention again before the 5 sec. limit expires to cancel hot-add
95 taskInfo->event_type = INT_BUTTON_CANCEL;
96 info("Button cancel on Slot(%d)\n", ctrl->first_slot + hp_slot);
97 } else if ((p_slot->state == POWERON_STATE)
98 || (p_slot->state == POWEROFF_STATE)) {
99 /* Ignore if the slot is on power-on or power-off state; this
100 * means that the previous attention button action to hot-add or
101 * hot-remove is undergoing
103 taskInfo->event_type = INT_BUTTON_IGNORE;
104 info("Button ignore on Slot(%d)\n", ctrl->first_slot + hp_slot);
108 up(&event_semaphore); /* signal event thread that new event is posted */
114 u8 pciehp_handle_switch_change(u8 hp_slot, void *inst_id)
116 struct controller *ctrl = (struct controller *) inst_id;
120 struct pci_func *func;
121 struct event_info *taskInfo;
124 dbg("pciehp: Switch interrupt received.\n");
126 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
128 /* This is the structure that tells the worker thread
131 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
132 ctrl->next_event = (ctrl->next_event + 1) % 10;
133 taskInfo->hp_slot = hp_slot;
136 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
137 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
138 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
144 info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot);
145 func->switch_save = 0;
146 taskInfo->event_type = INT_SWITCH_OPEN;
151 info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot);
152 func->switch_save = 0x10;
153 taskInfo->event_type = INT_SWITCH_CLOSE;
157 up(&event_semaphore); /* signal event thread that new event is posted */
162 u8 pciehp_handle_presence_change(u8 hp_slot, void *inst_id)
164 struct controller *ctrl = (struct controller *) inst_id;
167 struct pci_func *func;
168 struct event_info *taskInfo;
170 /* Presence Change */
171 dbg("pciehp: Presence/Notify input change.\n");
173 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
175 /* This is the structure that tells the worker thread
178 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
179 ctrl->next_event = (ctrl->next_event + 1) % 10;
180 taskInfo->hp_slot = hp_slot;
183 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
185 /* Switch is open, assume a presence change
186 * Save the presence state
188 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
189 if (func->presence_save) {
193 info("Card present on Slot(%d)\n", ctrl->first_slot + hp_slot);
194 taskInfo->event_type = INT_PRESENCE_ON;
199 info("Card not present on Slot(%d)\n", ctrl->first_slot + hp_slot);
200 taskInfo->event_type = INT_PRESENCE_OFF;
204 up(&event_semaphore); /* signal event thread that new event is posted */
209 u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id)
211 struct controller *ctrl = (struct controller *) inst_id;
214 struct pci_func *func;
215 struct event_info *taskInfo;
218 dbg("pciehp: Power fault interrupt received.\n");
220 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
222 /* this is the structure that tells the worker thread
225 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
226 ctrl->next_event = (ctrl->next_event + 1) % 10;
227 taskInfo->hp_slot = hp_slot;
230 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
232 if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) {
234 * power fault Cleared
236 info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot);
238 taskInfo->event_type = INT_POWER_FAULT_CLEAR;
243 info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot);
244 taskInfo->event_type = INT_POWER_FAULT;
245 /* set power fault status for this board */
247 info("power fault bit %x set\n", hp_slot);
250 up(&event_semaphore); /* signal event thread that new event is posted */
257 * sort_by_size: sort nodes by their length, smallest first.
259 * @head: list to sort
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: return one unused resource node
358 * @head: list to scan
361 static struct pci_resource *
362 do_pre_bridge_resource_split(struct pci_resource **head,
363 struct pci_resource **orig_head, u32 alignment)
365 struct pci_resource *prevnode = NULL;
366 struct pci_resource *node;
367 struct pci_resource *split_node;
370 dbg("do_pre_bridge_resource_split\n");
372 if (!(*head) || !(*orig_head))
375 rc = pciehp_resource_sort_and_combine(head);
380 if ((*head)->base != (*orig_head)->base)
383 if ((*head)->length == (*orig_head)->length)
387 /* If we got here, there the bridge requires some of the resource, but
388 * we may be able to split some off of the front
392 if (node->length & (alignment -1)) {
393 /* this one isn't an aligned length, so we'll make a new entry
396 split_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
401 temp_dword = (node->length | (alignment-1)) + 1 - alignment;
403 split_node->base = node->base;
404 split_node->length = temp_dword;
406 node->length -= temp_dword;
407 node->base += split_node->length;
409 /* Put it in the list */
411 split_node->next = node;
414 if (node->length < alignment)
422 while (prevnode->next != node)
423 prevnode = prevnode->next;
425 prevnode->next = node->next;
434 * do_bridge_resource_split: return one unused resource node
435 * @head: list to scan
438 static struct pci_resource *
439 do_bridge_resource_split(struct pci_resource **head, u32 alignment)
441 struct pci_resource *prevnode = NULL;
442 struct pci_resource *node;
449 rc = pciehp_resource_sort_and_combine(head);
462 if (node->length < alignment) {
467 if (node->base & (alignment - 1)) {
468 /* Short circuit if adjusted size is too small */
469 temp_dword = (node->base | (alignment-1)) + 1;
470 if ((node->length - (temp_dword - node->base)) < alignment) {
475 node->length -= (temp_dword - node->base);
476 node->base = temp_dword;
479 if (node->length & (alignment - 1)) {
480 /* There's stuff in use after this node */
492 * this function sorts the resource list by size and then
493 * returns the first node of "size" length that is not in the
494 * ISA aliasing window. If it finds a node larger than "size"
495 * it will split it up.
497 * size must be a power of two.
499 static struct pci_resource *get_io_resource(struct pci_resource **head, u32 size)
501 struct pci_resource *prevnode;
502 struct pci_resource *node;
503 struct pci_resource *split_node = NULL;
509 if ( pciehp_resource_sort_and_combine(head) )
512 if ( sort_by_size(head) )
515 for (node = *head; node; node = node->next) {
516 if (node->length < size)
519 if (node->base & (size - 1)) {
520 /* this one isn't base aligned properly
521 so we'll make a new entry and split it up */
522 temp_dword = (node->base | (size-1)) + 1;
524 /*/ Short circuit if adjusted size is too small */
525 if ((node->length - (temp_dword - node->base)) < size)
528 split_node = kmalloc(sizeof(struct pci_resource),
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 = kmalloc(sizeof(struct pci_resource),
554 split_node->base = node->base + size;
555 split_node->length = node->length - size;
558 /* Put it in the list */
559 split_node->next = node->next;
560 node->next = split_node;
561 } /* End of too big on top end */
563 /* For IO make sure it's not in the ISA aliasing space */
564 if (node->base & 0x300L)
567 /* If we got here, then it is the right size
568 Now take it out of the list */
573 while (prevnode->next != node)
574 prevnode = prevnode->next;
576 prevnode->next = node->next;
590 * Gets the largest node that is at least "size" big from the
591 * list pointed to by head. It aligns the node on top and bottom
592 * to "size" alignment before returning it.
593 * J.I. modified to put max size limits of; 64M->32M->16M->8M->4M->1M
594 * This is needed to avoid allocating entire ACPI _CRS res to one child bridge/slot.
596 static struct pci_resource *get_max_resource(struct pci_resource **head, u32 size)
598 struct pci_resource *max;
599 struct pci_resource *temp;
600 struct pci_resource *split_node;
602 u32 max_size[] = { 0x4000000, 0x2000000, 0x1000000, 0x0800000, 0x0400000, 0x0200000, 0x0100000, 0x00 };
608 if (pciehp_resource_sort_and_combine(head))
611 if (sort_by_max_size(head))
614 for (max = *head;max; max = max->next) {
616 /* If not big enough we could probably just bail,
617 instead we'll continue to the next. */
618 if (max->length < size)
621 if (max->base & (size - 1)) {
622 /* this one isn't base aligned properly
623 so we'll make a new entry and split it up */
624 temp_dword = (max->base | (size-1)) + 1;
626 /* Short circuit if adjusted size is too small */
627 if ((max->length - (temp_dword - max->base)) < size)
630 split_node = kmalloc(sizeof(struct pci_resource),
636 split_node->base = max->base;
637 split_node->length = temp_dword - max->base;
638 max->base = temp_dword;
639 max->length -= split_node->length;
641 /* Put it next in the list */
642 split_node->next = max->next;
643 max->next = split_node;
646 if ((max->base + max->length) & (size - 1)) {
647 /* this one isn't end aligned properly at the top
648 so we'll make a new entry and split it up */
649 split_node = kmalloc(sizeof(struct pci_resource),
654 temp_dword = ((max->base + max->length) & ~(size - 1));
655 split_node->base = temp_dword;
656 split_node->length = max->length + max->base
658 max->length -= split_node->length;
660 /* Put it in the list */
661 split_node->next = max->next;
662 max->next = split_node;
665 /* Make sure it didn't shrink too much when we aligned it */
666 if (max->length < size)
669 for ( i = 0; max_size[i] > size; i++) {
670 if (max->length > max_size[i]) {
671 split_node = kmalloc(sizeof(struct pci_resource),
674 break; /* return NULL; */
675 split_node->base = max->base + max_size[i];
676 split_node->length = max->length - max_size[i];
677 max->length = max_size[i];
678 /* Put it next in the list */
679 split_node->next = max->next;
680 max->next = split_node;
685 /* Now take it out of the list */
686 temp = (struct pci_resource*) *head;
690 while (temp && temp->next != max) {
694 temp->next = max->next;
701 /* If we get here, we couldn't find one */
709 * this function sorts the resource list by size and then
710 * returns the first node of "size" length. If it finds a node
711 * larger than "size" it will split it up.
713 * size must be a power of two.
715 static struct pci_resource *get_resource(struct pci_resource **head, u32 size)
717 struct pci_resource *prevnode;
718 struct pci_resource *node;
719 struct pci_resource *split_node;
725 if ( pciehp_resource_sort_and_combine(head) )
728 if ( sort_by_size(head) )
731 for (node = *head; node; node = node->next) {
732 dbg("%s: req_size =0x%x node=%p, base=0x%x, length=0x%x\n",
733 __FUNCTION__, size, node, node->base, node->length);
734 if (node->length < size)
737 if (node->base & (size - 1)) {
738 dbg("%s: not aligned\n", __FUNCTION__);
739 /* this one isn't base aligned properly
740 so we'll make a new entry and split it up */
741 temp_dword = (node->base | (size-1)) + 1;
743 /* Short circuit if adjusted size is too small */
744 if ((node->length - (temp_dword - node->base)) < size)
747 split_node = kmalloc(sizeof(struct pci_resource),
753 split_node->base = node->base;
754 split_node->length = temp_dword - node->base;
755 node->base = temp_dword;
756 node->length -= split_node->length;
758 /* Put it in the list */
759 split_node->next = node->next;
760 node->next = split_node;
761 } /* End of non-aligned base */
763 /* Don't need to check if too small since we already did */
764 if (node->length > size) {
765 dbg("%s: too big\n", __FUNCTION__);
766 /* this one is longer than we need
767 so we'll make a new entry and split it up */
768 split_node = kmalloc(sizeof(struct pci_resource),
774 split_node->base = node->base + size;
775 split_node->length = node->length - size;
778 /* Put it in the list */
779 split_node->next = node->next;
780 node->next = split_node;
781 } /* End of too big on top end */
783 dbg("%s: got one!!!\n", __FUNCTION__);
784 /* If we got here, then it is the right size
785 Now take it out of the list */
790 while (prevnode->next != node)
791 prevnode = prevnode->next;
793 prevnode->next = node->next;
804 * pciehp_resource_sort_and_combine
806 * Sorts all of the nodes in the list in ascending order by
807 * their base addresses. Also does garbage collection by
808 * combining adjacent nodes.
810 * returns 0 if success
812 int pciehp_resource_sort_and_combine(struct pci_resource **head)
814 struct pci_resource *node1;
815 struct pci_resource *node2;
816 int out_of_order = 1;
818 dbg("%s: head = %p, *head = %p\n", __FUNCTION__, head, *head);
823 dbg("*head->next = %p\n",(*head)->next);
826 return 0; /* only one item on the list, already sorted! */
828 dbg("*head->base = 0x%x\n",(*head)->base);
829 dbg("*head->next->base = 0x%x\n",(*head)->next->base);
830 while (out_of_order) {
833 /* Special case for swapping list head */
834 if (((*head)->next) &&
835 ((*head)->base > (*head)->next->base)) {
837 (*head) = (*head)->next;
838 node1->next = (*head)->next;
839 (*head)->next = node1;
845 while (node1->next && node1->next->next) {
846 if (node1->next->base > node1->next->next->base) {
849 node1->next = node1->next->next;
851 node2->next = node1->next;
856 } /* End of out_of_order loop */
860 while (node1 && node1->next) {
861 if ((node1->base + node1->length) == node1->next->base) {
864 node1->length += node1->next->length;
866 node1->next = node1->next->next;
877 * pciehp_slot_create - Creates a node and adds it to the proper bus.
878 * @busnumber - bus where new node is to be located
880 * Returns pointer to the new node or NULL if unsuccessful
882 struct pci_func *pciehp_slot_create(u8 busnumber)
884 struct pci_func *new_slot;
885 struct pci_func *next;
886 dbg("%s: busnumber %x\n", __FUNCTION__, busnumber);
887 new_slot = kmalloc(sizeof(struct pci_func), GFP_KERNEL);
889 if (new_slot == NULL)
892 memset(new_slot, 0, sizeof(struct pci_func));
894 new_slot->next = NULL;
895 new_slot->configured = 1;
897 if (pciehp_slot_list[busnumber] == NULL) {
898 pciehp_slot_list[busnumber] = new_slot;
900 next = pciehp_slot_list[busnumber];
901 while (next->next != NULL)
903 next->next = new_slot;
910 * slot_remove - Removes a node from the linked list of slots.
911 * @old_slot: slot to remove
913 * Returns 0 if successful, !0 otherwise.
915 static int slot_remove(struct pci_func * old_slot)
917 struct pci_func *next;
919 if (old_slot == NULL)
922 next = pciehp_slot_list[old_slot->bus];
927 if (next == old_slot) {
928 pciehp_slot_list[old_slot->bus] = old_slot->next;
929 pciehp_destroy_board_resources(old_slot);
934 while ((next->next != old_slot) && (next->next != NULL)) {
938 if (next->next == old_slot) {
939 next->next = old_slot->next;
940 pciehp_destroy_board_resources(old_slot);
949 * bridge_slot_remove - Removes a node from the linked list of slots.
950 * @bridge: bridge to remove
952 * Returns 0 if successful, !0 otherwise.
954 static int bridge_slot_remove(struct pci_func *bridge)
956 u8 subordinateBus, secondaryBus;
958 struct pci_func *next;
963 secondaryBus = (bridge->config_space[0x06] >> 8) & 0xFF;
964 subordinateBus = (bridge->config_space[0x06] >> 16) & 0xFF;
966 for (tempBus = secondaryBus; tempBus <= subordinateBus; tempBus++) {
967 next = pciehp_slot_list[tempBus];
969 while (!slot_remove(next)) {
970 next = pciehp_slot_list[tempBus];
974 next = pciehp_slot_list[bridge->bus];
980 if (next == bridge) {
981 pciehp_slot_list[bridge->bus] = bridge->next;
986 while ((next->next != bridge) && (next->next != NULL)) {
990 if (next->next == bridge) {
991 next->next = bridge->next;
1000 * pciehp_slot_find - Looks for a node by bus, and device, multiple functions accessed
1002 * @device: device to find
1003 * @index: is 0 for first function found, 1 for the second...
1005 * Returns pointer to the node if successful, %NULL otherwise.
1007 struct pci_func *pciehp_slot_find(u8 bus, u8 device, u8 index)
1010 struct pci_func *func;
1012 func = pciehp_slot_list[bus];
1013 dbg("%s: bus %x device %x index %x\n",
1014 __FUNCTION__, bus, device, index);
1016 dbg("%s: func-> bus %x device %x function %x pci_dev %p\n",
1017 __FUNCTION__, func->bus, func->device, func->function,
1020 dbg("%s: func == NULL\n", __FUNCTION__);
1022 if ((func == NULL) || ((func->device == device) && (index == 0)))
1025 if (func->device == device)
1028 while (func->next != NULL) {
1031 dbg("%s: In while loop, func-> bus %x device %x function %x pci_dev %p\n",
1032 __FUNCTION__, func->bus, func->device, func->function,
1034 if (func->device == device)
1036 dbg("%s: while loop, found %d, index %d\n", __FUNCTION__,
1039 if ((found == index) || (func->function == index)) {
1040 dbg("%s: Found bus %x dev %x func %x\n", __FUNCTION__,
1041 func->bus, func->device, func->function);
1049 static int is_bridge(struct pci_func * func)
1051 /* Check the header type */
1052 if (((func->config_space[0x03] >> 16) & 0xFF) == 0x01)
1059 /* The following routines constitute the bulk of the
1060 hotplug controller logic
1063 static void set_slot_off(struct controller *ctrl, struct slot * pslot)
1065 /* Wait for exclusive access to hardware */
1066 down(&ctrl->crit_sect);
1068 /* turn off slot, turn on Amber LED, turn off Green LED if supported*/
1069 if (POWER_CTRL(ctrl->ctrlcap)) {
1070 if (pslot->hpc_ops->power_off_slot(pslot)) {
1071 err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);
1072 up(&ctrl->crit_sect);
1075 wait_for_ctrl_irq (ctrl);
1078 if (PWR_LED(ctrl->ctrlcap)) {
1079 pslot->hpc_ops->green_led_off(pslot);
1080 wait_for_ctrl_irq (ctrl);
1083 if (ATTN_LED(ctrl->ctrlcap)) {
1084 if (pslot->hpc_ops->set_attention_status(pslot, 1)) {
1085 err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);
1086 up(&ctrl->crit_sect);
1089 wait_for_ctrl_irq (ctrl);
1092 /* Done with exclusive hardware access */
1093 up(&ctrl->crit_sect);
1097 * board_added - Called after a board has been added to the system.
1099 * Turns power on for the board
1103 static u32 board_added(struct pci_func * func, struct controller * ctrl)
1107 u32 temp_register = 0xFFFFFFFF;
1109 struct pci_func *new_func = NULL;
1110 struct slot *p_slot;
1111 struct resource_lists res_lists;
1113 p_slot = pciehp_find_slot(ctrl, func->device);
1114 hp_slot = func->device - ctrl->slot_device_offset;
1116 dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n", __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot);
1118 /* Wait for exclusive access to hardware */
1119 down(&ctrl->crit_sect);
1121 if (POWER_CTRL(ctrl->ctrlcap)) {
1123 rc = p_slot->hpc_ops->power_on_slot(p_slot);
1125 up(&ctrl->crit_sect);
1129 /* Wait for the command to complete */
1130 wait_for_ctrl_irq (ctrl);
1133 if (PWR_LED(ctrl->ctrlcap)) {
1134 p_slot->hpc_ops->green_led_blink(p_slot);
1136 /* Wait for the command to complete */
1137 wait_for_ctrl_irq (ctrl);
1140 /* Done with exclusive hardware access */
1141 up(&ctrl->crit_sect);
1143 /* Wait for ~1 second */
1144 dbg("%s: before long_delay\n", __FUNCTION__);
1145 wait_for_ctrl_irq (ctrl);
1146 dbg("%s: afterlong_delay\n", __FUNCTION__);
1148 /* Check link training status */
1149 rc = p_slot->hpc_ops->check_lnk_status(ctrl);
1151 err("%s: Failed to check link status\n", __FUNCTION__);
1152 set_slot_off(ctrl, p_slot);
1156 dbg("%s: func status = %x\n", __FUNCTION__, func->status);
1158 /* Check for a power fault */
1159 if (func->status == 0xFF) {
1160 /* power fault occurred, but it was benign */
1161 temp_register = 0xFFFFFFFF;
1162 dbg("%s: temp register set to %x by power fault\n", __FUNCTION__, temp_register);
1166 /* Get vendor/device ID u32 */
1167 rc = pci_bus_read_config_dword (ctrl->pci_dev->subordinate, PCI_DEVFN(func->device, func->function),
1168 PCI_VENDOR_ID, &temp_register);
1169 dbg("%s: pci_bus_read_config_dword returns %d\n", __FUNCTION__, rc);
1170 dbg("%s: temp_register is %x\n", __FUNCTION__, temp_register);
1173 /* Something's wrong here */
1174 temp_register = 0xFFFFFFFF;
1175 dbg("%s: temp register set to %x by error\n", __FUNCTION__, temp_register);
1177 /* Preset return code. It will be changed later if things go okay. */
1178 rc = NO_ADAPTER_PRESENT;
1181 /* All F's is an empty slot or an invalid board */
1182 if (temp_register != 0xFFFFFFFF) { /* Check for a board in the slot */
1183 res_lists.io_head = ctrl->io_head;
1184 res_lists.mem_head = ctrl->mem_head;
1185 res_lists.p_mem_head = ctrl->p_mem_head;
1186 res_lists.bus_head = ctrl->bus_head;
1187 res_lists.irqs = NULL;
1189 rc = configure_new_device(ctrl, func, 0, &res_lists, 0, 0);
1190 dbg("%s: back from configure_new_device\n", __FUNCTION__);
1192 ctrl->io_head = res_lists.io_head;
1193 ctrl->mem_head = res_lists.mem_head;
1194 ctrl->p_mem_head = res_lists.p_mem_head;
1195 ctrl->bus_head = res_lists.bus_head;
1197 pciehp_resource_sort_and_combine(&(ctrl->mem_head));
1198 pciehp_resource_sort_and_combine(&(ctrl->p_mem_head));
1199 pciehp_resource_sort_and_combine(&(ctrl->io_head));
1200 pciehp_resource_sort_and_combine(&(ctrl->bus_head));
1203 set_slot_off(ctrl, p_slot);
1206 pciehp_save_slot_config(ctrl, func);
1209 func->switch_save = 0x10;
1210 func->is_a_board = 0x01;
1212 /* next, we will instantiate the linux pci_dev structures
1213 * (with appropriate driver notification, if already present)
1217 new_func = pciehp_slot_find(ctrl->slot_bus, func->device, index++);
1218 if (new_func && !new_func->pci_dev) {
1219 dbg("%s:call pci_hp_configure_dev, func %x\n",
1220 __FUNCTION__, index);
1221 pciehp_configure_device(ctrl, new_func);
1226 * Some PCI Express root ports require fixup after hot-plug operation.
1229 pci_fixup_device(pci_fixup_final, ctrl->pci_dev);
1231 if (PWR_LED(ctrl->ctrlcap)) {
1232 /* Wait for exclusive access to hardware */
1233 down(&ctrl->crit_sect);
1235 p_slot->hpc_ops->green_led_on(p_slot);
1237 /* Wait for the command to complete */
1238 wait_for_ctrl_irq (ctrl);
1240 /* Done with exclusive hardware access */
1241 up(&ctrl->crit_sect);
1244 set_slot_off(ctrl, p_slot);
1252 * remove_board - Turns off slot and LED's
1255 static u32 remove_board(struct pci_func *func, struct controller *ctrl)
1262 struct resource_lists res_lists;
1263 struct pci_func *temp_func;
1264 struct slot *p_slot;
1269 if (pciehp_unconfigure_device(func))
1272 device = func->device;
1274 hp_slot = func->device - ctrl->slot_device_offset;
1275 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
1277 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
1279 if ((ctrl->add_support) &&
1280 !(func->bus_head || func->mem_head || func->p_mem_head || func->io_head)) {
1281 /* Here we check to see if we've saved any of the board's
1282 * resources already. If so, we'll skip the attempt to
1283 * determine what's being used.
1289 while ((temp_func = pciehp_slot_find(temp_func->bus, temp_func->device, index++))) {
1290 if (temp_func->bus_head || temp_func->mem_head
1291 || temp_func->p_mem_head || temp_func->io_head) {
1298 rc = pciehp_save_used_resources(ctrl, func, DISABLE_CARD);
1300 /* Change status to shutdown */
1301 if (func->is_a_board)
1302 func->status = 0x01;
1303 func->configured = 0;
1305 /* Wait for exclusive access to hardware */
1306 down(&ctrl->crit_sect);
1308 if (POWER_CTRL(ctrl->ctrlcap)) {
1309 /* power off slot */
1310 rc = p_slot->hpc_ops->power_off_slot(p_slot);
1312 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
1313 up(&ctrl->crit_sect);
1316 /* Wait for the command to complete */
1317 wait_for_ctrl_irq (ctrl);
1320 if (PWR_LED(ctrl->ctrlcap)) {
1321 /* turn off Green LED */
1322 p_slot->hpc_ops->green_led_off(p_slot);
1324 /* Wait for the command to complete */
1325 wait_for_ctrl_irq (ctrl);
1328 /* Done with exclusive hardware access */
1329 up(&ctrl->crit_sect);
1331 if (ctrl->add_support) {
1333 res_lists.io_head = ctrl->io_head;
1334 res_lists.mem_head = ctrl->mem_head;
1335 res_lists.p_mem_head = ctrl->p_mem_head;
1336 res_lists.bus_head = ctrl->bus_head;
1338 dbg("Returning resources to ctlr lists for (B/D/F) = (%#x/%#x/%#x)\n",
1339 func->bus, func->device, func->function);
1341 pciehp_return_board_resources(func, &res_lists);
1343 ctrl->io_head = res_lists.io_head;
1344 ctrl->mem_head = res_lists.mem_head;
1345 ctrl->p_mem_head = res_lists.p_mem_head;
1346 ctrl->bus_head = res_lists.bus_head;
1348 pciehp_resource_sort_and_combine(&(ctrl->mem_head));
1349 pciehp_resource_sort_and_combine(&(ctrl->p_mem_head));
1350 pciehp_resource_sort_and_combine(&(ctrl->io_head));
1351 pciehp_resource_sort_and_combine(&(ctrl->bus_head));
1353 if (is_bridge(func)) {
1354 dbg("PCI Bridge Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n",
1355 ctrl->seg, func->bus, func->device, func->function);
1356 bridge_slot_remove(func);
1358 dbg("PCI Function Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n",
1359 ctrl->seg, func->bus, func->device, func->function);
1362 func = pciehp_slot_find(ctrl->slot_bus, device, 0);
1365 /* Setup slot structure with entry for empty slot */
1366 func = pciehp_slot_create(ctrl->slot_bus);
1372 func->bus = ctrl->slot_bus;
1373 func->device = device;
1375 func->configured = 0;
1376 func->switch_save = 0x10;
1377 func->is_a_board = 0;
1384 static void pushbutton_helper_thread(unsigned long data)
1386 pushbutton_pending = data;
1388 up(&event_semaphore);
1392 * pciehp_pushbutton_thread
1394 * Scheduled procedure to handle blocking stuff for the pushbuttons
1395 * Handles all pending events and exits.
1398 static void pciehp_pushbutton_thread(unsigned long slot)
1400 struct slot *p_slot = (struct slot *) slot;
1403 pushbutton_pending = 0;
1406 dbg("%s: Error! slot NULL\n", __FUNCTION__);
1410 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1412 p_slot->state = POWEROFF_STATE;
1413 dbg("In power_down_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
1415 pciehp_disable_slot(p_slot);
1416 p_slot->state = STATIC_STATE;
1418 p_slot->state = POWERON_STATE;
1419 dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
1421 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
1422 /* Wait for exclusive access to hardware */
1423 down(&p_slot->ctrl->crit_sect);
1425 p_slot->hpc_ops->green_led_off(p_slot);
1427 /* Wait for the command to complete */
1428 wait_for_ctrl_irq (p_slot->ctrl);
1430 /* Done with exclusive hardware access */
1431 up(&p_slot->ctrl->crit_sect);
1433 p_slot->state = STATIC_STATE;
1440 * pciehp_surprise_rm_thread
1442 * Scheduled procedure to handle blocking stuff for the surprise removal
1443 * Handles all pending events and exits.
1446 static void pciehp_surprise_rm_thread(unsigned long slot)
1448 struct slot *p_slot = (struct slot *) slot;
1451 surprise_rm_pending = 0;
1454 dbg("%s: Error! slot NULL\n", __FUNCTION__);
1458 p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
1460 p_slot->state = POWEROFF_STATE;
1461 dbg("In removing board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
1463 pciehp_disable_slot(p_slot);
1464 p_slot->state = STATIC_STATE;
1466 p_slot->state = POWERON_STATE;
1467 dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
1469 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
1470 /* Wait for exclusive access to hardware */
1471 down(&p_slot->ctrl->crit_sect);
1473 p_slot->hpc_ops->green_led_off(p_slot);
1475 /* Wait for the command to complete */
1476 wait_for_ctrl_irq (p_slot->ctrl);
1478 /* Done with exclusive hardware access */
1479 up(&p_slot->ctrl->crit_sect);
1481 p_slot->state = STATIC_STATE;
1489 /* this is the main worker thread */
1490 static int event_thread(void* data)
1492 struct controller *ctrl;
1494 daemonize("pciehpd_event");
1499 dbg("!!!!event_thread sleeping\n");
1500 down_interruptible (&event_semaphore);
1501 dbg("event_thread woken finished = %d\n", event_finished);
1502 if (event_finished || signal_pending(current))
1505 if (pushbutton_pending)
1506 pciehp_pushbutton_thread(pushbutton_pending);
1507 else if (surprise_rm_pending)
1508 pciehp_surprise_rm_thread(surprise_rm_pending);
1510 for (ctrl = pciehp_ctrl_list; ctrl; ctrl=ctrl->next)
1511 interrupt_event_handler(ctrl);
1513 dbg("event_thread signals exit\n");
1518 int pciehp_event_start_thread(void)
1522 /* initialize our semaphores */
1523 init_MUTEX_LOCKED(&event_exit);
1526 init_MUTEX_LOCKED(&event_semaphore);
1527 pid = kernel_thread(event_thread, NULL, 0);
1530 err ("Can't start up our event thread\n");
1533 dbg("Our event thread pid = %d\n", pid);
1538 void pciehp_event_stop_thread(void)
1541 dbg("event_thread finish command given\n");
1542 up(&event_semaphore);
1543 dbg("wait for event_thread to exit\n");
1548 static int update_slot_info(struct slot *slot)
1550 struct hotplug_slot_info *info;
1551 /* char buffer[SLOT_NAME_SIZE]; */
1554 info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
1558 /* make_slot_name (&buffer[0], SLOT_NAME_SIZE, slot); */
1560 slot->hpc_ops->get_power_status(slot, &(info->power_status));
1561 slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
1562 slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
1563 slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
1565 /* result = pci_hp_change_slot_info(buffer, info); */
1566 result = pci_hp_change_slot_info(slot->hotplug_slot, info);
1571 static void interrupt_event_handler(struct controller *ctrl)
1575 struct pci_func *func;
1578 struct slot *p_slot;
1583 for (loop = 0; loop < 10; loop++) {
1584 if (ctrl->event_queue[loop].event_type != 0) {
1585 hp_slot = ctrl->event_queue[loop].hp_slot;
1587 func = pciehp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
1589 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
1591 dbg("hp_slot %d, func %p, p_slot %p\n", hp_slot, func, p_slot);
1593 if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {
1594 dbg("button cancel\n");
1595 del_timer(&p_slot->task_event);
1597 switch (p_slot->state) {
1598 case BLINKINGOFF_STATE:
1599 /* Wait for exclusive access to hardware */
1600 down(&ctrl->crit_sect);
1602 if (PWR_LED(ctrl->ctrlcap)) {
1603 p_slot->hpc_ops->green_led_on(p_slot);
1604 /* Wait for the command to complete */
1605 wait_for_ctrl_irq (ctrl);
1607 if (ATTN_LED(ctrl->ctrlcap)) {
1608 p_slot->hpc_ops->set_attention_status(p_slot, 0);
1610 /* Wait for the command to complete */
1611 wait_for_ctrl_irq (ctrl);
1613 /* Done with exclusive hardware access */
1614 up(&ctrl->crit_sect);
1616 case BLINKINGON_STATE:
1617 /* Wait for exclusive access to hardware */
1618 down(&ctrl->crit_sect);
1620 if (PWR_LED(ctrl->ctrlcap)) {
1621 p_slot->hpc_ops->green_led_off(p_slot);
1622 /* Wait for the command to complete */
1623 wait_for_ctrl_irq (ctrl);
1625 if (ATTN_LED(ctrl->ctrlcap)){
1626 p_slot->hpc_ops->set_attention_status(p_slot, 0);
1627 /* Wait for the command to complete */
1628 wait_for_ctrl_irq (ctrl);
1630 /* Done with exclusive hardware access */
1631 up(&ctrl->crit_sect);
1635 warn("Not a valid state\n");
1638 info(msg_button_cancel, p_slot->number);
1639 p_slot->state = STATIC_STATE;
1641 /* ***********Button Pressed (No action on 1st press...) */
1642 else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {
1644 if (ATTN_BUTTN(ctrl->ctrlcap)) {
1645 dbg("Button pressed\n");
1646 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1649 dbg("slot is on\n");
1650 p_slot->state = BLINKINGOFF_STATE;
1651 info(msg_button_off, p_slot->number);
1654 dbg("slot is off\n");
1655 p_slot->state = BLINKINGON_STATE;
1656 info(msg_button_on, p_slot->number);
1659 /* Wait for exclusive access to hardware */
1660 down(&ctrl->crit_sect);
1662 /* blink green LED and turn off amber */
1663 if (PWR_LED(ctrl->ctrlcap)) {
1664 p_slot->hpc_ops->green_led_blink(p_slot);
1665 /* Wait for the command to complete */
1666 wait_for_ctrl_irq (ctrl);
1669 if (ATTN_LED(ctrl->ctrlcap)) {
1670 p_slot->hpc_ops->set_attention_status(p_slot, 0);
1672 /* Wait for the command to complete */
1673 wait_for_ctrl_irq (ctrl);
1676 /* Done with exclusive hardware access */
1677 up(&ctrl->crit_sect);
1679 init_timer(&p_slot->task_event);
1680 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
1681 p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;
1682 p_slot->task_event.data = (unsigned long) p_slot;
1684 dbg("add_timer p_slot = %p\n", (void *) p_slot);
1685 add_timer(&p_slot->task_event);
1688 /***********POWER FAULT********************/
1689 else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
1690 if (POWER_CTRL(ctrl->ctrlcap)) {
1691 dbg("power fault\n");
1692 /* Wait for exclusive access to hardware */
1693 down(&ctrl->crit_sect);
1695 if (ATTN_LED(ctrl->ctrlcap)) {
1696 p_slot->hpc_ops->set_attention_status(p_slot, 1);
1697 wait_for_ctrl_irq (ctrl);
1700 if (PWR_LED(ctrl->ctrlcap)) {
1701 p_slot->hpc_ops->green_led_off(p_slot);
1702 wait_for_ctrl_irq (ctrl);
1705 /* Done with exclusive hardware access */
1706 up(&ctrl->crit_sect);
1709 /***********SURPRISE REMOVAL********************/
1710 else if ((ctrl->event_queue[loop].event_type == INT_PRESENCE_ON) ||
1711 (ctrl->event_queue[loop].event_type == INT_PRESENCE_OFF)) {
1712 if (HP_SUPR_RM(ctrl->ctrlcap)) {
1713 dbg("Surprise Removal\n");
1715 surprise_rm_pending = (unsigned long) p_slot;
1716 up(&event_semaphore);
1717 update_slot_info(p_slot);
1721 /* refresh notification */
1723 update_slot_info(p_slot);
1726 ctrl->event_queue[loop].event_type = 0;
1730 } /* End of FOR loop */
1735 int pciehp_enable_slot(struct slot *p_slot)
1739 struct pci_func *func;
1741 func = pciehp_slot_find(p_slot->bus, p_slot->device, 0);
1743 dbg("%s: Error! slot NULL\n", __FUNCTION__);
1747 /* Check to see if (latch closed, card present, power off) */
1748 down(&p_slot->ctrl->crit_sect);
1750 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
1751 if (rc || !getstatus) {
1752 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
1753 up(&p_slot->ctrl->crit_sect);
1756 if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
1757 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1758 if (rc || getstatus) {
1759 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
1760 up(&p_slot->ctrl->crit_sect);
1765 if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
1766 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1767 if (rc || getstatus) {
1768 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
1769 up(&p_slot->ctrl->crit_sect);
1773 up(&p_slot->ctrl->crit_sect);
1777 func = pciehp_slot_create(p_slot->bus);
1781 func->bus = p_slot->bus;
1782 func->device = p_slot->device;
1784 func->configured = 0;
1785 func->is_a_board = 1;
1787 /* We have to save the presence info for these slots */
1788 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
1789 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1790 func->switch_save = !getstatus? 0x10:0;
1792 rc = board_added(func, p_slot->ctrl);
1794 if (is_bridge(func))
1795 bridge_slot_remove(func);
1799 /* Setup slot structure with entry for empty slot */
1800 func = pciehp_slot_create(p_slot->bus);
1802 return 1; /* Out of memory */
1804 func->bus = p_slot->bus;
1805 func->device = p_slot->device;
1807 func->configured = 0;
1808 func->is_a_board = 1;
1810 /* We have to save the presence info for these slots */
1811 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
1812 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1813 func->switch_save = !getstatus? 0x10:0;
1817 update_slot_info(p_slot);
1823 int pciehp_disable_slot(struct slot *p_slot)
1825 u8 class_code, header_type, BCR;
1831 struct pci_bus *pci_bus = p_slot->ctrl->pci_dev->subordinate;
1832 struct pci_func *func;
1837 /* Check to see if (latch closed, card present, power on) */
1838 down(&p_slot->ctrl->crit_sect);
1840 if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) {
1841 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
1842 if (ret || !getstatus) {
1843 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
1844 up(&p_slot->ctrl->crit_sect);
1849 if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
1850 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1851 if (ret || getstatus) {
1852 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
1853 up(&p_slot->ctrl->crit_sect);
1858 if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
1859 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1860 if (ret || !getstatus) {
1861 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
1862 up(&p_slot->ctrl->crit_sect);
1867 up(&p_slot->ctrl->crit_sect);
1869 func = pciehp_slot_find(p_slot->bus, p_slot->device, index++);
1871 /* Make sure there are no video controllers here
1872 * for all func of p_slot
1874 while (func && !rc) {
1875 pci_bus->number = func->bus;
1876 devfn = PCI_DEVFN(func->device, func->function);
1878 /* Check the Class Code */
1879 rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
1883 if (class_code == PCI_BASE_CLASS_DISPLAY) {
1884 /* Display/Video adapter (not supported) */
1885 rc = REMOVE_NOT_SUPPORTED;
1887 /* See if it's a bridge */
1888 rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &header_type);
1892 /* If it's a bridge, check the VGA Enable bit */
1893 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
1894 rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_BRIDGE_CONTROL, &BCR);
1898 /* If the VGA Enable bit is set, remove isn't supported */
1899 if (BCR & PCI_BRIDGE_CTL_VGA) {
1900 rc = REMOVE_NOT_SUPPORTED;
1905 func = pciehp_slot_find(p_slot->bus, p_slot->device, index++);
1908 func = pciehp_slot_find(p_slot->bus, p_slot->device, 0);
1909 if ((func != NULL) && !rc) {
1910 rc = remove_board(func, p_slot->ctrl);
1915 update_slot_info(p_slot);
1922 * configure_new_device - Configures the PCI header information of one board.
1924 * @ctrl: pointer to controller structure
1925 * @func: pointer to function structure
1926 * @behind_bridge: 1 if this is a recursive call, 0 if not
1927 * @resources: pointer to set of resource lists
1929 * Returns 0 if success
1932 static u32 configure_new_device(struct controller * ctrl, struct pci_func * func,
1933 u8 behind_bridge, struct resource_lists * resources, u8 bridge_bus, u8 bridge_dev)
1935 u8 temp_byte, function, max_functions, stop_it;
1938 struct pci_func *new_slot;
1939 struct pci_bus lpci_bus, *pci_bus;
1944 dbg("%s\n", __FUNCTION__);
1945 memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));
1946 pci_bus = &lpci_bus;
1947 pci_bus->number = func->bus;
1949 /* Check for Multi-function device */
1950 rc = pci_bus_read_config_byte(pci_bus, PCI_DEVFN(func->device, func->function), 0x0E, &temp_byte);
1952 dbg("%s: rc = %d\n", __FUNCTION__, rc);
1956 if (temp_byte & 0x80) /* Multi-function device */
1964 rc = configure_new_function(ctrl, new_slot, behind_bridge,
1965 resources, bridge_bus, bridge_dev);
1968 dbg("configure_new_function failed: %d\n", rc);
1972 new_slot = pciehp_slot_find(new_slot->bus,
1973 new_slot->device, index++);
1976 pciehp_return_board_resources(new_slot,
1987 /* The following loop skips to the next present function
1988 * and creates a board structure
1991 while ((function < max_functions) && (!stop_it)) {
1992 pci_bus_read_config_dword(pci_bus, PCI_DEVFN(func->device, function), 0x00, &ID);
1994 if (ID == 0xFFFFFFFF) { /* There's nothing there. */
1996 } else { /* There's something there */
1997 /* Setup slot structure. */
1998 new_slot = pciehp_slot_create(func->bus);
2000 if (new_slot == NULL) {
2005 new_slot->bus = func->bus;
2006 new_slot->device = func->device;
2007 new_slot->function = function;
2008 new_slot->is_a_board = 1;
2009 new_slot->status = 0;
2015 } while (function < max_functions);
2016 dbg("returning from %s\n", __FUNCTION__);
2022 * Configuration logic that involves the hotplug data structures and
2027 * configure_bridge: fill bridge's registers, either configure or disable it.
2030 configure_bridge(struct pci_bus *pci_bus, unsigned int devfn,
2031 struct pci_resource *mem_node,
2032 struct pci_resource **hold_mem_node,
2033 int base_addr, int limit_addr)
2039 memcpy(*hold_mem_node, mem_node, sizeof(struct pci_resource));
2040 mem_node->next = NULL;
2042 /* set Mem base and Limit registers */
2043 RES_CHECK(mem_node->base, 16);
2044 temp_word = (u16)(mem_node->base >> 16);
2045 rc = pci_bus_write_config_word(pci_bus, devfn, base_addr, temp_word);
2047 RES_CHECK(mem_node->base + mem_node->length - 1, 16);
2048 temp_word = (u16)((mem_node->base + mem_node->length - 1) >> 16);
2049 rc = pci_bus_write_config_word(pci_bus, devfn, limit_addr, temp_word);
2052 rc = pci_bus_write_config_word(pci_bus, devfn, base_addr, temp_word);
2055 rc = pci_bus_write_config_word(pci_bus, devfn, limit_addr, temp_word);
2057 kfree(*hold_mem_node);
2058 *hold_mem_node = NULL;
2064 configure_new_bridge(struct controller *ctrl, struct pci_func *func,
2065 u8 behind_bridge, struct resource_lists *resources,
2066 struct pci_bus *pci_bus)
2075 struct pci_resource *mem_node;
2076 struct pci_resource *p_mem_node;
2077 struct pci_resource *io_node;
2078 struct pci_resource *bus_node;
2079 struct pci_resource *hold_mem_node;
2080 struct pci_resource *hold_p_mem_node;
2081 struct pci_resource *hold_IO_node;
2082 struct pci_resource *hold_bus_node;
2083 struct irq_mapping irqs;
2084 struct pci_func *new_slot;
2085 struct resource_lists temp_resources;
2087 devfn = PCI_DEVFN(func->device, func->function);
2089 /* set Primary bus */
2090 dbg("set Primary bus = 0x%x\n", func->bus);
2091 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_PRIMARY_BUS, func->bus);
2095 /* find range of busses to use */
2096 bus_node = get_max_resource(&resources->bus_head, 1L);
2098 /* If we don't have any busses to allocate, we can't continue */
2100 err("Got NO bus resource to use\n");
2103 dbg("Got ranges of buses to use: base:len=0x%x:%x\n", bus_node->base, bus_node->length);
2105 /* set Secondary bus */
2106 temp_byte = (u8)bus_node->base;
2107 dbg("set Secondary bus = 0x%x\n", temp_byte);
2108 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SECONDARY_BUS, temp_byte);
2112 /* set subordinate bus */
2113 temp_byte = (u8)(bus_node->base + bus_node->length - 1);
2114 dbg("set subordinate bus = 0x%x\n", temp_byte);
2115 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);
2119 /* Set HP parameters (Cache Line Size, Latency Timer) */
2120 rc = pciehprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_BRIDGE);
2124 /* Setup the IO, memory, and prefetchable windows */
2126 io_node = get_max_resource(&(resources->io_head), 0x1000L);
2128 dbg("io_node(base, len, next) (%x, %x, %p)\n", io_node->base,
2129 io_node->length, io_node->next);
2132 mem_node = get_max_resource(&(resources->mem_head), 0x100000L);
2134 dbg("mem_node(base, len, next) (%x, %x, %p)\n", mem_node->base,
2135 mem_node->length, mem_node->next);
2138 if (resources->p_mem_head)
2139 p_mem_node = get_max_resource(&(resources->p_mem_head), 0x100000L);
2142 * In some platform implementation, MEM and PMEM are not
2143 * distinguished, and hence ACPI _CRS has only MEM entries
2144 * for both MEM and PMEM.
2146 dbg("using MEM for PMEM\n");
2147 p_mem_node = get_max_resource(&(resources->mem_head), 0x100000L);
2150 dbg("p_mem_node(base, len, next) (%x, %x, %p)\n", p_mem_node->base,
2151 p_mem_node->length, p_mem_node->next);
2154 /* set up the IRQ info */
2155 if (!resources->irqs) {
2156 irqs.barber_pole = 0;
2157 irqs.interrupt[0] = 0;
2158 irqs.interrupt[1] = 0;
2159 irqs.interrupt[2] = 0;
2160 irqs.interrupt[3] = 0;
2163 irqs.barber_pole = resources->irqs->barber_pole;
2164 irqs.interrupt[0] = resources->irqs->interrupt[0];
2165 irqs.interrupt[1] = resources->irqs->interrupt[1];
2166 irqs.interrupt[2] = resources->irqs->interrupt[2];
2167 irqs.interrupt[3] = resources->irqs->interrupt[3];
2168 irqs.valid_INT = resources->irqs->valid_INT;
2171 /* set up resource lists that are now aligned on top and bottom
2172 * for anything behind the bridge.
2174 temp_resources.bus_head = bus_node;
2175 temp_resources.io_head = io_node;
2176 temp_resources.mem_head = mem_node;
2177 temp_resources.p_mem_head = p_mem_node;
2178 temp_resources.irqs = &irqs;
2180 /* Make copies of the nodes we are going to pass down so that
2181 * if there is a problem,we can just use these to free resources
2183 hold_bus_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2184 hold_IO_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2185 hold_mem_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2186 hold_p_mem_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
2188 if (!hold_bus_node || !hold_IO_node || !hold_mem_node || !hold_p_mem_node) {
2189 kfree(hold_bus_node);
2190 kfree(hold_IO_node);
2191 kfree(hold_mem_node);
2192 kfree(hold_p_mem_node);
2197 memcpy(hold_bus_node, bus_node, sizeof(struct pci_resource));
2199 bus_node->base += 1;
2200 bus_node->length -= 1;
2201 bus_node->next = NULL;
2203 /* If we have IO resources copy them and fill in the bridge's
2204 * IO range registers
2207 memcpy(hold_IO_node, io_node, sizeof(struct pci_resource));
2208 io_node->next = NULL;
2210 /* set IO base and Limit registers */
2211 RES_CHECK(io_node->base, 8);
2212 temp_byte = (u8)(io_node->base >> 8);
2213 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_BASE, temp_byte);
2215 RES_CHECK(io_node->base + io_node->length - 1, 8);
2216 temp_byte = (u8)((io_node->base + io_node->length - 1) >> 8);
2217 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2219 kfree(hold_IO_node);
2220 hold_IO_node = NULL;
2223 /* If we have memory resources copy them and fill in the bridge's
2224 * memory range registers. Otherwise, fill in the range
2225 * registers with values that disable them.
2227 rc = configure_bridge(pci_bus, devfn, mem_node, &hold_mem_node,
2228 PCI_MEMORY_BASE, PCI_MEMORY_LIMIT);
2230 /* If we have prefetchable memory resources copy them and
2231 * fill in the bridge's memory range registers. Otherwise,
2232 * fill in the range registers with values that disable them.
2234 rc = configure_bridge(pci_bus, devfn, p_mem_node, &hold_p_mem_node,
2235 PCI_PREF_MEMORY_BASE, PCI_PREF_MEMORY_LIMIT);
2237 /* Adjust this to compensate for extra adjustment in first loop */
2242 /* Here we actually find the devices and configure them */
2243 for (device = 0; (device <= 0x1F) && !rc; device++) {
2244 irqs.barber_pole = (irqs.barber_pole + 1) & 0x03;
2247 pci_bus->number = hold_bus_node->base;
2248 pci_bus_read_config_dword (pci_bus, PCI_DEVFN(device, 0), PCI_VENDOR_ID, &ID);
2249 pci_bus->number = func->bus;
2251 if (ID != 0xFFFFFFFF) { /* device Present */
2252 /* Setup slot structure. */
2253 new_slot = pciehp_slot_create(hold_bus_node->base);
2255 if (new_slot == NULL) {
2261 new_slot->bus = hold_bus_node->base;
2262 new_slot->device = device;
2263 new_slot->function = 0;
2264 new_slot->is_a_board = 1;
2265 new_slot->status = 0;
2267 rc = configure_new_device(ctrl, new_slot, 1,
2268 &temp_resources, func->bus,
2270 dbg("configure_new_device rc=0x%x\n",rc);
2271 } /* End of IF (device in slot?) */
2272 } /* End of FOR loop */
2275 pciehp_destroy_resource_list(&temp_resources);
2277 return_resource(&(resources->bus_head), hold_bus_node);
2278 return_resource(&(resources->io_head), hold_IO_node);
2279 return_resource(&(resources->mem_head), hold_mem_node);
2280 return_resource(&(resources->p_mem_head), hold_p_mem_node);
2284 /* save the interrupt routing information */
2285 if (resources->irqs) {
2286 resources->irqs->interrupt[0] = irqs.interrupt[0];
2287 resources->irqs->interrupt[1] = irqs.interrupt[1];
2288 resources->irqs->interrupt[2] = irqs.interrupt[2];
2289 resources->irqs->interrupt[3] = irqs.interrupt[3];
2290 resources->irqs->valid_INT = irqs.valid_INT;
2291 } else if (!behind_bridge) {
2292 /* We need to hook up the interrupts here */
2293 for (cloop = 0; cloop < 4; cloop++) {
2294 if (irqs.valid_INT & (0x01 << cloop)) {
2295 rc = pciehp_set_irq(func->bus, func->device,
2296 0x0A + cloop, irqs.interrupt[cloop]);
2298 pciehp_destroy_resource_list (&temp_resources);
2299 return_resource(&(resources->bus_head), hold_bus_node);
2300 return_resource(&(resources->io_head), hold_IO_node);
2301 return_resource(&(resources->mem_head), hold_mem_node);
2302 return_resource(&(resources->p_mem_head), hold_p_mem_node);
2306 } /* end of for loop */
2309 /* Return unused bus resources
2310 * First use the temporary node to store information for the board
2312 if (hold_bus_node && bus_node && temp_resources.bus_head) {
2313 hold_bus_node->length = bus_node->base - hold_bus_node->base;
2315 hold_bus_node->next = func->bus_head;
2316 func->bus_head = hold_bus_node;
2318 temp_byte = (u8)(temp_resources.bus_head->base - 1);
2320 /* set subordinate bus */
2321 dbg("re-set subordinate bus = 0x%x\n", temp_byte);
2322 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);
2324 if (temp_resources.bus_head->length == 0) {
2325 kfree(temp_resources.bus_head);
2326 temp_resources.bus_head = NULL;
2328 dbg("return bus res of b:d(0x%x:%x) base:len(0x%x:%x)\n",
2329 func->bus, func->device, temp_resources.bus_head->base, temp_resources.bus_head->length);
2330 return_resource(&(resources->bus_head), temp_resources.bus_head);
2334 /* If we have IO space available and there is some left,
2335 * return the unused portion
2337 if (hold_IO_node && temp_resources.io_head) {
2338 io_node = do_pre_bridge_resource_split(&(temp_resources.io_head),
2339 &hold_IO_node, 0x1000);
2341 /* Check if we were able to split something off */
2343 hold_IO_node->base = io_node->base + io_node->length;
2345 RES_CHECK(hold_IO_node->base, 8);
2346 temp_byte = (u8)((hold_IO_node->base) >> 8);
2347 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_BASE, temp_byte);
2349 return_resource(&(resources->io_head), io_node);
2352 io_node = do_bridge_resource_split(&(temp_resources.io_head), 0x1000);
2354 /* Check if we were able to split something off */
2356 /* First use the temporary node to store information for the board */
2357 hold_IO_node->length = io_node->base - hold_IO_node->base;
2359 /* If we used any, add it to the board's list */
2360 if (hold_IO_node->length) {
2361 hold_IO_node->next = func->io_head;
2362 func->io_head = hold_IO_node;
2364 RES_CHECK(io_node->base - 1, 8);
2365 temp_byte = (u8)((io_node->base - 1) >> 8);
2366 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2368 return_resource(&(resources->io_head), io_node);
2370 /* it doesn't need any IO */
2372 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2374 return_resource(&(resources->io_head), io_node);
2375 kfree(hold_IO_node);
2378 /* it used most of the range */
2379 hold_IO_node->next = func->io_head;
2380 func->io_head = hold_IO_node;
2382 } else if (hold_IO_node) {
2383 /* it used the whole range */
2384 hold_IO_node->next = func->io_head;
2385 func->io_head = hold_IO_node;
2388 /* If we have memory space available and there is some left,
2389 * return the unused portion
2391 if (hold_mem_node && temp_resources.mem_head) {
2392 mem_node = do_pre_bridge_resource_split(&(temp_resources.mem_head), &hold_mem_node, 0x100000L);
2394 /* Check if we were able to split something off */
2396 hold_mem_node->base = mem_node->base + mem_node->length;
2398 RES_CHECK(hold_mem_node->base, 16);
2399 temp_word = (u16)((hold_mem_node->base) >> 16);
2400 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_BASE, temp_word);
2402 return_resource(&(resources->mem_head), mem_node);
2405 mem_node = do_bridge_resource_split(&(temp_resources.mem_head), 0x100000L);
2407 /* Check if we were able to split something off */
2409 /* First use the temporary node to store information for the board */
2410 hold_mem_node->length = mem_node->base - hold_mem_node->base;
2412 if (hold_mem_node->length) {
2413 hold_mem_node->next = func->mem_head;
2414 func->mem_head = hold_mem_node;
2416 /* configure end address */
2417 RES_CHECK(mem_node->base - 1, 16);
2418 temp_word = (u16)((mem_node->base - 1) >> 16);
2419 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2421 /* Return unused resources to the pool */
2422 return_resource(&(resources->mem_head), mem_node);
2424 /* it doesn't need any Mem */
2426 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2428 return_resource(&(resources->mem_head), mem_node);
2429 kfree(hold_mem_node);
2432 /* it used most of the range */
2433 hold_mem_node->next = func->mem_head;
2434 func->mem_head = hold_mem_node;
2436 } else if (hold_mem_node) {
2437 /* it used the whole range */
2438 hold_mem_node->next = func->mem_head;
2439 func->mem_head = hold_mem_node;
2442 /* If we have prefetchable memory space available and there is some
2443 * left at the end, return the unused portion
2445 if (hold_p_mem_node && temp_resources.p_mem_head) {
2446 p_mem_node = do_pre_bridge_resource_split(&(temp_resources.p_mem_head),
2447 &hold_p_mem_node, 0x100000L);
2449 /* Check if we were able to split something off */
2451 hold_p_mem_node->base = p_mem_node->base + p_mem_node->length;
2453 RES_CHECK(hold_p_mem_node->base, 16);
2454 temp_word = (u16)((hold_p_mem_node->base) >> 16);
2455 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
2457 return_resource(&(resources->p_mem_head), p_mem_node);
2460 p_mem_node = do_bridge_resource_split(&(temp_resources.p_mem_head), 0x100000L);
2462 /* Check if we were able to split something off */
2464 /* First use the temporary node to store information for the board */
2465 hold_p_mem_node->length = p_mem_node->base - hold_p_mem_node->base;
2467 /* If we used any, add it to the board's list */
2468 if (hold_p_mem_node->length) {
2469 hold_p_mem_node->next = func->p_mem_head;
2470 func->p_mem_head = hold_p_mem_node;
2472 RES_CHECK(p_mem_node->base - 1, 16);
2473 temp_word = (u16)((p_mem_node->base - 1) >> 16);
2474 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2476 return_resource(&(resources->p_mem_head), p_mem_node);
2478 /* it doesn't need any PMem */
2480 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2482 return_resource(&(resources->p_mem_head), p_mem_node);
2483 kfree(hold_p_mem_node);
2486 /* it used the most of the range */
2487 hold_p_mem_node->next = func->p_mem_head;
2488 func->p_mem_head = hold_p_mem_node;
2490 } else if (hold_p_mem_node) {
2491 /* it used the whole range */
2492 hold_p_mem_node->next = func->p_mem_head;
2493 func->p_mem_head = hold_p_mem_node;
2496 /* We should be configuring an IRQ and the bridge's base address
2497 * registers if it needs them. Although we have never seen such
2501 pciehprm_enable_card(ctrl, func, PCI_HEADER_TYPE_BRIDGE);
2503 dbg("PCI Bridge Hot-Added s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, func->device, func->function);
2509 * configure_new_function - Configures the PCI header information of one device
2511 * @ctrl: pointer to controller structure
2512 * @func: pointer to function structure
2513 * @behind_bridge: 1 if this is a recursive call, 0 if not
2514 * @resources: pointer to set of resource lists
2516 * Calls itself recursively for bridged devices.
2517 * Returns 0 if success
2521 configure_new_function(struct controller *ctrl, struct pci_func *func,
2522 u8 behind_bridge, struct resource_lists *resources,
2523 u8 bridge_bus, u8 bridge_dev)
2533 struct pci_resource *mem_node;
2534 struct pci_resource *io_node;
2535 struct pci_bus lpci_bus, *pci_bus;
2537 memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));
2538 pci_bus = &lpci_bus;
2539 pci_bus->number = func->bus;
2540 devfn = PCI_DEVFN(func->device, func->function);
2542 /* Check for Bridge */
2543 rc = pci_bus_read_config_byte(pci_bus, devfn, PCI_HEADER_TYPE, &temp_byte);
2546 dbg("%s: bus %x dev %x func %x temp_byte = %x\n", __FUNCTION__,
2547 func->bus, func->device, func->function, temp_byte);
2549 if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { /* PCI-PCI Bridge */
2550 rc = configure_new_bridge(ctrl, func, behind_bridge, resources,
2555 } else if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_NORMAL) {
2556 /* Standard device */
2558 rc = pci_bus_read_config_byte(pci_bus, devfn, 0x0B, &class_code);
2560 if (class_code == PCI_BASE_CLASS_DISPLAY)
2561 return DEVICE_TYPE_NOT_SUPPORTED;
2563 /* Figure out IO and memory needs */
2564 for (cloop = PCI_BASE_ADDRESS_0; cloop <= PCI_BASE_ADDRESS_5; cloop += 4) {
2565 temp_register = 0xFFFFFFFF;
2567 rc = pci_bus_write_config_dword (pci_bus, devfn, cloop, temp_register);
2568 rc = pci_bus_read_config_dword(pci_bus, devfn, cloop, &temp_register);
2569 dbg("Bar[%x]=0x%x on bus:dev:func(0x%x:%x:%x)\n", cloop, temp_register,
2570 func->bus, func->device, func->function);
2576 if (temp_register & PCI_BASE_ADDRESS_SPACE_IO) {
2579 /* set base = amount of IO space */
2580 base = temp_register & 0xFFFFFFFC;
2583 dbg("NEED IO length(0x%x)\n", base);
2584 io_node = get_io_resource(&(resources->io_head),(ulong)base);
2586 /* allocate the resource to the board */
2588 dbg("Got IO base=0x%x(length=0x%x)\n", io_node->base, io_node->length);
2589 base = (u32)io_node->base;
2590 io_node->next = func->io_head;
2591 func->io_head = io_node;
2593 err("Got NO IO resource(length=0x%x)\n", base);
2596 } else { /* map MEM */
2597 int prefetchable = 1;
2598 struct pci_resource **res_node = &func->p_mem_head;
2599 char *res_type_str = "PMEM";
2602 if (!(temp_register & PCI_BASE_ADDRESS_MEM_PREFETCH)) {
2604 res_node = &func->mem_head;
2608 base = temp_register & 0xFFFFFFF0;
2611 switch (temp_register & PCI_BASE_ADDRESS_MEM_TYPE_MASK) {
2612 case PCI_BASE_ADDRESS_MEM_TYPE_32:
2613 dbg("NEED 32 %s bar=0x%x(length=0x%x)\n", res_type_str, temp_register, base);
2615 if (prefetchable && resources->p_mem_head)
2616 mem_node=get_resource(&(resources->p_mem_head), (ulong)base);
2619 dbg("using MEM for PMEM\n");
2620 mem_node = get_resource(&(resources->mem_head), (ulong)base);
2623 /* allocate the resource to the board */
2625 base = (u32)mem_node->base;
2626 mem_node->next = *res_node;
2627 *res_node = mem_node;
2628 dbg("Got 32 %s base=0x%x(length=0x%x)\n", res_type_str, mem_node->base,
2631 err("Got NO 32 %s resource(length=0x%x)\n", res_type_str, base);
2635 case PCI_BASE_ADDRESS_MEM_TYPE_64:
2636 rc = pci_bus_read_config_dword(pci_bus, devfn, cloop+4, &temp_register2);
2637 dbg("NEED 64 %s bar=0x%x:%x(length=0x%x)\n", res_type_str, temp_register2,
2638 temp_register, base);
2640 if (prefetchable && resources->p_mem_head)
2641 mem_node = get_resource(&(resources->p_mem_head), (ulong)base);
2644 dbg("using MEM for PMEM\n");
2645 mem_node = get_resource(&(resources->mem_head), (ulong)base);
2648 /* allocate the resource to the board */
2650 base64 = mem_node->base;
2651 mem_node->next = *res_node;
2652 *res_node = mem_node;
2653 dbg("Got 64 %s base=0x%x:%x(length=%x)\n", res_type_str, (u32)(base64 >> 32),
2654 (u32)base64, mem_node->length);
2656 err("Got NO 64 %s resource(length=0x%x)\n", res_type_str, base);
2661 dbg("reserved BAR type=0x%x\n", temp_register);
2668 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, (u32)base64);
2673 dbg("%s: high dword of base64(0x%x) set to 0\n", __FUNCTION__, (u32)base64);
2677 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, (u32)base64);
2679 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, base);
2681 } /* End of base register loop */
2683 /* disable ROM base Address */
2685 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_ROM_ADDRESS, temp_word);
2687 /* Set HP parameters (Cache Line Size, Latency Timer) */
2688 rc = pciehprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_NORMAL);
2692 pciehprm_enable_card(ctrl, func, PCI_HEADER_TYPE_NORMAL);
2694 dbg("PCI function Hot-Added s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, func->device,
2696 } /* End of Not-A-Bridge else */
2698 /* It's some strange type of PCI adapter (Cardbus?) */
2699 return DEVICE_TYPE_NOT_SUPPORTED;
2702 func->configured = 1;