pciehp_core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * PCI Express 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. * Copyright (C) 2003-2004 Intel Corporation
  8. *
  9. * All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or (at
  14. * your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  19. * NON INFRINGEMENT. See the GNU General Public License for more
  20. * details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. *
  26. * Send feedback to <greg@kroah.com>, <dely.l.sy@intel.com>
  27. *
  28. */
  29. #include <linux/config.h>
  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/init.h>
  39. #include <asm/uaccess.h>
  40. #include "pciehp.h"
  41. #include "pciehprm.h"
  42. #include <linux/interrupt.h>
  43. /* Global variables */
  44. int pciehp_debug;
  45. int pciehp_poll_mode;
  46. int pciehp_poll_time;
  47. struct controller *pciehp_ctrl_list;
  48. struct pci_func *pciehp_slot_list[256];
  49. #define DRIVER_VERSION "0.4"
  50. #define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>"
  51. #define DRIVER_DESC "PCI Express Hot Plug Controller Driver"
  52. MODULE_AUTHOR(DRIVER_AUTHOR);
  53. MODULE_DESCRIPTION(DRIVER_DESC);
  54. MODULE_LICENSE("GPL");
  55. module_param(pciehp_debug, bool, 0644);
  56. module_param(pciehp_poll_mode, bool, 0644);
  57. module_param(pciehp_poll_time, int, 0644);
  58. MODULE_PARM_DESC(pciehp_debug, "Debugging mode enabled or not");
  59. MODULE_PARM_DESC(pciehp_poll_mode, "Using polling mechanism for hot-plug events or not");
  60. MODULE_PARM_DESC(pciehp_poll_time, "Polling mechanism frequency, in seconds");
  61. #define PCIE_MODULE_NAME "pciehp"
  62. static int pcie_start_thread (void);
  63. static int set_attention_status (struct hotplug_slot *slot, u8 value);
  64. static int enable_slot (struct hotplug_slot *slot);
  65. static int disable_slot (struct hotplug_slot *slot);
  66. static int get_power_status (struct hotplug_slot *slot, u8 *value);
  67. static int get_attention_status (struct hotplug_slot *slot, u8 *value);
  68. static int get_latch_status (struct hotplug_slot *slot, u8 *value);
  69. static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
  70. static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
  71. static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
  72. static struct hotplug_slot_ops pciehp_hotplug_slot_ops = {
  73. .owner = THIS_MODULE,
  74. .set_attention_status = set_attention_status,
  75. .enable_slot = enable_slot,
  76. .disable_slot = disable_slot,
  77. .get_power_status = get_power_status,
  78. .get_attention_status = get_attention_status,
  79. .get_latch_status = get_latch_status,
  80. .get_adapter_status = get_adapter_status,
  81. .get_max_bus_speed = get_max_bus_speed,
  82. .get_cur_bus_speed = get_cur_bus_speed,
  83. };
  84. static int init_slots(struct controller *ctrl)
  85. {
  86. struct slot *new_slot;
  87. u8 number_of_slots;
  88. u8 slot_device;
  89. u32 slot_number;
  90. int result = -ENOMEM;
  91. dbg("%s\n",__FUNCTION__);
  92. number_of_slots = ctrl->num_slots;
  93. slot_device = ctrl->slot_device_offset;
  94. slot_number = ctrl->first_slot;
  95. while (number_of_slots) {
  96. new_slot = kmalloc(sizeof(*new_slot), GFP_KERNEL);
  97. if (!new_slot)
  98. goto error;
  99. memset(new_slot, 0, sizeof(struct slot));
  100. new_slot->hotplug_slot =
  101. kmalloc(sizeof(*(new_slot->hotplug_slot)),
  102. GFP_KERNEL);
  103. if (!new_slot->hotplug_slot)
  104. goto error_slot;
  105. memset(new_slot->hotplug_slot, 0, sizeof(struct hotplug_slot));
  106. new_slot->hotplug_slot->info =
  107. kmalloc(sizeof(*(new_slot->hotplug_slot->info)),
  108. GFP_KERNEL);
  109. if (!new_slot->hotplug_slot->info)
  110. goto error_hpslot;
  111. memset(new_slot->hotplug_slot->info, 0,
  112. sizeof(struct hotplug_slot_info));
  113. new_slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE,
  114. GFP_KERNEL);
  115. if (!new_slot->hotplug_slot->name)
  116. goto error_info;
  117. new_slot->ctrl = ctrl;
  118. new_slot->bus = ctrl->slot_bus;
  119. new_slot->device = slot_device;
  120. new_slot->hpc_ops = ctrl->hpc_ops;
  121. new_slot->number = ctrl->first_slot;
  122. new_slot->hp_slot = slot_device - ctrl->slot_device_offset;
  123. /* register this slot with the hotplug pci core */
  124. new_slot->hotplug_slot->private = new_slot;
  125. make_slot_name (new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot);
  126. new_slot->hotplug_slot->ops = &pciehp_hotplug_slot_ops;
  127. new_slot->hpc_ops->get_power_status(new_slot, &(new_slot->hotplug_slot->info->power_status));
  128. new_slot->hpc_ops->get_attention_status(new_slot, &(new_slot->hotplug_slot->info->attention_status));
  129. new_slot->hpc_ops->get_latch_status(new_slot, &(new_slot->hotplug_slot->info->latch_status));
  130. new_slot->hpc_ops->get_adapter_status(new_slot, &(new_slot->hotplug_slot->info->adapter_status));
  131. dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x slot_device_offset=%x\n",
  132. new_slot->bus, new_slot->device, new_slot->hp_slot, new_slot->number, ctrl->slot_device_offset);
  133. result = pci_hp_register (new_slot->hotplug_slot);
  134. if (result) {
  135. err ("pci_hp_register failed with error %d\n", result);
  136. goto error_name;
  137. }
  138. new_slot->next = ctrl->slot;
  139. ctrl->slot = new_slot;
  140. number_of_slots--;
  141. slot_device++;
  142. slot_number += ctrl->slot_num_inc;
  143. }
  144. return 0;
  145. error_name:
  146. kfree(new_slot->hotplug_slot->name);
  147. error_info:
  148. kfree(new_slot->hotplug_slot->info);
  149. error_hpslot:
  150. kfree(new_slot->hotplug_slot);
  151. error_slot:
  152. kfree(new_slot);
  153. error:
  154. return result;
  155. }
  156. static int cleanup_slots (struct controller * ctrl)
  157. {
  158. struct slot *old_slot, *next_slot;
  159. old_slot = ctrl->slot;
  160. ctrl->slot = NULL;
  161. while (old_slot) {
  162. next_slot = old_slot->next;
  163. pci_hp_deregister (old_slot->hotplug_slot);
  164. kfree(old_slot->hotplug_slot->info);
  165. kfree(old_slot->hotplug_slot->name);
  166. kfree(old_slot->hotplug_slot);
  167. kfree(old_slot);
  168. old_slot = next_slot;
  169. }
  170. return(0);
  171. }
  172. static int get_ctlr_slot_config(struct controller *ctrl)
  173. {
  174. int num_ctlr_slots; /* Not needed; PCI Express has 1 slot per port*/
  175. int first_device_num; /* Not needed */
  176. int physical_slot_num;
  177. u8 ctrlcap;
  178. int rc;
  179. rc = pcie_get_ctlr_slot_config(ctrl, &num_ctlr_slots, &first_device_num, &physical_slot_num, &ctrlcap);
  180. if (rc) {
  181. err("%s: get_ctlr_slot_config fail for b:d (%x:%x)\n", __FUNCTION__, ctrl->bus, ctrl->device);
  182. return (-1);
  183. }
  184. ctrl->num_slots = num_ctlr_slots; /* PCI Express has 1 slot per port */
  185. ctrl->slot_device_offset = first_device_num;
  186. ctrl->first_slot = physical_slot_num;
  187. ctrl->ctrlcap = ctrlcap;
  188. dbg("%s: bus(0x%x) num_slot(0x%x) 1st_dev(0x%x) psn(0x%x) ctrlcap(%x) for b:d (%x:%x)\n",
  189. __FUNCTION__, ctrl->slot_bus, num_ctlr_slots, first_device_num, physical_slot_num, ctrlcap,
  190. ctrl->bus, ctrl->device);
  191. return (0);
  192. }
  193. /*
  194. * set_attention_status - Turns the Amber LED for a slot on, off or blink
  195. */
  196. static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
  197. {
  198. struct slot *slot = hotplug_slot->private;
  199. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  200. hotplug_slot->info->attention_status = status;
  201. if (ATTN_LED(slot->ctrl->ctrlcap))
  202. slot->hpc_ops->set_attention_status(slot, status);
  203. return 0;
  204. }
  205. static int enable_slot(struct hotplug_slot *hotplug_slot)
  206. {
  207. struct slot *slot = hotplug_slot->private;
  208. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  209. return pciehp_enable_slot(slot);
  210. }
  211. static int disable_slot(struct hotplug_slot *hotplug_slot)
  212. {
  213. struct slot *slot = hotplug_slot->private;
  214. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  215. return pciehp_disable_slot(slot);
  216. }
  217. static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
  218. {
  219. struct slot *slot = hotplug_slot->private;
  220. int retval;
  221. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  222. retval = slot->hpc_ops->get_power_status(slot, value);
  223. if (retval < 0)
  224. *value = hotplug_slot->info->power_status;
  225. return 0;
  226. }
  227. static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
  228. {
  229. struct slot *slot = hotplug_slot->private;
  230. int retval;
  231. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  232. retval = slot->hpc_ops->get_attention_status(slot, value);
  233. if (retval < 0)
  234. *value = hotplug_slot->info->attention_status;
  235. return 0;
  236. }
  237. static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
  238. {
  239. struct slot *slot = hotplug_slot->private;
  240. int retval;
  241. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  242. retval = slot->hpc_ops->get_latch_status(slot, value);
  243. if (retval < 0)
  244. *value = hotplug_slot->info->latch_status;
  245. return 0;
  246. }
  247. static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
  248. {
  249. struct slot *slot = hotplug_slot->private;
  250. int retval;
  251. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  252. retval = slot->hpc_ops->get_adapter_status(slot, value);
  253. if (retval < 0)
  254. *value = hotplug_slot->info->adapter_status;
  255. return 0;
  256. }
  257. static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
  258. {
  259. struct slot *slot = hotplug_slot->private;
  260. int retval;
  261. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  262. retval = slot->hpc_ops->get_max_bus_speed(slot, value);
  263. if (retval < 0)
  264. *value = PCI_SPEED_UNKNOWN;
  265. return 0;
  266. }
  267. static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
  268. {
  269. struct slot *slot = hotplug_slot->private;
  270. int retval;
  271. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  272. retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
  273. if (retval < 0)
  274. *value = PCI_SPEED_UNKNOWN;
  275. return 0;
  276. }
  277. static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_id *id)
  278. {
  279. int rc;
  280. struct controller *ctrl;
  281. struct slot *t_slot;
  282. int first_device_num = 0 ; /* first PCI device number supported by this PCIE */
  283. int num_ctlr_slots; /* number of slots supported by this HPC */
  284. u8 value;
  285. struct pci_dev *pdev;
  286. dbg("%s: Called by hp_drv\n", __FUNCTION__);
  287. ctrl = kmalloc(sizeof(*ctrl), GFP_KERNEL);
  288. if (!ctrl) {
  289. err("%s : out of memory\n", __FUNCTION__);
  290. goto err_out_none;
  291. }
  292. memset(ctrl, 0, sizeof(struct controller));
  293. dbg("%s: DRV_thread pid = %d\n", __FUNCTION__, current->pid);
  294. pdev = dev->port;
  295. rc = pcie_init(ctrl, dev,
  296. (php_intr_callback_t) pciehp_handle_attention_button,
  297. (php_intr_callback_t) pciehp_handle_switch_change,
  298. (php_intr_callback_t) pciehp_handle_presence_change,
  299. (php_intr_callback_t) pciehp_handle_power_fault);
  300. if (rc) {
  301. dbg("%s: controller initialization failed\n", PCIE_MODULE_NAME);
  302. goto err_out_free_ctrl;
  303. }
  304. ctrl->pci_dev = pdev;
  305. pci_set_drvdata(pdev, ctrl);
  306. ctrl->pci_bus = kmalloc(sizeof(*ctrl->pci_bus), GFP_KERNEL);
  307. if (!ctrl->pci_bus) {
  308. err("%s: out of memory\n", __FUNCTION__);
  309. rc = -ENOMEM;
  310. goto err_out_unmap_mmio_region;
  311. }
  312. dbg("%s: ctrl->pci_bus %p\n", __FUNCTION__, ctrl->pci_bus);
  313. memcpy (ctrl->pci_bus, pdev->bus, sizeof (*ctrl->pci_bus));
  314. ctrl->bus = pdev->bus->number; /* ctrl bus */
  315. ctrl->slot_bus = pdev->subordinate->number; /* bus controlled by this HPC */
  316. ctrl->device = PCI_SLOT(pdev->devfn);
  317. ctrl->function = PCI_FUNC(pdev->devfn);
  318. dbg("%s: ctrl bus=0x%x, device=%x, function=%x, irq=%x\n", __FUNCTION__,
  319. ctrl->bus, ctrl->device, ctrl->function, pdev->irq);
  320. /*
  321. * Save configuration headers for this and subordinate PCI buses
  322. */
  323. rc = get_ctlr_slot_config(ctrl);
  324. if (rc) {
  325. err(msg_initialization_err, rc);
  326. goto err_out_free_ctrl_bus;
  327. }
  328. first_device_num = ctrl->slot_device_offset;
  329. num_ctlr_slots = ctrl->num_slots;
  330. /* Store PCI Config Space for all devices on this bus */
  331. dbg("%s: Before calling pciehp_save_config, ctrl->bus %x,ctrl->slot_bus %x\n",
  332. __FUNCTION__,ctrl->bus, ctrl->slot_bus);
  333. rc = pciehp_save_config(ctrl, ctrl->slot_bus, num_ctlr_slots, first_device_num);
  334. if (rc) {
  335. err("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc);
  336. goto err_out_free_ctrl_bus;
  337. }
  338. /* Get IO, memory, and IRQ resources for new devices */
  339. rc = pciehprm_find_available_resources(ctrl);
  340. ctrl->add_support = !rc;
  341. if (rc) {
  342. dbg("pciehprm_find_available_resources = %#x\n", rc);
  343. err("unable to locate PCI configuration resources for hot plug add.\n");
  344. goto err_out_free_ctrl_bus;
  345. }
  346. /* Setup the slot information structures */
  347. rc = init_slots(ctrl);
  348. if (rc) {
  349. err(msg_initialization_err, 6);
  350. goto err_out_free_ctrl_slot;
  351. }
  352. t_slot = pciehp_find_slot(ctrl, first_device_num);
  353. dbg("%s: t_slot %p\n", __FUNCTION__, t_slot);
  354. /* Finish setting up the hot plug ctrl device */
  355. ctrl->next_event = 0;
  356. if (!pciehp_ctrl_list) {
  357. pciehp_ctrl_list = ctrl;
  358. ctrl->next = NULL;
  359. } else {
  360. ctrl->next = pciehp_ctrl_list;
  361. pciehp_ctrl_list = ctrl;
  362. }
  363. /* Wait for exclusive access to hardware */
  364. down(&ctrl->crit_sect);
  365. t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */
  366. dbg("%s: adpater value %x\n", __FUNCTION__, value);
  367. if ((POWER_CTRL(ctrl->ctrlcap)) && !value) {
  368. rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/
  369. if (rc) {
  370. /* Done with exclusive hardware access */
  371. up(&ctrl->crit_sect);
  372. goto err_out_free_ctrl_slot;
  373. } else
  374. /* Wait for the command to complete */
  375. wait_for_ctrl_irq (ctrl);
  376. }
  377. /* Done with exclusive hardware access */
  378. up(&ctrl->crit_sect);
  379. return 0;
  380. err_out_free_ctrl_slot:
  381. cleanup_slots(ctrl);
  382. err_out_free_ctrl_bus:
  383. kfree(ctrl->pci_bus);
  384. err_out_unmap_mmio_region:
  385. ctrl->hpc_ops->release_ctlr(ctrl);
  386. err_out_free_ctrl:
  387. kfree(ctrl);
  388. err_out_none:
  389. return -ENODEV;
  390. }
  391. static int pcie_start_thread(void)
  392. {
  393. int loop;
  394. int retval = 0;
  395. dbg("Initialize + Start the notification/polling mechanism \n");
  396. retval = pciehp_event_start_thread();
  397. if (retval) {
  398. dbg("pciehp_event_start_thread() failed\n");
  399. return retval;
  400. }
  401. dbg("Initialize slot lists\n");
  402. /* One slot list for each bus in the system */
  403. for (loop = 0; loop < 256; loop++) {
  404. pciehp_slot_list[loop] = NULL;
  405. }
  406. return retval;
  407. }
  408. static inline void __exit
  409. free_pciehp_res(struct pci_resource *res)
  410. {
  411. struct pci_resource *tres;
  412. while (res) {
  413. tres = res;
  414. res = res->next;
  415. kfree(tres);
  416. }
  417. }
  418. static void __exit unload_pciehpd(void)
  419. {
  420. struct pci_func *next;
  421. struct pci_func *TempSlot;
  422. int loop;
  423. struct controller *ctrl;
  424. struct controller *tctrl;
  425. ctrl = pciehp_ctrl_list;
  426. while (ctrl) {
  427. cleanup_slots(ctrl);
  428. free_pciehp_res(ctrl->io_head);
  429. free_pciehp_res(ctrl->mem_head);
  430. free_pciehp_res(ctrl->p_mem_head);
  431. free_pciehp_res(ctrl->bus_head);
  432. kfree (ctrl->pci_bus);
  433. ctrl->hpc_ops->release_ctlr(ctrl);
  434. tctrl = ctrl;
  435. ctrl = ctrl->next;
  436. kfree(tctrl);
  437. }
  438. for (loop = 0; loop < 256; loop++) {
  439. next = pciehp_slot_list[loop];
  440. while (next != NULL) {
  441. free_pciehp_res(next->io_head);
  442. free_pciehp_res(next->mem_head);
  443. free_pciehp_res(next->p_mem_head);
  444. free_pciehp_res(next->bus_head);
  445. TempSlot = next;
  446. next = next->next;
  447. kfree(TempSlot);
  448. }
  449. }
  450. /* Stop the notification mechanism */
  451. pciehp_event_stop_thread();
  452. }
  453. int hpdriver_context = 0;
  454. static void pciehp_remove (struct pcie_device *device)
  455. {
  456. printk("%s ENTRY\n", __FUNCTION__);
  457. printk("%s -> Call free_irq for irq = %d\n",
  458. __FUNCTION__, device->irq);
  459. free_irq(device->irq, &hpdriver_context);
  460. }
  461. #ifdef CONFIG_PM
  462. static int pciehp_suspend (struct pcie_device *dev, pm_message_t state)
  463. {
  464. printk("%s ENTRY\n", __FUNCTION__);
  465. return 0;
  466. }
  467. static int pciehp_resume (struct pcie_device *dev)
  468. {
  469. printk("%s ENTRY\n", __FUNCTION__);
  470. return 0;
  471. }
  472. #endif
  473. static struct pcie_port_service_id port_pci_ids[] = { {
  474. .vendor = PCI_ANY_ID,
  475. .device = PCI_ANY_ID,
  476. .port_type = PCIE_RC_PORT,
  477. .service_type = PCIE_PORT_SERVICE_HP,
  478. .driver_data = 0,
  479. }, { /* end: all zeroes */ }
  480. };
  481. static const char device_name[] = "hpdriver";
  482. static struct pcie_port_service_driver hpdriver_portdrv = {
  483. .name = (char *)device_name,
  484. .id_table = &port_pci_ids[0],
  485. .probe = pciehp_probe,
  486. .remove = pciehp_remove,
  487. #ifdef CONFIG_PM
  488. .suspend = pciehp_suspend,
  489. .resume = pciehp_resume,
  490. #endif /* PM */
  491. };
  492. static int __init pcied_init(void)
  493. {
  494. int retval = 0;
  495. #ifdef CONFIG_HOTPLUG_PCI_PCIE_POLL_EVENT_MODE
  496. pciehp_poll_mode = 1;
  497. #endif
  498. retval = pcie_start_thread();
  499. if (retval)
  500. goto error_hpc_init;
  501. retval = pciehprm_init(PCI);
  502. if (!retval) {
  503. retval = pcie_port_service_register(&hpdriver_portdrv);
  504. dbg("pcie_port_service_register = %d\n", retval);
  505. info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
  506. if (retval)
  507. dbg("%s: Failure to register service\n", __FUNCTION__);
  508. }
  509. error_hpc_init:
  510. if (retval) {
  511. pciehprm_cleanup();
  512. pciehp_event_stop_thread();
  513. } else
  514. pciehprm_print_pirt();
  515. return retval;
  516. }
  517. static void __exit pcied_cleanup(void)
  518. {
  519. dbg("unload_pciehpd()\n");
  520. unload_pciehpd();
  521. pciehprm_cleanup();
  522. dbg("pcie_port_service_unregister\n");
  523. pcie_port_service_unregister(&hpdriver_portdrv);
  524. info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
  525. }
  526. module_init(pcied_init);
  527. module_exit(pcied_cleanup);