Rev 1392 | Rev 1463 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1392 | Rev 1443 | ||
---|---|---|---|
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 | #include <ipc/ipc.h> |
29 | #include <ipc/ipc.h> |
30 | #include <libc.h> |
30 | #include <libc.h> |
31 | #include <malloc.h> |
31 | #include <malloc.h> |
32 | #include <errno.h> |
32 | #include <errno.h> |
33 | #include <libadt/list.h> |
33 | #include <libadt/list.h> |
34 | #include <stdio.h> |
34 | #include <stdio.h> |
35 | #include <unistd.h> |
35 | #include <unistd.h> |
36 | #include <futex.h> |
36 | #include <futex.h> |
37 | #include <kernel/synch/synch.h> |
37 | #include <kernel/synch/synch.h> |
38 | 38 | ||
39 | /** Structure used for keeping track of sent async msgs |
39 | /** Structure used for keeping track of sent async msgs |
40 | * and queing unsent msgs |
40 | * and queing unsent msgs |
41 | * |
41 | * |
42 | */ |
42 | */ |
43 | typedef struct { |
43 | typedef struct { |
44 | link_t list; |
44 | link_t list; |
45 | 45 | ||
46 | ipc_async_callback_t callback; |
46 | ipc_async_callback_t callback; |
47 | void *private; |
47 | void *private; |
48 | union { |
48 | union { |
49 | ipc_callid_t callid; |
49 | ipc_callid_t callid; |
50 | struct { |
50 | struct { |
51 | ipc_call_t data; |
51 | ipc_call_t data; |
52 | int phoneid; |
52 | int phoneid; |
53 | } msg; |
53 | } msg; |
54 | }u; |
54 | }u; |
55 | } async_call_t; |
55 | } async_call_t; |
56 | 56 | ||
57 | LIST_INITIALIZE(dispatched_calls); |
57 | LIST_INITIALIZE(dispatched_calls); |
58 | LIST_INITIALIZE(queued_calls); |
58 | LIST_INITIALIZE(queued_calls); |
59 | 59 | ||
60 | static atomic_t ipc_futex = FUTEX_INITIALIZER; |
60 | static atomic_t ipc_futex = FUTEX_INITIALIZER; |
61 | 61 | ||
62 | int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1, |
62 | int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1, |
63 | ipcarg_t *result) |
63 | ipcarg_t *result) |
64 | { |
64 | { |
65 | ipc_call_t resdata; |
65 | ipc_call_t resdata; |
66 | int callres; |
66 | int callres; |
67 | 67 | ||
68 | callres = __SYSCALL4(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1, |
68 | callres = __SYSCALL4(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1, |
69 | (sysarg_t)&resdata); |
69 | (sysarg_t)&resdata); |
70 | if (callres) |
70 | if (callres) |
71 | return callres; |
71 | return callres; |
72 | if (result) |
72 | if (result) |
73 | *result = IPC_GET_ARG1(resdata); |
73 | *result = IPC_GET_ARG1(resdata); |
74 | return IPC_GET_RETVAL(resdata); |
74 | return IPC_GET_RETVAL(resdata); |
75 | } |
75 | } |
76 | 76 | ||
77 | int ipc_call_sync_3(int phoneid, ipcarg_t method, ipcarg_t arg1, |
77 | int ipc_call_sync_3(int phoneid, ipcarg_t method, ipcarg_t arg1, |
78 | ipcarg_t arg2, ipcarg_t arg3, |
78 | ipcarg_t arg2, ipcarg_t arg3, |
79 | ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3) |
79 | ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3) |
80 | { |
80 | { |
81 | ipc_call_t data; |
81 | ipc_call_t data; |
82 | int callres; |
82 | int callres; |
83 | 83 | ||
84 | IPC_SET_METHOD(data, method); |
84 | IPC_SET_METHOD(data, method); |
85 | IPC_SET_ARG1(data, arg1); |
85 | IPC_SET_ARG1(data, arg1); |
86 | IPC_SET_ARG2(data, arg2); |
86 | IPC_SET_ARG2(data, arg2); |
87 | IPC_SET_ARG3(data, arg3); |
87 | IPC_SET_ARG3(data, arg3); |
88 | 88 | ||
89 | callres = __SYSCALL3(SYS_IPC_CALL_SYNC, phoneid, (sysarg_t)&data, |
89 | callres = __SYSCALL3(SYS_IPC_CALL_SYNC, phoneid, (sysarg_t)&data, |
90 | (sysarg_t)&data); |
90 | (sysarg_t)&data); |
91 | if (callres) |
91 | if (callres) |
92 | return callres; |
92 | return callres; |
93 | 93 | ||
94 | if (result1) |
94 | if (result1) |
95 | *result1 = IPC_GET_ARG1(data); |
95 | *result1 = IPC_GET_ARG1(data); |
96 | if (result2) |
96 | if (result2) |
97 | *result2 = IPC_GET_ARG2(data); |
97 | *result2 = IPC_GET_ARG2(data); |
98 | if (result3) |
98 | if (result3) |
99 | *result3 = IPC_GET_ARG3(data); |
99 | *result3 = IPC_GET_ARG3(data); |
100 | return IPC_GET_RETVAL(data); |
100 | return IPC_GET_RETVAL(data); |
101 | } |
101 | } |
102 | 102 | ||
103 | /** Syscall to send asynchronous message */ |
103 | /** Syscall to send asynchronous message */ |
104 | static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data) |
104 | static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data) |
105 | { |
105 | { |
106 | return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t)data); |
106 | return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t)data); |
107 | } |
107 | } |
108 | 108 | ||
109 | /** Send asynchronous message |
109 | /** Send asynchronous message |
110 | * |
110 | * |
111 | * - if fatal error, call callback handler with proper error code |
111 | * - if fatal error, call callback handler with proper error code |
112 | * - if message cannot be temporarily sent, add to queue |
112 | * - if message cannot be temporarily sent, add to queue |
113 | */ |
113 | */ |
114 | void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1, |
114 | void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1, |
115 | ipcarg_t arg2, void *private, |
115 | ipcarg_t arg2, void *private, |
116 | ipc_async_callback_t callback) |
116 | ipc_async_callback_t callback) |
117 | { |
117 | { |
118 | async_call_t *call; |
118 | async_call_t *call; |
119 | ipc_callid_t callid; |
119 | ipc_callid_t callid; |
120 | 120 | ||
121 | call = malloc(sizeof(*call)); |
121 | call = malloc(sizeof(*call)); |
122 | if (!call) { |
122 | if (!call) { |
- | 123 | if (callback) |
|
123 | callback(private, ENOMEM, NULL); |
124 | callback(private, ENOMEM, NULL); |
124 | return; |
125 | return; |
125 | } |
126 | } |
126 | 127 | ||
127 | callid = __SYSCALL4(SYS_IPC_CALL_ASYNC_FAST, phoneid, method, arg1, arg2); |
128 | callid = __SYSCALL4(SYS_IPC_CALL_ASYNC_FAST, phoneid, method, arg1, arg2); |
128 | if (callid == IPC_CALLRET_FATAL) { |
129 | if (callid == IPC_CALLRET_FATAL) { |
129 | /* Call asynchronous handler with error code */ |
130 | /* Call asynchronous handler with error code */ |
- | 131 | if (callback) |
|
130 | callback(private, ENOENT, NULL); |
132 | callback(private, ENOENT, NULL); |
131 | free(call); |
133 | free(call); |
132 | return; |
134 | return; |
133 | } |
135 | } |
134 | 136 | ||
135 | call->callback = callback; |
137 | call->callback = callback; |
136 | call->private = private; |
138 | call->private = private; |
137 | 139 | ||
138 | if (callid == IPC_CALLRET_TEMPORARY) { |
140 | if (callid == IPC_CALLRET_TEMPORARY) { |
139 | /* Add asynchronous call to queue of non-dispatched async calls */ |
141 | /* Add asynchronous call to queue of non-dispatched async calls */ |
140 | call->u.msg.phoneid = phoneid; |
142 | call->u.msg.phoneid = phoneid; |
141 | IPC_SET_METHOD(call->u.msg.data, method); |
143 | IPC_SET_METHOD(call->u.msg.data, method); |
142 | IPC_SET_ARG1(call->u.msg.data, arg1); |
144 | IPC_SET_ARG1(call->u.msg.data, arg1); |
143 | IPC_SET_ARG2(call->u.msg.data, arg2); |
145 | IPC_SET_ARG2(call->u.msg.data, arg2); |
144 | 146 | ||
145 | futex_down(&ipc_futex); |
147 | futex_down(&ipc_futex); |
146 | list_append(&call->list, &queued_calls); |
148 | list_append(&call->list, &queued_calls); |
147 | futex_up(&ipc_futex); |
149 | futex_up(&ipc_futex); |
148 | return; |
150 | return; |
149 | } |
151 | } |
150 | call->u.callid = callid; |
152 | call->u.callid = callid; |
151 | /* Add call to list of dispatched calls */ |
153 | /* Add call to list of dispatched calls */ |
152 | futex_down(&ipc_futex); |
154 | futex_down(&ipc_futex); |
153 | list_append(&call->list, &dispatched_calls); |
155 | list_append(&call->list, &dispatched_calls); |
154 | futex_up(&ipc_futex); |
156 | futex_up(&ipc_futex); |
155 | } |
157 | } |
156 | 158 | ||
157 | 159 | ||
158 | /** Send a fast answer to a received call. |
160 | /** Send a fast answer to a received call. |
159 | * |
161 | * |
160 | * The fast answer makes use of passing retval and first two arguments in registers. |
162 | * The fast answer makes use of passing retval and first two arguments in registers. |
161 | * If you need to return more, use the ipc_answer() instead. |
163 | * If you need to return more, use the ipc_answer() instead. |
162 | * |
164 | * |
163 | * @param callid ID of the call being answered. |
165 | * @param callid ID of the call being answered. |
164 | * @param retval Return value. |
166 | * @param retval Return value. |
165 | * @param arg1 First return argument. |
167 | * @param arg1 First return argument. |
166 | * @param arg2 Second return argument. |
168 | * @param arg2 Second return argument. |
167 | * |
169 | * |
168 | * @return Zero on success or a value from @ref errno.h on failure. |
170 | * @return Zero on success or a value from @ref errno.h on failure. |
169 | */ |
171 | */ |
170 | ipcarg_t ipc_answer_fast(ipc_callid_t callid, ipcarg_t retval, ipcarg_t arg1, |
172 | ipcarg_t ipc_answer_fast(ipc_callid_t callid, ipcarg_t retval, ipcarg_t arg1, |
171 | ipcarg_t arg2) |
173 | ipcarg_t arg2) |
172 | { |
174 | { |
173 | return __SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2); |
175 | return __SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2); |
174 | } |
176 | } |
175 | 177 | ||
176 | /** Send a full answer to a received call. |
178 | /** Send a full answer to a received call. |
177 | * |
179 | * |
178 | * @param callid ID of the call being answered. |
180 | * @param callid ID of the call being answered. |
179 | * @param call Call data. Must be already initialized by the responder. |
181 | * @param call Call data. Must be already initialized by the responder. |
180 | * |
182 | * |
181 | * @return Zero on success or a value from @ref errno.h on failure. |
183 | * @return Zero on success or a value from @ref errno.h on failure. |
182 | */ |
184 | */ |
183 | ipcarg_t ipc_answer(ipc_callid_t callid, ipc_call_t *call) |
185 | ipcarg_t ipc_answer(ipc_callid_t callid, ipc_call_t *call) |
184 | { |
186 | { |
185 | return __SYSCALL2(SYS_IPC_ANSWER, callid, (sysarg_t) call); |
187 | return __SYSCALL2(SYS_IPC_ANSWER, callid, (sysarg_t) call); |
186 | } |
188 | } |
187 | 189 | ||
188 | 190 | ||
189 | /** Try to dispatch queed calls from async queue */ |
191 | /** Try to dispatch queed calls from async queue */ |
190 | static void try_dispatch_queued_calls(void) |
192 | static void try_dispatch_queued_calls(void) |
191 | { |
193 | { |
192 | async_call_t *call; |
194 | async_call_t *call; |
193 | ipc_callid_t callid; |
195 | ipc_callid_t callid; |
194 | 196 | ||
195 | futex_down(&ipc_futex); |
197 | futex_down(&ipc_futex); |
196 | while (!list_empty(&queued_calls)) { |
198 | while (!list_empty(&queued_calls)) { |
197 | call = list_get_instance(queued_calls.next, async_call_t, |
199 | call = list_get_instance(queued_calls.next, async_call_t, |
198 | list); |
200 | list); |
199 | 201 | ||
200 | callid = _ipc_call_async(call->u.msg.phoneid, |
202 | callid = _ipc_call_async(call->u.msg.phoneid, |
201 | &call->u.msg.data); |
203 | &call->u.msg.data); |
202 | if (callid == IPC_CALLRET_TEMPORARY) |
204 | if (callid == IPC_CALLRET_TEMPORARY) |
203 | break; |
205 | break; |
204 | list_remove(&call->list); |
206 | list_remove(&call->list); |
205 | 207 | ||
206 | if (callid == IPC_CALLRET_FATAL) { |
208 | if (callid == IPC_CALLRET_FATAL) { |
207 | futex_up(&ipc_futex); |
209 | futex_up(&ipc_futex); |
- | 210 | if (call->callback) |
|
208 | call->callback(call->private, ENOENT, NULL); |
211 | call->callback(call->private, ENOENT, NULL); |
209 | free(call); |
212 | free(call); |
210 | futex_down(&ipc_futex); |
213 | futex_down(&ipc_futex); |
211 | } else { |
214 | } else { |
212 | call->u.callid = callid; |
215 | call->u.callid = callid; |
213 | list_append(&call->list, &dispatched_calls); |
216 | list_append(&call->list, &dispatched_calls); |
214 | } |
217 | } |
215 | } |
218 | } |
216 | futex_up(&ipc_futex); |
219 | futex_up(&ipc_futex); |
217 | } |
220 | } |
218 | 221 | ||
219 | /** Handle received answer |
222 | /** Handle received answer |
220 | * |
223 | * |
221 | * TODO: Make it use hash table |
224 | * TODO: Make it use hash table |
222 | * |
225 | * |
223 | * @param callid Callid (with first bit set) of the answered call |
226 | * @param callid Callid (with first bit set) of the answered call |
224 | */ |
227 | */ |
225 | static void handle_answer(ipc_callid_t callid, ipc_call_t *data) |
228 | static void handle_answer(ipc_callid_t callid, ipc_call_t *data) |
226 | { |
229 | { |
227 | link_t *item; |
230 | link_t *item; |
228 | async_call_t *call; |
231 | async_call_t *call; |
229 | 232 | ||
230 | callid &= ~IPC_CALLID_ANSWERED; |
233 | callid &= ~IPC_CALLID_ANSWERED; |
231 | 234 | ||
232 | futex_down(&ipc_futex); |
235 | futex_down(&ipc_futex); |
233 | for (item = dispatched_calls.next; item != &dispatched_calls; |
236 | for (item = dispatched_calls.next; item != &dispatched_calls; |
234 | item = item->next) { |
237 | item = item->next) { |
235 | call = list_get_instance(item, async_call_t, list); |
238 | call = list_get_instance(item, async_call_t, list); |
236 | if (call->u.callid == callid) { |
239 | if (call->u.callid == callid) { |
237 | list_remove(&call->list); |
240 | list_remove(&call->list); |
238 | futex_up(&ipc_futex); |
241 | futex_up(&ipc_futex); |
- | 242 | if (call->callback) |
|
239 | call->callback(call->private, |
243 | call->callback(call->private, |
240 | IPC_GET_RETVAL(*data), |
244 | IPC_GET_RETVAL(*data), |
241 | data); |
245 | data); |
- | 246 | free(call); |
|
242 | return; |
247 | return; |
243 | } |
248 | } |
244 | } |
249 | } |
245 | futex_up(&ipc_futex); |
250 | futex_up(&ipc_futex); |
246 | printf("Received unidentified answer: %P!!!\n", callid); |
251 | printf("Received unidentified answer: %P!!!\n", callid); |
247 | } |
252 | } |
248 | 253 | ||
249 | 254 | ||
250 | /** One cycle of ipc wait for call call |
255 | /** One cycle of ipc wait for call call |
251 | * |
256 | * |
252 | * - dispatch ASYNC reoutines in the background |
257 | * - dispatch ASYNC reoutines in the background |
253 | * @param call Space where the message is stored |
258 | * @param call Space where the message is stored |
254 | * @param usec Timeout in microseconds |
259 | * @param usec Timeout in microseconds |
255 | * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking) |
260 | * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking) |
256 | * @return Callid of the answer. |
261 | * @return Callid of the answer. |
257 | */ |
262 | */ |
258 | ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags) |
263 | ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags) |
259 | { |
264 | { |
260 | ipc_callid_t callid; |
265 | ipc_callid_t callid; |
261 | 266 | ||
262 | try_dispatch_queued_calls(); |
267 | try_dispatch_queued_calls(); |
263 | 268 | ||
264 | callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags); |
269 | callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags); |
265 | /* Handle received answers */ |
270 | /* Handle received answers */ |
266 | if (callid & IPC_CALLID_ANSWERED) |
271 | if (callid & IPC_CALLID_ANSWERED) |
267 | handle_answer(callid, call); |
272 | handle_answer(callid, call); |
268 | 273 | ||
269 | return callid; |
274 | return callid; |
270 | } |
275 | } |
271 | 276 | ||
272 | /** Wait some time for an IPC call. |
277 | /** Wait some time for an IPC call. |
273 | * |
278 | * |
274 | * - dispatch ASYNC reoutines in the background |
279 | * - dispatch ASYNC reoutines in the background |
275 | * @param call Space where the message is stored |
280 | * @param call Space where the message is stored |
276 | * @param usec Timeout in microseconds. |
281 | * @param usec Timeout in microseconds. |
277 | * @return Callid of the answer. |
282 | * @return Callid of the answer. |
278 | */ |
283 | */ |
279 | ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec) |
284 | ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec) |
280 | { |
285 | { |
281 | ipc_callid_t callid; |
286 | ipc_callid_t callid; |
282 | 287 | ||
283 | do { |
288 | do { |
284 | callid = ipc_wait_cycle(call, usec, SYNCH_BLOCKING); |
289 | callid = ipc_wait_cycle(call, usec, SYNCH_BLOCKING); |
285 | } while (callid & IPC_CALLID_ANSWERED); |
290 | } while (callid & IPC_CALLID_ANSWERED); |
286 | 291 | ||
287 | return callid; |
292 | return callid; |
288 | } |
293 | } |
289 | 294 | ||
290 | /** Check if there is an IPC call waiting to be picked up. |
295 | /** Check if there is an IPC call waiting to be picked up. |
291 | * |
296 | * |
292 | * - dispatch ASYNC reoutines in the background |
297 | * - dispatch ASYNC reoutines in the background |
293 | * @param call Space where the message is stored |
298 | * @param call Space where the message is stored |
294 | * @return Callid of the answer. |
299 | * @return Callid of the answer. |
295 | */ |
300 | */ |
296 | ipc_callid_t ipc_trywait_for_call(ipc_call_t *call) |
301 | ipc_callid_t ipc_trywait_for_call(ipc_call_t *call) |
297 | { |
302 | { |
298 | ipc_callid_t callid; |
303 | ipc_callid_t callid; |
299 | 304 | ||
300 | do { |
305 | do { |
301 | callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT, SYNCH_NON_BLOCKING); |
306 | callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT, SYNCH_NON_BLOCKING); |
302 | } while (callid & IPC_CALLID_ANSWERED); |
307 | } while (callid & IPC_CALLID_ANSWERED); |
303 | 308 | ||
304 | return callid; |
309 | return callid; |
305 | } |
310 | } |
306 | 311 | ||
307 | /** Ask destination to do a callback connection |
312 | /** Ask destination to do a callback connection |
308 | * |
313 | * |
309 | * @return 0 - OK, error code |
314 | * @return 0 - OK, error code |
310 | */ |
315 | */ |
311 | int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phone) |
316 | int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phone) |
312 | { |
317 | { |
313 | return ipc_call_sync_3(phoneid, IPC_M_CONNECT_TO_ME, arg1, |
318 | return ipc_call_sync_3(phoneid, IPC_M_CONNECT_TO_ME, arg1, |
314 | arg2, 0, 0, 0, phone); |
319 | arg2, 0, 0, 0, phone); |
315 | } |
320 | } |
316 | 321 | ||
317 | /** Ask through phone for a new connection to some service |
322 | /** Ask through phone for a new connection to some service |
318 | * |
323 | * |
319 | * @return new phoneid - OK, error code |
324 | * @return new phoneid - OK, error code |
320 | */ |
325 | */ |
321 | int ipc_connect_me_to(int phoneid, int arg1, int arg2) |
326 | int ipc_connect_me_to(int phoneid, int arg1, int arg2) |
322 | { |
327 | { |
323 | ipcarg_t newphid; |
328 | ipcarg_t newphid; |
324 | int res; |
329 | int res; |
325 | 330 | ||
326 | res = ipc_call_sync_3(phoneid, IPC_M_CONNECT_ME_TO, arg1, |
331 | res = ipc_call_sync_3(phoneid, IPC_M_CONNECT_ME_TO, arg1, |
327 | arg2, 0, 0, 0, &newphid); |
332 | arg2, 0, 0, 0, &newphid); |
328 | if (res) |
333 | if (res) |
329 | return res; |
334 | return res; |
330 | return newphid; |
335 | return newphid; |
331 | } |
336 | } |
332 | 337 | ||
333 | /* Hang up specified phone */ |
338 | /* Hang up specified phone */ |
334 | int ipc_hangup(int phoneid) |
339 | int ipc_hangup(int phoneid) |
335 | { |
340 | { |
336 | return __SYSCALL1(SYS_IPC_HANGUP, phoneid); |
341 | return __SYSCALL1(SYS_IPC_HANGUP, phoneid); |
337 | } |
342 | } |
338 | 343 | ||
339 | int ipc_register_irq(int irq, irq_code_t *ucode) |
344 | int ipc_register_irq(int irq, irq_code_t *ucode) |
340 | { |
345 | { |
341 | return __SYSCALL2(SYS_IPC_REGISTER_IRQ, irq, (sysarg_t) ucode); |
346 | return __SYSCALL2(SYS_IPC_REGISTER_IRQ, irq, (sysarg_t) ucode); |
342 | } |
347 | } |
343 | 348 | ||
344 | int ipc_unregister_irq(int irq) |
349 | int ipc_unregister_irq(int irq) |
345 | { |
350 | { |
346 | return __SYSCALL1(SYS_IPC_UNREGISTER_IRQ, irq); |
351 | return __SYSCALL1(SYS_IPC_UNREGISTER_IRQ, irq); |
347 | } |
352 | } |
348 | 353 | ||
349 | int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1) |
354 | int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1) |
350 | { |
355 | { |
351 | return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1); |
356 | return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1); |
352 | } |
357 | } |
353 | 358 | ||
354 | 359 | ||
355 | /** Open shared memory connection over specified phoneid |
360 | /** Open shared memory connection over specified phoneid |
356 | * |
361 | * |
357 | * |
362 | * |
358 | * Allocate as_area, notify the other side about our intention |
363 | * Allocate as_area, notify the other side about our intention |
359 | * to open the connection |
364 | * to open the connection |
360 | * |
365 | * |
361 | * @return Connection id identifying this connection |
366 | * @return Connection id identifying this connection |
362 | */ |
367 | */ |
363 | //int ipc_dgr_open(int pohoneid, size_t bufsize) |
368 | //int ipc_dgr_open(int pohoneid, size_t bufsize) |
364 | //{ |
369 | //{ |
365 | /* Find new file descriptor in local descriptor table */ |
370 | /* Find new file descriptor in local descriptor table */ |
366 | /* Create AS_area, initialize structures */ |
371 | /* Create AS_area, initialize structures */ |
367 | /* Send AS to other side, handle error states */ |
372 | /* Send AS to other side, handle error states */ |
368 | 373 | ||
369 | //} |
374 | //} |
370 | /* |
375 | /* |
371 | void ipc_dgr_close(int cid) |
376 | void ipc_dgr_close(int cid) |
372 | { |
377 | { |
373 | } |
378 | } |
374 | 379 | ||
375 | void * ipc_dgr_alloc(int cid, size_t size) |
380 | void * ipc_dgr_alloc(int cid, size_t size) |
376 | { |
381 | { |
377 | } |
382 | } |
378 | 383 | ||
379 | void ipc_dgr_free(int cid, void *area) |
384 | void ipc_dgr_free(int cid, void *area) |
380 | { |
385 | { |
381 | 386 | ||
382 | } |
387 | } |
383 | 388 | ||
384 | int ipc_dgr_send(int cid, void *area) |
389 | int ipc_dgr_send(int cid, void *area) |
385 | { |
390 | { |
386 | } |
391 | } |
387 | 392 | ||
388 | 393 | ||
389 | int ipc_dgr_send_data(int cid, void *data, size_t size) |
394 | int ipc_dgr_send_data(int cid, void *data, size_t size) |
390 | { |
395 | { |
391 | } |
396 | } |
392 | 397 | ||
393 | */ |
398 | */ |
394 | 399 |