Subversion Repositories HelenOS

Rev

Rev 4345 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
954 palkovsky 1
/*
2071 jermar 2
 * Copyright (c) 2006 Ondrej Palkovsky
954 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.
1653 cejka 27
 */
28
 
1866 jermar 29
/** @addtogroup libcipc
1653 cejka 30
 * @{
31
 */
32
/** @file
4691 svoboda 33
 */
954 palkovsky 34
 
1866 jermar 35
#ifndef LIBIPC_IPC_H_
36
#define LIBIPC_IPC_H_
954 palkovsky 37
 
4691 svoboda 38
#include <task.h>
954 palkovsky 39
#include <kernel/ipc/ipc.h>
2089 decky 40
#include <kernel/ddi/irq.h>
2541 jermar 41
#include <sys/types.h>
1392 palkovsky 42
#include <kernel/synch/synch.h>
954 palkovsky 43
 
4691 svoboda 44
#define IPC_FLAG_BLOCKING  0x01
45
 
999 palkovsky 46
typedef sysarg_t ipcarg_t;
4691 svoboda 47
 
1006 palkovsky 48
typedef struct {
1091 palkovsky 49
    ipcarg_t args[IPC_CALL_LEN];
1336 jermar 50
    ipcarg_t in_phone_hash;
2089 decky 51
} ipc_call_t;
4691 svoboda 52
 
954 palkovsky 53
typedef sysarg_t ipc_callid_t;
54
 
4341 svoboda 55
typedef void (* ipc_async_callback_t)(void *, int, ipc_call_t *);
954 palkovsky 56
 
2615 jermar 57
/*
58
 * User-friendly wrappers for ipc_call_sync_fast() and ipc_call_sync_slow().
59
 * They are in the form ipc_call_sync_m_n(), where m denotes the number of
60
 * arguments of payload and n denotes number of return values. Whenever
61
 * possible, the fast version is used.
62
 */
63
#define ipc_call_sync_0_0(phoneid, method) \
4691 svoboda 64
    ipc_call_sync_fast((phoneid), (method), 0, 0, 0, 0, 0, 0, 0, 0)
2615 jermar 65
#define ipc_call_sync_0_1(phoneid, method, res1) \
4691 svoboda 66
    ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), 0, 0, 0, 0)
2615 jermar 67
#define ipc_call_sync_0_2(phoneid, method, res1, res2) \
4691 svoboda 68
    ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), 0, 0, 0)
2615 jermar 69
#define ipc_call_sync_0_3(phoneid, method, res1, res2, res3) \
4691 svoboda 70
    ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
71
        0, 0)
2615 jermar 72
#define ipc_call_sync_0_4(phoneid, method, res1, res2, res3, res4) \
4691 svoboda 73
    ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
74
        (res4), 0)
2615 jermar 75
#define ipc_call_sync_0_5(phoneid, method, res1, res2, res3, res4, res5) \
4691 svoboda 76
    ipc_call_sync_fast((phoneid), (method), 0, 0, 0, (res1), (res2), (res3), \
77
        (res4), (res5))
78
 
2615 jermar 79
#define ipc_call_sync_1_0(phoneid, method, arg1) \
4691 svoboda 80
    ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, 0, 0, 0, 0, 0)
2615 jermar 81
#define ipc_call_sync_1_1(phoneid, method, arg1, res1) \
4691 svoboda 82
    ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), 0, 0, 0, 0)
2615 jermar 83
#define ipc_call_sync_1_2(phoneid, method, arg1, res1, res2) \
4691 svoboda 84
    ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), 0, \
85
        0, 0)
2615 jermar 86
#define ipc_call_sync_1_3(phoneid, method, arg1, res1, res2, res3) \
4691 svoboda 87
    ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
88
        (res3), 0, 0)
2615 jermar 89
#define ipc_call_sync_1_4(phoneid, method, arg1, res1, res2, res3, res4) \
4691 svoboda 90
    ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
91
        (res3), (res4), 0)
2615 jermar 92
#define ipc_call_sync_1_5(phoneid, method, arg1, res1, res2, res3, res4, \
93
    res5) \
94
    ipc_call_sync_fast((phoneid), (method), (arg1), 0, 0, (res1), (res2), \
95
        (res3), (res4), (res5))
4691 svoboda 96
 
2615 jermar 97
#define ipc_call_sync_2_0(phoneid, method, arg1, arg2) \
4691 svoboda 98
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, 0, 0, 0, \
99
        0, 0)
2615 jermar 100
#define ipc_call_sync_2_1(phoneid, method, arg1, arg2, res1) \
4691 svoboda 101
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), 0, 0, \
102
        0, 0)
2615 jermar 103
#define ipc_call_sync_2_2(phoneid, method, arg1, arg2, res1, res2) \
4691 svoboda 104
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
105
        (res2), 0, 0, 0)
2615 jermar 106
#define ipc_call_sync_2_3(phoneid, method, arg1, arg2, res1, res2, res3) \
4691 svoboda 107
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
108
        (res2), (res3), 0, 0)
2615 jermar 109
#define ipc_call_sync_2_4(phoneid, method, arg1, arg2, res1, res2, res3, \
110
    res4) \
111
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
112
        (res2), (res3), (res4), 0)
113
#define ipc_call_sync_2_5(phoneid, method, arg1, arg2, res1, res2, res3, \
114
    res4, res5)\
115
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), 0, (res1), \
116
        (res2), (res3), (res4), (res5))
4691 svoboda 117
 
2615 jermar 118
#define ipc_call_sync_3_0(phoneid, method, arg1, arg2, arg3) \
4691 svoboda 119
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, 0, 0, \
120
        0, 0)
2615 jermar 121
#define ipc_call_sync_3_1(phoneid, method, arg1, arg2, arg3, res1) \
4691 svoboda 122
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), (res1), \
123
        0, 0, 0, 0)
2615 jermar 124
#define ipc_call_sync_3_2(phoneid, method, arg1, arg2, arg3, res1, res2) \
4691 svoboda 125
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), (res1), \
126
        (res2), 0, 0, 0)
2615 jermar 127
#define ipc_call_sync_3_3(phoneid, method, arg1, arg2, arg3, res1, res2, \
128
    res3) \
129
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
130
        (res1), (res2), (res3), 0, 0)
131
#define ipc_call_sync_3_4(phoneid, method, arg1, arg2, arg3, res1, res2, \
132
    res3, res4) \
133
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
134
        (res1), (res2), (res3), (res4), 0)
135
#define ipc_call_sync_3_5(phoneid, method, arg1, arg2, arg3, res1, res2, \
136
    res3, res4, res5) \
137
    ipc_call_sync_fast((phoneid), (method), (arg1), (arg2), (arg3), \
138
        (res1), (res2), (res3), (res4), (res5))
4691 svoboda 139
 
2615 jermar 140
#define ipc_call_sync_4_0(phoneid, method, arg1, arg2, arg3, arg4) \
4691 svoboda 141
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
142
        0, 0, 0, 0, 0)
2615 jermar 143
#define ipc_call_sync_4_1(phoneid, method, arg1, arg2, arg3, arg4, res1) \
4691 svoboda 144
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
145
        (res1), 0, 0, 0, 0)
2615 jermar 146
#define ipc_call_sync_4_2(phoneid, method, arg1, arg2, arg3, arg4, res1, res2) \
4691 svoboda 147
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), 0, \
148
        (res1), (res2), 0, 0, 0)
2615 jermar 149
#define ipc_call_sync_4_3(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
150
    res3) \
151
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
2814 jermar 152
        (arg4), 0, (res1), (res2), (res3), 0, 0)
2615 jermar 153
#define ipc_call_sync_4_4(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
154
    res3, res4) \
155
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
2814 jermar 156
        (arg4), 0, (res1), (res2), (res3), (res4), 0)
2615 jermar 157
#define ipc_call_sync_4_5(phoneid, method, arg1, arg2, arg3, arg4, res1, res2, \
158
    res3, res4, res5) \
159
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
2814 jermar 160
        (arg4), 0, (res1), (res2), (res3), (res4), (res5))
4691 svoboda 161
 
2615 jermar 162
#define ipc_call_sync_5_0(phoneid, method, arg1, arg2, arg3, arg4, arg5) \
4691 svoboda 163
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), \
164
        (arg5), 0, 0, 0, 0, 0)
2615 jermar 165
#define ipc_call_sync_5_1(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1) \
4691 svoboda 166
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), \
167
        (arg5), (res1), 0, 0, 0, 0)
2615 jermar 168
#define ipc_call_sync_5_2(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
169
    res2) \
170
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
171
        (arg4), (arg5), (res1), (res2), 0, 0, 0)
172
#define ipc_call_sync_5_3(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
173
    res2, res3) \
174
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
175
        (arg4), (arg5), (res1), (res2), (res3), 0, 0)
176
#define ipc_call_sync_5_4(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
177
    res2, res3, res4) \
178
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
179
        (arg4), (arg5), (res1), (res2), (res3), (res4), 0)
180
#define ipc_call_sync_5_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, res1, \
181
    res2, res3, res4, res5) \
182
    ipc_call_sync_slow((phoneid), (method), (arg1), (arg2), (arg3), \
183
        (arg4), (arg5), (res1), (res2), (res3), (res4), (res5))
184
 
4341 svoboda 185
extern int ipc_call_sync_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t,
186
    ipcarg_t *, ipcarg_t *, ipcarg_t *, ipcarg_t *, ipcarg_t *);
966 palkovsky 187
 
4341 svoboda 188
extern int ipc_call_sync_slow(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t,
189
    ipcarg_t, ipcarg_t, ipcarg_t *, ipcarg_t *, ipcarg_t *, ipcarg_t *,
190
    ipcarg_t *);
966 palkovsky 191
 
4341 svoboda 192
extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, uint32_t, int);
193
extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, uint32_t);
4691 svoboda 194
 
1392 palkovsky 195
static inline ipc_callid_t ipc_wait_for_call(ipc_call_t *data)
196
{
197
    return ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT);
198
}
4691 svoboda 199
 
4341 svoboda 200
extern ipc_callid_t ipc_trywait_for_call(ipc_call_t *);
1365 jermar 201
 
2619 jermar 202
/*
203
 * User-friendly wrappers for ipc_answer_fast() and ipc_answer_slow().
204
 * They are in the form of ipc_answer_m(), where m is the number of return
205
 * arguments. The macros decide between the fast and the slow version according
206
 * to m.
207
 */
208
#define ipc_answer_0(callid, retval) \
4691 svoboda 209
    ipc_answer_fast((callid), (retval), 0, 0, 0, 0)
2619 jermar 210
#define ipc_answer_1(callid, retval, arg1) \
4691 svoboda 211
    ipc_answer_fast((callid), (retval), (arg1), 0, 0, 0)
2619 jermar 212
#define ipc_answer_2(callid, retval, arg1, arg2) \
4691 svoboda 213
    ipc_answer_fast((callid), (retval), (arg1), (arg2), 0, 0)
2619 jermar 214
#define ipc_answer_3(callid, retval, arg1, arg2, arg3) \
4691 svoboda 215
    ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), 0)
2619 jermar 216
#define ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4) \
4691 svoboda 217
    ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), (arg4))
2619 jermar 218
#define ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5) \
4691 svoboda 219
    ipc_answer_slow((callid), (retval), (arg1), (arg2), (arg3), (arg4), (arg5))
2619 jermar 220
 
4341 svoboda 221
extern ipcarg_t ipc_answer_fast(ipc_callid_t, ipcarg_t, ipcarg_t, ipcarg_t,
222
    ipcarg_t, ipcarg_t);
223
extern ipcarg_t ipc_answer_slow(ipc_callid_t, ipcarg_t, ipcarg_t, ipcarg_t,
224
    ipcarg_t, ipcarg_t, ipcarg_t);
954 palkovsky 225
 
2618 jermar 226
/*
227
 * User-friendly wrappers for ipc_call_async_fast() and ipc_call_async_slow().
228
 * They are in the form of ipc_call_async_m(), where m is the number of payload
229
 * arguments. The macros decide between the fast and the slow version according
230
 * to m.
231
 */
4341 svoboda 232
#define ipc_call_async_0(phoneid, method, private, callback, can_preempt) \
2618 jermar 233
    ipc_call_async_fast((phoneid), (method), 0, 0, 0, 0, (private), \
234
        (callback), (can_preempt))
235
#define ipc_call_async_1(phoneid, method, arg1, private, callback, \
236
    can_preempt) \
237
    ipc_call_async_fast((phoneid), (method), (arg1), 0, 0, 0, (private), \
238
        (callback), (can_preempt))
239
#define ipc_call_async_2(phoneid, method, arg1, arg2, private, callback, \
240
    can_preempt) \
241
    ipc_call_async_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
242
        (private), (callback), (can_preempt))
243
#define ipc_call_async_3(phoneid, method, arg1, arg2, arg3, private, callback, \
244
    can_preempt) \
245
    ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \
246
        (private), (callback), (can_preempt))
247
#define ipc_call_async_4(phoneid, method, arg1, arg2, arg3, arg4, private, \
248
    callback, can_preempt) \
249
    ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), \
250
        (arg4), (private), (callback), (can_preempt))
251
#define ipc_call_async_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, \
252
    private, callback, can_preempt) \
253
    ipc_call_async_slow((phoneid), (method), (arg1), (arg2), (arg3), \
254
        (arg4), (arg5), (private), (callback), (can_preempt))
1518 palkovsky 255
 
4341 svoboda 256
extern void ipc_call_async_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t,
257
    ipcarg_t, void *, ipc_async_callback_t, int);
258
extern void ipc_call_async_slow(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t,
259
    ipcarg_t, ipcarg_t, void *, ipc_async_callback_t, int);
2618 jermar 260
 
4341 svoboda 261
extern int ipc_connect_to_me(int, int, int, int, ipcarg_t *);
262
extern int ipc_connect_me_to(int, int, int, int);
4345 svoboda 263
extern int ipc_connect_me_to_blocking(int, int, int, int);
4341 svoboda 264
extern int ipc_hangup(int);
265
extern int ipc_register_irq(int, int, int, irq_code_t *);
266
extern int ipc_unregister_irq(int, int);
267
extern int ipc_forward_fast(ipc_callid_t, int, int, ipcarg_t, ipcarg_t, int);
268
extern int ipc_forward_slow(ipc_callid_t, int, int, ipcarg_t, ipcarg_t,
4691 svoboda 269
    ipcarg_t, ipcarg_t, ipcarg_t, int);
2662 jermar 270
 
2677 jermar 271
/*
2678 jermar 272
 * User-friendly wrappers for ipc_share_in_start().
2677 jermar 273
 */
2678 jermar 274
#define ipc_share_in_start_0_0(phoneid, dst, size) \
4691 svoboda 275
    ipc_share_in_start((phoneid), (dst), (size), 0, NULL)
2678 jermar 276
#define ipc_share_in_start_0_1(phoneid, dst, size, flags) \
4691 svoboda 277
    ipc_share_in_start((phoneid), (dst), (size), 0, (flags))
2678 jermar 278
#define ipc_share_in_start_1_0(phoneid, dst, size, arg) \
4691 svoboda 279
    ipc_share_in_start((phoneid), (dst), (size), (arg), NULL)
2678 jermar 280
#define ipc_share_in_start_1_1(phoneid, dst, size, arg, flags) \
4691 svoboda 281
    ipc_share_in_start((phoneid), (dst), (size), (arg), (flags))
2677 jermar 282
 
4341 svoboda 283
extern int ipc_share_in_start(int, void *, size_t, ipcarg_t, int *);
284
extern int ipc_share_in_receive(ipc_callid_t *, size_t *);
285
extern int ipc_share_in_finalize(ipc_callid_t, void *, int );
286
extern int ipc_share_out_start(int, void *, int);
287
extern int ipc_share_out_receive(ipc_callid_t *, size_t *, int *);
288
extern int ipc_share_out_finalize(ipc_callid_t, void *);
289
extern int ipc_data_read_start(int, void *, size_t);
290
extern int ipc_data_read_receive(ipc_callid_t *, size_t *);
291
extern int ipc_data_read_finalize(ipc_callid_t, const void *, size_t);
292
extern int ipc_data_write_start(int, const void *, size_t);
293
extern int ipc_data_write_receive(ipc_callid_t *, size_t *);
294
extern int ipc_data_write_finalize(ipc_callid_t, void *, size_t);
2522 jermar 295
 
4341 svoboda 296
extern int ipc_connect_kbox(task_id_t);
3448 svoboda 297
 
954 palkovsky 298
#endif
1653 cejka 299
 
1866 jermar 300
/** @}
1653 cejka 301
 */