xp_main.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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/module.h>
  16. #include <linux/device.h>
  17. #include "xp.h"
  18. /* define the XP debug device structures to be used with dev_dbg() et al */
  19. struct device_driver xp_dbg_name = {
  20. .name = "xp"
  21. };
  22. struct device xp_dbg_subname = {
  23. .bus_id = {0}, /* set to "" */
  24. .driver = &xp_dbg_name
  25. };
  26. struct device *xp = &xp_dbg_subname;
  27. /* max #of partitions possible */
  28. short xp_max_npartitions;
  29. EXPORT_SYMBOL_GPL(xp_max_npartitions);
  30. short xp_partition_id;
  31. EXPORT_SYMBOL_GPL(xp_partition_id);
  32. u8 xp_region_size;
  33. EXPORT_SYMBOL_GPL(xp_region_size);
  34. enum xp_retval (*xp_remote_memcpy) (void *dst, const void *src, size_t len);
  35. EXPORT_SYMBOL_GPL(xp_remote_memcpy);
  36. int (*xp_cpu_to_nasid) (int cpuid);
  37. EXPORT_SYMBOL_GPL(xp_cpu_to_nasid);
  38. /*
  39. * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level
  40. * users of XPC.
  41. */
  42. struct xpc_registration xpc_registrations[XPC_MAX_NCHANNELS];
  43. EXPORT_SYMBOL_GPL(xpc_registrations);
  44. /*
  45. * Initialize the XPC interface to indicate that XPC isn't loaded.
  46. */
  47. static enum xp_retval
  48. xpc_notloaded(void)
  49. {
  50. return xpNotLoaded;
  51. }
  52. struct xpc_interface xpc_interface = {
  53. (void (*)(int))xpc_notloaded,
  54. (void (*)(int))xpc_notloaded,
  55. (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
  56. (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
  57. void *))xpc_notloaded,
  58. (void (*)(short, int, void *))xpc_notloaded,
  59. (enum xp_retval(*)(short, void *))xpc_notloaded
  60. };
  61. EXPORT_SYMBOL_GPL(xpc_interface);
  62. /*
  63. * XPC calls this when it (the XPC module) has been loaded.
  64. */
  65. void
  66. xpc_set_interface(void (*connect) (int),
  67. void (*disconnect) (int),
  68. enum xp_retval (*send) (short, int, u32, void *, u16),
  69. enum xp_retval (*send_notify) (short, int, u32, void *, u16,
  70. xpc_notify_func, void *),
  71. void (*received) (short, int, void *),
  72. enum xp_retval (*partid_to_nasids) (short, void *))
  73. {
  74. xpc_interface.connect = connect;
  75. xpc_interface.disconnect = disconnect;
  76. xpc_interface.send = send;
  77. xpc_interface.send_notify = send_notify;
  78. xpc_interface.received = received;
  79. xpc_interface.partid_to_nasids = partid_to_nasids;
  80. }
  81. EXPORT_SYMBOL_GPL(xpc_set_interface);
  82. /*
  83. * XPC calls this when it (the XPC module) is being unloaded.
  84. */
  85. void
  86. xpc_clear_interface(void)
  87. {
  88. xpc_interface.connect = (void (*)(int))xpc_notloaded;
  89. xpc_interface.disconnect = (void (*)(int))xpc_notloaded;
  90. xpc_interface.send = (enum xp_retval(*)(short, int, u32, void *, u16))
  91. xpc_notloaded;
  92. xpc_interface.send_notify = (enum xp_retval(*)(short, int, u32, void *,
  93. u16, 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");