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
6 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
10 * Cross Partition (XP) base.
12 * XP provides a base from which its users can interact
13 * with XPC, yet not be dependent on XPC.
17 #include <linux/module.h>
18 #include <linux/device.h>
21 /* define the XP debug device structures to be used with dev_dbg() et al */
23 struct device_driver xp_dbg_name = {
27 struct device xp_dbg_subname = {
28 .bus_id = {0}, /* set to "" */
29 .driver = &xp_dbg_name
32 struct device *xp = &xp_dbg_subname;
34 /* max #of partitions possible */
35 short xp_max_npartitions;
36 EXPORT_SYMBOL_GPL(xp_max_npartitions);
38 short xp_partition_id;
39 EXPORT_SYMBOL_GPL(xp_partition_id);
42 EXPORT_SYMBOL_GPL(xp_region_size);
44 enum xp_retval (*xp_remote_memcpy) (void *dst, const void *src, size_t len);
45 EXPORT_SYMBOL_GPL(xp_remote_memcpy);
47 int (*xp_cpu_to_nasid) (int cpuid);
48 EXPORT_SYMBOL_GPL(xp_cpu_to_nasid);
51 * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level
54 struct xpc_registration xpc_registrations[XPC_MAX_NCHANNELS];
55 EXPORT_SYMBOL_GPL(xpc_registrations);
58 * Initialize the XPC interface to indicate that XPC isn't loaded.
66 struct xpc_interface xpc_interface = {
67 (void (*)(int))xpc_notloaded,
68 (void (*)(int))xpc_notloaded,
69 (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
70 (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
71 void *))xpc_notloaded,
72 (void (*)(short, int, void *))xpc_notloaded,
73 (enum xp_retval(*)(short, void *))xpc_notloaded
75 EXPORT_SYMBOL_GPL(xpc_interface);
78 * XPC calls this when it (the XPC module) has been loaded.
81 xpc_set_interface(void (*connect) (int),
82 void (*disconnect) (int),
83 enum xp_retval (*send) (short, int, u32, void *, u16),
84 enum xp_retval (*send_notify) (short, int, u32, void *, u16,
85 xpc_notify_func, void *),
86 void (*received) (short, int, void *),
87 enum xp_retval (*partid_to_nasids) (short, void *))
89 xpc_interface.connect = connect;
90 xpc_interface.disconnect = disconnect;
91 xpc_interface.send = send;
92 xpc_interface.send_notify = send_notify;
93 xpc_interface.received = received;
94 xpc_interface.partid_to_nasids = partid_to_nasids;
96 EXPORT_SYMBOL_GPL(xpc_set_interface);
99 * XPC calls this when it (the XPC module) is being unloaded.
102 xpc_clear_interface(void)
104 xpc_interface.connect = (void (*)(int))xpc_notloaded;
105 xpc_interface.disconnect = (void (*)(int))xpc_notloaded;
106 xpc_interface.send = (enum xp_retval(*)(short, int, u32, void *, u16))
108 xpc_interface.send_notify = (enum xp_retval(*)(short, int, u32, void *,
109 u16, xpc_notify_func,
110 void *))xpc_notloaded;
111 xpc_interface.received = (void (*)(short, int, void *))
113 xpc_interface.partid_to_nasids = (enum xp_retval(*)(short, void *))
116 EXPORT_SYMBOL_GPL(xpc_clear_interface);
119 * Register for automatic establishment of a channel connection whenever
120 * a partition comes up.
124 * ch_number - channel # to register for connection.
125 * func - function to call for asynchronous notification of channel
126 * state changes (i.e., connection, disconnection, error) and
127 * the arrival of incoming messages.
128 * key - pointer to optional user-defined value that gets passed back
129 * to the user on any callouts made to func.
130 * payload_size - size in bytes of the XPC message's payload area which
131 * contains a user-defined message. The user should make
132 * this large enough to hold their largest message.
133 * nentries - max #of XPC message entries a message queue can contain.
134 * The actual number, which is determined when a connection
135 * is established and may be less then requested, will be
136 * passed to the user via the xpConnected callout.
137 * assigned_limit - max number of kthreads allowed to be processing
138 * messages (per connection) at any given instant.
139 * idle_limit - max number of kthreads allowed to be idle at any given
143 xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
144 u16 nentries, u32 assigned_limit, u32 idle_limit)
146 struct xpc_registration *registration;
148 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
149 DBUG_ON(payload_size == 0 || nentries == 0);
150 DBUG_ON(func == NULL);
151 DBUG_ON(assigned_limit == 0 || idle_limit > assigned_limit);
153 registration = &xpc_registrations[ch_number];
155 if (mutex_lock_interruptible(®istration->mutex) != 0)
156 return xpInterrupted;
158 /* if XPC_CHANNEL_REGISTERED(ch_number) */
159 if (registration->func != NULL) {
160 mutex_unlock(®istration->mutex);
161 return xpAlreadyRegistered;
164 /* register the channel for connection */
165 registration->msg_size = XPC_MSG_SIZE(payload_size);
166 registration->nentries = nentries;
167 registration->assigned_limit = assigned_limit;
168 registration->idle_limit = idle_limit;
169 registration->key = key;
170 registration->func = func;
172 mutex_unlock(®istration->mutex);
174 xpc_interface.connect(ch_number);
178 EXPORT_SYMBOL_GPL(xpc_connect);
181 * Remove the registration for automatic connection of the specified channel
182 * when a partition comes up.
184 * Before returning this xpc_disconnect() will wait for all connections on the
185 * specified channel have been closed/torndown. So the caller can be assured
186 * that they will not be receiving any more callouts from XPC to their
187 * function registered via xpc_connect().
191 * ch_number - channel # to unregister.
194 xpc_disconnect(int ch_number)
196 struct xpc_registration *registration;
198 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
200 registration = &xpc_registrations[ch_number];
203 * We've decided not to make this a down_interruptible(), since we
204 * figured XPC's users will just turn around and call xpc_disconnect()
205 * again anyways, so we might as well wait, if need be.
207 mutex_lock(®istration->mutex);
209 /* if !XPC_CHANNEL_REGISTERED(ch_number) */
210 if (registration->func == NULL) {
211 mutex_unlock(®istration->mutex);
215 /* remove the connection registration for the specified channel */
216 registration->func = NULL;
217 registration->key = NULL;
218 registration->nentries = 0;
219 registration->msg_size = 0;
220 registration->assigned_limit = 0;
221 registration->idle_limit = 0;
223 xpc_interface.disconnect(ch_number);
225 mutex_unlock(®istration->mutex);
229 EXPORT_SYMBOL_GPL(xpc_disconnect);
244 if (ret != xpSuccess)
247 /* initialize the connection registration mutex */
248 for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++)
249 mutex_init(&xpc_registrations[ch_number].mutex);
254 module_init(xp_init);
265 module_exit(xp_exit);
267 MODULE_AUTHOR("Silicon Graphics, Inc.");
268 MODULE_DESCRIPTION("Cross Partition (XP) base");
269 MODULE_LICENSE("GPL");