xp_main.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. /*
  9. * Cross Partition (XP) base.
  10. *
  11. * XP provides a base from which its users can interact
  12. * with XPC, yet not be dependent on XPC.
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/module.h>
  18. #include <linux/mutex.h>
  19. #include <asm/sn/intr.h>
  20. #include <asm/sn/sn_sal.h>
  21. #include <asm/sn/xp.h>
  22. /*
  23. * Target of nofault PIO read.
  24. */
  25. u64 xp_nofault_PIOR_target;
  26. /*
  27. * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level
  28. * users of XPC.
  29. */
  30. struct xpc_registration xpc_registrations[XPC_NCHANNELS];
  31. /*
  32. * Initialize the XPC interface to indicate that XPC isn't loaded.
  33. */
  34. static enum xpc_retval xpc_notloaded(void) { return xpcNotLoaded; }
  35. struct xpc_interface xpc_interface = {
  36. (void (*)(int)) xpc_notloaded,
  37. (void (*)(int)) xpc_notloaded,
  38. (enum xpc_retval (*)(partid_t, int, u32, void **)) xpc_notloaded,
  39. (enum xpc_retval (*)(partid_t, int, void *)) xpc_notloaded,
  40. (enum xpc_retval (*)(partid_t, int, void *, xpc_notify_func, void *))
  41. xpc_notloaded,
  42. (void (*)(partid_t, int, void *)) xpc_notloaded,
  43. (enum xpc_retval (*)(partid_t, void *)) xpc_notloaded
  44. };
  45. /*
  46. * XPC calls this when it (the XPC module) has been loaded.
  47. */
  48. void
  49. xpc_set_interface(void (*connect)(int),
  50. void (*disconnect)(int),
  51. enum xpc_retval (*allocate)(partid_t, int, u32, void **),
  52. enum xpc_retval (*send)(partid_t, int, void *),
  53. enum xpc_retval (*send_notify)(partid_t, int, void *,
  54. xpc_notify_func, void *),
  55. void (*received)(partid_t, int, void *),
  56. enum xpc_retval (*partid_to_nasids)(partid_t, void *))
  57. {
  58. xpc_interface.connect = connect;
  59. xpc_interface.disconnect = disconnect;
  60. xpc_interface.allocate = allocate;
  61. xpc_interface.send = send;
  62. xpc_interface.send_notify = send_notify;
  63. xpc_interface.received = received;
  64. xpc_interface.partid_to_nasids = partid_to_nasids;
  65. }
  66. /*
  67. * XPC calls this when it (the XPC module) is being unloaded.
  68. */
  69. void
  70. xpc_clear_interface(void)
  71. {
  72. xpc_interface.connect = (void (*)(int)) xpc_notloaded;
  73. xpc_interface.disconnect = (void (*)(int)) xpc_notloaded;
  74. xpc_interface.allocate = (enum xpc_retval (*)(partid_t, int, u32,
  75. void **)) xpc_notloaded;
  76. xpc_interface.send = (enum xpc_retval (*)(partid_t, int, void *))
  77. xpc_notloaded;
  78. xpc_interface.send_notify = (enum xpc_retval (*)(partid_t, int, void *,
  79. xpc_notify_func, void *)) xpc_notloaded;
  80. xpc_interface.received = (void (*)(partid_t, int, void *))
  81. xpc_notloaded;
  82. xpc_interface.partid_to_nasids = (enum xpc_retval (*)(partid_t, void *))
  83. xpc_notloaded;
  84. }
  85. /*
  86. * Register for automatic establishment of a channel connection whenever
  87. * a partition comes up.
  88. *
  89. * Arguments:
  90. *
  91. * ch_number - channel # to register for connection.
  92. * func - function to call for asynchronous notification of channel
  93. * state changes (i.e., connection, disconnection, error) and
  94. * the arrival of incoming messages.
  95. * key - pointer to optional user-defined value that gets passed back
  96. * to the user on any callouts made to func.
  97. * payload_size - size in bytes of the XPC message's payload area which
  98. * contains a user-defined message. The user should make
  99. * this large enough to hold their largest message.
  100. * nentries - max #of XPC message entries a message queue can contain.
  101. * The actual number, which is determined when a connection
  102. * is established and may be less then requested, will be
  103. * passed to the user via the xpcConnected callout.
  104. * assigned_limit - max number of kthreads allowed to be processing
  105. * messages (per connection) at any given instant.
  106. * idle_limit - max number of kthreads allowed to be idle at any given
  107. * instant.
  108. */
  109. enum xpc_retval
  110. xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
  111. u16 nentries, u32 assigned_limit, u32 idle_limit)
  112. {
  113. struct xpc_registration *registration;
  114. DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS);
  115. DBUG_ON(payload_size == 0 || nentries == 0);
  116. DBUG_ON(func == NULL);
  117. DBUG_ON(assigned_limit == 0 || idle_limit > assigned_limit);
  118. registration = &xpc_registrations[ch_number];
  119. if (mutex_lock_interruptible(&registration->mutex) != 0) {
  120. return xpcInterrupted;
  121. }
  122. /* if XPC_CHANNEL_REGISTERED(ch_number) */
  123. if (registration->func != NULL) {
  124. mutex_unlock(&registration->mutex);
  125. return xpcAlreadyRegistered;
  126. }
  127. /* register the channel for connection */
  128. registration->msg_size = XPC_MSG_SIZE(payload_size);
  129. registration->nentries = nentries;
  130. registration->assigned_limit = assigned_limit;
  131. registration->idle_limit = idle_limit;
  132. registration->key = key;
  133. registration->func = func;
  134. mutex_unlock(&registration->mutex);
  135. xpc_interface.connect(ch_number);
  136. return xpcSuccess;
  137. }
  138. /*
  139. * Remove the registration for automatic connection of the specified channel
  140. * when a partition comes up.
  141. *
  142. * Before returning this xpc_disconnect() will wait for all connections on the
  143. * specified channel have been closed/torndown. So the caller can be assured
  144. * that they will not be receiving any more callouts from XPC to their
  145. * function registered via xpc_connect().
  146. *
  147. * Arguments:
  148. *
  149. * ch_number - channel # to unregister.
  150. */
  151. void
  152. xpc_disconnect(int ch_number)
  153. {
  154. struct xpc_registration *registration;
  155. DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS);
  156. registration = &xpc_registrations[ch_number];
  157. /*
  158. * We've decided not to make this a down_interruptible(), since we
  159. * figured XPC's users will just turn around and call xpc_disconnect()
  160. * again anyways, so we might as well wait, if need be.
  161. */
  162. mutex_lock(&registration->mutex);
  163. /* if !XPC_CHANNEL_REGISTERED(ch_number) */
  164. if (registration->func == NULL) {
  165. mutex_unlock(&registration->mutex);
  166. return;
  167. }
  168. /* remove the connection registration for the specified channel */
  169. registration->func = NULL;
  170. registration->key = NULL;
  171. registration->nentries = 0;
  172. registration->msg_size = 0;
  173. registration->assigned_limit = 0;
  174. registration->idle_limit = 0;
  175. xpc_interface.disconnect(ch_number);
  176. mutex_unlock(&registration->mutex);
  177. return;
  178. }
  179. int __init
  180. xp_init(void)
  181. {
  182. int ret, ch_number;
  183. u64 func_addr = *(u64 *) xp_nofault_PIOR;
  184. u64 err_func_addr = *(u64 *) xp_error_PIOR;
  185. if (!ia64_platform_is("sn2")) {
  186. return -ENODEV;
  187. }
  188. /*
  189. * Register a nofault code region which performs a cross-partition
  190. * PIO read. If the PIO read times out, the MCA handler will consume
  191. * the error and return to a kernel-provided instruction to indicate
  192. * an error. This PIO read exists because it is guaranteed to timeout
  193. * if the destination is down (AMO operations do not timeout on at
  194. * least some CPUs on Shubs <= v1.2, which unfortunately we have to
  195. * work around).
  196. */
  197. if ((ret = sn_register_nofault_code(func_addr, err_func_addr,
  198. err_func_addr, 1, 1)) != 0) {
  199. printk(KERN_ERR "XP: can't register nofault code, error=%d\n",
  200. ret);
  201. }
  202. /*
  203. * Setup the nofault PIO read target. (There is no special reason why
  204. * SH_IPI_ACCESS was selected.)
  205. */
  206. if (is_shub2()) {
  207. xp_nofault_PIOR_target = SH2_IPI_ACCESS0;
  208. } else {
  209. xp_nofault_PIOR_target = SH1_IPI_ACCESS;
  210. }
  211. /* initialize the connection registration mutex */
  212. for (ch_number = 0; ch_number < XPC_NCHANNELS; ch_number++) {
  213. mutex_init(&xpc_registrations[ch_number].mutex);
  214. }
  215. return 0;
  216. }
  217. module_init(xp_init);
  218. void __exit
  219. xp_exit(void)
  220. {
  221. u64 func_addr = *(u64 *) xp_nofault_PIOR;
  222. u64 err_func_addr = *(u64 *) xp_error_PIOR;
  223. /* unregister the PIO read nofault code region */
  224. (void) sn_register_nofault_code(func_addr, err_func_addr,
  225. err_func_addr, 1, 0);
  226. }
  227. module_exit(xp_exit);
  228. MODULE_AUTHOR("Silicon Graphics, Inc.");
  229. MODULE_DESCRIPTION("Cross Partition (XP) base");
  230. MODULE_LICENSE("GPL");
  231. EXPORT_SYMBOL(xp_nofault_PIOR);
  232. EXPORT_SYMBOL(xp_nofault_PIOR_target);
  233. EXPORT_SYMBOL(xpc_registrations);
  234. EXPORT_SYMBOL(xpc_interface);
  235. EXPORT_SYMBOL(xpc_clear_interface);
  236. EXPORT_SYMBOL(xpc_set_interface);
  237. EXPORT_SYMBOL(xpc_connect);
  238. EXPORT_SYMBOL(xpc_disconnect);