1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723 |
- #include <linux/module.h>
- #include <linux/slab.h>
- #include <linux/pci.h>
- #include <linux/list.h>
- #include "ibmphp.h"
- static int configure_device(struct pci_func *);
- static int configure_bridge(struct pci_func **, u8);
- static struct res_needed *scan_behind_bridge(struct pci_func *, u8);
- static int add_new_bus (struct bus_node *, struct resource_node *, struct resource_node *, struct resource_node *, u8);
- static u8 find_sec_number (u8 primary_busno, u8 slotno);
- static void 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;
- }
- }
- }
- }
- 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;
- struct pci_func *cur_func, *prev_func;
- int rc, i, j;
- int cleanup_count;
- u8 flag;
- u8 valid_device = 0x00;
- debug ("inside configure_card, func->busno = %x\n", func->busno);
- device = func->device;
- cur_func = func;
-
-
- for (function = 0x00; function < 0x08; function++) {
- unsigned int devfn = PCI_DEVFN(device, function);
- ibmphp_pci_bus->number = cur_func->busno;
- cur_func->function = function;
- debug ("inside the loop, cur_func->busno = %x, cur_func->device = %x, cur_func->function = %x\n",
- cur_func->busno, cur_func->device, cur_func->function);
- pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_VENDOR_ID, &vendor_id);
- debug ("vendor_id is %x\n", vendor_id);
- if (vendor_id != PCI_VENDOR_ID_NOTVALID) {
-
- debug ("found valid device, vendor_id = %x\n", vendor_id);
- ++valid_device;
-
- pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_HEADER_TYPE, &hdr_type);
- pci_bus_read_config_dword (ibmphp_pci_bus, devfn, PCI_CLASS_REVISION, &class);
- class_code = class >> 24;
- debug ("hrd_type = %x, class = %x, class_code %x\n", hdr_type, class, class_code);
- class >>= 8;
- 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;
- } else if (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) {
-
- 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) {
-
- 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) {
- err ("out of system memory\n");
- 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) {
-
- err ("was not able to hot-add PPB properly.\n");
- func->bus = 1;
- 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) {
- err ("out of system memory\n");
- return -ENOMEM;
- }
- newfunc->busno = sec_number;
- newfunc->device = (u8) i;
- for (j = 0; j < 4; j++)
- newfunc->irq[j] = cur_func->irq[j];
- 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);
-
- if (rc) {
-
- func->bus = 1;
- cleanup_count = 2;
- goto error;
- }
- flag = 1;
- }
- }
- newfunc = kzalloc(sizeof(*newfunc), GFP_KERNEL);
- if (!newfunc) {
- err ("out of system memory\n");
- 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) {
-
- func->bus = 1;
- 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) {
- err (" out of system memory\n");
- return -ENOMEM;
- }
- newfunc->busno = sec_number;
- newfunc->device = (u8) i;
- for (j = 0; j < 4; j++)
- newfunc->irq[j] = cur_func->irq[j];
- 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);
-
- if (rc) {
-
- func->bus = 1;
- cleanup_count = 2;
- goto error;
- }
- flag = 1;
- }
- }
- function = 0x8;
- break;
- default:
- err ("MAJOR PROBLEM!!!!, header type not supported? %x\n", hdr_type);
- return -ENXIO;
- break;
- }
- }
- }
- 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;
- } else if (cur_func->pfmem[i]) {
- ibmphp_remove_resource (cur_func->pfmem[i]);
- cur_func->pfmem[i] = NULL;
- } else if (cur_func->mem[i]) {
- ibmphp_remove_resource (cur_func->mem[i]);
- cur_func->mem[i] = NULL;
- }
- }
- return rc;
- }
- static int configure_device (struct pci_func *func)
- {
- u32 bar[6];
- 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];
- unsigned int devfn;
- debug ("%s - inside\n", __func__);
- devfn = PCI_DEVFN(func->device, func->function);
- ibmphp_pci_bus->number = func->busno;
- for (count = 0; address[count]; count++) {
-
- 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])
- continue;
- debug ("Device %x BAR %d wants %x\n", func->device, count, bar[count]);
- if (bar[count] & PCI_BASE_ADDRESS_SPACE_IO) {
-
- debug ("inside IO SPACE\n");
- len[count] = bar[count] & 0xFFFFFFFC;
- len[count] = ~len[count] + 1;
- debug ("len[count] in IO %x, count %d\n", len[count], count);
- io[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
- if (!io[count]) {
- err ("out of system memory\n");
- return -ENOMEM;
- }
- io[count]->type = IO;
- io[count]->busno = func->busno;
- io[count]->devfunc = PCI_DEVFN(func->device, func->function);
- io[count]->len = len[count];
- if (ibmphp_check_resource(io[count], 0) == 0) {
- ibmphp_add_resource (io[count]);
- func->io[count] = io[count];
- } else {
- err ("cannot allocate requested io for bus %x device %x function %x len %x\n",
- func->busno, func->device, func->function, len[count]);
- kfree (io[count]);
- return -EIO;
- }
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], func->io[count]->start);
-
- 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 {
-
- if (bar[count] & PCI_BASE_ADDRESS_MEM_PREFETCH) {
-
- debug ("PFMEM SPACE\n");
- len[count] = bar[count] & 0xFFFFFFF0;
- len[count] = ~len[count] + 1;
- debug ("len[count] in PFMEM %x, count %d\n", len[count], count);
- pfmem[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
- if (!pfmem[count]) {
- err ("out of system memory\n");
- return -ENOMEM;
- }
- pfmem[count]->type = PFMEM;
- pfmem[count]->busno = func->busno;
- pfmem[count]->devfunc = PCI_DEVFN(func->device,
- func->function);
- pfmem[count]->len = len[count];
- pfmem[count]->fromMem = 0;
- if (ibmphp_check_resource (pfmem[count], 0) == 0) {
- ibmphp_add_resource (pfmem[count]);
- func->pfmem[count] = pfmem[count];
- } else {
- mem_tmp = kzalloc(sizeof(*mem_tmp), GFP_KERNEL);
- if (!mem_tmp) {
- err ("out of system memory\n");
- kfree (pfmem[count]);
- return -ENOMEM;
- }
- mem_tmp->type = MEM;
- mem_tmp->busno = pfmem[count]->busno;
- mem_tmp->devfunc = pfmem[count]->devfunc;
- mem_tmp->len = pfmem[count]->len;
- debug ("there's no pfmem... going into mem.\n");
- if (ibmphp_check_resource (mem_tmp, 0) == 0) {
- ibmphp_add_resource (mem_tmp);
- pfmem[count]->fromMem = 1;
- pfmem[count]->rangeno = mem_tmp->rangeno;
- pfmem[count]->start = mem_tmp->start;
- pfmem[count]->end = mem_tmp->end;
- ibmphp_add_pfmem_from_mem (pfmem[count]);
- func->pfmem[count] = pfmem[count];
- } else {
- err ("cannot allocate requested pfmem for bus %x, device %x, len %x\n",
- func->busno, func->device, len[count]);
- kfree (mem_tmp);
- kfree (pfmem[count]);
- return -EIO;
- }
- }
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], func->pfmem[count]->start);
-
- 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) {
- debug ("inside the mem 64 case, count %d\n", count);
- count += 1;
-
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], 0x00000000);
- }
- } else {
-
- debug ("REGULAR MEM SPACE\n");
- len[count] = bar[count] & 0xFFFFFFF0;
- len[count] = ~len[count] + 1;
- debug ("len[count] in Mem %x, count %d\n", len[count], count);
- mem[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
- if (!mem[count]) {
- err ("out of system memory\n");
- 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);
-
- 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) {
-
- debug ("inside mem 64 case, reg. mem, count %d\n", count);
- count += 1;
-
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], 0x00000000);
- }
- }
- }
- }
- func->bus = 0;
- 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]);
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_CACHE_LINE_SIZE, CACHE);
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_LATENCY_TIMER, LATENCY);
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, PCI_ROM_ADDRESS, 0x00L);
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_COMMAND, DEVICEENABLE);
- return 0;
- }
- static int configure_bridge (struct pci_func **func_passed, u8 slotno)
- {
- int count;
- int i;
- int rc;
- u8 sec_number;
- u8 io_base;
- u16 pfmem_base;
- u32 bar[2];
- u32 len[2];
- u8 flag_io = 0;
- u8 flag_mem = 0;
- u8 flag_pfmem = 0;
- u8 need_io_upper = 0;
- u8 need_pfmem_upper = 0;
- struct res_needed *amount_needed = NULL;
- struct resource_node *io = NULL;
- struct resource_node *bus_io[2] = {NULL, NULL};
- struct resource_node *mem = NULL;
- struct resource_node *bus_mem[2] = {NULL, NULL};
- struct resource_node *mem_tmp = NULL;
- struct resource_node *pfmem = NULL;
- struct resource_node *bus_pfmem[2] = {NULL, NULL};
- struct bus_node *bus;
- u32 address[] = {
- PCI_BASE_ADDRESS_0,
- PCI_BASE_ADDRESS_1,
- 0
- };
- struct pci_func *func = *func_passed;
- unsigned int devfn;
- u8 irq;
- int retval;
- debug ("%s - enter\n", __func__);
- devfn = PCI_DEVFN(func->function, func->device);
- ibmphp_pci_bus->number = func->busno;
-
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_PRIMARY_BUS, func->busno);
-
-
- 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);
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_SECONDARY_BUS, sec_number);
-
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_SUBORDINATE_BUS, sec_number);
-
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_CACHE_LINE_SIZE, CACHE);
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_LATENCY_TIMER, LATENCY);
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_SEC_LATENCY_TIMER, LATENCY);
- debug ("func->busno is %x\n", func->busno);
- debug ("sec_number after writing is %x\n", sec_number);
-
-
- for (count = 0; address[count]; count++) {
- 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]) {
-
- debug ("so we come here then, eh?, count = %d\n", count);
- continue;
- }
-
- debug ("Bar %d wants %x\n", count, bar[count]);
- if (bar[count] & PCI_BASE_ADDRESS_SPACE_IO) {
-
- len[count] = bar[count] & 0xFFFFFFFC;
- len[count] = ~len[count] + 1;
- debug ("len[count] in IO = %x\n", len[count]);
- bus_io[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
- if (!bus_io[count]) {
- err ("out of system memory\n");
- retval = -ENOMEM;
- goto error;
- }
- bus_io[count]->type = IO;
- bus_io[count]->busno = func->busno;
- bus_io[count]->devfunc = PCI_DEVFN(func->device,
- func->function);
- bus_io[count]->len = len[count];
- if (ibmphp_check_resource (bus_io[count], 0) == 0) {
- ibmphp_add_resource (bus_io[count]);
- func->io[count] = bus_io[count];
- } else {
- err ("cannot allocate requested io for bus %x, device %x, len %x\n",
- func->busno, func->device, len[count]);
- kfree (bus_io[count]);
- return -EIO;
- }
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], func->io[count]->start);
- } else {
-
- if (bar[count] & PCI_BASE_ADDRESS_MEM_PREFETCH) {
-
- len[count] = bar[count] & 0xFFFFFFF0;
- len[count] = ~len[count] + 1;
- debug ("len[count] in PFMEM = %x\n", len[count]);
- bus_pfmem[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
- if (!bus_pfmem[count]) {
- err ("out of system memory\n");
- retval = -ENOMEM;
- goto error;
- }
- bus_pfmem[count]->type = PFMEM;
- bus_pfmem[count]->busno = func->busno;
- bus_pfmem[count]->devfunc = PCI_DEVFN(func->device,
- func->function);
- bus_pfmem[count]->len = len[count];
- bus_pfmem[count]->fromMem = 0;
- if (ibmphp_check_resource (bus_pfmem[count], 0) == 0) {
- ibmphp_add_resource (bus_pfmem[count]);
- func->pfmem[count] = bus_pfmem[count];
- } else {
- mem_tmp = kzalloc(sizeof(*mem_tmp), GFP_KERNEL);
- if (!mem_tmp) {
- err ("out of system memory\n");
- retval = -ENOMEM;
- goto error;
- }
- mem_tmp->type = MEM;
- mem_tmp->busno = bus_pfmem[count]->busno;
- mem_tmp->devfunc = bus_pfmem[count]->devfunc;
- mem_tmp->len = bus_pfmem[count]->len;
- if (ibmphp_check_resource (mem_tmp, 0) == 0) {
- ibmphp_add_resource (mem_tmp);
- bus_pfmem[count]->fromMem = 1;
- bus_pfmem[count]->rangeno = mem_tmp->rangeno;
- ibmphp_add_pfmem_from_mem (bus_pfmem[count]);
- func->pfmem[count] = bus_pfmem[count];
- } else {
- err ("cannot allocate requested pfmem for bus %x, device %x, len %x\n",
- func->busno, func->device, len[count]);
- kfree (mem_tmp);
- kfree (bus_pfmem[count]);
- return -EIO;
- }
- }
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], func->pfmem[count]->start);
- if (bar[count] & PCI_BASE_ADDRESS_MEM_TYPE_64) {
-
- count += 1;
-
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], 0x00000000);
- }
- } else {
-
- len[count] = bar[count] & 0xFFFFFFF0;
- len[count] = ~len[count] + 1;
- debug ("len[count] in Memory is %x\n", len[count]);
- bus_mem[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
- if (!bus_mem[count]) {
- err ("out of system memory\n");
- retval = -ENOMEM;
- goto error;
- }
- bus_mem[count]->type = MEM;
- bus_mem[count]->busno = func->busno;
- bus_mem[count]->devfunc = PCI_DEVFN(func->device,
- func->function);
- bus_mem[count]->len = len[count];
- if (ibmphp_check_resource (bus_mem[count], 0) == 0) {
- ibmphp_add_resource (bus_mem[count]);
- func->mem[count] = bus_mem[count];
- } else {
- err ("cannot allocate requested mem for bus %x, device %x, len %x\n",
- func->busno, func->device, len[count]);
- kfree (bus_mem[count]);
- return -EIO;
- }
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], func->mem[count]->start);
- if (bar[count] & PCI_BASE_ADDRESS_MEM_TYPE_64) {
-
- count += 1;
-
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], 0x00000000);
- }
- }
- }
- }
-
- amount_needed = scan_behind_bridge (func, sec_number);
- if (amount_needed == NULL)
- return -ENOMEM;
- ibmphp_pci_bus->number = func->busno;
- debug ("after coming back from scan_behind_bridge\n");
- debug ("amount_needed->not_correct = %x\n", amount_needed->not_correct);
- debug ("amount_needed->io = %x\n", amount_needed->io);
- debug ("amount_needed->mem = %x\n", amount_needed->mem);
- debug ("amount_needed->pfmem = %x\n", amount_needed->pfmem);
- if (amount_needed->not_correct) {
- debug ("amount_needed is not correct\n");
- for (count = 0; address[count]; count++) {
-
- if (bus_io[count]) {
- ibmphp_remove_resource (bus_io[count]);
- func->io[count] = NULL;
- } else if (bus_pfmem[count]) {
- ibmphp_remove_resource (bus_pfmem[count]);
- func->pfmem[count] = NULL;
- } else if (bus_mem[count]) {
- ibmphp_remove_resource (bus_mem[count]);
- func->mem[count] = NULL;
- }
- }
- kfree (amount_needed);
- return -ENODEV;
- }
- if (!amount_needed->io) {
- debug ("it doesn't want IO?\n");
- flag_io = 1;
- } else {
- debug ("it wants %x IO behind the bridge\n", amount_needed->io);
- io = kzalloc(sizeof(*io), GFP_KERNEL);
- if (!io) {
- err ("out of system memory\n");
- retval = -ENOMEM;
- goto error;
- }
- io->type = IO;
- io->busno = func->busno;
- io->devfunc = PCI_DEVFN(func->device, func->function);
- io->len = amount_needed->io;
- if (ibmphp_check_resource (io, 1) == 0) {
- debug ("were we able to add io\n");
- ibmphp_add_resource (io);
- flag_io = 1;
- }
- }
- if (!amount_needed->mem) {
- debug ("it doesn't want n.e.memory?\n");
- flag_mem = 1;
- } else {
- debug ("it wants %x memory behind the bridge\n", amount_needed->mem);
- mem = kzalloc(sizeof(*mem), GFP_KERNEL);
- if (!mem) {
- err ("out of system memory\n");
- retval = -ENOMEM;
- goto error;
- }
- mem->type = MEM;
- mem->busno = func->busno;
- mem->devfunc = PCI_DEVFN(func->device, func->function);
- mem->len = amount_needed->mem;
- if (ibmphp_check_resource (mem, 1) == 0) {
- ibmphp_add_resource (mem);
- flag_mem = 1;
- debug ("were we able to add mem\n");
- }
- }
- if (!amount_needed->pfmem) {
- debug ("it doesn't want n.e.pfmem mem?\n");
- flag_pfmem = 1;
- } else {
- debug ("it wants %x pfmemory behind the bridge\n", amount_needed->pfmem);
- pfmem = kzalloc(sizeof(*pfmem), GFP_KERNEL);
- if (!pfmem) {
- err ("out of system memory\n");
- retval = -ENOMEM;
- goto error;
- }
- pfmem->type = PFMEM;
- pfmem->busno = func->busno;
- pfmem->devfunc = PCI_DEVFN(func->device, func->function);
- pfmem->len = amount_needed->pfmem;
- pfmem->fromMem = 0;
- if (ibmphp_check_resource (pfmem, 1) == 0) {
- ibmphp_add_resource (pfmem);
- flag_pfmem = 1;
- } else {
- mem_tmp = kzalloc(sizeof(*mem_tmp), GFP_KERNEL);
- if (!mem_tmp) {
- err ("out of system memory\n");
- retval = -ENOMEM;
- goto error;
- }
- mem_tmp->type = MEM;
- mem_tmp->busno = pfmem->busno;
- mem_tmp->devfunc = pfmem->devfunc;
- mem_tmp->len = pfmem->len;
- if (ibmphp_check_resource (mem_tmp, 1) == 0) {
- ibmphp_add_resource (mem_tmp);
- pfmem->fromMem = 1;
- pfmem->rangeno = mem_tmp->rangeno;
- ibmphp_add_pfmem_from_mem (pfmem);
- flag_pfmem = 1;
- }
- }
- }
- debug ("b4 if (flag_io && flag_mem && flag_pfmem)\n");
- debug ("flag_io = %x, flag_mem = %x, flag_pfmem = %x\n", flag_io, flag_mem, flag_pfmem);
- if (flag_io && flag_mem && flag_pfmem) {
-
- bus = ibmphp_find_res_bus (sec_number);
- if (!bus) {
- bus = kzalloc(sizeof(*bus), GFP_KERNEL);
- if (!bus) {
- err ("out of system memory\n");
- retval = -ENOMEM;
- goto error;
- }
- bus->busno = sec_number;
- debug ("b4 adding new bus\n");
- rc = add_new_bus (bus, io, mem, pfmem, func->busno);
- } else if (!(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);
- if ((io_base & PCI_IO_RANGE_TYPE_MASK) == PCI_IO_RANGE_TYPE_32) {
- debug ("io 32\n");
- need_io_upper = 1;
- }
- if ((pfmem_base & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) {
- debug ("pfmem 64\n");
- need_pfmem_upper = 1;
- }
- if (bus->noIORanges) {
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_IO_BASE, 0x00 | bus->rangeIO->start >> 8);
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_IO_LIMIT, 0x00 | bus->rangeIO->end >> 8);
-
- if (need_io_upper) {
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_IO_BASE_UPPER16, 0x0000);
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_IO_LIMIT_UPPER16, 0x0000);
- }
- } else {
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_IO_BASE, 0x00);
- pci_bus_write_config_byte (ibmphp_pci_bus, devfn, PCI_IO_LIMIT, 0x00);
- }
- if (bus->noMemRanges) {
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_MEMORY_BASE, 0x0000 | bus->rangeMem->start >> 16);
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_MEMORY_LIMIT, 0x0000 | bus->rangeMem->end >> 16);
-
- } else {
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_MEMORY_BASE, 0xffff);
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_MEMORY_LIMIT, 0x0000);
- }
- if (bus->noPFMemRanges) {
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_PREF_MEMORY_BASE, 0x0000 | bus->rangePFMem->start >> 16);
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, 0x0000 | bus->rangePFMem->end >> 16);
-
- if (need_pfmem_upper) {
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, PCI_PREF_BASE_UPPER32, 0x00000000);
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, PCI_PREF_LIMIT_UPPER32, 0x00000000);
- }
- } else {
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_PREF_MEMORY_BASE, 0xffff);
- pci_bus_write_config_word (ibmphp_pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, 0x0000);
- }
- debug ("b4 writing control information\n");
- 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]);
-
- 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;
- 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++) {
- if (bus_io[i]) {
- ibmphp_remove_resource (bus_io[i]);
- func->io[i] = NULL;
- } else if (bus_pfmem[i]) {
- ibmphp_remove_resource (bus_pfmem[i]);
- func->pfmem[i] = NULL;
- } else if (bus_mem[i]) {
- ibmphp_remove_resource (bus_mem[i]);
- func->mem[i] = NULL;
- }
- }
- return retval;
- }
- static struct res_needed *scan_behind_bridge (struct pci_func *func, u8 busno)
- {
- int count, len[6];
- u16 vendor_id;
- u8 hdr_type;
- u8 device, function;
- unsigned int devfn;
- int howmany = 0;
- u32 bar[6], class;
- 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
- };
- struct res_needed *amount;
- amount = kzalloc(sizeof(*amount), GFP_KERNEL);
- if (amount == NULL)
- return NULL;
- ibmphp_pci_bus->number = busno;
- debug ("the bus_no behind the bridge is %x\n", busno);
- debug ("scanning devices behind the bridge...\n");
- for (device = 0; device < 32; device++) {
- amount->devices[device] = 0;
- for (function = 0; function < 8; function++) {
- devfn = PCI_DEVFN(device, function);
- pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_VENDOR_ID, &vendor_id);
- if (vendor_id != PCI_VENDOR_ID_NOTVALID) {
-
- howmany++;
- pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_HEADER_TYPE, &hdr_type);
- pci_bus_read_config_dword (ibmphp_pci_bus, devfn, PCI_CLASS_REVISION, &class);
- debug ("hdr_type behind the bridge is %x\n", hdr_type);
- if (hdr_type & PCI_HEADER_TYPE_BRIDGE) {
- err ("embedded bridges not supported for hot-plugging.\n");
- amount->not_correct = 1;
- return amount;
- }
- class >>= 8;
- 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;
- } else if (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;
- }
- amount->devices[device] = 1;
- for (count = 0; address[count]; count++) {
-
-
- 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]);
- debug ("what is bar[count]? %x, count = %d\n", bar[count], count);
- if (!bar[count])
- continue;
-
- debug ("count %d device %x function %x wants %x resources\n", count, device, function, bar[count]);
- if (bar[count] & PCI_BASE_ADDRESS_SPACE_IO) {
-
- len[count] = bar[count] & 0xFFFFFFFC;
- len[count] = ~len[count] + 1;
- amount->io += len[count];
- } else {
-
- if (bar[count] & PCI_BASE_ADDRESS_MEM_PREFETCH) {
-
- len[count] = bar[count] & 0xFFFFFFF0;
- len[count] = ~len[count] + 1;
- amount->pfmem += len[count];
- if (bar[count] & PCI_BASE_ADDRESS_MEM_TYPE_64)
-
- count += 1;
- } else {
-
- len[count] = bar[count] & 0xFFFFFFF0;
- len[count] = ~len[count] + 1;
- amount->mem += len[count];
- if (bar[count] & PCI_BASE_ADDRESS_MEM_TYPE_64) {
-
- count += 1;
- }
- }
- }
- }
- }
- }
- }
- 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;
- }
- static int unconfigure_boot_device (u8 busno, u8 device, u8 function)
- {
- u32 start_address;
- 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;
- unsigned int devfn;
- debug ("%s - enter\n", __func__);
- bus = ibmphp_find_res_bus (busno);
- if (!bus) {
- debug ("cannot find corresponding bus.\n");
- return -EINVAL;
- }
- devfn = PCI_DEVFN(device, function);
- ibmphp_pci_bus->number = busno;
- for (count = 0; address[count]; count++) {
- pci_bus_read_config_dword (ibmphp_pci_bus, devfn, address[count], &start_address);
-
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], 0xFFFFFFFF);
- pci_bus_read_config_dword (ibmphp_pci_bus, devfn, address[count], &size);
- pci_bus_write_config_dword (ibmphp_pci_bus, devfn, address[count], start_address);
- debug ("start_address is %x\n", start_address);
- debug ("busno, device, function %x %x %x\n", busno, device, function);
- if (!size) {
-
- debug ("is this bar no implemented?, count = %d\n", count);
- continue;
- }
- tmp_address = start_address;
- if (start_address & PCI_BASE_ADDRESS_SPACE_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) < 0) {
- err ("cannot find corresponding IO resource to remove\n");
- return -EIO;
- }
- debug ("io->start = %x\n", io->start);
- temp_end = io->end;
- start_address = io->end + 1;
- ibmphp_remove_resource (io);
-
- while (temp_end < end_address) {
- if (ibmphp_find_resource (bus, start_address, &io, IO) < 0) {
- err ("cannot find corresponding IO resource to remove\n");
- return -EIO;
- }
- debug ("io->start = %x\n", io->start);
- temp_end = io->end;
- start_address = io->end + 1;
- ibmphp_remove_resource (io);
- }
-
- } else {
-
- if (start_address & PCI_BASE_ADDRESS_MEM_PREFETCH) {
-
- 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 {
-
- 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) {
-
- count += 1;
- }
- }
- }
- return 0;
- }
- static int unconfigure_boot_bridge (u8 busno, u8 device, u8 function)
- {
- int count;
- int bus_no, pri_no, sub_no, sec_no = 0;
- u32 start_address, tmp_address;
- u8 sec_number, sub_number, pri_number;
- struct resource_node *io = NULL;
- struct resource_node *mem = NULL;
- struct resource_node *pfmem = NULL;
- struct bus_node *bus;
- u32 address[] = {
- PCI_BASE_ADDRESS_0,
- PCI_BASE_ADDRESS_1,
- 0
- };
- unsigned int devfn;
- devfn = PCI_DEVFN(device, function);
- ibmphp_pci_bus->number = busno;
- bus_no = (int) busno;
- debug ("busno is %x\n", busno);
- pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_PRIMARY_BUS, &pri_number);
- debug ("%s - busno = %x, primary_number = %x\n", __func__, busno, pri_number);
- 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++) {
-
- pci_bus_read_config_dword (ibmphp_pci_bus, devfn, address[count], &start_address);
- if (!start_address) {
-
- continue;
- }
- tmp_address = start_address;
- if (start_address & PCI_BASE_ADDRESS_SPACE_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);
-
- } else {
-
- if (start_address & PCI_BASE_ADDRESS_MEM_PREFETCH) {
-
- 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 {
-
- 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) {
-
- count += 1;
- }
- }
- }
- debug ("%s - exiting, returning success\n", __func__);
- return 0;
- }
- static int unconfigure_boot_card (struct slot *slot_cur)
- {
- u16 vendor_id;
- u32 class;
- u8 hdr_type;
- u8 device;
- u8 busno;
- u8 function;
- int rc;
- unsigned int devfn;
- u8 valid_device = 0x00;
- debug ("%s - enter\n", __func__);
- device = slot_cur->device;
- busno = slot_cur->bus;
- debug ("b4 for loop, device is %x\n", device);
-
- for (function = 0x0; function < 0x08; function++) {
- devfn = PCI_DEVFN(device, function);
- ibmphp_pci_bus->number = busno;
- pci_bus_read_config_word (ibmphp_pci_bus, devfn, PCI_VENDOR_ID, &vendor_id);
- if (vendor_id != PCI_VENDOR_ID_NOTVALID) {
-
- ++valid_device;
- debug ("%s - found correct device\n", __func__);
-
- pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_HEADER_TYPE, &hdr_type);
- pci_bus_read_config_dword (ibmphp_pci_bus, devfn, PCI_CLASS_REVISION, &class);
- debug ("hdr_type %x, class %x\n", hdr_type, class);
- class >>= 8;
- 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;
- } else if (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;
- break;
- }
- }
- }
- if (!valid_device) {
- err ("Could not find device to unconfigure. Or could not read the card.\n");
- return -1;
- }
- return 0;
- }
- 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) {
-
- rc = unconfigure_boot_card (sl);
- if ((rc == -ENODEV) || (rc == -EIO) || (rc == -EINVAL)) {
-
- return rc;
- }
- }
- if (sl->func) {
- cur_func = sl->func;
- while (cur_func) {
-
- if (cur_func->bus) {
-
- 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;
- }
- }
- temp_func = cur_func->next;
- kfree (cur_func);
- cur_func = temp_func;
- }
- }
- sl->func = NULL;
- *slot_cur = sl;
- debug ("%s - exit\n", __func__);
- return 0;
- }
- static int 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;
-
- 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) {
- err ("out of system memory\n");
- return -ENOMEM;
- }
- io_range->start = io->start;
- io_range->end = io->end;
- io_range->rangeno = 1;
- bus->noIORanges = 1;
- bus->rangeIO = io_range;
- }
- if (mem) {
- mem_range = kzalloc(sizeof(*mem_range), GFP_KERNEL);
- if (!mem_range) {
- err ("out of system memory\n");
- return -ENOMEM;
- }
- mem_range->start = mem->start;
- mem_range->end = mem->end;
- mem_range->rangeno = 1;
- bus->noMemRanges = 1;
- bus->rangeMem = mem_range;
- }
- if (pfmem) {
- pfmem_range = kzalloc(sizeof(*pfmem_range), GFP_KERNEL);
- if (!pfmem_range) {
- err ("out of system memory\n");
- return -ENOMEM;
- }
- pfmem_range->start = pfmem->start;
- pfmem_range->end = pfmem->end;
- pfmem_range->rangeno = 1;
- bus->noPFMemRanges = 1;
- bus->rangePFMem = pfmem_range;
- }
- return 0;
- }
- 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);
-
- if ((!bus_cur) || (!(bus_cur->rangeIO) && !(bus_cur->rangeMem) && !(bus_cur->rangePFMem)))
- return busno;
- return 0xff;
- }
|