Subversion Repositories HelenOS

Rev

Rev 4348 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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