2 * Copyright 2014 IBM Corp.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
10 #include <linux/module.h>
11 #include <linux/rcupdate.h>
12 #include <asm/errno.h>
16 /* protected by rcu */
17 static struct cxl_calls
*cxl_calls
;
19 atomic_t cxl_use_count
= ATOMIC_INIT(0);
20 EXPORT_SYMBOL(cxl_use_count
);
22 #ifdef CONFIG_CXL_MODULE
24 static inline struct cxl_calls
*cxl_calls_get(void)
26 struct cxl_calls
*calls
= NULL
;
29 calls
= rcu_dereference(cxl_calls
);
30 if (calls
&& !try_module_get(calls
->owner
))
37 static inline void cxl_calls_put(struct cxl_calls
*calls
)
39 BUG_ON(calls
!= cxl_calls
);
41 /* we don't need to rcu this, as we hold a reference to the module */
42 module_put(cxl_calls
->owner
);
45 #else /* !defined CONFIG_CXL_MODULE */
47 static inline struct cxl_calls
*cxl_calls_get(void)
52 static inline void cxl_calls_put(struct cxl_calls
*calls
) { }
54 #endif /* CONFIG_CXL_MODULE */
56 void cxl_slbia(struct mm_struct
*mm
)
58 struct cxl_calls
*calls
;
60 calls
= cxl_calls_get();
70 int register_cxl_calls(struct cxl_calls
*calls
)
75 rcu_assign_pointer(cxl_calls
, calls
);
78 EXPORT_SYMBOL_GPL(register_cxl_calls
);
80 void unregister_cxl_calls(struct cxl_calls
*calls
)
82 BUG_ON(cxl_calls
->owner
!= calls
->owner
);
83 RCU_INIT_POINTER(cxl_calls
, NULL
);
86 EXPORT_SYMBOL_GPL(unregister_cxl_calls
);