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