/* * NOTE..... If BIOS doesn't provide default routing, we assign: * 9 for SCSI, 10 for LAN adapters, and 11 for everything else. * If adapter is bridged, then we assign 11 to it and devices behind it. * We also assign the same irq numbers for multi function devices. * These are PIC mode, so shouldn't matter n.e.ways (hopefully)
*/ staticvoid assign_alt_irq(struct pci_func *cur_func, u8 class_code)
{ int j; for (j = 0; j < 4; j++) { if (cur_func->irq[j] == 0xff) { switch (class_code) { case PCI_BASE_CLASS_STORAGE:
cur_func->irq[j] = SCSI_IRQ; break; case PCI_BASE_CLASS_NETWORK:
cur_func->irq[j] = LAN_IRQ; break; default:
cur_func->irq[j] = OTHER_IRQ; break;
}
}
}
}
/* * Configures the device to be added (will allocate needed resources if it * can), the device can be a bridge or a regular pci device, can also be * multi-functional * * Input: function to be added * * TO DO: The error case with Multifunction device or multi function bridge, * if there is an error, will need to go through all previous functions and * unconfigure....or can add some code into unconfigure_card....
*/ int ibmphp_configure_card(struct pci_func *func, u8 slotno)
{
u16 vendor_id;
u32 class;
u8 class_code;
u8 hdr_type, device, sec_number;
u8 function; struct pci_func *newfunc; /* for multi devices */ struct pci_func *cur_func, *prev_func; int rc, i, j; int cleanup_count;
u8 flag;
u8 valid_device = 0x00; /* to see if we are able to read from card any device info at all */
/* We only get bus and device from IRQ routing table. So at this point, * func->busno is correct, and func->device contains only device (at the 5 * highest bits)
*/
/* For every function on the card */ for (function = 0x00; function < 0x08; function++) { unsignedint devfn = PCI_DEVFN(device, function);
ibmphp_pci_bus->number = cur_func->busno;
debug("vendor_id is %x\n", vendor_id); if (vendor_id != PCI_VENDOR_ID_NOTVALID) { /* found correct device!!! */
debug("found valid device, vendor_id = %x\n", vendor_id);
++valid_device;
/* header: x x x x x x x x * | |___________|=> 1=PPB bridge, 0=normal device, 2=CardBus Bridge * |_=> 0 = single function device, 1 = multi-function device
*/
class_code = class >> 24;
debug("hrd_type = %x, class = %x, class_code %x\n", hdr_type, class, class_code); class >>= 8; /* to take revision out, class = class.subclass.prog i/f */ if (class == PCI_CLASS_NOT_DEFINED_VGA) {
err("The device %x is VGA compatible and as is not supported for hot plugging. " "Please choose another device.\n", cur_func->device); return -ENODEV;
} elseif (class == PCI_CLASS_DISPLAY_VGA) {
err("The device %x is not supported for hot plugging. Please choose another device.\n",
cur_func->device); return -ENODEV;
} switch (hdr_type) { case PCI_HEADER_TYPE_NORMAL:
debug("single device case.... vendor id = %x, hdr_type = %x, class = %x\n", vendor_id, hdr_type, class);
assign_alt_irq(cur_func, class_code);
rc = configure_device(cur_func); if (rc < 0) { /* We need to do this in case some other BARs were properly inserted */
err("was not able to configure devfunc %x on bus %x.\n",
cur_func->device, cur_func->busno);
cleanup_count = 6; goto error;
}
cur_func->next = NULL;
function = 0x8; break; case PCI_HEADER_TYPE_MULTIDEVICE:
assign_alt_irq(cur_func, class_code);
rc = configure_device(cur_func); if (rc < 0) { /* We need to do this in case some other BARs were properly inserted */
err("was not able to configure devfunc %x on bus %x...bailing out\n",
cur_func->device, cur_func->busno);
cleanup_count = 6; goto error;
}
newfunc = kzalloc(sizeof(*newfunc), GFP_KERNEL); if (!newfunc) return -ENOMEM;
newfunc->busno = cur_func->busno;
newfunc->device = device;
cur_func->next = newfunc;
cur_func = newfunc; for (j = 0; j < 4; j++)
newfunc->irq[j] = cur_func->irq[j]; break; case PCI_HEADER_TYPE_MULTIBRIDGE: class >>= 8; if (class != PCI_CLASS_BRIDGE_PCI) {
err("This %x is not PCI-to-PCI bridge, and as is not supported for hot-plugging. Please insert another card.\n",
cur_func->device); return -ENODEV;
}
assign_alt_irq(cur_func, class_code);
rc = configure_bridge(&cur_func, slotno); if (rc == -ENODEV) {
err("You chose to insert Single Bridge, or nested bridges, this is not supported...\n");
err("Bus %x, devfunc %x\n", cur_func->busno, cur_func->device); return rc;
} if (rc) { /* We need to do this in case some other BARs were properly inserted */
err("was not able to hot-add PPB properly.\n");
func->bus = 1; /* To indicate to the unconfigure function that this is a PPB */
cleanup_count = 2; goto error;
}
pci_bus_read_config_byte(ibmphp_pci_bus, devfn, PCI_SECONDARY_BUS, &sec_number);
flag = 0; for (i = 0; i < 32; i++) { if (func->devices[i]) {
newfunc = kzalloc(sizeof(*newfunc), GFP_KERNEL); if (!newfunc) return -ENOMEM;
if (flag) { for (prev_func = cur_func; prev_func->next; prev_func = prev_func->next) ;
prev_func->next = newfunc;
} else
cur_func->next = newfunc;
rc = ibmphp_configure_card(newfunc, slotno); /* This could only happen if kmalloc failed */ if (rc) { /* We need to do this in case bridge itself got configured properly, but devices behind it failed */
func->bus = 1; /* To indicate to the unconfigure function that this is a PPB */
cleanup_count = 2; goto error;
}
flag = 1;
}
}
newfunc = kzalloc(sizeof(*newfunc), GFP_KERNEL); if (!newfunc) return -ENOMEM;
newfunc->busno = cur_func->busno;
newfunc->device = device; for (j = 0; j < 4; j++)
newfunc->irq[j] = cur_func->irq[j]; for (prev_func = cur_func; prev_func->next; prev_func = prev_func->next);
prev_func->next = newfunc;
cur_func = newfunc; break; case PCI_HEADER_TYPE_BRIDGE: class >>= 8;
debug("class now is %x\n", class); if (class != PCI_CLASS_BRIDGE_PCI) {
err("This %x is not PCI-to-PCI bridge, and as is not supported for hot-plugging. Please insert another card.\n",
cur_func->device); return -ENODEV;
}
assign_alt_irq(cur_func, class_code);
debug("cur_func->busno b4 configure_bridge is %x\n", cur_func->busno);
rc = configure_bridge(&cur_func, slotno); if (rc == -ENODEV) {
err("You chose to insert Single Bridge, or nested bridges, this is not supported...\n");
err("Bus %x, devfunc %x\n", cur_func->busno, cur_func->device); return rc;
} if (rc) { /* We need to do this in case some other BARs were properly inserted */
func->bus = 1; /* To indicate to the unconfigure function that this is a PPB */
err("was not able to hot-add PPB properly.\n");
cleanup_count = 2; goto error;
}
debug("cur_func->busno = %x, device = %x, function = %x\n",
cur_func->busno, device, function);
pci_bus_read_config_byte(ibmphp_pci_bus, devfn, PCI_SECONDARY_BUS, &sec_number);
debug("after configuring bridge..., sec_number = %x\n", sec_number);
flag = 0; for (i = 0; i < 32; i++) { if (func->devices[i]) {
debug("inside for loop, device is %x\n", i);
newfunc = kzalloc(sizeof(*newfunc), GFP_KERNEL); if (!newfunc) return -ENOMEM;
if (flag) { for (prev_func = cur_func; prev_func->next; prev_func = prev_func->next);
prev_func->next = newfunc;
} else
cur_func->next = newfunc;
rc = ibmphp_configure_card(newfunc, slotno);
/* Again, this case should not happen... For complete paranoia, will need to call remove_bus */ if (rc) { /* We need to do this in case some other BARs were properly inserted */
func->bus = 1; /* To indicate to the unconfigure function that this is a PPB */
cleanup_count = 2; goto error;
}
flag = 1;
}
}
function = 0x8; break; default:
err("MAJOR PROBLEM!!!!, header type not supported? %x\n", hdr_type); return -ENXIO;
} /* end of switch */
} /* end of valid device */
} /* end of for */
if (!valid_device) {
err("Cannot find any valid devices on the card. Or unable to read from card.\n"); return -ENODEV;
}
return 0;
error: for (i = 0; i < cleanup_count; i++) { if (cur_func->io[i]) {
ibmphp_remove_resource(cur_func->io[i]);
cur_func->io[i] = NULL;
} elseif (cur_func->pfmem[i]) {
ibmphp_remove_resource(cur_func->pfmem[i]);
cur_func->pfmem[i] = NULL;
} elseif (cur_func->mem[i]) {
ibmphp_remove_resource(cur_func->mem[i]);
cur_func->mem[i] = NULL;
}
} return rc;
}
/* * This function configures the pci BARs of a single device. * Input: pointer to the pci_func * Output: configured PCI, 0, or error
*/ staticint configure_device(struct pci_func *func)
{
u32 bar[6]; staticconst u32 address[] = {
PCI_BASE_ADDRESS_0,
PCI_BASE_ADDRESS_1,
PCI_BASE_ADDRESS_2,
PCI_BASE_ADDRESS_3,
PCI_BASE_ADDRESS_4,
PCI_BASE_ADDRESS_5,
0
};
u8 irq; int count; int len[6]; struct resource_node *io[6]; struct resource_node *mem[6]; struct resource_node *mem_tmp; struct resource_node *pfmem[6]; unsignedint devfn;
for (count = 0; address[count]; count++) { /* for 6 BARs */
/* not sure if i need this. per scott, said maybe need * something like this if devices don't adhere 100% to the spec, so don't want to write to the reserved bits
/* _______________This is for debugging purposes only_____________________ */
debug("b4 writing, the IO address is %x\n", func->io[count]->start);
pci_bus_read_config_dword(ibmphp_pci_bus, devfn, address[count], &bar[count]);
debug("after writing.... the start address is %x\n", bar[count]); /* _________________________________________________________________________*/
} else { /* This is Memory */ if (bar[count] & PCI_BASE_ADDRESS_MEM_PREFETCH) { /* pfmem */
debug("PFMEM SPACE\n");
/*_______________This is for debugging purposes only______________________________*/
debug("b4 writing, start address is %x\n", func->pfmem[count]->start);
pci_bus_read_config_dword(ibmphp_pci_bus, devfn, address[count], &bar[count]);
debug("after writing, start address is %x\n", bar[count]); /*_________________________________________________________________________________*/
if (bar[count] & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
debug("inside the mem 64 case, count %d\n", count);
count += 1; /* on the 2nd dword, write all 0s, since we can't handle them n.e.ways */
pci_bus_write_config_dword(ibmphp_pci_bus, devfn, address[count], 0x00000000);
}
} else { /* regular memory */
debug("REGULAR MEM SPACE\n");
debug("len[count] in Mem %x, count %d\n", len[count], count);
mem[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL); if (!mem[count]) return -ENOMEM;
mem[count]->type = MEM;
mem[count]->busno = func->busno;
mem[count]->devfunc = PCI_DEVFN(func->device,
func->function);
mem[count]->len = len[count]; if (ibmphp_check_resource(mem[count], 0) == 0) {
ibmphp_add_resource(mem[count]);
func->mem[count] = mem[count];
} else {
err("cannot allocate requested mem for bus %x, device %x, len %x\n",
func->busno, func->device, len[count]);
kfree(mem[count]); return -EIO;
}
pci_bus_write_config_dword(ibmphp_pci_bus, devfn, address[count], func->mem[count]->start); /* _______________________This is for debugging purposes only _______________________*/
debug("b4 writing, start address is %x\n", func->mem[count]->start);
pci_bus_read_config_dword(ibmphp_pci_bus, devfn, address[count], &bar[count]);
debug("after writing, the address is %x\n", bar[count]); /* __________________________________________________________________________________*/
if (bar[count] & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
debug("inside mem 64 case, reg. mem, count %d\n", count);
count += 1; /* on the 2nd dword, write all 0s, since we can't handle them n.e.ways */
pci_bus_write_config_dword(ibmphp_pci_bus, devfn, address[count], 0x00000000);
}
}
} /* end of mem */
} /* end of for */
func->bus = 0; /* To indicate that this is not a PPB */
pci_bus_read_config_byte(ibmphp_pci_bus, devfn, PCI_INTERRUPT_PIN, &irq); if ((irq > 0x00) && (irq < 0x05))
pci_bus_write_config_byte(ibmphp_pci_bus, devfn, PCI_INTERRUPT_LINE, func->irq[irq - 1]);
/* _____________________For debugging purposes only __________________________ pci_bus_config_byte(ibmphp_pci_bus, devfn, PCI_PRIMARY_BUS, &pri_number); debug("primary # written into the bridge is %x\n", pri_number);
___________________________________________________________________________*/
/* in EBDA, only get allocated 1 additional bus # per slot */
sec_number = find_sec_number(func->busno, slotno); if (sec_number == 0xff) {
err("cannot allocate secondary bus number for the bridged device\n"); return -EINVAL;
}
debug("after find_sec_number, the number we got is %x\n", sec_number);
debug("AFTER FIND_SEC_NUMBER, func->busno IS %x\n", func->busno);
/* __________________For debugging purposes only ____________________________________ pci_bus_read_config_byte(ibmphp_pci_bus, devfn, PCI_SUBORDINATE_BUS, &sec_number); debug("subordinate number after write/read is %x\n", sec_number);
__________________________________________________________________________________*/
debug("func->busno is %x\n", func->busno);
debug("sec_number after writing is %x\n", sec_number);
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!NEED TO ADD!!! FAST BACK-TO-BACK ENABLE!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/* First we need to allocate mem/io for the bridge itself in case it needs it */ for (count = 0; address[count]; count++) { /* for 2 BARs */
pci_bus_write_config_dword(ibmphp_pci_bus, devfn, address[count], 0xFFFFFFFF);
pci_bus_read_config_dword(ibmphp_pci_bus, devfn, address[count], &bar[count]);
if (!bar[count]) { /* This BAR is not implemented */
debug("so we come here then, eh?, count = %d\n", count); continue;
} // tmp_bar = bar[count];
debug("Bar %d wants %x\n", count, bar[count]);
if (bar[count] & PCI_BASE_ADDRESS_SPACE_IO) { /* This is IO */
len[count] = bar[count] & 0xFFFFFFFC;
len[count] = ~len[count] + 1;
if (bar[count] & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
count += 1; /* on the 2nd dword, write all 0s, since we can't handle them n.e.ways */
pci_bus_write_config_dword(ibmphp_pci_bus, devfn, address[count], 0x00000000);
if (bar[count] & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
count += 1; /* on the 2nd dword, write all 0s, since we can't handle them n.e.ways */
pci_bus_write_config_dword(ibmphp_pci_bus, devfn, address[count], 0x00000000);
}
}
} /* end of mem */
} /* end of for */
/* Now need to see how much space the devices behind the bridge needed */
amount_needed = scan_behind_bridge(func, sec_number); if (amount_needed == NULL) return -ENOMEM;
if (flag_io && flag_mem && flag_pfmem) { /* If on bootup, there was a bridged card in this slot, * then card was removed and ibmphp got unloaded and loaded * back again, there's no way for us to remove the bus * struct, so no need to kmalloc, can use existing node
*/
bus = ibmphp_find_res_bus(sec_number); if (!bus) {
bus = kzalloc(sizeof(*bus), GFP_KERNEL); if (!bus) {
retval = -ENOMEM; goto error;
}
bus->busno = sec_number;
debug("b4 adding new bus\n");
rc = add_new_bus(bus, io, mem, pfmem, func->busno);
} elseif (!(bus->rangeIO) && !(bus->rangeMem) && !(bus->rangePFMem))
rc = add_new_bus(bus, io, mem, pfmem, 0xFF); else {
err("expected bus structure not empty?\n");
retval = -EIO; goto error;
} if (rc) { if (rc == -ENOMEM) {
ibmphp_remove_bus(bus, func->busno);
kfree(amount_needed); return rc;
}
retval = rc; goto error;
}
pci_bus_read_config_byte(ibmphp_pci_bus, devfn, PCI_IO_BASE, &io_base);
pci_bus_read_config_word(ibmphp_pci_bus, devfn, PCI_PREF_MEMORY_BASE, &pfmem_base);
pci_bus_write_config_word(ibmphp_pci_bus, devfn, PCI_COMMAND, DEVICEENABLE);
pci_bus_write_config_word(ibmphp_pci_bus, devfn, PCI_BRIDGE_CONTROL, 0x07); for (i = 0; i < 32; i++) { if (amount_needed->devices[i]) {
debug("device where devices[i] is 1 = %x\n", i);
func->devices[i] = 1;
}
}
func->bus = 1; /* For unconfiguring, to indicate it's PPB */
func_passed = &func;
debug("func->busno b4 returning is %x\n", func->busno);
debug("func->busno b4 returning in the other structure is %x\n", (*func_passed)->busno);
kfree(amount_needed); return 0;
} else {
err("Configuring bridge was unsuccessful...\n");
mem_tmp = NULL;
retval = -EIO; goto error;
}
error:
kfree(amount_needed); if (pfmem)
ibmphp_remove_resource(pfmem); if (io)
ibmphp_remove_resource(io); if (mem)
ibmphp_remove_resource(mem); for (i = 0; i < 2; i++) { /* for 2 BARs */ if (bus_io[i]) {
ibmphp_remove_resource(bus_io[i]);
func->io[i] = NULL;
} elseif (bus_pfmem[i]) {
ibmphp_remove_resource(bus_pfmem[i]);
func->pfmem[i] = NULL;
} elseif (bus_mem[i]) {
ibmphp_remove_resource(bus_mem[i]);
func->mem[i] = NULL;
}
} return retval;
}
/***************************************************************************** * This function adds up the amount of resources needed behind the PPB bridge * and passes it to the configure_bridge function * Input: bridge function * Output: amount of resources needed
*****************************************************************************/ staticstruct res_needed *scan_behind_bridge(struct pci_func *func, u8 busno)
{ int count, len[6];
u16 vendor_id;
u8 hdr_type;
u8 device, function; unsignedint devfn; int howmany = 0; /*this is to see if there are any devices behind the bridge */
debug("hdr_type behind the bridge is %x\n", hdr_type); if ((hdr_type & PCI_HEADER_TYPE_MASK) == PCI_HEADER_TYPE_BRIDGE) {
err("embedded bridges not supported for hot-plugging.\n");
amount->not_correct = 1; return amount;
}
class >>= 8; /* to take revision out, class = class.subclass.prog i/f */ if (class == PCI_CLASS_NOT_DEFINED_VGA) {
err("The device %x is VGA compatible and as is not supported for hot plugging. Please choose another device.\n", device);
amount->not_correct = 1; return amount;
} elseif (class == PCI_CLASS_DISPLAY_VGA) {
err("The device %x is not supported for hot plugging. Please choose another device.\n", device);
amount->not_correct = 1; return amount;
}
if (bar[count] & PCI_BASE_ADDRESS_SPACE_IO) { /* This is IO */
len[count] = bar[count] & 0xFFFFFFFC;
len[count] = ~len[count] + 1;
amount->io += len[count];
} else { /* This is Memory */ if (bar[count] & PCI_BASE_ADDRESS_MEM_PREFETCH) { /* pfmem */
len[count] = bar[count] & 0xFFFFFFF0;
len[count] = ~len[count] + 1;
amount->pfmem += len[count]; if (bar[count] & PCI_BASE_ADDRESS_MEM_TYPE_64) /* takes up another dword */
count += 1;
} else { /* regular memory */
len[count] = bar[count] & 0xFFFFFFF0;
len[count] = ~len[count] + 1;
amount->mem += len[count]; if (bar[count] & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
count += 1;
}
}
}
} /* end for */
} /* end if (valid) */
} /* end for */
} /* end for */
if (!howmany)
amount->not_correct = 1; else
amount->not_correct = 0; if ((amount->io) && (amount->io < IOBRIDGE))
amount->io = IOBRIDGE; if ((amount->mem) && (amount->mem < MEMBRIDGE))
amount->mem = MEMBRIDGE; if ((amount->pfmem) && (amount->pfmem < MEMBRIDGE))
amount->pfmem = MEMBRIDGE; return amount;
}
/* The following 3 unconfigure_boot_ routines deal with the case when we had the card * upon bootup in the system, since we don't allocate func to such case, we need to read * the start addresses from pci config space and then find the corresponding entries in * our resource lists. The functions return either 0, -ENODEV, or -1 (general failure) * Change: we also call these functions even if we configured the card ourselves (i.e., not * the bootup case), since it should work same way
*/ staticint unconfigure_boot_device(u8 busno, u8 device, u8 function)
{
u32 start_address; staticconst u32 address[] = {
PCI_BASE_ADDRESS_0,
PCI_BASE_ADDRESS_1,
PCI_BASE_ADDRESS_2,
PCI_BASE_ADDRESS_3,
PCI_BASE_ADDRESS_4,
PCI_BASE_ADDRESS_5,
0
}; int count; struct resource_node *io; struct resource_node *mem; struct resource_node *pfmem; struct bus_node *bus;
u32 end_address;
u32 temp_end;
u32 size;
u32 tmp_address; unsignedint devfn;
debug("%s - enter\n", __func__);
bus = ibmphp_find_res_bus(busno); if (!bus) {
debug("cannot find corresponding bus.\n"); return -EINVAL;
}
debug("start_address is %x\n", start_address);
debug("busno, device, function %x %x %x\n", busno, device, function); if (!size) { /* This BAR is not implemented */
debug("is this bar no implemented?, count = %d\n", count); continue;
}
tmp_address = start_address; if (start_address & PCI_BASE_ADDRESS_SPACE_IO) { /* This is IO */
start_address &= PCI_BASE_ADDRESS_IO_MASK;
size = size & 0xFFFFFFFC;
size = ~size + 1;
end_address = start_address + size - 1; if (ibmphp_find_resource(bus, start_address, &io, IO)) goto report_search_failure;
debug("io->start = %x\n", io->start);
temp_end = io->end;
start_address = io->end + 1;
ibmphp_remove_resource(io); /* This is needed b/c of the old I/O restrictions in the BIOS */ while (temp_end < end_address) { if (ibmphp_find_resource(bus, start_address,
&io, IO)) goto report_search_failure;
/* ????????? DO WE NEED TO WRITE ANYTHING INTO THE PCI CONFIG SPACE BACK ?????????? */
} else { /* This is Memory */ if (start_address & PCI_BASE_ADDRESS_MEM_PREFETCH) { /* pfmem */
debug("start address of pfmem is %x\n", start_address);
start_address &= PCI_BASE_ADDRESS_MEM_MASK;
if (ibmphp_find_resource(bus, start_address, &pfmem, PFMEM) < 0) {
err("cannot find corresponding PFMEM resource to remove\n"); return -EIO;
} if (pfmem) {
debug("pfmem->start = %x\n", pfmem->start);
ibmphp_remove_resource(pfmem);
}
} else { /* regular memory */
debug("start address of mem is %x\n", start_address);
start_address &= PCI_BASE_ADDRESS_MEM_MASK;
if (ibmphp_find_resource(bus, start_address, &mem, MEM) < 0) {
err("cannot find corresponding MEM resource to remove\n"); return -EIO;
} if (mem) {
debug("mem->start = %x\n", mem->start);
ibmphp_remove_resource(mem);
}
} if (tmp_address & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
count += 1;
}
} /* end of mem */
} /* end of for */
pci_bus_read_config_byte(ibmphp_pci_bus, devfn, PCI_SECONDARY_BUS, &sec_number);
debug("sec_number is %x\n", sec_number);
sec_no = (int) sec_number;
pri_no = (int) pri_number; if (pri_no != bus_no) {
err("primary numbers in our structures and pci config space don't match.\n"); return -EINVAL;
}
pci_bus_read_config_byte(ibmphp_pci_bus, devfn, PCI_SUBORDINATE_BUS, &sub_number);
sub_no = (int) sub_number;
debug("sub_no is %d, sec_no is %d\n", sub_no, sec_no); if (sec_no != sub_number) {
err("there're more buses behind this bridge. Hot removal is not supported. Please choose another card\n"); return -ENODEV;
}
bus = ibmphp_find_res_bus(sec_number); if (!bus) {
err("cannot find Bus structure for the bridged device\n"); return -EINVAL;
}
debug("bus->busno is %x\n", bus->busno);
debug("sec_number is %x\n", sec_number);
ibmphp_remove_bus(bus, busno);
for (count = 0; address[count]; count++) { /* for 2 BARs */
pci_bus_read_config_dword(ibmphp_pci_bus, devfn, address[count], &start_address);
if (!start_address) { /* This BAR is not implemented */ continue;
}
tmp_address = start_address;
if (start_address & PCI_BASE_ADDRESS_SPACE_IO) { /* This is IO */
start_address &= PCI_BASE_ADDRESS_IO_MASK; if (ibmphp_find_resource(bus, start_address, &io, IO) < 0) {
err("cannot find corresponding IO resource to remove\n"); return -EIO;
} if (io)
debug("io->start = %x\n", io->start);
ibmphp_remove_resource(io);
/* ????????? DO WE NEED TO WRITE ANYTHING INTO THE PCI CONFIG SPACE BACK ?????????? */
} else { /* This is Memory */ if (start_address & PCI_BASE_ADDRESS_MEM_PREFETCH) { /* pfmem */
start_address &= PCI_BASE_ADDRESS_MEM_MASK; if (ibmphp_find_resource(bus, start_address, &pfmem, PFMEM) < 0) {
err("cannot find corresponding PFMEM resource to remove\n"); return -EINVAL;
} if (pfmem) {
debug("pfmem->start = %x\n", pfmem->start);
ibmphp_remove_resource(pfmem);
}
} else { /* regular memory */
start_address &= PCI_BASE_ADDRESS_MEM_MASK; if (ibmphp_find_resource(bus, start_address, &mem, MEM) < 0) {
err("cannot find corresponding MEM resource to remove\n"); return -EINVAL;
} if (mem) {
debug("mem->start = %x\n", mem->start);
ibmphp_remove_resource(mem);
}
} if (tmp_address & PCI_BASE_ADDRESS_MEM_TYPE_64) { /* takes up another dword */
count += 1;
}
} /* end of mem */
} /* end of for */
debug("%s - exiting, returning success\n", __func__); return 0;
}
staticint unconfigure_boot_card(struct slot *slot_cur)
{
u16 vendor_id;
u32 class;
u8 hdr_type;
u8 device;
u8 busno;
u8 function; int rc; unsignedint devfn;
u8 valid_device = 0x00; /* To see if we are ever able to find valid device and read it */
debug("%s - enter\n", __func__);
device = slot_cur->device;
busno = slot_cur->bus;
debug("b4 for loop, device is %x\n", device); /* For every function on the card */ for (function = 0x0; function < 0x08; function++) {
devfn = PCI_DEVFN(device, function);
ibmphp_pci_bus->number = busno;
if (vendor_id != PCI_VENDOR_ID_NOTVALID) { /* found correct device!!! */
++valid_device;
debug("%s - found correct device\n", __func__);
/* header: x x x x x x x x * | |___________|=> 1=PPB bridge, 0=normal device, 2=CardBus Bridge * |_=> 0 = single function device, 1 = multi-function device
*/
debug("hdr_type %x, class %x\n", hdr_type, class); class >>= 8; /* to take revision out, class = class.subclass.prog i/f */ if (class == PCI_CLASS_NOT_DEFINED_VGA) {
err("The device %x function %x is VGA compatible and is not supported for hot removing. Please choose another device.\n", device, function); return -ENODEV;
} elseif (class == PCI_CLASS_DISPLAY_VGA) {
err("The device %x function %x is not supported for hot removing. Please choose another device.\n", device, function); return -ENODEV;
}
switch (hdr_type) { case PCI_HEADER_TYPE_NORMAL:
rc = unconfigure_boot_device(busno, device, function); if (rc) {
err("was not able to unconfigure device %x func %x on bus %x. bailing out...\n",
device, function, busno); return rc;
}
function = 0x8; break; case PCI_HEADER_TYPE_MULTIDEVICE:
rc = unconfigure_boot_device(busno, device, function); if (rc) {
err("was not able to unconfigure device %x func %x on bus %x. bailing out...\n",
device, function, busno); return rc;
} break; case PCI_HEADER_TYPE_BRIDGE: class >>= 8; if (class != PCI_CLASS_BRIDGE_PCI) {
err("This device %x function %x is not PCI-to-PCI bridge, and is not supported for hot-removing. Please try another card.\n", device, function); return -ENODEV;
}
rc = unconfigure_boot_bridge(busno, device, function); if (rc != 0) {
err("was not able to hot-remove PPB properly.\n"); return rc;
}
function = 0x8; break; case PCI_HEADER_TYPE_MULTIBRIDGE: class >>= 8; if (class != PCI_CLASS_BRIDGE_PCI) {
err("This device %x function %x is not PCI-to-PCI bridge, and is not supported for hot-removing. Please try another card.\n", device, function); return -ENODEV;
}
rc = unconfigure_boot_bridge(busno, device, function); if (rc != 0) {
err("was not able to hot-remove PPB properly.\n"); return rc;
} break; default:
err("MAJOR PROBLEM!!!! Cannot read device's header\n"); return -1;
} /* end of switch */
} /* end of valid device */
} /* end of for */
if (!valid_device) {
err("Could not find device to unconfigure. Or could not read the card.\n"); return -1;
} return 0;
}
/* * free the resources of the card (multi, single, or bridged) * Parameters: slot, flag to say if this is for removing entire module or just * unconfiguring the device * TO DO: will probably need to add some code in case there was some resource, * to remove it... this is from when we have errors in the configure_card... * !!!!!!!!!!!!!!!!!!!!!!!!!FOR BUSES!!!!!!!!!!!! * Returns: 0, -1, -ENODEV
*/ int ibmphp_unconfigure_card(struct slot **slot_cur, int the_end)
{ int i; int count; int rc; struct slot *sl = *slot_cur; struct pci_func *cur_func = NULL; struct pci_func *temp_func;
debug("%s - enter\n", __func__);
if (!the_end) { /* Need to unconfigure the card */
rc = unconfigure_boot_card(sl); if ((rc == -ENODEV) || (rc == -EIO) || (rc == -EINVAL)) { /* In all other cases, will still need to get rid of func structure if it exists */ return rc;
}
}
if (sl->func) {
cur_func = sl->func; while (cur_func) { /* TO DO: WILL MOST LIKELY NEED TO GET RID OF THE BUS STRUCTURE FROM RESOURCES AS WELL */ if (cur_func->bus) { /* in other words, it's a PPB */
count = 2;
} else {
count = 6;
}
for (i = 0; i < count; i++) { if (cur_func->io[i]) {
debug("io[%d] exists\n", i); if (the_end > 0)
ibmphp_remove_resource(cur_func->io[i]);
cur_func->io[i] = NULL;
} if (cur_func->mem[i]) {
debug("mem[%d] exists\n", i); if (the_end > 0)
ibmphp_remove_resource(cur_func->mem[i]);
cur_func->mem[i] = NULL;
} if (cur_func->pfmem[i]) {
debug("pfmem[%d] exists\n", i); if (the_end > 0)
ibmphp_remove_resource(cur_func->pfmem[i]);
cur_func->pfmem[i] = NULL;
}
}
/* * add a new bus resulting from hot-plugging a PPB bridge with devices * * Input: bus and the amount of resources needed (we know we can assign those, * since they've been checked already * Output: bus added to the correct spot * 0, -1, error
*/ staticint add_new_bus(struct bus_node *bus, struct resource_node *io, struct resource_node *mem, struct resource_node *pfmem, u8 parent_busno)
{ struct range_node *io_range = NULL; struct range_node *mem_range = NULL; struct range_node *pfmem_range = NULL; struct bus_node *cur_bus = NULL;
/* Trying to find the parent bus number */ if (parent_busno != 0xFF) {
cur_bus = ibmphp_find_res_bus(parent_busno); if (!cur_bus) {
err("strange, cannot find bus which is supposed to be at the system... something is terribly wrong...\n"); return -ENODEV;
}
list_add(&bus->bus_list, &cur_bus->bus_list);
} if (io) {
io_range = kzalloc(sizeof(*io_range), GFP_KERNEL); if (!io_range) return -ENOMEM;
/* * find the 1st available bus number for PPB to set as its secondary bus * Parameters: bus_number of the primary bus * Returns: bus_number of the secondary bus or 0xff in case of failure
*/ static u8 find_sec_number(u8 primary_busno, u8 slotno)
{ int min, max;
u8 busno; struct bus_info *bus; struct bus_node *bus_cur;
bus = ibmphp_find_same_bus_num(primary_busno); if (!bus) {
err("cannot get slot range of the bus from the BIOS\n"); return 0xff;
}
max = bus->slot_max;
min = bus->slot_min; if ((slotno > max) || (slotno < min)) {
err("got the wrong range\n"); return 0xff;
}
busno = (u8) (slotno - (u8) min);
busno += primary_busno + 0x01;
bus_cur = ibmphp_find_res_bus(busno); /* either there is no such bus number, or there are no ranges, which * can only happen if we removed the bridged device in previous load * of the driver, and now only have the skeleton bus struct
*/ if ((!bus_cur) || (!(bus_cur->rangeIO) && !(bus_cur->rangeMem) && !(bus_cur->rangePFMem))) return busno; return 0xff;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.