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/kernel.h>
18 #include <linux/module.h>
19 #include <linux/device.h>
22 /* define the XP debug device structures to be used with dev_dbg() et al */
24 struct device_driver xp_dbg_name = {
28 struct device xp_dbg_subname = {
29 .bus_id = {0}, /* set to "" */
30 .driver = &xp_dbg_name
33 struct device *xp = &xp_dbg_subname;
35 /* max #of partitions possible */
36 short xp_max_npartitions;
37 EXPORT_SYMBOL_GPL(xp_max_npartitions);
39 enum xp_retval (*xp_remote_memcpy) (void *dst, const void *src, size_t len);
40 EXPORT_SYMBOL_GPL(xp_remote_memcpy);
43 * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level
46 struct xpc_registration xpc_registrations[XPC_MAX_NCHANNELS];
47 EXPORT_SYMBOL_GPL(xpc_registrations);
50 * Initialize the XPC interface to indicate that XPC isn't loaded.
58 struct xpc_interface xpc_interface = {
59 (void (*)(int))xpc_notloaded,
60 (void (*)(int))xpc_notloaded,
61 (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
62 (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
63 void *))xpc_notloaded,
64 (void (*)(short, int, void *))xpc_notloaded,
65 (enum xp_retval(*)(short, void *))xpc_notloaded
67 EXPORT_SYMBOL_GPL(xpc_interface);
70 * XPC calls this when it (the XPC module) has been loaded.
73 xpc_set_interface(void (*connect) (int),
74 void (*disconnect) (int),
75 enum xp_retval (*send) (short, int, u32, void *, u16),
76 enum xp_retval (*send_notify) (short, int, u32, void *, u16,
77 xpc_notify_func, void *),
78 void (*received) (short, int, void *),
79 enum xp_retval (*partid_to_nasids) (short, void *))
81 xpc_interface.connect = connect;
82 xpc_interface.disconnect = disconnect;
83 xpc_interface.send = send;
84 xpc_interface.send_notify = send_notify;
85 xpc_interface.received = received;
86 xpc_interface.partid_to_nasids = partid_to_nasids;
88 EXPORT_SYMBOL_GPL(xpc_set_interface);
91 * XPC calls this when it (the XPC module) is being unloaded.
94 xpc_clear_interface(void)
96 xpc_interface.connect = (void (*)(int))xpc_notloaded;
97 xpc_interface.disconnect = (void (*)(int))xpc_notloaded;
98 xpc_interface.send = (enum xp_retval(*)(short, int, u32, void *, u16))
100 xpc_interface.send_notify = (enum xp_retval(*)(short, int, u32, void *,
101 u16, xpc_notify_func,
102 void *))xpc_notloaded;
103 xpc_interface.received = (void (*)(short, int, void *))
105 xpc_interface.partid_to_nasids = (enum xp_retval(*)(short, void *))
108 EXPORT_SYMBOL_GPL(xpc_clear_interface);
111 * Register for automatic establishment of a channel connection whenever
112 * a partition comes up.
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
135 xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
136 u16 nentries, u32 assigned_limit, u32 idle_limit)
138 struct xpc_registration *registration;
140 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
141 DBUG_ON(payload_size == 0 || nentries == 0);
142 DBUG_ON(func == NULL);
143 DBUG_ON(assigned_limit == 0 || idle_limit > assigned_limit);
145 registration = &xpc_registrations[ch_number];
147 if (mutex_lock_interruptible(®istration->mutex) != 0)
148 return xpInterrupted;
150 /* if XPC_CHANNEL_REGISTERED(ch_number) */
151 if (registration->func != NULL) {
152 mutex_unlock(®istration->mutex);
153 return xpAlreadyRegistered;
156 /* register the channel for connection */
157 registration->msg_size = XPC_MSG_SIZE(payload_size);
158 registration->nentries = nentries;
159 registration->assigned_limit = assigned_limit;
160 registration->idle_limit = idle_limit;
161 registration->key = key;
162 registration->func = func;
164 mutex_unlock(®istration->mutex);
166 xpc_interface.connect(ch_number);
170 EXPORT_SYMBOL_GPL(xpc_connect);
173 * Remove the registration for automatic connection of the specified channel
174 * when a partition comes up.
176 * Before returning this xpc_disconnect() will wait for all connections on the
177 * specified channel have been closed/torndown. So the caller can be assured
178 * that they will not be receiving any more callouts from XPC to their
179 * function registered via xpc_connect().
183 * ch_number - channel # to unregister.
186 xpc_disconnect(int ch_number)
188 struct xpc_registration *registration;
190 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
192 registration = &xpc_registrations[ch_number];
195 * We've decided not to make this a down_interruptible(), since we
196 * figured XPC's users will just turn around and call xpc_disconnect()
197 * again anyways, so we might as well wait, if need be.
199 mutex_lock(®istration->mutex);
201 /* if !XPC_CHANNEL_REGISTERED(ch_number) */
202 if (registration->func == NULL) {
203 mutex_unlock(®istration->mutex);
207 /* remove the connection registration for the specified channel */
208 registration->func = NULL;
209 registration->key = NULL;
210 registration->nentries = 0;
211 registration->msg_size = 0;
212 registration->assigned_limit = 0;
213 registration->idle_limit = 0;
215 xpc_interface.disconnect(ch_number);
217 mutex_unlock(®istration->mutex);
221 EXPORT_SYMBOL_GPL(xpc_disconnect);
236 if (ret != xpSuccess)
239 /* initialize the connection registration mutex */
240 for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++)
241 mutex_init(&xpc_registrations[ch_number].mutex);
246 module_init(xp_init);
257 module_exit(xp_exit);
259 MODULE_AUTHOR("Silicon Graphics, Inc.");
260 MODULE_DESCRIPTION("Cross Partition (XP) base");
261 MODULE_LICENSE("GPL");