Subversion Repositories HelenOS

Rev

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