29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/slab.h>
36 #include <linux/wait.h>
37 #include <linux/pci.h>
50 static unsigned long pushbutton_pending;
66 #define WRONG_BUS_FREQUENCY 0x07
79 dbg(
"cpqsbd: Switch interrupt received.\n");
81 for (hp_slot = 0; hp_slot < 6; hp_slot++) {
82 if (change & (0x1L << hp_slot)) {
134 while (slot && (slot->
device != device))
157 dbg(
"cpqsbd: Presence/Notify input change.\n");
158 dbg(
" Changed bits are 0x%4.4x\n", change );
160 for (hp_slot = 0; hp_slot < 6; hp_slot++) {
161 if (change & (0x0101 << hp_slot)) {
183 temp_byte = (temp_word >>
hp_slot) & 0x01;
184 temp_byte |= (temp_word >> (hp_slot + 7)) & 0x02;
190 dbg(
"hp_slot %d button pressed\n", hp_slot);
196 dbg(
"hp_slot %d button released\n", hp_slot);
203 dbg(
"hp_slot %d button cancel\n", hp_slot);
208 dbg(
"hp_slot %d button ignore\n", hp_slot);
249 info(
"power fault interrupt\n");
251 for (hp_slot = 0; hp_slot < 6; hp_slot++) {
252 if (change & (0x01 << hp_slot)) {
279 amber_LED_on (ctrl, hp_slot);
280 green_LED_off (ctrl, hp_slot);
298 info(
"power fault bit %x set\n", hp_slot);
316 int out_of_order = 1;
321 if (!((*head)->next))
324 while (out_of_order) {
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;
346 current_res->
next = next_res;
348 current_res = current_res->
next;
364 int out_of_order = 1;
369 if (!((*head)->next))
372 while (out_of_order) {
376 if (((*head)->next) &&
377 ((*head)->length < (*head)->next->length)) {
380 *head = (*head)->
next;
381 current_res->
next = (*head)->next;
382 (*head)->next = current_res;
387 while (current_res->
next && current_res->
next->next) {
388 if (current_res->
next->length < current_res->
next->next->length) {
390 next_res = current_res->
next;
391 current_res->
next = current_res->
next->next;
392 current_res = current_res->
next;
394 current_res->
next = next_res;
396 current_res = current_res->
next;
418 dbg(
"do_pre_bridge_resource_split\n");
420 if (!(*head) || !(*orig_head))
428 if ((*head)->base != (*orig_head)->base)
431 if ((*head)->length == (*orig_head)->length)
441 if (node->
length & (alignment -1)) {
453 split_node->
length = temp_dword;
455 node->
length -= temp_dword;
463 if (node->
length < alignment)
471 while (prevnode->
next != node)
472 prevnode = prevnode->
next;
507 if (node->
length < alignment)
510 if (node->
base & (alignment - 1)) {
512 temp_dword = (node->
base | (alignment-1)) + 1;
513 if ((node->
length - (temp_dword - node->
base)) < alignment)
517 node->
base = temp_dword;
520 if (node->
length & (alignment - 1))
553 if (sort_by_size(head))
556 for (node = *head;
node; node = node->
next) {
560 if (node->
base & (size - 1)) {
564 temp_dword = (node->
base | (size-1)) + 1;
567 if ((node->
length - (temp_dword - node->
base)) < size)
577 node->
base = temp_dword;
582 node->
next = split_node;
586 if (node->
length > size) {
601 node->
next = split_node;
605 if (node->
base & 0x300L)
615 while (prevnode->
next != node)
616 prevnode = prevnode->
next;
647 if (sort_by_max_size(head))
650 for (max = *head;
max; max = max->
next) {
657 if (max->
base & (size - 1)) {
661 temp_dword = (max->
base | (size-1)) + 1;
664 if ((max->
length - (temp_dword - max->
base)) < size)
674 max->
base = temp_dword;
678 max->
next = split_node;
689 temp_dword = ((max->
base + max->
length) & ~(size - 1));
690 split_node->
base = temp_dword;
696 max->
next = split_node;
708 while (temp && temp->
next != max) {
744 if (sort_by_size(head))
747 for (node = *head;
node; node = node->
next) {
748 dbg(
"%s: req_size =%x node=%p, base=%x, length=%x\n",
749 __func__, size, node, node->
base, node->
length);
753 if (node->
base & (size - 1)) {
754 dbg(
"%s: not aligned\n", __func__);
758 temp_dword = (node->
base | (size-1)) + 1;
761 if ((node->
length - (temp_dword - node->
base)) < size)
771 node->
base = temp_dword;
775 node->
next = split_node;
779 if (node->
length > size) {
780 dbg(
"%s: too big\n", __func__);
795 node->
next = split_node;
798 dbg(
"%s: got one!!!\n", __func__);
805 while (prevnode->
next != node)
806 prevnode = prevnode->
next;
831 int out_of_order = 1;
833 dbg(
"%s: head = %p, *head = %p\n", __func__, head, *head);
838 dbg(
"*head->next = %p\n",(*head)->next);
843 dbg(
"*head->base = 0x%x\n",(*head)->base);
844 dbg(
"*head->next->base = 0x%x\n",(*head)->next->base);
845 while (out_of_order) {
849 if (((*head)->next) &&
850 ((*head)->base > (*head)->next->base)) {
852 (*head) = (*head)->next;
853 node1->
next = (*head)->next;
854 (*head)->next = node1;
860 while (node1->
next && node1->
next->next) {
861 if (node1->
next->base > node1->
next->next->base) {
875 while (node1 && node1->
next) {
894 u8 schedule_flag = 0;
905 if (!(misc & 0x000C)) {
921 dbg (
"%s - waking up\n", __func__);
941 schedule_flag += handle_switch_change((
u8)(Diff & 0xFFL), ctrl);
942 schedule_flag += handle_presence_change((
u16)((Diff & 0xFFFF0000L) >> 16), ctrl);
943 schedule_flag += handle_power_fault((
u8)((Diff & 0xFF00L) >> 8), ctrl);
957 dbg(
"Waking even thread");
974 new_slot = kzalloc(
sizeof(*new_slot),
GFP_KERNEL);
975 if (new_slot ==
NULL)
987 next->
next = new_slot;
999 static int slot_remove(
struct pci_func * old_slot)
1003 if (old_slot ==
NULL)
1010 if (next == old_slot) {
1017 while ((next->
next != old_slot) && (next->
next !=
NULL))
1020 if (next->
next == old_slot) {
1036 static int bridge_slot_remove(
struct pci_func *bridge)
1038 u8 subordinateBus, secondaryBus;
1042 secondaryBus = (bridge->
config_space[0x06] >> 8) & 0xFF;
1043 subordinateBus = (bridge->
config_space[0x06] >> 16) & 0xFF;
1045 for (tempBus = secondaryBus; tempBus <= subordinateBus; tempBus++) {
1048 while (!slot_remove(next))
1057 if (next == bridge) {
1065 if (next->
next != bridge)
1089 if ((func ==
NULL) || ((func->
device == device) && (index == 0)))
1092 if (func->
device == device)
1098 if (func->
device == device)
1111 static int is_bridge(
struct pci_func * func)
1130 static u8 set_controller_speed(
struct controller *ctrl,
u8 adapter_speed,
u8 hp_slot)
1145 for(slot = ctrl->
slot; slot; slot = slot->
next) {
1185 wait_for_ctrl_irq(ctrl);
1191 pci_write_config_byte(ctrl->
pci_dev, 0x41, reg);
1195 switch(adapter_speed) {
1225 pci_write_config_byte(ctrl->
pci_dev, 0x41, reg);
1229 pci_read_config_byte(ctrl->
pci_dev, 0x43, ®);
1230 pci_write_config_byte(ctrl->
pci_dev, 0x43, reg);
1237 wait_for_ctrl_irq(ctrl);
1245 wait_for_ctrl_irq(ctrl);
1250 info(
"Successfully changed frequency/mode for adapter in slot %d\n",
1289 else if (is_slot_enabled (ctrl, hp_slot))
1295 enable_slot_power (ctrl, hp_slot);
1300 wait_for_ctrl_irq (ctrl);
1311 wait_for_ctrl_irq (ctrl);
1313 adapter_speed = get_adapter_speed(ctrl, hp_slot);
1315 if (set_controller_speed(ctrl, adapter_speed, hp_slot))
1319 disable_slot_power (ctrl, hp_slot);
1324 wait_for_ctrl_irq (ctrl);
1334 green_LED_blink (ctrl, hp_slot);
1336 amber_LED_off (ctrl, hp_slot);
1341 wait_for_ctrl_irq (ctrl);
1349 if (func->
status == 0xFF) {
1370 amber_LED_on (ctrl, hp_slot);
1371 green_LED_off (ctrl, hp_slot);
1372 slot_disable (ctrl, hp_slot);
1377 wait_for_ctrl_irq (ctrl);
1396 amber_LED_on (ctrl, hp_slot);
1397 green_LED_off (ctrl, hp_slot);
1398 slot_disable (ctrl, hp_slot);
1403 wait_for_ctrl_irq (ctrl);
1428 u32 temp_register = 0xFFFFFFFF;
1432 struct slot *p_slot;
1436 dbg(
"%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n",
1442 enable_slot_power(ctrl, hp_slot);
1447 wait_for_ctrl_irq (ctrl);
1459 wait_for_ctrl_irq (ctrl);
1461 adapter_speed = get_adapter_speed(ctrl, hp_slot);
1463 if (set_controller_speed(ctrl, adapter_speed, hp_slot))
1467 disable_slot_power (ctrl, hp_slot);
1472 wait_for_ctrl_irq(ctrl);
1483 dbg(
"%s: before down\n", __func__);
1485 dbg(
"%s: after down\n", __func__);
1487 dbg(
"%s: before slot_enable\n", __func__);
1490 dbg(
"%s: before green_LED_blink\n", __func__);
1491 green_LED_blink (ctrl, hp_slot);
1493 dbg(
"%s: before amber_LED_blink\n", __func__);
1494 amber_LED_off (ctrl, hp_slot);
1496 dbg(
"%s: before set_SOGO\n", __func__);
1500 dbg(
"%s: before wait_for_ctrl_irq\n", __func__);
1501 wait_for_ctrl_irq (ctrl);
1502 dbg(
"%s: after wait_for_ctrl_irq\n", __func__);
1504 dbg(
"%s: before up\n", __func__);
1506 dbg(
"%s: after up\n", __func__);
1509 dbg(
"%s: before long_delay\n", __func__);
1511 dbg(
"%s: after long_delay\n", __func__);
1513 dbg(
"%s: func status = %x\n", __func__, func->
status);
1515 if (func->
status == 0xFF) {
1517 temp_register = 0xFFFFFFFF;
1518 dbg(
"%s: temp register set to %x by power fault\n", __func__, temp_register);
1525 dbg(
"%s: pci_read_config_dword returns %d\n", __func__, rc);
1526 dbg(
"%s: temp_register is %x\n", __func__, temp_register);
1530 temp_register = 0xFFFFFFFF;
1531 dbg(
"%s: temp register set to %x by error\n", __func__, temp_register);
1538 if (temp_register != 0xFFFFFFFF) {
1539 res_lists.io_head = ctrl->
io_head;
1540 res_lists.mem_head = ctrl->
mem_head;
1542 res_lists.bus_head = ctrl->
bus_head;
1543 res_lists.irqs =
NULL;
1545 rc = configure_new_device(ctrl, func, 0, &res_lists);
1547 dbg(
"%s: back from configure_new_device\n", __func__);
1548 ctrl->
io_head = res_lists.io_head;
1549 ctrl->
mem_head = res_lists.mem_head;
1551 ctrl->
bus_head = res_lists.bus_head;
1561 amber_LED_on (ctrl, hp_slot);
1562 green_LED_off (ctrl, hp_slot);
1563 slot_disable (ctrl, hp_slot);
1568 wait_for_ctrl_irq (ctrl);
1583 dbg(
"%s: configure linux pci_dev structure\n", __func__);
1587 if (new_slot && !new_slot->
pci_dev)
1593 green_LED_on (ctrl, hp_slot);
1598 wait_for_ctrl_irq (ctrl);
1604 amber_LED_on (ctrl, hp_slot);
1605 green_LED_off (ctrl, hp_slot);
1606 slot_disable (ctrl, hp_slot);
1611 wait_for_ctrl_irq (ctrl);
1644 dbg(
"In %s, hp_slot = %d\n", __func__, hp_slot);
1676 green_LED_off (ctrl, hp_slot);
1677 slot_disable (ctrl, hp_slot);
1683 temp_byte &= ~(0x01 << hp_slot);
1687 wait_for_ctrl_irq (ctrl);
1693 res_lists.io_head = ctrl->
io_head;
1694 res_lists.mem_head = ctrl->
mem_head;
1696 res_lists.bus_head = ctrl->
bus_head;
1700 ctrl->
io_head = res_lists.io_head;
1701 ctrl->
mem_head = res_lists.mem_head;
1703 ctrl->
bus_head = res_lists.bus_head;
1710 if (is_bridge(func)) {
1711 bridge_slot_remove(func);
1736 static void pushbutton_helper_thread(
unsigned long data)
1738 pushbutton_pending =
data;
1744 static int event_thread(
void*
data)
1749 dbg(
"!!!!event_thread sleeping\n");
1756 if (pushbutton_pending)
1760 interrupt_event_handler(ctrl);
1762 dbg(
"event_thread signals exit\n");
1769 if (IS_ERR(cpqhp_event_thread)) {
1770 err (
"Can't start up our event thread\n");
1771 return PTR_ERR(cpqhp_event_thread);
1784 static int update_slot_info(
struct controller *ctrl,
struct slot *slot)
1802 static void interrupt_event_handler(
struct controller *ctrl)
1808 struct slot *p_slot;
1813 for (loop = 0; loop < 10; loop++) {
1826 dbg(
"hp_slot %d, func %p, p_slot %p\n",
1827 hp_slot, func, p_slot);
1830 dbg(
"button pressed\n");
1833 dbg(
"button cancel\n");
1840 dbg(
"turn on green LED\n");
1841 green_LED_on (ctrl, hp_slot);
1844 dbg(
"turn off green LED\n");
1845 green_LED_off (ctrl, hp_slot);
1852 amber_LED_off (ctrl, hp_slot);
1857 wait_for_ctrl_irq (ctrl);
1863 dbg(
"button release\n");
1865 if (is_slot_enabled (ctrl, hp_slot)) {
1866 dbg(
"slot is on\n");
1870 dbg(
"slot is off\n");
1876 dbg(
"blink green LED and turn off amber\n");
1878 amber_LED_off (ctrl, hp_slot);
1879 green_LED_blink (ctrl, hp_slot);
1884 wait_for_ctrl_irq (ctrl);
1892 p_slot->
task_event.function = pushbutton_helper_thread;
1895 dbg(
"add_timer p_slot = %p\n", p_slot);
1900 dbg(
"power fault\n");
1904 update_slot_info(ctrl, p_slot);
1930 struct slot *p_slot = (
struct slot *) slot;
1933 pushbutton_pending = 0;
1938 if (is_slot_enabled(ctrl, hp_slot)) {
1942 dbg(
"In power_down_board, func = %p, ctrl = %p\n", func, ctrl);
1944 dbg(
"Error! func NULL in %s\n", __func__);
1949 amber_LED_on(ctrl, hp_slot);
1950 green_LED_on(ctrl, hp_slot);
1955 wait_for_ctrl_irq(ctrl);
1964 dbg(
"In add_board, func = %p, ctrl = %p\n", func, ctrl);
1966 dbg(
"Error! func NULL in %s\n", __func__);
1972 amber_LED_on(ctrl, hp_slot);
1973 green_LED_off(ctrl, hp_slot);
1978 wait_for_ctrl_irq (ctrl);
1995 struct slot* p_slot;
1996 int physical_slot = 0;
2002 p_slot = cpqhp_find_slot(ctrl, device);
2004 physical_slot = p_slot->
number;
2009 if (tempdword & (0x01 << hp_slot)) {
2014 rc = board_replaced(func, ctrl);
2040 rc = board_added(func, ctrl);
2042 if (is_bridge(func)) {
2043 bridge_slot_remove(func);
2063 (temp_word >> (hp_slot + 7)) & 0x02;
2074 dbg(
"%s: rc = %d\n", __func__, rc);
2078 update_slot_info(ctrl, p_slot);
2091 struct slot* p_slot;
2093 int physical_slot=0;
2097 p_slot = cpqhp_find_slot(ctrl, device);
2099 physical_slot = p_slot->
number;
2103 while (func && !rc) {
2108 rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
2117 rc = pci_bus_read_config_byte (pci_bus, devfn,
PCI_HEADER_TYPE, &header_type);
2138 if ((func !=
NULL) && !rc) {
2141 rc = remove_board(func, replace_flag, ctrl);
2147 update_slot_info(ctrl, p_slot);
2159 static void switch_leds(
struct controller *ctrl,
const int num_of_slots,
2164 for (loop = 0; loop < num_of_slots; loop++) {
2166 *work_LED = *work_LED >> 1;
2168 *work_LED = *work_LED << 1;
2174 wait_for_ctrl_irq(ctrl);
2204 work_LED = 0x01010101;
2205 switch_leds(ctrl, num_of_slots, &work_LED, 0);
2206 switch_leds(ctrl, num_of_slots, &work_LED, 1);
2207 switch_leds(ctrl, num_of_slots, &work_LED, 0);
2208 switch_leds(ctrl, num_of_slots, &work_LED, 1);
2210 work_LED = 0x01010000;
2212 switch_leds(ctrl, num_of_slots, &work_LED, 0);
2213 switch_leds(ctrl, num_of_slots, &work_LED, 1);
2214 work_LED = 0x00000101;
2216 switch_leds(ctrl, num_of_slots, &work_LED, 0);
2217 switch_leds(ctrl, num_of_slots, &work_LED, 1);
2219 work_LED = 0x01010000;
2221 for (loop = 0; loop < num_of_slots; loop++) {
2225 wait_for_ctrl_irq (ctrl);
2229 work_LED = work_LED >> 16;
2235 wait_for_ctrl_irq (ctrl);
2239 work_LED = work_LED << 16;
2241 work_LED = work_LED << 1;
2251 wait_for_ctrl_irq (ctrl);
2276 u8 temp_byte,
function, max_functions, stop_it;
2284 dbg(
"%s\n", __func__);
2289 dbg(
"%s: rc = %d\n", __func__, rc);
2293 if (temp_byte & 0x80)
2301 rc = configure_new_function(ctrl, new_slot, behind_bridge, resources);
2304 dbg(
"configure_new_function failed %d\n",rc);
2324 while ((
function < max_functions) && (!stop_it)) {
2327 if (ID == 0xFFFFFFFF) {
2333 if (new_slot ==
NULL)
2336 new_slot->
bus = func->
bus;
2346 }
while (
function < max_functions);
2347 dbg(
"returning from configure_new_device\n");
2400 pci_bus->number = func->
bus;
2404 rc = pci_bus_read_config_byte(pci_bus, devfn,
PCI_HEADER_TYPE, &temp_byte);
2410 dbg(
"set Primary bus = %d\n", func->
bus);
2416 dbg(
"find ranges of buses to use\n");
2417 bus_node = get_max_resource(&(resources->
bus_head), 1);
2424 temp_byte = bus_node->
base;
2425 dbg(
"set Secondary bus = %d\n", bus_node->
base);
2431 temp_byte = bus_node->
base + bus_node->
length - 1;
2432 dbg(
"set subordinate bus = %d\n", bus_node->
base + bus_node->
length - 1);
2453 io_node = get_max_resource(&(resources->
io_head), 0x1000);
2456 mem_node = get_max_resource(&(resources->
mem_head), 0x100000);
2459 p_mem_node = get_max_resource(&(resources->
p_mem_head), 0x100000);
2462 dbg(
"Setup the IO, memory, and prefetchable windows\n");
2464 dbg(
"(base, len, next) (%x, %x, %p)\n", io_node->
base,
2467 dbg(
"(base, len, next) (%x, %x, %p)\n", mem_node->
base,
2469 dbg(
"p_mem_node\n");
2470 dbg(
"(base, len, next) (%x, %x, %p)\n", p_mem_node->
base,
2474 if (!resources->
irqs) {
2475 irqs.barber_pole = 0;
2476 irqs.interrupt[0] = 0;
2477 irqs.interrupt[1] = 0;
2478 irqs.interrupt[2] = 0;
2479 irqs.interrupt[3] = 0;
2482 irqs.barber_pole = resources->
irqs->barber_pole;
2483 irqs.interrupt[0] = resources->
irqs->interrupt[0];
2484 irqs.interrupt[1] = resources->
irqs->interrupt[1];
2485 irqs.interrupt[2] = resources->
irqs->interrupt[2];
2486 irqs.interrupt[3] = resources->
irqs->interrupt[3];
2487 irqs.valid_INT = resources->
irqs->valid_INT;
2492 temp_resources.bus_head = bus_node;
2493 temp_resources.io_head = io_node;
2494 temp_resources.mem_head = mem_node;
2495 temp_resources.p_mem_head = p_mem_node;
2496 temp_resources.irqs = &
irqs;
2506 if (!hold_bus_node || !hold_IO_node || !hold_mem_node || !hold_p_mem_node) {
2507 kfree(hold_bus_node);
2508 kfree(hold_IO_node);
2509 kfree(hold_mem_node);
2510 kfree(hold_p_mem_node);
2517 bus_node->
base += 1;
2528 temp_byte = io_node->
base >> 8;
2529 rc = pci_bus_write_config_byte(pci_bus, devfn,
PCI_IO_BASE, temp_byte);
2531 temp_byte = (io_node->
base + io_node->
length - 1) >> 8;
2532 rc = pci_bus_write_config_byte(pci_bus, devfn,
PCI_IO_LIMIT, temp_byte);
2534 kfree(hold_IO_node);
2535 hold_IO_node =
NULL;
2546 temp_word = mem_node->
base >> 16;
2547 rc = pci_bus_write_config_word(pci_bus, devfn,
PCI_MEMORY_BASE, temp_word);
2549 temp_word = (mem_node->
base + mem_node->
length - 1) >> 16;
2550 rc = pci_bus_write_config_word(pci_bus, devfn,
PCI_MEMORY_LIMIT, temp_word);
2553 rc = pci_bus_write_config_word(pci_bus, devfn,
PCI_MEMORY_BASE, temp_word);
2556 rc = pci_bus_write_config_word(pci_bus, devfn,
PCI_MEMORY_LIMIT, temp_word);
2558 kfree(hold_mem_node);
2559 hold_mem_node =
NULL;
2566 temp_word = p_mem_node->
base >> 16;
2569 temp_word = (p_mem_node->
base + p_mem_node->
length - 1) >> 16;
2579 for (device = 0; (device <= 0x1F) && !rc; device++) {
2580 irqs.barber_pole = (
irqs.barber_pole + 1) & 0x03;
2583 pci_bus->number = hold_bus_node->
base;
2584 pci_bus_read_config_dword (pci_bus,
PCI_DEVFN(device, 0), 0x00, &ID);
2585 pci_bus->number = func->
bus;
2587 if (ID != 0xFFFFFFFF) {
2591 if (new_slot ==
NULL) {
2596 new_slot->
bus = hold_bus_node->
base;
2597 new_slot->
device = device;
2602 rc = configure_new_device(ctrl, new_slot, 1, &temp_resources);
2603 dbg(
"configure_new_device rc=0x%x\n",rc);
2610 if (resources->
irqs) {
2611 resources->
irqs->interrupt[0] =
irqs.interrupt[0];
2612 resources->
irqs->interrupt[1] =
irqs.interrupt[1];
2613 resources->
irqs->interrupt[2] =
irqs.interrupt[2];
2614 resources->
irqs->interrupt[3] =
irqs.interrupt[3];
2615 resources->
irqs->valid_INT =
irqs.valid_INT;
2616 }
else if (!behind_bridge) {
2618 for (cloop = 0; cloop < 4; cloop++) {
2619 if (
irqs.valid_INT & (0x01 << cloop)) {
2621 cloop + 1,
irqs.interrupt[cloop]);
2630 if (hold_bus_node && bus_node && temp_resources.bus_head) {
2636 temp_byte = temp_resources.bus_head->
base - 1;
2641 if (temp_resources.bus_head->length == 0) {
2642 kfree(temp_resources.bus_head);
2643 temp_resources.bus_head =
NULL;
2645 return_resource(&(resources->
bus_head), temp_resources.bus_head);
2651 if (hold_IO_node && temp_resources.io_head) {
2652 io_node = do_pre_bridge_resource_split(&(temp_resources.io_head),
2653 &hold_IO_node, 0x1000);
2659 temp_byte = (hold_IO_node->
base) >> 8;
2660 rc = pci_bus_write_config_word (pci_bus, devfn,
PCI_IO_BASE, temp_byte);
2662 return_resource(&(resources->
io_head), io_node);
2665 io_node = do_bridge_resource_split(&(temp_resources.io_head), 0x1000);
2674 if (hold_IO_node->
length) {
2678 temp_byte = (io_node->
base - 1) >> 8;
2679 rc = pci_bus_write_config_byte (pci_bus, devfn,
PCI_IO_LIMIT, temp_byte);
2681 return_resource(&(resources->
io_head), io_node);
2685 rc = pci_bus_write_config_word (pci_bus, devfn,
PCI_IO_LIMIT, temp_word);
2687 return_resource(&(resources->
io_head), io_node);
2688 kfree(hold_IO_node);
2695 }
else if (hold_IO_node) {
2702 if (hold_mem_node && temp_resources.mem_head) {
2703 mem_node = do_pre_bridge_resource_split(&(temp_resources.
mem_head),
2704 &hold_mem_node, 0x100000);
2710 temp_word = (hold_mem_node->
base) >> 16;
2711 rc = pci_bus_write_config_word (pci_bus, devfn,
PCI_MEMORY_BASE, temp_word);
2713 return_resource(&(resources->
mem_head), mem_node);
2716 mem_node = do_bridge_resource_split(&(temp_resources.mem_head), 0x100000);
2724 if (hold_mem_node->
length) {
2729 temp_word = (mem_node->
base - 1) >> 16;
2730 rc = pci_bus_write_config_word (pci_bus, devfn,
PCI_MEMORY_LIMIT, temp_word);
2733 return_resource(&(resources->
mem_head), mem_node);
2737 rc = pci_bus_write_config_word (pci_bus, devfn,
PCI_MEMORY_LIMIT, temp_word);
2739 return_resource(&(resources->
mem_head), mem_node);
2740 kfree(hold_mem_node);
2747 }
else if (hold_mem_node) {
2754 if (hold_p_mem_node && temp_resources.p_mem_head) {
2755 p_mem_node = do_pre_bridge_resource_split(&(temp_resources.p_mem_head),
2756 &hold_p_mem_node, 0x100000);
2762 temp_word = (hold_p_mem_node->
base) >> 16;
2765 return_resource(&(resources->
p_mem_head), p_mem_node);
2768 p_mem_node = do_bridge_resource_split(&(temp_resources.p_mem_head), 0x100000);
2774 hold_p_mem_node->
length = p_mem_node->
base - hold_p_mem_node->
base;
2777 if (hold_p_mem_node->
length) {
2781 temp_word = (p_mem_node->
base - 1) >> 16;
2784 return_resource(&(resources->
p_mem_head), p_mem_node);
2790 return_resource(&(resources->
p_mem_head), p_mem_node);
2791 kfree(hold_p_mem_node);
2798 }
else if (hold_p_mem_node) {
2814 rc = pci_bus_write_config_word (pci_bus, devfn,
PCI_COMMAND, command);
2823 rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
2830 for (cloop = 0x10; cloop <= 0x24; cloop += 4) {
2831 temp_register = 0xFFFFFFFF;
2833 dbg(
"CND: bus=%d, devfn=%d, offset=%d\n", pci_bus->number, devfn, cloop);
2834 rc = pci_bus_write_config_dword (pci_bus, devfn, cloop, temp_register);
2836 rc = pci_bus_read_config_dword (pci_bus, devfn, cloop, &temp_register);
2837 dbg(
"CND: base = 0x%x\n", temp_register);
2839 if (temp_register) {
2840 if ((temp_register & 0x03L) == 0x01) {
2844 base = temp_register & 0xFFFFFFFC;
2847 dbg(
"CND: length = 0x%x\n", base);
2848 io_node = get_io_resource(&(resources->
io_head), base);
2849 dbg(
"Got io_node start = %8.8x, length = %8.8x next (%p)\n",
2851 dbg(
"func (%p) io_head (%p)\n", func, func->
io_head);
2855 base = io_node->
base;
2861 }
else if ((temp_register & 0x0BL) == 0x08) {
2863 base = temp_register & 0xFFFFFFF0;
2866 dbg(
"CND: length = 0x%x\n", base);
2867 p_mem_node = get_resource(&(resources->
p_mem_head), base);
2871 base = p_mem_node->
base;
2877 }
else if ((temp_register & 0x0BL) == 0x00) {
2879 base = temp_register & 0xFFFFFFF0;
2882 dbg(
"CND: length = 0x%x\n", base);
2883 mem_node = get_resource(&(resources->
mem_head), base);
2887 base = mem_node->
base;
2898 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, base);
2901 if ((temp_register & 0x07L) == 0x04) {
2909 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, base);
2915 rc = pci_bus_read_config_byte (pci_bus, devfn,
2921 if (temp_byte && resources->
irqs &&
2922 (resources->
irqs->valid_INT &
2923 (0x01 << ((temp_byte + resources->
irqs->barber_pole - 1) & 0x03)))) {
2925 IRQ = resources->
irqs->interrupt[(temp_byte +
2926 resources->
irqs->barber_pole - 1) & 0x03];
2929 rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
2941 if (!behind_bridge) {
2948 resources->
irqs->interrupt[(temp_byte + resources->
irqs->barber_pole - 1) & 0x03] = IRQ;
2949 resources->
irqs->valid_INT |= 0x01 << (temp_byte + resources->
irqs->barber_pole - 1) & 0x03;
2954 rc = pci_bus_write_config_byte(pci_bus, devfn,
2959 rc = pci_bus_write_config_byte(pci_bus, devfn,
2964 rc = pci_bus_write_config_word(pci_bus, devfn,
2974 rc = pci_bus_write_config_word (pci_bus, devfn,
2987 return_resource(&(resources->
bus_head), hold_bus_node);
2988 return_resource(&(resources->
io_head), hold_IO_node);
2989 return_resource(&(resources->
mem_head), hold_mem_node);
2990 return_resource(&(resources->
p_mem_head), hold_p_mem_node);