Changeset 01c3bb4 in mainline for uspace/lib/c/generic/ipc.c
- Timestamp:
- 2017-11-25T15:43:25Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ce4a21a0
- Parents:
- 98cb5e0d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/ipc.c
r98cb5e0d r01c3bb4 59 59 struct { 60 60 ipc_call_t data; 61 int phoneid;62 61 } msg; 63 62 } async_call_t; … … 91 90 /** Epilogue for ipc_call_async_*() functions. 92 91 * 93 * @param callid Value returned by the SYS_IPC_CALL_ASYNC_* syscall. 94 * @param phoneid Phone handle through which the call was made. 95 * @param call Structure returned by ipc_prepare_async(). 96 */ 97 static inline void ipc_finish_async(ipc_callid_t callid, int phoneid, 98 async_call_t *call) 92 * @param rc Value returned by the SYS_IPC_CALL_ASYNC_* syscall. 93 * @param call Structure returned by ipc_prepare_async(). 94 */ 95 static inline void ipc_finish_async(int rc, async_call_t *call) 99 96 { 100 97 if (!call) { … … 103 100 } 104 101 105 if ( callid == (ipc_callid_t)IPC_CALLRET_FATAL) {102 if (rc == IPC_CALLRET_FATAL) { 106 103 /* Call asynchronous handler with error code */ 107 104 if (call->callback) … … 124 121 * error code. If the call cannot be temporarily made, it is queued. 125 122 * 126 * @param ph oneidPhone handle for the call.127 * @param imethod 128 * @param arg1 129 * @param arg2 130 * @param arg3 131 * @param private 132 * @param callback 133 */ 134 void ipc_call_async_fast( int phoneid, sysarg_t imethod, sysarg_t arg1,123 * @param phandle Phone handle for the call. 124 * @param imethod Requested interface and method. 125 * @param arg1 Service-defined payload argument. 126 * @param arg2 Service-defined payload argument. 127 * @param arg3 Service-defined payload argument. 128 * @param private Argument to be passed to the answer/error callback. 129 * @param callback Answer or error callback. 130 */ 131 void ipc_call_async_fast(cap_handle_t phandle, sysarg_t imethod, sysarg_t arg1, 135 132 sysarg_t arg2, sysarg_t arg3, void *private, ipc_async_callback_t callback) 136 133 { … … 139 136 return; 140 137 141 i pc_callid_t callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid,142 imethod, arg1,arg2, arg3, (sysarg_t) call);143 144 ipc_finish_async( callid, phoneid, call);138 int rc = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phandle, imethod, arg1, 139 arg2, arg3, (sysarg_t) call); 140 141 ipc_finish_async(rc, call); 145 142 } 146 143 … … 153 150 * error code. If the call cannot be temporarily made, it is queued. 154 151 * 155 * @param ph oneidPhone handle for the call.156 * @param imethod 157 * @param arg1 158 * @param arg2 159 * @param arg3 160 * @param arg4 161 * @param arg5 162 * @param private 163 * @param callback 164 */ 165 void ipc_call_async_slow(int ph oneid, sysarg_t imethod, sysarg_t arg1,152 * @param phandle Phone handle for the call. 153 * @param imethod Requested interface and method. 154 * @param arg1 Service-defined payload argument. 155 * @param arg2 Service-defined payload argument. 156 * @param arg3 Service-defined payload argument. 157 * @param arg4 Service-defined payload argument. 158 * @param arg5 Service-defined payload argument. 159 * @param private Argument to be passed to the answer/error callback. 160 * @param callback Answer or error callback. 161 */ 162 void ipc_call_async_slow(int phandle, sysarg_t imethod, sysarg_t arg1, 166 163 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, void *private, 167 164 ipc_async_callback_t callback) … … 178 175 IPC_SET_ARG5(call->msg.data, arg5); 179 176 180 i pc_callid_t callid = __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW, phoneid,177 int rc = __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW, phandle, 181 178 (sysarg_t) &call->msg.data, (sysarg_t) call); 182 179 183 ipc_finish_async( callid, phoneid, call);180 ipc_finish_async(rc, call); 184 181 } 185 182 … … 189 186 * registers. If you need to return more, use the ipc_answer_slow() instead. 190 187 * 191 * @param c allid Hashof the call being answered.192 * @param retval Return value.193 * @param arg1 First return argument.194 * @param arg2 Second return argument.195 * @param arg3 Third return argument.196 * @param arg4 Fourth return argument.188 * @param chandle Handle of the call being answered. 189 * @param retval Return value. 190 * @param arg1 First return argument. 191 * @param arg2 Second return argument. 192 * @param arg3 Third return argument. 193 * @param arg4 Fourth return argument. 197 194 * 198 195 * @return Zero on success. … … 200 197 * 201 198 */ 202 sysarg_t ipc_answer_fast( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,199 sysarg_t ipc_answer_fast(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1, 203 200 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4) 204 201 { 205 return __SYSCALL6(SYS_IPC_ANSWER_FAST, c allid, retval, arg1, arg2, arg3,206 arg 4);202 return __SYSCALL6(SYS_IPC_ANSWER_FAST, chandle, retval, arg1, arg2, 203 arg3, arg4); 207 204 } 208 205 209 206 /** Answer received call (entire payload). 210 207 * 211 * @param c allid Hashof the call being answered.212 * @param retval Return value.213 * @param arg1 First return argument.214 * @param arg2 Second return argument.215 * @param arg3 Third return argument.216 * @param arg4 Fourth return argument.217 * @param arg5 Fifth return argument.208 * @param chandle Handle of the call being answered. 209 * @param retval Return value. 210 * @param arg1 First return argument. 211 * @param arg2 Second return argument. 212 * @param arg3 Third return argument. 213 * @param arg4 Fourth return argument. 214 * @param arg5 Fifth return argument. 218 215 * 219 216 * @return Zero on success. … … 221 218 * 222 219 */ 223 sysarg_t ipc_answer_slow( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,220 sysarg_t ipc_answer_slow(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1, 224 221 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5) 225 222 { … … 233 230 IPC_SET_ARG5(data, arg5); 234 231 235 return __SYSCALL2(SYS_IPC_ANSWER_SLOW, c allid, (sysarg_t) &data);232 return __SYSCALL2(SYS_IPC_ANSWER_SLOW, chandle, (sysarg_t) &data); 236 233 } 237 234 238 235 /** Handle received answer. 239 236 * 240 * @param callid Hash of the received answer. 241 * @param data Call data of the answer. 242 */ 243 static void handle_answer(ipc_callid_t callid, ipc_call_t *data) 237 * @param data Call data of the answer. 238 */ 239 static void handle_answer(ipc_call_t *data) 244 240 { 245 241 async_call_t *call = data->label; … … 255 251 /** Wait for first IPC call to come. 256 252 * 253 * @param call Incoming call storage. 254 * @param usec Timeout in microseconds 255 * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking). 256 * 257 * @return Call handle. 258 * @return Negative error code. 259 */ 260 cap_handle_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec, unsigned int flags) 261 { 262 cap_handle_t chandle = 263 __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags); 264 265 /* Handle received answers */ 266 if ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_ANSWERED)) 267 handle_answer(call); 268 269 return chandle; 270 } 271 272 /** Interrupt one thread of this task from waiting for IPC. 273 * 274 */ 275 void ipc_poke(void) 276 { 277 __SYSCALL0(SYS_IPC_POKE); 278 } 279 280 /** Wait for first IPC call to come. 281 * 282 * Only requests are returned, answers are processed internally. 283 * 257 284 * @param call Incoming call storage. 258 285 * @param usec Timeout in microseconds 259 * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking). 260 * 261 * @return Hash of the call. 262 */ 263 ipc_callid_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec, 264 unsigned int flags) 265 { 266 ipc_callid_t callid = 267 __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags); 268 269 /* Handle received answers */ 270 if (callid && (call->flags & IPC_CALLID_ANSWERED)) 271 handle_answer(callid, call); 272 273 return callid; 274 } 275 276 /** Interrupt one thread of this task from waiting for IPC. 277 * 278 */ 279 void ipc_poke(void) 280 { 281 __SYSCALL0(SYS_IPC_POKE); 282 } 283 284 /** Wait for first IPC call to come. 286 * 287 * @return Call handle. 288 * @return Negative error code. 289 * 290 */ 291 cap_handle_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec) 292 { 293 cap_handle_t chandle; 294 295 do { 296 chandle = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE); 297 } while ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_ANSWERED)); 298 299 return chandle; 300 } 301 302 /** Check if there is an IPC call waiting to be picked up. 285 303 * 286 304 * Only requests are returned, answers are processed internally. 287 305 * 288 * @param call Incoming call storage.289 * @param usec Timeout in microseconds290 * 291 * @return Hash of the call.292 * 293 */ 294 ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec)295 { 296 ipc_callid_t callid;306 * @param call Incoming call storage. 307 * 308 * @return Call handle. 309 * @return Negative error code. 310 * 311 */ 312 cap_handle_t ipc_trywait_for_call(ipc_call_t *call) 313 { 314 cap_handle_t chandle; 297 315 298 316 do { 299 callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE); 300 } while (callid && (call->flags & IPC_CALLID_ANSWERED)); 301 302 return callid; 303 } 304 305 /** Check if there is an IPC call waiting to be picked up. 306 * 307 * Only requests are returned, answers are processed internally. 308 * 309 * @param call Incoming call storage. 310 * 311 * @return Hash of the call. 312 * 313 */ 314 ipc_callid_t ipc_trywait_for_call(ipc_call_t *call) 315 { 316 ipc_callid_t callid; 317 318 do { 319 callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT, 317 chandle = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT, 320 318 SYNCH_FLAGS_NON_BLOCKING); 321 } while ( callid&& (call->flags & IPC_CALLID_ANSWERED));322 323 return c allid;319 } while ((chandle == CAP_NIL) && (call->flags & IPC_CALLID_ANSWERED)); 320 321 return chandle; 324 322 } 325 323 326 324 /** Hang up a phone. 327 325 * 328 * @param ph oneidHandle of the phone to be hung up.329 * 330 * @return Zero on success or a negative error code.331 * 332 */ 333 int ipc_hangup( int phoneid)334 { 335 return __SYSCALL1(SYS_IPC_HANGUP, ph oneid);326 * @param phandle Handle of the phone to be hung up. 327 * 328 * @return Zero on success or a negative error code. 329 * 330 */ 331 int ipc_hangup(cap_handle_t phandle) 332 { 333 return __SYSCALL1(SYS_IPC_HANGUP, phandle); 336 334 } 337 335 338 336 /** Forward a received call to another destination. 339 337 * 340 * For non-system methods, the old method, arg1 and arg2 are rewritten 341 * by the new values. For system methods, the new method, arg1 and arg2342 * are written to the old arg1, arg2 and arg3, respectivelly. Calls with343 * immutable methods areforwarded verbatim.344 * 345 * @param c allid Hashof the call to forward.346 * @param ph oneidPhone handle to use for forwarding.347 * @param imethod New interface and method for the forwarded call.348 * @param arg1 New value of the first argument for the forwarded call.349 * @param arg2 New value of the second argument for the forwarded call.350 * @param mode Flags specifying mode of the forward operation.351 * 352 * @return Zero on success or an error code.353 * 354 */ 355 int ipc_forward_fast( ipc_callid_t callid, int phoneid, sysarg_t imethod,356 sysarg_t arg1, sysarg_t arg2, unsigned int mode)357 { 358 return __SYSCALL6(SYS_IPC_FORWARD_FAST, c allid, phoneid, imethod, arg1,338 * For non-system methods, the old method, arg1 and arg2 are rewritten by the 339 * new values. For system methods, the new method, arg1 and arg2 are written to 340 * the old arg1, arg2 and arg3, respectivelly. Calls with immutable methods are 341 * forwarded verbatim. 342 * 343 * @param chandle Handle of the call to forward. 344 * @param phandle Phone handle to use for forwarding. 345 * @param imethod New interface and method for the forwarded call. 346 * @param arg1 New value of the first argument for the forwarded call. 347 * @param arg2 New value of the second argument for the forwarded call. 348 * @param mode Flags specifying mode of the forward operation. 349 * 350 * @return Zero on success or an error code. 351 * 352 */ 353 int ipc_forward_fast(cap_handle_t chandle, cap_handle_t phandle, 354 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode) 355 { 356 return __SYSCALL6(SYS_IPC_FORWARD_FAST, chandle, phandle, imethod, arg1, 359 357 arg2, mode); 360 358 } 361 359 362 int ipc_forward_slow( ipc_callid_t callid, int phoneid, sysarg_t imethod,363 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,364 unsigned int mode)360 int ipc_forward_slow(cap_handle_t chandle, cap_handle_t phandle, 361 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, 362 sysarg_t arg4, sysarg_t arg5, unsigned int mode) 365 363 { 366 364 ipc_call_t data; … … 373 371 IPC_SET_ARG5(data, arg5); 374 372 375 return __SYSCALL4(SYS_IPC_FORWARD_SLOW, c allid, phoneid, (sysarg_t) &data,376 mode);373 return __SYSCALL4(SYS_IPC_FORWARD_SLOW, chandle, phandle, 374 (sysarg_t) &data, mode); 377 375 } 378 376
Note:
See TracChangeset
for help on using the changeset viewer.