pciehp_core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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>, <kristen.c.accardi@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. /**
  85. * release_slot - free up the memory used by a slot
  86. * @hotplug_slot: slot to free
  87. */
  88. static void release_slot(struct hotplug_slot *hotplug_slot)
  89. {
  90. struct slot *slot = hotplug_slot->private;
  91. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  92. kfree(slot->hotplug_slot->info);
  93. kfree(slot->hotplug_slot->name);
  94. kfree(slot->hotplug_slot);
  95. kfree(slot);
  96. }
  97. static int init_slots(struct controller *ctrl)
  98. {
  99. struct slot *new_slot;
  100. u8 number_of_slots;
  101. u8 slot_device;
  102. u32 slot_number;
  103. int result = -ENOMEM;
  104. dbg("%s\n",__FUNCTION__);
  105. number_of_slots = ctrl->num_slots;
  106. slot_device = ctrl->slot_device_offset;
  107. slot_number = ctrl->first_slot;
  108. while (number_of_slots) {
  109. new_slot = kmalloc(sizeof(*new_slot), GFP_KERNEL);
  110. if (!new_slot)
  111. goto error;
  112. memset(new_slot, 0, sizeof(struct slot));
  113. new_slot->hotplug_slot =
  114. kmalloc(sizeof(*(new_slot->hotplug_slot)),
  115. GFP_KERNEL);
  116. if (!new_slot->hotplug_slot)
  117. goto error_slot;
  118. memset(new_slot->hotplug_slot, 0, sizeof(struct hotplug_slot));
  119. new_slot->hotplug_slot->info =
  120. kmalloc(sizeof(*(new_slot->hotplug_slot->info)),
  121. GFP_KERNEL);
  122. if (!new_slot->hotplug_slot->info)
  123. goto error_hpslot;
  124. memset(new_slot->hotplug_slot->info, 0,
  125. sizeof(struct hotplug_slot_info));
  126. new_slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE,
  127. GFP_KERNEL);
  128. if (!new_slot->hotplug_slot->name)
  129. goto error_info;
  130. new_slot->ctrl = ctrl;
  131. new_slot->bus = ctrl->slot_bus;
  132. new_slot->device = slot_device;
  133. new_slot->hpc_ops = ctrl->hpc_ops;
  134. new_slot->number = ctrl->first_slot;
  135. new_slot->hp_slot = slot_device - ctrl->slot_device_offset;
  136. /* register this slot with the hotplug pci core */
  137. new_slot->hotplug_slot->private = new_slot;
  138. new_slot->hotplug_slot->release = &release_slot;
  139. make_slot_name(new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot);
  140. new_slot->hotplug_slot->ops = &pciehp_hotplug_slot_ops;
  141. new_slot->hpc_ops->get_power_status(new_slot, &(new_slot->hotplug_slot->info->power_status));
  142. new_slot->hpc_ops->get_attention_status(new_slot, &(new_slot->hotplug_slot->info->attention_status));
  143. new_slot->hpc_ops->get_latch_status(new_slot, &(new_slot->hotplug_slot->info->latch_status));
  144. new_slot->hpc_ops->get_adapter_status(new_slot, &(new_slot->hotplug_slot->info->adapter_status));
  145. dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x slot_device_offset=%x\n",
  146. new_slot->bus, new_slot->device, new_slot->hp_slot, new_slot->number, ctrl->slot_device_offset);
  147. result = pci_hp_register (new_slot->hotplug_slot);
  148. if (result) {
  149. err ("pci_hp_register failed with error %d\n", result);
  150. goto error_name;
  151. }
  152. new_slot->next = ctrl->slot;
  153. ctrl->slot = new_slot;
  154. number_of_slots--;
  155. slot_device++;
  156. slot_number += ctrl->slot_num_inc;
  157. }
  158. return 0;
  159. error_name:
  160. kfree(new_slot->hotplug_slot->name);
  161. error_info:
  162. kfree(new_slot->hotplug_slot->info);
  163. error_hpslot:
  164. kfree(new_slot->hotplug_slot);
  165. error_slot:
  166. kfree(new_slot);
  167. error:
  168. return result;
  169. }
  170. static int cleanup_slots (struct controller * ctrl)
  171. {
  172. struct slot *old_slot, *next_slot;
  173. old_slot = ctrl->slot;
  174. ctrl->slot = NULL;
  175. while (old_slot) {
  176. next_slot = old_slot->next;
  177. pci_hp_deregister (old_slot->hotplug_slot);
  178. old_slot = next_slot;
  179. }
  180. return(0);
  181. }
  182. static int get_ctlr_slot_config(struct controller *ctrl)
  183. {
  184. int num_ctlr_slots; /* Not needed; PCI Express has 1 slot per port*/
  185. int first_device_num; /* Not needed */
  186. int physical_slot_num;
  187. u8 ctrlcap;
  188. int rc;
  189. rc = pcie_get_ctlr_slot_config(ctrl, &num_ctlr_slots, &first_device_num, &physical_slot_num, &ctrlcap);
  190. if (rc) {
  191. err("%s: get_ctlr_slot_config fail for b:d (%x:%x)\n", __FUNCTION__, ctrl->bus, ctrl->device);
  192. return (-1);
  193. }
  194. ctrl->num_slots = num_ctlr_slots; /* PCI Express has 1 slot per port */
  195. ctrl->slot_device_offset = first_device_num;
  196. ctrl->first_slot = physical_slot_num;
  197. ctrl->ctrlcap = ctrlcap;
  198. dbg("%s: bus(0x%x) num_slot(0x%x) 1st_dev(0x%x) psn(0x%x) ctrlcap(%x) for b:d (%x:%x)\n",
  199. __FUNCTION__, ctrl->slot_bus, num_ctlr_slots, first_device_num, physical_slot_num, ctrlcap,
  200. ctrl->bus, ctrl->device);
  201. return (0);
  202. }
  203. /*
  204. * set_attention_status - Turns the Amber LED for a slot on, off or blink
  205. */
  206. static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
  207. {
  208. struct slot *slot = hotplug_slot->private;
  209. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  210. hotplug_slot->info->attention_status = status;
  211. if (ATTN_LED(slot->ctrl->ctrlcap))
  212. slot->hpc_ops->set_attention_status(slot, status);
  213. return 0;
  214. }
  215. static int enable_slot(struct hotplug_slot *hotplug_slot)
  216. {
  217. struct slot *slot = hotplug_slot->private;
  218. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  219. return pciehp_enable_slot(slot);
  220. }
  221. static int disable_slot(struct hotplug_slot *hotplug_slot)
  222. {
  223. struct slot *slot = hotplug_slot->private;
  224. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  225. return pciehp_disable_slot(slot);
  226. }
  227. static int get_power_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_power_status(slot, value);
  233. if (retval < 0)
  234. *value = hotplug_slot->info->power_status;
  235. return 0;
  236. }
  237. static int get_attention_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_attention_status(slot, value);
  243. if (retval < 0)
  244. *value = hotplug_slot->info->attention_status;
  245. return 0;
  246. }
  247. static int get_latch_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_latch_status(slot, value);
  253. if (retval < 0)
  254. *value = hotplug_slot->info->latch_status;
  255. return 0;
  256. }
  257. static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *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_adapter_status(slot, value);
  263. if (retval < 0)
  264. *value = hotplug_slot->info->adapter_status;
  265. return 0;
  266. }
  267. static int get_max_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_max_bus_speed(slot, value);
  273. if (retval < 0)
  274. *value = PCI_SPEED_UNKNOWN;
  275. return 0;
  276. }
  277. static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
  278. {
  279. struct slot *slot = hotplug_slot->private;
  280. int retval;
  281. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  282. retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
  283. if (retval < 0)
  284. *value = PCI_SPEED_UNKNOWN;
  285. return 0;
  286. }
  287. static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_id *id)
  288. {
  289. int rc;
  290. struct controller *ctrl;
  291. struct slot *t_slot;
  292. int first_device_num = 0 ; /* first PCI device number supported by this PCIE */
  293. int num_ctlr_slots; /* number of slots supported by this HPC */
  294. u8 value;
  295. struct pci_dev *pdev;
  296. dbg("%s: Called by hp_drv\n", __FUNCTION__);
  297. ctrl = kmalloc(sizeof(*ctrl), GFP_KERNEL);
  298. if (!ctrl) {
  299. err("%s : out of memory\n", __FUNCTION__);
  300. goto err_out_none;
  301. }
  302. memset(ctrl, 0, sizeof(struct controller));
  303. dbg("%s: DRV_thread pid = %d\n", __FUNCTION__, current->pid);
  304. pdev = dev->port;
  305. rc = pcie_init(ctrl, dev,
  306. (php_intr_callback_t) pciehp_handle_attention_button,
  307. (php_intr_callback_t) pciehp_handle_switch_change,
  308. (php_intr_callback_t) pciehp_handle_presence_change,
  309. (php_intr_callback_t) pciehp_handle_power_fault);
  310. if (rc) {
  311. dbg("%s: controller initialization failed\n", PCIE_MODULE_NAME);
  312. goto err_out_free_ctrl;
  313. }
  314. ctrl->pci_dev = pdev;
  315. pci_set_drvdata(pdev, ctrl);
  316. ctrl->pci_bus = kmalloc(sizeof(*ctrl->pci_bus), GFP_KERNEL);
  317. if (!ctrl->pci_bus) {
  318. err("%s: out of memory\n", __FUNCTION__);
  319. rc = -ENOMEM;
  320. goto err_out_unmap_mmio_region;
  321. }
  322. dbg("%s: ctrl->pci_bus %p\n", __FUNCTION__, ctrl->pci_bus);
  323. memcpy (ctrl->pci_bus, pdev->bus, sizeof (*ctrl->pci_bus));
  324. ctrl->bus = pdev->bus->number; /* ctrl bus */
  325. ctrl->slot_bus = pdev->subordinate->number; /* bus controlled by this HPC */
  326. ctrl->device = PCI_SLOT(pdev->devfn);
  327. ctrl->function = PCI_FUNC(pdev->devfn);
  328. dbg("%s: ctrl bus=0x%x, device=%x, function=%x, irq=%x\n", __FUNCTION__,
  329. ctrl->bus, ctrl->device, ctrl->function, pdev->irq);
  330. /*
  331. * Save configuration headers for this and subordinate PCI buses
  332. */
  333. rc = get_ctlr_slot_config(ctrl);
  334. if (rc) {
  335. err(msg_initialization_err, rc);
  336. goto err_out_free_ctrl_bus;
  337. }
  338. first_device_num = ctrl->slot_device_offset;
  339. num_ctlr_slots = ctrl->num_slots;
  340. /* Store PCI Config Space for all devices on this bus */
  341. dbg("%s: Before calling pciehp_save_config, ctrl->bus %x,ctrl->slot_bus %x\n",
  342. __FUNCTION__,ctrl->bus, ctrl->slot_bus);
  343. rc = pciehp_save_config(ctrl, ctrl->slot_bus, num_ctlr_slots, first_device_num);
  344. if (rc) {
  345. err("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc);
  346. goto err_out_free_ctrl_bus;
  347. }
  348. /* Get IO, memory, and IRQ resources for new devices */
  349. rc = pciehprm_find_available_resources(ctrl);
  350. ctrl->add_support = !rc;
  351. if (rc) {
  352. dbg("pciehprm_find_available_resources = %#x\n", rc);
  353. err("unable to locate PCI configuration resources for hot plug add.\n");
  354. goto err_out_free_ctrl_bus;
  355. }
  356. /* Setup the slot information structures */
  357. rc = init_slots(ctrl);
  358. if (rc) {
  359. err(msg_initialization_err, 6);
  360. goto err_out_free_ctrl_slot;
  361. }
  362. t_slot = pciehp_find_slot(ctrl, first_device_num);
  363. dbg("%s: t_slot %p\n", __FUNCTION__, t_slot);
  364. /* Finish setting up the hot plug ctrl device */
  365. ctrl->next_event = 0;
  366. if (!pciehp_ctrl_list) {
  367. pciehp_ctrl_list = ctrl;
  368. ctrl->next = NULL;
  369. } else {
  370. ctrl->next = pciehp_ctrl_list;
  371. pciehp_ctrl_list = ctrl;
  372. }
  373. /* Wait for exclusive access to hardware */
  374. down(&ctrl->crit_sect);
  375. t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */
  376. dbg("%s: adpater value %x\n", __FUNCTION__, value);
  377. if ((POWER_CTRL(ctrl->ctrlcap)) && !value) {
  378. rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/
  379. if (rc) {
  380. /* Done with exclusive hardware access */
  381. up(&ctrl->crit_sect);
  382. goto err_out_free_ctrl_slot;
  383. } else
  384. /* Wait for the command to complete */
  385. wait_for_ctrl_irq (ctrl);
  386. }
  387. /* Done with exclusive hardware access */
  388. up(&ctrl->crit_sect);
  389. return 0;
  390. err_out_free_ctrl_slot:
  391. cleanup_slots(ctrl);
  392. err_out_free_ctrl_bus:
  393. kfree(ctrl->pci_bus);
  394. err_out_unmap_mmio_region:
  395. ctrl->hpc_ops->release_ctlr(ctrl);
  396. err_out_free_ctrl:
  397. kfree(ctrl);
  398. err_out_none:
  399. return -ENODEV;
  400. }
  401. static int pcie_start_thread(void)
  402. {
  403. int loop;
  404. int retval = 0;
  405. dbg("Initialize + Start the notification/polling mechanism \n");
  406. retval = pciehp_event_start_thread();
  407. if (retval) {
  408. dbg("pciehp_event_start_thread() failed\n");
  409. return retval;
  410. }
  411. dbg("Initialize slot lists\n");
  412. /* One slot list for each bus in the system */
  413. for (loop = 0; loop < 256; loop++) {
  414. pciehp_slot_list[loop] = NULL;
  415. }
  416. return retval;
  417. }
  418. static inline void __exit
  419. free_pciehp_res(struct pci_resource *res)
  420. {
  421. struct pci_resource *tres;
  422. while (res) {
  423. tres = res;
  424. res = res->next;
  425. kfree(tres);
  426. }
  427. }
  428. static void __exit unload_pciehpd(void)
  429. {
  430. struct pci_func *next;
  431. struct pci_func *TempSlot;
  432. int loop;
  433. struct controller *ctrl;
  434. struct controller *tctrl;
  435. ctrl = pciehp_ctrl_list;
  436. while (ctrl) {
  437. cleanup_slots(ctrl);
  438. free_pciehp_res(ctrl->io_head);
  439. free_pciehp_res(ctrl->mem_head);
  440. free_pciehp_res(ctrl->p_mem_head);
  441. free_pciehp_res(ctrl->bus_head);
  442. kfree (ctrl->pci_bus);
  443. ctrl->hpc_ops->release_ctlr(ctrl);
  444. tctrl = ctrl;
  445. ctrl = ctrl->next;
  446. kfree(tctrl);
  447. }
  448. for (loop = 0; loop < 256; loop++) {
  449. next = pciehp_slot_list[loop];
  450. while (next != NULL) {
  451. free_pciehp_res(next->io_head);
  452. free_pciehp_res(next->mem_head);
  453. free_pciehp_res(next->p_mem_head);
  454. free_pciehp_res(next->bus_head);
  455. TempSlot = next;
  456. next = next->next;
  457. kfree(TempSlot);
  458. }
  459. }
  460. /* Stop the notification mechanism */
  461. pciehp_event_stop_thread();
  462. }
  463. int hpdriver_context = 0;
  464. static void pciehp_remove (struct pcie_device *device)
  465. {
  466. printk("%s ENTRY\n", __FUNCTION__);
  467. printk("%s -> Call free_irq for irq = %d\n",
  468. __FUNCTION__, device->irq);
  469. free_irq(device->irq, &hpdriver_context);
  470. }
  471. #ifdef CONFIG_PM
  472. static int pciehp_suspend (struct pcie_device *dev, pm_message_t state)
  473. {
  474. printk("%s ENTRY\n", __FUNCTION__);
  475. return 0;
  476. }
  477. static int pciehp_resume (struct pcie_device *dev)
  478. {
  479. printk("%s ENTRY\n", __FUNCTION__);
  480. return 0;
  481. }
  482. #endif
  483. static struct pcie_port_service_id port_pci_ids[] = { {
  484. .vendor = PCI_ANY_ID,
  485. .device = PCI_ANY_ID,
  486. .port_type = PCIE_ANY_PORT,
  487. .service_type = PCIE_PORT_SERVICE_HP,
  488. .driver_data = 0,
  489. }, { /* end: all zeroes */ }
  490. };
  491. static const char device_name[] = "hpdriver";
  492. static struct pcie_port_service_driver hpdriver_portdrv = {
  493. .name = (char *)device_name,
  494. .id_table = &port_pci_ids[0],
  495. .probe = pciehp_probe,
  496. .remove = pciehp_remove,
  497. #ifdef CONFIG_PM
  498. .suspend = pciehp_suspend,
  499. .resume = pciehp_resume,
  500. #endif /* PM */
  501. };
  502. static int __init pcied_init(void)
  503. {
  504. int retval = 0;
  505. #ifdef CONFIG_HOTPLUG_PCI_PCIE_POLL_EVENT_MODE
  506. pciehp_poll_mode = 1;
  507. #endif
  508. retval = pcie_start_thread();
  509. if (retval)
  510. goto error_hpc_init;
  511. retval = pciehprm_init(PCI);
  512. if (!retval) {
  513. retval = pcie_port_service_register(&hpdriver_portdrv);
  514. dbg("pcie_port_service_register = %d\n", retval);
  515. info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
  516. if (retval)
  517. dbg("%s: Failure to register service\n", __FUNCTION__);
  518. }
  519. error_hpc_init:
  520. if (retval) {
  521. pciehprm_cleanup();
  522. pciehp_event_stop_thread();
  523. } else
  524. pciehprm_print_pirt();
  525. return retval;
  526. }
  527. static void __exit pcied_cleanup(void)
  528. {
  529. dbg("unload_pciehpd()\n");
  530. unload_pciehpd();
  531. pciehprm_cleanup();
  532. dbg("pcie_port_service_unregister\n");
  533. pcie_port_service_unregister(&hpdriver_portdrv);
  534. info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
  535. }
  536. module_init(pcied_init);
  537. module_exit(pcied_cleanup);