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/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. struct list_head *ptr1;
  112. list_for_each (ptr1, &bus_info_head) {
  113. ptr = list_entry (ptr1, struct bus_info, bus_info_list);
  114. debug ("%s - slot_min = %x\n", __FUNCTION__, ptr->slot_min);
  115. debug ("%s - slot_max = %x\n", __FUNCTION__, ptr->slot_max);
  116. debug ("%s - slot_count = %x\n", __FUNCTION__, ptr->slot_count);
  117. debug ("%s - bus# = %x\n", __FUNCTION__, ptr->busno);
  118. debug ("%s - current_speed = %x\n", __FUNCTION__, ptr->current_speed);
  119. debug ("%s - controller_id = %x\n", __FUNCTION__, ptr->controller_id);
  120. debug ("%s - slots_at_33_conv = %x\n", __FUNCTION__, ptr->slots_at_33_conv);
  121. debug ("%s - slots_at_66_conv = %x\n", __FUNCTION__, ptr->slots_at_66_conv);
  122. debug ("%s - slots_at_66_pcix = %x\n", __FUNCTION__, ptr->slots_at_66_pcix);
  123. debug ("%s - slots_at_100_pcix = %x\n", __FUNCTION__, ptr->slots_at_100_pcix);
  124. debug ("%s - slots_at_133_pcix = %x\n", __FUNCTION__, ptr->slots_at_133_pcix);
  125. }
  126. }
  127. static void print_lo_info (void)
  128. {
  129. struct rio_detail *ptr;
  130. struct list_head *ptr1;
  131. debug ("print_lo_info ----\n");
  132. list_for_each (ptr1, &rio_lo_head) {
  133. ptr = list_entry (ptr1, struct rio_detail, rio_detail_list);
  134. debug ("%s - rio_node_id = %x\n", __FUNCTION__, ptr->rio_node_id);
  135. debug ("%s - rio_type = %x\n", __FUNCTION__, ptr->rio_type);
  136. debug ("%s - owner_id = %x\n", __FUNCTION__, ptr->owner_id);
  137. debug ("%s - first_slot_num = %x\n", __FUNCTION__, ptr->first_slot_num);
  138. debug ("%s - wpindex = %x\n", __FUNCTION__, ptr->wpindex);
  139. debug ("%s - chassis_num = %x\n", __FUNCTION__, ptr->chassis_num);
  140. }
  141. }
  142. static void print_vg_info (void)
  143. {
  144. struct rio_detail *ptr;
  145. struct list_head *ptr1;
  146. debug ("%s ---\n", __FUNCTION__);
  147. list_for_each (ptr1, &rio_vg_head) {
  148. ptr = list_entry (ptr1, struct rio_detail, rio_detail_list);
  149. debug ("%s - rio_node_id = %x\n", __FUNCTION__, ptr->rio_node_id);
  150. debug ("%s - rio_type = %x\n", __FUNCTION__, ptr->rio_type);
  151. debug ("%s - owner_id = %x\n", __FUNCTION__, ptr->owner_id);
  152. debug ("%s - first_slot_num = %x\n", __FUNCTION__, ptr->first_slot_num);
  153. debug ("%s - wpindex = %x\n", __FUNCTION__, ptr->wpindex);
  154. debug ("%s - chassis_num = %x\n", __FUNCTION__, ptr->chassis_num);
  155. }
  156. }
  157. static void __init print_ebda_pci_rsrc (void)
  158. {
  159. struct ebda_pci_rsrc *ptr;
  160. struct list_head *ptr1;
  161. list_for_each (ptr1, &ibmphp_ebda_pci_rsrc_head) {
  162. ptr = list_entry (ptr1, struct ebda_pci_rsrc, ebda_pci_rsrc_list);
  163. debug ("%s - rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
  164. __FUNCTION__, ptr->rsrc_type ,ptr->bus_num, ptr->dev_fun,ptr->start_addr, ptr->end_addr);
  165. }
  166. }
  167. static void __init print_ibm_slot (void)
  168. {
  169. struct slot *ptr;
  170. struct list_head *ptr1;
  171. list_for_each (ptr1, &ibmphp_slot_head) {
  172. ptr = list_entry (ptr1, struct slot, ibm_slot_list);
  173. debug ("%s - slot_number: %x\n", __FUNCTION__, ptr->number);
  174. }
  175. }
  176. static void __init print_opt_vg (void)
  177. {
  178. struct opt_rio *ptr;
  179. struct list_head *ptr1;
  180. debug ("%s ---\n", __FUNCTION__);
  181. list_for_each (ptr1, &opt_vg_head) {
  182. ptr = list_entry (ptr1, struct opt_rio, opt_rio_list);
  183. debug ("%s - rio_type %x\n", __FUNCTION__, ptr->rio_type);
  184. debug ("%s - chassis_num: %x\n", __FUNCTION__, ptr->chassis_num);
  185. debug ("%s - first_slot_num: %x\n", __FUNCTION__, ptr->first_slot_num);
  186. debug ("%s - middle_num: %x\n", __FUNCTION__, ptr->middle_num);
  187. }
  188. }
  189. static void __init print_ebda_hpc (void)
  190. {
  191. struct controller *hpc_ptr;
  192. struct list_head *ptr1;
  193. u16 index;
  194. list_for_each (ptr1, &ebda_hpc_head) {
  195. hpc_ptr = list_entry (ptr1, struct controller, ebda_hpc_list);
  196. for (index = 0; index < hpc_ptr->slot_count; index++) {
  197. debug ("%s - physical slot#: %x\n", __FUNCTION__, hpc_ptr->slots[index].slot_num);
  198. debug ("%s - pci bus# of the slot: %x\n", __FUNCTION__, hpc_ptr->slots[index].slot_bus_num);
  199. debug ("%s - index into ctlr addr: %x\n", __FUNCTION__, hpc_ptr->slots[index].ctl_index);
  200. debug ("%s - cap of the slot: %x\n", __FUNCTION__, hpc_ptr->slots[index].slot_cap);
  201. }
  202. for (index = 0; index < hpc_ptr->bus_count; index++) {
  203. debug ("%s - bus# of each bus controlled by this ctlr: %x\n", __FUNCTION__, hpc_ptr->buses[index].bus_num);
  204. }
  205. debug ("%s - type of hpc: %x\n", __FUNCTION__, hpc_ptr->ctlr_type);
  206. switch (hpc_ptr->ctlr_type) {
  207. case 1:
  208. debug ("%s - bus: %x\n", __FUNCTION__, hpc_ptr->u.pci_ctlr.bus);
  209. debug ("%s - dev_fun: %x\n", __FUNCTION__, hpc_ptr->u.pci_ctlr.dev_fun);
  210. debug ("%s - irq: %x\n", __FUNCTION__, hpc_ptr->irq);
  211. break;
  212. case 0:
  213. debug ("%s - io_start: %x\n", __FUNCTION__, hpc_ptr->u.isa_ctlr.io_start);
  214. debug ("%s - io_end: %x\n", __FUNCTION__, hpc_ptr->u.isa_ctlr.io_end);
  215. debug ("%s - irq: %x\n", __FUNCTION__, hpc_ptr->irq);
  216. break;
  217. case 2:
  218. case 4:
  219. debug ("%s - wpegbbar: %lx\n", __FUNCTION__, hpc_ptr->u.wpeg_ctlr.wpegbbar);
  220. debug ("%s - i2c_addr: %x\n", __FUNCTION__, hpc_ptr->u.wpeg_ctlr.i2c_addr);
  221. debug ("%s - irq: %x\n", __FUNCTION__, hpc_ptr->irq);
  222. break;
  223. }
  224. }
  225. }
  226. int __init ibmphp_access_ebda (void)
  227. {
  228. u8 format, num_ctlrs, rio_complete, hs_complete;
  229. u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, re, rc_id, re_id, base;
  230. int rc = 0;
  231. rio_complete = 0;
  232. hs_complete = 0;
  233. io_mem = ioremap ((0x40 << 4) + 0x0e, 2);
  234. if (!io_mem )
  235. return -ENOMEM;
  236. ebda_seg = readw (io_mem);
  237. iounmap (io_mem);
  238. debug ("returned ebda segment: %x\n", ebda_seg);
  239. io_mem = ioremap (ebda_seg<<4, 65000);
  240. if (!io_mem )
  241. return -ENOMEM;
  242. next_offset = 0x180;
  243. for (;;) {
  244. offset = next_offset;
  245. next_offset = readw (io_mem + offset); /* offset of next blk */
  246. offset += 2;
  247. if (next_offset == 0) /* 0 indicate it's last blk */
  248. break;
  249. blk_id = readw (io_mem + offset); /* this blk id */
  250. offset += 2;
  251. /* check if it is hot swap block or rio block */
  252. if (blk_id != 0x4853 && blk_id != 0x4752)
  253. continue;
  254. /* found hs table */
  255. if (blk_id == 0x4853) {
  256. debug ("now enter hot swap block---\n");
  257. debug ("hot blk id: %x\n", blk_id);
  258. format = readb (io_mem + offset);
  259. offset += 1;
  260. if (format != 4)
  261. goto error_nodev;
  262. debug ("hot blk format: %x\n", format);
  263. /* hot swap sub blk */
  264. base = offset;
  265. sub_addr = base;
  266. re = readw (io_mem + sub_addr); /* next sub blk */
  267. sub_addr += 2;
  268. rc_id = readw (io_mem + sub_addr); /* sub blk id */
  269. sub_addr += 2;
  270. if (rc_id != 0x5243)
  271. goto error_nodev;
  272. /* rc sub blk signature */
  273. num_ctlrs = readb (io_mem + sub_addr);
  274. sub_addr += 1;
  275. hpc_list_ptr = alloc_ebda_hpc_list ();
  276. if (!hpc_list_ptr) {
  277. rc = -ENOMEM;
  278. goto out;
  279. }
  280. hpc_list_ptr->format = format;
  281. hpc_list_ptr->num_ctlrs = num_ctlrs;
  282. hpc_list_ptr->phys_addr = sub_addr; /* offset of RSRC_CONTROLLER blk */
  283. debug ("info about hpc descriptor---\n");
  284. debug ("hot blk format: %x\n", format);
  285. debug ("num of controller: %x\n", num_ctlrs);
  286. debug ("offset of hpc data structure enteries: %x\n ", sub_addr);
  287. sub_addr = base + re; /* re sub blk */
  288. /* FIXME: rc is never used/checked */
  289. rc = readw (io_mem + sub_addr); /* next sub blk */
  290. sub_addr += 2;
  291. re_id = readw (io_mem + sub_addr); /* sub blk id */
  292. sub_addr += 2;
  293. if (re_id != 0x5245)
  294. goto error_nodev;
  295. /* signature of re */
  296. num_entries = readw (io_mem + sub_addr);
  297. sub_addr += 2; /* offset of RSRC_ENTRIES blk */
  298. rsrc_list_ptr = alloc_ebda_rsrc_list ();
  299. if (!rsrc_list_ptr ) {
  300. rc = -ENOMEM;
  301. goto out;
  302. }
  303. rsrc_list_ptr->format = format;
  304. rsrc_list_ptr->num_entries = num_entries;
  305. rsrc_list_ptr->phys_addr = sub_addr;
  306. debug ("info about rsrc descriptor---\n");
  307. debug ("format: %x\n", format);
  308. debug ("num of rsrc: %x\n", num_entries);
  309. debug ("offset of rsrc data structure enteries: %x\n ", sub_addr);
  310. hs_complete = 1;
  311. } else {
  312. /* found rio table, blk_id == 0x4752 */
  313. debug ("now enter io table ---\n");
  314. debug ("rio blk id: %x\n", blk_id);
  315. rio_table_ptr = kzalloc(sizeof(struct rio_table_hdr), GFP_KERNEL);
  316. if (!rio_table_ptr)
  317. return -ENOMEM;
  318. rio_table_ptr->ver_num = readb (io_mem + offset);
  319. rio_table_ptr->scal_count = readb (io_mem + offset + 1);
  320. rio_table_ptr->riodev_count = readb (io_mem + offset + 2);
  321. rio_table_ptr->offset = offset +3 ;
  322. debug("info about rio table hdr ---\n");
  323. debug("ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ",
  324. rio_table_ptr->ver_num, rio_table_ptr->scal_count,
  325. rio_table_ptr->riodev_count, rio_table_ptr->offset);
  326. rio_complete = 1;
  327. }
  328. }
  329. if (!hs_complete && !rio_complete)
  330. goto error_nodev;
  331. if (rio_table_ptr) {
  332. if (rio_complete && rio_table_ptr->ver_num == 3) {
  333. rc = ebda_rio_table ();
  334. if (rc)
  335. goto out;
  336. }
  337. }
  338. rc = ebda_rsrc_controller ();
  339. if (rc)
  340. goto out;
  341. rc = ebda_rsrc_rsrc ();
  342. goto out;
  343. error_nodev:
  344. rc = -ENODEV;
  345. out:
  346. iounmap (io_mem);
  347. return rc;
  348. }
  349. /*
  350. * map info of scalability details and rio details from physical address
  351. */
  352. static int __init ebda_rio_table (void)
  353. {
  354. u16 offset;
  355. u8 i;
  356. struct rio_detail *rio_detail_ptr;
  357. offset = rio_table_ptr->offset;
  358. offset += 12 * rio_table_ptr->scal_count;
  359. // we do concern about rio details
  360. for (i = 0; i < rio_table_ptr->riodev_count; i++) {
  361. rio_detail_ptr = kzalloc(sizeof(struct rio_detail), GFP_KERNEL);
  362. if (!rio_detail_ptr)
  363. return -ENOMEM;
  364. rio_detail_ptr->rio_node_id = readb (io_mem + offset);
  365. rio_detail_ptr->bbar = readl (io_mem + offset + 1);
  366. rio_detail_ptr->rio_type = readb (io_mem + offset + 5);
  367. rio_detail_ptr->owner_id = readb (io_mem + offset + 6);
  368. rio_detail_ptr->port0_node_connect = readb (io_mem + offset + 7);
  369. rio_detail_ptr->port0_port_connect = readb (io_mem + offset + 8);
  370. rio_detail_ptr->port1_node_connect = readb (io_mem + offset + 9);
  371. rio_detail_ptr->port1_port_connect = readb (io_mem + offset + 10);
  372. rio_detail_ptr->first_slot_num = readb (io_mem + offset + 11);
  373. rio_detail_ptr->status = readb (io_mem + offset + 12);
  374. rio_detail_ptr->wpindex = readb (io_mem + offset + 13);
  375. rio_detail_ptr->chassis_num = readb (io_mem + offset + 14);
  376. // 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);
  377. //create linked list of chassis
  378. if (rio_detail_ptr->rio_type == 4 || rio_detail_ptr->rio_type == 5)
  379. list_add (&rio_detail_ptr->rio_detail_list, &rio_vg_head);
  380. //create linked list of expansion box
  381. else if (rio_detail_ptr->rio_type == 6 || rio_detail_ptr->rio_type == 7)
  382. list_add (&rio_detail_ptr->rio_detail_list, &rio_lo_head);
  383. else
  384. // not in my concern
  385. kfree (rio_detail_ptr);
  386. offset += 15;
  387. }
  388. print_lo_info ();
  389. print_vg_info ();
  390. return 0;
  391. }
  392. /*
  393. * reorganizing linked list of chassis
  394. */
  395. static struct opt_rio *search_opt_vg (u8 chassis_num)
  396. {
  397. struct opt_rio *ptr;
  398. struct list_head *ptr1;
  399. list_for_each (ptr1, &opt_vg_head) {
  400. ptr = list_entry (ptr1, struct opt_rio, opt_rio_list);
  401. if (ptr->chassis_num == chassis_num)
  402. return ptr;
  403. }
  404. return NULL;
  405. }
  406. static int __init combine_wpg_for_chassis (void)
  407. {
  408. struct opt_rio *opt_rio_ptr = NULL;
  409. struct rio_detail *rio_detail_ptr = NULL;
  410. struct list_head *list_head_ptr = NULL;
  411. list_for_each (list_head_ptr, &rio_vg_head) {
  412. rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list);
  413. opt_rio_ptr = search_opt_vg (rio_detail_ptr->chassis_num);
  414. if (!opt_rio_ptr) {
  415. opt_rio_ptr = kzalloc(sizeof(struct opt_rio), GFP_KERNEL);
  416. if (!opt_rio_ptr)
  417. return -ENOMEM;
  418. opt_rio_ptr->rio_type = rio_detail_ptr->rio_type;
  419. opt_rio_ptr->chassis_num = rio_detail_ptr->chassis_num;
  420. opt_rio_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
  421. opt_rio_ptr->middle_num = rio_detail_ptr->first_slot_num;
  422. list_add (&opt_rio_ptr->opt_rio_list, &opt_vg_head);
  423. } else {
  424. opt_rio_ptr->first_slot_num = min (opt_rio_ptr->first_slot_num, rio_detail_ptr->first_slot_num);
  425. opt_rio_ptr->middle_num = max (opt_rio_ptr->middle_num, rio_detail_ptr->first_slot_num);
  426. }
  427. }
  428. print_opt_vg ();
  429. return 0;
  430. }
  431. /*
  432. * reorgnizing linked list of expansion box
  433. */
  434. static struct opt_rio_lo *search_opt_lo (u8 chassis_num)
  435. {
  436. struct opt_rio_lo *ptr;
  437. struct list_head *ptr1;
  438. list_for_each (ptr1, &opt_lo_head) {
  439. ptr = list_entry (ptr1, struct opt_rio_lo, opt_rio_lo_list);
  440. if (ptr->chassis_num == chassis_num)
  441. return ptr;
  442. }
  443. return NULL;
  444. }
  445. static int combine_wpg_for_expansion (void)
  446. {
  447. struct opt_rio_lo *opt_rio_lo_ptr = NULL;
  448. struct rio_detail *rio_detail_ptr = NULL;
  449. struct list_head *list_head_ptr = NULL;
  450. list_for_each (list_head_ptr, &rio_lo_head) {
  451. rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list);
  452. opt_rio_lo_ptr = search_opt_lo (rio_detail_ptr->chassis_num);
  453. if (!opt_rio_lo_ptr) {
  454. opt_rio_lo_ptr = kzalloc(sizeof(struct opt_rio_lo), GFP_KERNEL);
  455. if (!opt_rio_lo_ptr)
  456. return -ENOMEM;
  457. opt_rio_lo_ptr->rio_type = rio_detail_ptr->rio_type;
  458. opt_rio_lo_ptr->chassis_num = rio_detail_ptr->chassis_num;
  459. opt_rio_lo_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
  460. opt_rio_lo_ptr->middle_num = rio_detail_ptr->first_slot_num;
  461. opt_rio_lo_ptr->pack_count = 1;
  462. list_add (&opt_rio_lo_ptr->opt_rio_lo_list, &opt_lo_head);
  463. } else {
  464. opt_rio_lo_ptr->first_slot_num = min (opt_rio_lo_ptr->first_slot_num, rio_detail_ptr->first_slot_num);
  465. opt_rio_lo_ptr->middle_num = max (opt_rio_lo_ptr->middle_num, rio_detail_ptr->first_slot_num);
  466. opt_rio_lo_ptr->pack_count = 2;
  467. }
  468. }
  469. return 0;
  470. }
  471. /* Since we don't know the max slot number per each chassis, hence go
  472. * through the list of all chassis to find out the range
  473. * Arguments: slot_num, 1st slot number of the chassis we think we are on,
  474. * var (0 = chassis, 1 = expansion box)
  475. */
  476. static int first_slot_num (u8 slot_num, u8 first_slot, u8 var)
  477. {
  478. struct opt_rio *opt_vg_ptr = NULL;
  479. struct opt_rio_lo *opt_lo_ptr = NULL;
  480. struct list_head *ptr = NULL;
  481. int rc = 0;
  482. if (!var) {
  483. list_for_each (ptr, &opt_vg_head) {
  484. opt_vg_ptr = list_entry (ptr, struct opt_rio, opt_rio_list);
  485. if ((first_slot < opt_vg_ptr->first_slot_num) && (slot_num >= opt_vg_ptr->first_slot_num)) {
  486. rc = -ENODEV;
  487. break;
  488. }
  489. }
  490. } else {
  491. list_for_each (ptr, &opt_lo_head) {
  492. opt_lo_ptr = list_entry (ptr, struct opt_rio_lo, opt_rio_lo_list);
  493. if ((first_slot < opt_lo_ptr->first_slot_num) && (slot_num >= opt_lo_ptr->first_slot_num)) {
  494. rc = -ENODEV;
  495. break;
  496. }
  497. }
  498. }
  499. return rc;
  500. }
  501. static struct opt_rio_lo * find_rxe_num (u8 slot_num)
  502. {
  503. struct opt_rio_lo *opt_lo_ptr;
  504. struct list_head *ptr;
  505. list_for_each (ptr, &opt_lo_head) {
  506. opt_lo_ptr = list_entry (ptr, struct opt_rio_lo, opt_rio_lo_list);
  507. //check to see if this slot_num belongs to expansion box
  508. if ((slot_num >= opt_lo_ptr->first_slot_num) && (!first_slot_num (slot_num, opt_lo_ptr->first_slot_num, 1)))
  509. return opt_lo_ptr;
  510. }
  511. return NULL;
  512. }
  513. static struct opt_rio * find_chassis_num (u8 slot_num)
  514. {
  515. struct opt_rio *opt_vg_ptr;
  516. struct list_head *ptr;
  517. list_for_each (ptr, &opt_vg_head) {
  518. opt_vg_ptr = list_entry (ptr, struct opt_rio, opt_rio_list);
  519. //check to see if this slot_num belongs to chassis
  520. if ((slot_num >= opt_vg_ptr->first_slot_num) && (!first_slot_num (slot_num, opt_vg_ptr->first_slot_num, 0)))
  521. return opt_vg_ptr;
  522. }
  523. return NULL;
  524. }
  525. /* This routine will find out how many slots are in the chassis, so that
  526. * the slot numbers for rxe100 would start from 1, and not from 7, or 6 etc
  527. */
  528. static u8 calculate_first_slot (u8 slot_num)
  529. {
  530. u8 first_slot = 1;
  531. struct list_head * list;
  532. struct slot * slot_cur;
  533. list_for_each (list, &ibmphp_slot_head) {
  534. slot_cur = list_entry (list, struct slot, ibm_slot_list);
  535. if (slot_cur->ctrl) {
  536. if ((slot_cur->ctrl->ctlr_type != 4) && (slot_cur->ctrl->ending_slot_num > first_slot) && (slot_num > slot_cur->ctrl->ending_slot_num))
  537. first_slot = slot_cur->ctrl->ending_slot_num;
  538. }
  539. }
  540. return first_slot + 1;
  541. }
  542. static char *create_file_name (struct slot * slot_cur)
  543. {
  544. struct opt_rio *opt_vg_ptr = NULL;
  545. struct opt_rio_lo *opt_lo_ptr = NULL;
  546. static char str[30];
  547. int which = 0; /* rxe = 1, chassis = 0 */
  548. u8 number = 1; /* either chassis or rxe # */
  549. u8 first_slot = 1;
  550. u8 slot_num;
  551. u8 flag = 0;
  552. if (!slot_cur) {
  553. err ("Structure passed is empty\n");
  554. return NULL;
  555. }
  556. slot_num = slot_cur->number;
  557. memset (str, 0, sizeof(str));
  558. if (rio_table_ptr) {
  559. if (rio_table_ptr->ver_num == 3) {
  560. opt_vg_ptr = find_chassis_num (slot_num);
  561. opt_lo_ptr = find_rxe_num (slot_num);
  562. }
  563. }
  564. if (opt_vg_ptr) {
  565. if (opt_lo_ptr) {
  566. if ((slot_num - opt_vg_ptr->first_slot_num) > (slot_num - opt_lo_ptr->first_slot_num)) {
  567. number = opt_lo_ptr->chassis_num;
  568. first_slot = opt_lo_ptr->first_slot_num;
  569. which = 1; /* it is RXE */
  570. } else {
  571. first_slot = opt_vg_ptr->first_slot_num;
  572. number = opt_vg_ptr->chassis_num;
  573. which = 0;
  574. }
  575. } else {
  576. first_slot = opt_vg_ptr->first_slot_num;
  577. number = opt_vg_ptr->chassis_num;
  578. which = 0;
  579. }
  580. ++flag;
  581. } else if (opt_lo_ptr) {
  582. number = opt_lo_ptr->chassis_num;
  583. first_slot = opt_lo_ptr->first_slot_num;
  584. which = 1;
  585. ++flag;
  586. } else if (rio_table_ptr) {
  587. if (rio_table_ptr->ver_num == 3) {
  588. /* if both NULL and we DO have correct RIO table in BIOS */
  589. return NULL;
  590. }
  591. }
  592. if (!flag) {
  593. if (slot_cur->ctrl->ctlr_type == 4) {
  594. first_slot = calculate_first_slot (slot_num);
  595. which = 1;
  596. } else {
  597. which = 0;
  598. }
  599. }
  600. sprintf(str, "%s%dslot%d",
  601. which == 0 ? "chassis" : "rxe",
  602. number, slot_num - first_slot + 1);
  603. return str;
  604. }
  605. static int fillslotinfo(struct hotplug_slot *hotplug_slot)
  606. {
  607. struct slot *slot;
  608. int rc = 0;
  609. if (!hotplug_slot || !hotplug_slot->private)
  610. return -EINVAL;
  611. slot = hotplug_slot->private;
  612. rc = ibmphp_hpc_readslot(slot, READ_ALLSTAT, NULL);
  613. if (rc)
  614. return rc;
  615. // power - enabled:1 not:0
  616. hotplug_slot->info->power_status = SLOT_POWER(slot->status);
  617. // attention - off:0, on:1, blinking:2
  618. hotplug_slot->info->attention_status = SLOT_ATTN(slot->status, slot->ext_status);
  619. // latch - open:1 closed:0
  620. hotplug_slot->info->latch_status = SLOT_LATCH(slot->status);
  621. // pci board - present:1 not:0
  622. if (SLOT_PRESENT (slot->status))
  623. hotplug_slot->info->adapter_status = 1;
  624. else
  625. hotplug_slot->info->adapter_status = 0;
  626. /*
  627. if (slot->bus_on->supported_bus_mode
  628. && (slot->bus_on->supported_speed == BUS_SPEED_66))
  629. hotplug_slot->info->max_bus_speed_status = BUS_SPEED_66PCIX;
  630. else
  631. hotplug_slot->info->max_bus_speed_status = slot->bus_on->supported_speed;
  632. */
  633. return rc;
  634. }
  635. static void release_slot(struct hotplug_slot *hotplug_slot)
  636. {
  637. struct slot *slot;
  638. if (!hotplug_slot || !hotplug_slot->private)
  639. return;
  640. slot = hotplug_slot->private;
  641. kfree(slot->hotplug_slot->info);
  642. kfree(slot->hotplug_slot->name);
  643. kfree(slot->hotplug_slot);
  644. slot->ctrl = NULL;
  645. slot->bus_on = NULL;
  646. /* we don't want to actually remove the resources, since free_resources will do just that */
  647. ibmphp_unconfigure_card(&slot, -1);
  648. kfree (slot);
  649. }
  650. static struct pci_driver ibmphp_driver;
  651. /*
  652. * map info (ctlr-id, slot count, slot#.. bus count, bus#, ctlr type...) of
  653. * each hpc from physical address to a list of hot plug controllers based on
  654. * hpc descriptors.
  655. */
  656. static int __init ebda_rsrc_controller (void)
  657. {
  658. u16 addr, addr_slot, addr_bus;
  659. u8 ctlr_id, temp, bus_index;
  660. u16 ctlr, slot, bus;
  661. u16 slot_num, bus_num, index;
  662. struct hotplug_slot *hp_slot_ptr;
  663. struct controller *hpc_ptr;
  664. struct ebda_hpc_bus *bus_ptr;
  665. struct ebda_hpc_slot *slot_ptr;
  666. struct bus_info *bus_info_ptr1, *bus_info_ptr2;
  667. int rc;
  668. struct slot *tmp_slot;
  669. struct list_head *list;
  670. addr = hpc_list_ptr->phys_addr;
  671. for (ctlr = 0; ctlr < hpc_list_ptr->num_ctlrs; ctlr++) {
  672. bus_index = 1;
  673. ctlr_id = readb (io_mem + addr);
  674. addr += 1;
  675. slot_num = readb (io_mem + addr);
  676. addr += 1;
  677. addr_slot = addr; /* offset of slot structure */
  678. addr += (slot_num * 4);
  679. bus_num = readb (io_mem + addr);
  680. addr += 1;
  681. addr_bus = addr; /* offset of bus */
  682. addr += (bus_num * 9); /* offset of ctlr_type */
  683. temp = readb (io_mem + addr);
  684. addr += 1;
  685. /* init hpc structure */
  686. hpc_ptr = alloc_ebda_hpc (slot_num, bus_num);
  687. if (!hpc_ptr ) {
  688. rc = -ENOMEM;
  689. goto error_no_hpc;
  690. }
  691. hpc_ptr->ctlr_id = ctlr_id;
  692. hpc_ptr->ctlr_relative_id = ctlr;
  693. hpc_ptr->slot_count = slot_num;
  694. hpc_ptr->bus_count = bus_num;
  695. debug ("now enter ctlr data struture ---\n");
  696. debug ("ctlr id: %x\n", ctlr_id);
  697. debug ("ctlr_relative_id: %x\n", hpc_ptr->ctlr_relative_id);
  698. debug ("count of slots controlled by this ctlr: %x\n", slot_num);
  699. debug ("count of buses controlled by this ctlr: %x\n", bus_num);
  700. /* init slot structure, fetch slot, bus, cap... */
  701. slot_ptr = hpc_ptr->slots;
  702. for (slot = 0; slot < slot_num; slot++) {
  703. slot_ptr->slot_num = readb (io_mem + addr_slot);
  704. slot_ptr->slot_bus_num = readb (io_mem + addr_slot + slot_num);
  705. slot_ptr->ctl_index = readb (io_mem + addr_slot + 2*slot_num);
  706. slot_ptr->slot_cap = readb (io_mem + addr_slot + 3*slot_num);
  707. // create bus_info lined list --- if only one slot per bus: slot_min = slot_max
  708. bus_info_ptr2 = ibmphp_find_same_bus_num (slot_ptr->slot_bus_num);
  709. if (!bus_info_ptr2) {
  710. bus_info_ptr1 = kzalloc(sizeof(struct bus_info), GFP_KERNEL);
  711. if (!bus_info_ptr1) {
  712. rc = -ENOMEM;
  713. goto error_no_hp_slot;
  714. }
  715. bus_info_ptr1->slot_min = slot_ptr->slot_num;
  716. bus_info_ptr1->slot_max = slot_ptr->slot_num;
  717. bus_info_ptr1->slot_count += 1;
  718. bus_info_ptr1->busno = slot_ptr->slot_bus_num;
  719. bus_info_ptr1->index = bus_index++;
  720. bus_info_ptr1->current_speed = 0xff;
  721. bus_info_ptr1->current_bus_mode = 0xff;
  722. bus_info_ptr1->controller_id = hpc_ptr->ctlr_id;
  723. list_add_tail (&bus_info_ptr1->bus_info_list, &bus_info_head);
  724. } else {
  725. bus_info_ptr2->slot_min = min (bus_info_ptr2->slot_min, slot_ptr->slot_num);
  726. bus_info_ptr2->slot_max = max (bus_info_ptr2->slot_max, slot_ptr->slot_num);
  727. bus_info_ptr2->slot_count += 1;
  728. }
  729. // end of creating the bus_info linked list
  730. slot_ptr++;
  731. addr_slot += 1;
  732. }
  733. /* init bus structure */
  734. bus_ptr = hpc_ptr->buses;
  735. for (bus = 0; bus < bus_num; bus++) {
  736. bus_ptr->bus_num = readb (io_mem + addr_bus + bus);
  737. bus_ptr->slots_at_33_conv = readb (io_mem + addr_bus + bus_num + 8 * bus);
  738. bus_ptr->slots_at_66_conv = readb (io_mem + addr_bus + bus_num + 8 * bus + 1);
  739. bus_ptr->slots_at_66_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 2);
  740. bus_ptr->slots_at_100_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 3);
  741. bus_ptr->slots_at_133_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 4);
  742. bus_info_ptr2 = ibmphp_find_same_bus_num (bus_ptr->bus_num);
  743. if (bus_info_ptr2) {
  744. bus_info_ptr2->slots_at_33_conv = bus_ptr->slots_at_33_conv;
  745. bus_info_ptr2->slots_at_66_conv = bus_ptr->slots_at_66_conv;
  746. bus_info_ptr2->slots_at_66_pcix = bus_ptr->slots_at_66_pcix;
  747. bus_info_ptr2->slots_at_100_pcix = bus_ptr->slots_at_100_pcix;
  748. bus_info_ptr2->slots_at_133_pcix = bus_ptr->slots_at_133_pcix;
  749. }
  750. bus_ptr++;
  751. }
  752. hpc_ptr->ctlr_type = temp;
  753. switch (hpc_ptr->ctlr_type) {
  754. case 1:
  755. hpc_ptr->u.pci_ctlr.bus = readb (io_mem + addr);
  756. hpc_ptr->u.pci_ctlr.dev_fun = readb (io_mem + addr + 1);
  757. hpc_ptr->irq = readb (io_mem + addr + 2);
  758. addr += 3;
  759. debug ("ctrl bus = %x, ctlr devfun = %x, irq = %x\n",
  760. hpc_ptr->u.pci_ctlr.bus,
  761. hpc_ptr->u.pci_ctlr.dev_fun, hpc_ptr->irq);
  762. break;
  763. case 0:
  764. hpc_ptr->u.isa_ctlr.io_start = readw (io_mem + addr);
  765. hpc_ptr->u.isa_ctlr.io_end = readw (io_mem + addr + 2);
  766. if (!request_region (hpc_ptr->u.isa_ctlr.io_start,
  767. (hpc_ptr->u.isa_ctlr.io_end - hpc_ptr->u.isa_ctlr.io_start + 1),
  768. "ibmphp")) {
  769. rc = -ENODEV;
  770. goto error_no_hp_slot;
  771. }
  772. hpc_ptr->irq = readb (io_mem + addr + 4);
  773. addr += 5;
  774. break;
  775. case 2:
  776. case 4:
  777. hpc_ptr->u.wpeg_ctlr.wpegbbar = readl (io_mem + addr);
  778. hpc_ptr->u.wpeg_ctlr.i2c_addr = readb (io_mem + addr + 4);
  779. hpc_ptr->irq = readb (io_mem + addr + 5);
  780. addr += 6;
  781. break;
  782. default:
  783. rc = -ENODEV;
  784. goto error_no_hp_slot;
  785. }
  786. //reorganize chassis' linked list
  787. combine_wpg_for_chassis ();
  788. combine_wpg_for_expansion ();
  789. hpc_ptr->revision = 0xff;
  790. hpc_ptr->options = 0xff;
  791. hpc_ptr->starting_slot_num = hpc_ptr->slots[0].slot_num;
  792. hpc_ptr->ending_slot_num = hpc_ptr->slots[slot_num-1].slot_num;
  793. // register slots with hpc core as well as create linked list of ibm slot
  794. for (index = 0; index < hpc_ptr->slot_count; index++) {
  795. hp_slot_ptr = kzalloc(sizeof(*hp_slot_ptr), GFP_KERNEL);
  796. if (!hp_slot_ptr) {
  797. rc = -ENOMEM;
  798. goto error_no_hp_slot;
  799. }
  800. hp_slot_ptr->info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
  801. if (!hp_slot_ptr->info) {
  802. rc = -ENOMEM;
  803. goto error_no_hp_info;
  804. }
  805. hp_slot_ptr->name = kmalloc(30, GFP_KERNEL);
  806. if (!hp_slot_ptr->name) {
  807. rc = -ENOMEM;
  808. goto error_no_hp_name;
  809. }
  810. tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL);
  811. if (!tmp_slot) {
  812. rc = -ENOMEM;
  813. goto error_no_slot;
  814. }
  815. tmp_slot->flag = 1;
  816. tmp_slot->capabilities = hpc_ptr->slots[index].slot_cap;
  817. if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_133_MAX) == EBDA_SLOT_133_MAX)
  818. tmp_slot->supported_speed = 3;
  819. else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_100_MAX) == EBDA_SLOT_100_MAX)
  820. tmp_slot->supported_speed = 2;
  821. else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_66_MAX) == EBDA_SLOT_66_MAX)
  822. tmp_slot->supported_speed = 1;
  823. if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_PCIX_CAP) == EBDA_SLOT_PCIX_CAP)
  824. tmp_slot->supported_bus_mode = 1;
  825. else
  826. tmp_slot->supported_bus_mode = 0;
  827. tmp_slot->bus = hpc_ptr->slots[index].slot_bus_num;
  828. bus_info_ptr1 = ibmphp_find_same_bus_num (hpc_ptr->slots[index].slot_bus_num);
  829. if (!bus_info_ptr1) {
  830. kfree(tmp_slot);
  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. }