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 * Target of nofault PIO read.
28 u64 xp_nofault_PIOR_target;
31 * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level
34 struct xpc_registration xpc_registrations[XPC_NCHANNELS];
37 * Initialize the XPC interface to indicate that XPC isn't loaded.
39 static enum xpc_retval
45 struct xpc_interface xpc_interface = {
46 (void (*)(int))xpc_notloaded,
47 (void (*)(int))xpc_notloaded,
48 (enum xpc_retval(*)(partid_t, int, u32, void **))xpc_notloaded,
49 (enum xpc_retval(*)(partid_t, int, void *))xpc_notloaded,
50 (enum xpc_retval(*)(partid_t, int, void *, xpc_notify_func, void *))
52 (void (*)(partid_t, int, void *))xpc_notloaded,
53 (enum xpc_retval(*)(partid_t, void *))xpc_notloaded
57 * XPC calls this when it (the XPC module) has been loaded.
60 xpc_set_interface(void (*connect) (int),
61 void (*disconnect) (int),
62 enum xpc_retval (*allocate) (partid_t, int, u32, void **),
63 enum xpc_retval (*send) (partid_t, int, void *),
64 enum xpc_retval (*send_notify) (partid_t, int, void *,
65 xpc_notify_func, void *),
66 void (*received) (partid_t, int, void *),
67 enum xpc_retval (*partid_to_nasids) (partid_t, void *))
69 xpc_interface.connect = connect;
70 xpc_interface.disconnect = disconnect;
71 xpc_interface.allocate = allocate;
72 xpc_interface.send = send;
73 xpc_interface.send_notify = send_notify;
74 xpc_interface.received = received;
75 xpc_interface.partid_to_nasids = partid_to_nasids;
79 * XPC calls this when it (the XPC module) is being unloaded.
82 xpc_clear_interface(void)
84 xpc_interface.connect = (void (*)(int))xpc_notloaded;
85 xpc_interface.disconnect = (void (*)(int))xpc_notloaded;
86 xpc_interface.allocate = (enum xpc_retval(*)(partid_t, int, u32,
87 void **))xpc_notloaded;
88 xpc_interface.send = (enum xpc_retval(*)(partid_t, int, void *))
90 xpc_interface.send_notify = (enum xpc_retval(*)(partid_t, int, void *,
92 void *))xpc_notloaded;
93 xpc_interface.received = (void (*)(partid_t, int, void *))
95 xpc_interface.partid_to_nasids = (enum xpc_retval(*)(partid_t, void *))
100 * Register for automatic establishment of a channel connection whenever
101 * a partition comes up.
105 * ch_number - channel # to register for connection.
106 * func - function to call for asynchronous notification of channel
107 * state changes (i.e., connection, disconnection, error) and
108 * the arrival of incoming messages.
109 * key - pointer to optional user-defined value that gets passed back
110 * to the user on any callouts made to func.
111 * payload_size - size in bytes of the XPC message's payload area which
112 * contains a user-defined message. The user should make
113 * this large enough to hold their largest message.
114 * nentries - max #of XPC message entries a message queue can contain.
115 * The actual number, which is determined when a connection
116 * is established and may be less then requested, will be
117 * passed to the user via the xpcConnected callout.
118 * assigned_limit - max number of kthreads allowed to be processing
119 * messages (per connection) at any given instant.
120 * idle_limit - max number of kthreads allowed to be idle at any given
124 xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
125 u16 nentries, u32 assigned_limit, u32 idle_limit)
127 struct xpc_registration *registration;
129 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS);
130 DBUG_ON(payload_size == 0 || nentries == 0);
131 DBUG_ON(func == NULL);
132 DBUG_ON(assigned_limit == 0 || idle_limit > assigned_limit);
134 registration = &xpc_registrations[ch_number];
136 if (mutex_lock_interruptible(®istration->mutex) != 0) {
137 return xpcInterrupted;
140 /* if XPC_CHANNEL_REGISTERED(ch_number) */
141 if (registration->func != NULL) {
142 mutex_unlock(®istration->mutex);
143 return xpcAlreadyRegistered;
146 /* register the channel for connection */
147 registration->msg_size = XPC_MSG_SIZE(payload_size);
148 registration->nentries = nentries;
149 registration->assigned_limit = assigned_limit;
150 registration->idle_limit = idle_limit;
151 registration->key = key;
152 registration->func = func;
154 mutex_unlock(®istration->mutex);
156 xpc_interface.connect(ch_number);
162 * Remove the registration for automatic connection of the specified channel
163 * when a partition comes up.
165 * Before returning this xpc_disconnect() will wait for all connections on the
166 * specified channel have been closed/torndown. So the caller can be assured
167 * that they will not be receiving any more callouts from XPC to their
168 * function registered via xpc_connect().
172 * ch_number - channel # to unregister.
175 xpc_disconnect(int ch_number)
177 struct xpc_registration *registration;
179 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS);
181 registration = &xpc_registrations[ch_number];
184 * We've decided not to make this a down_interruptible(), since we
185 * figured XPC's users will just turn around and call xpc_disconnect()
186 * again anyways, so we might as well wait, if need be.
188 mutex_lock(®istration->mutex);
190 /* if !XPC_CHANNEL_REGISTERED(ch_number) */
191 if (registration->func == NULL) {
192 mutex_unlock(®istration->mutex);
196 /* remove the connection registration for the specified channel */
197 registration->func = NULL;
198 registration->key = NULL;
199 registration->nentries = 0;
200 registration->msg_size = 0;
201 registration->assigned_limit = 0;
202 registration->idle_limit = 0;
204 xpc_interface.disconnect(ch_number);
206 mutex_unlock(®istration->mutex);
215 u64 func_addr = *(u64 *)xp_nofault_PIOR;
216 u64 err_func_addr = *(u64 *)xp_error_PIOR;
218 if (!ia64_platform_is("sn2")) {
223 * Register a nofault code region which performs a cross-partition
224 * PIO read. If the PIO read times out, the MCA handler will consume
225 * the error and return to a kernel-provided instruction to indicate
226 * an error. This PIO read exists because it is guaranteed to timeout
227 * if the destination is down (AMO operations do not timeout on at
228 * least some CPUs on Shubs <= v1.2, which unfortunately we have to
231 if ((ret = sn_register_nofault_code(func_addr, err_func_addr,
232 err_func_addr, 1, 1)) != 0) {
233 printk(KERN_ERR "XP: can't register nofault code, error=%d\n",
237 * Setup the nofault PIO read target. (There is no special reason why
238 * SH_IPI_ACCESS was selected.)
241 xp_nofault_PIOR_target = SH2_IPI_ACCESS0;
243 xp_nofault_PIOR_target = SH1_IPI_ACCESS;
246 /* initialize the connection registration mutex */
247 for (ch_number = 0; ch_number < XPC_NCHANNELS; ch_number++) {
248 mutex_init(&xpc_registrations[ch_number].mutex);
254 module_init(xp_init);
259 u64 func_addr = *(u64 *)xp_nofault_PIOR;
260 u64 err_func_addr = *(u64 *)xp_error_PIOR;
262 /* unregister the PIO read nofault code region */
263 (void)sn_register_nofault_code(func_addr, err_func_addr,
264 err_func_addr, 1, 0);
267 module_exit(xp_exit);
269 MODULE_AUTHOR("Silicon Graphics, Inc.");
270 MODULE_DESCRIPTION("Cross Partition (XP) base");
271 MODULE_LICENSE("GPL");
273 EXPORT_SYMBOL(xp_nofault_PIOR);
274 EXPORT_SYMBOL(xp_nofault_PIOR_target);
275 EXPORT_SYMBOL(xpc_registrations);
276 EXPORT_SYMBOL(xpc_interface);
277 EXPORT_SYMBOL(xpc_clear_interface);
278 EXPORT_SYMBOL(xpc_set_interface);
279 EXPORT_SYMBOL(xpc_connect);
280 EXPORT_SYMBOL(xpc_disconnect);