Subversion Repositories HelenOS

Rev

Rev 2471 | Rev 2494 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
955 palkovsky 1
/*
2071 jermar 2
 * Copyright (c) 2006 Ondrej Palkovsky
955 palkovsky 3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
1757 jermar 29
/** @addtogroup genericipc
1702 cejka 30
 * @{
31
 */
32
/** @file
33
 */
34
 
955 palkovsky 35
/* Lock ordering
36
 *
2471 jermar 37
 * First the answerbox, then the phone.
955 palkovsky 38
 */
39
 
1040 palkovsky 40
#include <synch/spinlock.h>
41
#include <synch/waitq.h>
1364 jermar 42
#include <synch/synch.h>
955 palkovsky 43
#include <ipc/ipc.h>
44
#include <errno.h>
45
#include <mm/slab.h>
46
#include <arch.h>
47
#include <proc/task.h>
48
#include <memstr.h>
49
#include <debug.h>
50
 
51
#include <print.h>
52
#include <proc/thread.h>
1258 palkovsky 53
#include <arch/interrupt.h>
1281 palkovsky 54
#include <ipc/irq.h>
955 palkovsky 55
 
2471 jermar 56
/** Open channel that is assigned automatically to new tasks */
965 palkovsky 57
answerbox_t *ipc_phone_0 = NULL;
955 palkovsky 58
 
59
static slab_cache_t *ipc_call_slab;
60
 
2471 jermar 61
/** Initialize a call structure.
62
 *
63
 * @param call      Call structure to be initialized.
64
 */
1084 palkovsky 65
static void _ipc_call_init(call_t *call)
66
{
2471 jermar 67
    memsetb((uintptr_t) call, sizeof(*call), 0);
1084 palkovsky 68
    call->callerbox = &TASK->answerbox;
69
    call->sender = TASK;
70
}
71
 
2471 jermar 72
/** Allocate and initialize a call structure.
955 palkovsky 73
 *
2471 jermar 74
 * The call is initialized, so that the reply will be directed to
75
 * TASK->answerbox.
1258 palkovsky 76
 *
2471 jermar 77
 * @param flags     Parameters for slab_alloc (e.g FRAME_ATOMIC).
78
 *
79
 * @return      If flags permit it, return NULL, or initialized kernel
80
 *          call structure.
955 palkovsky 81
 */
2471 jermar 82
call_t *ipc_call_alloc(int flags)
955 palkovsky 83
{
84
    call_t *call;
85
 
1258 palkovsky 86
    call = slab_alloc(ipc_call_slab, flags);
1084 palkovsky 87
    _ipc_call_init(call);
955 palkovsky 88
 
89
    return call;
90
}
91
 
2471 jermar 92
/** Initialize a statically allocated call structure.
93
 *
94
 * @param call      Statically allocated kernel call structure to be
95
 *          initialized.
96
 */
1084 palkovsky 97
void ipc_call_static_init(call_t *call)
965 palkovsky 98
{
1084 palkovsky 99
    _ipc_call_init(call);
100
    call->flags |= IPC_CALL_STATIC_ALLOC;
965 palkovsky 101
}
102
 
2472 jermar 103
/** Deallocate a call structure.
2471 jermar 104
 *
105
 * @param call      Call structure to be freed.
106
 */
955 palkovsky 107
void ipc_call_free(call_t *call)
108
{
2471 jermar 109
    ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
955 palkovsky 110
    slab_free(ipc_call_slab, call);
111
}
112
 
2471 jermar 113
/** Initialize an answerbox structure.
114
 *
115
 * @param box       Answerbox structure to be initialized.
955 palkovsky 116
 */
117
void ipc_answerbox_init(answerbox_t *box)
118
{
1040 palkovsky 119
    spinlock_initialize(&box->lock, "ipc_box_lock");
1258 palkovsky 120
    spinlock_initialize(&box->irq_lock, "ipc_box_irqlock");
1040 palkovsky 121
    waitq_initialize(&box->wq);
955 palkovsky 122
    list_initialize(&box->connected_phones);
123
    list_initialize(&box->calls);
124
    list_initialize(&box->dispatched_calls);
125
    list_initialize(&box->answers);
1258 palkovsky 126
    list_initialize(&box->irq_notifs);
1933 jermar 127
    list_initialize(&box->irq_head);
1027 palkovsky 128
    box->task = TASK;
955 palkovsky 129
}
130
 
2471 jermar 131
/** Connect a phone to an answerbox.
132
 *
133
 * @param phone     Initialized phone structure.
134
 * @param box       Initialized answerbox structure.
135
 */
1040 palkovsky 136
void ipc_phone_connect(phone_t *phone, answerbox_t *box)
955 palkovsky 137
{
1084 palkovsky 138
    spinlock_lock(&phone->lock);
139
 
1568 palkovsky 140
    phone->state = IPC_PHONE_CONNECTED;
955 palkovsky 141
    phone->callee = box;
965 palkovsky 142
 
1040 palkovsky 143
    spinlock_lock(&box->lock);
1573 palkovsky 144
    list_append(&phone->link, &box->connected_phones);
1040 palkovsky 145
    spinlock_unlock(&box->lock);
1084 palkovsky 146
 
147
    spinlock_unlock(&phone->lock);
955 palkovsky 148
}
149
 
2471 jermar 150
/** Initialize a phone structure.
151
 *
152
 * @param phone     Phone structure to be initialized.
1040 palkovsky 153
 */
154
void ipc_phone_init(phone_t *phone)
155
{
156
    spinlock_initialize(&phone->lock, "phone_lock");
157
    phone->callee = NULL;
1568 palkovsky 158
    phone->state = IPC_PHONE_FREE;
1088 palkovsky 159
    atomic_set(&phone->active_calls, 0);
1040 palkovsky 160
}
161
 
2471 jermar 162
/** Helper function to facilitate synchronous calls.
163
 *
164
 * @param phone     Destination kernel phone structure.
165
 * @param request   Call structure with request.
166
 */
959 palkovsky 167
void ipc_call_sync(phone_t *phone, call_t *request)
168
{
169
    answerbox_t sync_box;
955 palkovsky 170
 
959 palkovsky 171
    ipc_answerbox_init(&sync_box);
172
 
2471 jermar 173
    /* We will receive data in a special box. */
959 palkovsky 174
    request->callerbox = &sync_box;
175
 
176
    ipc_call(phone, request);
1502 jermar 177
    ipc_wait_for_call(&sync_box, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
959 palkovsky 178
}
179
 
2471 jermar 180
/** Answer a message which was not dispatched and is not listed in any queue.
181
 *
182
 * @param call      Call structure to be answered.
1084 palkovsky 183
 */
184
static void _ipc_answer_free_call(call_t *call)
185
{
186
    answerbox_t *callerbox = call->callerbox;
187
 
188
    call->flags |= IPC_CALL_ANSWERED;
189
 
190
    spinlock_lock(&callerbox->lock);
1573 palkovsky 191
    list_append(&call->link, &callerbox->answers);
1084 palkovsky 192
    spinlock_unlock(&callerbox->lock);
2310 jermar 193
    waitq_wakeup(&callerbox->wq, WAKEUP_FIRST);
1084 palkovsky 194
}
195
 
2471 jermar 196
/** Answer a message which is in a callee queue.
1084 palkovsky 197
 *
2471 jermar 198
 * @param box       Answerbox that is answering the message.
199
 * @param call      Modified request that is being sent back.
1084 palkovsky 200
 */
201
void ipc_answer(answerbox_t *box, call_t *call)
202
{
203
    /* Remove from active box */
204
    spinlock_lock(&box->lock);
1573 palkovsky 205
    list_remove(&call->link);
1084 palkovsky 206
    spinlock_unlock(&box->lock);
207
    /* Send back answer */
208
    _ipc_answer_free_call(call);
209
}
210
 
2471 jermar 211
/** Simulate sending back a message.
1090 palkovsky 212
 *
213
 * Most errors are better handled by forming a normal backward
214
 * message and sending it as a normal answer.
2471 jermar 215
 *
216
 * @param phone     Phone structure the call should appear to come from.
217
 * @param call      Call structure to be answered.
218
 * @param err       Return value to be used for the answer.
1090 palkovsky 219
 */
1780 jermar 220
void ipc_backsend_err(phone_t *phone, call_t *call, unative_t err)
1090 palkovsky 221
{
222
    call->data.phone = phone;
223
    atomic_inc(&phone->active_calls);
1568 palkovsky 224
    IPC_SET_RETVAL(call->data, err);
1090 palkovsky 225
    _ipc_answer_free_call(call);
226
}
227
 
2471 jermar 228
/** Unsafe unchecking version of ipc_call.
229
 *
230
 * @param phone     Phone structure the call comes from.
231
 * @param box       Destination answerbox structure.
232
 */
1086 palkovsky 233
static void _ipc_call(phone_t *phone, answerbox_t *box, call_t *call)
234
{
2471 jermar 235
    if (!(call->flags & IPC_CALL_FORWARDED)) {
1088 palkovsky 236
        atomic_inc(&phone->active_calls);
237
        call->data.phone = phone;
238
    }
1086 palkovsky 239
 
240
    spinlock_lock(&box->lock);
1573 palkovsky 241
    list_append(&call->link, &box->calls);
1086 palkovsky 242
    spinlock_unlock(&box->lock);
2310 jermar 243
    waitq_wakeup(&box->wq, WAKEUP_FIRST);
1086 palkovsky 244
}
245
 
2471 jermar 246
/** Send an asynchronous request using a phone to an answerbox.
955 palkovsky 247
 *
2471 jermar 248
 * @param phone     Phone structure the call comes from and which is
249
 *          connected to the destination answerbox.
250
 * @param call      Call structure with request.
251
 *
252
 * @return      Return 0 on success, ENOENT on error.
955 palkovsky 253
 */
1088 palkovsky 254
int ipc_call(phone_t *phone, call_t *call)
955 palkovsky 255
{
1084 palkovsky 256
    answerbox_t *box;
955 palkovsky 257
 
1084 palkovsky 258
    spinlock_lock(&phone->lock);
1568 palkovsky 259
    if (phone->state != IPC_PHONE_CONNECTED) {
1086 palkovsky 260
        spinlock_unlock(&phone->lock);
1088 palkovsky 261
        if (call->flags & IPC_CALL_FORWARDED) {
262
            IPC_SET_RETVAL(call->data, EFORWARD);
1090 palkovsky 263
            _ipc_answer_free_call(call);
1568 palkovsky 264
        } else {
265
            if (phone->state == IPC_PHONE_HUNGUP)
1090 palkovsky 266
                ipc_backsend_err(phone, call, EHANGUP);
1088 palkovsky 267
            else
1090 palkovsky 268
                ipc_backsend_err(phone, call, ENOENT);
1088 palkovsky 269
        }
270
        return ENOENT;
1084 palkovsky 271
    }
1568 palkovsky 272
    box = phone->callee;
1086 palkovsky 273
    _ipc_call(phone, box, call);
274
 
275
    spinlock_unlock(&phone->lock);
1088 palkovsky 276
    return 0;
1086 palkovsky 277
}
955 palkovsky 278
 
2471 jermar 279
/** Disconnect phone from answerbox.
1086 palkovsky 280
 *
2471 jermar 281
 * This call leaves the phone in the HUNGUP state. The change to 'free' is done
1568 palkovsky 282
 * lazily later.
1086 palkovsky 283
 *
2471 jermar 284
 * @param phone     Phone structure to be hung up.
1568 palkovsky 285
 *              
2471 jermar 286
 * @return      Return 0 if the phone is disconnected.
287
 *          Return -1 if the phone was already disconnected.
1086 palkovsky 288
 */
1591 palkovsky 289
int ipc_phone_hangup(phone_t *phone)
1086 palkovsky 290
{
291
    answerbox_t *box;
292
    call_t *call;
293
 
294
    spinlock_lock(&phone->lock);
2471 jermar 295
    if (phone->state == IPC_PHONE_FREE || phone->state == IPC_PHONE_HUNGUP ||
296
        phone->state == IPC_PHONE_CONNECTING) {
1568 palkovsky 297
        spinlock_unlock(&phone->lock);
298
        return -1;
299
    }
1086 palkovsky 300
    box = phone->callee;
1568 palkovsky 301
    if (phone->state != IPC_PHONE_SLAMMED) {
302
        /* Remove myself from answerbox */
303
        spinlock_lock(&box->lock);
1573 palkovsky 304
        list_remove(&phone->link);
1568 palkovsky 305
        spinlock_unlock(&box->lock);
306
 
307
        if (phone->state != IPC_PHONE_SLAMMED) {
308
            call = ipc_call_alloc(0);
309
            IPC_SET_METHOD(call->data, IPC_M_PHONE_HUNGUP);
310
            call->flags |= IPC_CALL_DISCARD_ANSWER;
311
            _ipc_call(phone, box, call);
1088 palkovsky 312
        }
1086 palkovsky 313
    }
314
 
1568 palkovsky 315
    phone->state = IPC_PHONE_HUNGUP;
1084 palkovsky 316
    spinlock_unlock(&phone->lock);
1086 palkovsky 317
 
318
    return 0;
955 palkovsky 319
}
320
 
2471 jermar 321
/** Forwards call from one answerbox to another one.
1040 palkovsky 322
 *
2471 jermar 323
 * @param call      Call structure to be redirected.
324
 * @param newphone  Phone structure to target answerbox.
325
 * @param oldbox    Old answerbox structure.
326
 *
327
 * @return      Return 0 if forwarding succeeded or an error code if
328
 *          there was error.
1088 palkovsky 329
 *
2471 jermar 330
 * The return value serves only as an information for the forwarder,
331
 * the original caller is notified automatically with EFORWARD.
1040 palkovsky 332
 */
1088 palkovsky 333
int ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox)
1040 palkovsky 334
{
335
    spinlock_lock(&oldbox->lock);
1573 palkovsky 336
    list_remove(&call->link);
1040 palkovsky 337
    spinlock_unlock(&oldbox->lock);
338
 
1088 palkovsky 339
    return ipc_call(newphone, call);
1040 palkovsky 340
}
341
 
955 palkovsky 342
 
2471 jermar 343
/** Wait for a phone call.
955 palkovsky 344
 *
2471 jermar 345
 * @param box       Answerbox expecting the call.
346
 * @param usec      Timeout in microseconds. See documentation for
347
 *          waitq_sleep_timeout() for decription of its special
348
 *          meaning.
349
 * @param flags     Select mode of sleep operation. See documentation for
350
 *          waitq_sleep_timeout() for description of its special
351
 *          meaning.
352
 * @return      Recived call structure or NULL.
353
 *
354
 * To distinguish between a call and an answer, have a look at call->flags.
955 palkovsky 355
 */
2471 jermar 356
call_t *ipc_wait_for_call(answerbox_t *box, uint32_t usec, int flags)
955 palkovsky 357
{
358
    call_t *request;
1258 palkovsky 359
    ipl_t ipl;
1364 jermar 360
    int rc;
955 palkovsky 361
 
1364 jermar 362
restart:
1502 jermar 363
    rc = waitq_sleep_timeout(&box->wq, usec, flags);
1364 jermar 364
    if (SYNCH_FAILED(rc))
365
        return NULL;
1086 palkovsky 366
 
1040 palkovsky 367
    spinlock_lock(&box->lock);
1258 palkovsky 368
    if (!list_empty(&box->irq_notifs)) {
369
        ipl = interrupts_disable();
370
        spinlock_lock(&box->irq_lock);
371
 
1573 palkovsky 372
        request = list_get_instance(box->irq_notifs.next, call_t, link);
373
        list_remove(&request->link);
1258 palkovsky 374
 
375
        spinlock_unlock(&box->irq_lock);
376
        interrupts_restore(ipl);
377
    } else if (!list_empty(&box->answers)) {
1086 palkovsky 378
        /* Handle asynchronous answers */
1573 palkovsky 379
        request = list_get_instance(box->answers.next, call_t, link);
380
        list_remove(&request->link);
1086 palkovsky 381
        atomic_dec(&request->data.phone->active_calls);
382
    } else if (!list_empty(&box->calls)) {
383
        /* Handle requests */
1573 palkovsky 384
        request = list_get_instance(box->calls.next, call_t, link);
385
        list_remove(&request->link);
1086 palkovsky 386
        /* Append request to dispatch queue */
1573 palkovsky 387
        list_append(&request->link, &box->dispatched_calls);
1086 palkovsky 388
    } else {
1595 palkovsky 389
        /* This can happen regularly after ipc_cleanup */
1086 palkovsky 390
        spinlock_unlock(&box->lock);
391
        goto restart;
955 palkovsky 392
    }
1040 palkovsky 393
    spinlock_unlock(&box->lock);
955 palkovsky 394
    return request;
395
}
396
 
2471 jermar 397
/** Answer all calls from list with EHANGUP answer.
398
 *
399
 * @param lst       Head of the list to be cleaned up.
400
 */
1141 palkovsky 401
static void ipc_cleanup_call_list(link_t *lst)
402
{
403
    call_t *call;
404
 
405
    while (!list_empty(lst)) {
1573 palkovsky 406
        call = list_get_instance(lst->next, call_t, link);
407
        list_remove(&call->link);
1141 palkovsky 408
 
409
        IPC_SET_RETVAL(call->data, EHANGUP);
410
        _ipc_answer_free_call(call);
411
    }
412
}
413
 
2471 jermar 414
/** Cleans up all IPC communication of the current task.
1072 palkovsky 415
 *
1582 palkovsky 416
 * Note: ipc_hangup sets returning answerbox to TASK->answerbox, you
2471 jermar 417
 * have to change it as well if you want to cleanup other tasks than TASK.
1072 palkovsky 418
 */
1582 palkovsky 419
void ipc_cleanup(void)
1072 palkovsky 420
{
1088 palkovsky 421
    int i;
1141 palkovsky 422
    call_t *call;
423
    phone_t *phone;
2183 jermar 424
    DEADLOCK_PROBE_INIT(p_phonelck);
1582 palkovsky 425
 
1088 palkovsky 426
    /* Disconnect all our phones ('ipc_phone_hangup') */
2471 jermar 427
    for (i = 0; i < IPC_MAX_PHONES; i++)
1591 palkovsky 428
        ipc_phone_hangup(&TASK->phones[i]);
1088 palkovsky 429
 
1258 palkovsky 430
    /* Disconnect all connected irqs */
1582 palkovsky 431
    ipc_irq_cleanup(&TASK->answerbox);
1258 palkovsky 432
 
1141 palkovsky 433
    /* Disconnect all phones connected to our answerbox */
434
restart_phones:
1582 palkovsky 435
    spinlock_lock(&TASK->answerbox.lock);
436
    while (!list_empty(&TASK->answerbox.connected_phones)) {
437
        phone = list_get_instance(TASK->answerbox.connected_phones.next,
2183 jermar 438
            phone_t, link);
2472 jermar 439
        if (!spinlock_trylock(&phone->lock)) {
1582 palkovsky 440
            spinlock_unlock(&TASK->answerbox.lock);
2183 jermar 441
            DEADLOCK_PROBE(p_phonelck, DEADLOCK_THRESHOLD);
1141 palkovsky 442
            goto restart_phones;
443
        }
444
 
445
        /* Disconnect phone */
1568 palkovsky 446
        ASSERT(phone->state == IPC_PHONE_CONNECTED);
447
        phone->state = IPC_PHONE_SLAMMED;
1573 palkovsky 448
        list_remove(&phone->link);
1088 palkovsky 449
 
1141 palkovsky 450
        spinlock_unlock(&phone->lock);
451
    }
452
 
1088 palkovsky 453
    /* Answer all messages in 'calls' and 'dispatched_calls' queues */
1582 palkovsky 454
    ipc_cleanup_call_list(&TASK->answerbox.dispatched_calls);
455
    ipc_cleanup_call_list(&TASK->answerbox.calls);
456
    spinlock_unlock(&TASK->answerbox.lock);
1072 palkovsky 457
 
1088 palkovsky 458
    /* Wait for all async answers to arrive */
1568 palkovsky 459
    while (1) {
460
        /* Go through all phones, until all are FREE... */
461
        /* Locking not needed, no one else should modify
462
         * it, when we are in cleanup */
2471 jermar 463
        for (i = 0; i < IPC_MAX_PHONES; i++) {
464
            if (TASK->phones[i].state == IPC_PHONE_HUNGUP &&
1582 palkovsky 465
                atomic_get(&TASK->phones[i].active_calls) == 0)
466
                TASK->phones[i].state = IPC_PHONE_FREE;
467
 
1591 palkovsky 468
            /* Just for sure, we might have had some
469
             * IPC_PHONE_CONNECTING phones */
1582 palkovsky 470
            if (TASK->phones[i].state == IPC_PHONE_CONNECTED)
1591 palkovsky 471
                ipc_phone_hangup(&TASK->phones[i]);
472
            /* If the hangup succeeded, it has sent a HANGUP
473
             * message, the IPC is now in HUNGUP state, we
474
             * wait for the reply to come */
1582 palkovsky 475
 
476
            if (TASK->phones[i].state != IPC_PHONE_FREE)
1568 palkovsky 477
                break;
478
        }
479
        /* Voila, got into cleanup */
480
        if (i == IPC_MAX_PHONES)
481
            break;
482
 
2471 jermar 483
        call = ipc_wait_for_call(&TASK->answerbox, SYNCH_NO_TIMEOUT,
484
            SYNCH_FLAGS_NONE);
485
        ASSERT((call->flags & IPC_CALL_ANSWERED) ||
486
            (call->flags & IPC_CALL_NOTIF));
487
        ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
1141 palkovsky 488
 
1582 palkovsky 489
        atomic_dec(&TASK->active_calls);
1141 palkovsky 490
        ipc_call_free(call);
491
    }
1072 palkovsky 492
}
1258 palkovsky 493
 
494
 
1923 jermar 495
/** Initilize IPC subsystem */
1258 palkovsky 496
void ipc_init(void)
497
{
2471 jermar 498
    ipc_call_slab = slab_cache_create("ipc_call", sizeof(call_t), 0, NULL,
499
        NULL, 0);
1258 palkovsky 500
}
501
 
1573 palkovsky 502
 
2471 jermar 503
/** List answerbox contents.
504
 *
505
 * @param taskid    Task ID.
506
 */
1573 palkovsky 507
void ipc_print_task(task_id_t taskid)
508
{
509
    task_t *task;
510
    int i;
511
    call_t *call;
512
    link_t *tmp;
513
 
514
    spinlock_lock(&tasks_lock);
515
    task = task_find_by_id(taskid);
516
    if (task)
517
        spinlock_lock(&task->lock);
518
    spinlock_unlock(&tasks_lock);
519
    if (!task)
520
        return;
521
 
522
    /* Print opened phones & details */
523
    printf("PHONE:\n");
2471 jermar 524
    for (i = 0; i < IPC_MAX_PHONES; i++) {
1573 palkovsky 525
        spinlock_lock(&task->phones[i].lock);
526
        if (task->phones[i].state != IPC_PHONE_FREE) {
2471 jermar 527
            printf("%d: ", i);
1573 palkovsky 528
            switch (task->phones[i].state) {
529
            case IPC_PHONE_CONNECTING:
530
                printf("connecting ");
531
                break;
532
            case IPC_PHONE_CONNECTED:
1735 decky 533
                printf("connected to: %p ",
1573 palkovsky 534
                       task->phones[i].callee);
535
                break;
536
            case IPC_PHONE_SLAMMED:
1735 decky 537
                printf("slammed by: %p ",
1573 palkovsky 538
                       task->phones[i].callee);
539
                break;
540
            case IPC_PHONE_HUNGUP:
1735 decky 541
                printf("hung up - was: %p ",
1573 palkovsky 542
                       task->phones[i].callee);
543
                break;
544
            default:
545
                break;
546
            }
2472 jermar 547
            printf("active: %d\n",
548
                atomic_get(&task->phones[i].active_calls));
1573 palkovsky 549
        }
550
        spinlock_unlock(&task->phones[i].lock);
551
    }
552
 
553
 
554
    /* Print answerbox - calls */
555
    spinlock_lock(&task->answerbox.lock);
556
    printf("ABOX - CALLS:\n");
2472 jermar 557
    for (tmp = task->answerbox.calls.next; tmp != &task->answerbox.calls;
558
        tmp = tmp->next) {
1573 palkovsky 559
        call = list_get_instance(tmp, call_t, link);
2472 jermar 560
        printf("Callid: %p Srctask:%llu M:%d A1:%d A2:%d A3:%d "
561
            "Flags:%x\n", call, call->sender->taskid,
562
            IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data),
563
            IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
564
            call->flags);
1573 palkovsky 565
    }
566
    /* Print answerbox - calls */
567
    printf("ABOX - DISPATCHED CALLS:\n");
568
    for (tmp=task->answerbox.dispatched_calls.next;
569
         tmp != &task->answerbox.dispatched_calls;
570
         tmp = tmp->next) {
571
        call = list_get_instance(tmp, call_t, link);
2472 jermar 572
        printf("Callid: %p Srctask:%llu M:%d A1:%d A2:%d A3:%d "
573
            "Flags:%x\n", call, call->sender->taskid,
574
            IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data),
575
            IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
576
            call->flags);
1573 palkovsky 577
    }
578
    /* Print answerbox - calls */
579
    printf("ABOX - ANSWERS:\n");
2472 jermar 580
    for (tmp = task->answerbox.answers.next; tmp != &task->answerbox.answers;
581
        tmp = tmp->next) {
1573 palkovsky 582
        call = list_get_instance(tmp, call_t, link);
2472 jermar 583
        printf("Callid:%p M:%d A1:%d A2:%d A3:%d Flags:%x\n", call,
584
            IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data),
585
            IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
586
            call->flags);
1573 palkovsky 587
    }
588
 
589
    spinlock_unlock(&task->answerbox.lock);
590
    spinlock_unlock(&task->lock);
591
}
1702 cejka 592
 
1757 jermar 593
/** @}
1702 cejka 594
 */