Subversion Repositories HelenOS-historic

Rev

Rev 1089 | Rev 1092 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1089 Rev 1091
Line 44... Line 44...
44
    ipc_async_callback_t callback;
44
    ipc_async_callback_t callback;
45
    void *private;
45
    void *private;
46
    union {
46
    union {
47
        ipc_callid_t callid;
47
        ipc_callid_t callid;
48
        struct {
48
        struct {
-
 
49
            ipc_call_t data;
49
            int phoneid;
50
            int phoneid;
50
            ipc_data_t data;
-
 
51
        } msg;
51
        } msg;
52
    }u;
52
    }u;
53
} async_call_t;
53
} async_call_t;
54
 
54
 
55
LIST_INITIALIZE(dispatched_calls);
55
LIST_INITIALIZE(dispatched_calls);
56
LIST_INITIALIZE(queued_calls);
56
LIST_INITIALIZE(queued_calls);
57
 
57
 
58
int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1,
58
int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1,
59
          ipcarg_t *result)
59
          ipcarg_t *result)
60
{
60
{
61
    ipc_data_t resdata;
61
    ipc_call_t resdata;
62
    int callres;
62
    int callres;
63
   
63
   
64
    callres = __SYSCALL4(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
64
    callres = __SYSCALL4(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
65
                 (sysarg_t)&resdata);
65
                 (sysarg_t)&resdata);
66
    if (callres)
66
    if (callres)
Line 72... Line 72...
72
 
72
 
73
int ipc_call_sync_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
73
int ipc_call_sync_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
74
            ipcarg_t arg2, ipcarg_t arg3,
74
            ipcarg_t arg2, ipcarg_t arg3,
75
            ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3)
75
            ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3)
76
{
76
{
77
    ipc_data_t data;
77
    ipc_call_t data;
78
    int callres;
78
    int callres;
79
 
79
 
80
    IPC_SET_METHOD(data, method);
80
    IPC_SET_METHOD(data, method);
81
    IPC_SET_ARG1(data, arg1);
81
    IPC_SET_ARG1(data, arg1);
82
    IPC_SET_ARG2(data, arg2);
82
    IPC_SET_ARG2(data, arg2);
Line 95... Line 95...
95
        *result3 = IPC_GET_ARG3(data);
95
        *result3 = IPC_GET_ARG3(data);
96
    return IPC_GET_RETVAL(data);
96
    return IPC_GET_RETVAL(data);
97
}
97
}
98
 
98
 
99
/** Syscall to send asynchronous message */
99
/** Syscall to send asynchronous message */
100
static  ipc_callid_t _ipc_call_async(int phoneid, ipc_data_t *data)
100
static  ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
101
{
101
{
102
    return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t)data);
102
    return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t)data);
103
}
103
}
104
 
104
 
105
/** Send asynchronous message
105
/** Send asynchronous message
Line 152... Line 152...
152
        ipcarg_t arg2)
152
        ipcarg_t arg2)
153
{
153
{
154
    __SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2);
154
    __SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2);
155
}
155
}
156
 
156
 
157
 
-
 
158
/** Call syscall function sys_ipc_wait_for_call */
-
 
159
static inline ipc_callid_t _ipc_wait_for_call(ipc_call_t *call, int flags)
-
 
160
{
-
 
161
    return __SYSCALL3(SYS_IPC_WAIT, (sysarg_t)&call->data,
-
 
162
              (sysarg_t)&call->taskid, flags);
-
 
163
}
-
 
164
 
-
 
165
/** Try to dispatch queed calls from async queue */
157
/** Try to dispatch queed calls from async queue */
166
static void try_dispatch_queued_calls(void)
158
static void try_dispatch_queued_calls(void)
167
{
159
{
168
    async_call_t *call;
160
    async_call_t *call;
169
    ipc_callid_t callid;
161
    ipc_callid_t callid;
Line 191... Line 183...
191
 *
183
 *
192
 * TODO: Make it use hash table
184
 * TODO: Make it use hash table
193
 *
185
 *
194
 * @param callid Callid (with first bit set) of the answered call
186
 * @param callid Callid (with first bit set) of the answered call
195
 */
187
 */
196
static void handle_answer(ipc_callid_t callid, ipc_data_t *data)
188
static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
197
{
189
{
198
    link_t *item;
190
    link_t *item;
199
    async_call_t *call;
191
    async_call_t *call;
200
 
192
 
201
    callid &= ~IPC_CALLID_ANSWERED;
193
    callid &= ~IPC_CALLID_ANSWERED;
Line 227... Line 219...
227
    ipc_callid_t callid;
219
    ipc_callid_t callid;
228
 
220
 
229
    do {
221
    do {
230
        try_dispatch_queued_calls();
222
        try_dispatch_queued_calls();
231
 
223
 
232
        callid = _ipc_wait_for_call(call, flags);
224
        callid = __SYSCALL2(SYS_IPC_WAIT, (sysarg_t)call, flags);
233
        /* Handle received answers */
225
        /* Handle received answers */
234
        if (callid & IPC_CALLID_ANSWERED)
226
        if (callid & IPC_CALLID_ANSWERED)
235
            handle_answer(callid, &call->data);
227
            handle_answer(callid, call);
236
    } while (callid & IPC_CALLID_ANSWERED);
228
    } while (callid & IPC_CALLID_ANSWERED);
237
 
229
 
238
    return callid;
230
    return callid;
239
}
231
}
240
 
232
 
241
/** Ask destination to do a callback connection */
233
/** Ask destination to do a callback connection
-
 
234
 *
-
 
235
 * @return 0 - OK, error code
-
 
236
 */
242
int ipc_connect_to_me(int phoneid, int arg1, int arg2,
237
int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phone)
243
              unsigned long long *taskid)
-
 
244
{
238
{
245
    return __SYSCALL4(SYS_IPC_CONNECT_TO_ME, phoneid, arg1, arg2,
239
    return ipc_call_sync_3(phoneid, IPC_M_CONNECT_TO_ME, arg1,
246
              (sysarg_t) taskid);
240
                   arg2, 0, 0, 0, phone);
247
}
241
}
248
 
242
 
249
/** Ask through phone for a new connection to some service */
243
/** Ask through phone for a new connection to some service
-
 
244
 *
-
 
245
 * @return new phoneid - OK, error code
-
 
246
 */
250
int ipc_connect_me_to(int phoneid, int arg1, int arg2)
247
int ipc_connect_me_to(int phoneid, int arg1, int arg2)
251
{
248
{
-
 
249
    int newphid;
-
 
250
    int res;
-
 
251
 
252
    return __SYSCALL3(SYS_IPC_CONNECT_ME_TO, phoneid, arg1, arg2);
252
    res =  ipc_call_sync_3(phoneid, IPC_M_CONNECT_ME_TO, arg1,
-
 
253
                   arg2, 0, 0, 0, &newphid);
-
 
254
    if (res)
-
 
255
        return res;
-
 
256
    return newphid;
253
}
257
}
254
 
258
 
255
/* Hang up specified phone */
259
/* Hang up specified phone */
256
int ipc_hangup(int phoneid)
260
int ipc_hangup(int phoneid)
257
{
261
{