xp_main.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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-2008 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/module.h>
  17. #include <linux/device.h>
  18. #include "xp.h"
  19. /* define the XP debug device structures to be used with dev_dbg() et al */
  20. struct device_driver xp_dbg_name = {
  21. .name = "xp"
  22. };
  23. struct device xp_dbg_subname = {
  24. .bus_id = {0}, /* set to "" */
  25. .driver = &xp_dbg_name
  26. };
  27. struct device *xp = &xp_dbg_subname;
  28. /* max #of partitions possible */
  29. short xp_max_npartitions;
  30. EXPORT_SYMBOL_GPL(xp_max_npartitions);
  31. enum xp_retval (*xp_remote_memcpy) (void *dst, const void *src, size_t len);
  32. EXPORT_SYMBOL_GPL(xp_remote_memcpy);
  33. /*
  34. * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level
  35. * users of XPC.
  36. */
  37. struct xpc_registration xpc_registrations[XPC_MAX_NCHANNELS];
  38. EXPORT_SYMBOL_GPL(xpc_registrations);
  39. /*
  40. * Initialize the XPC interface to indicate that XPC isn't loaded.
  41. */
  42. static enum xp_retval
  43. xpc_notloaded(void)
  44. {
  45. return xpNotLoaded;
  46. }
  47. struct xpc_interface xpc_interface = {
  48. (void (*)(int))xpc_notloaded,
  49. (void (*)(int))xpc_notloaded,
  50. (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
  51. (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
  52. void *))xpc_notloaded,
  53. (void (*)(short, int, void *))xpc_notloaded,
  54. (enum xp_retval(*)(short, void *))xpc_notloaded
  55. };
  56. EXPORT_SYMBOL_GPL(xpc_interface);
  57. /*
  58. * XPC calls this when it (the XPC module) has been loaded.
  59. */
  60. void
  61. xpc_set_interface(void (*connect) (int),
  62. void (*disconnect) (int),
  63. enum xp_retval (*send) (short, int, u32, void *, u16),
  64. enum xp_retval (*send_notify) (short, int, u32, void *, u16,
  65. xpc_notify_func, void *),
  66. void (*received) (short, int, void *),
  67. enum xp_retval (*partid_to_nasids) (short, void *))
  68. {
  69. xpc_interface.connect = connect;
  70. xpc_interface.disconnect = disconnect;
  71. xpc_interface.send = send;
  72. xpc_interface.send_notify = send_notify;
  73. xpc_interface.received = received;
  74. xpc_interface.partid_to_nasids = partid_to_nasids;
  75. }
  76. EXPORT_SYMBOL_GPL(xpc_set_interface);
  77. /*
  78. * XPC calls this when it (the XPC module) is being unloaded.
  79. */
  80. void
  81. xpc_clear_interface(void)
  82. {
  83. xpc_interface.connect = (void (*)(int))xpc_notloaded;
  84. xpc_interface.disconnect = (void (*)(int))xpc_notloaded;
  85. xpc_interface.send = (enum xp_retval(*)(short, int, u32, void *, u16))
  86. xpc_notloaded;
  87. xpc_interface.send_notify = (enum xp_retval(*)(short, int, u32, void *,
  88. u16, xpc_notify_func,
  89. void *))xpc_notloaded;
  90. xpc_interface.received = (void (*)(short, int, void *))
  91. xpc_notloaded;
  92. xpc_interface.partid_to_nasids = (enum xp_retval(*)(short, void *))
  93. xpc_notloaded;
  94. }
  95. EXPORT_SYMBOL_GPL(xpc_clear_interface);
  96. /*
  97. * Register for automatic establishment of a channel connection whenever
  98. * a partition comes up.
  99. *
  100. * Arguments:
  101. *
  102. * ch_number - channel # to register for connection.
  103. * func - function to call for asynchronous notification of channel
  104. * state changes (i.e., connection, disconnection, error) and
  105. * the arrival of incoming messages.
  106. * key - pointer to optional user-defined value that gets passed back
  107. * to the user on any callouts made to func.
  108. * payload_size - size in bytes of the XPC message's payload area which
  109. * contains a user-defined message. The user should make
  110. * this large enough to hold their largest message.
  111. * nentries - max #of XPC message entries a message queue can contain.
  112. * The actual number, which is determined when a connection
  113. * is established and may be less then requested, will be
  114. * passed to the user via the xpConnected callout.
  115. * assigned_limit - max number of kthreads allowed to be processing
  116. * messages (per connection) at any given instant.
  117. * idle_limit - max number of kthreads allowed to be idle at any given
  118. * instant.
  119. */
  120. enum xp_retval
  121. xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
  122. u16 nentries, u32 assigned_limit, u32 idle_limit)
  123. {
  124. struct xpc_registration *registration;
  125. DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
  126. DBUG_ON(payload_size == 0 || nentries == 0);
  127. DBUG_ON(func == NULL);
  128. DBUG_ON(assigned_limit == 0 || idle_limit > assigned_limit);
  129. registration = &xpc_registrations[ch_number];
  130. if (mutex_lock_interruptible(&registration->mutex) != 0)
  131. return xpInterrupted;
  132. /* if XPC_CHANNEL_REGISTERED(ch_number) */
  133. if (registration->func != NULL) {
  134. mutex_unlock(&registration->mutex);
  135. return xpAlreadyRegistered;
  136. }
  137. /* register the channel for connection */
  138. registration->msg_size = XPC_MSG_SIZE(payload_size);
  139. registration->nentries = nentries;
  140. registration->assigned_limit = assigned_limit;
  141. registration->idle_limit = idle_limit;
  142. registration->key = key;
  143. registration->func = func;
  144. mutex_unlock(&registration->mutex);
  145. xpc_interface.connect(ch_number);
  146. return xpSuccess;
  147. }
  148. EXPORT_SYMBOL_GPL(xpc_connect);
  149. /*
  150. * Remove the registration for automatic connection of the specified channel
  151. * when a partition comes up.
  152. *
  153. * Before returning this xpc_disconnect() will wait for all connections on the
  154. * specified channel have been closed/torndown. So the caller can be assured
  155. * that they will not be receiving any more callouts from XPC to their
  156. * function registered via xpc_connect().
  157. *
  158. * Arguments:
  159. *
  160. * ch_number - channel # to unregister.
  161. */
  162. void
  163. xpc_disconnect(int ch_number)
  164. {
  165. struct xpc_registration *registration;
  166. DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
  167. registration = &xpc_registrations[ch_number];
  168. /*
  169. * We've decided not to make this a down_interruptible(), since we
  170. * figured XPC's users will just turn around and call xpc_disconnect()
  171. * again anyways, so we might as well wait, if need be.
  172. */
  173. mutex_lock(&registration->mutex);
  174. /* if !XPC_CHANNEL_REGISTERED(ch_number) */
  175. if (registration->func == NULL) {
  176. mutex_unlock(&registration->mutex);
  177. return;
  178. }
  179. /* remove the connection registration for the specified channel */
  180. registration->func = NULL;
  181. registration->key = NULL;
  182. registration->nentries = 0;
  183. registration->msg_size = 0;
  184. registration->assigned_limit = 0;
  185. registration->idle_limit = 0;
  186. xpc_interface.disconnect(ch_number);
  187. mutex_unlock(&registration->mutex);
  188. return;
  189. }
  190. EXPORT_SYMBOL_GPL(xpc_disconnect);
  191. int __init
  192. xp_init(void)
  193. {
  194. enum xp_retval ret;
  195. int ch_number;
  196. if (is_shub())
  197. ret = xp_init_sn2();
  198. else if (is_uv())
  199. ret = xp_init_uv();
  200. else
  201. ret = xpUnsupported;
  202. if (ret != xpSuccess)
  203. return -ENODEV;
  204. /* initialize the connection registration mutex */
  205. for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++)
  206. mutex_init(&xpc_registrations[ch_number].mutex);
  207. return 0;
  208. }
  209. module_init(xp_init);
  210. void __exit
  211. xp_exit(void)
  212. {
  213. if (is_shub())
  214. xp_exit_sn2();
  215. else if (is_uv())
  216. xp_exit_uv();
  217. }
  218. module_exit(xp_exit);
  219. MODULE_AUTHOR("Silicon Graphics, Inc.");
  220. MODULE_DESCRIPTION("Cross Partition (XP) base");
  221. MODULE_LICENSE("GPL");