Subversion Repositories HelenOS-historic

Rev

Rev 1365 | Rev 1443 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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