cpqphp_core.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:38k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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