ibmphp_ebda.c 37 KB

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