isc.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Functions for registration of I/O interruption subclasses on s390.
  3. *
  4. * Copyright IBM Corp. 2008
  5. * Authors: Sebastian Ott <sebott@linux.vnet.ibm.com>
  6. */
  7. #include <linux/spinlock.h>
  8. #include <linux/module.h>
  9. #include <asm/isc.h>
  10. static unsigned int isc_refs[MAX_ISC + 1];
  11. static DEFINE_SPINLOCK(isc_ref_lock);
  12. /**
  13. * isc_register - register an I/O interruption subclass.
  14. * @isc: I/O interruption subclass to register
  15. *
  16. * The number of users for @isc is increased. If this is the first user to
  17. * register @isc, the corresponding I/O interruption subclass mask is enabled.
  18. *
  19. * Context:
  20. * This function must not be called in interrupt context.
  21. */
  22. void isc_register(unsigned int isc)
  23. {
  24. if (isc > MAX_ISC) {
  25. WARN_ON(1);
  26. return;
  27. }
  28. spin_lock(&isc_ref_lock);
  29. if (isc_refs[isc] == 0)
  30. ctl_set_bit(6, 31 - isc);
  31. isc_refs[isc]++;
  32. spin_unlock(&isc_ref_lock);
  33. }
  34. EXPORT_SYMBOL_GPL(isc_register);
  35. /**
  36. * isc_unregister - unregister an I/O interruption subclass.
  37. * @isc: I/O interruption subclass to unregister
  38. *
  39. * The number of users for @isc is decreased. If this is the last user to
  40. * unregister @isc, the corresponding I/O interruption subclass mask is
  41. * disabled.
  42. * Note: This function must not be called if isc_register() hasn't been called
  43. * before by the driver for @isc.
  44. *
  45. * Context:
  46. * This function must not be called in interrupt context.
  47. */
  48. void isc_unregister(unsigned int isc)
  49. {
  50. spin_lock(&isc_ref_lock);
  51. /* check for misuse */
  52. if (isc > MAX_ISC || isc_refs[isc] == 0) {
  53. WARN_ON(1);
  54. goto out_unlock;
  55. }
  56. if (isc_refs[isc] == 1)
  57. ctl_clear_bit(6, 31 - isc);
  58. isc_refs[isc]--;
  59. out_unlock:
  60. spin_unlock(&isc_ref_lock);
  61. }
  62. EXPORT_SYMBOL_GPL(isc_unregister);