ibmphp_ebda.c 33 KB

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