xp_main.c 7.3 KB

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