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 | * External Cross Partition (XP) structures and defines. |
| 11 | */ |
| 12 | |
Dean Nelson | 45d9ca4 | 2008-04-22 14:46:56 -0500 | [diff] [blame] | 13 | #ifndef _DRIVERS_MISC_SGIXP_XP_H |
| 14 | #define _DRIVERS_MISC_SGIXP_XP_H |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 15 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 16 | #include <linux/cache.h> |
| 17 | #include <linux/hardirq.h> |
Jes Sorensen | f9e505a | 2006-01-17 12:52:21 -0500 | [diff] [blame] | 18 | #include <linux/mutex.h> |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 19 | #include <asm/sn/types.h> |
| 20 | #include <asm/sn/bte.h> |
| 21 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 22 | #ifdef USE_DBUG_ON |
| 23 | #define DBUG_ON(condition) BUG_ON(condition) |
| 24 | #else |
| 25 | #define DBUG_ON(condition) |
| 26 | #endif |
| 27 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 28 | /* |
| 29 | * Define the maximum number of logically defined partitions the system |
| 30 | * can support. It is constrained by the maximum number of hardware |
| 31 | * partitionable regions. The term 'region' in this context refers to the |
| 32 | * minimum number of nodes that can comprise an access protection grouping. |
| 33 | * The access protection is in regards to memory, IPI and IOI. |
| 34 | * |
| 35 | * The maximum number of hardware partitionable regions is equal to the |
| 36 | * maximum number of nodes in the entire system divided by the minimum number |
| 37 | * of nodes that comprise an access protection grouping. |
| 38 | */ |
| 39 | #define XP_MAX_PARTITIONS 64 |
| 40 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 41 | /* |
| 42 | * Define the number of u64s required to represent all the C-brick nasids |
| 43 | * as a bitmap. The cross-partition kernel modules deal only with |
| 44 | * C-brick nasids, thus the need for bitmaps which don't account for |
| 45 | * odd-numbered (non C-brick) nasids. |
| 46 | */ |
Jack Steiner | 24ee0a6 | 2005-09-12 12:15:43 -0500 | [diff] [blame] | 47 | #define XP_MAX_PHYSNODE_ID (MAX_NUMALINK_NODES / 2) |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 48 | #define XP_NASID_MASK_BYTES ((XP_MAX_PHYSNODE_ID + 7) / 8) |
| 49 | #define XP_NASID_MASK_WORDS ((XP_MAX_PHYSNODE_ID + 63) / 64) |
| 50 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Wrapper for bte_copy() that should it return a failure status will retry |
| 53 | * the bte_copy() once in the hope that the failure was due to a temporary |
| 54 | * aberration (i.e., the link going down temporarily). |
| 55 | * |
Dean Nelson | 7682a4c | 2006-08-08 15:03:29 -0500 | [diff] [blame] | 56 | * src - physical address of the source of the transfer. |
| 57 | * vdst - virtual address of the destination of the transfer. |
| 58 | * len - number of bytes to transfer from source to destination. |
| 59 | * mode - see bte_copy() for definition. |
| 60 | * notification - see bte_copy() for definition. |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 61 | * |
| 62 | * Note: xp_bte_copy() should never be called while holding a spinlock. |
| 63 | */ |
| 64 | static inline bte_result_t |
Dean Nelson | 7682a4c | 2006-08-08 15:03:29 -0500 | [diff] [blame] | 65 | xp_bte_copy(u64 src, u64 vdst, u64 len, u64 mode, void *notification) |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 66 | { |
| 67 | bte_result_t ret; |
Dean Nelson | 7682a4c | 2006-08-08 15:03:29 -0500 | [diff] [blame] | 68 | u64 pdst = ia64_tpa(vdst); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 69 | |
Dean Nelson | 7682a4c | 2006-08-08 15:03:29 -0500 | [diff] [blame] | 70 | /* |
| 71 | * Ensure that the physically mapped memory is contiguous. |
| 72 | * |
| 73 | * We do this by ensuring that the memory is from region 7 only. |
| 74 | * If the need should arise to use memory from one of the other |
| 75 | * regions, then modify the BUG_ON() statement to ensure that the |
| 76 | * memory from that region is always physically contiguous. |
| 77 | */ |
| 78 | BUG_ON(REGION_NUMBER(vdst) != RGN_KERNEL); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 79 | |
Dean Nelson | 7682a4c | 2006-08-08 15:03:29 -0500 | [diff] [blame] | 80 | ret = bte_copy(src, pdst, len, mode, notification); |
Russ Anderson | 64135fa | 2007-08-21 16:45:12 -0500 | [diff] [blame] | 81 | if ((ret != BTE_SUCCESS) && BTE_ERROR_RETRY(ret)) { |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 82 | if (!in_interrupt()) |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 83 | cond_resched(); |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 84 | |
Dean Nelson | 7682a4c | 2006-08-08 15:03:29 -0500 | [diff] [blame] | 85 | ret = bte_copy(src, pdst, len, mode, notification); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | return ret; |
| 89 | } |
| 90 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 91 | /* |
| 92 | * XPC establishes channel connections between the local partition and any |
| 93 | * other partition that is currently up. Over these channels, kernel-level |
| 94 | * `users' can communicate with their counterparts on the other partitions. |
| 95 | * |
| 96 | * The maxinum number of channels is limited to eight. For performance reasons, |
| 97 | * the internal cross partition structures require sixteen bytes per channel, |
| 98 | * and eight allows all of this interface-shared info to fit in one cache line. |
| 99 | * |
| 100 | * XPC_NCHANNELS reflects the total number of channels currently defined. |
| 101 | * If the need for additional channels arises, one can simply increase |
| 102 | * XPC_NCHANNELS accordingly. If the day should come where that number |
| 103 | * exceeds the MAXIMUM number of channels allowed (eight), then one will need |
| 104 | * to make changes to the XPC code to allow for this. |
| 105 | */ |
| 106 | #define XPC_MEM_CHANNEL 0 /* memory channel number */ |
| 107 | #define XPC_NET_CHANNEL 1 /* network channel number */ |
| 108 | |
| 109 | #define XPC_NCHANNELS 2 /* #of defined channels */ |
| 110 | #define XPC_MAX_NCHANNELS 8 /* max #of channels allowed */ |
| 111 | |
| 112 | #if XPC_NCHANNELS > XPC_MAX_NCHANNELS |
| 113 | #error XPC_NCHANNELS exceeds MAXIMUM allowed. |
| 114 | #endif |
| 115 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 116 | /* |
| 117 | * The format of an XPC message is as follows: |
| 118 | * |
| 119 | * +-------+--------------------------------+ |
| 120 | * | flags |////////////////////////////////| |
| 121 | * +-------+--------------------------------+ |
| 122 | * | message # | |
| 123 | * +----------------------------------------+ |
| 124 | * | payload (user-defined message) | |
| 125 | * | | |
| 126 | * : |
| 127 | * | | |
| 128 | * +----------------------------------------+ |
| 129 | * |
| 130 | * The size of the payload is defined by the user via xpc_connect(). A user- |
| 131 | * defined message resides in the payload area. |
| 132 | * |
| 133 | * The user should have no dealings with the message header, but only the |
| 134 | * message's payload. When a message entry is allocated (via xpc_allocate()) |
| 135 | * a pointer to the payload area is returned and not the actual beginning of |
| 136 | * the XPC message. The user then constructs a message in the payload area |
| 137 | * and passes that pointer as an argument on xpc_send() or xpc_send_notify(). |
| 138 | * |
| 139 | * The size of a message entry (within a message queue) must be a cacheline |
| 140 | * sized multiple in order to facilitate the BTE transfer of messages from one |
| 141 | * message queue to another. A macro, XPC_MSG_SIZE(), is provided for the user |
| 142 | * that wants to fit as many msg entries as possible in a given memory size |
| 143 | * (e.g. a memory page). |
| 144 | */ |
| 145 | struct xpc_msg { |
| 146 | u8 flags; /* FOR XPC INTERNAL USE ONLY */ |
| 147 | u8 reserved[7]; /* FOR XPC INTERNAL USE ONLY */ |
| 148 | s64 number; /* FOR XPC INTERNAL USE ONLY */ |
| 149 | |
| 150 | u64 payload; /* user defined portion of message */ |
| 151 | }; |
| 152 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 153 | #define XPC_MSG_PAYLOAD_OFFSET (u64) (&((struct xpc_msg *)0)->payload) |
| 154 | #define XPC_MSG_SIZE(_payload_size) \ |
| 155 | L1_CACHE_ALIGN(XPC_MSG_PAYLOAD_OFFSET + (_payload_size)) |
| 156 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 157 | /* |
| 158 | * Define the return values and values passed to user's callout functions. |
| 159 | * (It is important to add new value codes at the end just preceding |
| 160 | * xpcUnknownReason, which must have the highest numerical value.) |
| 161 | */ |
| 162 | enum xpc_retval { |
| 163 | xpcSuccess = 0, |
| 164 | |
| 165 | xpcNotConnected, /* 1: channel is not connected */ |
| 166 | xpcConnected, /* 2: channel connected (opened) */ |
| 167 | xpcRETIRED1, /* 3: (formerly xpcDisconnected) */ |
| 168 | |
| 169 | xpcMsgReceived, /* 4: message received */ |
| 170 | xpcMsgDelivered, /* 5: message delivered and acknowledged */ |
| 171 | |
| 172 | xpcRETIRED2, /* 6: (formerly xpcTransferFailed) */ |
| 173 | |
| 174 | xpcNoWait, /* 7: operation would require wait */ |
| 175 | xpcRetry, /* 8: retry operation */ |
| 176 | xpcTimeout, /* 9: timeout in xpc_allocate_msg_wait() */ |
| 177 | xpcInterrupted, /* 10: interrupted wait */ |
| 178 | |
| 179 | xpcUnequalMsgSizes, /* 11: message size disparity between sides */ |
| 180 | xpcInvalidAddress, /* 12: invalid address */ |
| 181 | |
| 182 | xpcNoMemory, /* 13: no memory available for XPC structures */ |
| 183 | xpcLackOfResources, /* 14: insufficient resources for operation */ |
| 184 | xpcUnregistered, /* 15: channel is not registered */ |
| 185 | xpcAlreadyRegistered, /* 16: channel is already registered */ |
| 186 | |
| 187 | xpcPartitionDown, /* 17: remote partition is down */ |
| 188 | xpcNotLoaded, /* 18: XPC module is not loaded */ |
| 189 | xpcUnloading, /* 19: this side is unloading XPC module */ |
| 190 | |
| 191 | xpcBadMagic, /* 20: XPC MAGIC string not found */ |
| 192 | |
| 193 | xpcReactivating, /* 21: remote partition was reactivated */ |
| 194 | |
| 195 | xpcUnregistering, /* 22: this side is unregistering channel */ |
| 196 | xpcOtherUnregistering, /* 23: other side is unregistering channel */ |
| 197 | |
| 198 | xpcCloneKThread, /* 24: cloning kernel thread */ |
| 199 | xpcCloneKThreadFailed, /* 25: cloning kernel thread failed */ |
| 200 | |
| 201 | xpcNoHeartbeat, /* 26: remote partition has no heartbeat */ |
| 202 | |
| 203 | xpcPioReadError, /* 27: PIO read error */ |
| 204 | xpcPhysAddrRegFailed, /* 28: registration of phys addr range failed */ |
| 205 | |
| 206 | xpcBteDirectoryError, /* 29: maps to BTEFAIL_DIR */ |
| 207 | xpcBtePoisonError, /* 30: maps to BTEFAIL_POISON */ |
| 208 | xpcBteWriteError, /* 31: maps to BTEFAIL_WERR */ |
| 209 | xpcBteAccessError, /* 32: maps to BTEFAIL_ACCESS */ |
| 210 | xpcBtePWriteError, /* 33: maps to BTEFAIL_PWERR */ |
| 211 | xpcBtePReadError, /* 34: maps to BTEFAIL_PRERR */ |
| 212 | xpcBteTimeOutError, /* 35: maps to BTEFAIL_TOUT */ |
| 213 | xpcBteXtalkError, /* 36: maps to BTEFAIL_XTERR */ |
| 214 | xpcBteNotAvailable, /* 37: maps to BTEFAIL_NOTAVAIL */ |
| 215 | xpcBteUnmappedError, /* 38: unmapped BTEFAIL_ error */ |
| 216 | |
| 217 | xpcBadVersion, /* 39: bad version number */ |
| 218 | xpcVarsNotSet, /* 40: the XPC variables are not set up */ |
| 219 | xpcNoRsvdPageAddr, /* 41: unable to get rsvd page's phys addr */ |
| 220 | xpcInvalidPartid, /* 42: invalid partition ID */ |
| 221 | xpcLocalPartid, /* 43: local partition ID */ |
| 222 | |
Dean Nelson | a607c389 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 223 | xpcOtherGoingDown, /* 44: other side going down, reason unknown */ |
| 224 | xpcSystemGoingDown, /* 45: system is going down, reason unknown */ |
| 225 | xpcSystemHalt, /* 46: system is being halted */ |
| 226 | xpcSystemReboot, /* 47: system is being rebooted */ |
| 227 | xpcSystemPoweroff, /* 48: system is being powered off */ |
| 228 | |
| 229 | xpcDisconnecting, /* 49: channel disconnecting (closing) */ |
| 230 | |
Dean Nelson | e54af72 | 2005-10-25 14:07:43 -0500 | [diff] [blame] | 231 | xpcOpenCloseError, /* 50: channel open/close protocol error */ |
| 232 | |
Dean Nelson | 246c7e3 | 2005-12-22 14:32:56 -0600 | [diff] [blame] | 233 | xpcDisconnected, /* 51: channel disconnected (closed) */ |
| 234 | |
Russ Anderson | 64135fa | 2007-08-21 16:45:12 -0500 | [diff] [blame] | 235 | xpcBteSh2Start, /* 52: BTE CRB timeout */ |
| 236 | |
| 237 | /* 53: 0x1 BTE Error Response Short */ |
| 238 | xpcBteSh2RspShort = xpcBteSh2Start + BTEFAIL_SH2_RESP_SHORT, |
| 239 | |
| 240 | /* 54: 0x2 BTE Error Response Long */ |
| 241 | xpcBteSh2RspLong = xpcBteSh2Start + BTEFAIL_SH2_RESP_LONG, |
| 242 | |
| 243 | /* 56: 0x4 BTE Error Response DSB */ |
| 244 | xpcBteSh2RspDSB = xpcBteSh2Start + BTEFAIL_SH2_RESP_DSP, |
| 245 | |
| 246 | /* 60: 0x8 BTE Error Response Access */ |
| 247 | xpcBteSh2RspAccess = xpcBteSh2Start + BTEFAIL_SH2_RESP_ACCESS, |
| 248 | |
| 249 | /* 68: 0x10 BTE Error CRB timeout */ |
| 250 | xpcBteSh2CRBTO = xpcBteSh2Start + BTEFAIL_SH2_CRB_TO, |
| 251 | |
| 252 | /* 84: 0x20 BTE Error NACK limit */ |
| 253 | xpcBteSh2NACKLimit = xpcBteSh2Start + BTEFAIL_SH2_NACK_LIMIT, |
| 254 | |
| 255 | /* 115: BTE end */ |
| 256 | xpcBteSh2End = xpcBteSh2Start + BTEFAIL_SH2_ALL, |
| 257 | |
Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 258 | xpcUnknownReason /* 116: unknown reason - must be last in enum */ |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 259 | }; |
| 260 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 261 | /* |
| 262 | * Define the callout function types used by XPC to update the user on |
| 263 | * connection activity and state changes (via the user function registered by |
| 264 | * xpc_connect()) and to notify them of messages received and delivered (via |
| 265 | * the user function registered by xpc_send_notify()). |
| 266 | * |
| 267 | * The two function types are xpc_channel_func and xpc_notify_func and |
| 268 | * both share the following arguments, with the exception of "data", which |
| 269 | * only xpc_channel_func has. |
| 270 | * |
| 271 | * Arguments: |
| 272 | * |
| 273 | * reason - reason code. (See following table.) |
| 274 | * partid - partition ID associated with condition. |
| 275 | * ch_number - channel # associated with condition. |
| 276 | * data - pointer to optional data. (See following table.) |
| 277 | * key - pointer to optional user-defined value provided as the "key" |
| 278 | * argument to xpc_connect() or xpc_send_notify(). |
| 279 | * |
| 280 | * In the following table the "Optional Data" column applies to callouts made |
| 281 | * to functions registered by xpc_connect(). A "NA" in that column indicates |
| 282 | * that this reason code can be passed to functions registered by |
| 283 | * xpc_send_notify() (i.e. they don't have data arguments). |
| 284 | * |
| 285 | * Also, the first three reason codes in the following table indicate |
| 286 | * success, whereas the others indicate failure. When a failure reason code |
| 287 | * is received, one can assume that the channel is not connected. |
| 288 | * |
| 289 | * |
| 290 | * Reason Code | Cause | Optional Data |
| 291 | * =====================+================================+===================== |
| 292 | * xpcConnected | connection has been established| max #of entries |
| 293 | * | to the specified partition on | allowed in message |
| 294 | * | the specified channel | queue |
| 295 | * ---------------------+--------------------------------+--------------------- |
| 296 | * xpcMsgReceived | an XPC message arrived from | address of payload |
| 297 | * | the specified partition on the | |
| 298 | * | specified channel | [the user must call |
| 299 | * | | xpc_received() when |
| 300 | * | | finished with the |
| 301 | * | | payload] |
| 302 | * ---------------------+--------------------------------+--------------------- |
| 303 | * xpcMsgDelivered | notification that the message | NA |
| 304 | * | was delivered to the intended | |
| 305 | * | recipient and that they have | |
| 306 | * | acknowledged its receipt by | |
| 307 | * | calling xpc_received() | |
| 308 | * =====================+================================+===================== |
| 309 | * xpcUnequalMsgSizes | can't connect to the specified | NULL |
| 310 | * | partition on the specified | |
| 311 | * | channel because of mismatched | |
| 312 | * | message sizes | |
| 313 | * ---------------------+--------------------------------+--------------------- |
| 314 | * xpcNoMemory | insufficient memory avaiable | NULL |
| 315 | * | to allocate message queue | |
| 316 | * ---------------------+--------------------------------+--------------------- |
| 317 | * xpcLackOfResources | lack of resources to create | NULL |
| 318 | * | the necessary kthreads to | |
| 319 | * | support the channel | |
| 320 | * ---------------------+--------------------------------+--------------------- |
| 321 | * xpcUnregistering | this side's user has | NULL or NA |
| 322 | * | unregistered by calling | |
| 323 | * | xpc_disconnect() | |
| 324 | * ---------------------+--------------------------------+--------------------- |
| 325 | * xpcOtherUnregistering| the other side's user has | NULL or NA |
| 326 | * | unregistered by calling | |
| 327 | * | xpc_disconnect() | |
| 328 | * ---------------------+--------------------------------+--------------------- |
| 329 | * xpcNoHeartbeat | the other side's XPC is no | NULL or NA |
| 330 | * | longer heartbeating | |
| 331 | * | | |
| 332 | * ---------------------+--------------------------------+--------------------- |
| 333 | * xpcUnloading | this side's XPC module is | NULL or NA |
| 334 | * | being unloaded | |
| 335 | * | | |
| 336 | * ---------------------+--------------------------------+--------------------- |
| 337 | * xpcOtherUnloading | the other side's XPC module is | NULL or NA |
| 338 | * | is being unloaded | |
| 339 | * | | |
| 340 | * ---------------------+--------------------------------+--------------------- |
| 341 | * xpcPioReadError | xp_nofault_PIOR() returned an | NULL or NA |
| 342 | * | error while sending an IPI | |
| 343 | * | | |
| 344 | * ---------------------+--------------------------------+--------------------- |
| 345 | * xpcInvalidAddress | the address either received or | NULL or NA |
| 346 | * | sent by the specified partition| |
| 347 | * | is invalid | |
| 348 | * ---------------------+--------------------------------+--------------------- |
| 349 | * xpcBteNotAvailable | attempt to pull data from the | NULL or NA |
| 350 | * xpcBtePoisonError | specified partition over the | |
| 351 | * xpcBteWriteError | specified channel via a | |
| 352 | * xpcBteAccessError | bte_copy() failed | |
| 353 | * xpcBteTimeOutError | | |
| 354 | * xpcBteXtalkError | | |
| 355 | * xpcBteDirectoryError | | |
| 356 | * xpcBteGenericError | | |
| 357 | * xpcBteUnmappedError | | |
| 358 | * ---------------------+--------------------------------+--------------------- |
| 359 | * xpcUnknownReason | the specified channel to the | NULL or NA |
| 360 | * | specified partition was | |
| 361 | * | unavailable for unknown reasons| |
| 362 | * =====================+================================+===================== |
| 363 | */ |
| 364 | |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 365 | typedef void (*xpc_channel_func) (enum xpc_retval reason, partid_t partid, |
| 366 | int ch_number, void *data, void *key); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 367 | |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 368 | typedef void (*xpc_notify_func) (enum xpc_retval reason, partid_t partid, |
| 369 | int ch_number, void *key); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 370 | |
| 371 | /* |
| 372 | * The following is a registration entry. There is a global array of these, |
| 373 | * one per channel. It is used to record the connection registration made |
| 374 | * by the users of XPC. As long as a registration entry exists, for any |
| 375 | * partition that comes up, XPC will attempt to establish a connection on |
| 376 | * that channel. Notification that a connection has been made will occur via |
| 377 | * the xpc_channel_func function. |
| 378 | * |
| 379 | * The 'func' field points to the function to call when aynchronous |
| 380 | * notification is required for such events as: a connection established/lost, |
Dean Nelson | e54af72 | 2005-10-25 14:07:43 -0500 | [diff] [blame] | 381 | * or an incoming message received, or an error condition encountered. A |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 382 | * non-NULL 'func' field indicates that there is an active registration for |
| 383 | * the channel. |
| 384 | */ |
| 385 | struct xpc_registration { |
Jes Sorensen | f9e505a | 2006-01-17 12:52:21 -0500 | [diff] [blame] | 386 | struct mutex mutex; |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 387 | xpc_channel_func func; /* function to call */ |
| 388 | void *key; /* pointer to user's key */ |
| 389 | u16 nentries; /* #of msg entries in local msg queue */ |
| 390 | u16 msg_size; /* message queue's message size */ |
| 391 | u32 assigned_limit; /* limit on #of assigned kthreads */ |
| 392 | u32 idle_limit; /* limit on #of idle kthreads */ |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 393 | } ____cacheline_aligned; |
| 394 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 395 | #define XPC_CHANNEL_REGISTERED(_c) (xpc_registrations[_c].func != NULL) |
| 396 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 397 | /* the following are valid xpc_allocate() flags */ |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 398 | #define XPC_WAIT 0 /* wait flag */ |
| 399 | #define XPC_NOWAIT 1 /* no wait flag */ |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 400 | |
| 401 | struct xpc_interface { |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 402 | void (*connect) (int); |
| 403 | void (*disconnect) (int); |
| 404 | enum xpc_retval (*allocate) (partid_t, int, u32, void **); |
| 405 | enum xpc_retval (*send) (partid_t, int, void *); |
| 406 | enum xpc_retval (*send_notify) (partid_t, int, void *, |
| 407 | xpc_notify_func, void *); |
| 408 | void (*received) (partid_t, int, void *); |
| 409 | enum xpc_retval (*partid_to_nasids) (partid_t, void *); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 410 | }; |
| 411 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 412 | extern struct xpc_interface xpc_interface; |
| 413 | |
| 414 | extern void xpc_set_interface(void (*)(int), |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 415 | void (*)(int), |
| 416 | enum xpc_retval (*)(partid_t, int, u32, void **), |
| 417 | enum xpc_retval (*)(partid_t, int, void *), |
| 418 | enum xpc_retval (*)(partid_t, int, void *, |
| 419 | xpc_notify_func, void *), |
| 420 | void (*)(partid_t, int, void *), |
| 421 | enum xpc_retval (*)(partid_t, void *)); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 422 | extern void xpc_clear_interface(void); |
| 423 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 424 | extern enum xpc_retval xpc_connect(int, xpc_channel_func, void *, u16, |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 425 | u16, u32, u32); |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 426 | extern void xpc_disconnect(int); |
| 427 | |
| 428 | static inline enum xpc_retval |
| 429 | xpc_allocate(partid_t partid, int ch_number, u32 flags, void **payload) |
| 430 | { |
| 431 | return xpc_interface.allocate(partid, ch_number, flags, payload); |
| 432 | } |
| 433 | |
| 434 | static inline enum xpc_retval |
| 435 | xpc_send(partid_t partid, int ch_number, void *payload) |
| 436 | { |
| 437 | return xpc_interface.send(partid, ch_number, payload); |
| 438 | } |
| 439 | |
| 440 | static inline enum xpc_retval |
| 441 | xpc_send_notify(partid_t partid, int ch_number, void *payload, |
Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 442 | xpc_notify_func func, void *key) |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 443 | { |
| 444 | return xpc_interface.send_notify(partid, ch_number, payload, func, key); |
| 445 | } |
| 446 | |
| 447 | static inline void |
| 448 | xpc_received(partid_t partid, int ch_number, void *payload) |
| 449 | { |
| 450 | return xpc_interface.received(partid, ch_number, payload); |
| 451 | } |
| 452 | |
| 453 | static inline enum xpc_retval |
| 454 | xpc_partid_to_nasids(partid_t partid, void *nasids) |
| 455 | { |
| 456 | return xpc_interface.partid_to_nasids(partid, nasids); |
| 457 | } |
| 458 | |
Dean Nelson | b0d82bd | 2005-03-23 19:46:00 -0700 | [diff] [blame] | 459 | extern u64 xp_nofault_PIOR_target; |
| 460 | extern int xp_nofault_PIOR(void *); |
| 461 | extern int xp_error_PIOR(void); |
| 462 | |
Dean Nelson | 45d9ca4 | 2008-04-22 14:46:56 -0500 | [diff] [blame] | 463 | #endif /* _DRIVERS_MISC_SGIXP_XP_H */ |