ibmphp_ebda.c 35 KB

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