cpci_hotplug_core.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. /*
  2. * CompactPCI Hot Plug Driver
  3. *
  4. * Copyright (C) 2002,2005 SOMA Networks, Inc.
  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 <scottm@somanetworks.com>
  26. */
  27. #include <linux/config.h>
  28. #include <linux/module.h>
  29. #include <linux/kernel.h>
  30. #include <linux/slab.h>
  31. #include <linux/pci.h>
  32. #include <linux/init.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/smp_lock.h>
  35. #include <asm/atomic.h>
  36. #include <linux/delay.h>
  37. #include "pci_hotplug.h"
  38. #include "cpci_hotplug.h"
  39. #define DRIVER_AUTHOR "Scott Murray <scottm@somanetworks.com>"
  40. #define DRIVER_DESC "CompactPCI Hot Plug Core"
  41. #define MY_NAME "cpci_hotplug"
  42. #define dbg(format, arg...) \
  43. do { \
  44. if (cpci_debug) \
  45. printk (KERN_DEBUG "%s: " format "\n", \
  46. MY_NAME , ## arg); \
  47. } while (0)
  48. #define err(format, arg...) printk(KERN_ERR "%s: " format "\n", MY_NAME , ## arg)
  49. #define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME , ## arg)
  50. #define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME , ## arg)
  51. /* local variables */
  52. static DECLARE_RWSEM(list_rwsem);
  53. static LIST_HEAD(slot_list);
  54. static int slots;
  55. static atomic_t extracting;
  56. int cpci_debug;
  57. static struct cpci_hp_controller *controller;
  58. static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
  59. static struct semaphore thread_exit; /* guard ensure thread has exited before calling it quits */
  60. static int thread_finished = 1;
  61. static int enable_slot(struct hotplug_slot *slot);
  62. static int disable_slot(struct hotplug_slot *slot);
  63. static int set_attention_status(struct hotplug_slot *slot, u8 value);
  64. static int get_power_status(struct hotplug_slot *slot, u8 * value);
  65. static int get_attention_status(struct hotplug_slot *slot, u8 * value);
  66. static int get_adapter_status(struct hotplug_slot *slot, u8 * value);
  67. static int get_latch_status(struct hotplug_slot *slot, u8 * value);
  68. static struct hotplug_slot_ops cpci_hotplug_slot_ops = {
  69. .owner = THIS_MODULE,
  70. .enable_slot = enable_slot,
  71. .disable_slot = disable_slot,
  72. .set_attention_status = set_attention_status,
  73. .get_power_status = get_power_status,
  74. .get_attention_status = get_attention_status,
  75. .get_adapter_status = get_adapter_status,
  76. .get_latch_status = get_latch_status,
  77. };
  78. static int
  79. update_latch_status(struct hotplug_slot *hotplug_slot, u8 value)
  80. {
  81. struct hotplug_slot_info info;
  82. memcpy(&info, hotplug_slot->info, sizeof(struct hotplug_slot_info));
  83. info.latch_status = value;
  84. return pci_hp_change_slot_info(hotplug_slot, &info);
  85. }
  86. static int
  87. update_adapter_status(struct hotplug_slot *hotplug_slot, u8 value)
  88. {
  89. struct hotplug_slot_info info;
  90. memcpy(&info, hotplug_slot->info, sizeof(struct hotplug_slot_info));
  91. info.adapter_status = value;
  92. return pci_hp_change_slot_info(hotplug_slot, &info);
  93. }
  94. static int
  95. enable_slot(struct hotplug_slot *hotplug_slot)
  96. {
  97. struct slot *slot = hotplug_slot->private;
  98. int retval = 0;
  99. dbg("%s - physical_slot = %s", __FUNCTION__, hotplug_slot->name);
  100. if (controller->ops->set_power)
  101. retval = controller->ops->set_power(slot, 1);
  102. return retval;
  103. }
  104. static int
  105. disable_slot(struct hotplug_slot *hotplug_slot)
  106. {
  107. struct slot *slot = hotplug_slot->private;
  108. int retval = 0;
  109. dbg("%s - physical_slot = %s", __FUNCTION__, hotplug_slot->name);
  110. down_write(&list_rwsem);
  111. /* Unconfigure device */
  112. dbg("%s - unconfiguring slot %s",
  113. __FUNCTION__, slot->hotplug_slot->name);
  114. if ((retval = cpci_unconfigure_slot(slot))) {
  115. err("%s - could not unconfigure slot %s",
  116. __FUNCTION__, slot->hotplug_slot->name);
  117. goto disable_error;
  118. }
  119. dbg("%s - finished unconfiguring slot %s",
  120. __FUNCTION__, slot->hotplug_slot->name);
  121. /* Clear EXT (by setting it) */
  122. if (cpci_clear_ext(slot)) {
  123. err("%s - could not clear EXT for slot %s",
  124. __FUNCTION__, slot->hotplug_slot->name);
  125. retval = -ENODEV;
  126. goto disable_error;
  127. }
  128. cpci_led_on(slot);
  129. if (controller->ops->set_power)
  130. if ((retval = controller->ops->set_power(slot, 0)))
  131. goto disable_error;
  132. if (update_adapter_status(slot->hotplug_slot, 0))
  133. warn("failure to update adapter file");
  134. if (slot->extracting) {
  135. slot->extracting = 0;
  136. atomic_dec(&extracting);
  137. }
  138. disable_error:
  139. up_write(&list_rwsem);
  140. return retval;
  141. }
  142. static u8
  143. cpci_get_power_status(struct slot *slot)
  144. {
  145. u8 power = 1;
  146. if (controller->ops->get_power)
  147. power = controller->ops->get_power(slot);
  148. return power;
  149. }
  150. static int
  151. get_power_status(struct hotplug_slot *hotplug_slot, u8 * value)
  152. {
  153. struct slot *slot = hotplug_slot->private;
  154. *value = cpci_get_power_status(slot);
  155. return 0;
  156. }
  157. static int
  158. get_attention_status(struct hotplug_slot *hotplug_slot, u8 * value)
  159. {
  160. struct slot *slot = hotplug_slot->private;
  161. *value = cpci_get_attention_status(slot);
  162. return 0;
  163. }
  164. static int
  165. set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
  166. {
  167. return cpci_set_attention_status(hotplug_slot->private, status);
  168. }
  169. static int
  170. get_adapter_status(struct hotplug_slot *hotplug_slot, u8 * value)
  171. {
  172. *value = hotplug_slot->info->adapter_status;
  173. return 0;
  174. }
  175. static int
  176. get_latch_status(struct hotplug_slot *hotplug_slot, u8 * value)
  177. {
  178. *value = hotplug_slot->info->latch_status;
  179. return 0;
  180. }
  181. static void release_slot(struct hotplug_slot *hotplug_slot)
  182. {
  183. struct slot *slot = hotplug_slot->private;
  184. kfree(slot->hotplug_slot->info);
  185. kfree(slot->hotplug_slot->name);
  186. kfree(slot->hotplug_slot);
  187. if (slot->dev)
  188. pci_dev_put(slot->dev);
  189. kfree(slot);
  190. }
  191. #define SLOT_NAME_SIZE 6
  192. static void
  193. make_slot_name(struct slot *slot)
  194. {
  195. snprintf(slot->hotplug_slot->name,
  196. SLOT_NAME_SIZE, "%02x:%02x", slot->bus->number, slot->number);
  197. }
  198. int
  199. cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
  200. {
  201. struct slot *slot;
  202. struct hotplug_slot *hotplug_slot;
  203. struct hotplug_slot_info *info;
  204. char *name;
  205. int status = -ENOMEM;
  206. int i;
  207. if (!(controller && bus))
  208. return -ENODEV;
  209. /*
  210. * Create a structure for each slot, and register that slot
  211. * with the pci_hotplug subsystem.
  212. */
  213. for (i = first; i <= last; ++i) {
  214. slot = kzalloc(sizeof (struct slot), GFP_KERNEL);
  215. if (!slot)
  216. goto error;
  217. hotplug_slot =
  218. kzalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
  219. if (!hotplug_slot)
  220. goto error_slot;
  221. slot->hotplug_slot = hotplug_slot;
  222. info = kzalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL);
  223. if (!info)
  224. goto error_hpslot;
  225. hotplug_slot->info = info;
  226. name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
  227. if (!name)
  228. goto error_info;
  229. hotplug_slot->name = name;
  230. slot->bus = bus;
  231. slot->number = i;
  232. slot->devfn = PCI_DEVFN(i, 0);
  233. hotplug_slot->private = slot;
  234. hotplug_slot->release = &release_slot;
  235. make_slot_name(slot);
  236. hotplug_slot->ops = &cpci_hotplug_slot_ops;
  237. /*
  238. * Initialize the slot info structure with some known
  239. * good values.
  240. */
  241. dbg("initializing slot %s", slot->hotplug_slot->name);
  242. info->power_status = cpci_get_power_status(slot);
  243. info->attention_status = cpci_get_attention_status(slot);
  244. dbg("registering slot %s", slot->hotplug_slot->name);
  245. status = pci_hp_register(slot->hotplug_slot);
  246. if (status) {
  247. err("pci_hp_register failed with error %d", status);
  248. goto error_name;
  249. }
  250. /* Add slot to our internal list */
  251. down_write(&list_rwsem);
  252. list_add(&slot->slot_list, &slot_list);
  253. slots++;
  254. up_write(&list_rwsem);
  255. }
  256. return 0;
  257. error_name:
  258. kfree(name);
  259. error_info:
  260. kfree(info);
  261. error_hpslot:
  262. kfree(hotplug_slot);
  263. error_slot:
  264. kfree(slot);
  265. error:
  266. return status;
  267. }
  268. int
  269. cpci_hp_unregister_bus(struct pci_bus *bus)
  270. {
  271. struct slot *slot;
  272. struct slot *tmp;
  273. int status = 0;
  274. down_write(&list_rwsem);
  275. if (!slots) {
  276. up_write(&list_rwsem);
  277. return -1;
  278. }
  279. list_for_each_entry_safe(slot, tmp, &slot_list, slot_list) {
  280. if (slot->bus == bus) {
  281. list_del(&slot->slot_list);
  282. slots--;
  283. dbg("deregistering slot %s", slot->hotplug_slot->name);
  284. status = pci_hp_deregister(slot->hotplug_slot);
  285. if (status) {
  286. err("pci_hp_deregister failed with error %d",
  287. status);
  288. break;
  289. }
  290. }
  291. }
  292. up_write(&list_rwsem);
  293. return status;
  294. }
  295. /* This is the interrupt mode interrupt handler */
  296. static irqreturn_t
  297. cpci_hp_intr(int irq, void *data, struct pt_regs *regs)
  298. {
  299. dbg("entered cpci_hp_intr");
  300. /* Check to see if it was our interrupt */
  301. if ((controller->irq_flags & SA_SHIRQ) &&
  302. !controller->ops->check_irq(controller->dev_id)) {
  303. dbg("exited cpci_hp_intr, not our interrupt");
  304. return IRQ_NONE;
  305. }
  306. /* Disable ENUM interrupt */
  307. controller->ops->disable_irq();
  308. /* Trigger processing by the event thread */
  309. dbg("Signal event_semaphore");
  310. up(&event_semaphore);
  311. dbg("exited cpci_hp_intr");
  312. return IRQ_HANDLED;
  313. }
  314. /*
  315. * According to PICMG 2.1 R2.0, section 6.3.2, upon
  316. * initialization, the system driver shall clear the
  317. * INS bits of the cold-inserted devices.
  318. */
  319. static int
  320. init_slots(int clear_ins)
  321. {
  322. struct slot *slot;
  323. struct pci_dev* dev;
  324. dbg("%s - enter", __FUNCTION__);
  325. down_read(&list_rwsem);
  326. if (!slots) {
  327. up_read(&list_rwsem);
  328. return -1;
  329. }
  330. list_for_each_entry(slot, &slot_list, slot_list) {
  331. dbg("%s - looking at slot %s",
  332. __FUNCTION__, slot->hotplug_slot->name);
  333. if (clear_ins && cpci_check_and_clear_ins(slot))
  334. dbg("%s - cleared INS for slot %s",
  335. __FUNCTION__, slot->hotplug_slot->name);
  336. dev = pci_get_slot(slot->bus, PCI_DEVFN(slot->number, 0));
  337. if (dev) {
  338. if (update_adapter_status(slot->hotplug_slot, 1))
  339. warn("failure to update adapter file");
  340. if (update_latch_status(slot->hotplug_slot, 1))
  341. warn("failure to update latch file");
  342. slot->dev = dev;
  343. }
  344. }
  345. up_read(&list_rwsem);
  346. dbg("%s - exit", __FUNCTION__);
  347. return 0;
  348. }
  349. static int
  350. check_slots(void)
  351. {
  352. struct slot *slot;
  353. int extracted;
  354. int inserted;
  355. u16 hs_csr;
  356. down_read(&list_rwsem);
  357. if (!slots) {
  358. up_read(&list_rwsem);
  359. err("no slots registered, shutting down");
  360. return -1;
  361. }
  362. extracted = inserted = 0;
  363. list_for_each_entry(slot, &slot_list, slot_list) {
  364. dbg("%s - looking at slot %s",
  365. __FUNCTION__, slot->hotplug_slot->name);
  366. if (cpci_check_and_clear_ins(slot)) {
  367. /*
  368. * Some broken hardware (e.g. PLX 9054AB) asserts
  369. * ENUM# twice...
  370. */
  371. if (slot->dev) {
  372. warn("slot %s already inserted",
  373. slot->hotplug_slot->name);
  374. inserted++;
  375. continue;
  376. }
  377. /* Process insertion */
  378. dbg("%s - slot %s inserted",
  379. __FUNCTION__, slot->hotplug_slot->name);
  380. /* GSM, debug */
  381. hs_csr = cpci_get_hs_csr(slot);
  382. dbg("%s - slot %s HS_CSR (1) = %04x",
  383. __FUNCTION__, slot->hotplug_slot->name, hs_csr);
  384. /* Configure device */
  385. dbg("%s - configuring slot %s",
  386. __FUNCTION__, slot->hotplug_slot->name);
  387. if (cpci_configure_slot(slot)) {
  388. err("%s - could not configure slot %s",
  389. __FUNCTION__, slot->hotplug_slot->name);
  390. continue;
  391. }
  392. dbg("%s - finished configuring slot %s",
  393. __FUNCTION__, slot->hotplug_slot->name);
  394. /* GSM, debug */
  395. hs_csr = cpci_get_hs_csr(slot);
  396. dbg("%s - slot %s HS_CSR (2) = %04x",
  397. __FUNCTION__, slot->hotplug_slot->name, hs_csr);
  398. if (update_latch_status(slot->hotplug_slot, 1))
  399. warn("failure to update latch file");
  400. if (update_adapter_status(slot->hotplug_slot, 1))
  401. warn("failure to update adapter file");
  402. cpci_led_off(slot);
  403. /* GSM, debug */
  404. hs_csr = cpci_get_hs_csr(slot);
  405. dbg("%s - slot %s HS_CSR (3) = %04x",
  406. __FUNCTION__, slot->hotplug_slot->name, hs_csr);
  407. inserted++;
  408. } else if (cpci_check_ext(slot)) {
  409. /* Process extraction request */
  410. dbg("%s - slot %s extracted",
  411. __FUNCTION__, slot->hotplug_slot->name);
  412. /* GSM, debug */
  413. hs_csr = cpci_get_hs_csr(slot);
  414. dbg("%s - slot %s HS_CSR = %04x",
  415. __FUNCTION__, slot->hotplug_slot->name, hs_csr);
  416. if (!slot->extracting) {
  417. if (update_latch_status(slot->hotplug_slot, 0)) {
  418. warn("failure to update latch file");
  419. }
  420. slot->extracting = 1;
  421. atomic_inc(&extracting);
  422. }
  423. extracted++;
  424. } else if (slot->extracting) {
  425. hs_csr = cpci_get_hs_csr(slot);
  426. if (hs_csr == 0xffff) {
  427. /*
  428. * Hmmm, we're likely hosed at this point, should we
  429. * bother trying to tell the driver or not?
  430. */
  431. err("card in slot %s was improperly removed",
  432. slot->hotplug_slot->name);
  433. if (update_adapter_status(slot->hotplug_slot, 0))
  434. warn("failure to update adapter file");
  435. slot->extracting = 0;
  436. atomic_dec(&extracting);
  437. }
  438. }
  439. }
  440. up_read(&list_rwsem);
  441. dbg("inserted=%d, extracted=%d, extracting=%d",
  442. inserted, extracted, atomic_read(&extracting));
  443. if (inserted || extracted)
  444. return extracted;
  445. else if (!atomic_read(&extracting)) {
  446. err("cannot find ENUM# source, shutting down");
  447. return -1;
  448. }
  449. return 0;
  450. }
  451. /* This is the interrupt mode worker thread body */
  452. static int
  453. event_thread(void *data)
  454. {
  455. int rc;
  456. lock_kernel();
  457. daemonize("cpci_hp_eventd");
  458. unlock_kernel();
  459. dbg("%s - event thread started", __FUNCTION__);
  460. while (1) {
  461. dbg("event thread sleeping");
  462. down_interruptible(&event_semaphore);
  463. dbg("event thread woken, thread_finished = %d",
  464. thread_finished);
  465. if (thread_finished || signal_pending(current))
  466. break;
  467. do {
  468. rc = check_slots();
  469. if (rc > 0) {
  470. /* Give userspace a chance to handle extraction */
  471. msleep(500);
  472. } else if (rc < 0) {
  473. dbg("%s - error checking slots", __FUNCTION__);
  474. thread_finished = 1;
  475. break;
  476. }
  477. } while (atomic_read(&extracting) && !thread_finished);
  478. if (thread_finished)
  479. break;
  480. /* Re-enable ENUM# interrupt */
  481. dbg("%s - re-enabling irq", __FUNCTION__);
  482. controller->ops->enable_irq();
  483. }
  484. dbg("%s - event thread signals exit", __FUNCTION__);
  485. up(&thread_exit);
  486. return 0;
  487. }
  488. /* This is the polling mode worker thread body */
  489. static int
  490. poll_thread(void *data)
  491. {
  492. int rc;
  493. lock_kernel();
  494. daemonize("cpci_hp_polld");
  495. unlock_kernel();
  496. while (1) {
  497. if (thread_finished || signal_pending(current))
  498. break;
  499. if (controller->ops->query_enum()) {
  500. do {
  501. rc = check_slots();
  502. if (rc > 0) {
  503. /* Give userspace a chance to handle extraction */
  504. msleep(500);
  505. } else if (rc < 0) {
  506. dbg("%s - error checking slots", __FUNCTION__);
  507. thread_finished = 1;
  508. break;
  509. }
  510. } while (atomic_read(&extracting) && !thread_finished);
  511. }
  512. msleep(100);
  513. }
  514. dbg("poll thread signals exit");
  515. up(&thread_exit);
  516. return 0;
  517. }
  518. static int
  519. cpci_start_thread(void)
  520. {
  521. int pid;
  522. /* initialize our semaphores */
  523. init_MUTEX_LOCKED(&event_semaphore);
  524. init_MUTEX_LOCKED(&thread_exit);
  525. thread_finished = 0;
  526. if (controller->irq)
  527. pid = kernel_thread(event_thread, NULL, 0);
  528. else
  529. pid = kernel_thread(poll_thread, NULL, 0);
  530. if (pid < 0) {
  531. err("Can't start up our thread");
  532. return -1;
  533. }
  534. dbg("Our thread pid = %d", pid);
  535. return 0;
  536. }
  537. static void
  538. cpci_stop_thread(void)
  539. {
  540. thread_finished = 1;
  541. dbg("thread finish command given");
  542. if (controller->irq)
  543. up(&event_semaphore);
  544. dbg("wait for thread to exit");
  545. down(&thread_exit);
  546. }
  547. int
  548. cpci_hp_register_controller(struct cpci_hp_controller *new_controller)
  549. {
  550. int status = 0;
  551. if (controller)
  552. return -1;
  553. if (!(new_controller && new_controller->ops))
  554. return -EINVAL;
  555. if (new_controller->irq) {
  556. if (!(new_controller->ops->enable_irq &&
  557. new_controller->ops->disable_irq))
  558. status = -EINVAL;
  559. if (request_irq(new_controller->irq,
  560. cpci_hp_intr,
  561. new_controller->irq_flags,
  562. MY_NAME,
  563. new_controller->dev_id)) {
  564. err("Can't get irq %d for the hotplug cPCI controller",
  565. new_controller->irq);
  566. status = -ENODEV;
  567. }
  568. dbg("%s - acquired controller irq %d",
  569. __FUNCTION__, new_controller->irq);
  570. }
  571. if (!status)
  572. controller = new_controller;
  573. return status;
  574. }
  575. static void
  576. cleanup_slots(void)
  577. {
  578. struct slot *slot;
  579. struct slot *tmp;
  580. /*
  581. * Unregister all of our slots with the pci_hotplug subsystem,
  582. * and free up all memory that we had allocated.
  583. */
  584. down_write(&list_rwsem);
  585. if (!slots)
  586. goto cleanup_null;
  587. list_for_each_entry_safe(slot, tmp, &slot_list, slot_list) {
  588. list_del(&slot->slot_list);
  589. pci_hp_deregister(slot->hotplug_slot);
  590. }
  591. cleanup_null:
  592. up_write(&list_rwsem);
  593. return;
  594. }
  595. int
  596. cpci_hp_unregister_controller(struct cpci_hp_controller *old_controller)
  597. {
  598. int status = 0;
  599. if (controller) {
  600. if (!thread_finished)
  601. cpci_stop_thread();
  602. if (controller->irq)
  603. free_irq(controller->irq, controller->dev_id);
  604. controller = NULL;
  605. cleanup_slots();
  606. } else
  607. status = -ENODEV;
  608. return status;
  609. }
  610. int
  611. cpci_hp_start(void)
  612. {
  613. static int first = 1;
  614. int status;
  615. dbg("%s - enter", __FUNCTION__);
  616. if (!controller)
  617. return -ENODEV;
  618. down_read(&list_rwsem);
  619. if (list_empty(&slot_list)) {
  620. up_read(&list_rwsem);
  621. return -ENODEV;
  622. }
  623. up_read(&list_rwsem);
  624. status = init_slots(first);
  625. if (first)
  626. first = 0;
  627. if (status)
  628. return status;
  629. status = cpci_start_thread();
  630. if (status)
  631. return status;
  632. dbg("%s - thread started", __FUNCTION__);
  633. if (controller->irq) {
  634. /* Start enum interrupt processing */
  635. dbg("%s - enabling irq", __FUNCTION__);
  636. controller->ops->enable_irq();
  637. }
  638. dbg("%s - exit", __FUNCTION__);
  639. return 0;
  640. }
  641. int
  642. cpci_hp_stop(void)
  643. {
  644. if (!controller)
  645. return -ENODEV;
  646. if (controller->irq) {
  647. /* Stop enum interrupt processing */
  648. dbg("%s - disabling irq", __FUNCTION__);
  649. controller->ops->disable_irq();
  650. }
  651. cpci_stop_thread();
  652. return 0;
  653. }
  654. int __init
  655. cpci_hotplug_init(int debug)
  656. {
  657. cpci_debug = debug;
  658. return 0;
  659. }
  660. void __exit
  661. cpci_hotplug_exit(void)
  662. {
  663. /*
  664. * Clean everything up.
  665. */
  666. cpci_hp_stop();
  667. cpci_hp_unregister_controller(controller);
  668. }
  669. EXPORT_SYMBOL_GPL(cpci_hp_register_controller);
  670. EXPORT_SYMBOL_GPL(cpci_hp_unregister_controller);
  671. EXPORT_SYMBOL_GPL(cpci_hp_register_bus);
  672. EXPORT_SYMBOL_GPL(cpci_hp_unregister_bus);
  673. EXPORT_SYMBOL_GPL(cpci_hp_start);
  674. EXPORT_SYMBOL_GPL(cpci_hp_stop);