source: mainline/kernel/generic/src/ipc/ipc.c@ 52c60b6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 52c60b6 was 170332d, checked in by Jakub Jermar <jermar@…>, 15 years ago

Disable interrupts when taking TASK→lock.

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