Subversion Repositories HelenOS

Rev

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

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