ibmphp_ebda.c 36 KB

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