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 <kernel/synch/synch.h>
|
---|
45 | #include <task.h>
|
---|
46 |
|
---|
47 | typedef void (*ipc_async_callback_t)(void *, int, ipc_call_t *);
|
---|
48 |
|
---|
49 | /*
|
---|
50 | * User-friendly wrappers for ipc_call_sync_fast() and ipc_call_sync_slow().
|
---|
51 | * They are in the form ipc_call_sync_m_n(), where m denotes the number of
|
---|
52 | * arguments of payload and n denotes number of return values. Whenever
|
---|
53 | * possible, the fast version is used.
|
---|
54 | */
|
---|
55 | #define ipc_call_sync_0_0(phoneid, method) \
|
---|
56 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, 0, 0, 0, 0, 0)
|
---|
57 | #define ipc_call_sync_0_1(phoneid, method, res1) \
|
---|
58 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), 0, 0, 0, 0)
|
---|
59 | #define ipc_call_sync_0_2(phoneid, method, res1, res2) \
|
---|
60 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), 0, 0, 0)
|
---|
61 | #define ipc_call_sync_0_3(phoneid, method, res1, res2, res3) \
|
---|
62 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
|
---|
63 | 0, 0)
|
---|
64 | #define ipc_call_sync_0_4(phoneid, method, res1, res2, res3, res4) \
|
---|
65 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
|
---|
66 | (res4), 0)
|
---|
67 | #define ipc_call_sync_0_5(phoneid, method, res1, res2, res3, res4, res5) \
|
---|
68 | ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
|
---|
69 | (res4), (res5))
|
---|
70 |
|
---|
71 | #define ipc_call_sync_1_0(phoneid, method, arg1) \
|
---|
72 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, 0, 0, 0, 0, 0)
|
---|
73 | #define ipc_call_sync_1_1(phoneid, method, arg1, res1) \
|
---|
74 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), 0, 0, 0, 0)
|
---|
75 | #define ipc_call_sync_1_2(phoneid, method, arg1, res1, res2) \
|
---|
76 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), 0, \
|
---|
77 | 0, 0)
|
---|
78 | #define ipc_call_sync_1_3(phoneid, method, arg1, res1, res2, res3) \
|
---|
79 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
|
---|
80 | (res3), 0, 0)
|
---|
81 | #define ipc_call_sync_1_4(phoneid, method, arg1, res1, res2, res3, res4) \
|
---|
82 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
|
---|
83 | (res3), (res4), 0)
|
---|
84 | #define ipc_call_sync_1_5(phoneid, method, arg1, res1, res2, res3, res4, \
|
---|
85 | res5) \
|
---|
86 | ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
|
---|
87 | (res3), (res4), (res5))
|
---|
88 |
|
---|
89 | #define ipc_call_sync_2_0(phoneid, method, arg1, arg2) \
|
---|
90 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, 0, 0, 0, \
|
---|
91 | 0, 0)
|
---|
92 | #define ipc_call_sync_2_1(phoneid, method, arg1, arg2, res1) \
|
---|
93 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), 0, 0, \
|
---|
94 | 0, 0)
|
---|
95 | #define ipc_call_sync_2_2(phoneid, method, arg1, arg2, res1, res2) \
|
---|
96 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
|
---|
97 | (res2), 0, 0, 0)
|
---|
98 | #define ipc_call_sync_2_3(phoneid, method, arg1, arg2, res1, res2, res3) \
|
---|
99 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
|
---|
100 | (res2), (res3), 0, 0)
|
---|
101 | #define ipc_call_sync_2_4(phoneid, method, arg1, arg2, res1, res2, res3, \
|
---|
102 | res4) \
|
---|
103 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
|
---|
104 | (res2), (res3), (res4), 0)
|
---|
105 | #define ipc_call_sync_2_5(phoneid, method, arg1, arg2, res1, res2, res3, \
|
---|
106 | res4, res5)\
|
---|
107 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
|
---|
108 | (res2), (res3), (res4), (res5))
|
---|
109 |
|
---|
110 | #define ipc_call_sync_3_0(phoneid, method, arg1, arg2, arg3) \
|
---|
111 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, 0, 0, \
|
---|
112 | 0, 0)
|
---|
113 | #define ipc_call_sync_3_1(phoneid, method, arg1, arg2, arg3, res1) \
|
---|
114 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), (res1), \
|
---|
115 | 0, 0, 0, 0)
|
---|
116 | #define ipc_call_sync_3_2(phoneid, method, arg1, arg2, arg3, res1, res2) \
|
---|
117 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), (res1), \
|
---|
118 | (res2), 0, 0, 0)
|
---|
119 | #define ipc_call_sync_3_3(phoneid, method, arg1, arg2, arg3, res1, res2, \
|
---|
120 | res3) \
|
---|
121 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
122 | (res1), (res2), (res3), 0, 0)
|
---|
123 | #define ipc_call_sync_3_4(phoneid, method, arg1, arg2, arg3, res1, res2, \
|
---|
124 | res3, res4) \
|
---|
125 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
126 | (res1), (res2), (res3), (res4), 0)
|
---|
127 | #define ipc_call_sync_3_5(phoneid, method, arg1, arg2, arg3, res1, res2, \
|
---|
128 | res3, res4, res5) \
|
---|
129 | ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
130 | (res1), (res2), (res3), (res4), (res5))
|
---|
131 |
|
---|
132 | #define ipc_call_sync_4_0(phoneid, method, arg1, arg2, arg3, arg4) \
|
---|
133 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
|
---|
134 | 0, 0, 0, 0, 0)
|
---|
135 | #define ipc_call_sync_4_1(phoneid, method, arg1, arg2, arg3, arg4, res1) \
|
---|
136 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
|
---|
137 | (res1), 0, 0, 0, 0)
|
---|
138 | #define ipc_call_sync_4_2(phoneid, method, arg1, arg2, arg3, arg4, res1, res2) \
|
---|
139 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
|
---|
140 | (res1), (res2), 0, 0, 0)
|
---|
141 | #define ipc_call_sync_4_3(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
|
---|
142 | res3) \
|
---|
143 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
144 | (arg4), 0, (res1), (res2), (res3), 0, 0)
|
---|
145 | #define ipc_call_sync_4_4(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
|
---|
146 | res3, res4) \
|
---|
147 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
148 | (arg4), 0, (res1), (res2), (res3), (res4), 0)
|
---|
149 | #define ipc_call_sync_4_5(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
|
---|
150 | res3, res4, res5) \
|
---|
151 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
152 | (arg4), 0, (res1), (res2), (res3), (res4), (res5))
|
---|
153 |
|
---|
154 | #define ipc_call_sync_5_0(phoneid, method, arg1, arg2, arg3, arg4, arg5) \
|
---|
155 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), \
|
---|
156 | (arg5), 0, 0, 0, 0, 0)
|
---|
157 | #define ipc_call_sync_5_1(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1) \
|
---|
158 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), \
|
---|
159 | (arg5), (res1), 0, 0, 0, 0)
|
---|
160 | #define ipc_call_sync_5_2(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
|
---|
161 | res2) \
|
---|
162 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
163 | (arg4), (arg5), (res1), (res2), 0, 0, 0)
|
---|
164 | #define ipc_call_sync_5_3(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
|
---|
165 | res2, res3) \
|
---|
166 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
167 | (arg4), (arg5), (res1), (res2), (res3), 0, 0)
|
---|
168 | #define ipc_call_sync_5_4(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
|
---|
169 | res2, res3, res4) \
|
---|
170 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
171 | (arg4), (arg5), (res1), (res2), (res3), (res4), 0)
|
---|
172 | #define ipc_call_sync_5_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
|
---|
173 | res2, res3, res4, res5) \
|
---|
174 | ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
175 | (arg4), (arg5), (res1), (res2), (res3), (res4), (res5))
|
---|
176 |
|
---|
177 | extern int ipc_call_sync_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
178 | sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *);
|
---|
179 |
|
---|
180 | extern int ipc_call_sync_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
181 | sysarg_t, sysarg_t, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *,
|
---|
182 | sysarg_t *);
|
---|
183 |
|
---|
184 | extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, uint32_t, int);
|
---|
185 | extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, uint32_t);
|
---|
186 | extern void ipc_poke(void);
|
---|
187 |
|
---|
188 | static inline ipc_callid_t ipc_wait_for_call(ipc_call_t *data)
|
---|
189 | {
|
---|
190 | return ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT);
|
---|
191 | }
|
---|
192 |
|
---|
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 | #define ipc_answer_0(callid, retval) \
|
---|
202 | ipc_answer_fast((callid), (retval), 0, 0, 0, 0)
|
---|
203 | #define ipc_answer_1(callid, retval, arg1) \
|
---|
204 | ipc_answer_fast((callid), (retval), (arg1), 0, 0, 0)
|
---|
205 | #define ipc_answer_2(callid, retval, arg1, arg2) \
|
---|
206 | ipc_answer_fast((callid), (retval), (arg1), (arg2), 0, 0)
|
---|
207 | #define ipc_answer_3(callid, retval, arg1, arg2, arg3) \
|
---|
208 | ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), 0)
|
---|
209 | #define ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4) \
|
---|
210 | ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), (arg4))
|
---|
211 | #define ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5) \
|
---|
212 | ipc_answer_slow((callid), (retval), (arg1), (arg2), (arg3), (arg4), (arg5))
|
---|
213 |
|
---|
214 | extern sysarg_t ipc_answer_fast(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
215 | sysarg_t, sysarg_t);
|
---|
216 | extern sysarg_t ipc_answer_slow(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
217 | sysarg_t, sysarg_t, sysarg_t);
|
---|
218 |
|
---|
219 | /*
|
---|
220 | * User-friendly wrappers for ipc_call_async_fast() and ipc_call_async_slow().
|
---|
221 | * They are in the form of ipc_call_async_m(), where m is the number of payload
|
---|
222 | * arguments. The macros decide between the fast and the slow version according
|
---|
223 | * to m.
|
---|
224 | */
|
---|
225 | #define ipc_call_async_0(phoneid, method, private, callback, can_preempt) \
|
---|
226 | ipc_call_async_fast((phoneid), (method), 0, 0, 0, 0, (private), \
|
---|
227 | (callback), (can_preempt))
|
---|
228 | #define ipc_call_async_1(phoneid, method, arg1, private, callback, \
|
---|
229 | can_preempt) \
|
---|
230 | ipc_call_async_fast((phoneid), (method), (arg1), 0, 0, 0, (private), \
|
---|
231 | (callback), (can_preempt))
|
---|
232 | #define ipc_call_async_2(phoneid, method, arg1, arg2, private, callback, \
|
---|
233 | can_preempt) \
|
---|
234 | ipc_call_async_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
|
---|
235 | (private), (callback), (can_preempt))
|
---|
236 | #define ipc_call_async_3(phoneid, method, arg1, arg2, arg3, private, callback, \
|
---|
237 | can_preempt) \
|
---|
238 | ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \
|
---|
239 | (private), (callback), (can_preempt))
|
---|
240 | #define ipc_call_async_4(phoneid, method, arg1, arg2, arg3, arg4, private, \
|
---|
241 | callback, can_preempt) \
|
---|
242 | ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
243 | (arg4), (private), (callback), (can_preempt))
|
---|
244 | #define ipc_call_async_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, \
|
---|
245 | private, callback, can_preempt) \
|
---|
246 | ipc_call_async_slow((phoneid), (method), (arg1), (arg2), (arg3), \
|
---|
247 | (arg4), (arg5), (private), (callback), (can_preempt))
|
---|
248 |
|
---|
249 | extern void ipc_call_async_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
250 | sysarg_t, void *, ipc_async_callback_t, int);
|
---|
251 | extern void ipc_call_async_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
252 | sysarg_t, sysarg_t, void *, ipc_async_callback_t, int);
|
---|
253 |
|
---|
254 | extern int ipc_connect_to_me(int, int, int, int, sysarg_t *, sysarg_t *);
|
---|
255 | extern int ipc_connect_me_to(int, int, int, int);
|
---|
256 | extern int ipc_connect_me_to_blocking(int, int, int, int);
|
---|
257 | extern int ipc_hangup(int);
|
---|
258 | extern int ipc_forward_fast(ipc_callid_t, int, int, sysarg_t, sysarg_t, int);
|
---|
259 | extern int ipc_forward_slow(ipc_callid_t, int, int, sysarg_t, sysarg_t,
|
---|
260 | sysarg_t, sysarg_t, sysarg_t, int);
|
---|
261 |
|
---|
262 | /*
|
---|
263 | * User-friendly wrappers for ipc_share_in_start().
|
---|
264 | */
|
---|
265 | #define ipc_share_in_start_0_0(phoneid, dst, size) \
|
---|
266 | ipc_share_in_start((phoneid), (dst), (size), 0, NULL)
|
---|
267 | #define ipc_share_in_start_0_1(phoneid, dst, size, flags) \
|
---|
268 | ipc_share_in_start((phoneid), (dst), (size), 0, (flags))
|
---|
269 | #define ipc_share_in_start_1_0(phoneid, dst, size, arg) \
|
---|
270 | ipc_share_in_start((phoneid), (dst), (size), (arg), NULL)
|
---|
271 | #define ipc_share_in_start_1_1(phoneid, dst, size, arg, flags) \
|
---|
272 | ipc_share_in_start((phoneid), (dst), (size), (arg), (flags))
|
---|
273 |
|
---|
274 | extern int ipc_share_in_start(int, void *, size_t, sysarg_t, int *);
|
---|
275 | extern int ipc_share_in_finalize(ipc_callid_t, void *, int );
|
---|
276 | extern int ipc_share_out_start(int, void *, int);
|
---|
277 | extern int ipc_share_out_finalize(ipc_callid_t, void *);
|
---|
278 | extern int ipc_data_read_start(int, void *, size_t);
|
---|
279 | extern int ipc_data_read_finalize(ipc_callid_t, const void *, size_t);
|
---|
280 | extern int ipc_data_write_start(int, const void *, size_t);
|
---|
281 | extern int ipc_data_write_finalize(ipc_callid_t, void *, size_t);
|
---|
282 |
|
---|
283 | extern int ipc_connect_kbox(task_id_t);
|
---|
284 |
|
---|
285 | #endif
|
---|
286 |
|
---|
287 | /** @}
|
---|
288 | */
|
---|