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