ibmphp_ebda.c 34 KB

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