Subversion Repositories HelenOS

Rev

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

Rev 2615 Rev 2618
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 three payload arguments 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_slow() because the payload
88
 * function is faster than the generic ipc_call_sync_slow() because the payload
89
 * is passed directly in registers.
89
 * is passed directly in registers.
90
 *
90
 *
91
 * @param phoneid   Phone handle for the call.
91
 * @param phoneid   Phone handle for the call.
92
 * @param method    Requested method.
92
 * @param method    Requested method.
93
 * @param arg1      Service-defined payload argument.
93
 * @param arg1      Service-defined payload argument.
94
 * @param arg2      Service-defined payload argument.
94
 * @param arg2      Service-defined payload argument.
95
 * @param arg3      Service-defined payload argument.
95
 * @param arg3      Service-defined payload argument.
96
 * @param result1   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.
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.
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.
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.
100
 * @param result5   If non-NULL, the return ARG5 will be stored there.
101
 *
101
 *
102
 * @return      Negative values represent errors returned by IPC.
102
 * @return      Negative values represent errors returned by IPC.
103
 *          Otherwise the RETVAL of the answer is returned.
103
 *          Otherwise the RETVAL of the answer is returned.
104
 */
104
 */
105
int
105
int
106
ipc_call_sync_fast(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
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,
107
    ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3,
108
    ipcarg_t *result4, ipcarg_t *result5)
108
    ipcarg_t *result4, ipcarg_t *result5)
109
{
109
{
110
    ipc_call_t resdata;
110
    ipc_call_t resdata;
111
    int callres;
111
    int callres;
112
   
112
   
113
    callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
113
    callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
114
        arg2, arg3, (sysarg_t) &resdata);
114
        arg2, arg3, (sysarg_t) &resdata);
115
    if (callres)
115
    if (callres)
116
        return callres;
116
        return callres;
117
    if (result1)
117
    if (result1)
118
        *result1 = IPC_GET_ARG1(resdata);
118
        *result1 = IPC_GET_ARG1(resdata);
119
    if (result2)
119
    if (result2)
120
        *result2 = IPC_GET_ARG2(resdata);
120
        *result2 = IPC_GET_ARG2(resdata);
121
    if (result3)
121
    if (result3)
122
        *result3 = IPC_GET_ARG3(resdata);
122
        *result3 = IPC_GET_ARG3(resdata);
123
    if (result4)
123
    if (result4)
124
        *result4 = IPC_GET_ARG4(resdata);
124
        *result4 = IPC_GET_ARG4(resdata);
125
    if (result5)
125
    if (result5)
126
        *result5 = IPC_GET_ARG5(resdata);
126
        *result5 = IPC_GET_ARG5(resdata);
127
 
127
 
128
    return IPC_GET_RETVAL(resdata);
128
    return IPC_GET_RETVAL(resdata);
129
}
129
}
130
 
130
 
131
/** Make a synchronous call transmitting 5 arguments of payload.
131
/** Make a synchronous call transmitting 5 arguments of payload.
132
 *
132
 *
133
 * @param phoneid   Phone handle for the call.
133
 * @param phoneid   Phone handle for the call.
134
 * @param method    Requested method.
134
 * @param method    Requested method.
135
 * @param arg1      Service-defined payload argument.
135
 * @param arg1      Service-defined payload argument.
136
 * @param arg2      Service-defined payload argument.
136
 * @param arg2      Service-defined payload argument.
137
 * @param arg3      Service-defined payload argument.
137
 * @param arg3      Service-defined payload argument.
138
 * @param arg4      Service-defined payload argument.
138
 * @param arg4      Service-defined payload argument.
139
 * @param arg5      Service-defined payload argument.
139
 * @param arg5      Service-defined payload argument.
140
 * @param result1   If non-NULL, storage for the first return argument.
140
 * @param result1   If non-NULL, storage for the first return argument.
141
 * @param result2   If non-NULL, storage for the second return argument.
141
 * @param result2   If non-NULL, storage for the second return argument.
142
 * @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.
143
 * @param result4   If non-NULL, storage for the fourth return argument.
144
 * @param result5   If non-NULL, storage for the fifth return argument.
144
 * @param result5   If non-NULL, storage for the fifth return argument.
145
 *
145
 *
146
 * @return      Negative value means IPC error.
146
 * @return      Negative value means IPC error.
147
 *          Otherwise the RETVAL of the answer.
147
 *          Otherwise the RETVAL of the answer.
148
 */
148
 */
149
int
149
int
150
ipc_call_sync_slow(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,
151
    ipcarg_t arg3, ipcarg_t arg4, ipcarg_t arg5, ipcarg_t *result1,
152
    ipcarg_t *result2, ipcarg_t *result3, ipcarg_t *result4, ipcarg_t *result5)
152
    ipcarg_t *result2, ipcarg_t *result3, ipcarg_t *result4, ipcarg_t *result5)
153
{
153
{
154
    ipc_call_t data;
154
    ipc_call_t data;
155
    int callres;
155
    int callres;
156
 
156
 
157
    IPC_SET_METHOD(data, method);
157
    IPC_SET_METHOD(data, method);
158
    IPC_SET_ARG1(data, arg1);
158
    IPC_SET_ARG1(data, arg1);
159
    IPC_SET_ARG2(data, arg2);
159
    IPC_SET_ARG2(data, arg2);
160
    IPC_SET_ARG3(data, arg3);
160
    IPC_SET_ARG3(data, arg3);
161
    IPC_SET_ARG4(data, arg4);
161
    IPC_SET_ARG4(data, arg4);
162
    IPC_SET_ARG5(data, arg5);
162
    IPC_SET_ARG5(data, arg5);
163
 
163
 
164
    callres = __SYSCALL3(SYS_IPC_CALL_SYNC_SLOW, phoneid, (sysarg_t) &data,
164
    callres = __SYSCALL3(SYS_IPC_CALL_SYNC_SLOW, phoneid, (sysarg_t) &data,
165
        (sysarg_t) &data);
165
        (sysarg_t) &data);
166
    if (callres)
166
    if (callres)
167
        return callres;
167
        return callres;
168
 
168
 
169
    if (result1)
169
    if (result1)
170
        *result1 = IPC_GET_ARG1(data);
170
        *result1 = IPC_GET_ARG1(data);
171
    if (result2)
171
    if (result2)
172
        *result2 = IPC_GET_ARG2(data);
172
        *result2 = IPC_GET_ARG2(data);
173
    if (result3)
173
    if (result3)
174
        *result3 = IPC_GET_ARG3(data);
174
        *result3 = IPC_GET_ARG3(data);
175
    if (result4)
175
    if (result4)
176
        *result4 = IPC_GET_ARG4(data);
176
        *result4 = IPC_GET_ARG4(data);
177
    if (result5)
177
    if (result5)
178
        *result5 = IPC_GET_ARG5(data);
178
        *result5 = IPC_GET_ARG5(data);
179
 
179
 
180
    return IPC_GET_RETVAL(data);
180
    return IPC_GET_RETVAL(data);
181
}
181
}
182
 
182
 
183
/** Syscall to send asynchronous message.
183
/** Syscall to send asynchronous message.
184
 *
184
 *
185
 * @param phoneid   Phone handle for the call.
185
 * @param phoneid   Phone handle for the call.
186
 * @param data      Call data with the request.
186
 * @param data      Call data with the request.
187
 *
187
 *
188
 * @return      Hash of the call or an error code.
188
 * @return      Hash of the call or an error code.
189
 */
189
 */
190
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)
191
{
191
{
192
    return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t) data);
192
    return __SYSCALL2(SYS_IPC_CALL_ASYNC_SLOW, phoneid, (sysarg_t) data);
193
}
193
}
194
 
194
 
195
/** Prolog to ipc_call_async_*() functions.
195
/** Prolog to ipc_call_async_*() functions.
196
 *
196
 *
197
 * @param private   Argument for the answer/error callback.
197
 * @param private   Argument for the answer/error callback.
198
 * @param callback  Answer/error callback.
198
 * @param callback  Answer/error callback.
199
 *
199
 *
200
 * @return      New, partially initialized async_call structure or NULL.
200
 * @return      New, partially initialized async_call structure or NULL.
201
 */
201
 */
202
static inline async_call_t *ipc_prepare_async(void *private,
202
static inline async_call_t *ipc_prepare_async(void *private,
203
    ipc_async_callback_t callback)
203
    ipc_async_callback_t callback)
204
{
204
{
205
    async_call_t *call;
205
    async_call_t *call;
206
 
206
 
207
    call = malloc(sizeof(*call));
207
    call = malloc(sizeof(*call));
208
    if (!call) {
208
    if (!call) {
209
        if (callback)
209
        if (callback)
210
            callback(private, ENOMEM, NULL);
210
            callback(private, ENOMEM, NULL);
211
        return NULL;
211
        return NULL;
212
    }
212
    }
213
    call->callback = callback;
213
    call->callback = callback;
214
    call->private = private;
214
    call->private = private;
215
 
215
 
216
    return call;
216
    return call;
217
}
217
}
218
 
218
 
219
/** Epilogue of ipc_call_async_*() functions.
219
/** Epilogue of ipc_call_async_*() functions.
220
 *
220
 *
221
 * @param callid    Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
221
 * @param callid    Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
222
 * @param phoneid   Phone handle through which the call was made.
222
 * @param phoneid   Phone handle through which the call was made.
223
 * @param call      async_call structure returned by ipc_prepare_async().
223
 * @param call      async_call structure returned by ipc_prepare_async().
224
 * @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
225
 *          call.
225
 *          call.
226
 */
226
 */
227
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,
228
    async_call_t *call, int can_preempt)
228
    async_call_t *call, int can_preempt)
229
{
229
{
230
    if (!call) { /* Nothing to do regardless if failed or not */
230
    if (!call) { /* Nothing to do regardless if failed or not */
231
        futex_up(&ipc_futex);
231
        futex_up(&ipc_futex);
232
        return;
232
        return;
233
    }
233
    }
234
 
234
 
235
    if (callid == IPC_CALLRET_FATAL) {
235
    if (callid == IPC_CALLRET_FATAL) {
236
        futex_up(&ipc_futex);
236
        futex_up(&ipc_futex);
237
        /* Call asynchronous handler with error code */
237
        /* Call asynchronous handler with error code */
238
        if (call->callback)
238
        if (call->callback)
239
            call->callback(call->private, ENOENT, NULL);
239
            call->callback(call->private, ENOENT, NULL);
240
        free(call);
240
        free(call);
241
        return;
241
        return;
242
    }
242
    }
243
 
243
 
244
    if (callid == IPC_CALLRET_TEMPORARY) {
244
    if (callid == IPC_CALLRET_TEMPORARY) {
245
        futex_up(&ipc_futex);
245
        futex_up(&ipc_futex);
246
 
246
 
247
        call->u.msg.phoneid = phoneid;
247
        call->u.msg.phoneid = phoneid;
248
       
248
       
249
        futex_down(&async_futex);
249
        futex_down(&async_futex);
250
        list_append(&call->list, &queued_calls);
250
        list_append(&call->list, &queued_calls);
251
 
251
 
252
        if (can_preempt) {
252
        if (can_preempt) {
253
            call->fid = fibril_get_id();
253
            call->fid = fibril_get_id();
254
            fibril_switch(FIBRIL_TO_MANAGER);
254
            fibril_switch(FIBRIL_TO_MANAGER);
255
            /* Async futex unlocked by previous call */
255
            /* Async futex unlocked by previous call */
256
        } else {
256
        } else {
257
            call->fid = 0;
257
            call->fid = 0;
258
            futex_up(&async_futex);
258
            futex_up(&async_futex);
259
        }
259
        }
260
        return;
260
        return;
261
    }
261
    }
262
    call->u.callid = callid;
262
    call->u.callid = callid;
263
    /* Add call to the list of dispatched calls */
263
    /* Add call to the list of dispatched calls */
264
    list_append(&call->list, &dispatched_calls);
264
    list_append(&call->list, &dispatched_calls);
265
    futex_up(&ipc_futex);
265
    futex_up(&ipc_futex);
266
   
266
   
267
}
267
}
268
 
268
 
269
/** Make a fast asynchronous call.
269
/** Make a fast asynchronous call.
270
 *
270
 *
271
 * This function can only handle two arguments of payload. It is, however,
271
 * This function can only handle four arguments of payload. It is, however,
272
 * faster than the more generic ipc_call_async_3().
272
 * faster than the more generic ipc_call_async_slow().
273
 *
273
 *
274
 * Note that this function is a void function.
274
 * Note that this function is a void function.
275
 * During normal opertation, answering this call will trigger the callback.
275
 * During normal opertation, answering this call will trigger the callback.
276
 * 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.
277
 * If the call cannot be temporarily made, queue it.
277
 * If the call cannot be temporarily made, queue it.
278
 *
278
 *
279
 * @param phoneid   Phone handle for the call.
279
 * @param phoneid   Phone handle for the call.
280
 * @param method    Requested method.
280
 * @param method    Requested method.
281
 * @param arg1      Service-defined payload argument.
281
 * @param arg1      Service-defined payload argument.
282
 * @param arg2      Service-defined payload argument.
282
 * @param arg2      Service-defined payload argument.
-
 
283
 * @param arg3      Service-defined payload argument.
-
 
284
 * @param arg4      Service-defined payload argument.
283
 * @param private   Argument to be passed to the answer/error callback.
285
 * @param private   Argument to be passed to the answer/error callback.
284
 * @param callback  Answer or error callback.
286
 * @param callback  Answer or error callback.
285
 * @param can_preempt   If non-zero, the current fibril will be preempted in
287
 * @param can_preempt   If non-zero, the current fibril will be preempted in
286
 *          case the kernel temporarily refuses to accept more
288
 *          case the kernel temporarily refuses to accept more
287
 *          asynchronous calls.
289
 *          asynchronous calls.
288
 */
290
 */
289
void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
291
void ipc_call_async_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
290
    ipcarg_t arg2, void *private, ipc_async_callback_t callback,
292
    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, void *private,
291
    int can_preempt)
293
    ipc_async_callback_t callback, int can_preempt)
292
{
294
{
293
    async_call_t *call = NULL;
295
    async_call_t *call = NULL;
294
    ipc_callid_t callid;
296
    ipc_callid_t callid;
295
 
297
 
296
    if (callback) {
298
    if (callback) {
297
        call = ipc_prepare_async(private, callback);
299
        call = ipc_prepare_async(private, callback);
298
        if (!call)
300
        if (!call)
299
            return;
301
            return;
300
    }
302
    }
301
 
303
 
302
    /*
304
    /*
303
     * We need to make sure that we get callid before another thread
305
     * We need to make sure that we get callid before another thread
304
     * accesses the queue again.
306
     * accesses the queue again.
305
     */
307
     */
306
    futex_down(&ipc_futex);
308
    futex_down(&ipc_futex);
307
    callid = __SYSCALL4(SYS_IPC_CALL_ASYNC_FAST, phoneid, method, arg1,
309
    callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid, method, arg1,
308
        arg2);
310
        arg2, arg3, arg4);
309
 
311
 
310
    if (callid == IPC_CALLRET_TEMPORARY) {
312
    if (callid == IPC_CALLRET_TEMPORARY) {
311
        if (!call) {
313
        if (!call) {
312
            call = ipc_prepare_async(private, callback);
314
            call = ipc_prepare_async(private, callback);
313
            if (!call)
315
            if (!call)
314
                return;
316
                return;
315
        }
317
        }
316
        IPC_SET_METHOD(call->u.msg.data, method);
318
        IPC_SET_METHOD(call->u.msg.data, method);
317
        IPC_SET_ARG1(call->u.msg.data, arg1);
319
        IPC_SET_ARG1(call->u.msg.data, arg1);
318
        IPC_SET_ARG2(call->u.msg.data, arg2);
320
        IPC_SET_ARG2(call->u.msg.data, arg2);
-
 
321
        IPC_SET_ARG3(call->u.msg.data, arg3);
-
 
322
        IPC_SET_ARG4(call->u.msg.data, arg4);
319
    }
323
    }
320
    ipc_finish_async(callid, phoneid, call, can_preempt);
324
    ipc_finish_async(callid, phoneid, call, can_preempt);
321
}
325
}
322
 
326
 
323
/** Make an asynchronous call transmitting the entire payload.
327
/** Make an asynchronous call transmitting the entire payload.
324
 *
328
 *
325
 * Note that this function is a void function.
329
 * Note that this function is a void function.
326
 * During normal opertation, answering this call will trigger the callback.
330
 * During normal opertation, answering this call will trigger the callback.
327
 * In case of fatal error, call the callback handler with the proper error code.
331
 * In case of fatal error, call the callback handler with the proper error code.
328
 * If the call cannot be temporarily made, queue it.
332
 * If the call cannot be temporarily made, queue it.
329
 *
333
 *
330
 * @param phoneid   Phone handle for the call.
334
 * @param phoneid   Phone handle for the call.
331
 * @param method    Requested method.
335
 * @param method    Requested method.
332
 * @param arg1      Service-defined payload argument.
336
 * @param arg1      Service-defined payload argument.
333
 * @param arg2      Service-defined payload argument.
337
 * @param arg2      Service-defined payload argument.
334
 * @param arg3      Service-defined payload argument.
338
 * @param arg3      Service-defined payload argument.
-
 
339
 * @param arg4      Service-defined payload argument.
-
 
340
 * @param arg5      Service-defined payload argument.
335
 * @param private   Argument to be passed to the answer/error callback.
341
 * @param private   Argument to be passed to the answer/error callback.
336
 * @param callback  Answer or error callback.
342
 * @param callback  Answer or error callback.
337
 * @param can_preempt   If non-zero, the current fibril will be preempted in
343
 * @param can_preempt   If non-zero, the current fibril will be preempted in
338
 *          case the kernel temporarily refuses to accept more
344
 *          case the kernel temporarily refuses to accept more
339
 *          asynchronous calls.
345
 *          asynchronous calls.
340
 *
346
 *
341
 */
347
 */
342
void ipc_call_async_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
348
void ipc_call_async_slow(int phoneid, ipcarg_t method, ipcarg_t arg1,
343
    ipcarg_t arg2, ipcarg_t arg3, void *private, ipc_async_callback_t callback,
349
    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipcarg_t arg5, void *private,
344
    int can_preempt)
350
    ipc_async_callback_t callback, int can_preempt)
345
{
351
{
346
    async_call_t *call;
352
    async_call_t *call;
347
    ipc_callid_t callid;
353
    ipc_callid_t callid;
348
 
354
 
349
    call = ipc_prepare_async(private, callback);
355
    call = ipc_prepare_async(private, callback);
350
    if (!call)
356
    if (!call)
351
        return;
357
        return;
352
 
358
 
353
    IPC_SET_METHOD(call->u.msg.data, method);
359
    IPC_SET_METHOD(call->u.msg.data, method);
354
    IPC_SET_ARG1(call->u.msg.data, arg1);
360
    IPC_SET_ARG1(call->u.msg.data, arg1);
355
    IPC_SET_ARG2(call->u.msg.data, arg2);
361
    IPC_SET_ARG2(call->u.msg.data, arg2);
356
    IPC_SET_ARG3(call->u.msg.data, arg3);
362
    IPC_SET_ARG3(call->u.msg.data, arg3);
-
 
363
    IPC_SET_ARG4(call->u.msg.data, arg4);
-
 
364
    IPC_SET_ARG5(call->u.msg.data, arg5);
357
    /*
365
    /*
358
     * We need to make sure that we get callid before another thread accesses
366
     * We need to make sure that we get callid before another thread
359
     * the queue again.
367
     * accesses the queue again.
360
     */
368
     */
361
    futex_down(&ipc_futex);
369
    futex_down(&ipc_futex);
362
    callid = _ipc_call_async(phoneid, &call->u.msg.data);
370
    callid = _ipc_call_async(phoneid, &call->u.msg.data);
363
 
371
 
364
    ipc_finish_async(callid, phoneid, call, can_preempt);
372
    ipc_finish_async(callid, phoneid, call, can_preempt);
365
}
373
}
366
 
374
 
367
 
375
 
368
/** Answer a received call - fast version.
376
/** Answer a received call - fast version.
369
 *
377
 *
370
 * The fast answer makes use of passing retval and first two arguments in
378
 * The fast answer makes use of passing retval and first two arguments in
371
 * registers. If you need to return more, use the ipc_answer() instead.
379
 * registers. If you need to return more, use the ipc_answer() instead.
372
 *
380
 *
373
 * @param callid    Hash of the call being answered.
381
 * @param callid    Hash of the call being answered.
374
 * @param retval    Return value.
382
 * @param retval    Return value.
375
 * @param arg1      First return argument.
383
 * @param arg1      First return argument.
376
 * @param arg2      Second return argument.
384
 * @param arg2      Second return argument.
377
 *
385
 *
378
 * @return      Zero on success or a value from @ref errno.h on failure.
386
 * @return      Zero on success or a value from @ref errno.h on failure.
379
 */
387
 */
380
ipcarg_t ipc_answer_fast(ipc_callid_t callid, ipcarg_t retval, ipcarg_t arg1,
388
ipcarg_t ipc_answer_fast(ipc_callid_t callid, ipcarg_t retval, ipcarg_t arg1,
381
    ipcarg_t arg2)
389
    ipcarg_t arg2)
382
{
390
{
383
    return __SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2);
391
    return __SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2);
384
}
392
}
385
 
393
 
386
/** Answer a received call - full version.
394
/** Answer a received call - full version.
387
 *
395
 *
388
 * @param callid    Hash of the call being answered.
396
 * @param callid    Hash of the call being answered.
389
 * @param call      Call structure with the answer.
397
 * @param call      Call structure with the answer.
390
 *          Must be already initialized by the responder.
398
 *          Must be already initialized by the responder.
391
 *
399
 *
392
 * @return      Zero on success or a value from @ref errno.h on failure.
400
 * @return      Zero on success or a value from @ref errno.h on failure.
393
 */
401
 */
394
ipcarg_t ipc_answer(ipc_callid_t callid, ipc_call_t *call)
402
ipcarg_t ipc_answer(ipc_callid_t callid, ipc_call_t *call)
395
{
403
{
396
    return __SYSCALL2(SYS_IPC_ANSWER, callid, (sysarg_t) call);
404
    return __SYSCALL2(SYS_IPC_ANSWER, callid, (sysarg_t) call);
397
}
405
}
398
 
406
 
399
 
407
 
400
/** Try to dispatch queued calls from the async queue. */
408
/** Try to dispatch queued calls from the async queue. */
401
static void try_dispatch_queued_calls(void)
409
static void try_dispatch_queued_calls(void)
402
{
410
{
403
    async_call_t *call;
411
    async_call_t *call;
404
    ipc_callid_t callid;
412
    ipc_callid_t callid;
405
 
413
 
406
    /** @todo
414
    /** @todo
407
     * Integrate intelligently ipc_futex, so that it is locked during
415
     * Integrate intelligently ipc_futex, so that it is locked during
408
     * ipc_call_async_*(), until it is added to dispatched_calls.
416
     * ipc_call_async_*(), until it is added to dispatched_calls.
409
     */
417
     */
410
    futex_down(&async_futex);
418
    futex_down(&async_futex);
411
    while (!list_empty(&queued_calls)) {
419
    while (!list_empty(&queued_calls)) {
412
        call = list_get_instance(queued_calls.next, async_call_t, list);
420
        call = list_get_instance(queued_calls.next, async_call_t, list);
413
        callid = _ipc_call_async(call->u.msg.phoneid, &call->u.msg.data);
421
        callid = _ipc_call_async(call->u.msg.phoneid, &call->u.msg.data);
414
        if (callid == IPC_CALLRET_TEMPORARY) {
422
        if (callid == IPC_CALLRET_TEMPORARY) {
415
            break;
423
            break;
416
        }
424
        }
417
        list_remove(&call->list);
425
        list_remove(&call->list);
418
 
426
 
419
        futex_up(&async_futex);
427
        futex_up(&async_futex);
420
        if (call->fid)
428
        if (call->fid)
421
            fibril_add_ready(call->fid);
429
            fibril_add_ready(call->fid);
422
       
430
       
423
        if (callid == IPC_CALLRET_FATAL) {
431
        if (callid == IPC_CALLRET_FATAL) {
424
            if (call->callback)
432
            if (call->callback)
425
                call->callback(call->private, ENOENT, NULL);
433
                call->callback(call->private, ENOENT, NULL);
426
            free(call);
434
            free(call);
427
        } else {
435
        } else {
428
            call->u.callid = callid;
436
            call->u.callid = callid;
429
            futex_down(&ipc_futex);
437
            futex_down(&ipc_futex);
430
            list_append(&call->list, &dispatched_calls);
438
            list_append(&call->list, &dispatched_calls);
431
            futex_up(&ipc_futex);
439
            futex_up(&ipc_futex);
432
        }
440
        }
433
        futex_down(&async_futex);
441
        futex_down(&async_futex);
434
    }
442
    }
435
    futex_up(&async_futex);
443
    futex_up(&async_futex);
436
}
444
}
437
 
445
 
438
/** Handle a received answer.
446
/** Handle a received answer.
439
 *
447
 *
440
 * Find the hash of the answer and call the answer callback.
448
 * Find the hash of the answer and call the answer callback.
441
 *
449
 *
442
 * @todo Make it use hash table.
450
 * @todo Make it use hash table.
443
 *
451
 *
444
 * @param callid    Hash of the received answer.
452
 * @param callid    Hash of the received answer.
445
 *          The answer has the same hash as the request OR'ed with
453
 *          The answer has the same hash as the request OR'ed with
446
 *          the IPC_CALLID_ANSWERED bit.
454
 *          the IPC_CALLID_ANSWERED bit.
447
 * @param data      Call data of the answer.
455
 * @param data      Call data of the answer.
448
 */
456
 */
449
static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
457
static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
450
{
458
{
451
    link_t *item;
459
    link_t *item;
452
    async_call_t *call;
460
    async_call_t *call;
453
 
461
 
454
    callid &= ~IPC_CALLID_ANSWERED;
462
    callid &= ~IPC_CALLID_ANSWERED;
455
   
463
   
456
    futex_down(&ipc_futex);
464
    futex_down(&ipc_futex);
457
    for (item = dispatched_calls.next; item != &dispatched_calls;
465
    for (item = dispatched_calls.next; item != &dispatched_calls;
458
        item = item->next) {
466
        item = item->next) {
459
        call = list_get_instance(item, async_call_t, list);
467
        call = list_get_instance(item, async_call_t, list);
460
        if (call->u.callid == callid) {
468
        if (call->u.callid == callid) {
461
            list_remove(&call->list);
469
            list_remove(&call->list);
462
            futex_up(&ipc_futex);
470
            futex_up(&ipc_futex);
463
            if (call->callback)
471
            if (call->callback)
464
                call->callback(call->private,
472
                call->callback(call->private,
465
                    IPC_GET_RETVAL(*data), data);
473
                    IPC_GET_RETVAL(*data), data);
466
            free(call);
474
            free(call);
467
            return;
475
            return;
468
        }
476
        }
469
    }
477
    }
470
    futex_up(&ipc_futex);
478
    futex_up(&ipc_futex);
471
}
479
}
472
 
480
 
473
 
481
 
474
/** Wait for a first call to come.
482
/** Wait for a first call to come.
475
 *
483
 *
476
 * @param call      Storage where the incoming call data will be stored.
484
 * @param call      Storage where the incoming call data will be stored.
477
 * @param usec      Timeout in microseconds
485
 * @param usec      Timeout in microseconds
478
 * @param flags     Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
486
 * @param flags     Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
479
 *
487
 *
480
 * @return      Hash of the call. Note that certain bits have special
488
 * @return      Hash of the call. Note that certain bits have special
481
 *          meaning. IPC_CALLID_ANSWERED will be set in an answer
489
 *          meaning. IPC_CALLID_ANSWERED will be set in an answer
482
 *          and IPC_CALLID_NOTIFICATION is used for notifications.
490
 *          and IPC_CALLID_NOTIFICATION is used for notifications.
483
 *         
491
 *         
484
 */
492
 */
485
ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags)
493
ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags)
486
{
494
{
487
    ipc_callid_t callid;
495
    ipc_callid_t callid;
488
 
496
 
489
    callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
497
    callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
490
    /* Handle received answers */
498
    /* Handle received answers */
491
    if (callid & IPC_CALLID_ANSWERED) {
499
    if (callid & IPC_CALLID_ANSWERED) {
492
        handle_answer(callid, call);
500
        handle_answer(callid, call);
493
        try_dispatch_queued_calls();
501
        try_dispatch_queued_calls();
494
    }
502
    }
495
 
503
 
496
    return callid;
504
    return callid;
497
}
505
}
498
 
506
 
499
/** Wait some time for an IPC call.
507
/** Wait some time for an IPC call.
500
 *
508
 *
501
 * The call will return after an answer is received.
509
 * The call will return after an answer is received.
502
 *
510
 *
503
 * @param call      Storage where the incoming call data will be stored.
511
 * @param call      Storage where the incoming call data will be stored.
504
 * @param usec      Timeout in microseconds.
512
 * @param usec      Timeout in microseconds.
505
 *
513
 *
506
 * @return      Hash of the answer.
514
 * @return      Hash of the answer.
507
 */
515
 */
508
ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec)
516
ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec)
509
{
517
{
510
    ipc_callid_t callid;
518
    ipc_callid_t callid;
511
 
519
 
512
    do {
520
    do {
513
        callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
521
        callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
514
    } while (callid & IPC_CALLID_ANSWERED);
522
    } while (callid & IPC_CALLID_ANSWERED);
515
 
523
 
516
    return callid;
524
    return callid;
517
}
525
}
518
 
526
 
519
/** Check if there is an IPC call waiting to be picked up.
527
/** Check if there is an IPC call waiting to be picked up.
520
 *
528
 *
521
 * @param call      Storage where the incoming call will be stored.
529
 * @param call      Storage where the incoming call will be stored.
522
 * @return      Hash of the answer.
530
 * @return      Hash of the answer.
523
 */
531
 */
524
ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
532
ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
525
{
533
{
526
    ipc_callid_t callid;
534
    ipc_callid_t callid;
527
 
535
 
528
    do {
536
    do {
529
        callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
537
        callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
530
            SYNCH_FLAGS_NON_BLOCKING);
538
            SYNCH_FLAGS_NON_BLOCKING);
531
    } while (callid & IPC_CALLID_ANSWERED);
539
    } while (callid & IPC_CALLID_ANSWERED);
532
 
540
 
533
    return callid;
541
    return callid;
534
}
542
}
535
 
543
 
536
/** Ask destination to do a callback connection.
544
/** Ask destination to do a callback connection.
537
 *
545
 *
538
 * @param phoneid   Phone handle used for contacting the other side.
546
 * @param phoneid   Phone handle used for contacting the other side.
539
 * @param arg1      Service-defined argument.
547
 * @param arg1      Service-defined argument.
540
 * @param arg2      Service-defined argument.
548
 * @param arg2      Service-defined argument.
541
 * @param phonehash Storage where the library will store an opaque
549
 * @param phonehash Storage where the library will store an opaque
542
 *          identifier of the phone that will be used for incoming
550
 *          identifier of the phone that will be used for incoming
543
 *          calls. This identifier can be used for connection
551
 *          calls. This identifier can be used for connection
544
 *          tracking.
552
 *          tracking.
545
 *
553
 *
546
 * @return      Zero on success or a negative error code.
554
 * @return      Zero on success or a negative error code.
547
 */
555
 */
548
int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phonehash)
556
int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phonehash)
549
{
557
{
550
    return ipc_call_sync_2_3(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2,
558
    return ipc_call_sync_2_3(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2,
551
        NULL, NULL, phonehash);
559
        NULL, NULL, phonehash);
552
}
560
}
553
 
561
 
554
/** Ask through phone for a new connection to some service.
562
/** Ask through phone for a new connection to some service.
555
 *
563
 *
556
 * @param phoneid   Phone handle used for contacting the other side.
564
 * @param phoneid   Phone handle used for contacting the other side.
557
 * @param arg1      User defined argument.
565
 * @param arg1      User defined argument.
558
 * @param arg2      User defined argument.
566
 * @param arg2      User defined argument.
559
 *
567
 *
560
 * @return      New phone handle on success or a negative error code.
568
 * @return      New phone handle on success or a negative error code.
561
 */
569
 */
562
int ipc_connect_me_to(int phoneid, int arg1, int arg2)
570
int ipc_connect_me_to(int phoneid, int arg1, int arg2)
563
{
571
{
564
    ipcarg_t newphid;
572
    ipcarg_t newphid;
565
    int res;
573
    int res;
566
 
574
 
567
    res = ipc_call_sync_2_3(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, NULL,
575
    res = ipc_call_sync_2_3(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, NULL,
568
        NULL, &newphid);
576
        NULL, &newphid);
569
    if (res)
577
    if (res)
570
        return res;
578
        return res;
571
    return newphid;
579
    return newphid;
572
}
580
}
573
 
581
 
574
/** Hang up a phone.
582
/** Hang up a phone.
575
 *
583
 *
576
 * @param phoneid   Handle of the phone to be hung up.
584
 * @param phoneid   Handle of the phone to be hung up.
577
 *
585
 *
578
 * @return      Zero on success or a negative error code.
586
 * @return      Zero on success or a negative error code.
579
 */
587
 */
580
int ipc_hangup(int phoneid)
588
int ipc_hangup(int phoneid)
581
{
589
{
582
    return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
590
    return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
583
}
591
}
584
 
592
 
585
/** Register IRQ notification.
593
/** Register IRQ notification.
586
 *
594
 *
587
 * @param inr       IRQ number.
595
 * @param inr       IRQ number.
588
 * @param devno     Device number of the device generating inr.
596
 * @param devno     Device number of the device generating inr.
589
 * @param method    Use this method for notifying me.
597
 * @param method    Use this method for notifying me.
590
 * @param ucode     Top-half pseudocode handler.
598
 * @param ucode     Top-half pseudocode handler.
591
 *
599
 *
592
 * @return      Value returned by the kernel.
600
 * @return      Value returned by the kernel.
593
 */
601
 */
594
int ipc_register_irq(int inr, int devno, int method, irq_code_t *ucode)
602
int ipc_register_irq(int inr, int devno, int method, irq_code_t *ucode)
595
{
603
{
596
    return __SYSCALL4(SYS_IPC_REGISTER_IRQ, inr, devno, method,
604
    return __SYSCALL4(SYS_IPC_REGISTER_IRQ, inr, devno, method,
597
        (sysarg_t) ucode);
605
        (sysarg_t) ucode);
598
}
606
}
599
 
607
 
600
/** Unregister IRQ notification.
608
/** Unregister IRQ notification.
601
 *
609
 *
602
 * @param inr       IRQ number.
610
 * @param inr       IRQ number.
603
 * @param devno     Device number of the device generating inr.
611
 * @param devno     Device number of the device generating inr.
604
 *
612
 *
605
 * @return      Value returned by the kernel.
613
 * @return      Value returned by the kernel.
606
 */
614
 */
607
int ipc_unregister_irq(int inr, int devno)
615
int ipc_unregister_irq(int inr, int devno)
608
{
616
{
609
    return __SYSCALL2(SYS_IPC_UNREGISTER_IRQ, inr, devno);
617
    return __SYSCALL2(SYS_IPC_UNREGISTER_IRQ, inr, devno);
610
}
618
}
611
 
619
 
612
/** Forward a received call to another destination.
620
/** Forward a received call to another destination.
613
 *
621
 *
614
 * @param callid    Hash of the call to forward.
622
 * @param callid    Hash of the call to forward.
615
 * @param phoneid   Phone handle to use for forwarding.
623
 * @param phoneid   Phone handle to use for forwarding.
616
 * @param method    New method for the forwarded call.
624
 * @param method    New method for the forwarded call.
617
 * @param arg1      New value of the first argument for the forwarded call.
625
 * @param arg1      New value of the first argument for the forwarded call.
618
 *
626
 *
619
 * @return      Zero on success or an error code.
627
 * @return      Zero on success or an error code.
620
 *
628
 *
621
 * For non-system methods, the old method and arg1 are rewritten by the new
629
 * For non-system methods, the old method and arg1 are rewritten by the new
622
 * values. For system methods, the new method and arg1 are written to the old
630
 * values. For system methods, the new method and arg1 are written to the old
623
 * arg1 and arg2, respectivelly.
631
 * arg1 and arg2, respectivelly.
624
 */
632
 */
625
int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
633
int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
626
{
634
{
627
    return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
635
    return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
628
}
636
}
629
 
637
 
630
/** Wrapper for making IPC_M_DATA_SEND calls.
638
/** Wrapper for making IPC_M_DATA_SEND calls.
631
 *
639
 *
632
 * @param phoneid   Phone that will be used to contact the receiving side.
640
 * @param phoneid   Phone that will be used to contact the receiving side.
633
 * @param src       Address of the beginning of the source buffer.
641
 * @param src       Address of the beginning of the source buffer.
634
 * @param size      Size of the source buffer.
642
 * @param size      Size of the source buffer.
635
 *
643
 *
636
 * @return      Zero on success or a negative error code from errno.h.
644
 * @return      Zero on success or a negative error code from errno.h.
637
 */
645
 */
638
int ipc_data_send(int phoneid, void *src, size_t size)
646
int ipc_data_send(int phoneid, void *src, size_t size)
639
{
647
{
640
    return ipc_call_sync_3_0(phoneid, IPC_M_DATA_SEND, 0, (ipcarg_t) src,
648
    return ipc_call_sync_3_0(phoneid, IPC_M_DATA_SEND, 0, (ipcarg_t) src,
641
        (ipcarg_t) size);
649
        (ipcarg_t) size);
642
}
650
}
643
 
651
 
644
/** Wrapper for receiving the IPC_M_DATA_SEND calls.
652
/** Wrapper for receiving the IPC_M_DATA_SEND calls.
645
 *
653
 *
646
 * This wrapper only makes it more comfortable to receive IPC_M_DATA_SEND calls
654
 * This wrapper only makes it more comfortable to receive IPC_M_DATA_SEND calls
647
 * so that the user doesn't have to remember the meaning of each IPC argument.
655
 * so that the user doesn't have to remember the meaning of each IPC argument.
648
 *
656
 *
649
 * So far, this wrapper is to be used from within a connection fibril.
657
 * So far, this wrapper is to be used from within a connection fibril.
650
 *
658
 *
651
 * @param callid    Storage where the hash of the IPC_M_DATA_SEND call will
659
 * @param callid    Storage where the hash of the IPC_M_DATA_SEND call will
652
 *          be stored.
660
 *          be stored.
653
 * @param call      Storage where the incoming call will be stored.
661
 * @param call      Storage where the incoming call will be stored.
654
 * @param dst       Storage where the suggested destination address will
662
 * @param dst       Storage where the suggested destination address will
655
 *          be stored. May be NULL.
663
 *          be stored. May be NULL.
656
 * @param size      Storage where the suggested size will be stored. May be
664
 * @param size      Storage where the suggested size will be stored. May be
657
 *          NULL
665
 *          NULL
658
 *
666
 *
659
 * @return      Non-zero on success, zero on failure.
667
 * @return      Non-zero on success, zero on failure.
660
 */
668
 */
661
int ipc_data_receive(ipc_callid_t *callid, ipc_call_t *call, void **dst,
669
int ipc_data_receive(ipc_callid_t *callid, ipc_call_t *call, void **dst,
662
    size_t *size)
670
    size_t *size)
663
{
671
{
664
    assert(callid);
672
    assert(callid);
665
    assert(call);
673
    assert(call);
666
 
674
 
667
    *callid = async_get_call(call);
675
    *callid = async_get_call(call);
668
    if (IPC_GET_METHOD(*call) != IPC_M_DATA_SEND)
676
    if (IPC_GET_METHOD(*call) != IPC_M_DATA_SEND)
669
        return 0;
677
        return 0;
670
    if (dst)
678
    if (dst)
671
        *dst = (void *) IPC_GET_ARG1(*call);
679
        *dst = (void *) IPC_GET_ARG1(*call);
672
    if (size)
680
    if (size)
673
        *size = (size_t) IPC_GET_ARG3(*call);
681
        *size = (size_t) IPC_GET_ARG3(*call);
674
    return 1;
682
    return 1;
675
}
683
}
676
 
684
 
677
/** Wrapper for answering the IPC_M_DATA_SEND calls.
685
/** Wrapper for answering the IPC_M_DATA_SEND calls.
678
 *
686
 *
679
 * This wrapper only makes it more comfortable to answer IPC_M_DATA_SEND calls
687
 * This wrapper only makes it more comfortable to answer IPC_M_DATA_SEND calls
680
 * so that the user doesn't have to remember the meaning of each IPC argument.
688
 * so that the user doesn't have to remember the meaning of each IPC argument.
681
 *
689
 *
682
 * @param callid    Hash of the IPC_M_DATA_SEND call to answer.
690
 * @param callid    Hash of the IPC_M_DATA_SEND call to answer.
683
 * @param call      Call structure with the request.
691
 * @param call      Call structure with the request.
684
 * @param dst       Final destination address for the IPC_M_DATA_SEND call.
692
 * @param dst       Final destination address for the IPC_M_DATA_SEND call.
685
 * @param size      Final size for the IPC_M_DATA_SEND call.
693
 * @param size      Final size for the IPC_M_DATA_SEND call.
686
 *
694
 *
687
 * @return      Zero on success or a value from @ref errno.h on failure.
695
 * @return      Zero on success or a value from @ref errno.h on failure.
688
 */
696
 */
689
ipcarg_t ipc_data_deliver(ipc_callid_t callid, ipc_call_t *call, void *dst,
697
ipcarg_t ipc_data_deliver(ipc_callid_t callid, ipc_call_t *call, void *dst,
690
    size_t size)
698
    size_t size)
691
{
699
{
692
    IPC_SET_RETVAL(*call, EOK);
700
    IPC_SET_RETVAL(*call, EOK);
693
    IPC_SET_ARG1(*call, (ipcarg_t) dst);
701
    IPC_SET_ARG1(*call, (ipcarg_t) dst);
694
    IPC_SET_ARG3(*call, (ipcarg_t) size);
702
    IPC_SET_ARG3(*call, (ipcarg_t) size);
695
    return ipc_answer(callid, call);
703
    return ipc_answer(callid, call);
696
}
704
}
697
 
705
 
698
/** @}
706
/** @}
699
 */
707
 */
700
 
708