cpqphp_core.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  1. /*
  2. * Compaq Hot Plug Controller Driver
  3. *
  4. * Copyright (C) 1995,2001 Compaq Computer Corporation
  5. * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
  6. * Copyright (C) 2001 IBM Corp.
  7. *
  8. * All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or (at
  13. * your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  18. * NON INFRINGEMENT. See the GNU General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. * Send feedback to <greg@kroah.com>
  26. *
  27. * Jan 12, 2003 - Added 66/100/133MHz PCI-X support,
  28. * Torben Mathiasen <torben.mathiasen@hp.com>
  29. */
  30. #include <linux/module.h>
  31. #include <linux/moduleparam.h>
  32. #include <linux/kernel.h>
  33. #include <linux/types.h>
  34. #include <linux/proc_fs.h>
  35. #include <linux/slab.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/pci.h>
  38. #include <linux/pci_hotplug.h>
  39. #include <linux/init.h>
  40. #include <linux/interrupt.h>
  41. #include <asm/uaccess.h>
  42. #include "cpqphp.h"
  43. #include "cpqphp_nvram.h"
  44. /* Global variables */
  45. int cpqhp_debug;
  46. int cpqhp_legacy_mode;
  47. struct controller *cpqhp_ctrl_list; /* = NULL */
  48. struct pci_func *cpqhp_slot_list[256];
  49. struct irq_routing_table *cpqhp_routing_table;
  50. /* local variables */
  51. static void __iomem *smbios_table;
  52. static void __iomem *smbios_start;
  53. static void __iomem *cpqhp_rom_start;
  54. static bool power_mode;
  55. static bool debug;
  56. static int initialized;
  57. #define DRIVER_VERSION "0.9.8"
  58. #define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>"
  59. #define DRIVER_DESC "Compaq Hot Plug PCI Controller Driver"
  60. MODULE_AUTHOR(DRIVER_AUTHOR);
  61. MODULE_DESCRIPTION(DRIVER_DESC);
  62. MODULE_LICENSE("GPL");
  63. module_param(power_mode, bool, 0644);
  64. MODULE_PARM_DESC(power_mode, "Power mode enabled or not");
  65. module_param(debug, bool, 0644);
  66. MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
  67. #define CPQHPC_MODULE_MINOR 208
  68. static inline int is_slot64bit(struct slot *slot)
  69. {
  70. return (readb(slot->p_sm_slot + SMBIOS_SLOT_WIDTH) == 0x06) ? 1 : 0;
  71. }
  72. static inline int is_slot66mhz(struct slot *slot)
  73. {
  74. return (readb(slot->p_sm_slot + SMBIOS_SLOT_TYPE) == 0x0E) ? 1 : 0;
  75. }
  76. /**
  77. * detect_SMBIOS_pointer - find the System Management BIOS Table in mem region.
  78. * @begin: begin pointer for region to be scanned.
  79. * @end: end pointer for region to be scanned.
  80. *
  81. * Returns pointer to the head of the SMBIOS tables (or %NULL).
  82. */
  83. static void __iomem *detect_SMBIOS_pointer(void __iomem *begin, void __iomem *end)
  84. {
  85. void __iomem *fp;
  86. void __iomem *endp;
  87. u8 temp1, temp2, temp3, temp4;
  88. int status = 0;
  89. endp = (end - sizeof(u32) + 1);
  90. for (fp = begin; fp <= endp; fp += 16) {
  91. temp1 = readb(fp);
  92. temp2 = readb(fp+1);
  93. temp3 = readb(fp+2);
  94. temp4 = readb(fp+3);
  95. if (temp1 == '_' &&
  96. temp2 == 'S' &&
  97. temp3 == 'M' &&
  98. temp4 == '_') {
  99. status = 1;
  100. break;
  101. }
  102. }
  103. if (!status)
  104. fp = NULL;
  105. dbg("Discovered SMBIOS Entry point at %p\n", fp);
  106. return fp;
  107. }
  108. /**
  109. * init_SERR - Initializes the per slot SERR generation.
  110. * @ctrl: controller to use
  111. *
  112. * For unexpected switch opens
  113. */
  114. static int init_SERR(struct controller *ctrl)
  115. {
  116. u32 tempdword;
  117. u32 number_of_slots;
  118. u8 physical_slot;
  119. if (!ctrl)
  120. return 1;
  121. tempdword = ctrl->first_slot;
  122. number_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
  123. /* Loop through slots */
  124. while (number_of_slots) {
  125. physical_slot = tempdword;
  126. writeb(0, ctrl->hpc_reg + SLOT_SERR);
  127. tempdword++;
  128. number_of_slots--;
  129. }
  130. return 0;
  131. }
  132. static int init_cpqhp_routing_table(void)
  133. {
  134. int len;
  135. cpqhp_routing_table = pcibios_get_irq_routing_table();
  136. if (cpqhp_routing_table == NULL)
  137. return -ENOMEM;
  138. len = cpqhp_routing_table_length();
  139. if (len == 0) {
  140. kfree(cpqhp_routing_table);
  141. cpqhp_routing_table = NULL;
  142. return -1;
  143. }
  144. return 0;
  145. }
  146. /* nice debugging output */
  147. static void pci_print_IRQ_route(void)
  148. {
  149. int len;
  150. int loop;
  151. u8 tbus, tdevice, tslot;
  152. len = cpqhp_routing_table_length();
  153. dbg("bus dev func slot\n");
  154. for (loop = 0; loop < len; ++loop) {
  155. tbus = cpqhp_routing_table->slots[loop].bus;
  156. tdevice = cpqhp_routing_table->slots[loop].devfn;
  157. tslot = cpqhp_routing_table->slots[loop].slot;
  158. dbg("%d %d %d %d\n", tbus, tdevice >> 3, tdevice & 0x7, tslot);
  159. }
  160. return;
  161. }
  162. /**
  163. * get_subsequent_smbios_entry: get the next entry from bios table.
  164. * @smbios_start: where to start in the SMBIOS table
  165. * @smbios_table: location of the SMBIOS table
  166. * @curr: %NULL or pointer to previously returned structure
  167. *
  168. * Gets the first entry if previous == NULL;
  169. * otherwise, returns the next entry.
  170. * Uses global SMBIOS Table pointer.
  171. *
  172. * Returns a pointer to an SMBIOS structure or NULL if none found.
  173. */
  174. static void __iomem *get_subsequent_smbios_entry(void __iomem *smbios_start,
  175. void __iomem *smbios_table,
  176. void __iomem *curr)
  177. {
  178. u8 bail = 0;
  179. u8 previous_byte = 1;
  180. void __iomem *p_temp;
  181. void __iomem *p_max;
  182. if (!smbios_table || !curr)
  183. return NULL;
  184. /* set p_max to the end of the table */
  185. p_max = smbios_start + readw(smbios_table + ST_LENGTH);
  186. p_temp = curr;
  187. p_temp += readb(curr + SMBIOS_GENERIC_LENGTH);
  188. while ((p_temp < p_max) && !bail) {
  189. /* Look for the double NULL terminator
  190. * The first condition is the previous byte
  191. * and the second is the curr
  192. */
  193. if (!previous_byte && !(readb(p_temp)))
  194. bail = 1;
  195. previous_byte = readb(p_temp);
  196. p_temp++;
  197. }
  198. if (p_temp < p_max)
  199. return p_temp;
  200. else
  201. return NULL;
  202. }
  203. /**
  204. * get_SMBIOS_entry - return the requested SMBIOS entry or %NULL
  205. * @smbios_start: where to start in the SMBIOS table
  206. * @smbios_table: location of the SMBIOS table
  207. * @type: SMBIOS structure type to be returned
  208. * @previous: %NULL or pointer to previously returned structure
  209. *
  210. * Gets the first entry of the specified type if previous == %NULL;
  211. * Otherwise, returns the next entry of the given type.
  212. * Uses global SMBIOS Table pointer.
  213. * Uses get_subsequent_smbios_entry.
  214. *
  215. * Returns a pointer to an SMBIOS structure or %NULL if none found.
  216. */
  217. static void __iomem *get_SMBIOS_entry(void __iomem *smbios_start,
  218. void __iomem *smbios_table,
  219. u8 type,
  220. void __iomem *previous)
  221. {
  222. if (!smbios_table)
  223. return NULL;
  224. if (!previous)
  225. previous = smbios_start;
  226. else
  227. previous = get_subsequent_smbios_entry(smbios_start,
  228. smbios_table, previous);
  229. while (previous)
  230. if (readb(previous + SMBIOS_GENERIC_TYPE) != type)
  231. previous = get_subsequent_smbios_entry(smbios_start,
  232. smbios_table, previous);
  233. else
  234. break;
  235. return previous;
  236. }
  237. static void release_slot(struct hotplug_slot *hotplug_slot)
  238. {
  239. struct slot *slot = hotplug_slot->private;
  240. dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
  241. kfree(slot->hotplug_slot->info);
  242. kfree(slot->hotplug_slot);
  243. kfree(slot);
  244. }
  245. static int ctrl_slot_cleanup (struct controller *ctrl)
  246. {
  247. struct slot *old_slot, *next_slot;
  248. old_slot = ctrl->slot;
  249. ctrl->slot = NULL;
  250. while (old_slot) {
  251. /* memory will be freed by the release_slot callback */
  252. next_slot = old_slot->next;
  253. pci_hp_deregister (old_slot->hotplug_slot);
  254. old_slot = next_slot;
  255. }
  256. cpqhp_remove_debugfs_files(ctrl);
  257. /* Free IRQ associated with hot plug device */
  258. free_irq(ctrl->interrupt, ctrl);
  259. /* Unmap the memory */
  260. iounmap(ctrl->hpc_reg);
  261. /* Finally reclaim PCI mem */
  262. release_mem_region(pci_resource_start(ctrl->pci_dev, 0),
  263. pci_resource_len(ctrl->pci_dev, 0));
  264. return 0;
  265. }
  266. /**
  267. * get_slot_mapping - determine logical slot mapping for PCI device
  268. *
  269. * Won't work for more than one PCI-PCI bridge in a slot.
  270. *
  271. * @bus_num - bus number of PCI device
  272. * @dev_num - device number of PCI device
  273. * @slot - Pointer to u8 where slot number will be returned
  274. *
  275. * Output: SUCCESS or FAILURE
  276. */
  277. static int
  278. get_slot_mapping(struct pci_bus *bus, u8 bus_num, u8 dev_num, u8 *slot)
  279. {
  280. u32 work;
  281. long len;
  282. long loop;
  283. u8 tbus, tdevice, tslot, bridgeSlot;
  284. dbg("%s: %p, %d, %d, %p\n", __func__, bus, bus_num, dev_num, slot);
  285. bridgeSlot = 0xFF;
  286. len = cpqhp_routing_table_length();
  287. for (loop = 0; loop < len; ++loop) {
  288. tbus = cpqhp_routing_table->slots[loop].bus;
  289. tdevice = cpqhp_routing_table->slots[loop].devfn >> 3;
  290. tslot = cpqhp_routing_table->slots[loop].slot;
  291. if ((tbus == bus_num) && (tdevice == dev_num)) {
  292. *slot = tslot;
  293. return 0;
  294. } else {
  295. /* Did not get a match on the target PCI device. Check
  296. * if the current IRQ table entry is a PCI-to-PCI
  297. * bridge device. If so, and it's secondary bus
  298. * matches the bus number for the target device, I need
  299. * to save the bridge's slot number. If I can not find
  300. * an entry for the target device, I will have to
  301. * assume it's on the other side of the bridge, and
  302. * assign it the bridge's slot.
  303. */
  304. bus->number = tbus;
  305. pci_bus_read_config_dword(bus, PCI_DEVFN(tdevice, 0),
  306. PCI_CLASS_REVISION, &work);
  307. if ((work >> 8) == PCI_TO_PCI_BRIDGE_CLASS) {
  308. pci_bus_read_config_dword(bus,
  309. PCI_DEVFN(tdevice, 0),
  310. PCI_PRIMARY_BUS, &work);
  311. // See if bridge's secondary bus matches target bus.
  312. if (((work >> 8) & 0x000000FF) == (long) bus_num)
  313. bridgeSlot = tslot;
  314. }
  315. }
  316. }
  317. /* If we got here, we didn't find an entry in the IRQ mapping table for
  318. * the target PCI device. If we did determine that the target device
  319. * is on the other side of a PCI-to-PCI bridge, return the slot number
  320. * for the bridge.
  321. */
  322. if (bridgeSlot != 0xFF) {
  323. *slot = bridgeSlot;
  324. return 0;
  325. }
  326. /* Couldn't find an entry in the routing table for this PCI device */
  327. return -1;
  328. }
  329. /**
  330. * cpqhp_set_attention_status - Turns the Amber LED for a slot on or off
  331. * @ctrl: struct controller to use
  332. * @func: PCI device/function info
  333. * @status: LED control flag: 1 = LED on, 0 = LED off
  334. */
  335. static int
  336. cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
  337. u32 status)
  338. {
  339. u8 hp_slot;
  340. if (func == NULL)
  341. return 1;
  342. hp_slot = func->device - ctrl->slot_device_offset;
  343. /* Wait for exclusive access to hardware */
  344. mutex_lock(&ctrl->crit_sect);
  345. if (status == 1)
  346. amber_LED_on (ctrl, hp_slot);
  347. else if (status == 0)
  348. amber_LED_off (ctrl, hp_slot);
  349. else {
  350. /* Done with exclusive hardware access */
  351. mutex_unlock(&ctrl->crit_sect);
  352. return 1;
  353. }
  354. set_SOGO(ctrl);
  355. /* Wait for SOBS to be unset */
  356. wait_for_ctrl_irq (ctrl);
  357. /* Done with exclusive hardware access */
  358. mutex_unlock(&ctrl->crit_sect);
  359. return 0;
  360. }
  361. /**
  362. * set_attention_status - Turns the Amber LED for a slot on or off
  363. * @hotplug_slot: slot to change LED on
  364. * @status: LED control flag
  365. */
  366. static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
  367. {
  368. struct pci_func *slot_func;
  369. struct slot *slot = hotplug_slot->private;
  370. struct controller *ctrl = slot->ctrl;
  371. u8 bus;
  372. u8 devfn;
  373. u8 device;
  374. u8 function;
  375. dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
  376. if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
  377. return -ENODEV;
  378. device = devfn >> 3;
  379. function = devfn & 0x7;
  380. dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
  381. slot_func = cpqhp_slot_find(bus, device, function);
  382. if (!slot_func)
  383. return -ENODEV;
  384. return cpqhp_set_attention_status(ctrl, slot_func, status);
  385. }
  386. static int process_SI(struct hotplug_slot *hotplug_slot)
  387. {
  388. struct pci_func *slot_func;
  389. struct slot *slot = hotplug_slot->private;
  390. struct controller *ctrl = slot->ctrl;
  391. u8 bus;
  392. u8 devfn;
  393. u8 device;
  394. u8 function;
  395. dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
  396. if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
  397. return -ENODEV;
  398. device = devfn >> 3;
  399. function = devfn & 0x7;
  400. dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
  401. slot_func = cpqhp_slot_find(bus, device, function);
  402. if (!slot_func)
  403. return -ENODEV;
  404. slot_func->bus = bus;
  405. slot_func->device = device;
  406. slot_func->function = function;
  407. slot_func->configured = 0;
  408. dbg("board_added(%p, %p)\n", slot_func, ctrl);
  409. return cpqhp_process_SI(ctrl, slot_func);
  410. }
  411. static int process_SS(struct hotplug_slot *hotplug_slot)
  412. {
  413. struct pci_func *slot_func;
  414. struct slot *slot = hotplug_slot->private;
  415. struct controller *ctrl = slot->ctrl;
  416. u8 bus;
  417. u8 devfn;
  418. u8 device;
  419. u8 function;
  420. dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
  421. if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
  422. return -ENODEV;
  423. device = devfn >> 3;
  424. function = devfn & 0x7;
  425. dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
  426. slot_func = cpqhp_slot_find(bus, device, function);
  427. if (!slot_func)
  428. return -ENODEV;
  429. dbg("In %s, slot_func = %p, ctrl = %p\n", __func__, slot_func, ctrl);
  430. return cpqhp_process_SS(ctrl, slot_func);
  431. }
  432. static int hardware_test(struct hotplug_slot *hotplug_slot, u32 value)
  433. {
  434. struct slot *slot = hotplug_slot->private;
  435. struct controller *ctrl = slot->ctrl;
  436. dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
  437. return cpqhp_hardware_test(ctrl, value);
  438. }
  439. static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
  440. {
  441. struct slot *slot = hotplug_slot->private;
  442. struct controller *ctrl = slot->ctrl;
  443. dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
  444. *value = get_slot_enabled(ctrl, slot);
  445. return 0;
  446. }
  447. static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
  448. {
  449. struct slot *slot = hotplug_slot->private;
  450. struct controller *ctrl = slot->ctrl;
  451. dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
  452. *value = cpq_get_attention_status(ctrl, slot);
  453. return 0;
  454. }
  455. static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
  456. {
  457. struct slot *slot = hotplug_slot->private;
  458. struct controller *ctrl = slot->ctrl;
  459. dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
  460. *value = cpq_get_latch_status(ctrl, slot);
  461. return 0;
  462. }
  463. static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
  464. {
  465. struct slot *slot = hotplug_slot->private;
  466. struct controller *ctrl = slot->ctrl;
  467. dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
  468. *value = get_presence_status(ctrl, slot);
  469. return 0;
  470. }
  471. static struct hotplug_slot_ops cpqphp_hotplug_slot_ops = {
  472. .set_attention_status = set_attention_status,
  473. .enable_slot = process_SI,
  474. .disable_slot = process_SS,
  475. .hardware_test = hardware_test,
  476. .get_power_status = get_power_status,
  477. .get_attention_status = get_attention_status,
  478. .get_latch_status = get_latch_status,
  479. .get_adapter_status = get_adapter_status,
  480. };
  481. #define SLOT_NAME_SIZE 10
  482. static int ctrl_slot_setup(struct controller *ctrl,
  483. void __iomem *smbios_start,
  484. void __iomem *smbios_table)
  485. {
  486. struct slot *slot;
  487. struct hotplug_slot *hotplug_slot;
  488. struct hotplug_slot_info *hotplug_slot_info;
  489. struct pci_bus *bus = ctrl->pci_bus;
  490. u8 number_of_slots;
  491. u8 slot_device;
  492. u8 slot_number;
  493. u8 ctrl_slot;
  494. u32 tempdword;
  495. char name[SLOT_NAME_SIZE];
  496. void __iomem *slot_entry= NULL;
  497. int result;
  498. dbg("%s\n", __func__);
  499. tempdword = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
  500. number_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
  501. slot_device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  502. slot_number = ctrl->first_slot;
  503. while (number_of_slots) {
  504. slot = kzalloc(sizeof(*slot), GFP_KERNEL);
  505. if (!slot) {
  506. result = -ENOMEM;
  507. goto error;
  508. }
  509. slot->hotplug_slot = kzalloc(sizeof(*(slot->hotplug_slot)),
  510. GFP_KERNEL);
  511. if (!slot->hotplug_slot) {
  512. result = -ENOMEM;
  513. goto error_slot;
  514. }
  515. hotplug_slot = slot->hotplug_slot;
  516. hotplug_slot->info = kzalloc(sizeof(*(hotplug_slot->info)),
  517. GFP_KERNEL);
  518. if (!hotplug_slot->info) {
  519. result = -ENOMEM;
  520. goto error_hpslot;
  521. }
  522. hotplug_slot_info = hotplug_slot->info;
  523. slot->ctrl = ctrl;
  524. slot->bus = ctrl->bus;
  525. slot->device = slot_device;
  526. slot->number = slot_number;
  527. dbg("slot->number = %u\n", slot->number);
  528. slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9,
  529. slot_entry);
  530. while (slot_entry && (readw(slot_entry + SMBIOS_SLOT_NUMBER) !=
  531. slot->number)) {
  532. slot_entry = get_SMBIOS_entry(smbios_start,
  533. smbios_table, 9, slot_entry);
  534. }
  535. slot->p_sm_slot = slot_entry;
  536. init_timer(&slot->task_event);
  537. slot->task_event.expires = jiffies + 5 * HZ;
  538. slot->task_event.function = cpqhp_pushbutton_thread;
  539. /*FIXME: these capabilities aren't used but if they are
  540. * they need to be correctly implemented
  541. */
  542. slot->capabilities |= PCISLOT_REPLACE_SUPPORTED;
  543. slot->capabilities |= PCISLOT_INTERLOCK_SUPPORTED;
  544. if (is_slot64bit(slot))
  545. slot->capabilities |= PCISLOT_64_BIT_SUPPORTED;
  546. if (is_slot66mhz(slot))
  547. slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED;
  548. if (bus->cur_bus_speed == PCI_SPEED_66MHz)
  549. slot->capabilities |= PCISLOT_66_MHZ_OPERATION;
  550. ctrl_slot =
  551. slot_device - (readb(ctrl->hpc_reg + SLOT_MASK) >> 4);
  552. /* Check presence */
  553. slot->capabilities |=
  554. ((((~tempdword) >> 23) |
  555. ((~tempdword) >> 15)) >> ctrl_slot) & 0x02;
  556. /* Check the switch state */
  557. slot->capabilities |=
  558. ((~tempdword & 0xFF) >> ctrl_slot) & 0x01;
  559. /* Check the slot enable */
  560. slot->capabilities |=
  561. ((read_slot_enable(ctrl) << 2) >> ctrl_slot) & 0x04;
  562. /* register this slot with the hotplug pci core */
  563. hotplug_slot->release = &release_slot;
  564. hotplug_slot->private = slot;
  565. snprintf(name, SLOT_NAME_SIZE, "%u", slot->number);
  566. hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
  567. hotplug_slot_info->power_status = get_slot_enabled(ctrl, slot);
  568. hotplug_slot_info->attention_status =
  569. cpq_get_attention_status(ctrl, slot);
  570. hotplug_slot_info->latch_status =
  571. cpq_get_latch_status(ctrl, slot);
  572. hotplug_slot_info->adapter_status =
  573. get_presence_status(ctrl, slot);
  574. dbg("registering bus %d, dev %d, number %d, ctrl->slot_device_offset %d, slot %d\n",
  575. slot->bus, slot->device,
  576. slot->number, ctrl->slot_device_offset,
  577. slot_number);
  578. result = pci_hp_register(hotplug_slot,
  579. ctrl->pci_dev->bus,
  580. slot->device,
  581. name);
  582. if (result) {
  583. err("pci_hp_register failed with error %d\n", result);
  584. goto error_info;
  585. }
  586. slot->next = ctrl->slot;
  587. ctrl->slot = slot;
  588. number_of_slots--;
  589. slot_device++;
  590. slot_number++;
  591. }
  592. return 0;
  593. error_info:
  594. kfree(hotplug_slot_info);
  595. error_hpslot:
  596. kfree(hotplug_slot);
  597. error_slot:
  598. kfree(slot);
  599. error:
  600. return result;
  601. }
  602. static int one_time_init(void)
  603. {
  604. int loop;
  605. int retval = 0;
  606. if (initialized)
  607. return 0;
  608. power_mode = 0;
  609. retval = init_cpqhp_routing_table();
  610. if (retval)
  611. goto error;
  612. if (cpqhp_debug)
  613. pci_print_IRQ_route();
  614. dbg("Initialize + Start the notification mechanism \n");
  615. retval = cpqhp_event_start_thread();
  616. if (retval)
  617. goto error;
  618. dbg("Initialize slot lists\n");
  619. for (loop = 0; loop < 256; loop++)
  620. cpqhp_slot_list[loop] = NULL;
  621. /* FIXME: We also need to hook the NMI handler eventually.
  622. * this also needs to be worked with Christoph
  623. * register_NMI_handler();
  624. */
  625. /* Map rom address */
  626. cpqhp_rom_start = ioremap(ROM_PHY_ADDR, ROM_PHY_LEN);
  627. if (!cpqhp_rom_start) {
  628. err ("Could not ioremap memory region for ROM\n");
  629. retval = -EIO;
  630. goto error;
  631. }
  632. /* Now, map the int15 entry point if we are on compaq specific
  633. * hardware
  634. */
  635. compaq_nvram_init(cpqhp_rom_start);
  636. /* Map smbios table entry point structure */
  637. smbios_table = detect_SMBIOS_pointer(cpqhp_rom_start,
  638. cpqhp_rom_start + ROM_PHY_LEN);
  639. if (!smbios_table) {
  640. err ("Could not find the SMBIOS pointer in memory\n");
  641. retval = -EIO;
  642. goto error_rom_start;
  643. }
  644. smbios_start = ioremap(readl(smbios_table + ST_ADDRESS),
  645. readw(smbios_table + ST_LENGTH));
  646. if (!smbios_start) {
  647. err ("Could not ioremap memory region taken from SMBIOS values\n");
  648. retval = -EIO;
  649. goto error_smbios_start;
  650. }
  651. initialized = 1;
  652. return retval;
  653. error_smbios_start:
  654. iounmap(smbios_start);
  655. error_rom_start:
  656. iounmap(cpqhp_rom_start);
  657. error:
  658. return retval;
  659. }
  660. static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  661. {
  662. u8 num_of_slots = 0;
  663. u8 hp_slot = 0;
  664. u8 device;
  665. u8 bus_cap;
  666. u16 temp_word;
  667. u16 vendor_id;
  668. u16 subsystem_vid;
  669. u16 subsystem_deviceid;
  670. u32 rc;
  671. struct controller *ctrl;
  672. struct pci_func *func;
  673. struct pci_bus *bus;
  674. int err;
  675. err = pci_enable_device(pdev);
  676. if (err) {
  677. printk(KERN_ERR MY_NAME ": cannot enable PCI device %s (%d)\n",
  678. pci_name(pdev), err);
  679. return err;
  680. }
  681. bus = pdev->subordinate;
  682. if (!bus) {
  683. dev_notice(&pdev->dev, "the device is not a bridge, skipping\n");
  684. rc = -ENODEV;
  685. goto err_disable_device;
  686. }
  687. /* Need to read VID early b/c it's used to differentiate CPQ and INTC
  688. * discovery
  689. */
  690. vendor_id = pdev->vendor;
  691. if ((vendor_id != PCI_VENDOR_ID_COMPAQ) &&
  692. (vendor_id != PCI_VENDOR_ID_INTEL)) {
  693. err(msg_HPC_non_compaq_or_intel);
  694. rc = -ENODEV;
  695. goto err_disable_device;
  696. }
  697. dbg("Vendor ID: %x\n", vendor_id);
  698. dbg("revision: %d\n", pdev->revision);
  699. if ((vendor_id == PCI_VENDOR_ID_COMPAQ) && (!pdev->revision)) {
  700. err(msg_HPC_rev_error);
  701. rc = -ENODEV;
  702. goto err_disable_device;
  703. }
  704. /* Check for the proper subsystem IDs
  705. * Intel uses a different SSID programming model than Compaq.
  706. * For Intel, each SSID bit identifies a PHP capability.
  707. * Also Intel HPCs may have RID=0.
  708. */
  709. if ((pdev->revision <= 2) && (vendor_id != PCI_VENDOR_ID_INTEL)) {
  710. err(msg_HPC_not_supported);
  711. return -ENODEV;
  712. }
  713. /* TODO: This code can be made to support non-Compaq or Intel
  714. * subsystem IDs
  715. */
  716. subsystem_vid = pdev->subsystem_vendor;
  717. dbg("Subsystem Vendor ID: %x\n", subsystem_vid);
  718. if ((subsystem_vid != PCI_VENDOR_ID_COMPAQ) && (subsystem_vid != PCI_VENDOR_ID_INTEL)) {
  719. err(msg_HPC_non_compaq_or_intel);
  720. rc = -ENODEV;
  721. goto err_disable_device;
  722. }
  723. ctrl = kzalloc(sizeof(struct controller), GFP_KERNEL);
  724. if (!ctrl) {
  725. err("%s : out of memory\n", __func__);
  726. rc = -ENOMEM;
  727. goto err_disable_device;
  728. }
  729. subsystem_deviceid = pdev->subsystem_device;
  730. info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid);
  731. /* Set Vendor ID, so it can be accessed later from other
  732. * functions
  733. */
  734. ctrl->vendor_id = vendor_id;
  735. switch (subsystem_vid) {
  736. case PCI_VENDOR_ID_COMPAQ:
  737. if (pdev->revision >= 0x13) { /* CIOBX */
  738. ctrl->push_flag = 1;
  739. ctrl->slot_switch_type = 1;
  740. ctrl->push_button = 1;
  741. ctrl->pci_config_space = 1;
  742. ctrl->defeature_PHP = 1;
  743. ctrl->pcix_support = 1;
  744. ctrl->pcix_speed_capability = 1;
  745. pci_read_config_byte(pdev, 0x41, &bus_cap);
  746. if (bus_cap & 0x80) {
  747. dbg("bus max supports 133MHz PCI-X\n");
  748. bus->max_bus_speed = PCI_SPEED_133MHz_PCIX;
  749. break;
  750. }
  751. if (bus_cap & 0x40) {
  752. dbg("bus max supports 100MHz PCI-X\n");
  753. bus->max_bus_speed = PCI_SPEED_100MHz_PCIX;
  754. break;
  755. }
  756. if (bus_cap & 0x20) {
  757. dbg("bus max supports 66MHz PCI-X\n");
  758. bus->max_bus_speed = PCI_SPEED_66MHz_PCIX;
  759. break;
  760. }
  761. if (bus_cap & 0x10) {
  762. dbg("bus max supports 66MHz PCI\n");
  763. bus->max_bus_speed = PCI_SPEED_66MHz;
  764. break;
  765. }
  766. break;
  767. }
  768. switch (subsystem_deviceid) {
  769. case PCI_SUB_HPC_ID:
  770. /* Original 6500/7000 implementation */
  771. ctrl->slot_switch_type = 1;
  772. bus->max_bus_speed = PCI_SPEED_33MHz;
  773. ctrl->push_button = 0;
  774. ctrl->pci_config_space = 1;
  775. ctrl->defeature_PHP = 1;
  776. ctrl->pcix_support = 0;
  777. ctrl->pcix_speed_capability = 0;
  778. break;
  779. case PCI_SUB_HPC_ID2:
  780. /* First Pushbutton implementation */
  781. ctrl->push_flag = 1;
  782. ctrl->slot_switch_type = 1;
  783. bus->max_bus_speed = PCI_SPEED_33MHz;
  784. ctrl->push_button = 1;
  785. ctrl->pci_config_space = 1;
  786. ctrl->defeature_PHP = 1;
  787. ctrl->pcix_support = 0;
  788. ctrl->pcix_speed_capability = 0;
  789. break;
  790. case PCI_SUB_HPC_ID_INTC:
  791. /* Third party (6500/7000) */
  792. ctrl->slot_switch_type = 1;
  793. bus->max_bus_speed = PCI_SPEED_33MHz;
  794. ctrl->push_button = 0;
  795. ctrl->pci_config_space = 1;
  796. ctrl->defeature_PHP = 1;
  797. ctrl->pcix_support = 0;
  798. ctrl->pcix_speed_capability = 0;
  799. break;
  800. case PCI_SUB_HPC_ID3:
  801. /* First 66 Mhz implementation */
  802. ctrl->push_flag = 1;
  803. ctrl->slot_switch_type = 1;
  804. bus->max_bus_speed = PCI_SPEED_66MHz;
  805. ctrl->push_button = 1;
  806. ctrl->pci_config_space = 1;
  807. ctrl->defeature_PHP = 1;
  808. ctrl->pcix_support = 0;
  809. ctrl->pcix_speed_capability = 0;
  810. break;
  811. case PCI_SUB_HPC_ID4:
  812. /* First PCI-X implementation, 100MHz */
  813. ctrl->push_flag = 1;
  814. ctrl->slot_switch_type = 1;
  815. bus->max_bus_speed = PCI_SPEED_100MHz_PCIX;
  816. ctrl->push_button = 1;
  817. ctrl->pci_config_space = 1;
  818. ctrl->defeature_PHP = 1;
  819. ctrl->pcix_support = 1;
  820. ctrl->pcix_speed_capability = 0;
  821. break;
  822. default:
  823. err(msg_HPC_not_supported);
  824. rc = -ENODEV;
  825. goto err_free_ctrl;
  826. }
  827. break;
  828. case PCI_VENDOR_ID_INTEL:
  829. /* Check for speed capability (0=33, 1=66) */
  830. if (subsystem_deviceid & 0x0001)
  831. bus->max_bus_speed = PCI_SPEED_66MHz;
  832. else
  833. bus->max_bus_speed = PCI_SPEED_33MHz;
  834. /* Check for push button */
  835. if (subsystem_deviceid & 0x0002)
  836. ctrl->push_button = 0;
  837. else
  838. ctrl->push_button = 1;
  839. /* Check for slot switch type (0=mechanical, 1=not mechanical) */
  840. if (subsystem_deviceid & 0x0004)
  841. ctrl->slot_switch_type = 0;
  842. else
  843. ctrl->slot_switch_type = 1;
  844. /* PHP Status (0=De-feature PHP, 1=Normal operation) */
  845. if (subsystem_deviceid & 0x0008)
  846. ctrl->defeature_PHP = 1; /* PHP supported */
  847. else
  848. ctrl->defeature_PHP = 0; /* PHP not supported */
  849. /* Alternate Base Address Register Interface
  850. * (0=not supported, 1=supported)
  851. */
  852. if (subsystem_deviceid & 0x0010)
  853. ctrl->alternate_base_address = 1;
  854. else
  855. ctrl->alternate_base_address = 0;
  856. /* PCI Config Space Index (0=not supported, 1=supported) */
  857. if (subsystem_deviceid & 0x0020)
  858. ctrl->pci_config_space = 1;
  859. else
  860. ctrl->pci_config_space = 0;
  861. /* PCI-X support */
  862. if (subsystem_deviceid & 0x0080) {
  863. ctrl->pcix_support = 1;
  864. if (subsystem_deviceid & 0x0040)
  865. /* 133MHz PCI-X if bit 7 is 1 */
  866. ctrl->pcix_speed_capability = 1;
  867. else
  868. /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
  869. /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
  870. ctrl->pcix_speed_capability = 0;
  871. } else {
  872. /* Conventional PCI */
  873. ctrl->pcix_support = 0;
  874. ctrl->pcix_speed_capability = 0;
  875. }
  876. break;
  877. default:
  878. err(msg_HPC_not_supported);
  879. rc = -ENODEV;
  880. goto err_free_ctrl;
  881. }
  882. /* Tell the user that we found one. */
  883. info("Initializing the PCI hot plug controller residing on PCI bus %d\n",
  884. pdev->bus->number);
  885. dbg("Hotplug controller capabilities:\n");
  886. dbg(" speed_capability %d\n", bus->max_bus_speed);
  887. dbg(" slot_switch_type %s\n", ctrl->slot_switch_type ?
  888. "switch present" : "no switch");
  889. dbg(" defeature_PHP %s\n", ctrl->defeature_PHP ?
  890. "PHP supported" : "PHP not supported");
  891. dbg(" alternate_base_address %s\n", ctrl->alternate_base_address ?
  892. "supported" : "not supported");
  893. dbg(" pci_config_space %s\n", ctrl->pci_config_space ?
  894. "supported" : "not supported");
  895. dbg(" pcix_speed_capability %s\n", ctrl->pcix_speed_capability ?
  896. "supported" : "not supported");
  897. dbg(" pcix_support %s\n", ctrl->pcix_support ?
  898. "supported" : "not supported");
  899. ctrl->pci_dev = pdev;
  900. pci_set_drvdata(pdev, ctrl);
  901. /* make our own copy of the pci bus structure,
  902. * as we like tweaking it a lot */
  903. ctrl->pci_bus = kmemdup(pdev->bus, sizeof(*ctrl->pci_bus), GFP_KERNEL);
  904. if (!ctrl->pci_bus) {
  905. err("out of memory\n");
  906. rc = -ENOMEM;
  907. goto err_free_ctrl;
  908. }
  909. ctrl->bus = pdev->bus->number;
  910. ctrl->rev = pdev->revision;
  911. dbg("bus device function rev: %d %d %d %d\n", ctrl->bus,
  912. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), ctrl->rev);
  913. mutex_init(&ctrl->crit_sect);
  914. init_waitqueue_head(&ctrl->queue);
  915. /* initialize our threads if they haven't already been started up */
  916. rc = one_time_init();
  917. if (rc)
  918. goto err_free_bus;
  919. dbg("pdev = %p\n", pdev);
  920. dbg("pci resource start %llx\n", (unsigned long long)pci_resource_start(pdev, 0));
  921. dbg("pci resource len %llx\n", (unsigned long long)pci_resource_len(pdev, 0));
  922. if (!request_mem_region(pci_resource_start(pdev, 0),
  923. pci_resource_len(pdev, 0), MY_NAME)) {
  924. err("cannot reserve MMIO region\n");
  925. rc = -ENOMEM;
  926. goto err_free_bus;
  927. }
  928. ctrl->hpc_reg = ioremap(pci_resource_start(pdev, 0),
  929. pci_resource_len(pdev, 0));
  930. if (!ctrl->hpc_reg) {
  931. err("cannot remap MMIO region %llx @ %llx\n",
  932. (unsigned long long)pci_resource_len(pdev, 0),
  933. (unsigned long long)pci_resource_start(pdev, 0));
  934. rc = -ENODEV;
  935. goto err_free_mem_region;
  936. }
  937. /* Check for 66Mhz operation */
  938. bus->cur_bus_speed = get_controller_speed(ctrl);
  939. /********************************************************
  940. *
  941. * Save configuration headers for this and
  942. * subordinate PCI buses
  943. *
  944. ********************************************************/
  945. /* find the physical slot number of the first hot plug slot */
  946. /* Get slot won't work for devices behind bridges, but
  947. * in this case it will always be called for the "base"
  948. * bus/dev/func of a slot.
  949. * CS: this is leveraging the PCIIRQ routing code from the kernel
  950. * (pci-pc.c: get_irq_routing_table) */
  951. rc = get_slot_mapping(ctrl->pci_bus, pdev->bus->number,
  952. (readb(ctrl->hpc_reg + SLOT_MASK) >> 4),
  953. &(ctrl->first_slot));
  954. dbg("get_slot_mapping: first_slot = %d, returned = %d\n",
  955. ctrl->first_slot, rc);
  956. if (rc) {
  957. err(msg_initialization_err, rc);
  958. goto err_iounmap;
  959. }
  960. /* Store PCI Config Space for all devices on this bus */
  961. rc = cpqhp_save_config(ctrl, ctrl->bus, readb(ctrl->hpc_reg + SLOT_MASK));
  962. if (rc) {
  963. err("%s: unable to save PCI configuration data, error %d\n",
  964. __func__, rc);
  965. goto err_iounmap;
  966. }
  967. /*
  968. * Get IO, memory, and IRQ resources for new devices
  969. */
  970. /* The next line is required for cpqhp_find_available_resources */
  971. ctrl->interrupt = pdev->irq;
  972. if (ctrl->interrupt < 0x10) {
  973. cpqhp_legacy_mode = 1;
  974. dbg("System seems to be configured for Full Table Mapped MPS mode\n");
  975. }
  976. ctrl->cfgspc_irq = 0;
  977. pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &ctrl->cfgspc_irq);
  978. rc = cpqhp_find_available_resources(ctrl, cpqhp_rom_start);
  979. ctrl->add_support = !rc;
  980. if (rc) {
  981. dbg("cpqhp_find_available_resources = 0x%x\n", rc);
  982. err("unable to locate PCI configuration resources for hot plug add.\n");
  983. goto err_iounmap;
  984. }
  985. /*
  986. * Finish setting up the hot plug ctrl device
  987. */
  988. ctrl->slot_device_offset = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  989. dbg("NumSlots %d \n", ctrl->slot_device_offset);
  990. ctrl->next_event = 0;
  991. /* Setup the slot information structures */
  992. rc = ctrl_slot_setup(ctrl, smbios_start, smbios_table);
  993. if (rc) {
  994. err(msg_initialization_err, 6);
  995. err("%s: unable to save PCI configuration data, error %d\n",
  996. __func__, rc);
  997. goto err_iounmap;
  998. }
  999. /* Mask all general input interrupts */
  1000. writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_MASK);
  1001. /* set up the interrupt */
  1002. dbg("HPC interrupt = %d \n", ctrl->interrupt);
  1003. if (request_irq(ctrl->interrupt, cpqhp_ctrl_intr,
  1004. IRQF_SHARED, MY_NAME, ctrl)) {
  1005. err("Can't get irq %d for the hotplug pci controller\n",
  1006. ctrl->interrupt);
  1007. rc = -ENODEV;
  1008. goto err_iounmap;
  1009. }
  1010. /* Enable Shift Out interrupt and clear it, also enable SERR on power
  1011. * fault
  1012. */
  1013. temp_word = readw(ctrl->hpc_reg + MISC);
  1014. temp_word |= 0x4006;
  1015. writew(temp_word, ctrl->hpc_reg + MISC);
  1016. /* Changed 05/05/97 to clear all interrupts at start */
  1017. writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_INPUT_CLEAR);
  1018. ctrl->ctrl_int_comp = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
  1019. writel(0x0L, ctrl->hpc_reg + INT_MASK);
  1020. if (!cpqhp_ctrl_list) {
  1021. cpqhp_ctrl_list = ctrl;
  1022. ctrl->next = NULL;
  1023. } else {
  1024. ctrl->next = cpqhp_ctrl_list;
  1025. cpqhp_ctrl_list = ctrl;
  1026. }
  1027. /* turn off empty slots here unless command line option "ON" set
  1028. * Wait for exclusive access to hardware
  1029. */
  1030. mutex_lock(&ctrl->crit_sect);
  1031. num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
  1032. /* find first device number for the ctrl */
  1033. device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  1034. while (num_of_slots) {
  1035. dbg("num_of_slots: %d\n", num_of_slots);
  1036. func = cpqhp_slot_find(ctrl->bus, device, 0);
  1037. if (!func)
  1038. break;
  1039. hp_slot = func->device - ctrl->slot_device_offset;
  1040. dbg("hp_slot: %d\n", hp_slot);
  1041. /* We have to save the presence info for these slots */
  1042. temp_word = ctrl->ctrl_int_comp >> 16;
  1043. func->presence_save = (temp_word >> hp_slot) & 0x01;
  1044. func->presence_save |= (temp_word >> (hp_slot + 7)) & 0x02;
  1045. if (ctrl->ctrl_int_comp & (0x1L << hp_slot))
  1046. func->switch_save = 0;
  1047. else
  1048. func->switch_save = 0x10;
  1049. if (!power_mode)
  1050. if (!func->is_a_board) {
  1051. green_LED_off(ctrl, hp_slot);
  1052. slot_disable(ctrl, hp_slot);
  1053. }
  1054. device++;
  1055. num_of_slots--;
  1056. }
  1057. if (!power_mode) {
  1058. set_SOGO(ctrl);
  1059. /* Wait for SOBS to be unset */
  1060. wait_for_ctrl_irq(ctrl);
  1061. }
  1062. rc = init_SERR(ctrl);
  1063. if (rc) {
  1064. err("init_SERR failed\n");
  1065. mutex_unlock(&ctrl->crit_sect);
  1066. goto err_free_irq;
  1067. }
  1068. /* Done with exclusive hardware access */
  1069. mutex_unlock(&ctrl->crit_sect);
  1070. cpqhp_create_debugfs_files(ctrl);
  1071. return 0;
  1072. err_free_irq:
  1073. free_irq(ctrl->interrupt, ctrl);
  1074. err_iounmap:
  1075. iounmap(ctrl->hpc_reg);
  1076. err_free_mem_region:
  1077. release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
  1078. err_free_bus:
  1079. kfree(ctrl->pci_bus);
  1080. err_free_ctrl:
  1081. kfree(ctrl);
  1082. err_disable_device:
  1083. pci_disable_device(pdev);
  1084. return rc;
  1085. }
  1086. static void __exit unload_cpqphpd(void)
  1087. {
  1088. struct pci_func *next;
  1089. struct pci_func *TempSlot;
  1090. int loop;
  1091. u32 rc;
  1092. struct controller *ctrl;
  1093. struct controller *tctrl;
  1094. struct pci_resource *res;
  1095. struct pci_resource *tres;
  1096. rc = compaq_nvram_store(cpqhp_rom_start);
  1097. ctrl = cpqhp_ctrl_list;
  1098. while (ctrl) {
  1099. if (ctrl->hpc_reg) {
  1100. u16 misc;
  1101. rc = read_slot_enable (ctrl);
  1102. writeb(0, ctrl->hpc_reg + SLOT_SERR);
  1103. writel(0xFFFFFFC0L | ~rc, ctrl->hpc_reg + INT_MASK);
  1104. misc = readw(ctrl->hpc_reg + MISC);
  1105. misc &= 0xFFFD;
  1106. writew(misc, ctrl->hpc_reg + MISC);
  1107. }
  1108. ctrl_slot_cleanup(ctrl);
  1109. res = ctrl->io_head;
  1110. while (res) {
  1111. tres = res;
  1112. res = res->next;
  1113. kfree(tres);
  1114. }
  1115. res = ctrl->mem_head;
  1116. while (res) {
  1117. tres = res;
  1118. res = res->next;
  1119. kfree(tres);
  1120. }
  1121. res = ctrl->p_mem_head;
  1122. while (res) {
  1123. tres = res;
  1124. res = res->next;
  1125. kfree(tres);
  1126. }
  1127. res = ctrl->bus_head;
  1128. while (res) {
  1129. tres = res;
  1130. res = res->next;
  1131. kfree(tres);
  1132. }
  1133. kfree (ctrl->pci_bus);
  1134. tctrl = ctrl;
  1135. ctrl = ctrl->next;
  1136. kfree(tctrl);
  1137. }
  1138. for (loop = 0; loop < 256; loop++) {
  1139. next = cpqhp_slot_list[loop];
  1140. while (next != NULL) {
  1141. res = next->io_head;
  1142. while (res) {
  1143. tres = res;
  1144. res = res->next;
  1145. kfree(tres);
  1146. }
  1147. res = next->mem_head;
  1148. while (res) {
  1149. tres = res;
  1150. res = res->next;
  1151. kfree(tres);
  1152. }
  1153. res = next->p_mem_head;
  1154. while (res) {
  1155. tres = res;
  1156. res = res->next;
  1157. kfree(tres);
  1158. }
  1159. res = next->bus_head;
  1160. while (res) {
  1161. tres = res;
  1162. res = res->next;
  1163. kfree(tres);
  1164. }
  1165. TempSlot = next;
  1166. next = next->next;
  1167. kfree(TempSlot);
  1168. }
  1169. }
  1170. /* Stop the notification mechanism */
  1171. if (initialized)
  1172. cpqhp_event_stop_thread();
  1173. /* unmap the rom address */
  1174. if (cpqhp_rom_start)
  1175. iounmap(cpqhp_rom_start);
  1176. if (smbios_start)
  1177. iounmap(smbios_start);
  1178. }
  1179. static struct pci_device_id hpcd_pci_tbl[] = {
  1180. {
  1181. /* handle any PCI Hotplug controller */
  1182. .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00),
  1183. .class_mask = ~0,
  1184. /* no matter who makes it */
  1185. .vendor = PCI_ANY_ID,
  1186. .device = PCI_ANY_ID,
  1187. .subvendor = PCI_ANY_ID,
  1188. .subdevice = PCI_ANY_ID,
  1189. }, { /* end: all zeroes */ }
  1190. };
  1191. MODULE_DEVICE_TABLE(pci, hpcd_pci_tbl);
  1192. static struct pci_driver cpqhpc_driver = {
  1193. .name = "compaq_pci_hotplug",
  1194. .id_table = hpcd_pci_tbl,
  1195. .probe = cpqhpc_probe,
  1196. /* remove: cpqhpc_remove_one, */
  1197. };
  1198. static int __init cpqhpc_init(void)
  1199. {
  1200. int result;
  1201. cpqhp_debug = debug;
  1202. info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
  1203. cpqhp_initialize_debugfs();
  1204. result = pci_register_driver(&cpqhpc_driver);
  1205. dbg("pci_register_driver = %d\n", result);
  1206. return result;
  1207. }
  1208. static void __exit cpqhpc_cleanup(void)
  1209. {
  1210. dbg("unload_cpqphpd()\n");
  1211. unload_cpqphpd();
  1212. dbg("pci_unregister_driver\n");
  1213. pci_unregister_driver(&cpqhpc_driver);
  1214. cpqhp_shutdown_debugfs();
  1215. }
  1216. module_init(cpqhpc_init);
  1217. module_exit(cpqhpc_cleanup);