xp_main.c 7.5 KB

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