ibmphp_ebda.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  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", __func__, ptr->slot_min);
  115. debug ("%s - slot_max = %x\n", __func__, ptr->slot_max);
  116. debug ("%s - slot_count = %x\n", __func__, ptr->slot_count);
  117. debug ("%s - bus# = %x\n", __func__, ptr->busno);
  118. debug ("%s - current_speed = %x\n", __func__, ptr->current_speed);
  119. debug ("%s - controller_id = %x\n", __func__, ptr->controller_id);
  120. debug ("%s - slots_at_33_conv = %x\n", __func__, ptr->slots_at_33_conv);
  121. debug ("%s - slots_at_66_conv = %x\n", __func__, ptr->slots_at_66_conv);
  122. debug ("%s - slots_at_66_pcix = %x\n", __func__, ptr->slots_at_66_pcix);
  123. debug ("%s - slots_at_100_pcix = %x\n", __func__, ptr->slots_at_100_pcix);
  124. debug ("%s - slots_at_133_pcix = %x\n", __func__, 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", __func__, ptr->rio_node_id);
  135. debug ("%s - rio_type = %x\n", __func__, ptr->rio_type);
  136. debug ("%s - owner_id = %x\n", __func__, ptr->owner_id);
  137. debug ("%s - first_slot_num = %x\n", __func__, ptr->first_slot_num);
  138. debug ("%s - wpindex = %x\n", __func__, ptr->wpindex);
  139. debug ("%s - chassis_num = %x\n", __func__, 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", __func__);
  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", __func__, ptr->rio_node_id);
  150. debug ("%s - rio_type = %x\n", __func__, ptr->rio_type);
  151. debug ("%s - owner_id = %x\n", __func__, ptr->owner_id);
  152. debug ("%s - first_slot_num = %x\n", __func__, ptr->first_slot_num);
  153. debug ("%s - wpindex = %x\n", __func__, ptr->wpindex);
  154. debug ("%s - chassis_num = %x\n", __func__, 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. __func__, 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", __func__, 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", __func__);
  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", __func__, ptr->rio_type);
  184. debug ("%s - chassis_num: %x\n", __func__, ptr->chassis_num);
  185. debug ("%s - first_slot_num: %x\n", __func__, ptr->first_slot_num);
  186. debug ("%s - middle_num: %x\n", __func__, 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", __func__, hpc_ptr->slots[index].slot_num);
  198. debug ("%s - pci bus# of the slot: %x\n", __func__, hpc_ptr->slots[index].slot_bus_num);
  199. debug ("%s - index into ctlr addr: %x\n", __func__, hpc_ptr->slots[index].ctl_index);
  200. debug ("%s - cap of the slot: %x\n", __func__, 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", __func__, hpc_ptr->buses[index].bus_num);
  204. }
  205. debug ("%s - type of hpc: %x\n", __func__, hpc_ptr->ctlr_type);
  206. switch (hpc_ptr->ctlr_type) {
  207. case 1:
  208. debug ("%s - bus: %x\n", __func__, hpc_ptr->u.pci_ctlr.bus);
  209. debug ("%s - dev_fun: %x\n", __func__, hpc_ptr->u.pci_ctlr.dev_fun);
  210. debug ("%s - irq: %x\n", __func__, hpc_ptr->irq);
  211. break;
  212. case 0:
  213. debug ("%s - io_start: %x\n", __func__, hpc_ptr->u.isa_ctlr.io_start);
  214. debug ("%s - io_end: %x\n", __func__, hpc_ptr->u.isa_ctlr.io_end);
  215. debug ("%s - irq: %x\n", __func__, hpc_ptr->irq);
  216. break;
  217. case 2:
  218. case 4:
  219. debug ("%s - wpegbbar: %lx\n", __func__, hpc_ptr->u.wpeg_ctlr.wpegbbar);
  220. debug ("%s - i2c_addr: %x\n", __func__, hpc_ptr->u.wpeg_ctlr.i2c_addr);
  221. debug ("%s - irq: %x\n", __func__, 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, 1024);
  240. if (!io_mem )
  241. return -ENOMEM;
  242. next_offset = 0x180;
  243. for (;;) {
  244. offset = next_offset;
  245. next_offset = readw (io_mem + offset); /* offset of next blk */
  246. offset += 2;
  247. if (next_offset == 0) /* 0 indicate it's last blk */
  248. break;
  249. blk_id = readw (io_mem + offset); /* this blk id */
  250. offset += 2;
  251. /* check if it is hot swap block or rio block */
  252. if (blk_id != 0x4853 && blk_id != 0x4752)
  253. continue;
  254. /* found hs table */
  255. if (blk_id == 0x4853) {
  256. debug ("now enter hot swap block---\n");
  257. debug ("hot blk id: %x\n", blk_id);
  258. format = readb (io_mem + offset);
  259. offset += 1;
  260. if (format != 4)
  261. goto error_nodev;
  262. debug ("hot blk format: %x\n", format);
  263. /* hot swap sub blk */
  264. base = offset;
  265. sub_addr = base;
  266. re = readw (io_mem + sub_addr); /* next sub blk */
  267. sub_addr += 2;
  268. rc_id = readw (io_mem + sub_addr); /* sub blk id */
  269. sub_addr += 2;
  270. if (rc_id != 0x5243)
  271. goto error_nodev;
  272. /* rc sub blk signature */
  273. num_ctlrs = readb (io_mem + sub_addr);
  274. sub_addr += 1;
  275. hpc_list_ptr = alloc_ebda_hpc_list ();
  276. if (!hpc_list_ptr) {
  277. rc = -ENOMEM;
  278. goto out;
  279. }
  280. hpc_list_ptr->format = format;
  281. hpc_list_ptr->num_ctlrs = num_ctlrs;
  282. hpc_list_ptr->phys_addr = sub_addr; /* offset of RSRC_CONTROLLER blk */
  283. debug ("info about hpc descriptor---\n");
  284. debug ("hot blk format: %x\n", format);
  285. debug ("num of controller: %x\n", num_ctlrs);
  286. debug ("offset of hpc data structure enteries: %x\n ", sub_addr);
  287. sub_addr = base + re; /* re sub blk */
  288. /* FIXME: rc is never used/checked */
  289. rc = readw (io_mem + sub_addr); /* next sub blk */
  290. sub_addr += 2;
  291. re_id = readw (io_mem + sub_addr); /* sub blk id */
  292. sub_addr += 2;
  293. if (re_id != 0x5245)
  294. goto error_nodev;
  295. /* signature of re */
  296. num_entries = readw (io_mem + sub_addr);
  297. sub_addr += 2; /* offset of RSRC_ENTRIES blk */
  298. rsrc_list_ptr = alloc_ebda_rsrc_list ();
  299. if (!rsrc_list_ptr ) {
  300. rc = -ENOMEM;
  301. goto out;
  302. }
  303. rsrc_list_ptr->format = format;
  304. rsrc_list_ptr->num_entries = num_entries;
  305. rsrc_list_ptr->phys_addr = sub_addr;
  306. debug ("info about rsrc descriptor---\n");
  307. debug ("format: %x\n", format);
  308. debug ("num of rsrc: %x\n", num_entries);
  309. debug ("offset of rsrc data structure enteries: %x\n ", sub_addr);
  310. hs_complete = 1;
  311. } else {
  312. /* found rio table, blk_id == 0x4752 */
  313. debug ("now enter io table ---\n");
  314. debug ("rio blk id: %x\n", blk_id);
  315. rio_table_ptr = kzalloc(sizeof(struct rio_table_hdr), GFP_KERNEL);
  316. if (!rio_table_ptr)
  317. return -ENOMEM;
  318. rio_table_ptr->ver_num = readb (io_mem + offset);
  319. rio_table_ptr->scal_count = readb (io_mem + offset + 1);
  320. rio_table_ptr->riodev_count = readb (io_mem + offset + 2);
  321. rio_table_ptr->offset = offset +3 ;
  322. debug("info about rio table hdr ---\n");
  323. debug("ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ",
  324. rio_table_ptr->ver_num, rio_table_ptr->scal_count,
  325. rio_table_ptr->riodev_count, rio_table_ptr->offset);
  326. rio_complete = 1;
  327. }
  328. }
  329. if (!hs_complete && !rio_complete)
  330. goto error_nodev;
  331. if (rio_table_ptr) {
  332. if (rio_complete && rio_table_ptr->ver_num == 3) {
  333. rc = ebda_rio_table ();
  334. if (rc)
  335. goto out;
  336. }
  337. }
  338. rc = ebda_rsrc_controller ();
  339. if (rc)
  340. goto out;
  341. rc = ebda_rsrc_rsrc ();
  342. goto out;
  343. error_nodev:
  344. rc = -ENODEV;
  345. out:
  346. iounmap (io_mem);
  347. return rc;
  348. }
  349. /*
  350. * map info of scalability details and rio details from physical address
  351. */
  352. static int __init ebda_rio_table (void)
  353. {
  354. u16 offset;
  355. u8 i;
  356. struct rio_detail *rio_detail_ptr;
  357. offset = rio_table_ptr->offset;
  358. offset += 12 * rio_table_ptr->scal_count;
  359. // we do concern about rio details
  360. for (i = 0; i < rio_table_ptr->riodev_count; i++) {
  361. rio_detail_ptr = kzalloc(sizeof(struct rio_detail), GFP_KERNEL);
  362. if (!rio_detail_ptr)
  363. return -ENOMEM;
  364. rio_detail_ptr->rio_node_id = readb (io_mem + offset);
  365. rio_detail_ptr->bbar = readl (io_mem + offset + 1);
  366. rio_detail_ptr->rio_type = readb (io_mem + offset + 5);
  367. rio_detail_ptr->owner_id = readb (io_mem + offset + 6);
  368. rio_detail_ptr->port0_node_connect = readb (io_mem + offset + 7);
  369. rio_detail_ptr->port0_port_connect = readb (io_mem + offset + 8);
  370. rio_detail_ptr->port1_node_connect = readb (io_mem + offset + 9);
  371. rio_detail_ptr->port1_port_connect = readb (io_mem + offset + 10);
  372. rio_detail_ptr->first_slot_num = readb (io_mem + offset + 11);
  373. rio_detail_ptr->status = readb (io_mem + offset + 12);
  374. rio_detail_ptr->wpindex = readb (io_mem + offset + 13);
  375. rio_detail_ptr->chassis_num = readb (io_mem + offset + 14);
  376. // debug ("rio_node_id: %x\nbbar: %x\nrio_type: %x\nowner_id: %x\nport0_node: %x\nport0_port: %x\nport1_node: %x\nport1_port: %x\nfirst_slot_num: %x\nstatus: %x\n", rio_detail_ptr->rio_node_id, rio_detail_ptr->bbar, rio_detail_ptr->rio_type, rio_detail_ptr->owner_id, rio_detail_ptr->port0_node_connect, rio_detail_ptr->port0_port_connect, rio_detail_ptr->port1_node_connect, rio_detail_ptr->port1_port_connect, rio_detail_ptr->first_slot_num, rio_detail_ptr->status);
  377. //create linked list of chassis
  378. if (rio_detail_ptr->rio_type == 4 || rio_detail_ptr->rio_type == 5)
  379. list_add (&rio_detail_ptr->rio_detail_list, &rio_vg_head);
  380. //create linked list of expansion box
  381. else if (rio_detail_ptr->rio_type == 6 || rio_detail_ptr->rio_type == 7)
  382. list_add (&rio_detail_ptr->rio_detail_list, &rio_lo_head);
  383. else
  384. // not in my concern
  385. kfree (rio_detail_ptr);
  386. offset += 15;
  387. }
  388. print_lo_info ();
  389. print_vg_info ();
  390. return 0;
  391. }
  392. /*
  393. * reorganizing linked list of chassis
  394. */
  395. static struct opt_rio *search_opt_vg (u8 chassis_num)
  396. {
  397. struct opt_rio *ptr;
  398. struct list_head *ptr1;
  399. list_for_each (ptr1, &opt_vg_head) {
  400. ptr = list_entry (ptr1, struct opt_rio, opt_rio_list);
  401. if (ptr->chassis_num == chassis_num)
  402. return ptr;
  403. }
  404. return NULL;
  405. }
  406. static int __init combine_wpg_for_chassis (void)
  407. {
  408. struct opt_rio *opt_rio_ptr = NULL;
  409. struct rio_detail *rio_detail_ptr = NULL;
  410. struct list_head *list_head_ptr = NULL;
  411. list_for_each (list_head_ptr, &rio_vg_head) {
  412. rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list);
  413. opt_rio_ptr = search_opt_vg (rio_detail_ptr->chassis_num);
  414. if (!opt_rio_ptr) {
  415. opt_rio_ptr = kzalloc(sizeof(struct opt_rio), GFP_KERNEL);
  416. if (!opt_rio_ptr)
  417. return -ENOMEM;
  418. opt_rio_ptr->rio_type = rio_detail_ptr->rio_type;
  419. opt_rio_ptr->chassis_num = rio_detail_ptr->chassis_num;
  420. opt_rio_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
  421. opt_rio_ptr->middle_num = rio_detail_ptr->first_slot_num;
  422. list_add (&opt_rio_ptr->opt_rio_list, &opt_vg_head);
  423. } else {
  424. opt_rio_ptr->first_slot_num = min (opt_rio_ptr->first_slot_num, rio_detail_ptr->first_slot_num);
  425. opt_rio_ptr->middle_num = max (opt_rio_ptr->middle_num, rio_detail_ptr->first_slot_num);
  426. }
  427. }
  428. print_opt_vg ();
  429. return 0;
  430. }
  431. /*
  432. * reorgnizing linked list of expansion box
  433. */
  434. static struct opt_rio_lo *search_opt_lo (u8 chassis_num)
  435. {
  436. struct opt_rio_lo *ptr;
  437. struct list_head *ptr1;
  438. list_for_each (ptr1, &opt_lo_head) {
  439. ptr = list_entry (ptr1, struct opt_rio_lo, opt_rio_lo_list);
  440. if (ptr->chassis_num == chassis_num)
  441. return ptr;
  442. }
  443. return NULL;
  444. }
  445. static int combine_wpg_for_expansion (void)
  446. {
  447. struct opt_rio_lo *opt_rio_lo_ptr = NULL;
  448. struct rio_detail *rio_detail_ptr = NULL;
  449. struct list_head *list_head_ptr = NULL;
  450. list_for_each (list_head_ptr, &rio_lo_head) {
  451. rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list);
  452. opt_rio_lo_ptr = search_opt_lo (rio_detail_ptr->chassis_num);
  453. if (!opt_rio_lo_ptr) {
  454. opt_rio_lo_ptr = kzalloc(sizeof(struct opt_rio_lo), GFP_KERNEL);
  455. if (!opt_rio_lo_ptr)
  456. return -ENOMEM;
  457. opt_rio_lo_ptr->rio_type = rio_detail_ptr->rio_type;
  458. opt_rio_lo_ptr->chassis_num = rio_detail_ptr->chassis_num;
  459. opt_rio_lo_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
  460. opt_rio_lo_ptr->middle_num = rio_detail_ptr->first_slot_num;
  461. opt_rio_lo_ptr->pack_count = 1;
  462. list_add (&opt_rio_lo_ptr->opt_rio_lo_list, &opt_lo_head);
  463. } else {
  464. opt_rio_lo_ptr->first_slot_num = min (opt_rio_lo_ptr->first_slot_num, rio_detail_ptr->first_slot_num);
  465. opt_rio_lo_ptr->middle_num = max (opt_rio_lo_ptr->middle_num, rio_detail_ptr->first_slot_num);
  466. opt_rio_lo_ptr->pack_count = 2;
  467. }
  468. }
  469. return 0;
  470. }
  471. /* Since we don't know the max slot number per each chassis, hence go
  472. * through the list of all chassis to find out the range
  473. * Arguments: slot_num, 1st slot number of the chassis we think we are on,
  474. * var (0 = chassis, 1 = expansion box)
  475. */
  476. static int first_slot_num (u8 slot_num, u8 first_slot, u8 var)
  477. {
  478. struct opt_rio *opt_vg_ptr = NULL;
  479. struct opt_rio_lo *opt_lo_ptr = NULL;
  480. struct list_head *ptr = NULL;
  481. int rc = 0;
  482. if (!var) {
  483. list_for_each (ptr, &opt_vg_head) {
  484. opt_vg_ptr = list_entry (ptr, struct opt_rio, opt_rio_list);
  485. if ((first_slot < opt_vg_ptr->first_slot_num) && (slot_num >= opt_vg_ptr->first_slot_num)) {
  486. rc = -ENODEV;
  487. break;
  488. }
  489. }
  490. } else {
  491. list_for_each (ptr, &opt_lo_head) {
  492. opt_lo_ptr = list_entry (ptr, struct opt_rio_lo, opt_rio_lo_list);
  493. if ((first_slot < opt_lo_ptr->first_slot_num) && (slot_num >= opt_lo_ptr->first_slot_num)) {
  494. rc = -ENODEV;
  495. break;
  496. }
  497. }
  498. }
  499. return rc;
  500. }
  501. static struct opt_rio_lo * find_rxe_num (u8 slot_num)
  502. {
  503. struct opt_rio_lo *opt_lo_ptr;
  504. struct list_head *ptr;
  505. list_for_each (ptr, &opt_lo_head) {
  506. opt_lo_ptr = list_entry (ptr, struct opt_rio_lo, opt_rio_lo_list);
  507. //check to see if this slot_num belongs to expansion box
  508. if ((slot_num >= opt_lo_ptr->first_slot_num) && (!first_slot_num (slot_num, opt_lo_ptr->first_slot_num, 1)))
  509. return opt_lo_ptr;
  510. }
  511. return NULL;
  512. }
  513. static struct opt_rio * find_chassis_num (u8 slot_num)
  514. {
  515. struct opt_rio *opt_vg_ptr;
  516. struct list_head *ptr;
  517. list_for_each (ptr, &opt_vg_head) {
  518. opt_vg_ptr = list_entry (ptr, struct opt_rio, opt_rio_list);
  519. //check to see if this slot_num belongs to chassis
  520. if ((slot_num >= opt_vg_ptr->first_slot_num) && (!first_slot_num (slot_num, opt_vg_ptr->first_slot_num, 0)))
  521. return opt_vg_ptr;
  522. }
  523. return NULL;
  524. }
  525. /* This routine will find out how many slots are in the chassis, so that
  526. * the slot numbers for rxe100 would start from 1, and not from 7, or 6 etc
  527. */
  528. static u8 calculate_first_slot (u8 slot_num)
  529. {
  530. u8 first_slot = 1;
  531. struct list_head * list;
  532. struct slot * slot_cur;
  533. list_for_each (list, &ibmphp_slot_head) {
  534. slot_cur = list_entry (list, struct slot, ibm_slot_list);
  535. if (slot_cur->ctrl) {
  536. if ((slot_cur->ctrl->ctlr_type != 4) && (slot_cur->ctrl->ending_slot_num > first_slot) && (slot_num > slot_cur->ctrl->ending_slot_num))
  537. first_slot = slot_cur->ctrl->ending_slot_num;
  538. }
  539. }
  540. return first_slot + 1;
  541. }
  542. static char *create_file_name (struct slot * slot_cur)
  543. {
  544. struct opt_rio *opt_vg_ptr = NULL;
  545. struct opt_rio_lo *opt_lo_ptr = NULL;
  546. static char str[30];
  547. int which = 0; /* rxe = 1, chassis = 0 */
  548. u8 number = 1; /* either chassis or rxe # */
  549. u8 first_slot = 1;
  550. u8 slot_num;
  551. u8 flag = 0;
  552. if (!slot_cur) {
  553. err ("Structure passed is empty\n");
  554. return NULL;
  555. }
  556. slot_num = slot_cur->number;
  557. memset (str, 0, sizeof(str));
  558. if (rio_table_ptr) {
  559. if (rio_table_ptr->ver_num == 3) {
  560. opt_vg_ptr = find_chassis_num (slot_num);
  561. opt_lo_ptr = find_rxe_num (slot_num);
  562. }
  563. }
  564. if (opt_vg_ptr) {
  565. if (opt_lo_ptr) {
  566. if ((slot_num - opt_vg_ptr->first_slot_num) > (slot_num - opt_lo_ptr->first_slot_num)) {
  567. number = opt_lo_ptr->chassis_num;
  568. first_slot = opt_lo_ptr->first_slot_num;
  569. which = 1; /* it is RXE */
  570. } else {
  571. first_slot = opt_vg_ptr->first_slot_num;
  572. number = opt_vg_ptr->chassis_num;
  573. which = 0;
  574. }
  575. } else {
  576. first_slot = opt_vg_ptr->first_slot_num;
  577. number = opt_vg_ptr->chassis_num;
  578. which = 0;
  579. }
  580. ++flag;
  581. } else if (opt_lo_ptr) {
  582. number = opt_lo_ptr->chassis_num;
  583. first_slot = opt_lo_ptr->first_slot_num;
  584. which = 1;
  585. ++flag;
  586. } else if (rio_table_ptr) {
  587. if (rio_table_ptr->ver_num == 3) {
  588. /* if both NULL and we DO have correct RIO table in BIOS */
  589. return NULL;
  590. }
  591. }
  592. if (!flag) {
  593. if (slot_cur->ctrl->ctlr_type == 4) {
  594. first_slot = calculate_first_slot (slot_num);
  595. which = 1;
  596. } else {
  597. which = 0;
  598. }
  599. }
  600. sprintf(str, "%s%dslot%d",
  601. which == 0 ? "chassis" : "rxe",
  602. number, slot_num - first_slot + 1);
  603. return str;
  604. }
  605. static int fillslotinfo(struct hotplug_slot *hotplug_slot)
  606. {
  607. struct slot *slot;
  608. int rc = 0;
  609. if (!hotplug_slot || !hotplug_slot->private)
  610. return -EINVAL;
  611. slot = hotplug_slot->private;
  612. rc = ibmphp_hpc_readslot(slot, READ_ALLSTAT, NULL);
  613. if (rc)
  614. return rc;
  615. // power - enabled:1 not:0
  616. hotplug_slot->info->power_status = SLOT_POWER(slot->status);
  617. // attention - off:0, on:1, blinking:2
  618. hotplug_slot->info->attention_status = SLOT_ATTN(slot->status, slot->ext_status);
  619. // latch - open:1 closed:0
  620. hotplug_slot->info->latch_status = SLOT_LATCH(slot->status);
  621. // pci board - present:1 not:0
  622. if (SLOT_PRESENT (slot->status))
  623. hotplug_slot->info->adapter_status = 1;
  624. else
  625. hotplug_slot->info->adapter_status = 0;
  626. /*
  627. if (slot->bus_on->supported_bus_mode
  628. && (slot->bus_on->supported_speed == BUS_SPEED_66))
  629. hotplug_slot->info->max_bus_speed_status = BUS_SPEED_66PCIX;
  630. else
  631. hotplug_slot->info->max_bus_speed_status = slot->bus_on->supported_speed;
  632. */
  633. return rc;
  634. }
  635. static void release_slot(struct hotplug_slot *hotplug_slot)
  636. {
  637. struct slot *slot;
  638. if (!hotplug_slot || !hotplug_slot->private)
  639. return;
  640. slot = hotplug_slot->private;
  641. kfree(slot->hotplug_slot->info);
  642. kfree(slot->hotplug_slot->name);
  643. kfree(slot->hotplug_slot);
  644. slot->ctrl = NULL;
  645. slot->bus_on = NULL;
  646. /* we don't want to actually remove the resources, since free_resources will do just that */
  647. ibmphp_unconfigure_card(&slot, -1);
  648. kfree (slot);
  649. }
  650. static struct pci_driver ibmphp_driver;
  651. /*
  652. * map info (ctlr-id, slot count, slot#.. bus count, bus#, ctlr type...) of
  653. * each hpc from physical address to a list of hot plug controllers based on
  654. * hpc descriptors.
  655. */
  656. static int __init ebda_rsrc_controller (void)
  657. {
  658. u16 addr, addr_slot, addr_bus;
  659. u8 ctlr_id, temp, bus_index;
  660. u16 ctlr, slot, bus;
  661. u16 slot_num, bus_num, index;
  662. struct hotplug_slot *hp_slot_ptr;
  663. struct controller *hpc_ptr;
  664. struct ebda_hpc_bus *bus_ptr;
  665. struct ebda_hpc_slot *slot_ptr;
  666. struct bus_info *bus_info_ptr1, *bus_info_ptr2;
  667. int rc;
  668. struct slot *tmp_slot;
  669. struct list_head *list;
  670. addr = hpc_list_ptr->phys_addr;
  671. for (ctlr = 0; ctlr < hpc_list_ptr->num_ctlrs; ctlr++) {
  672. bus_index = 1;
  673. ctlr_id = readb (io_mem + addr);
  674. addr += 1;
  675. slot_num = readb (io_mem + addr);
  676. addr += 1;
  677. addr_slot = addr; /* offset of slot structure */
  678. addr += (slot_num * 4);
  679. bus_num = readb (io_mem + addr);
  680. addr += 1;
  681. addr_bus = addr; /* offset of bus */
  682. addr += (bus_num * 9); /* offset of ctlr_type */
  683. temp = readb (io_mem + addr);
  684. addr += 1;
  685. /* init hpc structure */
  686. hpc_ptr = alloc_ebda_hpc (slot_num, bus_num);
  687. if (!hpc_ptr ) {
  688. rc = -ENOMEM;
  689. goto error_no_hpc;
  690. }
  691. hpc_ptr->ctlr_id = ctlr_id;
  692. hpc_ptr->ctlr_relative_id = ctlr;
  693. hpc_ptr->slot_count = slot_num;
  694. hpc_ptr->bus_count = bus_num;
  695. debug ("now enter ctlr data struture ---\n");
  696. debug ("ctlr id: %x\n", ctlr_id);
  697. debug ("ctlr_relative_id: %x\n", hpc_ptr->ctlr_relative_id);
  698. debug ("count of slots controlled by this ctlr: %x\n", slot_num);
  699. debug ("count of buses controlled by this ctlr: %x\n", bus_num);
  700. /* init slot structure, fetch slot, bus, cap... */
  701. slot_ptr = hpc_ptr->slots;
  702. for (slot = 0; slot < slot_num; slot++) {
  703. slot_ptr->slot_num = readb (io_mem + addr_slot);
  704. slot_ptr->slot_bus_num = readb (io_mem + addr_slot + slot_num);
  705. slot_ptr->ctl_index = readb (io_mem + addr_slot + 2*slot_num);
  706. slot_ptr->slot_cap = readb (io_mem + addr_slot + 3*slot_num);
  707. // create bus_info lined list --- if only one slot per bus: slot_min = slot_max
  708. bus_info_ptr2 = ibmphp_find_same_bus_num (slot_ptr->slot_bus_num);
  709. if (!bus_info_ptr2) {
  710. bus_info_ptr1 = kzalloc(sizeof(struct bus_info), GFP_KERNEL);
  711. if (!bus_info_ptr1) {
  712. rc = -ENOMEM;
  713. goto error_no_hp_slot;
  714. }
  715. bus_info_ptr1->slot_min = slot_ptr->slot_num;
  716. bus_info_ptr1->slot_max = slot_ptr->slot_num;
  717. bus_info_ptr1->slot_count += 1;
  718. bus_info_ptr1->busno = slot_ptr->slot_bus_num;
  719. bus_info_ptr1->index = bus_index++;
  720. bus_info_ptr1->current_speed = 0xff;
  721. bus_info_ptr1->current_bus_mode = 0xff;
  722. bus_info_ptr1->controller_id = hpc_ptr->ctlr_id;
  723. list_add_tail (&bus_info_ptr1->bus_info_list, &bus_info_head);
  724. } else {
  725. bus_info_ptr2->slot_min = min (bus_info_ptr2->slot_min, slot_ptr->slot_num);
  726. bus_info_ptr2->slot_max = max (bus_info_ptr2->slot_max, slot_ptr->slot_num);
  727. bus_info_ptr2->slot_count += 1;
  728. }
  729. // end of creating the bus_info linked list
  730. slot_ptr++;
  731. addr_slot += 1;
  732. }
  733. /* init bus structure */
  734. bus_ptr = hpc_ptr->buses;
  735. for (bus = 0; bus < bus_num; bus++) {
  736. bus_ptr->bus_num = readb (io_mem + addr_bus + bus);
  737. bus_ptr->slots_at_33_conv = readb (io_mem + addr_bus + bus_num + 8 * bus);
  738. bus_ptr->slots_at_66_conv = readb (io_mem + addr_bus + bus_num + 8 * bus + 1);
  739. bus_ptr->slots_at_66_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 2);
  740. bus_ptr->slots_at_100_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 3);
  741. bus_ptr->slots_at_133_pcix = readb (io_mem + addr_bus + bus_num + 8 * bus + 4);
  742. bus_info_ptr2 = ibmphp_find_same_bus_num (bus_ptr->bus_num);
  743. if (bus_info_ptr2) {
  744. bus_info_ptr2->slots_at_33_conv = bus_ptr->slots_at_33_conv;
  745. bus_info_ptr2->slots_at_66_conv = bus_ptr->slots_at_66_conv;
  746. bus_info_ptr2->slots_at_66_pcix = bus_ptr->slots_at_66_pcix;
  747. bus_info_ptr2->slots_at_100_pcix = bus_ptr->slots_at_100_pcix;
  748. bus_info_ptr2->slots_at_133_pcix = bus_ptr->slots_at_133_pcix;
  749. }
  750. bus_ptr++;
  751. }
  752. hpc_ptr->ctlr_type = temp;
  753. switch (hpc_ptr->ctlr_type) {
  754. case 1:
  755. hpc_ptr->u.pci_ctlr.bus = readb (io_mem + addr);
  756. hpc_ptr->u.pci_ctlr.dev_fun = readb (io_mem + addr + 1);
  757. hpc_ptr->irq = readb (io_mem + addr + 2);
  758. addr += 3;
  759. debug ("ctrl bus = %x, ctlr devfun = %x, irq = %x\n",
  760. hpc_ptr->u.pci_ctlr.bus,
  761. hpc_ptr->u.pci_ctlr.dev_fun, hpc_ptr->irq);
  762. break;
  763. case 0:
  764. hpc_ptr->u.isa_ctlr.io_start = readw (io_mem + addr);
  765. hpc_ptr->u.isa_ctlr.io_end = readw (io_mem + addr + 2);
  766. if (!request_region (hpc_ptr->u.isa_ctlr.io_start,
  767. (hpc_ptr->u.isa_ctlr.io_end - hpc_ptr->u.isa_ctlr.io_start + 1),
  768. "ibmphp")) {
  769. rc = -ENODEV;
  770. goto error_no_hp_slot;
  771. }
  772. hpc_ptr->irq = readb (io_mem + addr + 4);
  773. addr += 5;
  774. break;
  775. case 2:
  776. case 4:
  777. hpc_ptr->u.wpeg_ctlr.wpegbbar = readl (io_mem + addr);
  778. hpc_ptr->u.wpeg_ctlr.i2c_addr = readb (io_mem + addr + 4);
  779. hpc_ptr->irq = readb (io_mem + addr + 5);
  780. addr += 6;
  781. break;
  782. default:
  783. rc = -ENODEV;
  784. goto error_no_hp_slot;
  785. }
  786. //reorganize chassis' linked list
  787. combine_wpg_for_chassis ();
  788. combine_wpg_for_expansion ();
  789. hpc_ptr->revision = 0xff;
  790. hpc_ptr->options = 0xff;
  791. hpc_ptr->starting_slot_num = hpc_ptr->slots[0].slot_num;
  792. hpc_ptr->ending_slot_num = hpc_ptr->slots[slot_num-1].slot_num;
  793. // register slots with hpc core as well as create linked list of ibm slot
  794. for (index = 0; index < hpc_ptr->slot_count; index++) {
  795. hp_slot_ptr = kzalloc(sizeof(*hp_slot_ptr), GFP_KERNEL);
  796. if (!hp_slot_ptr) {
  797. rc = -ENOMEM;
  798. goto error_no_hp_slot;
  799. }
  800. hp_slot_ptr->info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
  801. if (!hp_slot_ptr->info) {
  802. rc = -ENOMEM;
  803. goto error_no_hp_info;
  804. }
  805. hp_slot_ptr->name = kmalloc(30, GFP_KERNEL);
  806. if (!hp_slot_ptr->name) {
  807. rc = -ENOMEM;
  808. goto error_no_hp_name;
  809. }
  810. tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL);
  811. if (!tmp_slot) {
  812. rc = -ENOMEM;
  813. goto error_no_slot;
  814. }
  815. tmp_slot->flag = 1;
  816. tmp_slot->capabilities = hpc_ptr->slots[index].slot_cap;
  817. if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_133_MAX) == EBDA_SLOT_133_MAX)
  818. tmp_slot->supported_speed = 3;
  819. else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_100_MAX) == EBDA_SLOT_100_MAX)
  820. tmp_slot->supported_speed = 2;
  821. else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_66_MAX) == EBDA_SLOT_66_MAX)
  822. tmp_slot->supported_speed = 1;
  823. if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_PCIX_CAP) == EBDA_SLOT_PCIX_CAP)
  824. tmp_slot->supported_bus_mode = 1;
  825. else
  826. tmp_slot->supported_bus_mode = 0;
  827. tmp_slot->bus = hpc_ptr->slots[index].slot_bus_num;
  828. bus_info_ptr1 = ibmphp_find_same_bus_num (hpc_ptr->slots[index].slot_bus_num);
  829. if (!bus_info_ptr1) {
  830. kfree(tmp_slot);
  831. rc = -ENODEV;
  832. goto error;
  833. }
  834. tmp_slot->bus_on = bus_info_ptr1;
  835. bus_info_ptr1 = NULL;
  836. tmp_slot->ctrl = hpc_ptr;
  837. tmp_slot->ctlr_index = hpc_ptr->slots[index].ctl_index;
  838. tmp_slot->number = hpc_ptr->slots[index].slot_num;
  839. tmp_slot->hotplug_slot = hp_slot_ptr;
  840. hp_slot_ptr->private = tmp_slot;
  841. hp_slot_ptr->release = release_slot;
  842. rc = fillslotinfo(hp_slot_ptr);
  843. if (rc)
  844. goto error;
  845. rc = ibmphp_init_devno ((struct slot **) &hp_slot_ptr->private);
  846. if (rc)
  847. goto error;
  848. hp_slot_ptr->ops = &ibmphp_hotplug_slot_ops;
  849. // end of registering ibm slot with hotplug core
  850. list_add (& ((struct slot *)(hp_slot_ptr->private))->ibm_slot_list, &ibmphp_slot_head);
  851. }
  852. print_bus_info ();
  853. list_add (&hpc_ptr->ebda_hpc_list, &ebda_hpc_head );
  854. } /* each hpc */
  855. list_for_each (list, &ibmphp_slot_head) {
  856. tmp_slot = list_entry (list, struct slot, ibm_slot_list);
  857. snprintf (tmp_slot->hotplug_slot->name, 30, "%s", create_file_name (tmp_slot));
  858. pci_hp_register(tmp_slot->hotplug_slot,
  859. pci_find_bus(0, tmp_slot->bus), tmp_slot->device);
  860. }
  861. print_ebda_hpc ();
  862. print_ibm_slot ();
  863. return 0;
  864. error:
  865. kfree (hp_slot_ptr->private);
  866. error_no_slot:
  867. kfree (hp_slot_ptr->name);
  868. error_no_hp_name:
  869. kfree (hp_slot_ptr->info);
  870. error_no_hp_info:
  871. kfree (hp_slot_ptr);
  872. error_no_hp_slot:
  873. free_ebda_hpc (hpc_ptr);
  874. error_no_hpc:
  875. iounmap (io_mem);
  876. return rc;
  877. }
  878. /*
  879. * map info (bus, devfun, start addr, end addr..) of i/o, memory,
  880. * pfm from the physical addr to a list of resource.
  881. */
  882. static int __init ebda_rsrc_rsrc (void)
  883. {
  884. u16 addr;
  885. short rsrc;
  886. u8 type, rsrc_type;
  887. struct ebda_pci_rsrc *rsrc_ptr;
  888. addr = rsrc_list_ptr->phys_addr;
  889. debug ("now entering rsrc land\n");
  890. debug ("offset of rsrc: %x\n", rsrc_list_ptr->phys_addr);
  891. for (rsrc = 0; rsrc < rsrc_list_ptr->num_entries; rsrc++) {
  892. type = readb (io_mem + addr);
  893. addr += 1;
  894. rsrc_type = type & EBDA_RSRC_TYPE_MASK;
  895. if (rsrc_type == EBDA_IO_RSRC_TYPE) {
  896. rsrc_ptr = alloc_ebda_pci_rsrc ();
  897. if (!rsrc_ptr) {
  898. iounmap (io_mem);
  899. return -ENOMEM;
  900. }
  901. rsrc_ptr->rsrc_type = type;
  902. rsrc_ptr->bus_num = readb (io_mem + addr);
  903. rsrc_ptr->dev_fun = readb (io_mem + addr + 1);
  904. rsrc_ptr->start_addr = readw (io_mem + addr + 2);
  905. rsrc_ptr->end_addr = readw (io_mem + addr + 4);
  906. addr += 6;
  907. debug ("rsrc from io type ----\n");
  908. debug ("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
  909. rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr);
  910. list_add (&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head);
  911. }
  912. if (rsrc_type == EBDA_MEM_RSRC_TYPE || rsrc_type == EBDA_PFM_RSRC_TYPE) {
  913. rsrc_ptr = alloc_ebda_pci_rsrc ();
  914. if (!rsrc_ptr ) {
  915. iounmap (io_mem);
  916. return -ENOMEM;
  917. }
  918. rsrc_ptr->rsrc_type = type;
  919. rsrc_ptr->bus_num = readb (io_mem + addr);
  920. rsrc_ptr->dev_fun = readb (io_mem + addr + 1);
  921. rsrc_ptr->start_addr = readl (io_mem + addr + 2);
  922. rsrc_ptr->end_addr = readl (io_mem + addr + 6);
  923. addr += 10;
  924. debug ("rsrc from mem or pfm ---\n");
  925. debug ("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n",
  926. rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr);
  927. list_add (&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head);
  928. }
  929. }
  930. kfree (rsrc_list_ptr);
  931. rsrc_list_ptr = NULL;
  932. print_ebda_pci_rsrc ();
  933. return 0;
  934. }
  935. u16 ibmphp_get_total_controllers (void)
  936. {
  937. return hpc_list_ptr->num_ctlrs;
  938. }
  939. struct slot *ibmphp_get_slot_from_physical_num (u8 physical_num)
  940. {
  941. struct slot *slot;
  942. struct list_head *list;
  943. list_for_each (list, &ibmphp_slot_head) {
  944. slot = list_entry (list, struct slot, ibm_slot_list);
  945. if (slot->number == physical_num)
  946. return slot;
  947. }
  948. return NULL;
  949. }
  950. /* To find:
  951. * - the smallest slot number
  952. * - the largest slot number
  953. * - the total number of the slots based on each bus
  954. * (if only one slot per bus slot_min = slot_max )
  955. */
  956. struct bus_info *ibmphp_find_same_bus_num (u32 num)
  957. {
  958. struct bus_info *ptr;
  959. struct list_head *ptr1;
  960. list_for_each (ptr1, &bus_info_head) {
  961. ptr = list_entry (ptr1, struct bus_info, bus_info_list);
  962. if (ptr->busno == num)
  963. return ptr;
  964. }
  965. return NULL;
  966. }
  967. /* Finding relative bus number, in order to map corresponding
  968. * bus register
  969. */
  970. int ibmphp_get_bus_index (u8 num)
  971. {
  972. struct bus_info *ptr;
  973. struct list_head *ptr1;
  974. list_for_each (ptr1, &bus_info_head) {
  975. ptr = list_entry (ptr1, struct bus_info, bus_info_list);
  976. if (ptr->busno == num)
  977. return ptr->index;
  978. }
  979. return -ENODEV;
  980. }
  981. void ibmphp_free_bus_info_queue (void)
  982. {
  983. struct bus_info *bus_info;
  984. struct list_head *list;
  985. struct list_head *next;
  986. list_for_each_safe (list, next, &bus_info_head ) {
  987. bus_info = list_entry (list, struct bus_info, bus_info_list);
  988. kfree (bus_info);
  989. }
  990. }
  991. void ibmphp_free_ebda_hpc_queue (void)
  992. {
  993. struct controller *controller = NULL;
  994. struct list_head *list;
  995. struct list_head *next;
  996. int pci_flag = 0;
  997. list_for_each_safe (list, next, &ebda_hpc_head) {
  998. controller = list_entry (list, struct controller, ebda_hpc_list);
  999. if (controller->ctlr_type == 0)
  1000. release_region (controller->u.isa_ctlr.io_start, (controller->u.isa_ctlr.io_end - controller->u.isa_ctlr.io_start + 1));
  1001. else if ((controller->ctlr_type == 1) && (!pci_flag)) {
  1002. ++pci_flag;
  1003. pci_unregister_driver (&ibmphp_driver);
  1004. }
  1005. free_ebda_hpc (controller);
  1006. }
  1007. }
  1008. void ibmphp_free_ebda_pci_rsrc_queue (void)
  1009. {
  1010. struct ebda_pci_rsrc *resource;
  1011. struct list_head *list;
  1012. struct list_head *next;
  1013. list_for_each_safe (list, next, &ibmphp_ebda_pci_rsrc_head) {
  1014. resource = list_entry (list, struct ebda_pci_rsrc, ebda_pci_rsrc_list);
  1015. kfree (resource);
  1016. resource = NULL;
  1017. }
  1018. }
  1019. static struct pci_device_id id_table[] = {
  1020. {
  1021. .vendor = PCI_VENDOR_ID_IBM,
  1022. .device = HPC_DEVICE_ID,
  1023. .subvendor = PCI_VENDOR_ID_IBM,
  1024. .subdevice = HPC_SUBSYSTEM_ID,
  1025. .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00),
  1026. }, {}
  1027. };
  1028. MODULE_DEVICE_TABLE(pci, id_table);
  1029. static int ibmphp_probe (struct pci_dev *, const struct pci_device_id *);
  1030. static struct pci_driver ibmphp_driver = {
  1031. .name = "ibmphp",
  1032. .id_table = id_table,
  1033. .probe = ibmphp_probe,
  1034. };
  1035. int ibmphp_register_pci (void)
  1036. {
  1037. struct controller *ctrl;
  1038. struct list_head *tmp;
  1039. int rc = 0;
  1040. list_for_each (tmp, &ebda_hpc_head) {
  1041. ctrl = list_entry (tmp, struct controller, ebda_hpc_list);
  1042. if (ctrl->ctlr_type == 1) {
  1043. rc = pci_register_driver(&ibmphp_driver);
  1044. break;
  1045. }
  1046. }
  1047. return rc;
  1048. }
  1049. static int ibmphp_probe (struct pci_dev * dev, const struct pci_device_id *ids)
  1050. {
  1051. struct controller *ctrl;
  1052. struct list_head *tmp;
  1053. debug ("inside ibmphp_probe\n");
  1054. list_for_each (tmp, &ebda_hpc_head) {
  1055. ctrl = list_entry (tmp, struct controller, ebda_hpc_list);
  1056. if (ctrl->ctlr_type == 1) {
  1057. if ((dev->devfn == ctrl->u.pci_ctlr.dev_fun) && (dev->bus->number == ctrl->u.pci_ctlr.bus)) {
  1058. ctrl->ctrl_dev = dev;
  1059. debug ("found device!!!\n");
  1060. debug ("dev->device = %x, dev->subsystem_device = %x\n", dev->device, dev->subsystem_device);
  1061. return 0;
  1062. }
  1063. }
  1064. }
  1065. return -ENODEV;
  1066. }