Subversion Repositories HelenOS

Rev

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

Rev 3476 Rev 4173
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 genericipc
29
/** @addtogroup genericipc
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
/* Lock ordering
35
/* Lock ordering
36
 *
36
 *
37
 * First the answerbox, then the phone.
37
 * First the answerbox, then the phone.
38
 */
38
 */
39
 
39
 
40
#include <synch/synch.h>
40
#include <synch/synch.h>
41
#include <synch/spinlock.h>
41
#include <synch/spinlock.h>
42
#include <synch/mutex.h>
42
#include <synch/mutex.h>
43
#include <synch/waitq.h>
43
#include <synch/waitq.h>
44
#include <synch/synch.h>
44
#include <synch/synch.h>
45
#include <ipc/ipc.h>
45
#include <ipc/ipc.h>
46
#include <ipc/kbox.h>
46
#include <ipc/kbox.h>
-
 
47
#include <event/event.h>
47
#include <errno.h>
48
#include <errno.h>
48
#include <mm/slab.h>
49
#include <mm/slab.h>
49
#include <arch.h>
50
#include <arch.h>
50
#include <proc/task.h>
51
#include <proc/task.h>
51
#include <memstr.h>
52
#include <memstr.h>
52
#include <debug.h>
53
#include <debug.h>
53
 
54
 
-
 
55
 
54
#include <print.h>
56
#include <print.h>
55
#include <console/console.h>
57
#include <console/console.h>
56
#include <proc/thread.h>
58
#include <proc/thread.h>
57
#include <arch/interrupt.h>
59
#include <arch/interrupt.h>
58
#include <ipc/irq.h>
60
#include <ipc/irq.h>
59
 
61
 
60
/** Open channel that is assigned automatically to new tasks */
62
/** Open channel that is assigned automatically to new tasks */
61
answerbox_t *ipc_phone_0 = NULL;
63
answerbox_t *ipc_phone_0 = NULL;
62
 
64
 
63
static slab_cache_t *ipc_call_slab;
65
static slab_cache_t *ipc_call_slab;
64
 
66
 
65
/** Initialize a call structure.
67
/** Initialize a call structure.
66
 *
68
 *
67
 * @param call      Call structure to be initialized.
69
 * @param call      Call structure to be initialized.
68
 */
70
 */
69
static void _ipc_call_init(call_t *call)
71
static void _ipc_call_init(call_t *call)
70
{
72
{
71
    memsetb(call, sizeof(*call), 0);
73
    memsetb(call, sizeof(*call), 0);
72
    call->callerbox = &TASK->answerbox;
74
    call->callerbox = &TASK->answerbox;
73
    call->sender = TASK;
75
    call->sender = TASK;
74
    call->buffer = NULL;
76
    call->buffer = NULL;
75
}
77
}
76
 
78
 
77
/** Allocate and initialize a call structure.
79
/** Allocate and initialize a call structure.
78
 *
80
 *
79
 * The call is initialized, so that the reply will be directed to
81
 * The call is initialized, so that the reply will be directed to
80
 * TASK->answerbox.
82
 * TASK->answerbox.
81
 *
83
 *
82
 * @param flags     Parameters for slab_alloc (e.g FRAME_ATOMIC).
84
 * @param flags     Parameters for slab_alloc (e.g FRAME_ATOMIC).
83
 *
85
 *
84
 * @return      If flags permit it, return NULL, or initialized kernel
86
 * @return      If flags permit it, return NULL, or initialized kernel
85
 *          call structure.
87
 *          call structure.
86
 */
88
 */
87
call_t *ipc_call_alloc(int flags)
89
call_t *ipc_call_alloc(int flags)
88
{
90
{
89
    call_t *call;
91
    call_t *call;
90
 
92
 
91
    call = slab_alloc(ipc_call_slab, flags);
93
    call = slab_alloc(ipc_call_slab, flags);
92
    if (call)
94
    if (call)
93
        _ipc_call_init(call);
95
        _ipc_call_init(call);
94
 
96
 
95
    return call;
97
    return call;
96
}
98
}
97
 
99
 
98
/** Initialize a statically allocated call structure.
100
/** Initialize a statically allocated call structure.
99
 *
101
 *
100
 * @param call      Statically allocated kernel call structure to be
102
 * @param call      Statically allocated kernel call structure to be
101
 *          initialized.
103
 *          initialized.
102
 */
104
 */
103
void ipc_call_static_init(call_t *call)
105
void ipc_call_static_init(call_t *call)
104
{
106
{
105
    _ipc_call_init(call);
107
    _ipc_call_init(call);
106
    call->flags |= IPC_CALL_STATIC_ALLOC;
108
    call->flags |= IPC_CALL_STATIC_ALLOC;
107
}
109
}
108
 
110
 
109
/** Deallocate a call structure.
111
/** Deallocate a call structure.
110
 *
112
 *
111
 * @param call      Call structure to be freed.
113
 * @param call      Call structure to be freed.
112
 */
114
 */
113
void ipc_call_free(call_t *call)
115
void ipc_call_free(call_t *call)
114
{
116
{
115
    ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
117
    ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
116
    /* Check to see if we have data in the IPC_M_DATA_SEND buffer. */
118
    /* Check to see if we have data in the IPC_M_DATA_SEND buffer. */
117
    if (call->buffer)
119
    if (call->buffer)
118
        free(call->buffer);
120
        free(call->buffer);
119
    slab_free(ipc_call_slab, call);
121
    slab_free(ipc_call_slab, call);
120
}
122
}
121
 
123
 
122
/** Initialize an answerbox structure.
124
/** Initialize an answerbox structure.
123
 *
125
 *
124
 * @param box       Answerbox structure to be initialized.
126
 * @param box       Answerbox structure to be initialized.
125
 * @param task      Task to which the answerbox belongs.
127
 * @param task      Task to which the answerbox belongs.
126
 */
128
 */
127
void ipc_answerbox_init(answerbox_t *box, task_t *task)
129
void ipc_answerbox_init(answerbox_t *box, task_t *task)
128
{
130
{
129
    spinlock_initialize(&box->lock, "ipc_box_lock");
131
    spinlock_initialize(&box->lock, "ipc_box_lock");
130
    spinlock_initialize(&box->irq_lock, "ipc_box_irqlock");
132
    spinlock_initialize(&box->irq_lock, "ipc_box_irqlock");
131
    waitq_initialize(&box->wq);
133
    waitq_initialize(&box->wq);
132
    list_initialize(&box->connected_phones);
134
    list_initialize(&box->connected_phones);
133
    list_initialize(&box->calls);
135
    list_initialize(&box->calls);
134
    list_initialize(&box->dispatched_calls);
136
    list_initialize(&box->dispatched_calls);
135
    list_initialize(&box->answers);
137
    list_initialize(&box->answers);
136
    list_initialize(&box->irq_notifs);
138
    list_initialize(&box->irq_notifs);
137
    list_initialize(&box->irq_head);
139
    list_initialize(&box->irq_head);
138
    box->task = task;
140
    box->task = task;
139
}
141
}
140
 
142
 
141
/** Connect a phone to an answerbox.
143
/** Connect a phone to an answerbox.
142
 *
144
 *
143
 * @param phone     Initialized phone structure.
145
 * @param phone     Initialized phone structure.
144
 * @param box       Initialized answerbox structure.
146
 * @param box       Initialized answerbox structure.
145
 */
147
 */
146
void ipc_phone_connect(phone_t *phone, answerbox_t *box)
148
void ipc_phone_connect(phone_t *phone, answerbox_t *box)
147
{
149
{
148
    mutex_lock(&phone->lock);
150
    mutex_lock(&phone->lock);
149
 
151
 
150
    phone->state = IPC_PHONE_CONNECTED;
152
    phone->state = IPC_PHONE_CONNECTED;
151
    phone->callee = box;
153
    phone->callee = box;
152
 
154
 
153
    spinlock_lock(&box->lock);
155
    spinlock_lock(&box->lock);
154
    list_append(&phone->link, &box->connected_phones);
156
    list_append(&phone->link, &box->connected_phones);
155
    spinlock_unlock(&box->lock);
157
    spinlock_unlock(&box->lock);
156
 
158
 
157
    mutex_unlock(&phone->lock);
159
    mutex_unlock(&phone->lock);
158
}
160
}
159
 
161
 
160
/** Initialize a phone structure.
162
/** Initialize a phone structure.
161
 *
163
 *
162
 * @param phone     Phone structure to be initialized.
164
 * @param phone     Phone structure to be initialized.
163
 */
165
 */
164
void ipc_phone_init(phone_t *phone)
166
void ipc_phone_init(phone_t *phone)
165
{
167
{
166
    mutex_initialize(&phone->lock, MUTEX_PASSIVE);
168
    mutex_initialize(&phone->lock, MUTEX_PASSIVE);
167
    phone->callee = NULL;
169
    phone->callee = NULL;
168
    phone->state = IPC_PHONE_FREE;
170
    phone->state = IPC_PHONE_FREE;
169
    atomic_set(&phone->active_calls, 0);
171
    atomic_set(&phone->active_calls, 0);
170
}
172
}
171
 
173
 
172
/** Helper function to facilitate synchronous calls.
174
/** Helper function to facilitate synchronous calls.
173
 *
175
 *
174
 * @param phone     Destination kernel phone structure.
176
 * @param phone     Destination kernel phone structure.
175
 * @param request   Call structure with request.
177
 * @param request   Call structure with request.
176
 *
178
 *
177
 * @return      EOK on success or EINTR if the sleep was interrupted.
179
 * @return      EOK on success or EINTR if the sleep was interrupted.
178
 */
180
 */
179
int ipc_call_sync(phone_t *phone, call_t *request)
181
int ipc_call_sync(phone_t *phone, call_t *request)
180
{
182
{
181
    answerbox_t sync_box;
183
    answerbox_t sync_box;
182
 
184
 
183
    ipc_answerbox_init(&sync_box, TASK);
185
    ipc_answerbox_init(&sync_box, TASK);
184
 
186
 
185
    /* We will receive data in a special box. */
187
    /* We will receive data in a special box. */
186
    request->callerbox = &sync_box;
188
    request->callerbox = &sync_box;
187
 
189
 
188
    ipc_call(phone, request);
190
    ipc_call(phone, request);
189
    if (!ipc_wait_for_call(&sync_box, SYNCH_NO_TIMEOUT,
191
    if (!ipc_wait_for_call(&sync_box, SYNCH_NO_TIMEOUT,
190
        SYNCH_FLAGS_INTERRUPTIBLE))
192
        SYNCH_FLAGS_INTERRUPTIBLE))
191
        return EINTR;
193
        return EINTR;
192
    return EOK;
194
    return EOK;
193
}
195
}
194
 
196
 
195
/** Answer a message which was not dispatched and is not listed in any queue.
197
/** Answer a message which was not dispatched and is not listed in any queue.
196
 *
198
 *
197
 * @param call      Call structure to be answered.
199
 * @param call      Call structure to be answered.
198
 */
200
 */
199
static void _ipc_answer_free_call(call_t *call)
201
static void _ipc_answer_free_call(call_t *call)
200
{
202
{
201
    answerbox_t *callerbox = call->callerbox;
203
    answerbox_t *callerbox = call->callerbox;
202
 
204
 
203
    call->flags |= IPC_CALL_ANSWERED;
205
    call->flags |= IPC_CALL_ANSWERED;
204
 
206
 
205
    if (call->flags & IPC_CALL_FORWARDED) {
207
    if (call->flags & IPC_CALL_FORWARDED) {
206
        if (call->caller_phone) {
208
        if (call->caller_phone) {
207
            /* Demasquerade the caller phone. */
209
            /* Demasquerade the caller phone. */
208
            call->data.phone = call->caller_phone;
210
            call->data.phone = call->caller_phone;
209
        }
211
        }
210
    }
212
    }
211
 
213
 
212
    spinlock_lock(&callerbox->lock);
214
    spinlock_lock(&callerbox->lock);
213
    list_append(&call->link, &callerbox->answers);
215
    list_append(&call->link, &callerbox->answers);
214
    spinlock_unlock(&callerbox->lock);
216
    spinlock_unlock(&callerbox->lock);
215
    waitq_wakeup(&callerbox->wq, WAKEUP_FIRST);
217
    waitq_wakeup(&callerbox->wq, WAKEUP_FIRST);
216
}
218
}
217
 
219
 
218
/** Answer a message which is in a callee queue.
220
/** Answer a message which is in a callee queue.
219
 *
221
 *
220
 * @param box       Answerbox that is answering the message.
222
 * @param box       Answerbox that is answering the message.
221
 * @param call      Modified request that is being sent back.
223
 * @param call      Modified request that is being sent back.
222
 */
224
 */
223
void ipc_answer(answerbox_t *box, call_t *call)
225
void ipc_answer(answerbox_t *box, call_t *call)
224
{
226
{
225
    /* Remove from active box */
227
    /* Remove from active box */
226
    spinlock_lock(&box->lock);
228
    spinlock_lock(&box->lock);
227
    list_remove(&call->link);
229
    list_remove(&call->link);
228
    spinlock_unlock(&box->lock);
230
    spinlock_unlock(&box->lock);
229
    /* Send back answer */
231
    /* Send back answer */
230
    _ipc_answer_free_call(call);
232
    _ipc_answer_free_call(call);
231
}
233
}
232
 
234
 
233
/** Simulate sending back a message.
235
/** Simulate sending back a message.
234
 *
236
 *
235
 * Most errors are better handled by forming a normal backward
237
 * Most errors are better handled by forming a normal backward
236
 * message and sending it as a normal answer.
238
 * message and sending it as a normal answer.
237
 *
239
 *
238
 * @param phone     Phone structure the call should appear to come from.
240
 * @param phone     Phone structure the call should appear to come from.
239
 * @param call      Call structure to be answered.
241
 * @param call      Call structure to be answered.
240
 * @param err       Return value to be used for the answer.
242
 * @param err       Return value to be used for the answer.
241
 */
243
 */
242
void ipc_backsend_err(phone_t *phone, call_t *call, unative_t err)
244
void ipc_backsend_err(phone_t *phone, call_t *call, unative_t err)
243
{
245
{
244
    call->data.phone = phone;
246
    call->data.phone = phone;
245
    atomic_inc(&phone->active_calls);
247
    atomic_inc(&phone->active_calls);
246
    IPC_SET_RETVAL(call->data, err);
248
    IPC_SET_RETVAL(call->data, err);
247
    _ipc_answer_free_call(call);
249
    _ipc_answer_free_call(call);
248
}
250
}
249
 
251
 
250
/** Unsafe unchecking version of ipc_call.
252
/** Unsafe unchecking version of ipc_call.
251
 *
253
 *
252
 * @param phone     Phone structure the call comes from.
254
 * @param phone     Phone structure the call comes from.
253
 * @param box       Destination answerbox structure.
255
 * @param box       Destination answerbox structure.
254
 * @param call      Call structure with request.
256
 * @param call      Call structure with request.
255
 */
257
 */
256
static void _ipc_call(phone_t *phone, answerbox_t *box, call_t *call)
258
static void _ipc_call(phone_t *phone, answerbox_t *box, call_t *call)
257
{
259
{
258
    if (!(call->flags & IPC_CALL_FORWARDED)) {
260
    if (!(call->flags & IPC_CALL_FORWARDED)) {
259
        atomic_inc(&phone->active_calls);
261
        atomic_inc(&phone->active_calls);
260
        call->data.phone = phone;
262
        call->data.phone = phone;
261
    }
263
    }
262
 
264
 
263
    spinlock_lock(&box->lock);
265
    spinlock_lock(&box->lock);
264
    list_append(&call->link, &box->calls);
266
    list_append(&call->link, &box->calls);
265
    spinlock_unlock(&box->lock);
267
    spinlock_unlock(&box->lock);
266
    waitq_wakeup(&box->wq, WAKEUP_FIRST);
268
    waitq_wakeup(&box->wq, WAKEUP_FIRST);
267
}
269
}
268
 
270
 
269
/** Send an asynchronous request using a phone to an answerbox.
271
/** Send an asynchronous request using a phone to an answerbox.
270
 *
272
 *
271
 * @param phone     Phone structure the call comes from and which is
273
 * @param phone     Phone structure the call comes from and which is
272
 *          connected to the destination answerbox.
274
 *          connected to the destination answerbox.
273
 * @param call      Call structure with request.
275
 * @param call      Call structure with request.
274
 *
276
 *
275
 * @return      Return 0 on success, ENOENT on error.
277
 * @return      Return 0 on success, ENOENT on error.
276
 */
278
 */
277
int ipc_call(phone_t *phone, call_t *call)
279
int ipc_call(phone_t *phone, call_t *call)
278
{
280
{
279
    answerbox_t *box;
281
    answerbox_t *box;
280
 
282
 
281
    mutex_lock(&phone->lock);
283
    mutex_lock(&phone->lock);
282
    if (phone->state != IPC_PHONE_CONNECTED) {
284
    if (phone->state != IPC_PHONE_CONNECTED) {
283
        mutex_unlock(&phone->lock);
285
        mutex_unlock(&phone->lock);
284
        if (call->flags & IPC_CALL_FORWARDED) {
286
        if (call->flags & IPC_CALL_FORWARDED) {
285
            IPC_SET_RETVAL(call->data, EFORWARD);
287
            IPC_SET_RETVAL(call->data, EFORWARD);
286
            _ipc_answer_free_call(call);
288
            _ipc_answer_free_call(call);
287
        } else {
289
        } else {
288
            if (phone->state == IPC_PHONE_HUNGUP)
290
            if (phone->state == IPC_PHONE_HUNGUP)
289
                ipc_backsend_err(phone, call, EHANGUP);
291
                ipc_backsend_err(phone, call, EHANGUP);
290
            else
292
            else
291
                ipc_backsend_err(phone, call, ENOENT);
293
                ipc_backsend_err(phone, call, ENOENT);
292
        }
294
        }
293
        return ENOENT;
295
        return ENOENT;
294
    }
296
    }
295
    box = phone->callee;
297
    box = phone->callee;
296
    _ipc_call(phone, box, call);
298
    _ipc_call(phone, box, call);
297
   
299
   
298
    mutex_unlock(&phone->lock);
300
    mutex_unlock(&phone->lock);
299
    return 0;
301
    return 0;
300
}
302
}
301
 
303
 
302
/** Disconnect phone from answerbox.
304
/** Disconnect phone from answerbox.
303
 *
305
 *
304
 * This call leaves the phone in the HUNGUP state. The change to 'free' is done
306
 * This call leaves the phone in the HUNGUP state. The change to 'free' is done
305
 * lazily later.
307
 * lazily later.
306
 *
308
 *
307
 * @param phone     Phone structure to be hung up.
309
 * @param phone     Phone structure to be hung up.
308
 *              
310
 *              
309
 * @return      Return 0 if the phone is disconnected.
311
 * @return      Return 0 if the phone is disconnected.
310
 *          Return -1 if the phone was already disconnected.
312
 *          Return -1 if the phone was already disconnected.
311
 */
313
 */
312
int ipc_phone_hangup(phone_t *phone)
314
int ipc_phone_hangup(phone_t *phone)
313
{
315
{
314
    answerbox_t *box;
316
    answerbox_t *box;
315
    call_t *call;
317
    call_t *call;
316
   
318
   
317
    mutex_lock(&phone->lock);
319
    mutex_lock(&phone->lock);
318
    if (phone->state == IPC_PHONE_FREE ||
320
    if (phone->state == IPC_PHONE_FREE ||
319
        phone->state == IPC_PHONE_HUNGUP ||
321
        phone->state == IPC_PHONE_HUNGUP ||
320
        phone->state == IPC_PHONE_CONNECTING) {
322
        phone->state == IPC_PHONE_CONNECTING) {
321
        mutex_unlock(&phone->lock);
323
        mutex_unlock(&phone->lock);
322
        return -1;
324
        return -1;
323
    }
325
    }
324
    box = phone->callee;
326
    box = phone->callee;
325
    if (phone->state != IPC_PHONE_SLAMMED) {
327
    if (phone->state != IPC_PHONE_SLAMMED) {
326
        /* Remove myself from answerbox */
328
        /* Remove myself from answerbox */
327
        spinlock_lock(&box->lock);
329
        spinlock_lock(&box->lock);
328
        list_remove(&phone->link);
330
        list_remove(&phone->link);
329
        spinlock_unlock(&box->lock);
331
        spinlock_unlock(&box->lock);
330
 
332
 
331
        if (phone->state != IPC_PHONE_SLAMMED) {
333
        if (phone->state != IPC_PHONE_SLAMMED) {
332
            call = ipc_call_alloc(0);
334
            call = ipc_call_alloc(0);
333
            IPC_SET_METHOD(call->data, IPC_M_PHONE_HUNGUP);
335
            IPC_SET_METHOD(call->data, IPC_M_PHONE_HUNGUP);
334
            call->flags |= IPC_CALL_DISCARD_ANSWER;
336
            call->flags |= IPC_CALL_DISCARD_ANSWER;
335
            _ipc_call(phone, box, call);
337
            _ipc_call(phone, box, call);
336
        }
338
        }
337
    }
339
    }
338
 
340
 
339
    phone->state = IPC_PHONE_HUNGUP;
341
    phone->state = IPC_PHONE_HUNGUP;
340
    mutex_unlock(&phone->lock);
342
    mutex_unlock(&phone->lock);
341
 
343
 
342
    return 0;
344
    return 0;
343
}
345
}
344
 
346
 
345
/** Forwards call from one answerbox to another one.
347
/** Forwards call from one answerbox to another one.
346
 *
348
 *
347
 * @param call      Call structure to be redirected.
349
 * @param call      Call structure to be redirected.
348
 * @param newphone  Phone structure to target answerbox.
350
 * @param newphone  Phone structure to target answerbox.
349
 * @param oldbox    Old answerbox structure.
351
 * @param oldbox    Old answerbox structure.
350
 * @param mode      Flags that specify mode of the forward operation.
352
 * @param mode      Flags that specify mode of the forward operation.
351
 *
353
 *
352
 * @return      Return 0 if forwarding succeeded or an error code if
354
 * @return      Return 0 if forwarding succeeded or an error code if
353
 *          there was error.
355
 *          there was error.
354
 *
356
 *
355
 * The return value serves only as an information for the forwarder,
357
 * The return value serves only as an information for the forwarder,
356
 * the original caller is notified automatically with EFORWARD.
358
 * the original caller is notified automatically with EFORWARD.
357
 */
359
 */
358
int ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox, int mode)
360
int ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox, int mode)
359
{
361
{
360
    spinlock_lock(&oldbox->lock);
362
    spinlock_lock(&oldbox->lock);
361
    list_remove(&call->link);
363
    list_remove(&call->link);
362
    spinlock_unlock(&oldbox->lock);
364
    spinlock_unlock(&oldbox->lock);
363
 
365
 
364
    if (mode & IPC_FF_ROUTE_FROM_ME) {
366
    if (mode & IPC_FF_ROUTE_FROM_ME) {
365
        if (!call->caller_phone)
367
        if (!call->caller_phone)
366
            call->caller_phone = call->data.phone;
368
            call->caller_phone = call->data.phone;
367
        call->data.phone = newphone;
369
        call->data.phone = newphone;
368
    }
370
    }
369
 
371
 
370
    return ipc_call(newphone, call);
372
    return ipc_call(newphone, call);
371
}
373
}
372
 
374
 
373
 
375
 
374
/** Wait for a phone call.
376
/** Wait for a phone call.
375
 *
377
 *
376
 * @param box       Answerbox expecting the call.
378
 * @param box       Answerbox expecting the call.
377
 * @param usec      Timeout in microseconds. See documentation for
379
 * @param usec      Timeout in microseconds. See documentation for
378
 *          waitq_sleep_timeout() for decription of its special
380
 *          waitq_sleep_timeout() for decription of its special
379
 *          meaning.
381
 *          meaning.
380
 * @param flags     Select mode of sleep operation. See documentation for
382
 * @param flags     Select mode of sleep operation. See documentation for
381
 *          waitq_sleep_timeout() for description of its special
383
 *          waitq_sleep_timeout() for description of its special
382
 *          meaning.
384
 *          meaning.
383
 * @return      Recived call structure or NULL.
385
 * @return      Recived call structure or NULL.
384
 *
386
 *
385
 * To distinguish between a call and an answer, have a look at call->flags.
387
 * To distinguish between a call and an answer, have a look at call->flags.
386
 */
388
 */
387
call_t *ipc_wait_for_call(answerbox_t *box, uint32_t usec, int flags)
389
call_t *ipc_wait_for_call(answerbox_t *box, uint32_t usec, int flags)
388
{
390
{
389
    call_t *request;
391
    call_t *request;
390
    ipl_t ipl;
392
    ipl_t ipl;
391
    int rc;
393
    int rc;
392
 
394
 
393
restart:
395
restart:
394
    rc = waitq_sleep_timeout(&box->wq, usec, flags);
396
    rc = waitq_sleep_timeout(&box->wq, usec, flags);
395
    if (SYNCH_FAILED(rc))
397
    if (SYNCH_FAILED(rc))
396
        return NULL;
398
        return NULL;
397
   
399
   
398
    spinlock_lock(&box->lock);
400
    spinlock_lock(&box->lock);
399
    if (!list_empty(&box->irq_notifs)) {
401
    if (!list_empty(&box->irq_notifs)) {
400
        ipl = interrupts_disable();
402
        ipl = interrupts_disable();
401
        spinlock_lock(&box->irq_lock);
403
        spinlock_lock(&box->irq_lock);
402
 
404
 
403
        request = list_get_instance(box->irq_notifs.next, call_t, link);
405
        request = list_get_instance(box->irq_notifs.next, call_t, link);
404
        list_remove(&request->link);
406
        list_remove(&request->link);
405
 
407
 
406
        spinlock_unlock(&box->irq_lock);
408
        spinlock_unlock(&box->irq_lock);
407
        interrupts_restore(ipl);
409
        interrupts_restore(ipl);
408
    } else if (!list_empty(&box->answers)) {
410
    } else if (!list_empty(&box->answers)) {
409
        /* Handle asynchronous answers */
411
        /* Handle asynchronous answers */
410
        request = list_get_instance(box->answers.next, call_t, link);
412
        request = list_get_instance(box->answers.next, call_t, link);
411
        list_remove(&request->link);
413
        list_remove(&request->link);
412
        atomic_dec(&request->data.phone->active_calls);
414
        atomic_dec(&request->data.phone->active_calls);
413
    } else if (!list_empty(&box->calls)) {
415
    } else if (!list_empty(&box->calls)) {
414
        /* Handle requests */
416
        /* Handle requests */
415
        request = list_get_instance(box->calls.next, call_t, link);
417
        request = list_get_instance(box->calls.next, call_t, link);
416
        list_remove(&request->link);
418
        list_remove(&request->link);
417
        /* Append request to dispatch queue */
419
        /* Append request to dispatch queue */
418
        list_append(&request->link, &box->dispatched_calls);
420
        list_append(&request->link, &box->dispatched_calls);
419
    } else {
421
    } else {
420
        /* This can happen regularly after ipc_cleanup */
422
        /* This can happen regularly after ipc_cleanup */
421
        spinlock_unlock(&box->lock);
423
        spinlock_unlock(&box->lock);
422
        goto restart;
424
        goto restart;
423
    }
425
    }
424
    spinlock_unlock(&box->lock);
426
    spinlock_unlock(&box->lock);
425
    return request;
427
    return request;
426
}
428
}
427
 
429
 
428
/** Answer all calls from list with EHANGUP answer.
430
/** Answer all calls from list with EHANGUP answer.
429
 *
431
 *
430
 * @param lst       Head of the list to be cleaned up.
432
 * @param lst       Head of the list to be cleaned up.
431
 */
433
 */
432
void ipc_cleanup_call_list(link_t *lst)
434
void ipc_cleanup_call_list(link_t *lst)
433
{
435
{
434
    call_t *call;
436
    call_t *call;
435
 
437
 
436
    while (!list_empty(lst)) {
438
    while (!list_empty(lst)) {
437
        call = list_get_instance(lst->next, call_t, link);
439
        call = list_get_instance(lst->next, call_t, link);
438
        if (call->buffer)
440
        if (call->buffer)
439
            free(call->buffer);
441
            free(call->buffer);
440
        list_remove(&call->link);
442
        list_remove(&call->link);
441
 
443
 
442
        IPC_SET_RETVAL(call->data, EHANGUP);
444
        IPC_SET_RETVAL(call->data, EHANGUP);
443
        _ipc_answer_free_call(call);
445
        _ipc_answer_free_call(call);
444
    }
446
    }
445
}
447
}
446
 
448
 
447
/** Disconnects all phones connected to an answerbox.
449
/** Disconnects all phones connected to an answerbox.
448
 *
450
 *
449
 * @param box       Answerbox to disconnect phones from.
451
 * @param box       Answerbox to disconnect phones from.
450
 * @param notify_box    If true, the answerbox will get a hangup message for
452
 * @param notify_box    If true, the answerbox will get a hangup message for
451
 *          each disconnected phone.
453
 *          each disconnected phone.
452
 */
454
 */
453
void ipc_answerbox_slam_phones(answerbox_t *box, bool notify_box)
455
void ipc_answerbox_slam_phones(answerbox_t *box, bool notify_box)
454
{
456
{
455
    phone_t *phone;
457
    phone_t *phone;
456
    DEADLOCK_PROBE_INIT(p_phonelck);
458
    DEADLOCK_PROBE_INIT(p_phonelck);
457
    ipl_t ipl;
459
    ipl_t ipl;
458
    call_t *call;
460
    call_t *call;
459
 
461
 
460
    call = notify_box ? ipc_call_alloc(0) : NULL;
462
    call = notify_box ? ipc_call_alloc(0) : NULL;
461
 
463
 
462
    /* Disconnect all phones connected to our answerbox */
464
    /* Disconnect all phones connected to our answerbox */
463
restart_phones:
465
restart_phones:
464
    ipl = interrupts_disable();
466
    ipl = interrupts_disable();
465
    spinlock_lock(&box->lock);
467
    spinlock_lock(&box->lock);
466
    while (!list_empty(&box->connected_phones)) {
468
    while (!list_empty(&box->connected_phones)) {
467
        phone = list_get_instance(box->connected_phones.next,
469
        phone = list_get_instance(box->connected_phones.next,
468
            phone_t, link);
470
            phone_t, link);
469
        if (SYNCH_FAILED(mutex_trylock(&phone->lock))) {
471
        if (SYNCH_FAILED(mutex_trylock(&phone->lock))) {
470
            spinlock_unlock(&box->lock);
472
            spinlock_unlock(&box->lock);
471
            interrupts_restore(ipl);
473
            interrupts_restore(ipl);
472
            DEADLOCK_PROBE(p_phonelck, DEADLOCK_THRESHOLD);
474
            DEADLOCK_PROBE(p_phonelck, DEADLOCK_THRESHOLD);
473
            goto restart_phones;
475
            goto restart_phones;
474
        }
476
        }
475
       
477
       
476
        /* Disconnect phone */
478
        /* Disconnect phone */
477
        ASSERT(phone->state == IPC_PHONE_CONNECTED);
479
        ASSERT(phone->state == IPC_PHONE_CONNECTED);
478
 
480
 
479
        list_remove(&phone->link);
481
        list_remove(&phone->link);
480
        phone->state = IPC_PHONE_SLAMMED;
482
        phone->state = IPC_PHONE_SLAMMED;
481
 
483
 
482
        if (notify_box) {
484
        if (notify_box) {
483
            mutex_unlock(&phone->lock);
485
            mutex_unlock(&phone->lock);
484
            spinlock_unlock(&box->lock);
486
            spinlock_unlock(&box->lock);
485
            interrupts_restore(ipl);
487
            interrupts_restore(ipl);
486
 
488
 
487
            /*
489
            /*
488
             * Send one message to the answerbox for each
490
             * Send one message to the answerbox for each
489
             * phone. Used to make sure the kbox thread
491
             * phone. Used to make sure the kbox thread
490
             * wakes up after the last phone has been
492
             * wakes up after the last phone has been
491
             * disconnected.
493
             * disconnected.
492
             */
494
             */
493
            IPC_SET_METHOD(call->data, IPC_M_PHONE_HUNGUP);
495
            IPC_SET_METHOD(call->data, IPC_M_PHONE_HUNGUP);
494
            call->flags |= IPC_CALL_DISCARD_ANSWER;
496
            call->flags |= IPC_CALL_DISCARD_ANSWER;
495
            _ipc_call(phone, box, call);
497
            _ipc_call(phone, box, call);
496
 
498
 
497
            /* Allocate another call in advance */
499
            /* Allocate another call in advance */
498
            call = ipc_call_alloc(0);
500
            call = ipc_call_alloc(0);
499
 
501
 
500
            /* Must start again */
502
            /* Must start again */
501
            goto restart_phones;
503
            goto restart_phones;
502
        }
504
        }
503
 
505
 
504
        mutex_unlock(&phone->lock);
506
        mutex_unlock(&phone->lock);
505
    }
507
    }
506
 
508
 
507
    spinlock_unlock(&box->lock);
509
    spinlock_unlock(&box->lock);
508
    interrupts_restore(ipl);
510
    interrupts_restore(ipl);
509
 
511
 
510
    /* Free unused call */
512
    /* Free unused call */
511
    if (call)
513
    if (call)
512
        ipc_call_free(call);
514
        ipc_call_free(call);
513
}
515
}
514
 
516
 
515
/** Cleans up all IPC communication of the current task.
517
/** Cleans up all IPC communication of the current task.
516
 *
518
 *
517
 * Note: ipc_hangup sets returning answerbox to TASK->answerbox, you
519
 * Note: ipc_hangup sets returning answerbox to TASK->answerbox, you
518
 * have to change it as well if you want to cleanup other tasks than TASK.
520
 * have to change it as well if you want to cleanup other tasks than TASK.
519
 */
521
 */
520
void ipc_cleanup(void)
522
void ipc_cleanup(void)
521
{
523
{
522
    int i;
524
    int i;
523
    call_t *call;
525
    call_t *call;
524
 
526
 
525
    /* Disconnect all our phones ('ipc_phone_hangup') */
527
    /* Disconnect all our phones ('ipc_phone_hangup') */
526
    for (i = 0; i < IPC_MAX_PHONES; i++)
528
    for (i = 0; i < IPC_MAX_PHONES; i++)
527
        ipc_phone_hangup(&TASK->phones[i]);
529
        ipc_phone_hangup(&TASK->phones[i]);
528
 
530
 
-
 
531
    /* Unsubscribe from any event notifications. */
-
 
532
    event_cleanup_answerbox(&TASK->answerbox);
-
 
533
 
529
    /* Disconnect all connected irqs */
534
    /* Disconnect all connected irqs */
530
    ipc_irq_cleanup(&TASK->answerbox);
535
    ipc_irq_cleanup(&TASK->answerbox);
531
 
536
 
532
    /* Disconnect all phones connected to our regular answerbox */
537
    /* Disconnect all phones connected to our regular answerbox */
533
    ipc_answerbox_slam_phones(&TASK->answerbox, false);
538
    ipc_answerbox_slam_phones(&TASK->answerbox, false);
534
 
539
 
535
#ifdef CONFIG_UDEBUG
540
#ifdef CONFIG_UDEBUG
536
    /* Clean up kbox thread and communications */
541
    /* Clean up kbox thread and communications */
537
    ipc_kbox_cleanup();
542
    ipc_kbox_cleanup();
538
#endif
543
#endif
539
 
544
 
540
    /* Answer all messages in 'calls' and 'dispatched_calls' queues */
545
    /* Answer all messages in 'calls' and 'dispatched_calls' queues */
541
    spinlock_lock(&TASK->answerbox.lock);
546
    spinlock_lock(&TASK->answerbox.lock);
542
    ipc_cleanup_call_list(&TASK->answerbox.dispatched_calls);
547
    ipc_cleanup_call_list(&TASK->answerbox.dispatched_calls);
543
    ipc_cleanup_call_list(&TASK->answerbox.calls);
548
    ipc_cleanup_call_list(&TASK->answerbox.calls);
544
    spinlock_unlock(&TASK->answerbox.lock);
549
    spinlock_unlock(&TASK->answerbox.lock);
545
   
550
   
546
    /* Wait for all async answers to arrive */
551
    /* Wait for all async answers to arrive */
547
    while (1) {
552
    while (1) {
548
        /* Go through all phones, until all are FREE... */
553
        /* Go through all phones, until all are FREE... */
549
        /* Locking not needed, no one else should modify
554
        /* Locking not needed, no one else should modify
550
         * it, when we are in cleanup */
555
         * it, when we are in cleanup */
551
        for (i = 0; i < IPC_MAX_PHONES; i++) {
556
        for (i = 0; i < IPC_MAX_PHONES; i++) {
552
            if (TASK->phones[i].state == IPC_PHONE_HUNGUP &&
557
            if (TASK->phones[i].state == IPC_PHONE_HUNGUP &&
553
                atomic_get(&TASK->phones[i].active_calls) == 0)
558
                atomic_get(&TASK->phones[i].active_calls) == 0)
554
                TASK->phones[i].state = IPC_PHONE_FREE;
559
                TASK->phones[i].state = IPC_PHONE_FREE;
555
           
560
           
556
            /* Just for sure, we might have had some
561
            /* Just for sure, we might have had some
557
             * IPC_PHONE_CONNECTING phones */
562
             * IPC_PHONE_CONNECTING phones */
558
            if (TASK->phones[i].state == IPC_PHONE_CONNECTED)
563
            if (TASK->phones[i].state == IPC_PHONE_CONNECTED)
559
                ipc_phone_hangup(&TASK->phones[i]);
564
                ipc_phone_hangup(&TASK->phones[i]);
560
            /* If the hangup succeeded, it has sent a HANGUP
565
            /* If the hangup succeeded, it has sent a HANGUP
561
             * message, the IPC is now in HUNGUP state, we
566
             * message, the IPC is now in HUNGUP state, we
562
             * wait for the reply to come */
567
             * wait for the reply to come */
563
           
568
           
564
            if (TASK->phones[i].state != IPC_PHONE_FREE)
569
            if (TASK->phones[i].state != IPC_PHONE_FREE)
565
                break;
570
                break;
566
        }
571
        }
567
        /* Voila, got into cleanup */
572
        /* Voila, got into cleanup */
568
        if (i == IPC_MAX_PHONES)
573
        if (i == IPC_MAX_PHONES)
569
            break;
574
            break;
570
       
575
       
571
        call = ipc_wait_for_call(&TASK->answerbox, SYNCH_NO_TIMEOUT,
576
        call = ipc_wait_for_call(&TASK->answerbox, SYNCH_NO_TIMEOUT,
572
            SYNCH_FLAGS_NONE);
577
            SYNCH_FLAGS_NONE);
573
        ASSERT((call->flags & IPC_CALL_ANSWERED) ||
578
        ASSERT((call->flags & IPC_CALL_ANSWERED) ||
574
            (call->flags & IPC_CALL_NOTIF));
579
            (call->flags & IPC_CALL_NOTIF));
575
        ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
580
        ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
576
       
581
       
577
        /*
582
        /*
578
         * Record the receipt of this call in the current task's counter
583
         * Record the receipt of this call in the current task's counter
579
         * of active calls. IPC_M_PHONE_HUNGUP calls do not contribute
584
         * of active calls. IPC_M_PHONE_HUNGUP calls do not contribute
580
         * to this counter so do not record answers to them either.
585
         * to this counter so do not record answers to them either.
581
         */
586
         */
582
        if (!(call->flags & IPC_CALL_DISCARD_ANSWER))
587
        if (!(call->flags & IPC_CALL_DISCARD_ANSWER))
583
            atomic_dec(&TASK->active_calls);
588
            atomic_dec(&TASK->active_calls);
584
        ipc_call_free(call);
589
        ipc_call_free(call);
585
    }
590
    }
586
}
591
}
587
 
592
 
588
 
593
 
589
/** Initilize IPC subsystem */
594
/** Initilize IPC subsystem */
590
void ipc_init(void)
595
void ipc_init(void)
591
{
596
{
592
    ipc_call_slab = slab_cache_create("ipc_call", sizeof(call_t), 0, NULL,
597
    ipc_call_slab = slab_cache_create("ipc_call", sizeof(call_t), 0, NULL,
593
        NULL, 0);
598
        NULL, 0);
594
}
599
}
595
 
600
 
596
 
601
 
597
/** List answerbox contents.
602
/** List answerbox contents.
598
 *
603
 *
599
 * @param taskid    Task ID.
604
 * @param taskid    Task ID.
600
 */
605
 */
601
void ipc_print_task(task_id_t taskid)
606
void ipc_print_task(task_id_t taskid)
602
{
607
{
603
    task_t *task;
608
    task_t *task;
604
    int i;
609
    int i;
605
    call_t *call;
610
    call_t *call;
606
    link_t *tmp;
611
    link_t *tmp;
607
   
612
   
608
    spinlock_lock(&tasks_lock);
613
    spinlock_lock(&tasks_lock);
609
    task = task_find_by_id(taskid);
614
    task = task_find_by_id(taskid);
610
    if (task)
615
    if (task)
611
        spinlock_lock(&task->lock);
616
        spinlock_lock(&task->lock);
612
    spinlock_unlock(&tasks_lock);
617
    spinlock_unlock(&tasks_lock);
613
    if (!task)
618
    if (!task)
614
        return;
619
        return;
615
 
620
 
616
    /* Print opened phones & details */
621
    /* Print opened phones & details */
617
    printf("PHONE:\n");
622
    printf("PHONE:\n");
618
    for (i = 0; i < IPC_MAX_PHONES; i++) {
623
    for (i = 0; i < IPC_MAX_PHONES; i++) {
619
        if (SYNCH_FAILED(mutex_trylock(&task->phones[i].lock))) {
624
        if (SYNCH_FAILED(mutex_trylock(&task->phones[i].lock))) {
620
            printf("%d: mutex busy\n", i);
625
            printf("%d: mutex busy\n", i);
621
            continue;
626
            continue;
622
        }
627
        }
623
        if (task->phones[i].state != IPC_PHONE_FREE) {
628
        if (task->phones[i].state != IPC_PHONE_FREE) {
624
            printf("%d: ", i);
629
            printf("%d: ", i);
625
            switch (task->phones[i].state) {
630
            switch (task->phones[i].state) {
626
            case IPC_PHONE_CONNECTING:
631
            case IPC_PHONE_CONNECTING:
627
                printf("connecting ");
632
                printf("connecting ");
628
                break;
633
                break;
629
            case IPC_PHONE_CONNECTED:
634
            case IPC_PHONE_CONNECTED:
630
                printf("connected to: %p ",
635
                printf("connected to: %p ",
631
                       task->phones[i].callee);
636
                       task->phones[i].callee);
632
                break;
637
                break;
633
            case IPC_PHONE_SLAMMED:
638
            case IPC_PHONE_SLAMMED:
634
                printf("slammed by: %p ",
639
                printf("slammed by: %p ",
635
                       task->phones[i].callee);
640
                       task->phones[i].callee);
636
                break;
641
                break;
637
            case IPC_PHONE_HUNGUP:
642
            case IPC_PHONE_HUNGUP:
638
                printf("hung up - was: %p ",
643
                printf("hung up - was: %p ",
639
                       task->phones[i].callee);
644
                       task->phones[i].callee);
640
                break;
645
                break;
641
            default:
646
            default:
642
                break;
647
                break;
643
            }
648
            }
644
            printf("active: %ld\n",
649
            printf("active: %ld\n",
645
                atomic_get(&task->phones[i].active_calls));
650
                atomic_get(&task->phones[i].active_calls));
646
        }
651
        }
647
        mutex_unlock(&task->phones[i].lock);
652
        mutex_unlock(&task->phones[i].lock);
648
    }
653
    }
649
 
654
 
650
 
655
 
651
    /* Print answerbox - calls */
656
    /* Print answerbox - calls */
652
    spinlock_lock(&task->answerbox.lock);
657
    spinlock_lock(&task->answerbox.lock);
653
    printf("ABOX - CALLS:\n");
658
    printf("ABOX - CALLS:\n");
654
    for (tmp = task->answerbox.calls.next; tmp != &task->answerbox.calls;
659
    for (tmp = task->answerbox.calls.next; tmp != &task->answerbox.calls;
655
        tmp = tmp->next) {
660
        tmp = tmp->next) {
656
        call = list_get_instance(tmp, call_t, link);
661
        call = list_get_instance(tmp, call_t, link);
657
        printf("Callid: %p Srctask:%" PRIu64 " M:%" PRIun
662
        printf("Callid: %p Srctask:%" PRIu64 " M:%" PRIun
658
            " A1:%" PRIun " A2:%" PRIun " A3:%" PRIun
663
            " A1:%" PRIun " A2:%" PRIun " A3:%" PRIun
659
            " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", call,
664
            " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", call,
660
            call->sender->taskid,
665
            call->sender->taskid,
661
            IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data),
666
            IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data),
662
            IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
667
            IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
663
            IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
668
            IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
664
            call->flags);
669
            call->flags);
665
    }
670
    }
666
    /* Print answerbox - calls */
671
    /* Print answerbox - calls */
667
    printf("ABOX - DISPATCHED CALLS:\n");
672
    printf("ABOX - DISPATCHED CALLS:\n");
668
    for (tmp = task->answerbox.dispatched_calls.next;
673
    for (tmp = task->answerbox.dispatched_calls.next;
669
        tmp != &task->answerbox.dispatched_calls;
674
        tmp != &task->answerbox.dispatched_calls;
670
        tmp = tmp->next) {
675
        tmp = tmp->next) {
671
        call = list_get_instance(tmp, call_t, link);
676
        call = list_get_instance(tmp, call_t, link);
672
        printf("Callid: %p Srctask:%" PRIu64 " M:%" PRIun
677
        printf("Callid: %p Srctask:%" PRIu64 " M:%" PRIun
673
            " A1:%" PRIun " A2:%" PRIun " A3:%" PRIun
678
            " A1:%" PRIun " A2:%" PRIun " A3:%" PRIun
674
            " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", call,
679
            " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", call,
675
            call->sender->taskid,
680
            call->sender->taskid,
676
            IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data),
681
            IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data),
677
            IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
682
            IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
678
            IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
683
            IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
679
            call->flags);
684
            call->flags);
680
    }
685
    }
681
    /* Print answerbox - calls */
686
    /* Print answerbox - calls */
682
    printf("ABOX - ANSWERS:\n");
687
    printf("ABOX - ANSWERS:\n");
683
    for (tmp = task->answerbox.answers.next;
688
    for (tmp = task->answerbox.answers.next;
684
        tmp != &task->answerbox.answers;
689
        tmp != &task->answerbox.answers;
685
        tmp = tmp->next) {
690
        tmp = tmp->next) {
686
        call = list_get_instance(tmp, call_t, link);
691
        call = list_get_instance(tmp, call_t, link);
687
        printf("Callid:%p M:%" PRIun " A1:%" PRIun " A2:%" PRIun
692
        printf("Callid:%p M:%" PRIun " A1:%" PRIun " A2:%" PRIun
688
            " A3:%" PRIun " A4:%" PRIun " A5:%" PRIun " Flags:%x\n",
693
            " A3:%" PRIun " A4:%" PRIun " A5:%" PRIun " Flags:%x\n",
689
            call, IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data),
694
            call, IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data),
690
            IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
695
            IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
691
            IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
696
            IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
692
            call->flags);
697
            call->flags);
693
    }
698
    }
694
 
699
 
695
    spinlock_unlock(&task->answerbox.lock);
700
    spinlock_unlock(&task->answerbox.lock);
696
    spinlock_unlock(&task->lock);
701
    spinlock_unlock(&task->lock);
697
}
702
}
698
 
703
 
699
/** @}
704
/** @}
700
 */
705
 */
701
 
706