ibmphp_ebda.c 34 KB

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