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