Subversion Repositories HelenOS

Rev

Rev 4055 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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