cpci_hotplug_core.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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 = kmalloc(sizeof (struct slot), GFP_KERNEL);
  215. if (!slot)
  216. goto error;
  217. memset(slot, 0, sizeof (struct slot));
  218. hotplug_slot =
  219. kmalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
  220. if (!hotplug_slot)
  221. goto error_slot;
  222. memset(hotplug_slot, 0, sizeof (struct hotplug_slot));
  223. slot->hotplug_slot = hotplug_slot;
  224. info = kmalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL);
  225. if (!info)
  226. goto error_hpslot;
  227. memset(info, 0, sizeof (struct hotplug_slot_info));
  228. hotplug_slot->info = info;
  229. name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
  230. if (!name)
  231. goto error_info;
  232. hotplug_slot->name = name;
  233. slot->bus = bus;
  234. slot->number = i;
  235. slot->devfn = PCI_DEVFN(i, 0);
  236. hotplug_slot->private = slot;
  237. hotplug_slot->release = &release_slot;
  238. make_slot_name(slot);
  239. hotplug_slot->ops = &cpci_hotplug_slot_ops;
  240. /*
  241. * Initialize the slot info structure with some known
  242. * good values.
  243. */
  244. dbg("initializing slot %s", slot->hotplug_slot->name);
  245. info->power_status = cpci_get_power_status(slot);
  246. info->attention_status = cpci_get_attention_status(slot);
  247. dbg("registering slot %s", slot->hotplug_slot->name);
  248. status = pci_hp_register(slot->hotplug_slot);
  249. if (status) {
  250. err("pci_hp_register failed with error %d", status);
  251. goto error_name;
  252. }
  253. /* Add slot to our internal list */
  254. down_write(&list_rwsem);
  255. list_add(&slot->slot_list, &slot_list);
  256. slots++;
  257. up_write(&list_rwsem);
  258. }
  259. return 0;
  260. error_name:
  261. kfree(name);
  262. error_info:
  263. kfree(info);
  264. error_hpslot:
  265. kfree(hotplug_slot);
  266. error_slot:
  267. kfree(slot);
  268. error:
  269. return status;
  270. }
  271. int
  272. cpci_hp_unregister_bus(struct pci_bus *bus)
  273. {
  274. struct slot *slot;
  275. struct slot *tmp;
  276. int status = 0;
  277. down_write(&list_rwsem);
  278. if (!slots) {
  279. up_write(&list_rwsem);
  280. return -1;
  281. }
  282. list_for_each_entry_safe(slot, tmp, &slot_list, slot_list) {
  283. if (slot->bus == bus) {
  284. list_del(&slot->slot_list);
  285. slots--;
  286. dbg("deregistering slot %s", slot->hotplug_slot->name);
  287. status = pci_hp_deregister(slot->hotplug_slot);
  288. if (status) {
  289. err("pci_hp_deregister failed with error %d",
  290. status);
  291. break;
  292. }
  293. }
  294. }
  295. up_write(&list_rwsem);
  296. return status;
  297. }
  298. /* This is the interrupt mode interrupt handler */
  299. static irqreturn_t
  300. cpci_hp_intr(int irq, void *data, struct pt_regs *regs)
  301. {
  302. dbg("entered cpci_hp_intr");
  303. /* Check to see if it was our interrupt */
  304. if ((controller->irq_flags & SA_SHIRQ) &&
  305. !controller->ops->check_irq(controller->dev_id)) {
  306. dbg("exited cpci_hp_intr, not our interrupt");
  307. return IRQ_NONE;
  308. }
  309. /* Disable ENUM interrupt */
  310. controller->ops->disable_irq();
  311. /* Trigger processing by the event thread */
  312. dbg("Signal event_semaphore");
  313. up(&event_semaphore);
  314. dbg("exited cpci_hp_intr");
  315. return IRQ_HANDLED;
  316. }
  317. /*
  318. * According to PICMG 2.1 R2.0, section 6.3.2, upon
  319. * initialization, the system driver shall clear the
  320. * INS bits of the cold-inserted devices.
  321. */
  322. static int
  323. init_slots(int clear_ins)
  324. {
  325. struct slot *slot;
  326. struct pci_dev* dev;
  327. dbg("%s - enter", __FUNCTION__);
  328. down_read(&list_rwsem);
  329. if (!slots) {
  330. up_read(&list_rwsem);
  331. return -1;
  332. }
  333. list_for_each_entry(slot, &slot_list, slot_list) {
  334. dbg("%s - looking at slot %s",
  335. __FUNCTION__, slot->hotplug_slot->name);
  336. if (clear_ins && cpci_check_and_clear_ins(slot))
  337. dbg("%s - cleared INS for slot %s",
  338. __FUNCTION__, slot->hotplug_slot->name);
  339. dev = pci_get_slot(slot->bus, PCI_DEVFN(slot->number, 0));
  340. if (dev) {
  341. if (update_adapter_status(slot->hotplug_slot, 1))
  342. warn("failure to update adapter file");
  343. if (update_latch_status(slot->hotplug_slot, 1))
  344. warn("failure to update latch file");
  345. slot->dev = dev;
  346. }
  347. }
  348. up_read(&list_rwsem);
  349. dbg("%s - exit", __FUNCTION__);
  350. return 0;
  351. }
  352. static int
  353. check_slots(void)
  354. {
  355. struct slot *slot;
  356. int extracted;
  357. int inserted;
  358. u16 hs_csr;
  359. down_read(&list_rwsem);
  360. if (!slots) {
  361. up_read(&list_rwsem);
  362. err("no slots registered, shutting down");
  363. return -1;
  364. }
  365. extracted = inserted = 0;
  366. list_for_each_entry(slot, &slot_list, slot_list) {
  367. dbg("%s - looking at slot %s",
  368. __FUNCTION__, slot->hotplug_slot->name);
  369. if (cpci_check_and_clear_ins(slot)) {
  370. /*
  371. * Some broken hardware (e.g. PLX 9054AB) asserts
  372. * ENUM# twice...
  373. */
  374. if (slot->dev) {
  375. warn("slot %s already inserted",
  376. slot->hotplug_slot->name);
  377. inserted++;
  378. continue;
  379. }
  380. /* Process insertion */
  381. dbg("%s - slot %s inserted",
  382. __FUNCTION__, slot->hotplug_slot->name);
  383. /* GSM, debug */
  384. hs_csr = cpci_get_hs_csr(slot);
  385. dbg("%s - slot %s HS_CSR (1) = %04x",
  386. __FUNCTION__, slot->hotplug_slot->name, hs_csr);
  387. /* Configure device */
  388. dbg("%s - configuring slot %s",
  389. __FUNCTION__, slot->hotplug_slot->name);
  390. if (cpci_configure_slot(slot)) {
  391. err("%s - could not configure slot %s",
  392. __FUNCTION__, slot->hotplug_slot->name);
  393. continue;
  394. }
  395. dbg("%s - finished configuring slot %s",
  396. __FUNCTION__, slot->hotplug_slot->name);
  397. /* GSM, debug */
  398. hs_csr = cpci_get_hs_csr(slot);
  399. dbg("%s - slot %s HS_CSR (2) = %04x",
  400. __FUNCTION__, slot->hotplug_slot->name, hs_csr);
  401. if (update_latch_status(slot->hotplug_slot, 1))
  402. warn("failure to update latch file");
  403. if (update_adapter_status(slot->hotplug_slot, 1))
  404. warn("failure to update adapter file");
  405. cpci_led_off(slot);
  406. /* GSM, debug */
  407. hs_csr = cpci_get_hs_csr(slot);
  408. dbg("%s - slot %s HS_CSR (3) = %04x",
  409. __FUNCTION__, slot->hotplug_slot->name, hs_csr);
  410. inserted++;
  411. } else if (cpci_check_ext(slot)) {
  412. /* Process extraction request */
  413. dbg("%s - slot %s extracted",
  414. __FUNCTION__, slot->hotplug_slot->name);
  415. /* GSM, debug */
  416. hs_csr = cpci_get_hs_csr(slot);
  417. dbg("%s - slot %s HS_CSR = %04x",
  418. __FUNCTION__, slot->hotplug_slot->name, hs_csr);
  419. if (!slot->extracting) {
  420. if (update_latch_status(slot->hotplug_slot, 0)) {
  421. warn("failure to update latch file");
  422. }
  423. slot->extracting = 1;
  424. atomic_inc(&extracting);
  425. }
  426. extracted++;
  427. } else if (slot->extracting) {
  428. hs_csr = cpci_get_hs_csr(slot);
  429. if (hs_csr == 0xffff) {
  430. /*
  431. * Hmmm, we're likely hosed at this point, should we
  432. * bother trying to tell the driver or not?
  433. */
  434. err("card in slot %s was improperly removed",
  435. slot->hotplug_slot->name);
  436. if (update_adapter_status(slot->hotplug_slot, 0))
  437. warn("failure to update adapter file");
  438. slot->extracting = 0;
  439. atomic_dec(&extracting);
  440. }
  441. }
  442. }
  443. up_read(&list_rwsem);
  444. dbg("inserted=%d, extracted=%d, extracting=%d",
  445. inserted, extracted, atomic_read(&extracting));
  446. if (inserted || extracted)
  447. return extracted;
  448. else if (!atomic_read(&extracting)) {
  449. err("cannot find ENUM# source, shutting down");
  450. return -1;
  451. }
  452. return 0;
  453. }
  454. /* This is the interrupt mode worker thread body */
  455. static int
  456. event_thread(void *data)
  457. {
  458. int rc;
  459. lock_kernel();
  460. daemonize("cpci_hp_eventd");
  461. unlock_kernel();
  462. dbg("%s - event thread started", __FUNCTION__);
  463. while (1) {
  464. dbg("event thread sleeping");
  465. down_interruptible(&event_semaphore);
  466. dbg("event thread woken, thread_finished = %d",
  467. thread_finished);
  468. if (thread_finished || signal_pending(current))
  469. break;
  470. do {
  471. rc = check_slots();
  472. if (rc > 0) {
  473. /* Give userspace a chance to handle extraction */
  474. msleep(500);
  475. } else if (rc < 0) {
  476. dbg("%s - error checking slots", __FUNCTION__);
  477. thread_finished = 1;
  478. break;
  479. }
  480. } while (atomic_read(&extracting) && !thread_finished);
  481. if (thread_finished)
  482. break;
  483. /* Re-enable ENUM# interrupt */
  484. dbg("%s - re-enabling irq", __FUNCTION__);
  485. controller->ops->enable_irq();
  486. }
  487. dbg("%s - event thread signals exit", __FUNCTION__);
  488. up(&thread_exit);
  489. return 0;
  490. }
  491. /* This is the polling mode worker thread body */
  492. static int
  493. poll_thread(void *data)
  494. {
  495. int rc;
  496. lock_kernel();
  497. daemonize("cpci_hp_polld");
  498. unlock_kernel();
  499. while (1) {
  500. if (thread_finished || signal_pending(current))
  501. break;
  502. if (controller->ops->query_enum()) {
  503. do {
  504. rc = check_slots();
  505. if (rc > 0) {
  506. /* Give userspace a chance to handle extraction */
  507. msleep(500);
  508. } else if (rc < 0) {
  509. dbg("%s - error checking slots", __FUNCTION__);
  510. thread_finished = 1;
  511. break;
  512. }
  513. } while (atomic_read(&extracting) && !thread_finished);
  514. }
  515. msleep(100);
  516. }
  517. dbg("poll thread signals exit");
  518. up(&thread_exit);
  519. return 0;
  520. }
  521. static int
  522. cpci_start_thread(void)
  523. {
  524. int pid;
  525. /* initialize our semaphores */
  526. init_MUTEX_LOCKED(&event_semaphore);
  527. init_MUTEX_LOCKED(&thread_exit);
  528. thread_finished = 0;
  529. if (controller->irq)
  530. pid = kernel_thread(event_thread, NULL, 0);
  531. else
  532. pid = kernel_thread(poll_thread, NULL, 0);
  533. if (pid < 0) {
  534. err("Can't start up our thread");
  535. return -1;
  536. }
  537. dbg("Our thread pid = %d", pid);
  538. return 0;
  539. }
  540. static void
  541. cpci_stop_thread(void)
  542. {
  543. thread_finished = 1;
  544. dbg("thread finish command given");
  545. if (controller->irq)
  546. up(&event_semaphore);
  547. dbg("wait for thread to exit");
  548. down(&thread_exit);
  549. }
  550. int
  551. cpci_hp_register_controller(struct cpci_hp_controller *new_controller)
  552. {
  553. int status = 0;
  554. if (controller)
  555. return -1;
  556. if (!(new_controller && new_controller->ops))
  557. return -EINVAL;
  558. if (new_controller->irq) {
  559. if (!(new_controller->ops->enable_irq &&
  560. new_controller->ops->disable_irq))
  561. status = -EINVAL;
  562. if (request_irq(new_controller->irq,
  563. cpci_hp_intr,
  564. new_controller->irq_flags,
  565. MY_NAME,
  566. new_controller->dev_id)) {
  567. err("Can't get irq %d for the hotplug cPCI controller",
  568. new_controller->irq);
  569. status = -ENODEV;
  570. }
  571. dbg("%s - acquired controller irq %d",
  572. __FUNCTION__, new_controller->irq);
  573. }
  574. if (!status)
  575. controller = new_controller;
  576. return status;
  577. }
  578. static void
  579. cleanup_slots(void)
  580. {
  581. struct slot *slot;
  582. struct slot *tmp;
  583. /*
  584. * Unregister all of our slots with the pci_hotplug subsystem,
  585. * and free up all memory that we had allocated.
  586. */
  587. down_write(&list_rwsem);
  588. if (!slots)
  589. goto cleanup_null;
  590. list_for_each_entry_safe(slot, tmp, &slot_list, slot_list) {
  591. list_del(&slot->slot_list);
  592. pci_hp_deregister(slot->hotplug_slot);
  593. }
  594. cleanup_null:
  595. up_write(&list_rwsem);
  596. return;
  597. }
  598. int
  599. cpci_hp_unregister_controller(struct cpci_hp_controller *old_controller)
  600. {
  601. int status = 0;
  602. if (controller) {
  603. if (!thread_finished)
  604. cpci_stop_thread();
  605. if (controller->irq)
  606. free_irq(controller->irq, controller->dev_id);
  607. controller = NULL;
  608. cleanup_slots();
  609. } else
  610. status = -ENODEV;
  611. return status;
  612. }
  613. int
  614. cpci_hp_start(void)
  615. {
  616. static int first = 1;
  617. int status;
  618. dbg("%s - enter", __FUNCTION__);
  619. if (!controller)
  620. return -ENODEV;
  621. down_read(&list_rwsem);
  622. if (list_empty(&slot_list)) {
  623. up_read(&list_rwsem);
  624. return -ENODEV;
  625. }
  626. up_read(&list_rwsem);
  627. status = init_slots(first);
  628. if (first)
  629. first = 0;
  630. if (status)
  631. return status;
  632. status = cpci_start_thread();
  633. if (status)
  634. return status;
  635. dbg("%s - thread started", __FUNCTION__);
  636. if (controller->irq) {
  637. /* Start enum interrupt processing */
  638. dbg("%s - enabling irq", __FUNCTION__);
  639. controller->ops->enable_irq();
  640. }
  641. dbg("%s - exit", __FUNCTION__);
  642. return 0;
  643. }
  644. int
  645. cpci_hp_stop(void)
  646. {
  647. if (!controller)
  648. return -ENODEV;
  649. if (controller->irq) {
  650. /* Stop enum interrupt processing */
  651. dbg("%s - disabling irq", __FUNCTION__);
  652. controller->ops->disable_irq();
  653. }
  654. cpci_stop_thread();
  655. return 0;
  656. }
  657. int __init
  658. cpci_hotplug_init(int debug)
  659. {
  660. cpci_debug = debug;
  661. return 0;
  662. }
  663. void __exit
  664. cpci_hotplug_exit(void)
  665. {
  666. /*
  667. * Clean everything up.
  668. */
  669. cpci_hp_stop();
  670. cpci_hp_unregister_controller(controller);
  671. }
  672. EXPORT_SYMBOL_GPL(cpci_hp_register_controller);
  673. EXPORT_SYMBOL_GPL(cpci_hp_unregister_controller);
  674. EXPORT_SYMBOL_GPL(cpci_hp_register_bus);
  675. EXPORT_SYMBOL_GPL(cpci_hp_unregister_bus);
  676. EXPORT_SYMBOL_GPL(cpci_hp_start);
  677. EXPORT_SYMBOL_GPL(cpci_hp_stop);