1 /* 2 * IBM Hot Plug Controller Driver 3 * 4 * Written By: Tong Yu, IBM Corporation 5 * 6 * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com) 7 * Copyright (C) 2001-2003 IBM Corp. 8 * 9 * All rights reserved. 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or (at 14 * your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, but 17 * WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or 19 * NON INFRINGEMENT. See the GNU General Public License for more 20 * details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 * 26 * Send feedback to <gregkh@us.ibm.com> 27 * 28 */ 29 30 #include <linux/module.h> 31 #include <linux/errno.h> 32 #include <linux/mm.h> 33 #include <linux/slab.h> 34 #include <linux/pci.h> 35 #include <linux/list.h> 36 #include <linux/init.h> 37 #include "ibmphp.h" 38 39 /* 40 * POST builds data blocks(in this data block definition, a char-1 41 * byte, short(or word)-2 byte, long(dword)-4 byte) in the Extended 42 * BIOS Data Area which describe the configuration of the hot-plug 43 * controllers and resources used by the PCI Hot-Plug devices. 44 * 45 * This file walks EBDA, maps data block from physical addr, 46 * reconstruct linked lists about all system resource(MEM, PFM, IO) 47 * already assigned by POST, as well as linked lists about hot plug 48 * controllers (ctlr#, slot#, bus&slot features...) 49 */ 50 51 /* Global lists */ 52 LIST_HEAD (ibmphp_ebda_pci_rsrc_head); 53 LIST_HEAD (ibmphp_slot_head); 54 55 /* Local variables */ 56 static struct ebda_hpc_list *hpc_list_ptr; 57 static struct ebda_rsrc_list *rsrc_list_ptr; 58 static struct rio_table_hdr *rio_table_ptr = NULL; 59 static LIST_HEAD (ebda_hpc_head); 60 static LIST_HEAD (bus_info_head); 61 static LIST_HEAD (rio_vg_head); 62 static LIST_HEAD (rio_lo_head); 63 static LIST_HEAD (opt_vg_head); 64 static LIST_HEAD (opt_lo_head); 65 static void __iomem *io_mem; 66 67 /* Local functions */ 68 static int ebda_rsrc_controller (void); 69 static int ebda_rsrc_rsrc (void); 70 static int ebda_rio_table (void); 71 72 static struct ebda_hpc_list * __init alloc_ebda_hpc_list (void) 73 { 74 return kzalloc(sizeof(struct ebda_hpc_list), GFP_KERNEL); 75 } 76 77 static struct controller *alloc_ebda_hpc (u32 slot_count, u32 bus_count) 78 { 79 struct controller *controller; 80 struct ebda_hpc_slot *slots; 81 struct ebda_hpc_bus *buses; 82 83 controller = kzalloc(sizeof(struct controller), GFP_KERNEL); 84 if (!controller) 85 goto error; 86 87 slots = kcalloc(slot_count, sizeof(struct ebda_hpc_slot), GFP_KERNEL); 88 if (!slots) 89 goto error_contr; 90 controller->slots = slots; 91 92 buses = kcalloc(bus_count, sizeof(struct ebda_hpc_bus), GFP_KERNEL); 93 if (!buses) 94 goto error_slots; 95 controller->buses = buses; 96 97 return controller; 98 error_slots: 99 kfree(controller->slots); 100 error_contr: 101 kfree(controller); 102 error: 103 return NULL; 104 } 105 106 static void free_ebda_hpc (struct controller *controller) 107 { 108 kfree (controller->slots); 109 kfree (controller->buses); 110 kfree (controller); 111 } 112 113 static struct ebda_rsrc_list * __init alloc_ebda_rsrc_list (void) 114 { 115 return kzalloc(sizeof(struct ebda_rsrc_list), GFP_KERNEL); 116 } 117 118 static struct ebda_pci_rsrc *alloc_ebda_pci_rsrc (void) 119 { 120 return kzalloc(sizeof(struct ebda_pci_rsrc), GFP_KERNEL); 121 } 122 123 static void __init print_bus_info (void) 124 { 125 struct bus_info *ptr; 126 127 list_for_each_entry(ptr, &bus_info_head, bus_info_list) { 128 debug ("%s - slot_min = %x\n", __func__, ptr->slot_min); 129 debug ("%s - slot_max = %x\n", __func__, ptr->slot_max); 130 debug ("%s - slot_count = %x\n", __func__, ptr->slot_count); 131 debug ("%s - bus# = %x\n", __func__, ptr->busno); 132 debug ("%s - current_speed = %x\n", __func__, ptr->current_speed); 133 debug ("%s - controller_id = %x\n", __func__, ptr->controller_id); 134 135 debug ("%s - slots_at_33_conv = %x\n", __func__, ptr->slots_at_33_conv); 136 debug ("%s - slots_at_66_conv = %x\n", __func__, ptr->slots_at_66_conv); 137 debug ("%s - slots_at_66_pcix = %x\n", __func__, ptr->slots_at_66_pcix); 138 debug ("%s - slots_at_100_pcix = %x\n", __func__, ptr->slots_at_100_pcix); 139 debug ("%s - slots_at_133_pcix = %x\n", __func__, ptr->slots_at_133_pcix); 140 141 } 142 } 143 144 static void print_lo_info (void) 145 { 146 struct rio_detail *ptr; 147 debug ("print_lo_info ----\n"); 148 list_for_each_entry(ptr, &rio_lo_head, rio_detail_list) { 149 debug ("%s - rio_node_id = %x\n", __func__, ptr->rio_node_id); 150 debug ("%s - rio_type = %x\n", __func__, ptr->rio_type); 151 debug ("%s - owner_id = %x\n", __func__, ptr->owner_id); 152 debug ("%s - first_slot_num = %x\n", __func__, ptr->first_slot_num); 153 debug ("%s - wpindex = %x\n", __func__, ptr->wpindex); 154 debug ("%s - chassis_num = %x\n", __func__, ptr->chassis_num); 155 156 } 157 } 158 159 static void print_vg_info (void) 160 { 161 struct rio_detail *ptr; 162 debug ("%s ---\n", __func__); 163 list_for_each_entry(ptr, &rio_vg_head, rio_detail_list) { 164 debug ("%s - rio_node_id = %x\n", __func__, ptr->rio_node_id); 165 debug ("%s - rio_type = %x\n", __func__, ptr->rio_type); 166 debug ("%s - owner_id = %x\n", __func__, ptr->owner_id); 167 debug ("%s - first_slot_num = %x\n", __func__, ptr->first_slot_num); 168 debug ("%s - wpindex = %x\n", __func__, ptr->wpindex); 169 debug ("%s - chassis_num = %x\n", __func__, ptr->chassis_num); 170 171 } 172 } 173 174 static void __init print_ebda_pci_rsrc (void) 175 { 176 struct ebda_pci_rsrc *ptr; 177 178 list_for_each_entry(ptr, &ibmphp_ebda_pci_rsrc_head, ebda_pci_rsrc_list) { 179 debug ("%s - rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n", 180 __func__, ptr->rsrc_type ,ptr->bus_num, ptr->dev_fun,ptr->start_addr, ptr->end_addr); 181 } 182 } 183 184 static void __init print_ibm_slot (void) 185 { 186 struct slot *ptr; 187 188 list_for_each_entry(ptr, &ibmphp_slot_head, ibm_slot_list) { 189 debug ("%s - slot_number: %x\n", __func__, ptr->number); 190 } 191 } 192 193 static void __init print_opt_vg (void) 194 { 195 struct opt_rio *ptr; 196 debug ("%s ---\n", __func__); 197 list_for_each_entry(ptr, &opt_vg_head, opt_rio_list) { 198 debug ("%s - rio_type %x\n", __func__, ptr->rio_type); 199 debug ("%s - chassis_num: %x\n", __func__, ptr->chassis_num); 200 debug ("%s - first_slot_num: %x\n", __func__, ptr->first_slot_num); 201 debug ("%s - middle_num: %x\n", __func__, ptr->middle_num); 202 } 203 } 204 205 static void __init print_ebda_hpc (void) 206 { 207 struct controller *hpc_ptr; 208 u16 index; 209 210 list_for_each_entry(hpc_ptr, &ebda_hpc_head, ebda_hpc_list) { 211 for (index = 0; index < hpc_ptr->slot_count; index++) { 212 debug ("%s - physical slot#: %x\n", __func__, hpc_ptr->slots[index].slot_num); 213 debug ("%s - pci bus# of the slot: %x\n", __func__, hpc_ptr->slots[index].slot_bus_num); 214 debug ("%s - index into ctlr addr: %x\n", __func__, hpc_ptr->slots[index].ctl_index); 215 debug ("%s - cap of the slot: %x\n", __func__, hpc_ptr->slots[index].slot_cap); 216 } 217 218 for (index = 0; index < hpc_ptr->bus_count; index++) { 219 debug ("%s - bus# of each bus controlled by this ctlr: %x\n", __func__, hpc_ptr->buses[index].bus_num); 220 } 221 222 debug ("%s - type of hpc: %x\n", __func__, hpc_ptr->ctlr_type); 223 switch (hpc_ptr->ctlr_type) { 224 case 1: 225 debug ("%s - bus: %x\n", __func__, hpc_ptr->u.pci_ctlr.bus); 226 debug ("%s - dev_fun: %x\n", __func__, hpc_ptr->u.pci_ctlr.dev_fun); 227 debug ("%s - irq: %x\n", __func__, hpc_ptr->irq); 228 break; 229 230 case 0: 231 debug ("%s - io_start: %x\n", __func__, hpc_ptr->u.isa_ctlr.io_start); 232 debug ("%s - io_end: %x\n", __func__, hpc_ptr->u.isa_ctlr.io_end); 233 debug ("%s - irq: %x\n", __func__, hpc_ptr->irq); 234 break; 235 236 case 2: 237 case 4: 238 debug ("%s - wpegbbar: %lx\n", __func__, hpc_ptr->u.wpeg_ctlr.wpegbbar); 239 debug ("%s - i2c_addr: %x\n", __func__, hpc_ptr->u.wpeg_ctlr.i2c_addr); 240 debug ("%s - irq: %x\n", __func__, hpc_ptr->irq); 241 break; 242 } 243 } 244 } 245 246 int __init ibmphp_access_ebda (void) 247 { 248 u8 format, num_ctlrs, rio_complete, hs_complete, ebda_sz; 249 u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, re, rc_id, re_id, base; 250 int rc = 0; 251 252 253 rio_complete = 0; 254 hs_complete = 0; 255 256 io_mem = ioremap ((0x40 << 4) + 0x0e, 2); 257 if (!io_mem ) 258 return -ENOMEM; 259 ebda_seg = readw (io_mem); 260 iounmap (io_mem); 261 debug ("returned ebda segment: %x\n", ebda_seg); 262 263 io_mem = ioremap(ebda_seg<<4, 1); 264 if (!io_mem) 265 return -ENOMEM; 266 ebda_sz = readb(io_mem); 267 iounmap(io_mem); 268 debug("ebda size: %d(KiB)\n", ebda_sz); 269 if (ebda_sz == 0) 270 return -ENOMEM; 271 272 io_mem = ioremap(ebda_seg<<4, (ebda_sz * 1024)); 273 if (!io_mem ) 274 return -ENOMEM; 275 next_offset = 0x180; 276 277 for (;;) { 278 offset = next_offset; 279 next_offset = readw (io_mem + offset); /* offset of next blk */ 280 281 offset += 2; 282 if (next_offset == 0) /* 0 indicate it's last blk */ 283 break; 284 blk_id = readw (io_mem + offset); /* this blk id */ 285 286 offset += 2; 287 /* check if it is hot swap block or rio block */ 288 if (blk_id != 0x4853 && blk_id != 0x4752) 289 continue; 290 /* found hs table */ 291 if (blk_id == 0x4853) { 292 debug ("now enter hot swap block---\n"); 293 debug ("hot blk id: %x\n", blk_id); 294 format = readb (io_mem + offset); 295 296 offset += 1; 297 if (format != 4) 298 goto error_nodev; 299 debug ("hot blk format: %x\n", format); 300 /* hot swap sub blk */ 301 base = offset; 302 303 sub_addr = base; 304 re = readw (io_mem + sub_addr); /* next sub blk */ 305 306 sub_addr += 2; 307 rc_id = readw (io_mem + sub_addr); /* sub blk id */ 308 309 sub_addr += 2; 310 if (rc_id != 0x5243) 311 goto error_nodev; 312 /* rc sub blk signature */ 313 num_ctlrs = readb (io_mem + sub_addr); 314 315 sub_addr += 1; 316 hpc_list_ptr = alloc_ebda_hpc_list (); 317 if (!hpc_list_ptr) { 318 rc = -ENOMEM; 319 goto out; 320 } 321 hpc_list_ptr->format = format; 322 hpc_list_ptr->num_ctlrs = num_ctlrs; 323 hpc_list_ptr->phys_addr = sub_addr; /* offset of RSRC_CONTROLLER blk */ 324 debug ("info about hpc descriptor---\n"); 325 debug ("hot blk format: %x\n", format); 326 debug ("num of controller: %x\n", num_ctlrs); 327 debug ("offset of hpc data structure enteries: %x\n ", sub_addr); 328 329 sub_addr = base + re; /* re sub blk */ 330 /* FIXME: rc is never used/checked */ 331 rc = readw (io_mem + sub_addr); /* next sub blk */ 332 333 sub_addr += 2; 334 re_id = readw (io_mem + sub_addr); /* sub blk id */ 335 336 sub_addr += 2; 337 if (re_id != 0x5245) 338 goto error_nodev; 339 340 /* signature of re */ 341 num_entries = readw (io_mem + sub_addr); 342 343 sub_addr += 2; /* offset of RSRC_ENTRIES blk */ 344 rsrc_list_ptr = alloc_ebda_rsrc_list (); 345 if (!rsrc_list_ptr ) { 346 rc = -ENOMEM; 347 goto out; 348 } 349 rsrc_list_ptr->format = format; 350 rsrc_list_ptr->num_entries = num_entries; 351 rsrc_list_ptr->phys_addr = sub_addr; 352 353 debug ("info about rsrc descriptor---\n"); 354 debug ("format: %x\n", format); 355 debug ("num of rsrc: %x\n", num_entries); 356 debug ("offset of rsrc data structure enteries: %x\n ", sub_addr); 357 358 hs_complete = 1; 359 } else { 360 /* found rio table, blk_id == 0x4752 */ 361 debug ("now enter io table ---\n"); 362 debug ("rio blk id: %x\n", blk_id); 363 364 rio_table_ptr = kzalloc(sizeof(struct rio_table_hdr), GFP_KERNEL); 365 if (!rio_table_ptr) 366 return -ENOMEM; 367 rio_table_ptr->ver_num = readb (io_mem + offset); 368 rio_table_ptr->scal_count = readb (io_mem + offset + 1); 369 rio_table_ptr->riodev_count = readb (io_mem + offset + 2); 370 rio_table_ptr->offset = offset +3 ; 371 372 debug("info about rio table hdr ---\n"); 373 debug("ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ", 374 rio_table_ptr->ver_num, rio_table_ptr->scal_count, 375 rio_table_ptr->riodev_count, rio_table_ptr->offset); 376 377 rio_complete = 1; 378 } 379 } 380 381 if (!hs_complete && !rio_complete) 382 goto error_nodev; 383 384 if (rio_table_ptr) { 385 if (rio_complete && rio_table_ptr->ver_num == 3) { 386 rc = ebda_rio_table (); 387 if (rc) 388 goto out; 389 } 390 } 391 rc = ebda_rsrc_controller (); 392 if (rc) 393 goto out; 394 395 rc = ebda_rsrc_rsrc (); 396 goto out; 397 error_nodev: 398 rc = -ENODEV; 399 out: 400 iounmap (io_mem); 401 return rc; 402 } 403 404 /* 405 * map info of scalability details and rio details from physical address 406 */ 407 static int __init ebda_rio_table (void) 408 { 409 u16 offset; 410 u8 i; 411 struct rio_detail *rio_detail_ptr; 412 413 offset = rio_table_ptr->offset; 414 offset += 12 * rio_table_ptr->scal_count; 415 416 // we do concern about rio details 417 for (i = 0; i < rio_table_ptr->riodev_count; i++) { 418 rio_detail_ptr = kzalloc(sizeof(struct rio_detail), GFP_KERNEL); 419 if (!rio_detail_ptr) 420 return -ENOMEM; 421 rio_detail_ptr->rio_node_id = readb (io_mem + offset); 422 rio_detail_ptr->bbar = readl (io_mem + offset + 1); 423 rio_detail_ptr->rio_type = readb (io_mem + offset + 5); 424 rio_detail_ptr->owner_id = readb (io_mem + offset + 6); 425 rio_detail_ptr->port0_node_connect = readb (io_mem + offset + 7); 426 rio_detail_ptr->port0_port_connect = readb (io_mem + offset + 8); 427 rio_detail_ptr->port1_node_connect = readb (io_mem + offset + 9); 428 rio_detail_ptr->port1_port_connect = readb (io_mem + offset + 10); 429 rio_detail_ptr->first_slot_num = readb (io_mem + offset + 11); 430 rio_detail_ptr->status = readb (io_mem + offset + 12); 431 rio_detail_ptr->wpindex = readb (io_mem + offset + 13); 432 rio_detail_ptr->chassis_num = readb (io_mem + offset + 14); 433 // 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); 434 //create linked list of chassis 435 if (rio_detail_ptr->rio_type == 4 || rio_detail_ptr->rio_type == 5) 436 list_add (&rio_detail_ptr->rio_detail_list, &rio_vg_head); 437 //create linked list of expansion box 438 else if (rio_detail_ptr->rio_type == 6 || rio_detail_ptr->rio_type == 7) 439 list_add (&rio_detail_ptr->rio_detail_list, &rio_lo_head); 440 else 441 // not in my concern 442 kfree (rio_detail_ptr); 443 offset += 15; 444 } 445 print_lo_info (); 446 print_vg_info (); 447 return 0; 448 } 449 450 /* 451 * reorganizing linked list of chassis 452 */ 453 static struct opt_rio *search_opt_vg (u8 chassis_num) 454 { 455 struct opt_rio *ptr; 456 list_for_each_entry(ptr, &opt_vg_head, opt_rio_list) { 457 if (ptr->chassis_num == chassis_num) 458 return ptr; 459 } 460 return NULL; 461 } 462 463 static int __init combine_wpg_for_chassis (void) 464 { 465 struct opt_rio *opt_rio_ptr = NULL; 466 struct rio_detail *rio_detail_ptr = NULL; 467 468 list_for_each_entry(rio_detail_ptr, &rio_vg_head, rio_detail_list) { 469 opt_rio_ptr = search_opt_vg (rio_detail_ptr->chassis_num); 470 if (!opt_rio_ptr) { 471 opt_rio_ptr = kzalloc(sizeof(struct opt_rio), GFP_KERNEL); 472 if (!opt_rio_ptr) 473 return -ENOMEM; 474 opt_rio_ptr->rio_type = rio_detail_ptr->rio_type; 475 opt_rio_ptr->chassis_num = rio_detail_ptr->chassis_num; 476 opt_rio_ptr->first_slot_num = rio_detail_ptr->first_slot_num; 477 opt_rio_ptr->middle_num = rio_detail_ptr->first_slot_num; 478 list_add (&opt_rio_ptr->opt_rio_list, &opt_vg_head); 479 } else { 480 opt_rio_ptr->first_slot_num = min (opt_rio_ptr->first_slot_num, rio_detail_ptr->first_slot_num); 481 opt_rio_ptr->middle_num = max (opt_rio_ptr->middle_num, rio_detail_ptr->first_slot_num); 482 } 483 } 484 print_opt_vg (); 485 return 0; 486 } 487 488 /* 489 * reorganizing linked list of expansion box 490 */ 491 static struct opt_rio_lo *search_opt_lo (u8 chassis_num) 492 { 493 struct opt_rio_lo *ptr; 494 list_for_each_entry(ptr, &opt_lo_head, opt_rio_lo_list) { 495 if (ptr->chassis_num == chassis_num) 496 return ptr; 497 } 498 return NULL; 499 } 500 501 static int combine_wpg_for_expansion (void) 502 { 503 struct opt_rio_lo *opt_rio_lo_ptr = NULL; 504 struct rio_detail *rio_detail_ptr = NULL; 505 506 list_for_each_entry(rio_detail_ptr, &rio_lo_head, rio_detail_list) { 507 opt_rio_lo_ptr = search_opt_lo (rio_detail_ptr->chassis_num); 508 if (!opt_rio_lo_ptr) { 509 opt_rio_lo_ptr = kzalloc(sizeof(struct opt_rio_lo), GFP_KERNEL); 510 if (!opt_rio_lo_ptr) 511 return -ENOMEM; 512 opt_rio_lo_ptr->rio_type = rio_detail_ptr->rio_type; 513 opt_rio_lo_ptr->chassis_num = rio_detail_ptr->chassis_num; 514 opt_rio_lo_ptr->first_slot_num = rio_detail_ptr->first_slot_num; 515 opt_rio_lo_ptr->middle_num = rio_detail_ptr->first_slot_num; 516 opt_rio_lo_ptr->pack_count = 1; 517 518 list_add (&opt_rio_lo_ptr->opt_rio_lo_list, &opt_lo_head); 519 } else { 520 opt_rio_lo_ptr->first_slot_num = min (opt_rio_lo_ptr->first_slot_num, rio_detail_ptr->first_slot_num); 521 opt_rio_lo_ptr->middle_num = max (opt_rio_lo_ptr->middle_num, rio_detail_ptr->first_slot_num); 522 opt_rio_lo_ptr->pack_count = 2; 523 } 524 } 525 return 0; 526 } 527 528 529 /* Since we don't know the max slot number per each chassis, hence go 530 * through the list of all chassis to find out the range 531 * Arguments: slot_num, 1st slot number of the chassis we think we are on, 532 * var (0 = chassis, 1 = expansion box) 533 */ 534 static int first_slot_num (u8 slot_num, u8 first_slot, u8 var) 535 { 536 struct opt_rio *opt_vg_ptr = NULL; 537 struct opt_rio_lo *opt_lo_ptr = NULL; 538 int rc = 0; 539 540 if (!var) { 541 list_for_each_entry(opt_vg_ptr, &opt_vg_head, opt_rio_list) { 542 if ((first_slot < opt_vg_ptr->first_slot_num) && (slot_num >= opt_vg_ptr->first_slot_num)) { 543 rc = -ENODEV; 544 break; 545 } 546 } 547 } else { 548 list_for_each_entry(opt_lo_ptr, &opt_lo_head, opt_rio_lo_list) { 549 if ((first_slot < opt_lo_ptr->first_slot_num) && (slot_num >= opt_lo_ptr->first_slot_num)) { 550 rc = -ENODEV; 551 break; 552 } 553 } 554 } 555 return rc; 556 } 557 558 static struct opt_rio_lo * find_rxe_num (u8 slot_num) 559 { 560 struct opt_rio_lo *opt_lo_ptr; 561 562 list_for_each_entry(opt_lo_ptr, &opt_lo_head, opt_rio_lo_list) { 563 //check to see if this slot_num belongs to expansion box 564 if ((slot_num >= opt_lo_ptr->first_slot_num) && (!first_slot_num (slot_num, opt_lo_ptr->first_slot_num, 1))) 565 return opt_lo_ptr; 566 } 567 return NULL; 568 } 569 570 static struct opt_rio * find_chassis_num (u8 slot_num) 571 { 572 struct opt_rio *opt_vg_ptr; 573 574 list_for_each_entry(opt_vg_ptr, &opt_vg_head, opt_rio_list) { 575 //check to see if this slot_num belongs to chassis 576 if ((slot_num >= opt_vg_ptr->first_slot_num) && (!first_slot_num (slot_num, opt_vg_ptr->first_slot_num, 0))) 577 return opt_vg_ptr; 578 } 579 return NULL; 580 } 581 582 /* This routine will find out how many slots are in the chassis, so that 583 * the slot numbers for rxe100 would start from 1, and not from 7, or 6 etc 584 */ 585 static u8 calculate_first_slot (u8 slot_num) 586 { 587 u8 first_slot = 1; 588 struct slot * slot_cur; 589 590 list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) { 591 if (slot_cur->ctrl) { 592 if ((slot_cur->ctrl->ctlr_type != 4) && (slot_cur->ctrl->ending_slot_num > first_slot) && (slot_num > slot_cur->ctrl->ending_slot_num)) 593 first_slot = slot_cur->ctrl->ending_slot_num; 594 } 595 } 596 return first_slot + 1; 597 598 } 599 600 #define SLOT_NAME_SIZE 30 601 602 static char *create_file_name (struct slot * slot_cur) 603 { 604 struct opt_rio *opt_vg_ptr = NULL; 605 struct opt_rio_lo *opt_lo_ptr = NULL; 606 static char str[SLOT_NAME_SIZE]; 607 int which = 0; /* rxe = 1, chassis = 0 */ 608 u8 number = 1; /* either chassis or rxe # */ 609 u8 first_slot = 1; 610 u8 slot_num; 611 u8 flag = 0; 612 613 if (!slot_cur) { 614 err ("Structure passed is empty\n"); 615 return NULL; 616 } 617 618 slot_num = slot_cur->number; 619 620 memset (str, 0, sizeof(str)); 621 622 if (rio_table_ptr) { 623 if (rio_table_ptr->ver_num == 3) { 624 opt_vg_ptr = find_chassis_num (slot_num); 625 opt_lo_ptr = find_rxe_num (slot_num); 626 } 627 } 628 if (opt_vg_ptr) { 629 if (opt_lo_ptr) { 630 if ((slot_num - opt_vg_ptr->first_slot_num) > (slot_num - opt_lo_ptr->first_slot_num)) { 631 number = opt_lo_ptr->chassis_num; 632 first_slot = opt_lo_ptr->first_slot_num; 633 which = 1; /* it is RXE */ 634 } else { 635 first_slot = opt_vg_ptr->first_slot_num; 636 number = opt_vg_ptr->chassis_num; 637 which = 0; 638 } 639 } else { 640 first_slot = opt_vg_ptr->first_slot_num; 641 number = opt_vg_ptr->chassis_num; 642 which = 0; 643 } 644 ++flag; 645 } else if (opt_lo_ptr) { 646 number = opt_lo_ptr->chassis_num; 647 first_slot = opt_lo_ptr->first_slot_num; 648 which = 1; 649 ++flag; 650 } else if (rio_table_ptr) { 651 if (rio_table_ptr->ver_num == 3) { 652 /* if both NULL and we DO have correct RIO table in BIOS */ 653 return NULL; 654 } 655 } 656 if (!flag) { 657 if (slot_cur->ctrl->ctlr_type == 4) { 658 first_slot = calculate_first_slot (slot_num); 659 which = 1; 660 } else { 661 which = 0; 662 } 663 } 664 665 sprintf(str, "%s%dslot%d", 666 which == 0 ? "chassis" : "rxe", 667 number, slot_num - first_slot + 1); 668 return str; 669 } 670 671 static int fillslotinfo(struct hotplug_slot *hotplug_slot) 672 { 673 struct slot *slot; 674 int rc = 0; 675 676 if (!hotplug_slot || !hotplug_slot->private) 677 return -EINVAL; 678 679 slot = hotplug_slot->private; 680 rc = ibmphp_hpc_readslot(slot, READ_ALLSTAT, NULL); 681 if (rc) 682 return rc; 683 684 // power - enabled:1 not:0 685 hotplug_slot->info->power_status = SLOT_POWER(slot->status); 686 687 // attention - off:0, on:1, blinking:2 688 hotplug_slot->info->attention_status = SLOT_ATTN(slot->status, slot->ext_status); 689 690 // latch - open:1 closed:0 691 hotplug_slot->info->latch_status = SLOT_LATCH(slot->status); 692 693 // pci board - present:1 not:0 694 if (SLOT_PRESENT (slot->status)) 695 hotplug_slot->info->adapter_status = 1; 696 else 697 hotplug_slot->info->adapter_status = 0; 698 /* 699 if (slot->bus_on->supported_bus_mode 700 && (slot->bus_on->supported_speed == BUS_SPEED_66)) 701 hotplug_slot->info->max_bus_speed_status = BUS_SPEED_66PCIX; 702 else 703 hotplug_slot->info->max_bus_speed_status = slot->bus_on->supported_speed; 704 */ 705 706 return rc; 707 } 708 709 static void release_slot(struct hotplug_slot *hotplug_slot) 710 { 711 struct slot *slot; 712 713 if (!hotplug_slot || !hotplug_slot->private) 714 return; 715 716 slot = hotplug_slot->private; 717 kfree(slot->hotplug_slot->info); 718 kfree(slot->hotplug_slot); 719 slot->ctrl = NULL; 720 slot->bus_on = NULL; 721 722 /* we don't want to actually remove the resources, since free_resources will do just that */ 723 ibmphp_unconfigure_card(&slot, -1); 724 725 kfree (slot); 726 } 727 728 static struct pci_driver ibmphp_driver; 729 730 /* 731 * map info (ctlr-id, slot count, slot#.. bus count, bus#, ctlr type...) of 732 * each hpc from physical address to a list of hot plug controllers based on 733 * hpc descriptors. 734 */ 735 static int __init ebda_rsrc_controller (void) 736 { 737 u16 addr, addr_slot, addr_bus; 738 u8 ctlr_id, temp, bus_index; 739 u16 ctlr, slot, bus; 740 u16 slot_num, bus_num, index; 741 struct hotplug_slot *hp_slot_ptr; 742 struct controller *hpc_ptr; 743 struct ebda_hpc_bus *bus_ptr; 744 struct ebda_hpc_slot *slot_ptr; 745 struct bus_info *bus_info_ptr1, *bus_info_ptr2; 746 int rc; 747 struct slot *tmp_slot; 748 char name[SLOT_NAME_SIZE]; 749 750 addr = hpc_list_ptr->phys_addr; 751 for (ctlr = 0; ctlr < hpc_list_ptr->num_ctlrs; ctlr++) { 752 bus_index = 1; 753 ctlr_id = readb (io_mem + addr); 754 addr += 1; 755 slot_num = readb (io_mem + addr); 756 757 addr += 1; 758 addr_slot = addr; /* offset of slot structure */ 759 addr += (slot_num * 4); 760 761 bus_num = readb (io_mem + addr); 762 763 addr += 1; 764 addr_bus = addr; /* offset of bus */ 765 addr += (bus_num * 9); /* offset of ctlr_type */ 766 temp = readb (io_mem + addr); 767 768 addr += 1; 769 /* init hpc structure */ 770 hpc_ptr = alloc_ebda_hpc (slot_num, bus_num); 771 if (!hpc_ptr ) { 772 rc = -ENOMEM; 773 goto error_no_hpc; 774 } 775 hpc_ptr->ctlr_id = ctlr_id; 776 hpc_ptr->ctlr_relative_id = ctlr; 777 hpc_ptr->slot_count = slot_num; 778 hpc_ptr->bus_count = bus_num; 779 debug ("now enter ctlr data struture ---\n"); 780 debug ("ctlr id: %x\n", ctlr_id); 781 debug ("ctlr_relative_id: %x\n", hpc_ptr->ctlr_relative_id); 782 debug ("count of slots controlled by this ctlr: %x\n", slot_num); 783 debug ("count of buses controlled by this ctlr: %x\n", bus_num); 784 785 /* init slot structure, fetch slot, bus, cap... */ 786 slot_ptr = hpc_ptr->slots; 787 for (slot = 0; slot < slot_num; slot++) { 788 slot_ptr->slot_num = readb (io_mem + addr_slot); 789 slot_ptr->slot_bus_num = readb (io_mem + addr_slot + slot_num); 790 slot_ptr->ctl_index = readb (io_mem + addr_slot + 2*slot_num); 791 slot_ptr->slot_cap = readb (io_mem + addr_slot + 3*slot_num); 792 793 // create bus_info lined list --- if only one slot per bus: slot_min = slot_max 794 795 bus_info_ptr2 = ibmphp_find_same_bus_num (slot_ptr->slot_bus_num); 796 if (!bus_info_ptr2) { 797 bus_info_ptr1 = kzalloc(sizeof(struct bus_info), GFP_KERNEL); 798 if (!bus_info_ptr1) { 799 rc = -ENOMEM; 800 goto error_no_hp_slot; 801 } 802 bus_info_ptr1->slot_min = slot_ptr->slot_num; 803 bus_info_ptr1->slot_max = slot_ptr->slot_num; 804 bus_info_ptr1->slot_count += 1; 805 bus_info_ptr1->busno = slot_ptr->slot_bus_num; 806 bus_info_ptr1->index = bus_index++; 807 bus_info_ptr1->current_speed = 0xff; 808 bus_info_ptr1->current_bus_mode = 0xff; 809 810 bus_info_ptr1->controller_id = hpc_ptr->ctlr_id; 811 812 list_add_tail (&bus_info_ptr1->bus_info_list, &bus_info_head); 813 814 } else { 815 bus_info_ptr2->slot_min = min (bus_info_ptr2->slot_min, slot_ptr->slot_num); 816 bus_info_ptr2->slot_max = max (bus_info_ptr2->slot_max, slot_ptr->slot_num); 817 bus_info_ptr2->slot_count += 1; 818 819 } 820 821 // end of creating the bus_info linked list 822 823 slot_ptr++; 824 addr_slot += 1; 825 } 826 827 /* init bus structure */ 828 bus_ptr = hpc_ptr->buses; 829 for (bus = 0; bus < bus_num; bus++) { 830 bus_ptr->bus_num = readb (io_mem + addr_bus + bus); 831 bus_ptr->slots_at_33_conv = readb (io_mem + addr_bus + bus_num + 8 * bus); 832 bus_ptr->slots_at_66_conv = readb (io_mem + addr_bus + bus_num + 8 * bus + 1); 833 834 bus_ptr->slots_at_66_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 2); 835 836 bus_ptr->slots_at_100_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 3); 837 838 bus_ptr->slots_at_133_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 4); 839 840 bus_info_ptr2 = ibmphp_find_same_bus_num (bus_ptr->bus_num); 841 if (bus_info_ptr2) { 842 bus_info_ptr2->slots_at_33_conv = bus_ptr->slots_at_33_conv; 843 bus_info_ptr2->slots_at_66_conv = bus_ptr->slots_at_66_conv; 844 bus_info_ptr2->slots_at_66_pcix = bus_ptr->slots_at_66_pcix; 845 bus_info_ptr2->slots_at_100_pcix = bus_ptr->slots_at_100_pcix; 846 bus_info_ptr2->slots_at_133_pcix = bus_ptr->slots_at_133_pcix; 847 } 848 bus_ptr++; 849 } 850 851 hpc_ptr->ctlr_type = temp; 852 853 switch (hpc_ptr->ctlr_type) { 854 case 1: 855 hpc_ptr->u.pci_ctlr.bus = readb (io_mem + addr); 856 hpc_ptr->u.pci_ctlr.dev_fun = readb (io_mem + addr + 1); 857 hpc_ptr->irq = readb (io_mem + addr + 2); 858 addr += 3; 859 debug ("ctrl bus = %x, ctlr devfun = %x, irq = %x\n", 860 hpc_ptr->u.pci_ctlr.bus, 861 hpc_ptr->u.pci_ctlr.dev_fun, hpc_ptr->irq); 862 break; 863 864 case 0: 865 hpc_ptr->u.isa_ctlr.io_start = readw (io_mem + addr); 866 hpc_ptr->u.isa_ctlr.io_end = readw (io_mem + addr + 2); 867 if (!request_region (hpc_ptr->u.isa_ctlr.io_start, 868 (hpc_ptr->u.isa_ctlr.io_end - hpc_ptr->u.isa_ctlr.io_start + 1), 869 "ibmphp")) { 870 rc = -ENODEV; 871 goto error_no_hp_slot; 872 } 873 hpc_ptr->irq = readb (io_mem + addr + 4); 874 addr += 5; 875 break; 876 877 case 2: 878 case 4: 879 hpc_ptr->u.wpeg_ctlr.wpegbbar = readl (io_mem + addr); 880 hpc_ptr->u.wpeg_ctlr.i2c_addr = readb (io_mem + addr + 4); 881 hpc_ptr->irq = readb (io_mem + addr + 5); 882 addr += 6; 883 break; 884 default: 885 rc = -ENODEV; 886 goto error_no_hp_slot; 887 } 888 889 //reorganize chassis' linked list 890 combine_wpg_for_chassis (); 891 combine_wpg_for_expansion (); 892 hpc_ptr->revision = 0xff; 893 hpc_ptr->options = 0xff; 894 hpc_ptr->starting_slot_num = hpc_ptr->slots[0].slot_num; 895 hpc_ptr->ending_slot_num = hpc_ptr->slots[slot_num-1].slot_num; 896 897 // register slots with hpc core as well as create linked list of ibm slot 898 for (index = 0; index < hpc_ptr->slot_count; index++) { 899 900 hp_slot_ptr = kzalloc(sizeof(*hp_slot_ptr), GFP_KERNEL); 901 if (!hp_slot_ptr) { 902 rc = -ENOMEM; 903 goto error_no_hp_slot; 904 } 905 906 hp_slot_ptr->info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); 907 if (!hp_slot_ptr->info) { 908 rc = -ENOMEM; 909 goto error_no_hp_info; 910 } 911 912 tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL); 913 if (!tmp_slot) { 914 rc = -ENOMEM; 915 goto error_no_slot; 916 } 917 918 tmp_slot->flag = 1; 919 920 tmp_slot->capabilities = hpc_ptr->slots[index].slot_cap; 921 if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_133_MAX) == EBDA_SLOT_133_MAX) 922 tmp_slot->supported_speed = 3; 923 else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_100_MAX) == EBDA_SLOT_100_MAX) 924 tmp_slot->supported_speed = 2; 925 else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_66_MAX) == EBDA_SLOT_66_MAX) 926 tmp_slot->supported_speed = 1; 927 928 if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_PCIX_CAP) == EBDA_SLOT_PCIX_CAP) 929 tmp_slot->supported_bus_mode = 1; 930 else 931 tmp_slot->supported_bus_mode = 0; 932 933 934 tmp_slot->bus = hpc_ptr->slots[index].slot_bus_num; 935 936 bus_info_ptr1 = ibmphp_find_same_bus_num (hpc_ptr->slots[index].slot_bus_num); 937 if (!bus_info_ptr1) { 938 kfree(tmp_slot); 939 rc = -ENODEV; 940 goto error; 941 } 942 tmp_slot->bus_on = bus_info_ptr1; 943 bus_info_ptr1 = NULL; 944 tmp_slot->ctrl = hpc_ptr; 945 946 tmp_slot->ctlr_index = hpc_ptr->slots[index].ctl_index; 947 tmp_slot->number = hpc_ptr->slots[index].slot_num; 948 tmp_slot->hotplug_slot = hp_slot_ptr; 949 950 hp_slot_ptr->private = tmp_slot; 951 hp_slot_ptr->release = release_slot; 952 953 rc = fillslotinfo(hp_slot_ptr); 954 if (rc) 955 goto error; 956 957 rc = ibmphp_init_devno ((struct slot **) &hp_slot_ptr->private); 958 if (rc) 959 goto error; 960 hp_slot_ptr->ops = &ibmphp_hotplug_slot_ops; 961 962 // end of registering ibm slot with hotplug core 963 964 list_add (& ((struct slot *)(hp_slot_ptr->private))->ibm_slot_list, &ibmphp_slot_head); 965 } 966 967 print_bus_info (); 968 list_add (&hpc_ptr->ebda_hpc_list, &ebda_hpc_head ); 969 970 } /* each hpc */ 971 972 list_for_each_entry(tmp_slot, &ibmphp_slot_head, ibm_slot_list) { 973 snprintf(name, SLOT_NAME_SIZE, "%s", create_file_name(tmp_slot)); 974 pci_hp_register(tmp_slot->hotplug_slot, 975 pci_find_bus(0, tmp_slot->bus), tmp_slot->device, name); 976 } 977 978 print_ebda_hpc (); 979 print_ibm_slot (); 980 return 0; 981 982 error: 983 kfree (hp_slot_ptr->private); 984 error_no_slot: 985 kfree (hp_slot_ptr->info); 986 error_no_hp_info: 987 kfree (hp_slot_ptr); 988 error_no_hp_slot: 989 free_ebda_hpc (hpc_ptr); 990 error_no_hpc: 991 iounmap (io_mem); 992 return rc; 993 } 994 995 /* 996 * map info (bus, devfun, start addr, end addr..) of i/o, memory, 997 * pfm from the physical addr to a list of resource. 998 */ 999 static int __init ebda_rsrc_rsrc (void) 1000 { 1001 u16 addr; 1002 short rsrc; 1003 u8 type, rsrc_type; 1004 struct ebda_pci_rsrc *rsrc_ptr; 1005 1006 addr = rsrc_list_ptr->phys_addr; 1007 debug ("now entering rsrc land\n"); 1008 debug ("offset of rsrc: %x\n", rsrc_list_ptr->phys_addr); 1009 1010 for (rsrc = 0; rsrc < rsrc_list_ptr->num_entries; rsrc++) { 1011 type = readb (io_mem + addr); 1012 1013 addr += 1; 1014 rsrc_type = type & EBDA_RSRC_TYPE_MASK; 1015 1016 if (rsrc_type == EBDA_IO_RSRC_TYPE) { 1017 rsrc_ptr = alloc_ebda_pci_rsrc (); 1018 if (!rsrc_ptr) { 1019 iounmap (io_mem); 1020 return -ENOMEM; 1021 } 1022 rsrc_ptr->rsrc_type = type; 1023 1024 rsrc_ptr->bus_num = readb (io_mem + addr); 1025 rsrc_ptr->dev_fun = readb (io_mem + addr + 1); 1026 rsrc_ptr->start_addr = readw (io_mem + addr + 2); 1027 rsrc_ptr->end_addr = readw (io_mem + addr + 4); 1028 addr += 6; 1029 1030 debug ("rsrc from io type ----\n"); 1031 debug ("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n", 1032 rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr); 1033 1034 list_add (&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head); 1035 } 1036 1037 if (rsrc_type == EBDA_MEM_RSRC_TYPE || rsrc_type == EBDA_PFM_RSRC_TYPE) { 1038 rsrc_ptr = alloc_ebda_pci_rsrc (); 1039 if (!rsrc_ptr ) { 1040 iounmap (io_mem); 1041 return -ENOMEM; 1042 } 1043 rsrc_ptr->rsrc_type = type; 1044 1045 rsrc_ptr->bus_num = readb (io_mem + addr); 1046 rsrc_ptr->dev_fun = readb (io_mem + addr + 1); 1047 rsrc_ptr->start_addr = readl (io_mem + addr + 2); 1048 rsrc_ptr->end_addr = readl (io_mem + addr + 6); 1049 addr += 10; 1050 1051 debug ("rsrc from mem or pfm ---\n"); 1052 debug ("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n", 1053 rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr); 1054 1055 list_add (&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head); 1056 } 1057 } 1058 kfree (rsrc_list_ptr); 1059 rsrc_list_ptr = NULL; 1060 print_ebda_pci_rsrc (); 1061 return 0; 1062 } 1063 1064 u16 ibmphp_get_total_controllers (void) 1065 { 1066 return hpc_list_ptr->num_ctlrs; 1067 } 1068 1069 struct slot *ibmphp_get_slot_from_physical_num (u8 physical_num) 1070 { 1071 struct slot *slot; 1072 1073 list_for_each_entry(slot, &ibmphp_slot_head, ibm_slot_list) { 1074 if (slot->number == physical_num) 1075 return slot; 1076 } 1077 return NULL; 1078 } 1079 1080 /* To find: 1081 * - the smallest slot number 1082 * - the largest slot number 1083 * - the total number of the slots based on each bus 1084 * (if only one slot per bus slot_min = slot_max ) 1085 */ 1086 struct bus_info *ibmphp_find_same_bus_num (u32 num) 1087 { 1088 struct bus_info *ptr; 1089 1090 list_for_each_entry(ptr, &bus_info_head, bus_info_list) { 1091 if (ptr->busno == num) 1092 return ptr; 1093 } 1094 return NULL; 1095 } 1096 1097 /* Finding relative bus number, in order to map corresponding 1098 * bus register 1099 */ 1100 int ibmphp_get_bus_index (u8 num) 1101 { 1102 struct bus_info *ptr; 1103 1104 list_for_each_entry(ptr, &bus_info_head, bus_info_list) { 1105 if (ptr->busno == num) 1106 return ptr->index; 1107 } 1108 return -ENODEV; 1109 } 1110 1111 void ibmphp_free_bus_info_queue (void) 1112 { 1113 struct bus_info *bus_info; 1114 struct list_head *list; 1115 struct list_head *next; 1116 1117 list_for_each_safe (list, next, &bus_info_head ) { 1118 bus_info = list_entry (list, struct bus_info, bus_info_list); 1119 kfree (bus_info); 1120 } 1121 } 1122 1123 void ibmphp_free_ebda_hpc_queue (void) 1124 { 1125 struct controller *controller = NULL; 1126 struct list_head *list; 1127 struct list_head *next; 1128 int pci_flag = 0; 1129 1130 list_for_each_safe (list, next, &ebda_hpc_head) { 1131 controller = list_entry (list, struct controller, ebda_hpc_list); 1132 if (controller->ctlr_type == 0) 1133 release_region (controller->u.isa_ctlr.io_start, (controller->u.isa_ctlr.io_end - controller->u.isa_ctlr.io_start + 1)); 1134 else if ((controller->ctlr_type == 1) && (!pci_flag)) { 1135 ++pci_flag; 1136 pci_unregister_driver (&ibmphp_driver); 1137 } 1138 free_ebda_hpc (controller); 1139 } 1140 } 1141 1142 void ibmphp_free_ebda_pci_rsrc_queue (void) 1143 { 1144 struct ebda_pci_rsrc *resource; 1145 struct list_head *list; 1146 struct list_head *next; 1147 1148 list_for_each_safe (list, next, &ibmphp_ebda_pci_rsrc_head) { 1149 resource = list_entry (list, struct ebda_pci_rsrc, ebda_pci_rsrc_list); 1150 kfree (resource); 1151 resource = NULL; 1152 } 1153 } 1154 1155 static struct pci_device_id id_table[] = { 1156 { 1157 .vendor = PCI_VENDOR_ID_IBM, 1158 .device = HPC_DEVICE_ID, 1159 .subvendor = PCI_VENDOR_ID_IBM, 1160 .subdevice = HPC_SUBSYSTEM_ID, 1161 .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00), 1162 }, {} 1163 }; 1164 1165 MODULE_DEVICE_TABLE(pci, id_table); 1166 1167 static int ibmphp_probe (struct pci_dev *, const struct pci_device_id *); 1168 static struct pci_driver ibmphp_driver = { 1169 .name = "ibmphp", 1170 .id_table = id_table, 1171 .probe = ibmphp_probe, 1172 }; 1173 1174 int ibmphp_register_pci (void) 1175 { 1176 struct controller *ctrl; 1177 int rc = 0; 1178 1179 list_for_each_entry(ctrl, &ebda_hpc_head, ebda_hpc_list) { 1180 if (ctrl->ctlr_type == 1) { 1181 rc = pci_register_driver(&ibmphp_driver); 1182 break; 1183 } 1184 } 1185 return rc; 1186 } 1187 static int ibmphp_probe (struct pci_dev * dev, const struct pci_device_id *ids) 1188 { 1189 struct controller *ctrl; 1190 1191 debug ("inside ibmphp_probe\n"); 1192 1193 list_for_each_entry(ctrl, &ebda_hpc_head, ebda_hpc_list) { 1194 if (ctrl->ctlr_type == 1) { 1195 if ((dev->devfn == ctrl->u.pci_ctlr.dev_fun) && (dev->bus->number == ctrl->u.pci_ctlr.bus)) { 1196 ctrl->ctrl_dev = dev; 1197 debug ("found device!!!\n"); 1198 debug ("dev->device = %x, dev->subsystem_device = %x\n", dev->device, dev->subsystem_device); 1199 return 0; 1200 } 1201 } 1202 } 1203 return -ENODEV; 1204 } 1205 1206