ibmphp_ebda.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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. rc = -ENODEV;
  831. goto error;
  832. }
  833. tmp_slot->bus_on = bus_info_ptr1;
  834. bus_info_ptr1 = NULL;
  835. tmp_slot->ctrl = hpc_ptr;
  836. tmp_slot->ctlr_index = hpc_ptr->slots[index].ctl_index;
  837. tmp_slot->number = hpc_ptr->slots[index].slot_num;
  838. tmp_slot->hotplug_slot = hp_slot_ptr;
  839. hp_slot_ptr->private = tmp_slot;
  840. hp_slot_ptr->release = release_slot;
  841. rc = fillslotinfo(hp_slot_ptr);
  842. if (rc)
  843. goto error;
  844. rc = ibmphp_init_devno ((struct slot **) &hp_slot_ptr->private);
  845. if (rc)
  846. goto error;
  847. hp_slot_ptr->ops = &ibmphp_hotplug_slot_ops;
  848. // end of registering ibm slot with hotplug core
  849. list_add (& ((struct slot *)(hp_slot_ptr->private))->ibm_slot_list, &ibmphp_slot_head);
  850. }
  851. print_bus_info ();
  852. list_add (&hpc_ptr->ebda_hpc_list, &ebda_hpc_head );
  853. } /* each hpc */
  854. list_for_each (list, &ibmphp_slot_head) {
  855. tmp_slot = list_entry (list, struct slot, ibm_slot_list);
  856. snprintf (tmp_slot->hotplug_slot->name, 30, "%s", create_file_name (tmp_slot));
  857. pci_hp_register (tmp_slot->hotplug_slot);
  858. }
  859. print_ebda_hpc ();
  860. print_ibm_slot ();
  861. return 0;
  862. error:
  863. kfree (hp_slot_ptr->private);
  864. error_no_slot:
  865. kfree (hp_slot_ptr->name);
  866. error_no_hp_name:
  867. kfree (hp_slot_ptr->info);
  868. error_no_hp_info:
  869. kfree (hp_slot_ptr);
  870. error_no_hp_slot:
  871. free_ebda_hpc (hpc_ptr);
  872. error_no_hpc:
  873. iounmap (io_mem);
  874. return rc;
  875. }
  876. /*
  877. * map info (bus, devfun, start addr, end addr..) of i/o, memory,
  878. * pfm from the physical addr to a list of resource.
  879. */
  880. static int __init ebda_rsrc_rsrc (void)
  881. {
  882. u16 addr;
  883. short rsrc;
  884. u8 type, rsrc_type;
  885. struct ebda_pci_rsrc *rsrc_ptr;
  886. addr = rsrc_list_ptr->phys_addr;
  887. debug ("now entering rsrc land\n");
  888. debug ("offset of rsrc: %x\n", rsrc_list_ptr->phys_addr);
  889. for (rsrc = 0; rsrc < rsrc_list_ptr->num_entries; rsrc++) {
  890. type = readb (io_mem + addr);
  891. addr += 1;
  892. rsrc_type = type & EBDA_RSRC_TYPE_MASK;
  893. if (rsrc_type == EBDA_IO_RSRC_TYPE) {
  894. rsrc_ptr = alloc_ebda_pci_rsrc ();
  895. if (!rsrc_ptr) {
  896. iounmap (io_mem);
  897. return -ENOMEM;
  898. }
  899. rsrc_ptr->rsrc_type = type;
  900. rsrc_ptr->bus_num = readb (io_mem + addr);
  901. rsrc_ptr->dev_fun = readb (io_mem + addr + 1);
  902. rsrc_ptr->start_addr = readw (io_mem + addr + 2);
  903. rsrc_ptr->end_addr = readw (io_mem + addr + 4);
  904. addr += 6;
  905. debug ("rsrc from io type ----\n");
  906. debug ("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
  907. rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr);
  908. list_add (&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head);
  909. }
  910. if (rsrc_type == EBDA_MEM_RSRC_TYPE || rsrc_type == EBDA_PFM_RSRC_TYPE) {
  911. rsrc_ptr = alloc_ebda_pci_rsrc ();
  912. if (!rsrc_ptr ) {
  913. iounmap (io_mem);
  914. return -ENOMEM;
  915. }
  916. rsrc_ptr->rsrc_type = type;
  917. rsrc_ptr->bus_num = readb (io_mem + addr);
  918. rsrc_ptr->dev_fun = readb (io_mem + addr + 1);
  919. rsrc_ptr->start_addr = readl (io_mem + addr + 2);
  920. rsrc_ptr->end_addr = readl (io_mem + addr + 6);
  921. addr += 10;
  922. debug ("rsrc from mem or pfm ---\n");
  923. debug ("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
  924. rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr);
  925. list_add (&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head);
  926. }
  927. }
  928. kfree (rsrc_list_ptr);
  929. rsrc_list_ptr = NULL;
  930. print_ebda_pci_rsrc ();
  931. return 0;
  932. }
  933. u16 ibmphp_get_total_controllers (void)
  934. {
  935. return hpc_list_ptr->num_ctlrs;
  936. }
  937. struct slot *ibmphp_get_slot_from_physical_num (u8 physical_num)
  938. {
  939. struct slot *slot;
  940. struct list_head *list;
  941. list_for_each (list, &ibmphp_slot_head) {
  942. slot = list_entry (list, struct slot, ibm_slot_list);
  943. if (slot->number == physical_num)
  944. return slot;
  945. }
  946. return NULL;
  947. }
  948. /* To find:
  949. * - the smallest slot number
  950. * - the largest slot number
  951. * - the total number of the slots based on each bus
  952. * (if only one slot per bus slot_min = slot_max )
  953. */
  954. struct bus_info *ibmphp_find_same_bus_num (u32 num)
  955. {
  956. struct bus_info *ptr;
  957. struct list_head *ptr1;
  958. list_for_each (ptr1, &bus_info_head) {
  959. ptr = list_entry (ptr1, struct bus_info, bus_info_list);
  960. if (ptr->busno == num)
  961. return ptr;
  962. }
  963. return NULL;
  964. }
  965. /* Finding relative bus number, in order to map corresponding
  966. * bus register
  967. */
  968. int ibmphp_get_bus_index (u8 num)
  969. {
  970. struct bus_info *ptr;
  971. struct list_head *ptr1;
  972. list_for_each (ptr1, &bus_info_head) {
  973. ptr = list_entry (ptr1, struct bus_info, bus_info_list);
  974. if (ptr->busno == num)
  975. return ptr->index;
  976. }
  977. return -ENODEV;
  978. }
  979. void ibmphp_free_bus_info_queue (void)
  980. {
  981. struct bus_info *bus_info;
  982. struct list_head *list;
  983. struct list_head *next;
  984. list_for_each_safe (list, next, &bus_info_head ) {
  985. bus_info = list_entry (list, struct bus_info, bus_info_list);
  986. kfree (bus_info);
  987. }
  988. }
  989. void ibmphp_free_ebda_hpc_queue (void)
  990. {
  991. struct controller *controller = NULL;
  992. struct list_head *list;
  993. struct list_head *next;
  994. int pci_flag = 0;
  995. list_for_each_safe (list, next, &ebda_hpc_head) {
  996. controller = list_entry (list, struct controller, ebda_hpc_list);
  997. if (controller->ctlr_type == 0)
  998. release_region (controller->u.isa_ctlr.io_start, (controller->u.isa_ctlr.io_end - controller->u.isa_ctlr.io_start + 1));
  999. else if ((controller->ctlr_type == 1) && (!pci_flag)) {
  1000. ++pci_flag;
  1001. pci_unregister_driver (&ibmphp_driver);
  1002. }
  1003. free_ebda_hpc (controller);
  1004. }
  1005. }
  1006. void ibmphp_free_ebda_pci_rsrc_queue (void)
  1007. {
  1008. struct ebda_pci_rsrc *resource;
  1009. struct list_head *list;
  1010. struct list_head *next;
  1011. list_for_each_safe (list, next, &ibmphp_ebda_pci_rsrc_head) {
  1012. resource = list_entry (list, struct ebda_pci_rsrc, ebda_pci_rsrc_list);
  1013. kfree (resource);
  1014. resource = NULL;
  1015. }
  1016. }
  1017. static struct pci_device_id id_table[] = {
  1018. {
  1019. .vendor = PCI_VENDOR_ID_IBM,
  1020. .device = HPC_DEVICE_ID,
  1021. .subvendor = PCI_VENDOR_ID_IBM,
  1022. .subdevice = HPC_SUBSYSTEM_ID,
  1023. .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00),
  1024. }, {}
  1025. };
  1026. MODULE_DEVICE_TABLE(pci, id_table);
  1027. static int ibmphp_probe (struct pci_dev *, const struct pci_device_id *);
  1028. static struct pci_driver ibmphp_driver = {
  1029. .name = "ibmphp",
  1030. .id_table = id_table,
  1031. .probe = ibmphp_probe,
  1032. };
  1033. int ibmphp_register_pci (void)
  1034. {
  1035. struct controller *ctrl;
  1036. struct list_head *tmp;
  1037. int rc = 0;
  1038. list_for_each (tmp, &ebda_hpc_head) {
  1039. ctrl = list_entry (tmp, struct controller, ebda_hpc_list);
  1040. if (ctrl->ctlr_type == 1) {
  1041. rc = pci_register_driver(&ibmphp_driver);
  1042. break;
  1043. }
  1044. }
  1045. return rc;
  1046. }
  1047. static int ibmphp_probe (struct pci_dev * dev, const struct pci_device_id *ids)
  1048. {
  1049. struct controller *ctrl;
  1050. struct list_head *tmp;
  1051. debug ("inside ibmphp_probe\n");
  1052. list_for_each (tmp, &ebda_hpc_head) {
  1053. ctrl = list_entry (tmp, struct controller, ebda_hpc_list);
  1054. if (ctrl->ctlr_type == 1) {
  1055. if ((dev->devfn == ctrl->u.pci_ctlr.dev_fun) && (dev->bus->number == ctrl->u.pci_ctlr.bus)) {
  1056. ctrl->ctrl_dev = dev;
  1057. debug ("found device!!!\n");
  1058. debug ("dev->device = %x, dev->subsystem_device = %x\n", dev->device, dev->subsystem_device);
  1059. return 0;
  1060. }
  1061. }
  1062. }
  1063. return -ENODEV;
  1064. }