30 #include <linux/module.h>
31 #include <linux/errno.h>
33 #include <linux/slab.h>
34 #include <linux/pci.h>
35 #include <linux/list.h>
68 static int ebda_rsrc_controller (
void);
69 static int ebda_rsrc_rsrc (
void);
70 static int ebda_rio_table (
void);
83 controller = kzalloc(
sizeof(
struct controller),
GFP_KERNEL);
95 controller->
buses = buses;
106 static void free_ebda_hpc (
struct controller *controller)
123 static void __init print_bus_info (
void)
131 debug (
"%s - bus# = %x\n", __func__, ptr->
busno);
144 static void print_lo_info (
void)
147 debug (
"print_lo_info ----\n");
159 static void print_vg_info (
void)
162 debug (
"%s ---\n", __func__);
174 static void __init print_ebda_pci_rsrc (
void)
179 debug (
"%s - rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
184 static void __init print_ibm_slot (
void)
189 debug (
"%s - slot_number: %x\n", __func__, ptr->
number);
193 static void __init print_opt_vg (
void)
196 debug (
"%s ---\n", __func__);
205 static void __init print_ebda_hpc (
void)
207 struct controller *hpc_ptr;
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);
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);
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);
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);
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);
248 u8 format, num_ctlrs, rio_complete, hs_complete, ebda_sz;
256 io_mem =
ioremap ((0x40 << 4) + 0x0e, 2);
259 ebda_seg =
readw (io_mem);
261 debug (
"returned ebda segment: %x\n", ebda_seg);
263 io_mem =
ioremap(ebda_seg<<4, 1);
266 ebda_sz =
readb(io_mem);
268 debug(
"ebda size: %d(KiB)\n", ebda_sz);
272 io_mem =
ioremap(ebda_seg<<4, (ebda_sz * 1024));
278 offset = next_offset;
281 if (
WARN(offset > (ebda_sz * 1024 - 4),
282 "ibmphp_ebda: next read is beyond ebda_sz\n"))
285 next_offset =
readw (io_mem + offset);
288 if (next_offset == 0)
290 blk_id =
readw (io_mem + offset);
294 if (blk_id != 0x4853 && blk_id != 0x4752)
297 if (blk_id == 0x4853) {
298 debug (
"now enter hot swap block---\n");
299 debug (
"hot blk id: %x\n", blk_id);
300 format =
readb (io_mem + offset);
305 debug (
"hot blk format: %x\n", format);
310 re =
readw (io_mem + sub_addr);
313 rc_id =
readw (io_mem + sub_addr);
319 num_ctlrs =
readb (io_mem + sub_addr);
322 hpc_list_ptr = alloc_ebda_hpc_list ();
330 debug (
"info about hpc descriptor---\n");
331 debug (
"hot blk format: %x\n", format);
332 debug (
"num of controller: %x\n", num_ctlrs);
333 debug (
"offset of hpc data structure enteries: %x\n ", sub_addr);
335 sub_addr = base + re;
337 rc =
readw (io_mem + sub_addr);
340 re_id =
readw (io_mem + sub_addr);
347 num_entries =
readw (io_mem + sub_addr);
350 rsrc_list_ptr = alloc_ebda_rsrc_list ();
351 if (!rsrc_list_ptr ) {
359 debug (
"info about rsrc descriptor---\n");
360 debug (
"format: %x\n", format);
361 debug (
"num of rsrc: %x\n", num_entries);
362 debug (
"offset of rsrc data structure enteries: %x\n ", sub_addr);
367 debug (
"now enter io table ---\n");
368 debug (
"rio blk id: %x\n", blk_id);
371 if (!rio_table_ptr) {
378 rio_table_ptr->
offset = offset +3 ;
380 debug(
"info about rio table hdr ---\n");
381 debug(
"ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ",
389 if (!hs_complete && !rio_complete)
393 if (rio_complete && rio_table_ptr->
ver_num == 3) {
394 rc = ebda_rio_table ();
399 rc = ebda_rsrc_controller ();
403 rc = ebda_rsrc_rsrc ();
415 static int __init ebda_rio_table (
void)
421 offset = rio_table_ptr->
offset;
430 rio_detail_ptr->
bbar =
readl (io_mem + offset + 1);
438 rio_detail_ptr->
status =
readb (io_mem + offset + 12);
450 kfree (rio_detail_ptr);
471 static int __init combine_wpg_for_chassis (
void)
477 opt_rio_ptr = search_opt_vg (rio_detail_ptr->
chassis_num);
499 static struct opt_rio_lo *search_opt_lo (
u8 chassis_num)
509 static int combine_wpg_for_expansion (
void)
515 opt_rio_lo_ptr = search_opt_lo (rio_detail_ptr->
chassis_num);
516 if (!opt_rio_lo_ptr) {
578 static struct opt_rio * find_chassis_num (
u8 slot_num)
593 static u8 calculate_first_slot (
u8 slot_num)
596 struct slot * slot_cur;
599 if (slot_cur->
ctrl) {
600 if ((slot_cur->
ctrl->ctlr_type != 4) && (slot_cur->
ctrl->ending_slot_num > first_slot) && (slot_num > slot_cur->
ctrl->ending_slot_num))
601 first_slot = slot_cur->
ctrl->ending_slot_num;
604 return first_slot + 1;
608 #define SLOT_NAME_SIZE 30
610 static char *create_file_name (
struct slot * slot_cur)
622 err (
"Structure passed is empty\n");
626 slot_num = slot_cur->
number;
628 memset (str, 0,
sizeof(str));
631 if (rio_table_ptr->
ver_num == 3) {
632 opt_vg_ptr = find_chassis_num (slot_num);
633 opt_lo_ptr = find_rxe_num (slot_num);
653 }
else if (opt_lo_ptr) {
658 }
else if (rio_table_ptr) {
659 if (rio_table_ptr->
ver_num == 3) {
665 if (slot_cur->
ctrl->ctlr_type == 4) {
666 first_slot = calculate_first_slot (slot_num);
674 which == 0 ?
"chassis" :
"rxe",
675 number, slot_num - first_slot + 1);
679 static int fillslotinfo(
struct hotplug_slot *hotplug_slot)
684 if (!hotplug_slot || !hotplug_slot->private)
687 slot = hotplug_slot->private;
703 hotplug_slot->info->adapter_status = 1;
705 hotplug_slot->info->adapter_status = 0;
717 static void release_slot(
struct hotplug_slot *hotplug_slot)
721 if (!hotplug_slot || !hotplug_slot->private)
724 slot = hotplug_slot->private;
743 static int __init ebda_rsrc_controller (
void)
746 u8 ctlr_id,
temp, bus_index;
749 struct hotplug_slot *hp_slot_ptr;
750 struct controller *hpc_ptr;
753 struct bus_info *bus_info_ptr1, *bus_info_ptr2;
755 struct slot *tmp_slot;
759 for (ctlr = 0; ctlr < hpc_list_ptr->
num_ctlrs; ctlr++) {
761 ctlr_id =
readb (io_mem + addr);
763 slot_num =
readb (io_mem + addr);
767 addr += (slot_num * 4);
769 bus_num =
readb (io_mem + addr);
773 addr += (bus_num * 9);
774 temp =
readb (io_mem + addr);
778 hpc_ptr = alloc_ebda_hpc (slot_num, bus_num);
787 debug (
"now enter ctlr data structure ---\n");
788 debug (
"ctlr id: %x\n", ctlr_id);
790 debug (
"count of slots controlled by this ctlr: %x\n", slot_num);
791 debug (
"count of buses controlled by this ctlr: %x\n", bus_num);
794 slot_ptr = hpc_ptr->
slots;
795 for (slot = 0; slot < slot_num; slot++) {
799 slot_ptr->
slot_cap =
readb (io_mem + addr_slot + 3*slot_num);
804 if (!bus_info_ptr2) {
806 if (!bus_info_ptr1) {
808 goto error_no_hp_slot;
814 bus_info_ptr1->
index = bus_index++;
836 bus_ptr = hpc_ptr->
buses;
837 for (bus = 0; bus < bus_num; bus++) {
865 hpc_ptr->
irq =
readb (io_mem + addr + 2);
867 debug (
"ctrl bus = %x, ctlr devfun = %x, irq = %x\n",
879 goto error_no_hp_slot;
881 hpc_ptr->
irq =
readb (io_mem + addr + 4);
889 hpc_ptr->
irq =
readb (io_mem + addr + 5);
894 goto error_no_hp_slot;
898 combine_wpg_for_chassis ();
899 combine_wpg_for_expansion ();
906 for (index = 0; index < hpc_ptr->
slot_count; index++) {
908 hp_slot_ptr = kzalloc(
sizeof(*hp_slot_ptr),
GFP_KERNEL);
911 goto error_no_hp_slot;
915 if (!hp_slot_ptr->info) {
917 goto error_no_hp_info;
920 tmp_slot = kzalloc(
sizeof(*tmp_slot),
GFP_KERNEL);
945 if (!bus_info_ptr1) {
950 tmp_slot->
bus_on = bus_info_ptr1;
951 bus_info_ptr1 =
NULL;
952 tmp_slot->
ctrl = hpc_ptr;
958 hp_slot_ptr->private = tmp_slot;
959 hp_slot_ptr->release = release_slot;
961 rc = fillslotinfo(hp_slot_ptr);
972 list_add (& ((
struct slot *)(hp_slot_ptr->private))->ibm_slot_list, &ibmphp_slot_head);
991 kfree (hp_slot_ptr->private);
993 kfree (hp_slot_ptr->info);
997 free_ebda_hpc (hpc_ptr);
1007 static int __init ebda_rsrc_rsrc (
void)
1015 debug (
"now entering rsrc land\n");
1018 for (rsrc = 0; rsrc < rsrc_list_ptr->
num_entries; rsrc++) {
1019 type =
readb (io_mem + addr);
1025 rsrc_ptr = alloc_ebda_pci_rsrc ();
1038 debug (
"rsrc from io type ----\n");
1039 debug (
"rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
1046 rsrc_ptr = alloc_ebda_pci_rsrc ();
1059 debug (
"rsrc from mem or pfm ---\n");
1060 debug (
"rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
1066 kfree (rsrc_list_ptr);
1067 rsrc_list_ptr =
NULL;
1068 print_ebda_pci_rsrc ();
1082 if (slot->
number == physical_num)
1099 if (ptr->
busno == num)
1113 if (ptr->
busno == num)
1126 bus_info =
list_entry (list,
struct bus_info, bus_info_list);
1133 struct controller *controller =
NULL;
1142 else if ((controller->
ctlr_type == 1) && (!pci_flag)) {
1146 free_ebda_hpc (controller);
1179 .probe = ibmphp_probe,
1184 struct controller *
ctrl;
1189 rc = pci_register_driver(&ibmphp_driver);
1197 struct controller *
ctrl;
1199 debug (
"inside ibmphp_probe\n");
1205 debug (
"found device!!!\n");