Rev 1595 | Rev 1705 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
955 | palkovsky | 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 | |||
1702 | cejka | 29 | /** @addtogroup genericipc IPC |
30 | * @ingroup kernel |
||
31 | * @brief Interprocess communication protocol |
||
32 | * @{ |
||
33 | */ |
||
34 | /** @file |
||
35 | */ |
||
36 | |||
955 | palkovsky | 37 | /* Lock ordering |
38 | * |
||
39 | * First the answerbox, then the phone |
||
40 | */ |
||
41 | |||
1040 | palkovsky | 42 | #include <synch/spinlock.h> |
43 | #include <synch/waitq.h> |
||
1364 | jermar | 44 | #include <synch/synch.h> |
955 | palkovsky | 45 | #include <ipc/ipc.h> |
46 | #include <errno.h> |
||
47 | #include <mm/slab.h> |
||
48 | #include <arch.h> |
||
49 | #include <proc/task.h> |
||
50 | #include <memstr.h> |
||
51 | #include <debug.h> |
||
52 | |||
53 | #include <print.h> |
||
54 | #include <proc/thread.h> |
||
1258 | palkovsky | 55 | #include <arch/interrupt.h> |
1281 | palkovsky | 56 | #include <ipc/irq.h> |
955 | palkovsky | 57 | |
965 | palkovsky | 58 | /* Open channel that is assigned automatically to new tasks */ |
59 | answerbox_t *ipc_phone_0 = NULL; |
||
955 | palkovsky | 60 | |
61 | static slab_cache_t *ipc_call_slab; |
||
62 | |||
1084 | palkovsky | 63 | /* Initialize new call */ |
64 | static void _ipc_call_init(call_t *call) |
||
65 | { |
||
66 | memsetb((__address)call, sizeof(*call), 0); |
||
67 | call->callerbox = &TASK->answerbox; |
||
68 | call->sender = TASK; |
||
69 | } |
||
70 | |||
955 | palkovsky | 71 | /** Allocate & initialize call structure |
72 | * |
||
73 | * The call is initialized, so that the reply will be directed |
||
74 | * to TASK->answerbox |
||
1258 | palkovsky | 75 | * |
76 | * @param flags Parameters for slab_alloc (ATOMIC, etc.) |
||
955 | palkovsky | 77 | */ |
1258 | palkovsky | 78 | call_t * ipc_call_alloc(int flags) |
955 | palkovsky | 79 | { |
80 | call_t *call; |
||
81 | |||
1258 | palkovsky | 82 | call = slab_alloc(ipc_call_slab, flags); |
1084 | palkovsky | 83 | _ipc_call_init(call); |
955 | palkovsky | 84 | |
85 | return call; |
||
86 | } |
||
87 | |||
965 | palkovsky | 88 | /** Initialize allocated call */ |
1084 | palkovsky | 89 | void ipc_call_static_init(call_t *call) |
965 | palkovsky | 90 | { |
1084 | palkovsky | 91 | _ipc_call_init(call); |
92 | call->flags |= IPC_CALL_STATIC_ALLOC; |
||
965 | palkovsky | 93 | } |
94 | |||
955 | palkovsky | 95 | /** Deallocate call stracuture */ |
96 | void ipc_call_free(call_t *call) |
||
97 | { |
||
98 | slab_free(ipc_call_slab, call); |
||
99 | } |
||
100 | |||
101 | /** Initialize answerbox structure |
||
102 | */ |
||
103 | void ipc_answerbox_init(answerbox_t *box) |
||
104 | { |
||
1040 | palkovsky | 105 | spinlock_initialize(&box->lock, "ipc_box_lock"); |
1258 | palkovsky | 106 | spinlock_initialize(&box->irq_lock, "ipc_box_irqlock"); |
1040 | palkovsky | 107 | waitq_initialize(&box->wq); |
955 | palkovsky | 108 | list_initialize(&box->connected_phones); |
109 | list_initialize(&box->calls); |
||
110 | list_initialize(&box->dispatched_calls); |
||
111 | list_initialize(&box->answers); |
||
1258 | palkovsky | 112 | list_initialize(&box->irq_notifs); |
1027 | palkovsky | 113 | box->task = TASK; |
955 | palkovsky | 114 | } |
115 | |||
1040 | palkovsky | 116 | /** Connect phone to answerbox */ |
117 | void ipc_phone_connect(phone_t *phone, answerbox_t *box) |
||
955 | palkovsky | 118 | { |
1084 | palkovsky | 119 | spinlock_lock(&phone->lock); |
120 | |||
1568 | palkovsky | 121 | phone->state = IPC_PHONE_CONNECTED; |
955 | palkovsky | 122 | phone->callee = box; |
965 | palkovsky | 123 | |
1040 | palkovsky | 124 | spinlock_lock(&box->lock); |
1573 | palkovsky | 125 | list_append(&phone->link, &box->connected_phones); |
1040 | palkovsky | 126 | spinlock_unlock(&box->lock); |
1084 | palkovsky | 127 | |
128 | spinlock_unlock(&phone->lock); |
||
955 | palkovsky | 129 | } |
130 | |||
1223 | jermar | 131 | /** Initialize phone structure and connect phone to answerbox |
1040 | palkovsky | 132 | */ |
133 | void ipc_phone_init(phone_t *phone) |
||
134 | { |
||
135 | spinlock_initialize(&phone->lock, "phone_lock"); |
||
136 | phone->callee = NULL; |
||
1568 | palkovsky | 137 | phone->state = IPC_PHONE_FREE; |
1088 | palkovsky | 138 | atomic_set(&phone->active_calls, 0); |
1040 | palkovsky | 139 | } |
140 | |||
959 | palkovsky | 141 | /** Helper function to facilitate synchronous calls */ |
142 | void ipc_call_sync(phone_t *phone, call_t *request) |
||
143 | { |
||
144 | answerbox_t sync_box; |
||
955 | palkovsky | 145 | |
959 | palkovsky | 146 | ipc_answerbox_init(&sync_box); |
147 | |||
148 | /* We will receive data on special box */ |
||
149 | request->callerbox = &sync_box; |
||
150 | |||
151 | ipc_call(phone, request); |
||
1502 | jermar | 152 | ipc_wait_for_call(&sync_box, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE); |
959 | palkovsky | 153 | } |
154 | |||
1084 | palkovsky | 155 | /** Answer message that was not dispatched and is not entered in |
156 | * any queue |
||
157 | */ |
||
158 | static void _ipc_answer_free_call(call_t *call) |
||
159 | { |
||
160 | answerbox_t *callerbox = call->callerbox; |
||
161 | |||
162 | call->flags |= IPC_CALL_ANSWERED; |
||
163 | |||
164 | spinlock_lock(&callerbox->lock); |
||
1573 | palkovsky | 165 | list_append(&call->link, &callerbox->answers); |
1084 | palkovsky | 166 | spinlock_unlock(&callerbox->lock); |
167 | waitq_wakeup(&callerbox->wq, 0); |
||
168 | } |
||
169 | |||
170 | /** Answer message, that is in callee queue |
||
171 | * |
||
172 | * @param box Answerbox that is answering the message |
||
173 | * @param call Modified request that is being sent back |
||
174 | */ |
||
175 | void ipc_answer(answerbox_t *box, call_t *call) |
||
176 | { |
||
177 | /* Remove from active box */ |
||
178 | spinlock_lock(&box->lock); |
||
1573 | palkovsky | 179 | list_remove(&call->link); |
1084 | palkovsky | 180 | spinlock_unlock(&box->lock); |
181 | /* Send back answer */ |
||
182 | _ipc_answer_free_call(call); |
||
183 | } |
||
184 | |||
1090 | palkovsky | 185 | /** Simulate sending back a message |
186 | * |
||
187 | * Most errors are better handled by forming a normal backward |
||
188 | * message and sending it as a normal answer. |
||
189 | */ |
||
190 | void ipc_backsend_err(phone_t *phone, call_t *call, __native err) |
||
191 | { |
||
192 | call->data.phone = phone; |
||
193 | atomic_inc(&phone->active_calls); |
||
1568 | palkovsky | 194 | IPC_SET_RETVAL(call->data, err); |
1090 | palkovsky | 195 | _ipc_answer_free_call(call); |
196 | } |
||
197 | |||
1086 | palkovsky | 198 | /* Unsafe unchecking ipc_call */ |
199 | static void _ipc_call(phone_t *phone, answerbox_t *box, call_t *call) |
||
200 | { |
||
1088 | palkovsky | 201 | if (! (call->flags & IPC_CALL_FORWARDED)) { |
202 | atomic_inc(&phone->active_calls); |
||
203 | call->data.phone = phone; |
||
204 | } |
||
1086 | palkovsky | 205 | |
206 | spinlock_lock(&box->lock); |
||
1573 | palkovsky | 207 | list_append(&call->link, &box->calls); |
1086 | palkovsky | 208 | spinlock_unlock(&box->lock); |
209 | waitq_wakeup(&box->wq, 0); |
||
210 | } |
||
211 | |||
959 | palkovsky | 212 | /** Send a asynchronous request using phone to answerbox |
955 | palkovsky | 213 | * |
214 | * @param phone Phone connected to answerbox |
||
215 | * @param request Request to be sent |
||
216 | */ |
||
1088 | palkovsky | 217 | int ipc_call(phone_t *phone, call_t *call) |
955 | palkovsky | 218 | { |
1084 | palkovsky | 219 | answerbox_t *box; |
955 | palkovsky | 220 | |
1084 | palkovsky | 221 | spinlock_lock(&phone->lock); |
1568 | palkovsky | 222 | if (phone->state != IPC_PHONE_CONNECTED) { |
1086 | palkovsky | 223 | spinlock_unlock(&phone->lock); |
1088 | palkovsky | 224 | if (call->flags & IPC_CALL_FORWARDED) { |
225 | IPC_SET_RETVAL(call->data, EFORWARD); |
||
1090 | palkovsky | 226 | _ipc_answer_free_call(call); |
1568 | palkovsky | 227 | } else { |
228 | if (phone->state == IPC_PHONE_HUNGUP) |
||
1090 | palkovsky | 229 | ipc_backsend_err(phone, call, EHANGUP); |
1088 | palkovsky | 230 | else |
1090 | palkovsky | 231 | ipc_backsend_err(phone, call, ENOENT); |
1088 | palkovsky | 232 | } |
233 | return ENOENT; |
||
1084 | palkovsky | 234 | } |
1568 | palkovsky | 235 | box = phone->callee; |
1086 | palkovsky | 236 | _ipc_call(phone, box, call); |
237 | |||
238 | spinlock_unlock(&phone->lock); |
||
1088 | palkovsky | 239 | return 0; |
1086 | palkovsky | 240 | } |
955 | palkovsky | 241 | |
1086 | palkovsky | 242 | /** Disconnect phone from answerbox |
243 | * |
||
1568 | palkovsky | 244 | * This call leaves the phone in HUNGUP state. The change to 'free' is done |
245 | * lazily later. |
||
1086 | palkovsky | 246 | * |
1568 | palkovsky | 247 | * @param phone Phone to be hung up |
248 | * |
||
1086 | palkovsky | 249 | * @return 0 - phone disconnected, -1 - the phone was already disconnected |
250 | */ |
||
1591 | palkovsky | 251 | int ipc_phone_hangup(phone_t *phone) |
1086 | palkovsky | 252 | { |
253 | answerbox_t *box; |
||
254 | call_t *call; |
||
255 | |||
256 | spinlock_lock(&phone->lock); |
||
1568 | palkovsky | 257 | if (phone->state == IPC_PHONE_FREE || phone->state ==IPC_PHONE_HUNGUP \ |
258 | || phone->state == IPC_PHONE_CONNECTING) { |
||
259 | spinlock_unlock(&phone->lock); |
||
260 | return -1; |
||
261 | } |
||
1086 | palkovsky | 262 | box = phone->callee; |
1568 | palkovsky | 263 | if (phone->state != IPC_PHONE_SLAMMED) { |
264 | /* Remove myself from answerbox */ |
||
265 | spinlock_lock(&box->lock); |
||
1573 | palkovsky | 266 | list_remove(&phone->link); |
1568 | palkovsky | 267 | spinlock_unlock(&box->lock); |
268 | |||
269 | if (phone->state != IPC_PHONE_SLAMMED) { |
||
270 | call = ipc_call_alloc(0); |
||
271 | IPC_SET_METHOD(call->data, IPC_M_PHONE_HUNGUP); |
||
272 | call->flags |= IPC_CALL_DISCARD_ANSWER; |
||
273 | _ipc_call(phone, box, call); |
||
1088 | palkovsky | 274 | } |
1086 | palkovsky | 275 | } |
276 | |||
1568 | palkovsky | 277 | phone->state = IPC_PHONE_HUNGUP; |
1084 | palkovsky | 278 | spinlock_unlock(&phone->lock); |
1086 | palkovsky | 279 | |
280 | return 0; |
||
955 | palkovsky | 281 | } |
282 | |||
1040 | palkovsky | 283 | /** Forwards call from one answerbox to a new one |
284 | * |
||
1342 | jermar | 285 | * @param call Call to be redirected. |
286 | * @param newphone Phone to target answerbox. |
||
1040 | palkovsky | 287 | * @param oldbox Old answerbox |
1088 | palkovsky | 288 | * @return 0 on forward ok, error code, if there was error |
289 | * |
||
290 | * - the return value serves only as an information for the forwarder, |
||
291 | * the original caller is notified automatically with EFORWARD |
||
1040 | palkovsky | 292 | */ |
1088 | palkovsky | 293 | int ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox) |
1040 | palkovsky | 294 | { |
295 | spinlock_lock(&oldbox->lock); |
||
1573 | palkovsky | 296 | list_remove(&call->link); |
1040 | palkovsky | 297 | spinlock_unlock(&oldbox->lock); |
298 | |||
1088 | palkovsky | 299 | return ipc_call(newphone, call); |
1040 | palkovsky | 300 | } |
301 | |||
955 | palkovsky | 302 | |
303 | /** Wait for phone call |
||
304 | * |
||
1364 | jermar | 305 | * @param box Answerbox expecting the call. |
306 | * @param usec Timeout in microseconds. See documentation for waitq_sleep_timeout() for |
||
307 | * decription of its special meaning. |
||
1502 | jermar | 308 | * @param flags Select mode of sleep operation. See documentation for waitq_sleep_timeout()i |
309 | * for description of its special meaning. |
||
955 | palkovsky | 310 | * @return Recived message address |
311 | * - to distinguish between call and answer, look at call->flags |
||
312 | */ |
||
1502 | jermar | 313 | call_t * ipc_wait_for_call(answerbox_t *box, __u32 usec, int flags) |
955 | palkovsky | 314 | { |
315 | call_t *request; |
||
1258 | palkovsky | 316 | ipl_t ipl; |
1364 | jermar | 317 | int rc; |
955 | palkovsky | 318 | |
1364 | jermar | 319 | restart: |
1502 | jermar | 320 | rc = waitq_sleep_timeout(&box->wq, usec, flags); |
1364 | jermar | 321 | if (SYNCH_FAILED(rc)) |
322 | return NULL; |
||
1086 | palkovsky | 323 | |
1040 | palkovsky | 324 | spinlock_lock(&box->lock); |
1258 | palkovsky | 325 | if (!list_empty(&box->irq_notifs)) { |
326 | ipl = interrupts_disable(); |
||
327 | spinlock_lock(&box->irq_lock); |
||
328 | |||
1573 | palkovsky | 329 | request = list_get_instance(box->irq_notifs.next, call_t, link); |
330 | list_remove(&request->link); |
||
1258 | palkovsky | 331 | |
332 | spinlock_unlock(&box->irq_lock); |
||
333 | interrupts_restore(ipl); |
||
334 | } else if (!list_empty(&box->answers)) { |
||
1086 | palkovsky | 335 | /* Handle asynchronous answers */ |
1573 | palkovsky | 336 | request = list_get_instance(box->answers.next, call_t, link); |
337 | list_remove(&request->link); |
||
1086 | palkovsky | 338 | atomic_dec(&request->data.phone->active_calls); |
339 | } else if (!list_empty(&box->calls)) { |
||
340 | /* Handle requests */ |
||
1573 | palkovsky | 341 | request = list_get_instance(box->calls.next, call_t, link); |
342 | list_remove(&request->link); |
||
1086 | palkovsky | 343 | /* Append request to dispatch queue */ |
1573 | palkovsky | 344 | list_append(&request->link, &box->dispatched_calls); |
1086 | palkovsky | 345 | } else { |
1595 | palkovsky | 346 | /* This can happen regularly after ipc_cleanup */ |
1086 | palkovsky | 347 | spinlock_unlock(&box->lock); |
348 | goto restart; |
||
955 | palkovsky | 349 | } |
1040 | palkovsky | 350 | spinlock_unlock(&box->lock); |
955 | palkovsky | 351 | return request; |
352 | } |
||
353 | |||
1141 | palkovsky | 354 | /** Answer all calls from list with EHANGUP msg */ |
355 | static void ipc_cleanup_call_list(link_t *lst) |
||
356 | { |
||
357 | call_t *call; |
||
358 | |||
359 | while (!list_empty(lst)) { |
||
1573 | palkovsky | 360 | call = list_get_instance(lst->next, call_t, link); |
361 | list_remove(&call->link); |
||
1141 | palkovsky | 362 | |
363 | IPC_SET_RETVAL(call->data, EHANGUP); |
||
364 | _ipc_answer_free_call(call); |
||
365 | } |
||
366 | } |
||
367 | |||
1582 | palkovsky | 368 | /** Cleans up all IPC communication of the current task |
1072 | palkovsky | 369 | * |
1582 | palkovsky | 370 | * Note: ipc_hangup sets returning answerbox to TASK->answerbox, you |
371 | * have to change it as well if you want to cleanup other current then current. |
||
1072 | palkovsky | 372 | */ |
1582 | palkovsky | 373 | void ipc_cleanup(void) |
1072 | palkovsky | 374 | { |
1088 | palkovsky | 375 | int i; |
1141 | palkovsky | 376 | call_t *call; |
377 | phone_t *phone; |
||
1582 | palkovsky | 378 | |
1088 | palkovsky | 379 | /* Disconnect all our phones ('ipc_phone_hangup') */ |
380 | for (i=0;i < IPC_MAX_PHONES; i++) |
||
1591 | palkovsky | 381 | ipc_phone_hangup(&TASK->phones[i]); |
1088 | palkovsky | 382 | |
1258 | palkovsky | 383 | /* Disconnect all connected irqs */ |
1582 | palkovsky | 384 | ipc_irq_cleanup(&TASK->answerbox); |
1258 | palkovsky | 385 | |
1141 | palkovsky | 386 | /* Disconnect all phones connected to our answerbox */ |
387 | restart_phones: |
||
1582 | palkovsky | 388 | spinlock_lock(&TASK->answerbox.lock); |
389 | while (!list_empty(&TASK->answerbox.connected_phones)) { |
||
390 | phone = list_get_instance(TASK->answerbox.connected_phones.next, |
||
1573 | palkovsky | 391 | phone_t, link); |
1141 | palkovsky | 392 | if (! spinlock_trylock(&phone->lock)) { |
1582 | palkovsky | 393 | spinlock_unlock(&TASK->answerbox.lock); |
1141 | palkovsky | 394 | goto restart_phones; |
395 | } |
||
396 | |||
397 | /* Disconnect phone */ |
||
1568 | palkovsky | 398 | ASSERT(phone->state == IPC_PHONE_CONNECTED); |
399 | phone->state = IPC_PHONE_SLAMMED; |
||
1573 | palkovsky | 400 | list_remove(&phone->link); |
1088 | palkovsky | 401 | |
1141 | palkovsky | 402 | spinlock_unlock(&phone->lock); |
403 | } |
||
404 | |||
1088 | palkovsky | 405 | /* Answer all messages in 'calls' and 'dispatched_calls' queues */ |
1582 | palkovsky | 406 | ipc_cleanup_call_list(&TASK->answerbox.dispatched_calls); |
407 | ipc_cleanup_call_list(&TASK->answerbox.calls); |
||
408 | spinlock_unlock(&TASK->answerbox.lock); |
||
1072 | palkovsky | 409 | |
1088 | palkovsky | 410 | /* Wait for all async answers to arrive */ |
1568 | palkovsky | 411 | while (1) { |
412 | /* Go through all phones, until all are FREE... */ |
||
413 | /* Locking not needed, no one else should modify |
||
414 | * it, when we are in cleanup */ |
||
415 | for (i=0;i < IPC_MAX_PHONES; i++) { |
||
1582 | palkovsky | 416 | if (TASK->phones[i].state == IPC_PHONE_HUNGUP && \ |
417 | atomic_get(&TASK->phones[i].active_calls) == 0) |
||
418 | TASK->phones[i].state = IPC_PHONE_FREE; |
||
419 | |||
1591 | palkovsky | 420 | /* Just for sure, we might have had some |
421 | * IPC_PHONE_CONNECTING phones */ |
||
1582 | palkovsky | 422 | if (TASK->phones[i].state == IPC_PHONE_CONNECTED) |
1591 | palkovsky | 423 | ipc_phone_hangup(&TASK->phones[i]); |
424 | /* If the hangup succeeded, it has sent a HANGUP |
||
425 | * message, the IPC is now in HUNGUP state, we |
||
426 | * wait for the reply to come */ |
||
1582 | palkovsky | 427 | |
428 | if (TASK->phones[i].state != IPC_PHONE_FREE) |
||
1568 | palkovsky | 429 | break; |
430 | } |
||
431 | /* Voila, got into cleanup */ |
||
432 | if (i == IPC_MAX_PHONES) |
||
433 | break; |
||
434 | |||
1582 | palkovsky | 435 | call = ipc_wait_for_call(&TASK->answerbox, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE); |
1260 | palkovsky | 436 | ASSERT((call->flags & IPC_CALL_ANSWERED) || (call->flags & IPC_CALL_NOTIF)); |
1141 | palkovsky | 437 | ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC)); |
438 | |||
1582 | palkovsky | 439 | atomic_dec(&TASK->active_calls); |
1141 | palkovsky | 440 | ipc_call_free(call); |
441 | } |
||
1072 | palkovsky | 442 | } |
1258 | palkovsky | 443 | |
444 | |||
445 | /** Initilize ipc subsystem */ |
||
446 | void ipc_init(void) |
||
447 | { |
||
448 | ipc_call_slab = slab_cache_create("ipc_call", |
||
449 | sizeof(call_t), |
||
450 | 0, |
||
451 | NULL, NULL, 0); |
||
452 | ipc_irq_make_table(IRQ_COUNT); |
||
453 | } |
||
454 | |||
1573 | palkovsky | 455 | |
456 | /** Kconsole - list answerbox contents */ |
||
457 | void ipc_print_task(task_id_t taskid) |
||
458 | { |
||
459 | task_t *task; |
||
460 | int i; |
||
461 | call_t *call; |
||
462 | link_t *tmp; |
||
463 | |||
464 | spinlock_lock(&tasks_lock); |
||
465 | task = task_find_by_id(taskid); |
||
466 | if (task) |
||
467 | spinlock_lock(&task->lock); |
||
468 | spinlock_unlock(&tasks_lock); |
||
469 | if (!task) |
||
470 | return; |
||
471 | |||
472 | /* Print opened phones & details */ |
||
473 | printf("PHONE:\n"); |
||
474 | for (i=0; i < IPC_MAX_PHONES;i++) { |
||
475 | spinlock_lock(&task->phones[i].lock); |
||
476 | if (task->phones[i].state != IPC_PHONE_FREE) { |
||
477 | printf("%d: ",i); |
||
478 | switch (task->phones[i].state) { |
||
479 | case IPC_PHONE_CONNECTING: |
||
480 | printf("connecting "); |
||
481 | break; |
||
482 | case IPC_PHONE_CONNECTED: |
||
483 | printf("connected to: %P ", |
||
484 | task->phones[i].callee); |
||
485 | break; |
||
486 | case IPC_PHONE_SLAMMED: |
||
487 | printf("slammed by: %P ", |
||
488 | task->phones[i].callee); |
||
489 | break; |
||
490 | case IPC_PHONE_HUNGUP: |
||
491 | printf("hung up - was: %P ", |
||
492 | task->phones[i].callee); |
||
493 | break; |
||
494 | default: |
||
495 | break; |
||
496 | } |
||
497 | printf("active: %d\n", atomic_get(&task->phones[i].active_calls)); |
||
498 | } |
||
499 | spinlock_unlock(&task->phones[i].lock); |
||
500 | } |
||
501 | |||
502 | |||
503 | /* Print answerbox - calls */ |
||
504 | spinlock_lock(&task->answerbox.lock); |
||
505 | printf("ABOX - CALLS:\n"); |
||
506 | for (tmp=task->answerbox.calls.next; tmp != &task->answerbox.calls;tmp = tmp->next) { |
||
507 | call = list_get_instance(tmp, call_t, link); |
||
508 | printf("Callid: %P Srctask:%lld M:%d A1:%d A2:%d A3:%d Flags:%x\n",call, |
||
509 | call->sender->taskid, IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data), |
||
510 | IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data), call->flags); |
||
511 | } |
||
512 | /* Print answerbox - calls */ |
||
513 | printf("ABOX - DISPATCHED CALLS:\n"); |
||
514 | for (tmp=task->answerbox.dispatched_calls.next; |
||
515 | tmp != &task->answerbox.dispatched_calls; |
||
516 | tmp = tmp->next) { |
||
517 | call = list_get_instance(tmp, call_t, link); |
||
518 | printf("Callid: %P Srctask:%lld M:%d A1:%d A2:%d A3:%d Flags:%x\n",call, |
||
519 | call->sender->taskid, IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data), |
||
520 | IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data), call->flags); |
||
521 | } |
||
522 | /* Print answerbox - calls */ |
||
523 | printf("ABOX - ANSWERS:\n"); |
||
524 | for (tmp=task->answerbox.answers.next; tmp != &task->answerbox.answers; tmp = tmp->next) { |
||
525 | call = list_get_instance(tmp, call_t, link); |
||
526 | printf("Callid:%P M:%d A1:%d A2:%d A3:%d Flags:%x\n",call, |
||
527 | IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data), |
||
528 | IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data), call->flags); |
||
529 | } |
||
530 | |||
531 | spinlock_unlock(&task->answerbox.lock); |
||
532 | spinlock_unlock(&task->lock); |
||
533 | } |
||
1702 | cejka | 534 | |
535 | /** @} |
||
536 | */ |
||
537 |