Subversion Repositories HelenOS

Rev

Rev 2568 | Rev 2618 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2568 Rev 2615
1
/*
1
/*
2
 * Copyright (c) 2006 Ondrej Palkovsky
2
 * Copyright (c) 2006 Ondrej Palkovsky
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup libc
29
/** @addtogroup libc
30
 * @{
30
 * @{
31
 * @}
31
 * @}
32
 */
32
 */
33
 
33
 
34
/** @addtogroup libcipc IPC
34
/** @addtogroup libcipc IPC
35
 * @brief HelenOS uspace IPC
35
 * @brief HelenOS uspace IPC
36
 * @{
36
 * @{
37
 * @ingroup libc
37
 * @ingroup libc
38
 */
38
 */
39
/** @file
39
/** @file
40
 */
40
 */
41
 
41
 
42
#include <ipc/ipc.h>
42
#include <ipc/ipc.h>
43
#include <libc.h>
43
#include <libc.h>
44
#include <malloc.h>
44
#include <malloc.h>
45
#include <errno.h>
45
#include <errno.h>
46
#include <libadt/list.h>
46
#include <libadt/list.h>
47
#include <stdio.h>
47
#include <stdio.h>
48
#include <unistd.h>
48
#include <unistd.h>
49
#include <futex.h>
49
#include <futex.h>
50
#include <kernel/synch/synch.h>
50
#include <kernel/synch/synch.h>
51
#include <async.h>
51
#include <async.h>
52
#include <fibril.h>
52
#include <fibril.h>
53
#include <assert.h>
53
#include <assert.h>
54
 
54
 
55
/**
55
/**
56
 * Structures of this type are used for keeping track of sent asynchronous calls
56
 * Structures of this type are used for keeping track of sent asynchronous calls
57
 * and queing unsent calls.
57
 * and queing unsent calls.
58
 */
58
 */
59
typedef struct {
59
typedef struct {
60
    link_t list;
60
    link_t list;
61
 
61
 
62
    ipc_async_callback_t callback;
62
    ipc_async_callback_t callback;
63
    void *private;
63
    void *private;
64
    union {
64
    union {
65
        ipc_callid_t callid;
65
        ipc_callid_t callid;
66
        struct {
66
        struct {
67
            ipc_call_t data;
67
            ipc_call_t data;
68
            int phoneid;
68
            int phoneid;
69
        } msg;
69
        } msg;
70
    } u;
70
    } u;
71
    fid_t fid;  /**< Fibril waiting for sending this call. */
71
    fid_t fid;  /**< Fibril waiting for sending this call. */
72
} async_call_t;
72
} async_call_t;
73
 
73
 
74
LIST_INITIALIZE(dispatched_calls);
74
LIST_INITIALIZE(dispatched_calls);
75
 
75
 
76
/** List of asynchronous calls that were not accepted by kernel.
76
/** List of asynchronous calls that were not accepted by kernel.
77
 *
77
 *
78
 * It is protected by async_futex, because if the call cannot be sent into the
78
 * It is protected by async_futex, because if the call cannot be sent into the
79
 * kernel, the async framework is used automatically.
79
 * kernel, the async framework is used automatically.
80
 */
80
 */
81
LIST_INITIALIZE(queued_calls);
81
LIST_INITIALIZE(queued_calls);
82
 
82
 
83
static atomic_t ipc_futex = FUTEX_INITIALIZER;
83
static atomic_t ipc_futex = FUTEX_INITIALIZER;
84
 
84
 
85
/** Make a fast synchronous call.
85
/** Make a fast synchronous call.
86
 *
86
 *
87
 * Only one payload argument can be passed using this function. However, this
87
 * Only three payload arguments can be passed using this function. However, this
88
 * function is faster than the generic ipc_call_sync_3().
88
 * function is faster than the generic ipc_call_sync_slow() because the payload
-
 
89
 * is passed directly in registers.
89
 *
90
 *
90
 * @param phoneid   Phone handle for the call.
91
 * @param phoneid   Phone handle for the call.
91
 * @param method    Requested method.
92
 * @param method    Requested method.
92
 * @param arg1      Service-defined payload argument.
93
 * @param arg1      Service-defined payload argument.
-
 
94
 * @param arg2      Service-defined payload argument.
-
 
95
 * @param arg3      Service-defined payload argument.
93
 * @param result    If non-NULL, the return ARG1 will be stored there.
96
 * @param result1   If non-NULL, the return ARG1 will be stored there.
-
 
97
 * @param result2   If non-NULL, the return ARG2 will be stored there.
-
 
98
 * @param result3   If non-NULL, the return ARG3 will be stored there.
-
 
99
 * @param result4   If non-NULL, the return ARG4 will be stored there.
-
 
100
 * @param result5   If non-NULL, the return ARG5 will be stored there.
94
 *
101
 *
95
 * @return      Negative values represent errors returned by IPC.
102
 * @return      Negative values represent errors returned by IPC.
96
 *          Otherwise the RETVAL of the answer is returned.
103
 *          Otherwise the RETVAL of the answer is returned.
97
 */
104
 */
-
 
105
int
98
int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t *result)
106
ipc_call_sync_fast(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
-
 
107
    ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3,
-
 
108
    ipcarg_t *result4, ipcarg_t *result5)
99
{
109
{
100
    ipc_call_t resdata;
110
    ipc_call_t resdata;
101
    int callres;
111
    int callres;
102
   
112
   
103
    callres = __SYSCALL4(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
113
    callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
104
        (sysarg_t) &resdata);
114
        arg2, arg3, (sysarg_t) &resdata);
105
    if (callres)
115
    if (callres)
106
        return callres;
116
        return callres;
107
    if (result)
117
    if (result1)
108
        *result = IPC_GET_ARG1(resdata);
118
        *result1 = IPC_GET_ARG1(resdata);
-
 
119
    if (result2)
-
 
120
        *result2 = IPC_GET_ARG2(resdata);
-
 
121
    if (result3)
-
 
122
        *result3 = IPC_GET_ARG3(resdata);
-
 
123
    if (result4)
-
 
124
        *result4 = IPC_GET_ARG4(resdata);
-
 
125
    if (result5)
-
 
126
        *result5 = IPC_GET_ARG5(resdata);
-
 
127
 
109
    return IPC_GET_RETVAL(resdata);
128
    return IPC_GET_RETVAL(resdata);
110
}
129
}
111
 
130
 
112
/** Make a synchronous call transmitting 3 arguments of payload.
131
/** Make a synchronous call transmitting 5 arguments of payload.
113
 *
132
 *
114
 * @param phoneid   Phone handle for the call.
133
 * @param phoneid   Phone handle for the call.
115
 * @param method    Requested method.
134
 * @param method    Requested method.
116
 * @param arg1      Service-defined payload argument.
135
 * @param arg1      Service-defined payload argument.
117
 * @param arg2      Service-defined payload argument.
136
 * @param arg2      Service-defined payload argument.
118
 * @param arg3      Service-defined payload argument.
137
 * @param arg3      Service-defined payload argument.
-
 
138
 * @param arg4      Service-defined payload argument.
-
 
139
 * @param arg5      Service-defined payload argument.
119
 * @param result1   If non-NULL, storage for the first return argument.
140
 * @param result1   If non-NULL, storage for the first return argument.
120
 * @param result2   If non-NULL, storage for the second return argument.
141
 * @param result2   If non-NULL, storage for the second return argument.
121
 * @param result3   If non-NULL, storage for the third return argument.
142
 * @param result3   If non-NULL, storage for the third return argument.
-
 
143
 * @param result4   If non-NULL, storage for the fourth return argument.
-
 
144
 * @param result5   If non-NULL, storage for the fifth return argument.
122
 *
145
 *
123
 * @return      Negative value means IPC error.
146
 * @return      Negative value means IPC error.
124
 *          Otherwise the RETVAL of the answer.
147
 *          Otherwise the RETVAL of the answer.
125
 */
148
 */
-
 
149
int
126
int ipc_call_sync_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
150
ipc_call_sync_slow(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
-
 
151
    ipcarg_t arg3, ipcarg_t arg4, ipcarg_t arg5, ipcarg_t *result1,
127
    ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3)
152
    ipcarg_t *result2, ipcarg_t *result3, ipcarg_t *result4, ipcarg_t *result5)
128
{
153
{
129
    ipc_call_t data;
154
    ipc_call_t data;
130
    int callres;
155
    int callres;
131
 
156
 
132
    IPC_SET_METHOD(data, method);
157
    IPC_SET_METHOD(data, method);
133
    IPC_SET_ARG1(data, arg1);
158
    IPC_SET_ARG1(data, arg1);
134
    IPC_SET_ARG2(data, arg2);
159
    IPC_SET_ARG2(data, arg2);
135
    IPC_SET_ARG3(data, arg3);
160
    IPC_SET_ARG3(data, arg3);
-
 
161
    IPC_SET_ARG4(data, arg4);
-
 
162
    IPC_SET_ARG5(data, arg5);
136
 
163
 
137
    callres = __SYSCALL3(SYS_IPC_CALL_SYNC, phoneid, (sysarg_t) &data,
164
    callres = __SYSCALL3(SYS_IPC_CALL_SYNC_SLOW, phoneid, (sysarg_t) &data,
138
        (sysarg_t) &data);
165
        (sysarg_t) &data);
139
    if (callres)
166
    if (callres)
140
        return callres;
167
        return callres;
141
 
168
 
142
    if (result1)
169
    if (result1)
143
        *result1 = IPC_GET_ARG1(data);
170
        *result1 = IPC_GET_ARG1(data);
144
    if (result2)
171
    if (result2)
145
        *result2 = IPC_GET_ARG2(data);
172
        *result2 = IPC_GET_ARG2(data);
146
    if (result3)
173
    if (result3)
147
        *result3 = IPC_GET_ARG3(data);
174
        *result3 = IPC_GET_ARG3(data);
-
 
175
    if (result4)
-
 
176
        *result4 = IPC_GET_ARG4(data);
-
 
177
    if (result5)
-
 
178
        *result5 = IPC_GET_ARG5(data);
-
 
179
 
148
    return IPC_GET_RETVAL(data);
180
    return IPC_GET_RETVAL(data);
149
}
181
}
150
 
182
 
151
/** Syscall to send asynchronous message.
183
/** Syscall to send asynchronous message.
152
 *
184
 *
153
 * @param phoneid   Phone handle for the call.
185
 * @param phoneid   Phone handle for the call.
154
 * @param data      Call data with the request.
186
 * @param data      Call data with the request.
155
 *
187
 *
156
 * @return      Hash of the call or an error code.
188
 * @return      Hash of the call or an error code.
157
 */
189
 */
158
static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
190
static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
159
{
191
{
160
    return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t) data);
192
    return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t) data);
161
}
193
}
162
 
194
 
163
/** Prolog to ipc_call_async_*() functions.
195
/** Prolog to ipc_call_async_*() functions.
164
 *
196
 *
165
 * @param private   Argument for the answer/error callback.
197
 * @param private   Argument for the answer/error callback.
166
 * @param callback  Answer/error callback.
198
 * @param callback  Answer/error callback.
167
 *
199
 *
168
 * @return      New, partially initialized async_call structure or NULL.
200
 * @return      New, partially initialized async_call structure or NULL.
169
 */
201
 */
170
static inline async_call_t *ipc_prepare_async(void *private,
202
static inline async_call_t *ipc_prepare_async(void *private,
171
    ipc_async_callback_t callback)
203
    ipc_async_callback_t callback)
172
{
204
{
173
    async_call_t *call;
205
    async_call_t *call;
174
 
206
 
175
    call = malloc(sizeof(*call));
207
    call = malloc(sizeof(*call));
176
    if (!call) {
208
    if (!call) {
177
        if (callback)
209
        if (callback)
178
            callback(private, ENOMEM, NULL);
210
            callback(private, ENOMEM, NULL);
179
        return NULL;
211
        return NULL;
180
    }
212
    }
181
    call->callback = callback;
213
    call->callback = callback;
182
    call->private = private;
214
    call->private = private;
183
 
215
 
184
    return call;
216
    return call;
185
}
217
}
186
 
218
 
187
/** Epilogue of ipc_call_async_*() functions.
219
/** Epilogue of ipc_call_async_*() functions.
188
 *
220
 *
189
 * @param callid    Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
221
 * @param callid    Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
190
 * @param phoneid   Phone handle through which the call was made.
222
 * @param phoneid   Phone handle through which the call was made.
191
 * @param call      async_call structure returned by ipc_prepare_async().
223
 * @param call      async_call structure returned by ipc_prepare_async().
192
 * @param can_preempt   If non-zero, the current fibril can be preempted in this
224
 * @param can_preempt   If non-zero, the current fibril can be preempted in this
193
 *          call.
225
 *          call.
194
 */
226
 */
195
static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
227
static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
196
    async_call_t *call, int can_preempt)
228
    async_call_t *call, int can_preempt)
197
{
229
{
198
    if (!call) { /* Nothing to do regardless if failed or not */
230
    if (!call) { /* Nothing to do regardless if failed or not */
199
        futex_up(&ipc_futex);
231
        futex_up(&ipc_futex);
200
        return;
232
        return;
201
    }
233
    }
202
 
234
 
203
    if (callid == IPC_CALLRET_FATAL) {
235
    if (callid == IPC_CALLRET_FATAL) {
204
        futex_up(&ipc_futex);
236
        futex_up(&ipc_futex);
205
        /* Call asynchronous handler with error code */
237
        /* Call asynchronous handler with error code */
206
        if (call->callback)
238
        if (call->callback)
207
            call->callback(call->private, ENOENT, NULL);
239
            call->callback(call->private, ENOENT, NULL);
208
        free(call);
240
        free(call);
209
        return;
241
        return;
210
    }
242
    }
211
 
243
 
212
    if (callid == IPC_CALLRET_TEMPORARY) {
244
    if (callid == IPC_CALLRET_TEMPORARY) {
213
        futex_up(&ipc_futex);
245
        futex_up(&ipc_futex);
214
 
246
 
215
        call->u.msg.phoneid = phoneid;
247
        call->u.msg.phoneid = phoneid;
216
       
248
       
217
        futex_down(&async_futex);
249
        futex_down(&async_futex);
218
        list_append(&call->list, &queued_calls);
250
        list_append(&call->list, &queued_calls);
219
 
251
 
220
        if (can_preempt) {
252
        if (can_preempt) {
221
            call->fid = fibril_get_id();
253
            call->fid = fibril_get_id();
222
            fibril_switch(FIBRIL_TO_MANAGER);
254
            fibril_switch(FIBRIL_TO_MANAGER);
223
            /* Async futex unlocked by previous call */
255
            /* Async futex unlocked by previous call */
224
        } else {
256
        } else {
225
            call->fid = 0;
257
            call->fid = 0;
226
            futex_up(&async_futex);
258
            futex_up(&async_futex);
227
        }
259
        }
228
        return;
260
        return;
229
    }
261
    }
230
    call->u.callid = callid;
262
    call->u.callid = callid;
231
    /* Add call to the list of dispatched calls */
263
    /* Add call to the list of dispatched calls */
232
    list_append(&call->list, &dispatched_calls);
264
    list_append(&call->list, &dispatched_calls);
233
    futex_up(&ipc_futex);
265
    futex_up(&ipc_futex);
234
   
266
   
235
}
267
}
236
 
268
 
237
/** Make a fast asynchronous call.
269
/** Make a fast asynchronous call.
238
 *
270
 *
239
 * This function can only handle two arguments of payload. It is, however,
271
 * This function can only handle two arguments of payload. It is, however,
240
 * faster than the more generic ipc_call_async_3().
272
 * faster than the more generic ipc_call_async_3().
241
 *
273
 *
242
 * Note that this function is a void function.
274
 * Note that this function is a void function.
243
 * During normal opertation, answering this call will trigger the callback.
275
 * During normal opertation, answering this call will trigger the callback.
244
 * In case of fatal error, call the callback handler with the proper error code.
276
 * In case of fatal error, call the callback handler with the proper error code.
245
 * If the call cannot be temporarily made, queue it.
277
 * If the call cannot be temporarily made, queue it.
246
 *
278
 *
247
 * @param phoneid   Phone handle for the call.
279
 * @param phoneid   Phone handle for the call.
248
 * @param method    Requested method.
280
 * @param method    Requested method.
249
 * @param arg1      Service-defined payload argument.
281
 * @param arg1      Service-defined payload argument.
250
 * @param arg2      Service-defined payload argument.
282
 * @param arg2      Service-defined payload argument.
251
 * @param private   Argument to be passed to the answer/error callback.
283
 * @param private   Argument to be passed to the answer/error callback.
252
 * @param callback  Answer or error callback.
284
 * @param callback  Answer or error callback.
253
 * @param can_preempt   If non-zero, the current fibril will be preempted in
285
 * @param can_preempt   If non-zero, the current fibril will be preempted in
254
 *          case the kernel temporarily refuses to accept more
286
 *          case the kernel temporarily refuses to accept more
255
 *          asynchronous calls.
287
 *          asynchronous calls.
256
 */
288
 */
257
void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
289
void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
258
    ipcarg_t arg2, void *private, ipc_async_callback_t callback,
290
    ipcarg_t arg2, void *private, ipc_async_callback_t callback,
259
    int can_preempt)
291
    int can_preempt)
260
{
292
{
261
    async_call_t *call = NULL;
293
    async_call_t *call = NULL;
262
    ipc_callid_t callid;
294
    ipc_callid_t callid;
263
 
295
 
264
    if (callback) {
296
    if (callback) {
265
        call = ipc_prepare_async(private, callback);
297
        call = ipc_prepare_async(private, callback);
266
        if (!call)
298
        if (!call)
267
            return;
299
            return;
268
    }
300
    }
269
 
301
 
270
    /*
302
    /*
271
     * We need to make sure that we get callid before another thread
303
     * We need to make sure that we get callid before another thread
272
     * accesses the queue again.
304
     * accesses the queue again.
273
     */
305
     */
274
    futex_down(&ipc_futex);
306
    futex_down(&ipc_futex);
275
    callid = __SYSCALL4(SYS_IPC_CALL_ASYNC_FAST, phoneid, method, arg1,
307
    callid = __SYSCALL4(SYS_IPC_CALL_ASYNC_FAST, phoneid, method, arg1,
276
        arg2);
308
        arg2);
277
 
309
 
278
    if (callid == IPC_CALLRET_TEMPORARY) {
310
    if (callid == IPC_CALLRET_TEMPORARY) {
279
        if (!call) {
311
        if (!call) {
280
            call = ipc_prepare_async(private, callback);
312
            call = ipc_prepare_async(private, callback);
281
            if (!call)
313
            if (!call)
282
                return;
314
                return;
283
        }
315
        }
284
        IPC_SET_METHOD(call->u.msg.data, method);
316
        IPC_SET_METHOD(call->u.msg.data, method);
285
        IPC_SET_ARG1(call->u.msg.data, arg1);
317
        IPC_SET_ARG1(call->u.msg.data, arg1);
286
        IPC_SET_ARG2(call->u.msg.data, arg2);
318
        IPC_SET_ARG2(call->u.msg.data, arg2);
287
    }
319
    }
288
    ipc_finish_async(callid, phoneid, call, can_preempt);
320
    ipc_finish_async(callid, phoneid, call, can_preempt);
289
}
321
}
290
 
322
 
291
/** Make an asynchronous call transmitting the entire payload.
323
/** Make an asynchronous call transmitting the entire payload.
292
 *
324
 *
293
 * Note that this function is a void function.
325
 * Note that this function is a void function.
294
 * During normal opertation, answering this call will trigger the callback.
326
 * During normal opertation, answering this call will trigger the callback.
295
 * In case of fatal error, call the callback handler with the proper error code.
327
 * In case of fatal error, call the callback handler with the proper error code.
296
 * If the call cannot be temporarily made, queue it.
328
 * If the call cannot be temporarily made, queue it.
297
 *
329
 *
298
 * @param phoneid   Phone handle for the call.
330
 * @param phoneid   Phone handle for the call.
299
 * @param method    Requested method.
331
 * @param method    Requested method.
300
 * @param arg1      Service-defined payload argument.
332
 * @param arg1      Service-defined payload argument.
301
 * @param arg2      Service-defined payload argument.
333
 * @param arg2      Service-defined payload argument.
302
 * @param arg3      Service-defined payload argument.
334
 * @param arg3      Service-defined payload argument.
303
 * @param private   Argument to be passed to the answer/error callback.
335
 * @param private   Argument to be passed to the answer/error callback.
304
 * @param callback  Answer or error callback.
336
 * @param callback  Answer or error callback.
305
 * @param can_preempt   If non-zero, the current fibril will be preempted in
337
 * @param can_preempt   If non-zero, the current fibril will be preempted in
306
 *          case the kernel temporarily refuses to accept more
338
 *          case the kernel temporarily refuses to accept more
307
 *          asynchronous calls.
339
 *          asynchronous calls.
308
 *
340
 *
309
 */
341
 */
310
void ipc_call_async_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
342
void ipc_call_async_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
311
    ipcarg_t arg2, ipcarg_t arg3, void *private, ipc_async_callback_t callback,
343
    ipcarg_t arg2, ipcarg_t arg3, void *private, ipc_async_callback_t callback,
312
    int can_preempt)
344
    int can_preempt)
313
{
345
{
314
    async_call_t *call;
346
    async_call_t *call;
315
    ipc_callid_t callid;
347
    ipc_callid_t callid;
316
 
348
 
317
    call = ipc_prepare_async(private, callback);
349
    call = ipc_prepare_async(private, callback);
318
    if (!call)
350
    if (!call)
319
        return;
351
        return;
320
 
352
 
321
    IPC_SET_METHOD(call->u.msg.data, method);
353
    IPC_SET_METHOD(call->u.msg.data, method);
322
    IPC_SET_ARG1(call->u.msg.data, arg1);
354
    IPC_SET_ARG1(call->u.msg.data, arg1);
323
    IPC_SET_ARG2(call->u.msg.data, arg2);
355
    IPC_SET_ARG2(call->u.msg.data, arg2);
324
    IPC_SET_ARG3(call->u.msg.data, arg3);
356
    IPC_SET_ARG3(call->u.msg.data, arg3);
325
    /*
357
    /*
326
     * We need to make sure that we get callid before another thread accesses
358
     * We need to make sure that we get callid before another thread accesses
327
     * the queue again.
359
     * the queue again.
328
     */
360
     */
329
    futex_down(&ipc_futex);
361
    futex_down(&ipc_futex);
330
    callid = _ipc_call_async(phoneid, &call->u.msg.data);
362
    callid = _ipc_call_async(phoneid, &call->u.msg.data);
331
 
363
 
332
    ipc_finish_async(callid, phoneid, call, can_preempt);
364
    ipc_finish_async(callid, phoneid, call, can_preempt);
333
}
365
}
334
 
366
 
335
 
367
 
336
/** Answer a received call - fast version.
368
/** Answer a received call - fast version.
337
 *
369
 *
338
 * The fast answer makes use of passing retval and first two arguments in
370
 * The fast answer makes use of passing retval and first two arguments in
339
 * registers. If you need to return more, use the ipc_answer() instead.
371
 * registers. If you need to return more, use the ipc_answer() instead.
340
 *
372
 *
341
 * @param callid    Hash of the call being answered.
373
 * @param callid    Hash of the call being answered.
342
 * @param retval    Return value.
374
 * @param retval    Return value.
343
 * @param arg1      First return argument.
375
 * @param arg1      First return argument.
344
 * @param arg2      Second return argument.
376
 * @param arg2      Second return argument.
345
 *
377
 *
346
 * @return      Zero on success or a value from @ref errno.h on failure.
378
 * @return      Zero on success or a value from @ref errno.h on failure.
347
 */
379
 */
348
ipcarg_t ipc_answer_fast(ipc_callid_t callid, ipcarg_t retval, ipcarg_t arg1,
380
ipcarg_t ipc_answer_fast(ipc_callid_t callid, ipcarg_t retval, ipcarg_t arg1,
349
    ipcarg_t arg2)
381
    ipcarg_t arg2)
350
{
382
{
351
    return __SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2);
383
    return __SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2);
352
}
384
}
353
 
385
 
354
/** Answer a received call - full version.
386
/** Answer a received call - full version.
355
 *
387
 *
356
 * @param callid    Hash of the call being answered.
388
 * @param callid    Hash of the call being answered.
357
 * @param call      Call structure with the answer.
389
 * @param call      Call structure with the answer.
358
 *          Must be already initialized by the responder.
390
 *          Must be already initialized by the responder.
359
 *
391
 *
360
 * @return      Zero on success or a value from @ref errno.h on failure.
392
 * @return      Zero on success or a value from @ref errno.h on failure.
361
 */
393
 */
362
ipcarg_t ipc_answer(ipc_callid_t callid, ipc_call_t *call)
394
ipcarg_t ipc_answer(ipc_callid_t callid, ipc_call_t *call)
363
{
395
{
364
    return __SYSCALL2(SYS_IPC_ANSWER, callid, (sysarg_t) call);
396
    return __SYSCALL2(SYS_IPC_ANSWER, callid, (sysarg_t) call);
365
}
397
}
366
 
398
 
367
 
399
 
368
/** Try to dispatch queued calls from the async queue. */
400
/** Try to dispatch queued calls from the async queue. */
369
static void try_dispatch_queued_calls(void)
401
static void try_dispatch_queued_calls(void)
370
{
402
{
371
    async_call_t *call;
403
    async_call_t *call;
372
    ipc_callid_t callid;
404
    ipc_callid_t callid;
373
 
405
 
374
    /** @todo
406
    /** @todo
375
     * Integrate intelligently ipc_futex, so that it is locked during
407
     * Integrate intelligently ipc_futex, so that it is locked during
376
     * ipc_call_async_*(), until it is added to dispatched_calls.
408
     * ipc_call_async_*(), until it is added to dispatched_calls.
377
     */
409
     */
378
    futex_down(&async_futex);
410
    futex_down(&async_futex);
379
    while (!list_empty(&queued_calls)) {
411
    while (!list_empty(&queued_calls)) {
380
        call = list_get_instance(queued_calls.next, async_call_t, list);
412
        call = list_get_instance(queued_calls.next, async_call_t, list);
381
        callid = _ipc_call_async(call->u.msg.phoneid, &call->u.msg.data);
413
        callid = _ipc_call_async(call->u.msg.phoneid, &call->u.msg.data);
382
        if (callid == IPC_CALLRET_TEMPORARY) {
414
        if (callid == IPC_CALLRET_TEMPORARY) {
383
            break;
415
            break;
384
        }
416
        }
385
        list_remove(&call->list);
417
        list_remove(&call->list);
386
 
418
 
387
        futex_up(&async_futex);
419
        futex_up(&async_futex);
388
        if (call->fid)
420
        if (call->fid)
389
            fibril_add_ready(call->fid);
421
            fibril_add_ready(call->fid);
390
       
422
       
391
        if (callid == IPC_CALLRET_FATAL) {
423
        if (callid == IPC_CALLRET_FATAL) {
392
            if (call->callback)
424
            if (call->callback)
393
                call->callback(call->private, ENOENT, NULL);
425
                call->callback(call->private, ENOENT, NULL);
394
            free(call);
426
            free(call);
395
        } else {
427
        } else {
396
            call->u.callid = callid;
428
            call->u.callid = callid;
397
            futex_down(&ipc_futex);
429
            futex_down(&ipc_futex);
398
            list_append(&call->list, &dispatched_calls);
430
            list_append(&call->list, &dispatched_calls);
399
            futex_up(&ipc_futex);
431
            futex_up(&ipc_futex);
400
        }
432
        }
401
        futex_down(&async_futex);
433
        futex_down(&async_futex);
402
    }
434
    }
403
    futex_up(&async_futex);
435
    futex_up(&async_futex);
404
}
436
}
405
 
437
 
406
/** Handle a received answer.
438
/** Handle a received answer.
407
 *
439
 *
408
 * Find the hash of the answer and call the answer callback.
440
 * Find the hash of the answer and call the answer callback.
409
 *
441
 *
410
 * @todo Make it use hash table.
442
 * @todo Make it use hash table.
411
 *
443
 *
412
 * @param callid    Hash of the received answer.
444
 * @param callid    Hash of the received answer.
413
 *          The answer has the same hash as the request OR'ed with
445
 *          The answer has the same hash as the request OR'ed with
414
 *          the IPC_CALLID_ANSWERED bit.
446
 *          the IPC_CALLID_ANSWERED bit.
415
 * @param data      Call data of the answer.
447
 * @param data      Call data of the answer.
416
 */
448
 */
417
static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
449
static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
418
{
450
{
419
    link_t *item;
451
    link_t *item;
420
    async_call_t *call;
452
    async_call_t *call;
421
 
453
 
422
    callid &= ~IPC_CALLID_ANSWERED;
454
    callid &= ~IPC_CALLID_ANSWERED;
423
   
455
   
424
    futex_down(&ipc_futex);
456
    futex_down(&ipc_futex);
425
    for (item = dispatched_calls.next; item != &dispatched_calls;
457
    for (item = dispatched_calls.next; item != &dispatched_calls;
426
        item = item->next) {
458
        item = item->next) {
427
        call = list_get_instance(item, async_call_t, list);
459
        call = list_get_instance(item, async_call_t, list);
428
        if (call->u.callid == callid) {
460
        if (call->u.callid == callid) {
429
            list_remove(&call->list);
461
            list_remove(&call->list);
430
            futex_up(&ipc_futex);
462
            futex_up(&ipc_futex);
431
            if (call->callback)
463
            if (call->callback)
432
                call->callback(call->private,
464
                call->callback(call->private,
433
                    IPC_GET_RETVAL(*data), data);
465
                    IPC_GET_RETVAL(*data), data);
434
            free(call);
466
            free(call);
435
            return;
467
            return;
436
        }
468
        }
437
    }
469
    }
438
    futex_up(&ipc_futex);
470
    futex_up(&ipc_futex);
439
}
471
}
440
 
472
 
441
 
473
 
442
/** Wait for a first call to come.
474
/** Wait for a first call to come.
443
 *
475
 *
444
 * @param call      Storage where the incoming call data will be stored.
476
 * @param call      Storage where the incoming call data will be stored.
445
 * @param usec      Timeout in microseconds
477
 * @param usec      Timeout in microseconds
446
 * @param flags     Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
478
 * @param flags     Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
447
 *
479
 *
448
 * @return      Hash of the call. Note that certain bits have special
480
 * @return      Hash of the call. Note that certain bits have special
449
 *          meaning. IPC_CALLID_ANSWERED will be set in an answer
481
 *          meaning. IPC_CALLID_ANSWERED will be set in an answer
450
 *          and IPC_CALLID_NOTIFICATION is used for notifications.
482
 *          and IPC_CALLID_NOTIFICATION is used for notifications.
451
 *         
483
 *         
452
 */
484
 */
453
ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags)
485
ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags)
454
{
486
{
455
    ipc_callid_t callid;
487
    ipc_callid_t callid;
456
 
488
 
457
    callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
489
    callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
458
    /* Handle received answers */
490
    /* Handle received answers */
459
    if (callid & IPC_CALLID_ANSWERED) {
491
    if (callid & IPC_CALLID_ANSWERED) {
460
        handle_answer(callid, call);
492
        handle_answer(callid, call);
461
        try_dispatch_queued_calls();
493
        try_dispatch_queued_calls();
462
    }
494
    }
463
 
495
 
464
    return callid;
496
    return callid;
465
}
497
}
466
 
498
 
467
/** Wait some time for an IPC call.
499
/** Wait some time for an IPC call.
468
 *
500
 *
469
 * The call will return after an answer is received.
501
 * The call will return after an answer is received.
470
 *
502
 *
471
 * @param call      Storage where the incoming call data will be stored.
503
 * @param call      Storage where the incoming call data will be stored.
472
 * @param usec      Timeout in microseconds.
504
 * @param usec      Timeout in microseconds.
473
 *
505
 *
474
 * @return      Hash of the answer.
506
 * @return      Hash of the answer.
475
 */
507
 */
476
ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec)
508
ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec)
477
{
509
{
478
    ipc_callid_t callid;
510
    ipc_callid_t callid;
479
 
511
 
480
    do {
512
    do {
481
        callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
513
        callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
482
    } while (callid & IPC_CALLID_ANSWERED);
514
    } while (callid & IPC_CALLID_ANSWERED);
483
 
515
 
484
    return callid;
516
    return callid;
485
}
517
}
486
 
518
 
487
/** Check if there is an IPC call waiting to be picked up.
519
/** Check if there is an IPC call waiting to be picked up.
488
 *
520
 *
489
 * @param call      Storage where the incoming call will be stored.
521
 * @param call      Storage where the incoming call will be stored.
490
 * @return      Hash of the answer.
522
 * @return      Hash of the answer.
491
 */
523
 */
492
ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
524
ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
493
{
525
{
494
    ipc_callid_t callid;
526
    ipc_callid_t callid;
495
 
527
 
496
    do {
528
    do {
497
        callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
529
        callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
498
            SYNCH_FLAGS_NON_BLOCKING);
530
            SYNCH_FLAGS_NON_BLOCKING);
499
    } while (callid & IPC_CALLID_ANSWERED);
531
    } while (callid & IPC_CALLID_ANSWERED);
500
 
532
 
501
    return callid;
533
    return callid;
502
}
534
}
503
 
535
 
504
/** Ask destination to do a callback connection.
536
/** Ask destination to do a callback connection.
505
 *
537
 *
506
 * @param phoneid   Phone handle used for contacting the other side.
538
 * @param phoneid   Phone handle used for contacting the other side.
507
 * @param arg1      Service-defined argument.
539
 * @param arg1      Service-defined argument.
508
 * @param arg2      Service-defined argument.
540
 * @param arg2      Service-defined argument.
509
 * @param phonehash Storage where the library will store an opaque
541
 * @param phonehash Storage where the library will store an opaque
510
 *          identifier of the phone that will be used for incoming
542
 *          identifier of the phone that will be used for incoming
511
 *          calls. This identifier can be used for connection
543
 *          calls. This identifier can be used for connection
512
 *          tracking.
544
 *          tracking.
513
 *
545
 *
514
 * @return      Zero on success or a negative error code.
546
 * @return      Zero on success or a negative error code.
515
 */
547
 */
516
int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phonehash)
548
int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phonehash)
517
{
549
{
518
    return ipc_call_sync_3(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2, 0, 0,
550
    return ipc_call_sync_2_3(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2,
519
        0, phonehash);
551
        NULL, NULL, phonehash);
520
}
552
}
521
 
553
 
522
/** Ask through phone for a new connection to some service.
554
/** Ask through phone for a new connection to some service.
523
 *
555
 *
524
 * @param phoneid   Phone handle used for contacting the other side.
556
 * @param phoneid   Phone handle used for contacting the other side.
525
 * @param arg1      User defined argument.
557
 * @param arg1      User defined argument.
526
 * @param arg2      User defined argument.
558
 * @param arg2      User defined argument.
527
 *
559
 *
528
 * @return      New phone handle on success or a negative error code.
560
 * @return      New phone handle on success or a negative error code.
529
 */
561
 */
530
int ipc_connect_me_to(int phoneid, int arg1, int arg2)
562
int ipc_connect_me_to(int phoneid, int arg1, int arg2)
531
{
563
{
532
    ipcarg_t newphid;
564
    ipcarg_t newphid;
533
    int res;
565
    int res;
534
 
566
 
535
    res = ipc_call_sync_3(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, 0, 0, 0,
567
    res = ipc_call_sync_2_3(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, NULL,
536
        &newphid);
568
        NULL, &newphid);
537
    if (res)
569
    if (res)
538
        return res;
570
        return res;
539
    return newphid;
571
    return newphid;
540
}
572
}
541
 
573
 
542
/** Hang up a phone.
574
/** Hang up a phone.
543
 *
575
 *
544
 * @param phoneid   Handle of the phone to be hung up.
576
 * @param phoneid   Handle of the phone to be hung up.
545
 *
577
 *
546
 * @return      Zero on success or a negative error code.
578
 * @return      Zero on success or a negative error code.
547
 */
579
 */
548
int ipc_hangup(int phoneid)
580
int ipc_hangup(int phoneid)
549
{
581
{
550
    return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
582
    return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
551
}
583
}
552
 
584
 
553
/** Register IRQ notification.
585
/** Register IRQ notification.
554
 *
586
 *
555
 * @param inr       IRQ number.
587
 * @param inr       IRQ number.
556
 * @param devno     Device number of the device generating inr.
588
 * @param devno     Device number of the device generating inr.
557
 * @param method    Use this method for notifying me.
589
 * @param method    Use this method for notifying me.
558
 * @param ucode     Top-half pseudocode handler.
590
 * @param ucode     Top-half pseudocode handler.
559
 *
591
 *
560
 * @return      Value returned by the kernel.
592
 * @return      Value returned by the kernel.
561
 */
593
 */
562
int ipc_register_irq(int inr, int devno, int method, irq_code_t *ucode)
594
int ipc_register_irq(int inr, int devno, int method, irq_code_t *ucode)
563
{
595
{
564
    return __SYSCALL4(SYS_IPC_REGISTER_IRQ, inr, devno, method,
596
    return __SYSCALL4(SYS_IPC_REGISTER_IRQ, inr, devno, method,
565
        (sysarg_t) ucode);
597
        (sysarg_t) ucode);
566
}
598
}
567
 
599
 
568
/** Unregister IRQ notification.
600
/** Unregister IRQ notification.
569
 *
601
 *
570
 * @param inr       IRQ number.
602
 * @param inr       IRQ number.
571
 * @param devno     Device number of the device generating inr.
603
 * @param devno     Device number of the device generating inr.
572
 *
604
 *
573
 * @return      Value returned by the kernel.
605
 * @return      Value returned by the kernel.
574
 */
606
 */
575
int ipc_unregister_irq(int inr, int devno)
607
int ipc_unregister_irq(int inr, int devno)
576
{
608
{
577
    return __SYSCALL2(SYS_IPC_UNREGISTER_IRQ, inr, devno);
609
    return __SYSCALL2(SYS_IPC_UNREGISTER_IRQ, inr, devno);
578
}
610
}
579
 
611
 
580
/** Forward a received call to another destination.
612
/** Forward a received call to another destination.
581
 *
613
 *
582
 * @param callid    Hash of the call to forward.
614
 * @param callid    Hash of the call to forward.
583
 * @param phoneid   Phone handle to use for forwarding.
615
 * @param phoneid   Phone handle to use for forwarding.
584
 * @param method    New method for the forwarded call.
616
 * @param method    New method for the forwarded call.
585
 * @param arg1      New value of the first argument for the forwarded call.
617
 * @param arg1      New value of the first argument for the forwarded call.
586
 *
618
 *
587
 * @return      Zero on success or an error code.
619
 * @return      Zero on success or an error code.
588
 *
620
 *
589
 * For non-system methods, the old method and arg1 are rewritten by the new
621
 * For non-system methods, the old method and arg1 are rewritten by the new
590
 * values. For system methods, the new method and arg1 are written to the old
622
 * values. For system methods, the new method and arg1 are written to the old
591
 * arg1 and arg2, respectivelly.
623
 * arg1 and arg2, respectivelly.
592
 */
624
 */
593
int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
625
int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
594
{
626
{
595
    return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
627
    return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
596
}
628
}
597
 
629
 
598
/** Wrapper for making IPC_M_DATA_SEND calls.
630
/** Wrapper for making IPC_M_DATA_SEND calls.
599
 *
631
 *
600
 * @param phoneid   Phone that will be used to contact the receiving side.
632
 * @param phoneid   Phone that will be used to contact the receiving side.
601
 * @param src       Address of the beginning of the source buffer.
633
 * @param src       Address of the beginning of the source buffer.
602
 * @param size      Size of the source buffer.
634
 * @param size      Size of the source buffer.
603
 *
635
 *
604
 * @return      Zero on success or a negative error code from errno.h.
636
 * @return      Zero on success or a negative error code from errno.h.
605
 */
637
 */
606
int ipc_data_send(int phoneid, void *src, size_t size)
638
int ipc_data_send(int phoneid, void *src, size_t size)
607
{
639
{
608
    return ipc_call_sync_3(phoneid, IPC_M_DATA_SEND, 0, (ipcarg_t) src,
640
    return ipc_call_sync_3_0(phoneid, IPC_M_DATA_SEND, 0, (ipcarg_t) src,
609
        (ipcarg_t) size, NULL, NULL, NULL);
641
        (ipcarg_t) size);
610
}
642
}
611
 
643
 
612
/** Wrapper for receiving the IPC_M_DATA_SEND calls.
644
/** Wrapper for receiving the IPC_M_DATA_SEND calls.
613
 *
645
 *
614
 * This wrapper only makes it more comfortable to receive IPC_M_DATA_SEND calls
646
 * This wrapper only makes it more comfortable to receive IPC_M_DATA_SEND calls
615
 * so that the user doesn't have to remember the meaning of each IPC argument.
647
 * so that the user doesn't have to remember the meaning of each IPC argument.
616
 *
648
 *
617
 * So far, this wrapper is to be used from within a connection fibril.
649
 * So far, this wrapper is to be used from within a connection fibril.
618
 *
650
 *
619
 * @param callid    Storage where the hash of the IPC_M_DATA_SEND call will
651
 * @param callid    Storage where the hash of the IPC_M_DATA_SEND call will
620
 *          be stored.
652
 *          be stored.
621
 * @param call      Storage where the incoming call will be stored.
653
 * @param call      Storage where the incoming call will be stored.
622
 * @param dst       Storage where the suggested destination address will
654
 * @param dst       Storage where the suggested destination address will
623
 *          be stored. May be NULL.
655
 *          be stored. May be NULL.
624
 * @param size      Storage where the suggested size will be stored. May be
656
 * @param size      Storage where the suggested size will be stored. May be
625
 *          NULL
657
 *          NULL
626
 *
658
 *
627
 * @return      Non-zero on success, zero on failure.
659
 * @return      Non-zero on success, zero on failure.
628
 */
660
 */
629
int ipc_data_receive(ipc_callid_t *callid, ipc_call_t *call, void **dst,
661
int ipc_data_receive(ipc_callid_t *callid, ipc_call_t *call, void **dst,
630
    size_t *size)
662
    size_t *size)
631
{
663
{
632
    assert(callid);
664
    assert(callid);
633
    assert(call);
665
    assert(call);
634
 
666
 
635
    *callid = async_get_call(call);
667
    *callid = async_get_call(call);
636
    if (IPC_GET_METHOD(*call) != IPC_M_DATA_SEND)
668
    if (IPC_GET_METHOD(*call) != IPC_M_DATA_SEND)
637
        return 0;
669
        return 0;
638
    if (dst)
670
    if (dst)
639
        *dst = (void *) IPC_GET_ARG1(*call);
671
        *dst = (void *) IPC_GET_ARG1(*call);
640
    if (size)
672
    if (size)
641
        *size = (size_t) IPC_GET_ARG3(*call);
673
        *size = (size_t) IPC_GET_ARG3(*call);
642
    return 1;
674
    return 1;
643
}
675
}
644
 
676
 
645
/** Wrapper for answering the IPC_M_DATA_SEND calls.
677
/** Wrapper for answering the IPC_M_DATA_SEND calls.
646
 *
678
 *
647
 * This wrapper only makes it more comfortable to answer IPC_M_DATA_SEND calls
679
 * This wrapper only makes it more comfortable to answer IPC_M_DATA_SEND calls
648
 * so that the user doesn't have to remember the meaning of each IPC argument.
680
 * so that the user doesn't have to remember the meaning of each IPC argument.
649
 *
681
 *
650
 * @param callid    Hash of the IPC_M_DATA_SEND call to answer.
682
 * @param callid    Hash of the IPC_M_DATA_SEND call to answer.
651
 * @param call      Call structure with the request.
683
 * @param call      Call structure with the request.
652
 * @param dst       Final destination address for the IPC_M_DATA_SEND call.
684
 * @param dst       Final destination address for the IPC_M_DATA_SEND call.
653
 * @param size      Final size for the IPC_M_DATA_SEND call.
685
 * @param size      Final size for the IPC_M_DATA_SEND call.
654
 *
686
 *
655
 * @return      Zero on success or a value from @ref errno.h on failure.
687
 * @return      Zero on success or a value from @ref errno.h on failure.
656
 */
688
 */
657
ipcarg_t ipc_data_deliver(ipc_callid_t callid, ipc_call_t *call, void *dst,
689
ipcarg_t ipc_data_deliver(ipc_callid_t callid, ipc_call_t *call, void *dst,
658
    size_t size)
690
    size_t size)
659
{
691
{
660
    IPC_SET_RETVAL(*call, EOK);
692
    IPC_SET_RETVAL(*call, EOK);
661
    IPC_SET_ARG1(*call, (ipcarg_t) dst);
693
    IPC_SET_ARG1(*call, (ipcarg_t) dst);
662
    IPC_SET_ARG3(*call, (ipcarg_t) size);
694
    IPC_SET_ARG3(*call, (ipcarg_t) size);
663
    return ipc_answer(callid, call);
695
    return ipc_answer(callid, call);
664
}
696
}
665
 
697
 
666
/** @}
698
/** @}
667
 */
699
 */
668
 
700