ibmphp_ebda.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:38k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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