xp_main.c 7.0 KB

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