cpci_hotplug_core.c 18 KB

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