Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * IBM Hot Plug Controller Driver
0004  *
0005  * Written By: Tong Yu, IBM Corporation
0006  *
0007  * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com)
0008  * Copyright (C) 2001-2003 IBM Corp.
0009  *
0010  * All rights reserved.
0011  *
0012  * Send feedback to <gregkh@us.ibm.com>
0013  *
0014  */
0015 
0016 #include <linux/module.h>
0017 #include <linux/errno.h>
0018 #include <linux/mm.h>
0019 #include <linux/slab.h>
0020 #include <linux/pci.h>
0021 #include <linux/list.h>
0022 #include <linux/init.h>
0023 #include "ibmphp.h"
0024 
0025 /*
0026  * POST builds data blocks(in this data block definition, a char-1
0027  * byte, short(or word)-2 byte, long(dword)-4 byte) in the Extended
0028  * BIOS Data Area which describe the configuration of the hot-plug
0029  * controllers and resources used by the PCI Hot-Plug devices.
0030  *
0031  * This file walks EBDA, maps data block from physical addr,
0032  * reconstruct linked lists about all system resource(MEM, PFM, IO)
0033  * already assigned by POST, as well as linked lists about hot plug
0034  * controllers (ctlr#, slot#, bus&slot features...)
0035  */
0036 
0037 /* Global lists */
0038 LIST_HEAD(ibmphp_ebda_pci_rsrc_head);
0039 LIST_HEAD(ibmphp_slot_head);
0040 
0041 /* Local variables */
0042 static struct ebda_hpc_list *hpc_list_ptr;
0043 static struct ebda_rsrc_list *rsrc_list_ptr;
0044 static struct rio_table_hdr *rio_table_ptr = NULL;
0045 static LIST_HEAD(ebda_hpc_head);
0046 static LIST_HEAD(bus_info_head);
0047 static LIST_HEAD(rio_vg_head);
0048 static LIST_HEAD(rio_lo_head);
0049 static LIST_HEAD(opt_vg_head);
0050 static LIST_HEAD(opt_lo_head);
0051 static void __iomem *io_mem;
0052 
0053 /* Local functions */
0054 static int ebda_rsrc_controller(void);
0055 static int ebda_rsrc_rsrc(void);
0056 static int ebda_rio_table(void);
0057 
0058 static struct ebda_hpc_list * __init alloc_ebda_hpc_list(void)
0059 {
0060     return kzalloc(sizeof(struct ebda_hpc_list), GFP_KERNEL);
0061 }
0062 
0063 static struct controller *alloc_ebda_hpc(u32 slot_count, u32 bus_count)
0064 {
0065     struct controller *controller;
0066     struct ebda_hpc_slot *slots;
0067     struct ebda_hpc_bus *buses;
0068 
0069     controller = kzalloc(sizeof(struct controller), GFP_KERNEL);
0070     if (!controller)
0071         goto error;
0072 
0073     slots = kcalloc(slot_count, sizeof(struct ebda_hpc_slot), GFP_KERNEL);
0074     if (!slots)
0075         goto error_contr;
0076     controller->slots = slots;
0077 
0078     buses = kcalloc(bus_count, sizeof(struct ebda_hpc_bus), GFP_KERNEL);
0079     if (!buses)
0080         goto error_slots;
0081     controller->buses = buses;
0082 
0083     return controller;
0084 error_slots:
0085     kfree(controller->slots);
0086 error_contr:
0087     kfree(controller);
0088 error:
0089     return NULL;
0090 }
0091 
0092 static void free_ebda_hpc(struct controller *controller)
0093 {
0094     kfree(controller->slots);
0095     kfree(controller->buses);
0096     kfree(controller);
0097 }
0098 
0099 static struct ebda_rsrc_list * __init alloc_ebda_rsrc_list(void)
0100 {
0101     return kzalloc(sizeof(struct ebda_rsrc_list), GFP_KERNEL);
0102 }
0103 
0104 static struct ebda_pci_rsrc *alloc_ebda_pci_rsrc(void)
0105 {
0106     return kzalloc(sizeof(struct ebda_pci_rsrc), GFP_KERNEL);
0107 }
0108 
0109 static void __init print_bus_info(void)
0110 {
0111     struct bus_info *ptr;
0112 
0113     list_for_each_entry(ptr, &bus_info_head, bus_info_list) {
0114         debug("%s - slot_min = %x\n", __func__, ptr->slot_min);
0115         debug("%s - slot_max = %x\n", __func__, ptr->slot_max);
0116         debug("%s - slot_count = %x\n", __func__, ptr->slot_count);
0117         debug("%s - bus# = %x\n", __func__, ptr->busno);
0118         debug("%s - current_speed = %x\n", __func__, ptr->current_speed);
0119         debug("%s - controller_id = %x\n", __func__, ptr->controller_id);
0120 
0121         debug("%s - slots_at_33_conv = %x\n", __func__, ptr->slots_at_33_conv);
0122         debug("%s - slots_at_66_conv = %x\n", __func__, ptr->slots_at_66_conv);
0123         debug("%s - slots_at_66_pcix = %x\n", __func__, ptr->slots_at_66_pcix);
0124         debug("%s - slots_at_100_pcix = %x\n", __func__, ptr->slots_at_100_pcix);
0125         debug("%s - slots_at_133_pcix = %x\n", __func__, ptr->slots_at_133_pcix);
0126 
0127     }
0128 }
0129 
0130 static void print_lo_info(void)
0131 {
0132     struct rio_detail *ptr;
0133     debug("print_lo_info ----\n");
0134     list_for_each_entry(ptr, &rio_lo_head, rio_detail_list) {
0135         debug("%s - rio_node_id = %x\n", __func__, ptr->rio_node_id);
0136         debug("%s - rio_type = %x\n", __func__, ptr->rio_type);
0137         debug("%s - owner_id = %x\n", __func__, ptr->owner_id);
0138         debug("%s - first_slot_num = %x\n", __func__, ptr->first_slot_num);
0139         debug("%s - wpindex = %x\n", __func__, ptr->wpindex);
0140         debug("%s - chassis_num = %x\n", __func__, ptr->chassis_num);
0141 
0142     }
0143 }
0144 
0145 static void print_vg_info(void)
0146 {
0147     struct rio_detail *ptr;
0148     debug("%s ---\n", __func__);
0149     list_for_each_entry(ptr, &rio_vg_head, rio_detail_list) {
0150         debug("%s - rio_node_id = %x\n", __func__, ptr->rio_node_id);
0151         debug("%s - rio_type = %x\n", __func__, ptr->rio_type);
0152         debug("%s - owner_id = %x\n", __func__, ptr->owner_id);
0153         debug("%s - first_slot_num = %x\n", __func__, ptr->first_slot_num);
0154         debug("%s - wpindex = %x\n", __func__, ptr->wpindex);
0155         debug("%s - chassis_num = %x\n", __func__, ptr->chassis_num);
0156 
0157     }
0158 }
0159 
0160 static void __init print_ebda_pci_rsrc(void)
0161 {
0162     struct ebda_pci_rsrc *ptr;
0163 
0164     list_for_each_entry(ptr, &ibmphp_ebda_pci_rsrc_head, ebda_pci_rsrc_list) {
0165         debug("%s - rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
0166             __func__, ptr->rsrc_type, ptr->bus_num, ptr->dev_fun, ptr->start_addr, ptr->end_addr);
0167     }
0168 }
0169 
0170 static void __init print_ibm_slot(void)
0171 {
0172     struct slot *ptr;
0173 
0174     list_for_each_entry(ptr, &ibmphp_slot_head, ibm_slot_list) {
0175         debug("%s - slot_number: %x\n", __func__, ptr->number);
0176     }
0177 }
0178 
0179 static void __init print_opt_vg(void)
0180 {
0181     struct opt_rio *ptr;
0182     debug("%s ---\n", __func__);
0183     list_for_each_entry(ptr, &opt_vg_head, opt_rio_list) {
0184         debug("%s - rio_type %x\n", __func__, ptr->rio_type);
0185         debug("%s - chassis_num: %x\n", __func__, ptr->chassis_num);
0186         debug("%s - first_slot_num: %x\n", __func__, ptr->first_slot_num);
0187         debug("%s - middle_num: %x\n", __func__, ptr->middle_num);
0188     }
0189 }
0190 
0191 static void __init print_ebda_hpc(void)
0192 {
0193     struct controller *hpc_ptr;
0194     u16 index;
0195 
0196     list_for_each_entry(hpc_ptr, &ebda_hpc_head, ebda_hpc_list) {
0197         for (index = 0; index < hpc_ptr->slot_count; index++) {
0198             debug("%s - physical slot#: %x\n", __func__, hpc_ptr->slots[index].slot_num);
0199             debug("%s - pci bus# of the slot: %x\n", __func__, hpc_ptr->slots[index].slot_bus_num);
0200             debug("%s - index into ctlr addr: %x\n", __func__, hpc_ptr->slots[index].ctl_index);
0201             debug("%s - cap of the slot: %x\n", __func__, hpc_ptr->slots[index].slot_cap);
0202         }
0203 
0204         for (index = 0; index < hpc_ptr->bus_count; index++)
0205             debug("%s - bus# of each bus controlled by this ctlr: %x\n", __func__, hpc_ptr->buses[index].bus_num);
0206 
0207         debug("%s - type of hpc: %x\n", __func__, hpc_ptr->ctlr_type);
0208         switch (hpc_ptr->ctlr_type) {
0209         case 1:
0210             debug("%s - bus: %x\n", __func__, hpc_ptr->u.pci_ctlr.bus);
0211             debug("%s - dev_fun: %x\n", __func__, hpc_ptr->u.pci_ctlr.dev_fun);
0212             debug("%s - irq: %x\n", __func__, hpc_ptr->irq);
0213             break;
0214 
0215         case 0:
0216             debug("%s - io_start: %x\n", __func__, hpc_ptr->u.isa_ctlr.io_start);
0217             debug("%s - io_end: %x\n", __func__, hpc_ptr->u.isa_ctlr.io_end);
0218             debug("%s - irq: %x\n", __func__, hpc_ptr->irq);
0219             break;
0220 
0221         case 2:
0222         case 4:
0223             debug("%s - wpegbbar: %lx\n", __func__, hpc_ptr->u.wpeg_ctlr.wpegbbar);
0224             debug("%s - i2c_addr: %x\n", __func__, hpc_ptr->u.wpeg_ctlr.i2c_addr);
0225             debug("%s - irq: %x\n", __func__, hpc_ptr->irq);
0226             break;
0227         }
0228     }
0229 }
0230 
0231 int __init ibmphp_access_ebda(void)
0232 {
0233     u8 format, num_ctlrs, rio_complete, hs_complete, ebda_sz;
0234     u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, re, rc_id, re_id, base;
0235     int rc = 0;
0236 
0237 
0238     rio_complete = 0;
0239     hs_complete = 0;
0240 
0241     io_mem = ioremap((0x40 << 4) + 0x0e, 2);
0242     if (!io_mem)
0243         return -ENOMEM;
0244     ebda_seg = readw(io_mem);
0245     iounmap(io_mem);
0246     debug("returned ebda segment: %x\n", ebda_seg);
0247 
0248     io_mem = ioremap(ebda_seg<<4, 1);
0249     if (!io_mem)
0250         return -ENOMEM;
0251     ebda_sz = readb(io_mem);
0252     iounmap(io_mem);
0253     debug("ebda size: %d(KiB)\n", ebda_sz);
0254     if (ebda_sz == 0)
0255         return -ENOMEM;
0256 
0257     io_mem = ioremap(ebda_seg<<4, (ebda_sz * 1024));
0258     if (!io_mem)
0259         return -ENOMEM;
0260     next_offset = 0x180;
0261 
0262     for (;;) {
0263         offset = next_offset;
0264 
0265         /* Make sure what we read is still in the mapped section */
0266         if (WARN(offset > (ebda_sz * 1024 - 4),
0267              "ibmphp_ebda: next read is beyond ebda_sz\n"))
0268             break;
0269 
0270         next_offset = readw(io_mem + offset);   /* offset of next blk */
0271 
0272         offset += 2;
0273         if (next_offset == 0)   /* 0 indicate it's last blk */
0274             break;
0275         blk_id = readw(io_mem + offset);    /* this blk id */
0276 
0277         offset += 2;
0278         /* check if it is hot swap block or rio block */
0279         if (blk_id != 0x4853 && blk_id != 0x4752)
0280             continue;
0281         /* found hs table */
0282         if (blk_id == 0x4853) {
0283             debug("now enter hot swap block---\n");
0284             debug("hot blk id: %x\n", blk_id);
0285             format = readb(io_mem + offset);
0286 
0287             offset += 1;
0288             if (format != 4)
0289                 goto error_nodev;
0290             debug("hot blk format: %x\n", format);
0291             /* hot swap sub blk */
0292             base = offset;
0293 
0294             sub_addr = base;
0295             re = readw(io_mem + sub_addr);  /* next sub blk */
0296 
0297             sub_addr += 2;
0298             rc_id = readw(io_mem + sub_addr);   /* sub blk id */
0299 
0300             sub_addr += 2;
0301             if (rc_id != 0x5243)
0302                 goto error_nodev;
0303             /* rc sub blk signature  */
0304             num_ctlrs = readb(io_mem + sub_addr);
0305 
0306             sub_addr += 1;
0307             hpc_list_ptr = alloc_ebda_hpc_list();
0308             if (!hpc_list_ptr) {
0309                 rc = -ENOMEM;
0310                 goto out;
0311             }
0312             hpc_list_ptr->format = format;
0313             hpc_list_ptr->num_ctlrs = num_ctlrs;
0314             hpc_list_ptr->phys_addr = sub_addr; /*  offset of RSRC_CONTROLLER blk */
0315             debug("info about hpc descriptor---\n");
0316             debug("hot blk format: %x\n", format);
0317             debug("num of controller: %x\n", num_ctlrs);
0318             debug("offset of hpc data structure entries: %x\n ", sub_addr);
0319 
0320             sub_addr = base + re;   /* re sub blk */
0321             /* FIXME: rc is never used/checked */
0322             rc = readw(io_mem + sub_addr);  /* next sub blk */
0323 
0324             sub_addr += 2;
0325             re_id = readw(io_mem + sub_addr);   /* sub blk id */
0326 
0327             sub_addr += 2;
0328             if (re_id != 0x5245)
0329                 goto error_nodev;
0330 
0331             /* signature of re */
0332             num_entries = readw(io_mem + sub_addr);
0333 
0334             sub_addr += 2;  /* offset of RSRC_ENTRIES blk */
0335             rsrc_list_ptr = alloc_ebda_rsrc_list();
0336             if (!rsrc_list_ptr) {
0337                 rc = -ENOMEM;
0338                 goto out;
0339             }
0340             rsrc_list_ptr->format = format;
0341             rsrc_list_ptr->num_entries = num_entries;
0342             rsrc_list_ptr->phys_addr = sub_addr;
0343 
0344             debug("info about rsrc descriptor---\n");
0345             debug("format: %x\n", format);
0346             debug("num of rsrc: %x\n", num_entries);
0347             debug("offset of rsrc data structure entries: %x\n ", sub_addr);
0348 
0349             hs_complete = 1;
0350         } else {
0351         /* found rio table, blk_id == 0x4752 */
0352             debug("now enter io table ---\n");
0353             debug("rio blk id: %x\n", blk_id);
0354 
0355             rio_table_ptr = kzalloc(sizeof(struct rio_table_hdr), GFP_KERNEL);
0356             if (!rio_table_ptr) {
0357                 rc = -ENOMEM;
0358                 goto out;
0359             }
0360             rio_table_ptr->ver_num = readb(io_mem + offset);
0361             rio_table_ptr->scal_count = readb(io_mem + offset + 1);
0362             rio_table_ptr->riodev_count = readb(io_mem + offset + 2);
0363             rio_table_ptr->offset = offset + 3 ;
0364 
0365             debug("info about rio table hdr ---\n");
0366             debug("ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ",
0367                 rio_table_ptr->ver_num, rio_table_ptr->scal_count,
0368                 rio_table_ptr->riodev_count, rio_table_ptr->offset);
0369 
0370             rio_complete = 1;
0371         }
0372     }
0373 
0374     if (!hs_complete && !rio_complete)
0375         goto error_nodev;
0376 
0377     if (rio_table_ptr) {
0378         if (rio_complete && rio_table_ptr->ver_num == 3) {
0379             rc = ebda_rio_table();
0380             if (rc)
0381                 goto out;
0382         }
0383     }
0384     rc = ebda_rsrc_controller();
0385     if (rc)
0386         goto out;
0387 
0388     rc = ebda_rsrc_rsrc();
0389     goto out;
0390 error_nodev:
0391     rc = -ENODEV;
0392 out:
0393     iounmap(io_mem);
0394     return rc;
0395 }
0396 
0397 /*
0398  * map info of scalability details and rio details from physical address
0399  */
0400 static int __init ebda_rio_table(void)
0401 {
0402     u16 offset;
0403     u8 i;
0404     struct rio_detail *rio_detail_ptr;
0405 
0406     offset = rio_table_ptr->offset;
0407     offset += 12 * rio_table_ptr->scal_count;
0408 
0409     // we do concern about rio details
0410     for (i = 0; i < rio_table_ptr->riodev_count; i++) {
0411         rio_detail_ptr = kzalloc(sizeof(struct rio_detail), GFP_KERNEL);
0412         if (!rio_detail_ptr)
0413             return -ENOMEM;
0414         rio_detail_ptr->rio_node_id = readb(io_mem + offset);
0415         rio_detail_ptr->bbar = readl(io_mem + offset + 1);
0416         rio_detail_ptr->rio_type = readb(io_mem + offset + 5);
0417         rio_detail_ptr->owner_id = readb(io_mem + offset + 6);
0418         rio_detail_ptr->port0_node_connect = readb(io_mem + offset + 7);
0419         rio_detail_ptr->port0_port_connect = readb(io_mem + offset + 8);
0420         rio_detail_ptr->port1_node_connect = readb(io_mem + offset + 9);
0421         rio_detail_ptr->port1_port_connect = readb(io_mem + offset + 10);
0422         rio_detail_ptr->first_slot_num = readb(io_mem + offset + 11);
0423         rio_detail_ptr->status = readb(io_mem + offset + 12);
0424         rio_detail_ptr->wpindex = readb(io_mem + offset + 13);
0425         rio_detail_ptr->chassis_num = readb(io_mem + offset + 14);
0426 //      debug("rio_node_id: %x\nbbar: %x\nrio_type: %x\nowner_id: %x\nport0_node: %x\nport0_port: %x\nport1_node: %x\nport1_port: %x\nfirst_slot_num: %x\nstatus: %x\n", rio_detail_ptr->rio_node_id, rio_detail_ptr->bbar, rio_detail_ptr->rio_type, rio_detail_ptr->owner_id, rio_detail_ptr->port0_node_connect, rio_detail_ptr->port0_port_connect, rio_detail_ptr->port1_node_connect, rio_detail_ptr->port1_port_connect, rio_detail_ptr->first_slot_num, rio_detail_ptr->status);
0427         //create linked list of chassis
0428         if (rio_detail_ptr->rio_type == 4 || rio_detail_ptr->rio_type == 5)
0429             list_add(&rio_detail_ptr->rio_detail_list, &rio_vg_head);
0430         //create linked list of expansion box
0431         else if (rio_detail_ptr->rio_type == 6 || rio_detail_ptr->rio_type == 7)
0432             list_add(&rio_detail_ptr->rio_detail_list, &rio_lo_head);
0433         else
0434             // not in my concern
0435             kfree(rio_detail_ptr);
0436         offset += 15;
0437     }
0438     print_lo_info();
0439     print_vg_info();
0440     return 0;
0441 }
0442 
0443 /*
0444  * reorganizing linked list of chassis
0445  */
0446 static struct opt_rio *search_opt_vg(u8 chassis_num)
0447 {
0448     struct opt_rio *ptr;
0449     list_for_each_entry(ptr, &opt_vg_head, opt_rio_list) {
0450         if (ptr->chassis_num == chassis_num)
0451             return ptr;
0452     }
0453     return NULL;
0454 }
0455 
0456 static int __init combine_wpg_for_chassis(void)
0457 {
0458     struct opt_rio *opt_rio_ptr = NULL;
0459     struct rio_detail *rio_detail_ptr = NULL;
0460 
0461     list_for_each_entry(rio_detail_ptr, &rio_vg_head, rio_detail_list) {
0462         opt_rio_ptr = search_opt_vg(rio_detail_ptr->chassis_num);
0463         if (!opt_rio_ptr) {
0464             opt_rio_ptr = kzalloc(sizeof(struct opt_rio), GFP_KERNEL);
0465             if (!opt_rio_ptr)
0466                 return -ENOMEM;
0467             opt_rio_ptr->rio_type = rio_detail_ptr->rio_type;
0468             opt_rio_ptr->chassis_num = rio_detail_ptr->chassis_num;
0469             opt_rio_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
0470             opt_rio_ptr->middle_num = rio_detail_ptr->first_slot_num;
0471             list_add(&opt_rio_ptr->opt_rio_list, &opt_vg_head);
0472         } else {
0473             opt_rio_ptr->first_slot_num = min(opt_rio_ptr->first_slot_num, rio_detail_ptr->first_slot_num);
0474             opt_rio_ptr->middle_num = max(opt_rio_ptr->middle_num, rio_detail_ptr->first_slot_num);
0475         }
0476     }
0477     print_opt_vg();
0478     return 0;
0479 }
0480 
0481 /*
0482  * reorganizing linked list of expansion box
0483  */
0484 static struct opt_rio_lo *search_opt_lo(u8 chassis_num)
0485 {
0486     struct opt_rio_lo *ptr;
0487     list_for_each_entry(ptr, &opt_lo_head, opt_rio_lo_list) {
0488         if (ptr->chassis_num == chassis_num)
0489             return ptr;
0490     }
0491     return NULL;
0492 }
0493 
0494 static int combine_wpg_for_expansion(void)
0495 {
0496     struct opt_rio_lo *opt_rio_lo_ptr = NULL;
0497     struct rio_detail *rio_detail_ptr = NULL;
0498 
0499     list_for_each_entry(rio_detail_ptr, &rio_lo_head, rio_detail_list) {
0500         opt_rio_lo_ptr = search_opt_lo(rio_detail_ptr->chassis_num);
0501         if (!opt_rio_lo_ptr) {
0502             opt_rio_lo_ptr = kzalloc(sizeof(struct opt_rio_lo), GFP_KERNEL);
0503             if (!opt_rio_lo_ptr)
0504                 return -ENOMEM;
0505             opt_rio_lo_ptr->rio_type = rio_detail_ptr->rio_type;
0506             opt_rio_lo_ptr->chassis_num = rio_detail_ptr->chassis_num;
0507             opt_rio_lo_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
0508             opt_rio_lo_ptr->middle_num = rio_detail_ptr->first_slot_num;
0509             opt_rio_lo_ptr->pack_count = 1;
0510 
0511             list_add(&opt_rio_lo_ptr->opt_rio_lo_list, &opt_lo_head);
0512         } else {
0513             opt_rio_lo_ptr->first_slot_num = min(opt_rio_lo_ptr->first_slot_num, rio_detail_ptr->first_slot_num);
0514             opt_rio_lo_ptr->middle_num = max(opt_rio_lo_ptr->middle_num, rio_detail_ptr->first_slot_num);
0515             opt_rio_lo_ptr->pack_count = 2;
0516         }
0517     }
0518     return 0;
0519 }
0520 
0521 
0522 /* Since we don't know the max slot number per each chassis, hence go
0523  * through the list of all chassis to find out the range
0524  * Arguments: slot_num, 1st slot number of the chassis we think we are on,
0525  * var (0 = chassis, 1 = expansion box)
0526  */
0527 static int first_slot_num(u8 slot_num, u8 first_slot, u8 var)
0528 {
0529     struct opt_rio *opt_vg_ptr = NULL;
0530     struct opt_rio_lo *opt_lo_ptr = NULL;
0531     int rc = 0;
0532 
0533     if (!var) {
0534         list_for_each_entry(opt_vg_ptr, &opt_vg_head, opt_rio_list) {
0535             if ((first_slot < opt_vg_ptr->first_slot_num) && (slot_num >= opt_vg_ptr->first_slot_num)) {
0536                 rc = -ENODEV;
0537                 break;
0538             }
0539         }
0540     } else {
0541         list_for_each_entry(opt_lo_ptr, &opt_lo_head, opt_rio_lo_list) {
0542             if ((first_slot < opt_lo_ptr->first_slot_num) && (slot_num >= opt_lo_ptr->first_slot_num)) {
0543                 rc = -ENODEV;
0544                 break;
0545             }
0546         }
0547     }
0548     return rc;
0549 }
0550 
0551 static struct opt_rio_lo *find_rxe_num(u8 slot_num)
0552 {
0553     struct opt_rio_lo *opt_lo_ptr;
0554 
0555     list_for_each_entry(opt_lo_ptr, &opt_lo_head, opt_rio_lo_list) {
0556         //check to see if this slot_num belongs to expansion box
0557         if ((slot_num >= opt_lo_ptr->first_slot_num) && (!first_slot_num(slot_num, opt_lo_ptr->first_slot_num, 1)))
0558             return opt_lo_ptr;
0559     }
0560     return NULL;
0561 }
0562 
0563 static struct opt_rio *find_chassis_num(u8 slot_num)
0564 {
0565     struct opt_rio *opt_vg_ptr;
0566 
0567     list_for_each_entry(opt_vg_ptr, &opt_vg_head, opt_rio_list) {
0568         //check to see if this slot_num belongs to chassis
0569         if ((slot_num >= opt_vg_ptr->first_slot_num) && (!first_slot_num(slot_num, opt_vg_ptr->first_slot_num, 0)))
0570             return opt_vg_ptr;
0571     }
0572     return NULL;
0573 }
0574 
0575 /* This routine will find out how many slots are in the chassis, so that
0576  * the slot numbers for rxe100 would start from 1, and not from 7, or 6 etc
0577  */
0578 static u8 calculate_first_slot(u8 slot_num)
0579 {
0580     u8 first_slot = 1;
0581     struct slot *slot_cur;
0582 
0583     list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) {
0584         if (slot_cur->ctrl) {
0585             if ((slot_cur->ctrl->ctlr_type != 4) && (slot_cur->ctrl->ending_slot_num > first_slot) && (slot_num > slot_cur->ctrl->ending_slot_num))
0586                 first_slot = slot_cur->ctrl->ending_slot_num;
0587         }
0588     }
0589     return first_slot + 1;
0590 
0591 }
0592 
0593 #define SLOT_NAME_SIZE 30
0594 
0595 static char *create_file_name(struct slot *slot_cur)
0596 {
0597     struct opt_rio *opt_vg_ptr = NULL;
0598     struct opt_rio_lo *opt_lo_ptr = NULL;
0599     static char str[SLOT_NAME_SIZE];
0600     int which = 0; /* rxe = 1, chassis = 0 */
0601     u8 number = 1; /* either chassis or rxe # */
0602     u8 first_slot = 1;
0603     u8 slot_num;
0604     u8 flag = 0;
0605 
0606     if (!slot_cur) {
0607         err("Structure passed is empty\n");
0608         return NULL;
0609     }
0610 
0611     slot_num = slot_cur->number;
0612 
0613     memset(str, 0, sizeof(str));
0614 
0615     if (rio_table_ptr) {
0616         if (rio_table_ptr->ver_num == 3) {
0617             opt_vg_ptr = find_chassis_num(slot_num);
0618             opt_lo_ptr = find_rxe_num(slot_num);
0619         }
0620     }
0621     if (opt_vg_ptr) {
0622         if (opt_lo_ptr) {
0623             if ((slot_num - opt_vg_ptr->first_slot_num) > (slot_num - opt_lo_ptr->first_slot_num)) {
0624                 number = opt_lo_ptr->chassis_num;
0625                 first_slot = opt_lo_ptr->first_slot_num;
0626                 which = 1; /* it is RXE */
0627             } else {
0628                 first_slot = opt_vg_ptr->first_slot_num;
0629                 number = opt_vg_ptr->chassis_num;
0630                 which = 0;
0631             }
0632         } else {
0633             first_slot = opt_vg_ptr->first_slot_num;
0634             number = opt_vg_ptr->chassis_num;
0635             which = 0;
0636         }
0637         ++flag;
0638     } else if (opt_lo_ptr) {
0639         number = opt_lo_ptr->chassis_num;
0640         first_slot = opt_lo_ptr->first_slot_num;
0641         which = 1;
0642         ++flag;
0643     } else if (rio_table_ptr) {
0644         if (rio_table_ptr->ver_num == 3) {
0645             /* if both NULL and we DO have correct RIO table in BIOS */
0646             return NULL;
0647         }
0648     }
0649     if (!flag) {
0650         if (slot_cur->ctrl->ctlr_type == 4) {
0651             first_slot = calculate_first_slot(slot_num);
0652             which = 1;
0653         } else {
0654             which = 0;
0655         }
0656     }
0657 
0658     sprintf(str, "%s%dslot%d",
0659         which == 0 ? "chassis" : "rxe",
0660         number, slot_num - first_slot + 1);
0661     return str;
0662 }
0663 
0664 static int fillslotinfo(struct hotplug_slot *hotplug_slot)
0665 {
0666     struct slot *slot;
0667     int rc = 0;
0668 
0669     slot = to_slot(hotplug_slot);
0670     rc = ibmphp_hpc_readslot(slot, READ_ALLSTAT, NULL);
0671     return rc;
0672 }
0673 
0674 static struct pci_driver ibmphp_driver;
0675 
0676 /*
0677  * map info (ctlr-id, slot count, slot#.. bus count, bus#, ctlr type...) of
0678  * each hpc from physical address to a list of hot plug controllers based on
0679  * hpc descriptors.
0680  */
0681 static int __init ebda_rsrc_controller(void)
0682 {
0683     u16 addr, addr_slot, addr_bus;
0684     u8 ctlr_id, temp, bus_index;
0685     u16 ctlr, slot, bus;
0686     u16 slot_num, bus_num, index;
0687     struct controller *hpc_ptr;
0688     struct ebda_hpc_bus *bus_ptr;
0689     struct ebda_hpc_slot *slot_ptr;
0690     struct bus_info *bus_info_ptr1, *bus_info_ptr2;
0691     int rc;
0692     struct slot *tmp_slot;
0693     char name[SLOT_NAME_SIZE];
0694 
0695     addr = hpc_list_ptr->phys_addr;
0696     for (ctlr = 0; ctlr < hpc_list_ptr->num_ctlrs; ctlr++) {
0697         bus_index = 1;
0698         ctlr_id = readb(io_mem + addr);
0699         addr += 1;
0700         slot_num = readb(io_mem + addr);
0701 
0702         addr += 1;
0703         addr_slot = addr;   /* offset of slot structure */
0704         addr += (slot_num * 4);
0705 
0706         bus_num = readb(io_mem + addr);
0707 
0708         addr += 1;
0709         addr_bus = addr;    /* offset of bus */
0710         addr += (bus_num * 9);  /* offset of ctlr_type */
0711         temp = readb(io_mem + addr);
0712 
0713         addr += 1;
0714         /* init hpc structure */
0715         hpc_ptr = alloc_ebda_hpc(slot_num, bus_num);
0716         if (!hpc_ptr) {
0717             return -ENOMEM;
0718         }
0719         hpc_ptr->ctlr_id = ctlr_id;
0720         hpc_ptr->ctlr_relative_id = ctlr;
0721         hpc_ptr->slot_count = slot_num;
0722         hpc_ptr->bus_count = bus_num;
0723         debug("now enter ctlr data structure ---\n");
0724         debug("ctlr id: %x\n", ctlr_id);
0725         debug("ctlr_relative_id: %x\n", hpc_ptr->ctlr_relative_id);
0726         debug("count of slots controlled by this ctlr: %x\n", slot_num);
0727         debug("count of buses controlled by this ctlr: %x\n", bus_num);
0728 
0729         /* init slot structure, fetch slot, bus, cap... */
0730         slot_ptr = hpc_ptr->slots;
0731         for (slot = 0; slot < slot_num; slot++) {
0732             slot_ptr->slot_num = readb(io_mem + addr_slot);
0733             slot_ptr->slot_bus_num = readb(io_mem + addr_slot + slot_num);
0734             slot_ptr->ctl_index = readb(io_mem + addr_slot + 2*slot_num);
0735             slot_ptr->slot_cap = readb(io_mem + addr_slot + 3*slot_num);
0736 
0737             // create bus_info lined list --- if only one slot per bus: slot_min = slot_max
0738 
0739             bus_info_ptr2 = ibmphp_find_same_bus_num(slot_ptr->slot_bus_num);
0740             if (!bus_info_ptr2) {
0741                 bus_info_ptr1 = kzalloc(sizeof(struct bus_info), GFP_KERNEL);
0742                 if (!bus_info_ptr1) {
0743                     rc = -ENOMEM;
0744                     goto error_no_slot;
0745                 }
0746                 bus_info_ptr1->slot_min = slot_ptr->slot_num;
0747                 bus_info_ptr1->slot_max = slot_ptr->slot_num;
0748                 bus_info_ptr1->slot_count += 1;
0749                 bus_info_ptr1->busno = slot_ptr->slot_bus_num;
0750                 bus_info_ptr1->index = bus_index++;
0751                 bus_info_ptr1->current_speed = 0xff;
0752                 bus_info_ptr1->current_bus_mode = 0xff;
0753 
0754                 bus_info_ptr1->controller_id = hpc_ptr->ctlr_id;
0755 
0756                 list_add_tail(&bus_info_ptr1->bus_info_list, &bus_info_head);
0757 
0758             } else {
0759                 bus_info_ptr2->slot_min = min(bus_info_ptr2->slot_min, slot_ptr->slot_num);
0760                 bus_info_ptr2->slot_max = max(bus_info_ptr2->slot_max, slot_ptr->slot_num);
0761                 bus_info_ptr2->slot_count += 1;
0762 
0763             }
0764 
0765             // end of creating the bus_info linked list
0766 
0767             slot_ptr++;
0768             addr_slot += 1;
0769         }
0770 
0771         /* init bus structure */
0772         bus_ptr = hpc_ptr->buses;
0773         for (bus = 0; bus < bus_num; bus++) {
0774             bus_ptr->bus_num = readb(io_mem + addr_bus + bus);
0775             bus_ptr->slots_at_33_conv = readb(io_mem + addr_bus + bus_num + 8 * bus);
0776             bus_ptr->slots_at_66_conv = readb(io_mem + addr_bus + bus_num + 8 * bus + 1);
0777 
0778             bus_ptr->slots_at_66_pcix = readb(io_mem + addr_bus + bus_num + 8 * bus + 2);
0779 
0780             bus_ptr->slots_at_100_pcix = readb(io_mem + addr_bus + bus_num + 8 * bus + 3);
0781 
0782             bus_ptr->slots_at_133_pcix = readb(io_mem + addr_bus + bus_num + 8 * bus + 4);
0783 
0784             bus_info_ptr2 = ibmphp_find_same_bus_num(bus_ptr->bus_num);
0785             if (bus_info_ptr2) {
0786                 bus_info_ptr2->slots_at_33_conv = bus_ptr->slots_at_33_conv;
0787                 bus_info_ptr2->slots_at_66_conv = bus_ptr->slots_at_66_conv;
0788                 bus_info_ptr2->slots_at_66_pcix = bus_ptr->slots_at_66_pcix;
0789                 bus_info_ptr2->slots_at_100_pcix = bus_ptr->slots_at_100_pcix;
0790                 bus_info_ptr2->slots_at_133_pcix = bus_ptr->slots_at_133_pcix;
0791             }
0792             bus_ptr++;
0793         }
0794 
0795         hpc_ptr->ctlr_type = temp;
0796 
0797         switch (hpc_ptr->ctlr_type) {
0798             case 1:
0799                 hpc_ptr->u.pci_ctlr.bus = readb(io_mem + addr);
0800                 hpc_ptr->u.pci_ctlr.dev_fun = readb(io_mem + addr + 1);
0801                 hpc_ptr->irq = readb(io_mem + addr + 2);
0802                 addr += 3;
0803                 debug("ctrl bus = %x, ctlr devfun = %x, irq = %x\n",
0804                     hpc_ptr->u.pci_ctlr.bus,
0805                     hpc_ptr->u.pci_ctlr.dev_fun, hpc_ptr->irq);
0806                 break;
0807 
0808             case 0:
0809                 hpc_ptr->u.isa_ctlr.io_start = readw(io_mem + addr);
0810                 hpc_ptr->u.isa_ctlr.io_end = readw(io_mem + addr + 2);
0811                 if (!request_region(hpc_ptr->u.isa_ctlr.io_start,
0812                              (hpc_ptr->u.isa_ctlr.io_end - hpc_ptr->u.isa_ctlr.io_start + 1),
0813                              "ibmphp")) {
0814                     rc = -ENODEV;
0815                     goto error_no_slot;
0816                 }
0817                 hpc_ptr->irq = readb(io_mem + addr + 4);
0818                 addr += 5;
0819                 break;
0820 
0821             case 2:
0822             case 4:
0823                 hpc_ptr->u.wpeg_ctlr.wpegbbar = readl(io_mem + addr);
0824                 hpc_ptr->u.wpeg_ctlr.i2c_addr = readb(io_mem + addr + 4);
0825                 hpc_ptr->irq = readb(io_mem + addr + 5);
0826                 addr += 6;
0827                 break;
0828             default:
0829                 rc = -ENODEV;
0830                 goto error_no_slot;
0831         }
0832 
0833         //reorganize chassis' linked list
0834         combine_wpg_for_chassis();
0835         combine_wpg_for_expansion();
0836         hpc_ptr->revision = 0xff;
0837         hpc_ptr->options = 0xff;
0838         hpc_ptr->starting_slot_num = hpc_ptr->slots[0].slot_num;
0839         hpc_ptr->ending_slot_num = hpc_ptr->slots[slot_num-1].slot_num;
0840 
0841         // register slots with hpc core as well as create linked list of ibm slot
0842         for (index = 0; index < hpc_ptr->slot_count; index++) {
0843             tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL);
0844             if (!tmp_slot) {
0845                 rc = -ENOMEM;
0846                 goto error_no_slot;
0847             }
0848 
0849             tmp_slot->flag = 1;
0850 
0851             tmp_slot->capabilities = hpc_ptr->slots[index].slot_cap;
0852             if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_133_MAX) == EBDA_SLOT_133_MAX)
0853                 tmp_slot->supported_speed =  3;
0854             else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_100_MAX) == EBDA_SLOT_100_MAX)
0855                 tmp_slot->supported_speed =  2;
0856             else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_66_MAX) == EBDA_SLOT_66_MAX)
0857                 tmp_slot->supported_speed =  1;
0858 
0859             if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_PCIX_CAP) == EBDA_SLOT_PCIX_CAP)
0860                 tmp_slot->supported_bus_mode = 1;
0861             else
0862                 tmp_slot->supported_bus_mode = 0;
0863 
0864 
0865             tmp_slot->bus = hpc_ptr->slots[index].slot_bus_num;
0866 
0867             bus_info_ptr1 = ibmphp_find_same_bus_num(hpc_ptr->slots[index].slot_bus_num);
0868             if (!bus_info_ptr1) {
0869                 rc = -ENODEV;
0870                 goto error;
0871             }
0872             tmp_slot->bus_on = bus_info_ptr1;
0873             bus_info_ptr1 = NULL;
0874             tmp_slot->ctrl = hpc_ptr;
0875 
0876             tmp_slot->ctlr_index = hpc_ptr->slots[index].ctl_index;
0877             tmp_slot->number = hpc_ptr->slots[index].slot_num;
0878 
0879             rc = fillslotinfo(&tmp_slot->hotplug_slot);
0880             if (rc)
0881                 goto error;
0882 
0883             rc = ibmphp_init_devno(&tmp_slot);
0884             if (rc)
0885                 goto error;
0886             tmp_slot->hotplug_slot.ops = &ibmphp_hotplug_slot_ops;
0887 
0888             // end of registering ibm slot with hotplug core
0889 
0890             list_add(&tmp_slot->ibm_slot_list, &ibmphp_slot_head);
0891         }
0892 
0893         print_bus_info();
0894         list_add(&hpc_ptr->ebda_hpc_list, &ebda_hpc_head);
0895 
0896     }           /* each hpc  */
0897 
0898     list_for_each_entry(tmp_slot, &ibmphp_slot_head, ibm_slot_list) {
0899         snprintf(name, SLOT_NAME_SIZE, "%s", create_file_name(tmp_slot));
0900         pci_hp_register(&tmp_slot->hotplug_slot,
0901             pci_find_bus(0, tmp_slot->bus), tmp_slot->device, name);
0902     }
0903 
0904     print_ebda_hpc();
0905     print_ibm_slot();
0906     return 0;
0907 
0908 error:
0909     kfree(tmp_slot);
0910 error_no_slot:
0911     free_ebda_hpc(hpc_ptr);
0912     return rc;
0913 }
0914 
0915 /*
0916  * map info (bus, devfun, start addr, end addr..) of i/o, memory,
0917  * pfm from the physical addr to a list of resource.
0918  */
0919 static int __init ebda_rsrc_rsrc(void)
0920 {
0921     u16 addr;
0922     short rsrc;
0923     u8 type, rsrc_type;
0924     struct ebda_pci_rsrc *rsrc_ptr;
0925 
0926     addr = rsrc_list_ptr->phys_addr;
0927     debug("now entering rsrc land\n");
0928     debug("offset of rsrc: %x\n", rsrc_list_ptr->phys_addr);
0929 
0930     for (rsrc = 0; rsrc < rsrc_list_ptr->num_entries; rsrc++) {
0931         type = readb(io_mem + addr);
0932 
0933         addr += 1;
0934         rsrc_type = type & EBDA_RSRC_TYPE_MASK;
0935 
0936         if (rsrc_type == EBDA_IO_RSRC_TYPE) {
0937             rsrc_ptr = alloc_ebda_pci_rsrc();
0938             if (!rsrc_ptr) {
0939                 iounmap(io_mem);
0940                 return -ENOMEM;
0941             }
0942             rsrc_ptr->rsrc_type = type;
0943 
0944             rsrc_ptr->bus_num = readb(io_mem + addr);
0945             rsrc_ptr->dev_fun = readb(io_mem + addr + 1);
0946             rsrc_ptr->start_addr = readw(io_mem + addr + 2);
0947             rsrc_ptr->end_addr = readw(io_mem + addr + 4);
0948             addr += 6;
0949 
0950             debug("rsrc from io type ----\n");
0951             debug("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
0952                 rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr);
0953 
0954             list_add(&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head);
0955         }
0956 
0957         if (rsrc_type == EBDA_MEM_RSRC_TYPE || rsrc_type == EBDA_PFM_RSRC_TYPE) {
0958             rsrc_ptr = alloc_ebda_pci_rsrc();
0959             if (!rsrc_ptr) {
0960                 iounmap(io_mem);
0961                 return -ENOMEM;
0962             }
0963             rsrc_ptr->rsrc_type = type;
0964 
0965             rsrc_ptr->bus_num = readb(io_mem + addr);
0966             rsrc_ptr->dev_fun = readb(io_mem + addr + 1);
0967             rsrc_ptr->start_addr = readl(io_mem + addr + 2);
0968             rsrc_ptr->end_addr = readl(io_mem + addr + 6);
0969             addr += 10;
0970 
0971             debug("rsrc from mem or pfm ---\n");
0972             debug("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
0973                 rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr);
0974 
0975             list_add(&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head);
0976         }
0977     }
0978     kfree(rsrc_list_ptr);
0979     rsrc_list_ptr = NULL;
0980     print_ebda_pci_rsrc();
0981     return 0;
0982 }
0983 
0984 u16 ibmphp_get_total_controllers(void)
0985 {
0986     return hpc_list_ptr->num_ctlrs;
0987 }
0988 
0989 struct slot *ibmphp_get_slot_from_physical_num(u8 physical_num)
0990 {
0991     struct slot *slot;
0992 
0993     list_for_each_entry(slot, &ibmphp_slot_head, ibm_slot_list) {
0994         if (slot->number == physical_num)
0995             return slot;
0996     }
0997     return NULL;
0998 }
0999 
1000 /* To find:
1001  *  - the smallest slot number
1002  *  - the largest slot number
1003  *  - the total number of the slots based on each bus
1004  *    (if only one slot per bus slot_min = slot_max )
1005  */
1006 struct bus_info *ibmphp_find_same_bus_num(u32 num)
1007 {
1008     struct bus_info *ptr;
1009 
1010     list_for_each_entry(ptr, &bus_info_head, bus_info_list) {
1011         if (ptr->busno == num)
1012              return ptr;
1013     }
1014     return NULL;
1015 }
1016 
1017 /*  Finding relative bus number, in order to map corresponding
1018  *  bus register
1019  */
1020 int ibmphp_get_bus_index(u8 num)
1021 {
1022     struct bus_info *ptr;
1023 
1024     list_for_each_entry(ptr, &bus_info_head, bus_info_list) {
1025         if (ptr->busno == num)
1026             return ptr->index;
1027     }
1028     return -ENODEV;
1029 }
1030 
1031 void ibmphp_free_bus_info_queue(void)
1032 {
1033     struct bus_info *bus_info, *next;
1034 
1035     list_for_each_entry_safe(bus_info, next, &bus_info_head,
1036                  bus_info_list) {
1037         kfree (bus_info);
1038     }
1039 }
1040 
1041 void ibmphp_free_ebda_hpc_queue(void)
1042 {
1043     struct controller *controller = NULL, *next;
1044     int pci_flag = 0;
1045 
1046     list_for_each_entry_safe(controller, next, &ebda_hpc_head,
1047                  ebda_hpc_list) {
1048         if (controller->ctlr_type == 0)
1049             release_region(controller->u.isa_ctlr.io_start, (controller->u.isa_ctlr.io_end - controller->u.isa_ctlr.io_start + 1));
1050         else if ((controller->ctlr_type == 1) && (!pci_flag)) {
1051             ++pci_flag;
1052             pci_unregister_driver(&ibmphp_driver);
1053         }
1054         free_ebda_hpc(controller);
1055     }
1056 }
1057 
1058 void ibmphp_free_ebda_pci_rsrc_queue(void)
1059 {
1060     struct ebda_pci_rsrc *resource, *next;
1061 
1062     list_for_each_entry_safe(resource, next, &ibmphp_ebda_pci_rsrc_head,
1063                  ebda_pci_rsrc_list) {
1064         kfree (resource);
1065         resource = NULL;
1066     }
1067 }
1068 
1069 static const struct pci_device_id id_table[] = {
1070     {
1071         .vendor     = PCI_VENDOR_ID_IBM,
1072         .device     = HPC_DEVICE_ID,
1073         .subvendor  = PCI_VENDOR_ID_IBM,
1074         .subdevice  = HPC_SUBSYSTEM_ID,
1075         .class      = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00),
1076     }, {}
1077 };
1078 
1079 MODULE_DEVICE_TABLE(pci, id_table);
1080 
1081 static int ibmphp_probe(struct pci_dev *, const struct pci_device_id *);
1082 static struct pci_driver ibmphp_driver = {
1083     .name       = "ibmphp",
1084     .id_table   = id_table,
1085     .probe      = ibmphp_probe,
1086 };
1087 
1088 int ibmphp_register_pci(void)
1089 {
1090     struct controller *ctrl;
1091     int rc = 0;
1092 
1093     list_for_each_entry(ctrl, &ebda_hpc_head, ebda_hpc_list) {
1094         if (ctrl->ctlr_type == 1) {
1095             rc = pci_register_driver(&ibmphp_driver);
1096             break;
1097         }
1098     }
1099     return rc;
1100 }
1101 static int ibmphp_probe(struct pci_dev *dev, const struct pci_device_id *ids)
1102 {
1103     struct controller *ctrl;
1104 
1105     debug("inside ibmphp_probe\n");
1106 
1107     list_for_each_entry(ctrl, &ebda_hpc_head, ebda_hpc_list) {
1108         if (ctrl->ctlr_type == 1) {
1109             if ((dev->devfn == ctrl->u.pci_ctlr.dev_fun) && (dev->bus->number == ctrl->u.pci_ctlr.bus)) {
1110                 ctrl->ctrl_dev = dev;
1111                 debug("found device!!!\n");
1112                 debug("dev->device = %x, dev->subsystem_device = %x\n", dev->device, dev->subsystem_device);
1113                 return 0;
1114             }
1115         }
1116     }
1117     return -ENODEV;
1118 }