cpqphp_core.c 35 KB

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