xp_main.c 7.7 KB

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