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