cpqphp_core.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  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 = -ENOMEM;
  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. goto error;
  507. slot->hotplug_slot = kzalloc(sizeof(*(slot->hotplug_slot)),
  508. GFP_KERNEL);
  509. if (!slot->hotplug_slot)
  510. goto error_slot;
  511. hotplug_slot = slot->hotplug_slot;
  512. hotplug_slot->info = kzalloc(sizeof(*(hotplug_slot->info)),
  513. GFP_KERNEL);
  514. if (!hotplug_slot->info)
  515. goto error_hpslot;
  516. hotplug_slot_info = hotplug_slot->info;
  517. slot->ctrl = ctrl;
  518. slot->bus = ctrl->bus;
  519. slot->device = slot_device;
  520. slot->number = slot_number;
  521. dbg("slot->number = %u\n", slot->number);
  522. slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9,
  523. slot_entry);
  524. while (slot_entry && (readw(slot_entry + SMBIOS_SLOT_NUMBER) !=
  525. slot->number)) {
  526. slot_entry = get_SMBIOS_entry(smbios_start,
  527. smbios_table, 9, slot_entry);
  528. }
  529. slot->p_sm_slot = slot_entry;
  530. init_timer(&slot->task_event);
  531. slot->task_event.expires = jiffies + 5 * HZ;
  532. slot->task_event.function = cpqhp_pushbutton_thread;
  533. /*FIXME: these capabilities aren't used but if they are
  534. * they need to be correctly implemented
  535. */
  536. slot->capabilities |= PCISLOT_REPLACE_SUPPORTED;
  537. slot->capabilities |= PCISLOT_INTERLOCK_SUPPORTED;
  538. if (is_slot64bit(slot))
  539. slot->capabilities |= PCISLOT_64_BIT_SUPPORTED;
  540. if (is_slot66mhz(slot))
  541. slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED;
  542. if (bus->cur_bus_speed == PCI_SPEED_66MHz)
  543. slot->capabilities |= PCISLOT_66_MHZ_OPERATION;
  544. ctrl_slot =
  545. slot_device - (readb(ctrl->hpc_reg + SLOT_MASK) >> 4);
  546. /* Check presence */
  547. slot->capabilities |=
  548. ((((~tempdword) >> 23) |
  549. ((~tempdword) >> 15)) >> ctrl_slot) & 0x02;
  550. /* Check the switch state */
  551. slot->capabilities |=
  552. ((~tempdword & 0xFF) >> ctrl_slot) & 0x01;
  553. /* Check the slot enable */
  554. slot->capabilities |=
  555. ((read_slot_enable(ctrl) << 2) >> ctrl_slot) & 0x04;
  556. /* register this slot with the hotplug pci core */
  557. hotplug_slot->release = &release_slot;
  558. hotplug_slot->private = slot;
  559. snprintf(name, SLOT_NAME_SIZE, "%u", slot->number);
  560. hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
  561. hotplug_slot_info->power_status = get_slot_enabled(ctrl, slot);
  562. hotplug_slot_info->attention_status =
  563. cpq_get_attention_status(ctrl, slot);
  564. hotplug_slot_info->latch_status =
  565. cpq_get_latch_status(ctrl, slot);
  566. hotplug_slot_info->adapter_status =
  567. get_presence_status(ctrl, slot);
  568. dbg("registering bus %d, dev %d, number %d, "
  569. "ctrl->slot_device_offset %d, slot %d\n",
  570. slot->bus, slot->device,
  571. slot->number, ctrl->slot_device_offset,
  572. slot_number);
  573. result = pci_hp_register(hotplug_slot,
  574. ctrl->pci_dev->bus,
  575. slot->device,
  576. name);
  577. if (result) {
  578. err("pci_hp_register failed with error %d\n", result);
  579. goto error_info;
  580. }
  581. slot->next = ctrl->slot;
  582. ctrl->slot = slot;
  583. number_of_slots--;
  584. slot_device++;
  585. slot_number++;
  586. }
  587. return 0;
  588. error_info:
  589. kfree(hotplug_slot_info);
  590. error_hpslot:
  591. kfree(hotplug_slot);
  592. error_slot:
  593. kfree(slot);
  594. error:
  595. return result;
  596. }
  597. static int one_time_init(void)
  598. {
  599. int loop;
  600. int retval = 0;
  601. if (initialized)
  602. return 0;
  603. power_mode = 0;
  604. retval = init_cpqhp_routing_table();
  605. if (retval)
  606. goto error;
  607. if (cpqhp_debug)
  608. pci_print_IRQ_route();
  609. dbg("Initialize + Start the notification mechanism \n");
  610. retval = cpqhp_event_start_thread();
  611. if (retval)
  612. goto error;
  613. dbg("Initialize slot lists\n");
  614. for (loop = 0; loop < 256; loop++)
  615. cpqhp_slot_list[loop] = NULL;
  616. /* FIXME: We also need to hook the NMI handler eventually.
  617. * this also needs to be worked with Christoph
  618. * register_NMI_handler();
  619. */
  620. /* Map rom address */
  621. cpqhp_rom_start = ioremap(ROM_PHY_ADDR, ROM_PHY_LEN);
  622. if (!cpqhp_rom_start) {
  623. err ("Could not ioremap memory region for ROM\n");
  624. retval = -EIO;
  625. goto error;
  626. }
  627. /* Now, map the int15 entry point if we are on compaq specific
  628. * hardware
  629. */
  630. compaq_nvram_init(cpqhp_rom_start);
  631. /* Map smbios table entry point structure */
  632. smbios_table = detect_SMBIOS_pointer(cpqhp_rom_start,
  633. cpqhp_rom_start + ROM_PHY_LEN);
  634. if (!smbios_table) {
  635. err ("Could not find the SMBIOS pointer in memory\n");
  636. retval = -EIO;
  637. goto error_rom_start;
  638. }
  639. smbios_start = ioremap(readl(smbios_table + ST_ADDRESS),
  640. readw(smbios_table + ST_LENGTH));
  641. if (!smbios_start) {
  642. err ("Could not ioremap memory region taken from SMBIOS values\n");
  643. retval = -EIO;
  644. goto error_smbios_start;
  645. }
  646. initialized = 1;
  647. return retval;
  648. error_smbios_start:
  649. iounmap(smbios_start);
  650. error_rom_start:
  651. iounmap(cpqhp_rom_start);
  652. error:
  653. return retval;
  654. }
  655. static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  656. {
  657. u8 num_of_slots = 0;
  658. u8 hp_slot = 0;
  659. u8 device;
  660. u8 bus_cap;
  661. u16 temp_word;
  662. u16 vendor_id;
  663. u16 subsystem_vid;
  664. u16 subsystem_deviceid;
  665. u32 rc;
  666. struct controller *ctrl;
  667. struct pci_func *func;
  668. struct pci_bus *bus;
  669. int err;
  670. err = pci_enable_device(pdev);
  671. if (err) {
  672. printk(KERN_ERR MY_NAME ": cannot enable PCI device %s (%d)\n",
  673. pci_name(pdev), err);
  674. return err;
  675. }
  676. bus = pdev->subordinate;
  677. if (!bus) {
  678. dev_notice(&pdev->dev, "the device is not a bridge, "
  679. "skipping\n");
  680. rc = -ENODEV;
  681. goto err_disable_device;
  682. }
  683. /* Need to read VID early b/c it's used to differentiate CPQ and INTC
  684. * discovery
  685. */
  686. vendor_id = pdev->vendor;
  687. if ((vendor_id != PCI_VENDOR_ID_COMPAQ) &&
  688. (vendor_id != PCI_VENDOR_ID_INTEL)) {
  689. err(msg_HPC_non_compaq_or_intel);
  690. rc = -ENODEV;
  691. goto err_disable_device;
  692. }
  693. dbg("Vendor ID: %x\n", vendor_id);
  694. dbg("revision: %d\n", pdev->revision);
  695. if ((vendor_id == PCI_VENDOR_ID_COMPAQ) && (!pdev->revision)) {
  696. err(msg_HPC_rev_error);
  697. rc = -ENODEV;
  698. goto err_disable_device;
  699. }
  700. /* Check for the proper subsystem ID's
  701. * Intel uses a different SSID programming model than Compaq.
  702. * For Intel, each SSID bit identifies a PHP capability.
  703. * Also Intel HPC's may have RID=0.
  704. */
  705. if ((pdev->revision <= 2) && (vendor_id != PCI_VENDOR_ID_INTEL)) {
  706. err(msg_HPC_not_supported);
  707. return -ENODEV;
  708. }
  709. /* TODO: This code can be made to support non-Compaq or Intel
  710. * subsystem IDs
  711. */
  712. subsystem_vid = pdev->subsystem_vendor;
  713. dbg("Subsystem Vendor ID: %x\n", subsystem_vid);
  714. if ((subsystem_vid != PCI_VENDOR_ID_COMPAQ) && (subsystem_vid != PCI_VENDOR_ID_INTEL)) {
  715. err(msg_HPC_non_compaq_or_intel);
  716. rc = -ENODEV;
  717. goto err_disable_device;
  718. }
  719. ctrl = kzalloc(sizeof(struct controller), GFP_KERNEL);
  720. if (!ctrl) {
  721. err("%s : out of memory\n", __func__);
  722. rc = -ENOMEM;
  723. goto err_disable_device;
  724. }
  725. subsystem_deviceid = pdev->subsystem_device;
  726. info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid);
  727. /* Set Vendor ID, so it can be accessed later from other
  728. * functions
  729. */
  730. ctrl->vendor_id = vendor_id;
  731. switch (subsystem_vid) {
  732. case PCI_VENDOR_ID_COMPAQ:
  733. if (pdev->revision >= 0x13) { /* CIOBX */
  734. ctrl->push_flag = 1;
  735. ctrl->slot_switch_type = 1;
  736. ctrl->push_button = 1;
  737. ctrl->pci_config_space = 1;
  738. ctrl->defeature_PHP = 1;
  739. ctrl->pcix_support = 1;
  740. ctrl->pcix_speed_capability = 1;
  741. pci_read_config_byte(pdev, 0x41, &bus_cap);
  742. if (bus_cap & 0x80) {
  743. dbg("bus max supports 133MHz PCI-X\n");
  744. bus->max_bus_speed = PCI_SPEED_133MHz_PCIX;
  745. break;
  746. }
  747. if (bus_cap & 0x40) {
  748. dbg("bus max supports 100MHz PCI-X\n");
  749. bus->max_bus_speed = PCI_SPEED_100MHz_PCIX;
  750. break;
  751. }
  752. if (bus_cap & 20) {
  753. dbg("bus max supports 66MHz PCI-X\n");
  754. bus->max_bus_speed = PCI_SPEED_66MHz_PCIX;
  755. break;
  756. }
  757. if (bus_cap & 10) {
  758. dbg("bus max supports 66MHz PCI\n");
  759. bus->max_bus_speed = PCI_SPEED_66MHz;
  760. break;
  761. }
  762. break;
  763. }
  764. switch (subsystem_deviceid) {
  765. case PCI_SUB_HPC_ID:
  766. /* Original 6500/7000 implementation */
  767. ctrl->slot_switch_type = 1;
  768. bus->max_bus_speed = PCI_SPEED_33MHz;
  769. ctrl->push_button = 0;
  770. ctrl->pci_config_space = 1;
  771. ctrl->defeature_PHP = 1;
  772. ctrl->pcix_support = 0;
  773. ctrl->pcix_speed_capability = 0;
  774. break;
  775. case PCI_SUB_HPC_ID2:
  776. /* First Pushbutton implementation */
  777. ctrl->push_flag = 1;
  778. ctrl->slot_switch_type = 1;
  779. bus->max_bus_speed = PCI_SPEED_33MHz;
  780. ctrl->push_button = 1;
  781. ctrl->pci_config_space = 1;
  782. ctrl->defeature_PHP = 1;
  783. ctrl->pcix_support = 0;
  784. ctrl->pcix_speed_capability = 0;
  785. break;
  786. case PCI_SUB_HPC_ID_INTC:
  787. /* Third party (6500/7000) */
  788. ctrl->slot_switch_type = 1;
  789. bus->max_bus_speed = PCI_SPEED_33MHz;
  790. ctrl->push_button = 0;
  791. ctrl->pci_config_space = 1;
  792. ctrl->defeature_PHP = 1;
  793. ctrl->pcix_support = 0;
  794. ctrl->pcix_speed_capability = 0;
  795. break;
  796. case PCI_SUB_HPC_ID3:
  797. /* First 66 Mhz implementation */
  798. ctrl->push_flag = 1;
  799. ctrl->slot_switch_type = 1;
  800. bus->max_bus_speed = PCI_SPEED_66MHz;
  801. ctrl->push_button = 1;
  802. ctrl->pci_config_space = 1;
  803. ctrl->defeature_PHP = 1;
  804. ctrl->pcix_support = 0;
  805. ctrl->pcix_speed_capability = 0;
  806. break;
  807. case PCI_SUB_HPC_ID4:
  808. /* First PCI-X implementation, 100MHz */
  809. ctrl->push_flag = 1;
  810. ctrl->slot_switch_type = 1;
  811. bus->max_bus_speed = PCI_SPEED_100MHz_PCIX;
  812. ctrl->push_button = 1;
  813. ctrl->pci_config_space = 1;
  814. ctrl->defeature_PHP = 1;
  815. ctrl->pcix_support = 1;
  816. ctrl->pcix_speed_capability = 0;
  817. break;
  818. default:
  819. err(msg_HPC_not_supported);
  820. rc = -ENODEV;
  821. goto err_free_ctrl;
  822. }
  823. break;
  824. case PCI_VENDOR_ID_INTEL:
  825. /* Check for speed capability (0=33, 1=66) */
  826. if (subsystem_deviceid & 0x0001)
  827. bus->max_bus_speed = PCI_SPEED_66MHz;
  828. else
  829. bus->max_bus_speed = PCI_SPEED_33MHz;
  830. /* Check for push button */
  831. if (subsystem_deviceid & 0x0002)
  832. ctrl->push_button = 0;
  833. else
  834. ctrl->push_button = 1;
  835. /* Check for slot switch type (0=mechanical, 1=not mechanical) */
  836. if (subsystem_deviceid & 0x0004)
  837. ctrl->slot_switch_type = 0;
  838. else
  839. ctrl->slot_switch_type = 1;
  840. /* PHP Status (0=De-feature PHP, 1=Normal operation) */
  841. if (subsystem_deviceid & 0x0008)
  842. ctrl->defeature_PHP = 1; /* PHP supported */
  843. else
  844. ctrl->defeature_PHP = 0; /* PHP not supported */
  845. /* Alternate Base Address Register Interface
  846. * (0=not supported, 1=supported)
  847. */
  848. if (subsystem_deviceid & 0x0010)
  849. ctrl->alternate_base_address = 1;
  850. else
  851. ctrl->alternate_base_address = 0;
  852. /* PCI Config Space Index (0=not supported, 1=supported) */
  853. if (subsystem_deviceid & 0x0020)
  854. ctrl->pci_config_space = 1;
  855. else
  856. ctrl->pci_config_space = 0;
  857. /* PCI-X support */
  858. if (subsystem_deviceid & 0x0080) {
  859. ctrl->pcix_support = 1;
  860. if (subsystem_deviceid & 0x0040)
  861. /* 133MHz PCI-X if bit 7 is 1 */
  862. ctrl->pcix_speed_capability = 1;
  863. else
  864. /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
  865. /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
  866. ctrl->pcix_speed_capability = 0;
  867. } else {
  868. /* Conventional PCI */
  869. ctrl->pcix_support = 0;
  870. ctrl->pcix_speed_capability = 0;
  871. }
  872. break;
  873. default:
  874. err(msg_HPC_not_supported);
  875. rc = -ENODEV;
  876. goto err_free_ctrl;
  877. }
  878. /* Tell the user that we found one. */
  879. info("Initializing the PCI hot plug controller residing on PCI bus %d\n",
  880. pdev->bus->number);
  881. dbg("Hotplug controller capabilities:\n");
  882. dbg(" speed_capability %d\n", bus->max_bus_speed);
  883. dbg(" slot_switch_type %s\n", ctrl->slot_switch_type ?
  884. "switch present" : "no switch");
  885. dbg(" defeature_PHP %s\n", ctrl->defeature_PHP ?
  886. "PHP supported" : "PHP not supported");
  887. dbg(" alternate_base_address %s\n", ctrl->alternate_base_address ?
  888. "supported" : "not supported");
  889. dbg(" pci_config_space %s\n", ctrl->pci_config_space ?
  890. "supported" : "not supported");
  891. dbg(" pcix_speed_capability %s\n", ctrl->pcix_speed_capability ?
  892. "supported" : "not supported");
  893. dbg(" pcix_support %s\n", ctrl->pcix_support ?
  894. "supported" : "not supported");
  895. ctrl->pci_dev = pdev;
  896. pci_set_drvdata(pdev, ctrl);
  897. /* make our own copy of the pci bus structure,
  898. * as we like tweaking it a lot */
  899. ctrl->pci_bus = kmemdup(pdev->bus, sizeof(*ctrl->pci_bus), GFP_KERNEL);
  900. if (!ctrl->pci_bus) {
  901. err("out of memory\n");
  902. rc = -ENOMEM;
  903. goto err_free_ctrl;
  904. }
  905. ctrl->bus = pdev->bus->number;
  906. ctrl->rev = pdev->revision;
  907. dbg("bus device function rev: %d %d %d %d\n", ctrl->bus,
  908. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), ctrl->rev);
  909. mutex_init(&ctrl->crit_sect);
  910. init_waitqueue_head(&ctrl->queue);
  911. /* initialize our threads if they haven't already been started up */
  912. rc = one_time_init();
  913. if (rc) {
  914. goto err_free_bus;
  915. }
  916. dbg("pdev = %p\n", pdev);
  917. dbg("pci resource start %llx\n", (unsigned long long)pci_resource_start(pdev, 0));
  918. dbg("pci resource len %llx\n", (unsigned long long)pci_resource_len(pdev, 0));
  919. if (!request_mem_region(pci_resource_start(pdev, 0),
  920. pci_resource_len(pdev, 0), MY_NAME)) {
  921. err("cannot reserve MMIO region\n");
  922. rc = -ENOMEM;
  923. goto err_free_bus;
  924. }
  925. ctrl->hpc_reg = ioremap(pci_resource_start(pdev, 0),
  926. pci_resource_len(pdev, 0));
  927. if (!ctrl->hpc_reg) {
  928. err("cannot remap MMIO region %llx @ %llx\n",
  929. (unsigned long long)pci_resource_len(pdev, 0),
  930. (unsigned long long)pci_resource_start(pdev, 0));
  931. rc = -ENODEV;
  932. goto err_free_mem_region;
  933. }
  934. /* Check for 66Mhz operation */
  935. bus->cur_bus_speed = get_controller_speed(ctrl);
  936. /********************************************************
  937. *
  938. * Save configuration headers for this and
  939. * subordinate PCI buses
  940. *
  941. ********************************************************/
  942. /* find the physical slot number of the first hot plug slot */
  943. /* Get slot won't work for devices behind bridges, but
  944. * in this case it will always be called for the "base"
  945. * bus/dev/func of a slot.
  946. * CS: this is leveraging the PCIIRQ routing code from the kernel
  947. * (pci-pc.c: get_irq_routing_table) */
  948. rc = get_slot_mapping(ctrl->pci_bus, pdev->bus->number,
  949. (readb(ctrl->hpc_reg + SLOT_MASK) >> 4),
  950. &(ctrl->first_slot));
  951. dbg("get_slot_mapping: first_slot = %d, returned = %d\n",
  952. ctrl->first_slot, rc);
  953. if (rc) {
  954. err(msg_initialization_err, rc);
  955. goto err_iounmap;
  956. }
  957. /* Store PCI Config Space for all devices on this bus */
  958. rc = cpqhp_save_config(ctrl, ctrl->bus, readb(ctrl->hpc_reg + SLOT_MASK));
  959. if (rc) {
  960. err("%s: unable to save PCI configuration data, error %d\n",
  961. __func__, rc);
  962. goto err_iounmap;
  963. }
  964. /*
  965. * Get IO, memory, and IRQ resources for new devices
  966. */
  967. /* The next line is required for cpqhp_find_available_resources */
  968. ctrl->interrupt = pdev->irq;
  969. if (ctrl->interrupt < 0x10) {
  970. cpqhp_legacy_mode = 1;
  971. dbg("System seems to be configured for Full Table Mapped MPS mode\n");
  972. }
  973. ctrl->cfgspc_irq = 0;
  974. pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &ctrl->cfgspc_irq);
  975. rc = cpqhp_find_available_resources(ctrl, cpqhp_rom_start);
  976. ctrl->add_support = !rc;
  977. if (rc) {
  978. dbg("cpqhp_find_available_resources = 0x%x\n", rc);
  979. err("unable to locate PCI configuration resources for hot plug add.\n");
  980. goto err_iounmap;
  981. }
  982. /*
  983. * Finish setting up the hot plug ctrl device
  984. */
  985. ctrl->slot_device_offset = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  986. dbg("NumSlots %d \n", ctrl->slot_device_offset);
  987. ctrl->next_event = 0;
  988. /* Setup the slot information structures */
  989. rc = ctrl_slot_setup(ctrl, smbios_start, smbios_table);
  990. if (rc) {
  991. err(msg_initialization_err, 6);
  992. err("%s: unable to save PCI configuration data, error %d\n",
  993. __func__, rc);
  994. goto err_iounmap;
  995. }
  996. /* Mask all general input interrupts */
  997. writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_MASK);
  998. /* set up the interrupt */
  999. dbg("HPC interrupt = %d \n", ctrl->interrupt);
  1000. if (request_irq(ctrl->interrupt, cpqhp_ctrl_intr,
  1001. IRQF_SHARED, MY_NAME, ctrl)) {
  1002. err("Can't get irq %d for the hotplug pci controller\n",
  1003. ctrl->interrupt);
  1004. rc = -ENODEV;
  1005. goto err_iounmap;
  1006. }
  1007. /* Enable Shift Out interrupt and clear it, also enable SERR on power
  1008. * fault
  1009. */
  1010. temp_word = readw(ctrl->hpc_reg + MISC);
  1011. temp_word |= 0x4006;
  1012. writew(temp_word, ctrl->hpc_reg + MISC);
  1013. /* Changed 05/05/97 to clear all interrupts at start */
  1014. writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_INPUT_CLEAR);
  1015. ctrl->ctrl_int_comp = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
  1016. writel(0x0L, ctrl->hpc_reg + INT_MASK);
  1017. if (!cpqhp_ctrl_list) {
  1018. cpqhp_ctrl_list = ctrl;
  1019. ctrl->next = NULL;
  1020. } else {
  1021. ctrl->next = cpqhp_ctrl_list;
  1022. cpqhp_ctrl_list = ctrl;
  1023. }
  1024. /* turn off empty slots here unless command line option "ON" set
  1025. * Wait for exclusive access to hardware
  1026. */
  1027. mutex_lock(&ctrl->crit_sect);
  1028. num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
  1029. /* find first device number for the ctrl */
  1030. device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  1031. while (num_of_slots) {
  1032. dbg("num_of_slots: %d\n", num_of_slots);
  1033. func = cpqhp_slot_find(ctrl->bus, device, 0);
  1034. if (!func)
  1035. break;
  1036. hp_slot = func->device - ctrl->slot_device_offset;
  1037. dbg("hp_slot: %d\n", hp_slot);
  1038. /* We have to save the presence info for these slots */
  1039. temp_word = ctrl->ctrl_int_comp >> 16;
  1040. func->presence_save = (temp_word >> hp_slot) & 0x01;
  1041. func->presence_save |= (temp_word >> (hp_slot + 7)) & 0x02;
  1042. if (ctrl->ctrl_int_comp & (0x1L << hp_slot))
  1043. func->switch_save = 0;
  1044. else
  1045. func->switch_save = 0x10;
  1046. if (!power_mode)
  1047. if (!func->is_a_board) {
  1048. green_LED_off(ctrl, hp_slot);
  1049. slot_disable(ctrl, hp_slot);
  1050. }
  1051. device++;
  1052. num_of_slots--;
  1053. }
  1054. if (!power_mode) {
  1055. set_SOGO(ctrl);
  1056. /* Wait for SOBS to be unset */
  1057. wait_for_ctrl_irq(ctrl);
  1058. }
  1059. rc = init_SERR(ctrl);
  1060. if (rc) {
  1061. err("init_SERR failed\n");
  1062. mutex_unlock(&ctrl->crit_sect);
  1063. goto err_free_irq;
  1064. }
  1065. /* Done with exclusive hardware access */
  1066. mutex_unlock(&ctrl->crit_sect);
  1067. cpqhp_create_debugfs_files(ctrl);
  1068. return 0;
  1069. err_free_irq:
  1070. free_irq(ctrl->interrupt, ctrl);
  1071. err_iounmap:
  1072. iounmap(ctrl->hpc_reg);
  1073. err_free_mem_region:
  1074. release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
  1075. err_free_bus:
  1076. kfree(ctrl->pci_bus);
  1077. err_free_ctrl:
  1078. kfree(ctrl);
  1079. err_disable_device:
  1080. pci_disable_device(pdev);
  1081. return rc;
  1082. }
  1083. static void __exit unload_cpqphpd(void)
  1084. {
  1085. struct pci_func *next;
  1086. struct pci_func *TempSlot;
  1087. int loop;
  1088. u32 rc;
  1089. struct controller *ctrl;
  1090. struct controller *tctrl;
  1091. struct pci_resource *res;
  1092. struct pci_resource *tres;
  1093. rc = compaq_nvram_store(cpqhp_rom_start);
  1094. ctrl = cpqhp_ctrl_list;
  1095. while (ctrl) {
  1096. if (ctrl->hpc_reg) {
  1097. u16 misc;
  1098. rc = read_slot_enable (ctrl);
  1099. writeb(0, ctrl->hpc_reg + SLOT_SERR);
  1100. writel(0xFFFFFFC0L | ~rc, ctrl->hpc_reg + INT_MASK);
  1101. misc = readw(ctrl->hpc_reg + MISC);
  1102. misc &= 0xFFFD;
  1103. writew(misc, ctrl->hpc_reg + MISC);
  1104. }
  1105. ctrl_slot_cleanup(ctrl);
  1106. res = ctrl->io_head;
  1107. while (res) {
  1108. tres = res;
  1109. res = res->next;
  1110. kfree(tres);
  1111. }
  1112. res = ctrl->mem_head;
  1113. while (res) {
  1114. tres = res;
  1115. res = res->next;
  1116. kfree(tres);
  1117. }
  1118. res = ctrl->p_mem_head;
  1119. while (res) {
  1120. tres = res;
  1121. res = res->next;
  1122. kfree(tres);
  1123. }
  1124. res = ctrl->bus_head;
  1125. while (res) {
  1126. tres = res;
  1127. res = res->next;
  1128. kfree(tres);
  1129. }
  1130. kfree (ctrl->pci_bus);
  1131. tctrl = ctrl;
  1132. ctrl = ctrl->next;
  1133. kfree(tctrl);
  1134. }
  1135. for (loop = 0; loop < 256; loop++) {
  1136. next = cpqhp_slot_list[loop];
  1137. while (next != NULL) {
  1138. res = next->io_head;
  1139. while (res) {
  1140. tres = res;
  1141. res = res->next;
  1142. kfree(tres);
  1143. }
  1144. res = next->mem_head;
  1145. while (res) {
  1146. tres = res;
  1147. res = res->next;
  1148. kfree(tres);
  1149. }
  1150. res = next->p_mem_head;
  1151. while (res) {
  1152. tres = res;
  1153. res = res->next;
  1154. kfree(tres);
  1155. }
  1156. res = next->bus_head;
  1157. while (res) {
  1158. tres = res;
  1159. res = res->next;
  1160. kfree(tres);
  1161. }
  1162. TempSlot = next;
  1163. next = next->next;
  1164. kfree(TempSlot);
  1165. }
  1166. }
  1167. /* Stop the notification mechanism */
  1168. if (initialized)
  1169. cpqhp_event_stop_thread();
  1170. /* unmap the rom address */
  1171. if (cpqhp_rom_start)
  1172. iounmap(cpqhp_rom_start);
  1173. if (smbios_start)
  1174. iounmap(smbios_start);
  1175. }
  1176. static struct pci_device_id hpcd_pci_tbl[] = {
  1177. {
  1178. /* handle any PCI Hotplug controller */
  1179. .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00),
  1180. .class_mask = ~0,
  1181. /* no matter who makes it */
  1182. .vendor = PCI_ANY_ID,
  1183. .device = PCI_ANY_ID,
  1184. .subvendor = PCI_ANY_ID,
  1185. .subdevice = PCI_ANY_ID,
  1186. }, { /* end: all zeroes */ }
  1187. };
  1188. MODULE_DEVICE_TABLE(pci, hpcd_pci_tbl);
  1189. static struct pci_driver cpqhpc_driver = {
  1190. .name = "compaq_pci_hotplug",
  1191. .id_table = hpcd_pci_tbl,
  1192. .probe = cpqhpc_probe,
  1193. /* remove: cpqhpc_remove_one, */
  1194. };
  1195. static int __init cpqhpc_init(void)
  1196. {
  1197. int result;
  1198. cpqhp_debug = debug;
  1199. info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
  1200. cpqhp_initialize_debugfs();
  1201. result = pci_register_driver(&cpqhpc_driver);
  1202. dbg("pci_register_driver = %d\n", result);
  1203. return result;
  1204. }
  1205. static void __exit cpqhpc_cleanup(void)
  1206. {
  1207. dbg("unload_cpqphpd()\n");
  1208. unload_cpqphpd();
  1209. dbg("pci_unregister_driver\n");
  1210. pci_unregister_driver(&cpqhpc_driver);
  1211. cpqhp_shutdown_debugfs();
  1212. }
  1213. module_init(cpqhpc_init);
  1214. module_exit(cpqhpc_cleanup);