/kernel/2.6.32_froyo_photon_nightly/drivers/pci/hotplug/cpqphp_core.c

http://photon-android.googlecode.com/ · C · 1488 lines · 1016 code · 257 blank · 215 comment · 147 complexity · dcc3291cabbcba9b7ee423029bba62b7 MD5 · raw file

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