1 | /*
|
---|
2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup libcipc
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | */
|
---|
34 |
|
---|
35 | #if ((defined(LIBC_ASYNC_H_)) && (!defined(LIBC_ASYNC_C_)))
|
---|
36 | #error Do not intermix low-level IPC interface and async framework
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #ifndef LIBC_IPC_H_
|
---|
40 | #define LIBC_IPC_H_
|
---|
41 |
|
---|
42 | #include <sys/types.h>
|
---|
43 | #include <ipc/common.h>
|
---|
44 | #include <abi/ipc/methods.h>
|
---|
45 | #include <abi/synch.h>
|
---|
46 | #include <task.h>
|
---|
47 |
|
---|
48 | typedef void (*ipc_async_callback_t)(void *, int, ipc_call_t *);
|
---|
49 |
|
---|
50 | /*
|
---|
51 | * User-friendly wrappers for ipc_call_sync_fast() and ipc_call_sync_slow().
|
---|
52 | * They are in the form ipc_call_sync_m_n(), where m denotes the number of
|
---|
53 | * arguments of payload and n denotes number of return values. Whenever
|
---|
54 | * possible, the fast version is used.
|
---|
55 | */
|
---|
56 |
|
---|
57 | #define ipc_call_sync_0_0(phoneid, method) \
|
---|
58 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, 0, 0, 0, 0, 0)
|
---|
59 | #define ipc_call_sync_0_1(phoneid, method, res1) \
|
---|
60 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), 0, 0, 0, 0)
|
---|
61 | #define ipc_call_sync_0_2(phoneid, method, res1, res2) \
|
---|
62 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), 0, 0, 0)
|
---|
63 | #define ipc_call_sync_0_3(phoneid, method, res1, res2, res3) \
|
---|
64 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
|
---|
65 | 0, 0)
|
---|
66 | #define ipc_call_sync_0_4(phoneid, method, res1, res2, res3, res4) \
|
---|
67 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
|
---|
68 | (res4), 0)
|
---|
69 | #define ipc_call_sync_0_5(phoneid, method, res1, res2, res3, res4, res5) \
|
---|
70 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
|
---|
71 | (res4), (res5))
|
---|
72 |
|
---|
73 | #define ipc_call_sync_1_0(phoneid, method, arg1) \
|
---|
74 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, 0, 0, 0, 0, 0)
|
---|
75 | #define ipc_call_sync_1_1(phoneid, method, arg1, res1) \
|
---|
76 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), 0, 0, 0, 0)
|
---|
77 | #define ipc_call_sync_1_2(phoneid, method, arg1, res1, res2) \
|
---|
78 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), 0, \
|
---|
79 | 0, 0)
|
---|
80 | #define ipc_call_sync_1_3(phoneid, method, arg1, res1, res2, res3) \
|
---|
81 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
|
---|
82 | (res3), 0, 0)
|
---|
83 | #define ipc_call_sync_1_4(phoneid, method, arg1, res1, res2, res3, res4) \
|
---|
84 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
|
---|
85 | (res3), (res4), 0)
|
---|
86 | #define ipc_call_sync_1_5(phoneid, method, arg1, res1, res2, res3, res4, \
|
---|
87 | res5) \
|
---|
88 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
|
---|
89 | (res3), (res4), (res5))
|
---|
90 |
|
---|
91 | #define ipc_call_sync_2_0(phoneid, method, arg1, arg2) \
|
---|
92 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, 0, 0, 0, \
|
---|
93 | 0, 0)
|
---|
94 | #define ipc_call_sync_2_1(phoneid, method, arg1, arg2, res1) \
|
---|
95 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), 0, 0, \
|
---|
96 | 0, 0)
|
---|
97 | #define ipc_call_sync_2_2(phoneid, method, arg1, arg2, res1, res2) \
|
---|
98 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
|
---|
99 | (res2), 0, 0, 0)
|
---|
100 | #define ipc_call_sync_2_3(phoneid, method, arg1, arg2, res1, res2, res3) \
|
---|
101 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
|
---|
102 | (res2), (res3), 0, 0)
|
---|
103 | #define ipc_call_sync_2_4(phoneid, method, arg1, arg2, res1, res2, res3, \
|
---|
104 | res4) \
|
---|
105 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
|
---|
106 | (res2), (res3), (res4), 0)
|
---|
107 | #define ipc_call_sync_2_5(phoneid, method, arg1, arg2, res1, res2, res3, \
|
---|
108 | res4, res5)\
|
---|
109 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
|
---|
110 | (res2), (res3), (res4), (res5))
|
---|
111 |
|
---|
112 | #define ipc_call_sync_3_0(phoneid, method, arg1, arg2, arg3) \
|
---|
113 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, 0, 0, \
|
---|
114 | 0, 0)
|
---|
115 | #define ipc_call_sync_3_1(phoneid, method, arg1, arg2, arg3, res1) \
|
---|
116 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), (res1), \
|
---|
117 | 0, 0, 0, 0)
|
---|
118 | #define ipc_call_sync_3_2(phoneid, method, arg1, arg2, arg3, res1, res2) \
|
---|
119 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), (res1), \
|
---|
120 | (res2), 0, 0, 0)
|
---|
121 | #define ipc_call_sync_3_3(phoneid, method, arg1, arg2, arg3, res1, res2, \
|
---|
122 | res3) \
|
---|
123 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
124 | (res1), (res2), (res3), 0, 0)
|
---|
125 | #define ipc_call_sync_3_4(phoneid, method, arg1, arg2, arg3, res1, res2, \
|
---|
126 | res3, res4) \
|
---|
127 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
128 | (res1), (res2), (res3), (res4), 0)
|
---|
129 | #define ipc_call_sync_3_5(phoneid, method, arg1, arg2, arg3, res1, res2, \
|
---|
130 | res3, res4, res5) \
|
---|
131 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
132 | (res1), (res2), (res3), (res4), (res5))
|
---|
133 |
|
---|
134 | #define ipc_call_sync_4_0(phoneid, method, arg1, arg2, arg3, arg4) \
|
---|
135 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
|
---|
136 | 0, 0, 0, 0, 0)
|
---|
137 | #define ipc_call_sync_4_1(phoneid, method, arg1, arg2, arg3, arg4, res1) \
|
---|
138 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
|
---|
139 | (res1), 0, 0, 0, 0)
|
---|
140 | #define ipc_call_sync_4_2(phoneid, method, arg1, arg2, arg3, arg4, res1, res2) \
|
---|
141 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
|
---|
142 | (res1), (res2), 0, 0, 0)
|
---|
143 | #define ipc_call_sync_4_3(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
|
---|
144 | res3) \
|
---|
145 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
146 | (arg4), 0, (res1), (res2), (res3), 0, 0)
|
---|
147 | #define ipc_call_sync_4_4(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
|
---|
148 | res3, res4) \
|
---|
149 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
150 | (arg4), 0, (res1), (res2), (res3), (res4), 0)
|
---|
151 | #define ipc_call_sync_4_5(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
|
---|
152 | res3, res4, res5) \
|
---|
153 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
154 | (arg4), 0, (res1), (res2), (res3), (res4), (res5))
|
---|
155 |
|
---|
156 | #define ipc_call_sync_5_0(phoneid, method, arg1, arg2, arg3, arg4, arg5) \
|
---|
157 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), \
|
---|
158 | (arg5), 0, 0, 0, 0, 0)
|
---|
159 | #define ipc_call_sync_5_1(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1) \
|
---|
160 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), \
|
---|
161 | (arg5), (res1), 0, 0, 0, 0)
|
---|
162 | #define ipc_call_sync_5_2(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
|
---|
163 | res2) \
|
---|
164 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
165 | (arg4), (arg5), (res1), (res2), 0, 0, 0)
|
---|
166 | #define ipc_call_sync_5_3(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
|
---|
167 | res2, res3) \
|
---|
168 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
169 | (arg4), (arg5), (res1), (res2), (res3), 0, 0)
|
---|
170 | #define ipc_call_sync_5_4(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
|
---|
171 | res2, res3, res4) \
|
---|
172 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
173 | (arg4), (arg5), (res1), (res2), (res3), (res4), 0)
|
---|
174 | #define ipc_call_sync_5_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
|
---|
175 | res2, res3, res4, res5) \
|
---|
176 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
177 | (arg4), (arg5), (res1), (res2), (res3), (res4), (res5))
|
---|
178 |
|
---|
179 | extern int ipc_call_sync_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
180 | sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *);
|
---|
181 |
|
---|
182 | extern int ipc_call_sync_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
183 | sysarg_t, sysarg_t, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *,
|
---|
184 | sysarg_t *);
|
---|
185 |
|
---|
186 | extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, sysarg_t, unsigned int);
|
---|
187 | extern void ipc_poke(void);
|
---|
188 |
|
---|
189 | #define ipc_wait_for_call(data) \
|
---|
190 | ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT);
|
---|
191 |
|
---|
192 | extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, sysarg_t);
|
---|
193 | extern ipc_callid_t ipc_trywait_for_call(ipc_call_t *);
|
---|
194 |
|
---|
195 | /*
|
---|
196 | * User-friendly wrappers for ipc_answer_fast() and ipc_answer_slow().
|
---|
197 | * They are in the form of ipc_answer_m(), where m is the number of return
|
---|
198 | * arguments. The macros decide between the fast and the slow version according
|
---|
199 | * to m.
|
---|
200 | */
|
---|
201 |
|
---|
202 | #define ipc_answer_0(callid, retval) \
|
---|
203 | ipc_answer_fast((callid), (retval), 0, 0, 0, 0)
|
---|
204 | #define ipc_answer_1(callid, retval, arg1) \
|
---|
205 | ipc_answer_fast((callid), (retval), (arg1), 0, 0, 0)
|
---|
206 | #define ipc_answer_2(callid, retval, arg1, arg2) \
|
---|
207 | ipc_answer_fast((callid), (retval), (arg1), (arg2), 0, 0)
|
---|
208 | #define ipc_answer_3(callid, retval, arg1, arg2, arg3) \
|
---|
209 | ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), 0)
|
---|
210 | #define ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4) \
|
---|
211 | ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), (arg4))
|
---|
212 | #define ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5) \
|
---|
213 | ipc_answer_slow((callid), (retval), (arg1), (arg2), (arg3), (arg4), (arg5))
|
---|
214 |
|
---|
215 | extern sysarg_t ipc_answer_fast(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
216 | sysarg_t, sysarg_t);
|
---|
217 | extern sysarg_t ipc_answer_slow(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
218 | sysarg_t, sysarg_t, sysarg_t);
|
---|
219 |
|
---|
220 | /*
|
---|
221 | * User-friendly wrappers for ipc_call_async_fast() and ipc_call_async_slow().
|
---|
222 | * They are in the form of ipc_call_async_m(), where m is the number of payload
|
---|
223 | * arguments. The macros decide between the fast and the slow version according
|
---|
224 | * to m.
|
---|
225 | */
|
---|
226 |
|
---|
227 | #define ipc_call_async_0(phoneid, method, private, callback, can_preempt) \
|
---|
228 | ipc_call_async_fast((phoneid), (method), 0, 0, 0, 0, (private), \
|
---|
229 | (callback), (can_preempt))
|
---|
230 | #define ipc_call_async_1(phoneid, method, arg1, private, callback, \
|
---|
231 | can_preempt) \
|
---|
232 | ipc_call_async_fast((phoneid), (method), (arg1), 0, 0, 0, (private), \
|
---|
233 | (callback), (can_preempt))
|
---|
234 | #define ipc_call_async_2(phoneid, method, arg1, arg2, private, callback, \
|
---|
235 | can_preempt) \
|
---|
236 | ipc_call_async_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
|
---|
237 | (private), (callback), (can_preempt))
|
---|
238 | #define ipc_call_async_3(phoneid, method, arg1, arg2, arg3, private, callback, \
|
---|
239 | can_preempt) \
|
---|
240 | ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \
|
---|
241 | (private), (callback), (can_preempt))
|
---|
242 | #define ipc_call_async_4(phoneid, method, arg1, arg2, arg3, arg4, private, \
|
---|
243 | callback, can_preempt) \
|
---|
244 | ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
245 | (arg4), (private), (callback), (can_preempt))
|
---|
246 | #define ipc_call_async_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, \
|
---|
247 | private, callback, can_preempt) \
|
---|
248 | ipc_call_async_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
249 | (arg4), (arg5), (private), (callback), (can_preempt))
|
---|
250 |
|
---|
251 | extern void ipc_call_async_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
252 | sysarg_t, void *, ipc_async_callback_t, bool);
|
---|
253 | extern void ipc_call_async_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
254 | sysarg_t, sysarg_t, void *, ipc_async_callback_t, bool);
|
---|
255 |
|
---|
256 | extern int ipc_connect_to_me(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t *,
|
---|
257 | sysarg_t *);
|
---|
258 | extern int ipc_connect_me(int);
|
---|
259 | extern int ipc_connect_me_to(int, sysarg_t, sysarg_t, sysarg_t);
|
---|
260 | extern int ipc_connect_me_to_blocking(int, sysarg_t, sysarg_t, sysarg_t);
|
---|
261 |
|
---|
262 | extern int ipc_hangup(int);
|
---|
263 |
|
---|
264 | extern int ipc_forward_fast(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
|
---|
265 | unsigned int);
|
---|
266 | extern int ipc_forward_slow(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
|
---|
267 | sysarg_t, sysarg_t, sysarg_t, unsigned int);
|
---|
268 |
|
---|
269 | /*
|
---|
270 | * User-friendly wrappers for ipc_share_in_start().
|
---|
271 | */
|
---|
272 |
|
---|
273 | #define ipc_share_in_start_0_0(phoneid, dst, size) \
|
---|
274 | ipc_share_in_start((phoneid), (dst), (size), 0, NULL)
|
---|
275 | #define ipc_share_in_start_0_1(phoneid, dst, size, flags) \
|
---|
276 | ipc_share_in_start((phoneid), (dst), (size), 0, (flags))
|
---|
277 | #define ipc_share_in_start_1_0(phoneid, dst, size, arg) \
|
---|
278 | ipc_share_in_start((phoneid), (dst), (size), (arg), NULL)
|
---|
279 | #define ipc_share_in_start_1_1(phoneid, dst, size, arg, flags) \
|
---|
280 | ipc_share_in_start((phoneid), (dst), (size), (arg), (flags))
|
---|
281 |
|
---|
282 | extern int ipc_share_in_start(int, void *, size_t, sysarg_t, unsigned int *);
|
---|
283 | extern int ipc_share_in_finalize(ipc_callid_t, void *, unsigned int);
|
---|
284 | extern int ipc_share_out_start(int, void *, unsigned int);
|
---|
285 | extern int ipc_share_out_finalize(ipc_callid_t, void *);
|
---|
286 | extern int ipc_data_read_start(int, void *, size_t);
|
---|
287 | extern int ipc_data_read_finalize(ipc_callid_t, const void *, size_t);
|
---|
288 | extern int ipc_data_write_start(int, const void *, size_t);
|
---|
289 | extern int ipc_data_write_finalize(ipc_callid_t, void *, size_t);
|
---|
290 |
|
---|
291 | extern int ipc_connect_kbox(task_id_t);
|
---|
292 |
|
---|
293 | #endif
|
---|
294 |
|
---|
295 | /** @}
|
---|
296 | */
|
---|