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/interrupt.h>
19 #include <linux/module.h>
20 #include <linux/mutex.h>
21 #include <asm/sn/intr.h>
22 #include <asm/sn/sn_sal.h>
26 * The export of xp_nofault_PIOR needs to happen here since it is defined
27 * in drivers/misc/sgi-xp/xp_nofault.S. The target of the nofault read is
30 EXPORT_SYMBOL_GPL(xp_nofault_PIOR);
32 u64 xp_nofault_PIOR_target;
33 EXPORT_SYMBOL_GPL(xp_nofault_PIOR_target);
36 * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level
39 struct xpc_registration xpc_registrations[XPC_NCHANNELS];
40 EXPORT_SYMBOL_GPL(xpc_registrations);
43 * Initialize the XPC interface to indicate that XPC isn't loaded.
51 struct xpc_interface xpc_interface = {
52 (void (*)(int))xpc_notloaded,
53 (void (*)(int))xpc_notloaded,
54 (enum xp_retval(*)(short, int, u32, void **))xpc_notloaded,
55 (enum xp_retval(*)(short, int, void *))xpc_notloaded,
56 (enum xp_retval(*)(short, int, void *, xpc_notify_func, void *))
58 (void (*)(short, int, void *))xpc_notloaded,
59 (enum xp_retval(*)(short, void *))xpc_notloaded
61 EXPORT_SYMBOL_GPL(xpc_interface);
64 * XPC calls this when it (the XPC module) has been loaded.
67 xpc_set_interface(void (*connect) (int),
68 void (*disconnect) (int),
69 enum xp_retval (*allocate) (short, int, u32, void **),
70 enum xp_retval (*send) (short, int, void *),
71 enum xp_retval (*send_notify) (short, int, void *,
72 xpc_notify_func, void *),
73 void (*received) (short, int, void *),
74 enum xp_retval (*partid_to_nasids) (short, void *))
76 xpc_interface.connect = connect;
77 xpc_interface.disconnect = disconnect;
78 xpc_interface.allocate = allocate;
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;
84 EXPORT_SYMBOL_GPL(xpc_set_interface);
87 * XPC calls this when it (the XPC module) is being unloaded.
90 xpc_clear_interface(void)
92 xpc_interface.connect = (void (*)(int))xpc_notloaded;
93 xpc_interface.disconnect = (void (*)(int))xpc_notloaded;
94 xpc_interface.allocate = (enum xp_retval(*)(short, int, u32,
95 void **))xpc_notloaded;
96 xpc_interface.send = (enum xp_retval(*)(short, int, void *))
98 xpc_interface.send_notify = (enum xp_retval(*)(short, int, void *,
100 void *))xpc_notloaded;
101 xpc_interface.received = (void (*)(short, int, void *))
103 xpc_interface.partid_to_nasids = (enum xp_retval(*)(short, void *))
106 EXPORT_SYMBOL_GPL(xpc_clear_interface);
109 * Register for automatic establishment of a channel connection whenever
110 * a partition comes up.
114 * ch_number - channel # to register for connection.
115 * func - function to call for asynchronous notification of channel
116 * state changes (i.e., connection, disconnection, error) and
117 * the arrival of incoming messages.
118 * key - pointer to optional user-defined value that gets passed back
119 * to the user on any callouts made to func.
120 * payload_size - size in bytes of the XPC message's payload area which
121 * contains a user-defined message. The user should make
122 * this large enough to hold their largest message.
123 * nentries - max #of XPC message entries a message queue can contain.
124 * The actual number, which is determined when a connection
125 * is established and may be less then requested, will be
126 * passed to the user via the xpConnected callout.
127 * assigned_limit - max number of kthreads allowed to be processing
128 * messages (per connection) at any given instant.
129 * idle_limit - max number of kthreads allowed to be idle at any given
133 xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
134 u16 nentries, u32 assigned_limit, u32 idle_limit)
136 struct xpc_registration *registration;
138 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS);
139 DBUG_ON(payload_size == 0 || nentries == 0);
140 DBUG_ON(func == NULL);
141 DBUG_ON(assigned_limit == 0 || idle_limit > assigned_limit);
143 registration = &xpc_registrations[ch_number];
145 if (mutex_lock_interruptible(®istration->mutex) != 0)
146 return xpInterrupted;
148 /* if XPC_CHANNEL_REGISTERED(ch_number) */
149 if (registration->func != NULL) {
150 mutex_unlock(®istration->mutex);
151 return xpAlreadyRegistered;
154 /* register the channel for connection */
155 registration->msg_size = XPC_MSG_SIZE(payload_size);
156 registration->nentries = nentries;
157 registration->assigned_limit = assigned_limit;
158 registration->idle_limit = idle_limit;
159 registration->key = key;
160 registration->func = func;
162 mutex_unlock(®istration->mutex);
164 xpc_interface.connect(ch_number);
168 EXPORT_SYMBOL_GPL(xpc_connect);
171 * Remove the registration for automatic connection of the specified channel
172 * when a partition comes up.
174 * Before returning this xpc_disconnect() will wait for all connections on the
175 * specified channel have been closed/torndown. So the caller can be assured
176 * that they will not be receiving any more callouts from XPC to their
177 * function registered via xpc_connect().
181 * ch_number - channel # to unregister.
184 xpc_disconnect(int ch_number)
186 struct xpc_registration *registration;
188 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS);
190 registration = &xpc_registrations[ch_number];
193 * We've decided not to make this a down_interruptible(), since we
194 * figured XPC's users will just turn around and call xpc_disconnect()
195 * again anyways, so we might as well wait, if need be.
197 mutex_lock(®istration->mutex);
199 /* if !XPC_CHANNEL_REGISTERED(ch_number) */
200 if (registration->func == NULL) {
201 mutex_unlock(®istration->mutex);
205 /* remove the connection registration for the specified channel */
206 registration->func = NULL;
207 registration->key = NULL;
208 registration->nentries = 0;
209 registration->msg_size = 0;
210 registration->assigned_limit = 0;
211 registration->idle_limit = 0;
213 xpc_interface.disconnect(ch_number);
215 mutex_unlock(®istration->mutex);
219 EXPORT_SYMBOL_GPL(xpc_disconnect);
225 u64 func_addr = *(u64 *)xp_nofault_PIOR;
226 u64 err_func_addr = *(u64 *)xp_error_PIOR;
228 if (!ia64_platform_is("sn2"))
232 * Register a nofault code region which performs a cross-partition
233 * PIO read. If the PIO read times out, the MCA handler will consume
234 * the error and return to a kernel-provided instruction to indicate
235 * an error. This PIO read exists because it is guaranteed to timeout
236 * if the destination is down (AMO operations do not timeout on at
237 * least some CPUs on Shubs <= v1.2, which unfortunately we have to
240 ret = sn_register_nofault_code(func_addr, err_func_addr, err_func_addr,
243 printk(KERN_ERR "XP: can't register nofault code, error=%d\n",
247 * Setup the nofault PIO read target. (There is no special reason why
248 * SH_IPI_ACCESS was selected.)
251 xp_nofault_PIOR_target = SH2_IPI_ACCESS0;
253 xp_nofault_PIOR_target = SH1_IPI_ACCESS;
255 /* initialize the connection registration mutex */
256 for (ch_number = 0; ch_number < XPC_NCHANNELS; ch_number++)
257 mutex_init(&xpc_registrations[ch_number].mutex);
262 module_init(xp_init);
267 u64 func_addr = *(u64 *)xp_nofault_PIOR;
268 u64 err_func_addr = *(u64 *)xp_error_PIOR;
270 /* unregister the PIO read nofault code region */
271 (void)sn_register_nofault_code(func_addr, err_func_addr,
272 err_func_addr, 1, 0);
275 module_exit(xp_exit);
277 MODULE_AUTHOR("Silicon Graphics, Inc.");
278 MODULE_DESCRIPTION("Cross Partition (XP) base");
279 MODULE_LICENSE("GPL");