2 * IBM Hot Plug Controller Driver
4 * Written By: Tong Yu, IBM Corporation
6 * Copyright (c) 2001 Greg Kroah-Hartman (greg@kroah.com)
7 * Copyright (c) 2001,2002 IBM Corp.
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.
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
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.
26 * Send feedback to <gregkh@us.ibm.com>
30 #include <linux/module.h>
31 #include <linux/sched.h>
32 #include <linux/errno.h>
34 #include <linux/slab.h>
35 #include <linux/pci.h>
36 #include <linux/list.h>
37 #include <linux/init.h>
41 * POST builds data blocks(in this data block definition, a char-1
42 * byte, short(or word)-2 byte, long(dword)-4 byte) in the Extended
43 * BIOS Data Area which describe the configuration of the hot-plug
44 * controllers and resources used by the PCI Hot-Plug devices.
46 * This file walks EBDA, maps data block from physical addr,
47 * reconstruct linked lists about all system resource(MEM, PFM, IO)
48 * already assigned by POST, as well as linked lists about hot plug
49 * controllers (ctlr#, slot#, bus&slot features...)
53 LIST_HEAD (ibmphp_ebda_pci_rsrc_head);
54 LIST_HEAD (ibmphp_slot_head);
57 static struct ebda_hpc_list *hpc_list_ptr;
58 static struct ebda_rsrc_list *rsrc_list_ptr;
59 static struct rio_table_hdr *rio_table_ptr = NULL;
60 static LIST_HEAD (ebda_hpc_head);
61 static LIST_HEAD (bus_info_head);
62 static LIST_HEAD (rio_vg_head);
63 static LIST_HEAD (rio_lo_head);
64 static LIST_HEAD (opt_vg_head);
65 static LIST_HEAD (opt_lo_head);
68 char *chassis_str, *rxe_str, *str;
71 static int ebda_rsrc_controller (void);
72 static int ebda_rsrc_rsrc (void);
73 static int ebda_rio_table (void);
75 static struct slot *alloc_ibm_slot (void)
79 slot = kmalloc (sizeof (struct slot), GFP_KERNEL);
82 memset (slot, 0, sizeof (*slot));
86 static struct ebda_hpc_list * __init alloc_ebda_hpc_list (void)
88 struct ebda_hpc_list *list;
90 list = kmalloc (sizeof (struct ebda_hpc_list), GFP_KERNEL);
93 memset (list, 0, sizeof (*list));
97 static struct controller *alloc_ebda_hpc (u32 slot_count, u32 bus_count)
99 struct controller *controller;
100 struct ebda_hpc_slot *slots;
101 struct ebda_hpc_bus *buses;
103 controller = kmalloc (sizeof (struct controller), GFP_KERNEL);
106 memset (controller, 0, sizeof (*controller));
108 slots = kmalloc (sizeof (struct ebda_hpc_slot) * slot_count, GFP_KERNEL);
113 memset (slots, 0, sizeof (*slots) * slot_count);
114 controller->slots = slots;
116 buses = kmalloc (sizeof (struct ebda_hpc_bus) * bus_count, GFP_KERNEL);
118 kfree (controller->slots);
122 memset (buses, 0, sizeof (*buses) * bus_count);
123 controller->buses = buses;
128 static void free_ebda_hpc (struct controller *controller)
130 kfree (controller->slots);
131 controller->slots = NULL;
132 kfree (controller->buses);
133 controller->buses = NULL;
134 controller->ctrl_dev = NULL;
138 static struct ebda_rsrc_list * __init alloc_ebda_rsrc_list (void)
140 struct ebda_rsrc_list *list;
142 list = kmalloc (sizeof (struct ebda_rsrc_list), GFP_KERNEL);
145 memset (list, 0, sizeof (*list));
149 static struct ebda_pci_rsrc *alloc_ebda_pci_rsrc (void)
151 struct ebda_pci_rsrc *resource;
153 resource = kmalloc (sizeof (struct ebda_pci_rsrc), GFP_KERNEL);
156 memset (resource, 0, sizeof (*resource));
160 static void __init print_bus_info (void)
162 struct bus_info *ptr;
163 struct list_head *ptr1;
165 list_for_each (ptr1, &bus_info_head) {
166 ptr = list_entry (ptr1, struct bus_info, bus_info_list);
167 debug ("%s - slot_min = %x\n", __FUNCTION__, ptr->slot_min);
168 debug ("%s - slot_max = %x\n", __FUNCTION__, ptr->slot_max);
169 debug ("%s - slot_count = %x\n", __FUNCTION__, ptr->slot_count);
170 debug ("%s - bus# = %x\n", __FUNCTION__, ptr->busno);
171 debug ("%s - current_speed = %x\n", __FUNCTION__, ptr->current_speed);
172 debug ("%s - controller_id = %x\n", __FUNCTION__, ptr->controller_id);
174 debug ("%s - slots_at_33_conv = %x\n", __FUNCTION__, ptr->slots_at_33_conv);
175 debug ("%s - slots_at_66_conv = %x\n", __FUNCTION__, ptr->slots_at_66_conv);
176 debug ("%s - slots_at_66_pcix = %x\n", __FUNCTION__, ptr->slots_at_66_pcix);
177 debug ("%s - slots_at_100_pcix = %x\n", __FUNCTION__, ptr->slots_at_100_pcix);
178 debug ("%s - slots_at_133_pcix = %x\n", __FUNCTION__, ptr->slots_at_133_pcix);
183 static void print_lo_info (void)
185 struct rio_detail *ptr;
186 struct list_head *ptr1;
187 debug ("print_lo_info ---- \n");
188 list_for_each (ptr1, &rio_lo_head) {
189 ptr = list_entry (ptr1, struct rio_detail, rio_detail_list);
190 debug ("%s - rio_node_id = %x\n", __FUNCTION__, ptr->rio_node_id);
191 debug ("%s - rio_type = %x\n", __FUNCTION__, ptr->rio_type);
192 debug ("%s - owner_id = %x\n", __FUNCTION__, ptr->owner_id);
193 debug ("%s - first_slot_num = %x\n", __FUNCTION__, ptr->first_slot_num);
194 debug ("%s - wpindex = %x\n", __FUNCTION__, ptr->wpindex);
195 debug ("%s - chassis_num = %x\n", __FUNCTION__, ptr->chassis_num);
200 static void print_vg_info (void)
202 struct rio_detail *ptr;
203 struct list_head *ptr1;
204 debug ("%s --- \n", __FUNCTION__);
205 list_for_each (ptr1, &rio_vg_head) {
206 ptr = list_entry (ptr1, struct rio_detail, rio_detail_list);
207 debug ("%s - rio_node_id = %x\n", __FUNCTION__, ptr->rio_node_id);
208 debug ("%s - rio_type = %x\n", __FUNCTION__, ptr->rio_type);
209 debug ("%s - owner_id = %x\n", __FUNCTION__, ptr->owner_id);
210 debug ("%s - first_slot_num = %x\n", __FUNCTION__, ptr->first_slot_num);
211 debug ("%s - wpindex = %x\n", __FUNCTION__, ptr->wpindex);
212 debug ("%s - chassis_num = %x\n", __FUNCTION__, ptr->chassis_num);
217 static void __init print_ebda_pci_rsrc (void)
219 struct ebda_pci_rsrc *ptr;
220 struct list_head *ptr1;
222 list_for_each (ptr1, &ibmphp_ebda_pci_rsrc_head) {
223 ptr = list_entry (ptr1, struct ebda_pci_rsrc, ebda_pci_rsrc_list);
224 debug ("%s - rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
225 __FUNCTION__, ptr->rsrc_type ,ptr->bus_num, ptr->dev_fun,ptr->start_addr, ptr->end_addr);
229 static void __init print_ibm_slot (void)
232 struct list_head *ptr1;
234 list_for_each (ptr1, &ibmphp_slot_head) {
235 ptr = list_entry (ptr1, struct slot, ibm_slot_list);
236 debug ("%s - slot_number: %x \n", __FUNCTION__, ptr->number);
240 static void __init print_opt_vg (void)
243 struct list_head *ptr1;
244 debug ("%s --- \n", __FUNCTION__);
245 list_for_each (ptr1, &opt_vg_head) {
246 ptr = list_entry (ptr1, struct opt_rio, opt_rio_list);
247 debug ("%s - rio_type %x \n", __FUNCTION__, ptr->rio_type);
248 debug ("%s - chassis_num: %x \n", __FUNCTION__, ptr->chassis_num);
249 debug ("%s - first_slot_num: %x \n", __FUNCTION__, ptr->first_slot_num);
250 debug ("%s - middle_num: %x \n", __FUNCTION__, ptr->middle_num);
254 static void __init print_ebda_hpc (void)
256 struct controller *hpc_ptr;
257 struct list_head *ptr1;
260 list_for_each (ptr1, &ebda_hpc_head) {
262 hpc_ptr = list_entry (ptr1, struct controller, ebda_hpc_list);
264 for (index = 0; index < hpc_ptr->slot_count; index++) {
265 debug ("%s - physical slot#: %x\n", __FUNCTION__, hpc_ptr->slots[index].slot_num);
266 debug ("%s - pci bus# of the slot: %x\n", __FUNCTION__, hpc_ptr->slots[index].slot_bus_num);
267 debug ("%s - index into ctlr addr: %x\n", __FUNCTION__, hpc_ptr->slots[index].ctl_index);
268 debug ("%s - cap of the slot: %x\n", __FUNCTION__, hpc_ptr->slots[index].slot_cap);
271 for (index = 0; index < hpc_ptr->bus_count; index++) {
272 debug ("%s - bus# of each bus controlled by this ctlr: %x\n", __FUNCTION__, hpc_ptr->buses[index].bus_num);
275 debug ("%s - type of hpc: %x\n", __FUNCTION__, hpc_ptr->ctlr_type);
276 switch (hpc_ptr->ctlr_type) {
278 debug ("%s - bus: %x\n", __FUNCTION__, hpc_ptr->u.pci_ctlr.bus);
279 debug ("%s - dev_fun: %x\n", __FUNCTION__, hpc_ptr->u.pci_ctlr.dev_fun);
280 debug ("%s - irq: %x\n", __FUNCTION__, hpc_ptr->irq);
284 debug ("%s - io_start: %x\n", __FUNCTION__, hpc_ptr->u.isa_ctlr.io_start);
285 debug ("%s - io_end: %x\n", __FUNCTION__, hpc_ptr->u.isa_ctlr.io_end);
286 debug ("%s - irq: %x\n", __FUNCTION__, hpc_ptr->irq);
291 debug ("%s - wpegbbar: %lx\n", __FUNCTION__, hpc_ptr->u.wpeg_ctlr.wpegbbar);
292 debug ("%s - i2c_addr: %x\n", __FUNCTION__, hpc_ptr->u.wpeg_ctlr.i2c_addr);
293 debug ("%s - irq: %x\n", __FUNCTION__, hpc_ptr->irq);
299 int __init ibmphp_access_ebda (void)
301 u8 format, num_ctlrs, rio_complete, hs_complete;
302 u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, rc, re, rc_id, re_id, base;
308 io_mem = ioremap ((0x40 << 4) + 0x0e, 2);
311 ebda_seg = readw (io_mem);
313 debug ("returned ebda segment: %x\n", ebda_seg);
315 io_mem = ioremap (ebda_seg<<4, 65000);
321 offset = next_offset;
322 next_offset = readw (io_mem + offset); /* offset of next blk */
325 if (next_offset == 0) /* 0 indicate it's last blk */
327 blk_id = readw (io_mem + offset); /* this blk id */
330 /* check if it is hot swap block or rio block */
331 if (blk_id != 0x4853 && blk_id != 0x4752)
334 if (blk_id == 0x4853) {
335 debug ("now enter hot swap block---\n");
336 debug ("hot blk id: %x\n", blk_id);
337 format = readb (io_mem + offset);
344 debug ("hot blk format: %x\n", format);
345 /* hot swap sub blk */
349 re = readw (io_mem + sub_addr); /* next sub blk */
352 rc_id = readw (io_mem + sub_addr); /* sub blk id */
355 if (rc_id != 0x5243) {
359 /* rc sub blk signature */
360 num_ctlrs = readb (io_mem + sub_addr);
363 hpc_list_ptr = alloc_ebda_hpc_list ();
368 hpc_list_ptr->format = format;
369 hpc_list_ptr->num_ctlrs = num_ctlrs;
370 hpc_list_ptr->phys_addr = sub_addr; /* offset of RSRC_CONTROLLER blk */
371 debug ("info about hpc descriptor---\n");
372 debug ("hot blk format: %x\n", format);
373 debug ("num of controller: %x\n", num_ctlrs);
374 debug ("offset of hpc data structure enteries: %x\n ", sub_addr);
376 sub_addr = base + re; /* re sub blk */
377 rc = readw (io_mem + sub_addr); /* next sub blk */
380 re_id = readw (io_mem + sub_addr); /* sub blk id */
383 if (re_id != 0x5245) {
388 /* signature of re */
389 num_entries = readw (io_mem + sub_addr);
391 sub_addr += 2; /* offset of RSRC_ENTRIES blk */
392 rsrc_list_ptr = alloc_ebda_rsrc_list ();
393 if (!rsrc_list_ptr ) {
397 rsrc_list_ptr->format = format;
398 rsrc_list_ptr->num_entries = num_entries;
399 rsrc_list_ptr->phys_addr = sub_addr;
401 debug ("info about rsrc descriptor---\n");
402 debug ("format: %x\n", format);
403 debug ("num of rsrc: %x\n", num_entries);
404 debug ("offset of rsrc data structure enteries: %x\n ", sub_addr);
408 /* found rio table */
409 else if (blk_id == 0x4752) {
410 debug ("now enter io table ---\n");
411 debug ("rio blk id: %x\n", blk_id);
413 rio_table_ptr = kmalloc (sizeof (struct rio_table_hdr), GFP_KERNEL);
416 memset (rio_table_ptr, 0, sizeof (struct rio_table_hdr) );
417 rio_table_ptr->ver_num = readb (io_mem + offset);
418 rio_table_ptr->scal_count = readb (io_mem + offset + 1);
419 rio_table_ptr->riodev_count = readb (io_mem + offset + 2);
420 rio_table_ptr->offset = offset +3 ;
422 debug ("info about rio table hdr ---\n");
423 debug ("ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ", rio_table_ptr->ver_num, rio_table_ptr->scal_count, rio_table_ptr->riodev_count, rio_table_ptr->offset);
429 if (!hs_complete && !rio_complete) {
435 if (rio_complete == 1 && rio_table_ptr->ver_num == 3) {
436 rc = ebda_rio_table ();
443 rc = ebda_rsrc_controller ();
449 rc = ebda_rsrc_rsrc ();
460 * map info of scalability details and rio details from physical address
462 static int __init ebda_rio_table (void)
466 struct rio_detail *rio_detail_ptr;
468 offset = rio_table_ptr->offset;
469 offset += 12 * rio_table_ptr->scal_count;
471 // we do concern about rio details
472 for (i = 0; i < rio_table_ptr->riodev_count; i++) {
473 rio_detail_ptr = kmalloc (sizeof (struct rio_detail), GFP_KERNEL);
476 memset (rio_detail_ptr, 0, sizeof (struct rio_detail));
477 rio_detail_ptr->rio_node_id = readb (io_mem + offset);
478 rio_detail_ptr->bbar = readl (io_mem + offset + 1);
479 rio_detail_ptr->rio_type = readb (io_mem + offset + 5);
480 rio_detail_ptr->owner_id = readb (io_mem + offset + 6);
481 rio_detail_ptr->port0_node_connect = readb (io_mem + offset + 7);
482 rio_detail_ptr->port0_port_connect = readb (io_mem + offset + 8);
483 rio_detail_ptr->port1_node_connect = readb (io_mem + offset + 9);
484 rio_detail_ptr->port1_port_connect = readb (io_mem + offset + 10);
485 rio_detail_ptr->first_slot_num = readb (io_mem + offset + 11);
486 rio_detail_ptr->status = readb (io_mem + offset + 12);
487 rio_detail_ptr->wpindex = readb (io_mem + offset + 13);
488 rio_detail_ptr->chassis_num = readb (io_mem + offset + 14);
489 // 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);
490 //create linked list of chassis
491 if (rio_detail_ptr->rio_type == 4 || rio_detail_ptr->rio_type == 5)
492 list_add (&rio_detail_ptr->rio_detail_list, &rio_vg_head);
493 //create linked list of expansion box
494 else if (rio_detail_ptr->rio_type == 6 || rio_detail_ptr->rio_type == 7)
495 list_add (&rio_detail_ptr->rio_detail_list, &rio_lo_head);
498 kfree (rio_detail_ptr);
507 * reorganizing linked list of chassis
509 static struct opt_rio *search_opt_vg (u8 chassis_num)
512 struct list_head *ptr1;
513 list_for_each (ptr1, &opt_vg_head) {
514 ptr = list_entry (ptr1, struct opt_rio, opt_rio_list);
515 if (ptr->chassis_num == chassis_num)
521 static int __init combine_wpg_for_chassis (void)
523 struct opt_rio *opt_rio_ptr = NULL;
524 struct rio_detail *rio_detail_ptr = NULL;
525 struct list_head *list_head_ptr = NULL;
527 list_for_each (list_head_ptr, &rio_vg_head) {
528 rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list);
529 opt_rio_ptr = search_opt_vg (rio_detail_ptr->chassis_num);
531 opt_rio_ptr = (struct opt_rio *) kmalloc (sizeof (struct opt_rio), GFP_KERNEL);
534 memset (opt_rio_ptr, 0, sizeof (struct opt_rio));
535 opt_rio_ptr->rio_type = rio_detail_ptr->rio_type;
536 opt_rio_ptr->chassis_num = rio_detail_ptr->chassis_num;
537 opt_rio_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
538 opt_rio_ptr->middle_num = rio_detail_ptr->first_slot_num;
539 list_add (&opt_rio_ptr->opt_rio_list, &opt_vg_head);
541 opt_rio_ptr->first_slot_num = min (opt_rio_ptr->first_slot_num, rio_detail_ptr->first_slot_num);
542 opt_rio_ptr->middle_num = max (opt_rio_ptr->middle_num, rio_detail_ptr->first_slot_num);
550 * reorgnizing linked list of expansion box
552 static struct opt_rio_lo *search_opt_lo (u8 chassis_num)
554 struct opt_rio_lo *ptr;
555 struct list_head *ptr1;
556 list_for_each (ptr1, &opt_lo_head) {
557 ptr = list_entry (ptr1, struct opt_rio_lo, opt_rio_lo_list);
558 if (ptr->chassis_num == chassis_num)
564 static int combine_wpg_for_expansion (void)
566 struct opt_rio_lo *opt_rio_lo_ptr = NULL;
567 struct rio_detail *rio_detail_ptr = NULL;
568 struct list_head *list_head_ptr = NULL;
570 list_for_each (list_head_ptr, &rio_lo_head) {
571 rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list);
572 opt_rio_lo_ptr = search_opt_lo (rio_detail_ptr->chassis_num);
573 if (!opt_rio_lo_ptr) {
574 opt_rio_lo_ptr = (struct opt_rio_lo *) kmalloc (sizeof (struct opt_rio_lo), GFP_KERNEL);
577 memset (opt_rio_lo_ptr, 0, sizeof (struct opt_rio_lo));
578 opt_rio_lo_ptr->rio_type = rio_detail_ptr->rio_type;
579 opt_rio_lo_ptr->chassis_num = rio_detail_ptr->chassis_num;
580 opt_rio_lo_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
581 opt_rio_lo_ptr->middle_num = rio_detail_ptr->first_slot_num;
582 opt_rio_lo_ptr->pack_count = 1;
584 list_add (&opt_rio_lo_ptr->opt_rio_lo_list, &opt_lo_head);
586 opt_rio_lo_ptr->first_slot_num = min (opt_rio_lo_ptr->first_slot_num, rio_detail_ptr->first_slot_num);
587 opt_rio_lo_ptr->middle_num = max (opt_rio_lo_ptr->middle_num, rio_detail_ptr->first_slot_num);
588 opt_rio_lo_ptr->pack_count = 2;
594 static char *convert_2digits_to_char (int var)
599 str = (char *) kmalloc (3, GFP_KERNEL);
601 str1 = (char *) kmalloc (2, GFP_KERNEL);
603 bit = (int)(var / 10);
607 *str = (char)(var + 48);
611 *str1 = (char)(bit + 48);
612 strncpy (str, str1, 1);
614 *str1 = (char)((var % 10) + 48);
621 /* Since we don't know the max slot number per each chassis, hence go
622 * through the list of all chassis to find out the range
623 * Arguments: slot_num, 1st slot number of the chassis we think we are on,
624 * var (0 = chassis, 1 = expansion box)
626 static int first_slot_num (u8 slot_num, u8 first_slot, u8 var)
628 struct opt_rio *opt_vg_ptr = NULL;
629 struct opt_rio_lo *opt_lo_ptr = NULL;
630 struct list_head *ptr = NULL;
634 list_for_each (ptr, &opt_vg_head) {
635 opt_vg_ptr = list_entry (ptr, struct opt_rio, opt_rio_list);
636 if ((first_slot < opt_vg_ptr->first_slot_num) && (slot_num >= opt_vg_ptr->first_slot_num)) {
642 list_for_each (ptr, &opt_lo_head) {
643 opt_lo_ptr = list_entry (ptr, struct opt_rio_lo, opt_rio_lo_list);
644 if ((first_slot < opt_lo_ptr->first_slot_num) && (slot_num >= opt_lo_ptr->first_slot_num)) {
653 static struct opt_rio_lo * find_rxe_num (u8 slot_num)
655 struct opt_rio_lo *opt_lo_ptr;
656 struct list_head *ptr;
658 list_for_each (ptr, &opt_lo_head) {
659 opt_lo_ptr = list_entry (ptr, struct opt_rio_lo, opt_rio_lo_list);
660 //check to see if this slot_num belongs to expansion box
661 if ((slot_num >= opt_lo_ptr->first_slot_num) && (!first_slot_num (slot_num, opt_lo_ptr->first_slot_num, 1)))
667 static struct opt_rio * find_chassis_num (u8 slot_num)
669 struct opt_rio *opt_vg_ptr;
670 struct list_head *ptr;
672 list_for_each (ptr, &opt_vg_head) {
673 opt_vg_ptr = list_entry (ptr, struct opt_rio, opt_rio_list);
674 //check to see if this slot_num belongs to chassis
675 if ((slot_num >= opt_vg_ptr->first_slot_num) && (!first_slot_num (slot_num, opt_vg_ptr->first_slot_num, 0)))
681 /* This routine will find out how many slots are in the chassis, so that
682 * the slot numbers for rxe100 would start from 1, and not from 7, or 6 etc
684 static u8 calculate_first_slot (u8 slot_num)
687 struct list_head * list;
688 struct slot * slot_cur;
690 list_for_each (list, &ibmphp_slot_head) {
691 slot_cur = list_entry (list, struct slot, ibm_slot_list);
692 if (slot_cur->ctrl) {
693 if ((slot_cur->ctrl->ctlr_type != 4) && (slot_cur->ctrl->ending_slot_num > first_slot) && (slot_num > slot_cur->ctrl->ending_slot_num))
694 first_slot = slot_cur->ctrl->ending_slot_num;
697 return first_slot + 1;
700 static char *create_file_name (struct slot * slot_cur)
702 struct opt_rio *opt_vg_ptr = NULL;
703 struct opt_rio_lo *opt_lo_ptr = NULL;
704 char *ptr_chassis_num, *ptr_rxe_num, *ptr_slot_num;
705 int which = 0; /* rxe = 1, chassis = 0 */
706 u8 number = 1; /* either chassis or rxe # */
712 err ("Structure passed is empty \n");
716 slot_num = slot_cur->number;
718 chassis_str = (char *) kmalloc (30, GFP_KERNEL);
719 memset (chassis_str, 0, 30);
720 rxe_str = (char *) kmalloc (30, GFP_KERNEL);
721 memset (rxe_str, 0, 30);
722 ptr_chassis_num = (char *) kmalloc (3, GFP_KERNEL);
723 memset (ptr_chassis_num, 0, 3);
724 ptr_rxe_num = (char *) kmalloc (3, GFP_KERNEL);
725 memset (ptr_rxe_num, 0, 3);
726 ptr_slot_num = (char *) kmalloc (3, GFP_KERNEL);
727 memset (ptr_slot_num, 0, 3);
729 strcpy (chassis_str, "chassis");
730 strcpy (rxe_str, "rxe");
733 if (rio_table_ptr->ver_num == 3) {
734 opt_vg_ptr = find_chassis_num (slot_num);
735 opt_lo_ptr = find_rxe_num (slot_num);
740 if ((slot_num - opt_vg_ptr->first_slot_num) > (slot_num - opt_lo_ptr->first_slot_num)) {
741 number = opt_lo_ptr->chassis_num;
742 first_slot = opt_lo_ptr->first_slot_num;
743 which = 1; /* it is RXE */
745 first_slot = opt_vg_ptr->first_slot_num;
746 number = opt_vg_ptr->chassis_num;
750 first_slot = opt_vg_ptr->first_slot_num;
751 number = opt_vg_ptr->chassis_num;
755 } else if (opt_lo_ptr) {
756 number = opt_lo_ptr->chassis_num;
757 first_slot = opt_lo_ptr->first_slot_num;
760 } else if (rio_table_ptr) {
761 if (rio_table_ptr->ver_num == 3) {
762 /* if both NULL and we DO have correct RIO table in BIOS */
767 if (slot_cur->ctrl->ctlr_type == 4) {
768 first_slot = calculate_first_slot (slot_num);
778 *ptr_chassis_num = (char)(number + 48);
779 strcat (chassis_str, ptr_chassis_num);
780 kfree (ptr_chassis_num);
781 strcat (chassis_str, "slot");
782 ptr_slot_num = convert_2digits_to_char (slot_num - first_slot + 1);
783 strcat (chassis_str, ptr_slot_num);
784 kfree (ptr_slot_num);
789 *ptr_rxe_num = (char)(number + 48);
790 strcat (rxe_str, ptr_rxe_num);
792 strcat (rxe_str, "slot");
793 ptr_slot_num = convert_2digits_to_char (slot_num - first_slot + 1);
794 strcat (rxe_str, ptr_slot_num);
795 kfree (ptr_slot_num);
802 static struct pci_driver ibmphp_driver;
805 * map info (ctlr-id, slot count, slot#.. bus count, bus#, ctlr type...) of
806 * each hpc from physical address to a list of hot plug controllers based on
809 static int __init ebda_rsrc_controller (void)
811 u16 addr, addr_slot, addr_bus;
812 u8 ctlr_id, temp, bus_index;
814 u16 slot_num, bus_num, index;
815 struct hotplug_slot *hp_slot_ptr;
816 struct controller *hpc_ptr;
817 struct ebda_hpc_bus *bus_ptr;
818 struct ebda_hpc_slot *slot_ptr;
819 struct bus_info *bus_info_ptr1, *bus_info_ptr2;
822 struct slot *slot_cur;
823 struct list_head *list;
825 addr = hpc_list_ptr->phys_addr;
826 for (ctlr = 0; ctlr < hpc_list_ptr->num_ctlrs; ctlr++) {
828 ctlr_id = readb (io_mem + addr);
830 slot_num = readb (io_mem + addr);
833 addr_slot = addr; /* offset of slot structure */
834 addr += (slot_num * 4);
836 bus_num = readb (io_mem + addr);
839 addr_bus = addr; /* offset of bus */
840 addr += (bus_num * 9); /* offset of ctlr_type */
841 temp = readb (io_mem + addr);
844 /* init hpc structure */
845 hpc_ptr = alloc_ebda_hpc (slot_num, bus_num);
850 hpc_ptr->ctlr_id = ctlr_id;
851 hpc_ptr->ctlr_relative_id = ctlr;
852 hpc_ptr->slot_count = slot_num;
853 hpc_ptr->bus_count = bus_num;
854 debug ("now enter ctlr data struture ---\n");
855 debug ("ctlr id: %x\n", ctlr_id);
856 debug ("ctlr_relative_id: %x\n", hpc_ptr->ctlr_relative_id);
857 debug ("count of slots controlled by this ctlr: %x\n", slot_num);
858 debug ("count of buses controlled by this ctlr: %x\n", bus_num);
860 /* init slot structure, fetch slot, bus, cap... */
861 slot_ptr = hpc_ptr->slots;
862 for (slot = 0; slot < slot_num; slot++) {
863 slot_ptr->slot_num = readb (io_mem + addr_slot);
864 slot_ptr->slot_bus_num = readb (io_mem + addr_slot + slot_num);
865 slot_ptr->ctl_index = readb (io_mem + addr_slot + 2*slot_num);
866 slot_ptr->slot_cap = readb (io_mem + addr_slot + 3*slot_num);
868 // create bus_info lined list --- if only one slot per bus: slot_min = slot_max
870 bus_info_ptr2 = ibmphp_find_same_bus_num (slot_ptr->slot_bus_num);
871 if (!bus_info_ptr2) {
872 bus_info_ptr1 = (struct bus_info *) kmalloc (sizeof (struct bus_info), GFP_KERNEL);
873 if (!bus_info_ptr1) {
877 memset (bus_info_ptr1, 0, sizeof (struct bus_info));
878 bus_info_ptr1->slot_min = slot_ptr->slot_num;
879 bus_info_ptr1->slot_max = slot_ptr->slot_num;
880 bus_info_ptr1->slot_count += 1;
881 bus_info_ptr1->busno = slot_ptr->slot_bus_num;
882 bus_info_ptr1->index = bus_index++;
883 bus_info_ptr1->current_speed = 0xff;
884 bus_info_ptr1->current_bus_mode = 0xff;
886 bus_info_ptr1->controller_id = hpc_ptr->ctlr_id;
888 list_add_tail (&bus_info_ptr1->bus_info_list, &bus_info_head);
891 bus_info_ptr2->slot_min = min (bus_info_ptr2->slot_min, slot_ptr->slot_num);
892 bus_info_ptr2->slot_max = max (bus_info_ptr2->slot_max, slot_ptr->slot_num);
893 bus_info_ptr2->slot_count += 1;
897 // end of creating the bus_info linked list
903 /* init bus structure */
904 bus_ptr = hpc_ptr->buses;
905 for (bus = 0; bus < bus_num; bus++) {
906 bus_ptr->bus_num = readb (io_mem + addr_bus + bus);
907 bus_ptr->slots_at_33_conv = readb (io_mem + addr_bus + bus_num + 8 * bus);
908 bus_ptr->slots_at_66_conv = readb (io_mem + addr_bus + bus_num + 8 * bus + 1);
910 bus_ptr->slots_at_66_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 2);
912 bus_ptr->slots_at_100_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 3);
914 bus_ptr->slots_at_133_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 4);
916 bus_info_ptr2 = ibmphp_find_same_bus_num (bus_ptr->bus_num);
918 bus_info_ptr2->slots_at_33_conv = bus_ptr->slots_at_33_conv;
919 bus_info_ptr2->slots_at_66_conv = bus_ptr->slots_at_66_conv;
920 bus_info_ptr2->slots_at_66_pcix = bus_ptr->slots_at_66_pcix;
921 bus_info_ptr2->slots_at_100_pcix = bus_ptr->slots_at_100_pcix;
922 bus_info_ptr2->slots_at_133_pcix = bus_ptr->slots_at_133_pcix;
927 hpc_ptr->ctlr_type = temp;
929 switch (hpc_ptr->ctlr_type) {
931 hpc_ptr->u.pci_ctlr.bus = readb (io_mem + addr);
932 hpc_ptr->u.pci_ctlr.dev_fun = readb (io_mem + addr + 1);
933 hpc_ptr->irq = readb (io_mem + addr + 2);
935 debug ("ctrl bus = %x, ctlr devfun = %x, irq = %x\n", hpc_ptr->u.pci_ctlr.bus, hpc_ptr->u.pci_ctlr.dev_fun, hpc_ptr->irq);
939 hpc_ptr->u.isa_ctlr.io_start = readw (io_mem + addr);
940 hpc_ptr->u.isa_ctlr.io_end = readw (io_mem + addr + 2);
941 retval = check_region (hpc_ptr->u.isa_ctlr.io_start, (hpc_ptr->u.isa_ctlr.io_end - hpc_ptr->u.isa_ctlr.io_start + 1));
944 request_region (hpc_ptr->u.isa_ctlr.io_start, (hpc_ptr->u.isa_ctlr.io_end - hpc_ptr->u.isa_ctlr.io_start + 1), "ibmphp");
945 hpc_ptr->irq = readb (io_mem + addr + 4);
951 hpc_ptr->u.wpeg_ctlr.wpegbbar = readl (io_mem + addr);
952 hpc_ptr->u.wpeg_ctlr.i2c_addr = readb (io_mem + addr + 4);
953 hpc_ptr->irq = readb (io_mem + addr + 5);
961 //reorganize chassis' linked list
962 combine_wpg_for_chassis ();
963 combine_wpg_for_expansion ();
964 hpc_ptr->revision = 0xff;
965 hpc_ptr->options = 0xff;
966 hpc_ptr->starting_slot_num = hpc_ptr->slots[0].slot_num;
967 hpc_ptr->ending_slot_num = hpc_ptr->slots[slot_num-1].slot_num;
969 // register slots with hpc core as well as create linked list of ibm slot
970 for (index = 0; index < hpc_ptr->slot_count; index++) {
972 hp_slot_ptr = (struct hotplug_slot *) kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL);
977 memset (hp_slot_ptr, 0, sizeof (struct hotplug_slot));
979 hp_slot_ptr->info = (struct hotplug_slot_info *) kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL);
980 if (!hp_slot_ptr->info) {
985 memset (hp_slot_ptr->info, 0, sizeof (struct hotplug_slot_info));
987 hp_slot_ptr->name = (char *) kmalloc (30, GFP_KERNEL);
988 if (!hp_slot_ptr->name) {
990 kfree (hp_slot_ptr->info);
995 hp_slot_ptr->private = alloc_ibm_slot ();
996 if (!hp_slot_ptr->private) {
998 kfree (hp_slot_ptr->name);
999 kfree (hp_slot_ptr->info);
1000 kfree (hp_slot_ptr);
1004 ((struct slot *)hp_slot_ptr->private)->flag = TRUE;
1006 ((struct slot *) hp_slot_ptr->private)->capabilities = hpc_ptr->slots[index].slot_cap;
1007 if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_133_MAX) == EBDA_SLOT_133_MAX)
1008 ((struct slot *) hp_slot_ptr->private)->supported_speed = 3;
1009 else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_100_MAX) == EBDA_SLOT_100_MAX)
1010 ((struct slot *) hp_slot_ptr->private)->supported_speed = 2;
1011 else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_66_MAX) == EBDA_SLOT_66_MAX)
1012 ((struct slot *) hp_slot_ptr->private)->supported_speed = 1;
1014 if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_PCIX_CAP) == EBDA_SLOT_PCIX_CAP)
1015 ((struct slot *) hp_slot_ptr->private)->supported_bus_mode = 1;
1017 ((struct slot *) hp_slot_ptr->private)->supported_bus_mode = 0;
1020 ((struct slot *) hp_slot_ptr->private)->bus = hpc_ptr->slots[index].slot_bus_num;
1022 bus_info_ptr1 = ibmphp_find_same_bus_num (hpc_ptr->slots[index].slot_bus_num);
1023 if (!bus_info_ptr1) {
1027 ((struct slot *) hp_slot_ptr->private)->bus_on = bus_info_ptr1;
1028 bus_info_ptr1 = NULL;
1029 ((struct slot *) hp_slot_ptr->private)->ctrl = hpc_ptr;
1032 ((struct slot *) hp_slot_ptr->private)->ctlr_index = hpc_ptr->slots[index].ctl_index;
1033 ((struct slot *) hp_slot_ptr->private)->number = hpc_ptr->slots[index].slot_num;
1035 ((struct slot *) hp_slot_ptr->private)->hotplug_slot = hp_slot_ptr;
1036 rc = ibmphp_hpc_fillhpslotinfo (hp_slot_ptr);
1042 rc = ibmphp_init_devno ((struct slot **) &hp_slot_ptr->private);
1047 hp_slot_ptr->ops = &ibmphp_hotplug_slot_ops;
1049 // end of registering ibm slot with hotplug core
1051 list_add (& ((struct slot *)(hp_slot_ptr->private))->ibm_slot_list, &ibmphp_slot_head);
1055 list_add (&hpc_ptr->ebda_hpc_list, &ebda_hpc_head );
1059 list_for_each (list, &ibmphp_slot_head) {
1060 slot_cur = list_entry (list, struct slot, ibm_slot_list);
1062 snprintf (slot_cur->hotplug_slot->name, 30, "%s", create_file_name (slot_cur));
1064 kfree (chassis_str);
1067 pci_hp_register (slot_cur->hotplug_slot);
1076 * map info (bus, devfun, start addr, end addr..) of i/o, memory,
1077 * pfm from the physical addr to a list of resource.
1079 static int __init ebda_rsrc_rsrc (void)
1084 struct ebda_pci_rsrc *rsrc_ptr;
1086 addr = rsrc_list_ptr->phys_addr;
1087 debug ("now entering rsrc land\n");
1088 debug ("offset of rsrc: %x\n", rsrc_list_ptr->phys_addr);
1090 for (rsrc = 0; rsrc < rsrc_list_ptr->num_entries; rsrc++) {
1091 type = readb (io_mem + addr);
1094 rsrc_type = type & EBDA_RSRC_TYPE_MASK;
1096 if (rsrc_type == EBDA_IO_RSRC_TYPE) {
1097 rsrc_ptr = alloc_ebda_pci_rsrc ();
1102 rsrc_ptr->rsrc_type = type;
1104 rsrc_ptr->bus_num = readb (io_mem + addr);
1105 rsrc_ptr->dev_fun = readb (io_mem + addr + 1);
1106 rsrc_ptr->start_addr = readw (io_mem + addr + 2);
1107 rsrc_ptr->end_addr = readw (io_mem + addr + 4);
1110 debug ("rsrc from io type ----\n");
1111 debug ("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
1112 rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr);
1114 list_add (&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head);
1117 if (rsrc_type == EBDA_MEM_RSRC_TYPE || rsrc_type == EBDA_PFM_RSRC_TYPE) {
1118 rsrc_ptr = alloc_ebda_pci_rsrc ();
1123 rsrc_ptr->rsrc_type = type;
1125 rsrc_ptr->bus_num = readb (io_mem + addr);
1126 rsrc_ptr->dev_fun = readb (io_mem + addr + 1);
1127 rsrc_ptr->start_addr = readl (io_mem + addr + 2);
1128 rsrc_ptr->end_addr = readl (io_mem + addr + 6);
1131 debug ("rsrc from mem or pfm ---\n");
1132 debug ("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
1133 rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr);
1135 list_add (&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head);
1138 kfree (rsrc_list_ptr);
1139 rsrc_list_ptr = NULL;
1140 print_ebda_pci_rsrc ();
1144 u16 ibmphp_get_total_controllers (void)
1146 return hpc_list_ptr->num_ctlrs;
1149 struct slot *ibmphp_get_slot_from_physical_num (u8 physical_num)
1152 struct list_head *list;
1154 list_for_each (list, &ibmphp_slot_head) {
1155 slot = list_entry (list, struct slot, ibm_slot_list);
1156 if (slot->number == physical_num)
1163 * - the smallest slot number
1164 * - the largest slot number
1165 * - the total number of the slots based on each bus
1166 * (if only one slot per bus slot_min = slot_max )
1168 struct bus_info *ibmphp_find_same_bus_num (u32 num)
1170 struct bus_info *ptr;
1171 struct list_head *ptr1;
1173 list_for_each (ptr1, &bus_info_head) {
1174 ptr = list_entry (ptr1, struct bus_info, bus_info_list);
1175 if (ptr->busno == num)
1181 /* Finding relative bus number, in order to map corresponding
1184 int ibmphp_get_bus_index (u8 num)
1186 struct bus_info *ptr;
1187 struct list_head *ptr1;
1189 list_for_each (ptr1, &bus_info_head) {
1190 ptr = list_entry (ptr1, struct bus_info, bus_info_list);
1191 if (ptr->busno == num)
1197 void ibmphp_free_bus_info_queue (void)
1199 struct bus_info *bus_info;
1200 struct list_head *list;
1201 struct list_head *next;
1203 list_for_each_safe (list, next, &bus_info_head ) {
1204 bus_info = list_entry (list, struct bus_info, bus_info_list);
1209 void ibmphp_free_ebda_hpc_queue (void)
1211 struct controller *controller = NULL;
1212 struct list_head *list;
1213 struct list_head *next;
1216 list_for_each_safe (list, next, &ebda_hpc_head) {
1217 controller = list_entry (list, struct controller, ebda_hpc_list);
1218 if (controller->ctlr_type == 0)
1219 release_region (controller->u.isa_ctlr.io_start, (controller->u.isa_ctlr.io_end - controller->u.isa_ctlr.io_start + 1));
1220 else if ((controller->ctlr_type == 1) && (!pci_flag)) {
1222 pci_unregister_driver (&ibmphp_driver);
1224 free_ebda_hpc (controller);
1228 void ibmphp_free_ebda_pci_rsrc_queue (void)
1230 struct ebda_pci_rsrc *resource;
1231 struct list_head *list;
1232 struct list_head *next;
1234 list_for_each_safe (list, next, &ibmphp_ebda_pci_rsrc_head) {
1235 resource = list_entry (list, struct ebda_pci_rsrc, ebda_pci_rsrc_list);
1241 static struct pci_device_id id_table[] __devinitdata = {
1243 vendor: PCI_VENDOR_ID_IBM,
1244 device: HPC_DEVICE_ID,
1245 subvendor: PCI_VENDOR_ID_IBM,
1246 subdevice: HPC_SUBSYSTEM_ID,
1247 class: ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00),
1251 MODULE_DEVICE_TABLE(pci, id_table);
1253 static int ibmphp_probe (struct pci_dev *, const struct pci_device_id *);
1254 static struct pci_driver ibmphp_driver = {
1257 probe: ibmphp_probe,
1260 int ibmphp_register_pci (void)
1262 struct controller *ctrl;
1263 struct list_head *tmp;
1266 list_for_each (tmp, &ebda_hpc_head) {
1267 ctrl = list_entry (tmp, struct controller, ebda_hpc_list);
1268 if (ctrl->ctlr_type == 1) {
1269 rc = pci_module_init (&ibmphp_driver);
1275 static int ibmphp_probe (struct pci_dev * dev, const struct pci_device_id *ids)
1277 struct controller *ctrl;
1278 struct list_head *tmp;
1280 debug ("inside ibmphp_probe \n");
1282 list_for_each (tmp, &ebda_hpc_head) {
1283 ctrl = list_entry (tmp, struct controller, ebda_hpc_list);
1284 if (ctrl->ctlr_type == 1) {
1285 if ((dev->devfn == ctrl->u.pci_ctlr.dev_fun) && (dev->bus->number == ctrl->u.pci_ctlr.bus)) {
1286 ctrl->ctrl_dev = dev;
1287 debug ("found device!!! \n");
1288 debug ("dev->device = %x, dev->subsystem_device = %x\n", dev->device, dev->subsystem_device);