Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 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 | * |
Dean Nelson | 45d9ca4 | 2008-04-22 14:46:56 -0500 | [diff] [blame] | 6 | * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved. |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 9 | /* |
| 10 | * Cross Partition (XP) base. |
| 11 | * |
| 12 | * XP provides a base from which its users can interact |
| 13 | * with XPC, yet not be dependent on XPC. |
| 14 | * |
| 15 | */ |
| 16 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 17 | #include <linux/kernel.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/module.h> |
Jes Sorensen | f9e505a | 2006-01-17 12:52:21 -0500 | [diff] [blame] | 20 | #include <linux/mutex.h> |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 21 | #include <asm/sn/intr.h> |
| 22 | #include <asm/sn/sn_sal.h> |
Dean Nelson | 45d9ca4 | 2008-04-22 14:46:56 -0500 | [diff] [blame] | 23 | #include "xp.h" |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 24 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 25 | /* |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 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 |
| 28 | * defined here. |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 29 | */ |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 30 | EXPORT_SYMBOL_GPL(xp_nofault_PIOR); |
| 31 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 32 | u64 xp_nofault_PIOR_target; |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 33 | EXPORT_SYMBOL_GPL(xp_nofault_PIOR_target); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 34 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 35 | /* |
| 36 | * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level |
| 37 | * users of XPC. |
| 38 | */ |
| 39 | struct xpc_registration xpc_registrations[XPC_NCHANNELS]; |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 40 | EXPORT_SYMBOL_GPL(xpc_registrations); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 41 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 42 | /* |
| 43 | * Initialize the XPC interface to indicate that XPC isn't loaded. |
| 44 | */ |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 45 | static enum xpc_retval |
| 46 | xpc_notloaded(void) |
| 47 | { |
| 48 | return xpcNotLoaded; |
| 49 | } |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 50 | |
| 51 | struct xpc_interface xpc_interface = { |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 52 | (void (*)(int))xpc_notloaded, |
| 53 | (void (*)(int))xpc_notloaded, |
| 54 | (enum xpc_retval(*)(partid_t, int, u32, void **))xpc_notloaded, |
| 55 | (enum xpc_retval(*)(partid_t, int, void *))xpc_notloaded, |
| 56 | (enum xpc_retval(*)(partid_t, int, void *, xpc_notify_func, void *)) |
| 57 | xpc_notloaded, |
| 58 | (void (*)(partid_t, int, void *))xpc_notloaded, |
| 59 | (enum xpc_retval(*)(partid_t, void *))xpc_notloaded |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 60 | }; |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 61 | EXPORT_SYMBOL_GPL(xpc_interface); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 62 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 63 | /* |
| 64 | * XPC calls this when it (the XPC module) has been loaded. |
| 65 | */ |
| 66 | void |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 67 | xpc_set_interface(void (*connect) (int), |
| 68 | void (*disconnect) (int), |
| 69 | enum xpc_retval (*allocate) (partid_t, int, u32, void **), |
| 70 | enum xpc_retval (*send) (partid_t, int, void *), |
| 71 | enum xpc_retval (*send_notify) (partid_t, int, void *, |
| 72 | xpc_notify_func, void *), |
| 73 | void (*received) (partid_t, int, void *), |
| 74 | enum xpc_retval (*partid_to_nasids) (partid_t, void *)) |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 75 | { |
| 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; |
| 83 | } |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 84 | EXPORT_SYMBOL_GPL(xpc_set_interface); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 85 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 86 | /* |
| 87 | * XPC calls this when it (the XPC module) is being unloaded. |
| 88 | */ |
| 89 | void |
| 90 | xpc_clear_interface(void) |
| 91 | { |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 92 | xpc_interface.connect = (void (*)(int))xpc_notloaded; |
| 93 | xpc_interface.disconnect = (void (*)(int))xpc_notloaded; |
| 94 | xpc_interface.allocate = (enum xpc_retval(*)(partid_t, int, u32, |
| 95 | void **))xpc_notloaded; |
| 96 | xpc_interface.send = (enum xpc_retval(*)(partid_t, int, void *)) |
| 97 | xpc_notloaded; |
| 98 | xpc_interface.send_notify = (enum xpc_retval(*)(partid_t, int, void *, |
| 99 | xpc_notify_func, |
| 100 | void *))xpc_notloaded; |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 101 | xpc_interface.received = (void (*)(partid_t, int, void *)) |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 102 | xpc_notloaded; |
| 103 | xpc_interface.partid_to_nasids = (enum xpc_retval(*)(partid_t, void *)) |
| 104 | xpc_notloaded; |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 105 | } |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 106 | EXPORT_SYMBOL_GPL(xpc_clear_interface); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 107 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 108 | /* |
| 109 | * Register for automatic establishment of a channel connection whenever |
| 110 | * a partition comes up. |
| 111 | * |
| 112 | * Arguments: |
| 113 | * |
| 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 xpcConnected 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 |
| 130 | * instant. |
| 131 | */ |
| 132 | enum xpc_retval |
| 133 | xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size, |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 134 | u16 nentries, u32 assigned_limit, u32 idle_limit) |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 135 | { |
| 136 | struct xpc_registration *registration; |
| 137 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 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); |
| 142 | |
| 143 | registration = &xpc_registrations[ch_number]; |
| 144 | |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 145 | if (mutex_lock_interruptible(®istration->mutex) != 0) |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 146 | return xpcInterrupted; |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 147 | |
| 148 | /* if XPC_CHANNEL_REGISTERED(ch_number) */ |
| 149 | if (registration->func != NULL) { |
Jes Sorensen | f9e505a | 2006-01-17 12:52:21 -0500 | [diff] [blame] | 150 | mutex_unlock(®istration->mutex); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 151 | return xpcAlreadyRegistered; |
| 152 | } |
| 153 | |
| 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; |
| 161 | |
Jes Sorensen | f9e505a | 2006-01-17 12:52:21 -0500 | [diff] [blame] | 162 | mutex_unlock(®istration->mutex); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 163 | |
| 164 | xpc_interface.connect(ch_number); |
| 165 | |
| 166 | return xpcSuccess; |
| 167 | } |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 168 | EXPORT_SYMBOL_GPL(xpc_connect); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 169 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 170 | /* |
| 171 | * Remove the registration for automatic connection of the specified channel |
| 172 | * when a partition comes up. |
| 173 | * |
| 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(). |
| 178 | * |
| 179 | * Arguments: |
| 180 | * |
| 181 | * ch_number - channel # to unregister. |
| 182 | */ |
| 183 | void |
| 184 | xpc_disconnect(int ch_number) |
| 185 | { |
| 186 | struct xpc_registration *registration; |
| 187 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 188 | DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS); |
| 189 | |
| 190 | registration = &xpc_registrations[ch_number]; |
| 191 | |
| 192 | /* |
| 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. |
| 196 | */ |
Jes Sorensen | f9e505a | 2006-01-17 12:52:21 -0500 | [diff] [blame] | 197 | mutex_lock(®istration->mutex); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 198 | |
| 199 | /* if !XPC_CHANNEL_REGISTERED(ch_number) */ |
| 200 | if (registration->func == NULL) { |
Jes Sorensen | f9e505a | 2006-01-17 12:52:21 -0500 | [diff] [blame] | 201 | mutex_unlock(®istration->mutex); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 202 | return; |
| 203 | } |
| 204 | |
| 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; |
| 212 | |
| 213 | xpc_interface.disconnect(ch_number); |
| 214 | |
Jes Sorensen | f9e505a | 2006-01-17 12:52:21 -0500 | [diff] [blame] | 215 | mutex_unlock(®istration->mutex); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 216 | |
| 217 | return; |
| 218 | } |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 219 | EXPORT_SYMBOL_GPL(xpc_disconnect); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 220 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 221 | int __init |
| 222 | xp_init(void) |
| 223 | { |
| 224 | int ret, ch_number; |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 225 | u64 func_addr = *(u64 *)xp_nofault_PIOR; |
| 226 | u64 err_func_addr = *(u64 *)xp_error_PIOR; |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 227 | |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 228 | if (!ia64_platform_is("sn2")) |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 229 | return -ENODEV; |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 230 | |
| 231 | /* |
| 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 |
| 238 | * work around). |
| 239 | */ |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 240 | ret = sn_register_nofault_code(func_addr, err_func_addr, err_func_addr, |
| 241 | 1, 1); |
| 242 | if (ret != 0) { |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 243 | printk(KERN_ERR "XP: can't register nofault code, error=%d\n", |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 244 | ret); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 245 | } |
| 246 | /* |
| 247 | * Setup the nofault PIO read target. (There is no special reason why |
| 248 | * SH_IPI_ACCESS was selected.) |
| 249 | */ |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 250 | if (is_shub2()) |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 251 | xp_nofault_PIOR_target = SH2_IPI_ACCESS0; |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 252 | else |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 253 | xp_nofault_PIOR_target = SH1_IPI_ACCESS; |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 254 | |
Jes Sorensen | f9e505a | 2006-01-17 12:52:21 -0500 | [diff] [blame] | 255 | /* initialize the connection registration mutex */ |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame^] | 256 | for (ch_number = 0; ch_number < XPC_NCHANNELS; ch_number++) |
Jes Sorensen | f9e505a | 2006-01-17 12:52:21 -0500 | [diff] [blame] | 257 | mutex_init(&xpc_registrations[ch_number].mutex); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 258 | |
| 259 | return 0; |
| 260 | } |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 261 | |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 262 | module_init(xp_init); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 263 | |
| 264 | void __exit |
| 265 | xp_exit(void) |
| 266 | { |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 267 | u64 func_addr = *(u64 *)xp_nofault_PIOR; |
| 268 | u64 err_func_addr = *(u64 *)xp_error_PIOR; |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 269 | |
| 270 | /* unregister the PIO read nofault code region */ |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 271 | (void)sn_register_nofault_code(func_addr, err_func_addr, |
| 272 | err_func_addr, 1, 0); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 273 | } |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 274 | |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 275 | module_exit(xp_exit); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 276 | |
| 277 | MODULE_AUTHOR("Silicon Graphics, Inc."); |
| 278 | MODULE_DESCRIPTION("Cross Partition (XP) base"); |
| 279 | MODULE_LICENSE("GPL"); |