cpci_hotplug_core.c 18 KB

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