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