isc.c 1.7 KB

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