Rev 960 | Rev 999 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 960 | Rev 966 | ||
---|---|---|---|
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.h> |
29 | #include <ipc.h> |
30 | #include <libc.h> |
30 | #include <libc.h> |
31 | 31 | ||
32 | int ipc_call_sync(int phoneid, int arg1, int arg2, ipc_data_t *resdata) |
32 | int ipc_call_sync(int phoneid, sysarg_t method, sysarg_t arg1, |
- | 33 | sysarg_t *result) |
|
33 | { |
34 | { |
- | 35 | ipc_data_t resdata; |
|
- | 36 | int callres; |
|
- | 37 | ||
34 | return __SYSCALL4(SYS_IPC_CALL_SYNC, phoneid, arg1, arg2, |
38 | callres = __SYSCALL4(SYS_IPC_CALL_SYNC, phoneid, method, arg1, |
35 | (sysarg_t)resdata); |
39 | (sysarg_t)&resdata); |
- | 40 | if (callres) |
|
- | 41 | return callres; |
|
- | 42 | if (result) |
|
- | 43 | *result = IPC_GET_ARG1(resdata); |
|
- | 44 | return IPC_GET_RETVAL(resdata); |
|
36 | } |
45 | } |
37 | 46 | ||
38 | /* |
- | |
- | 47 | int ipc_call_sync_3(int phoneid, sysarg_t method, sysarg_t arg1, |
|
39 | int ipc_call_async() |
48 | sysarg_t arg2, sysarg_t arg3, |
- | 49 | sysarg_t *result1, sysarg_t *result2, sysarg_t *result3) |
|
40 | { |
50 | { |
- | 51 | ipc_data_t data; |
|
- | 52 | int callres; |
|
- | 53 | ||
- | 54 | IPC_SET_METHOD(data, method); |
|
- | 55 | IPC_SET_ARG1(data, arg1); |
|
- | 56 | IPC_SET_ARG2(data, arg2); |
|
- | 57 | IPC_SET_ARG3(data, arg3); |
|
- | 58 | ||
- | 59 | callres = __SYSCALL2(SYS_IPC_CALL_SYNC_MEDIUM, phoneid, (sysarg_t)&data); |
|
- | 60 | if (callres) |
|
- | 61 | return callres; |
|
- | 62 | ||
- | 63 | if (result1) |
|
- | 64 | *result1 = IPC_GET_ARG1(data); |
|
- | 65 | if (result2) |
|
- | 66 | *result2 = IPC_GET_ARG2(data); |
|
- | 67 | if (result3) |
|
- | 68 | *result3 = IPC_GET_ARG3(data); |
|
- | 69 | return IPC_GET_RETVAL(data); |
|
- | 70 | } |
|
- | 71 | ||
- | 72 | /** Send asynchronous message |
|
- | 73 | * |
|
- | 74 | * - if fatal error, call callback handler with proper error code |
|
- | 75 | * - if message cannot be temporarily sent, add to queue |
|
- | 76 | */ |
|
- | 77 | void ipc_call_async_2(int phoneid, sysarg_t method, sysarg_t arg1, |
|
- | 78 | sysarg_t arg2, |
|
- | 79 | ipc_async_callback_t callback) |
|
- | 80 | { |
|
- | 81 | ipc_callid_t callid; |
|
- | 82 | ipc_data_t data; /* Data storage for saving calls */ |
|
- | 83 | ||
- | 84 | callid = __SYSCALL4(SYS_IPC_CALL_ASYNC, phoneid, method, arg1, arg2); |
|
- | 85 | if (callid == IPC_CALLRET_FATAL) { |
|
- | 86 | /* Call asynchronous handler with error code */ |
|
- | 87 | IPC_SET_RETVAL(data, IPC_CALLRET_FATAL); |
|
- | 88 | callback(&data); |
|
- | 89 | return; |
|
- | 90 | } |
|
- | 91 | if (callid == IPC_CALLRET_TEMPORARY) { |
|
- | 92 | /* Add asynchronous call to queue of non-dispatched async calls */ |
|
- | 93 | IPC_SET_METHOD(data, method); |
|
- | 94 | IPC_SET_ARG1(data, arg1); |
|
- | 95 | IPC_SET_ARG2(data, arg2); |
|
- | 96 | ||
- | 97 | return; |
|
- | 98 | } |
|
- | 99 | /* Add callid to list of dispatched calls */ |
|
41 | |
100 | |
42 | } |
101 | } |
43 | 102 | ||
- | 103 | ||
- | 104 | /** Send answer to a received call */ |
|
- | 105 | void ipc_answer(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1, |
|
44 | int ipc_answer() |
106 | sysarg_t arg2) |
45 | { |
107 | { |
- | 108 | __SYSCALL4(SYS_IPC_ANSWER, callid, retval, arg1, arg2); |
|
46 | } |
109 | } |
47 | */ |
110 | |
48 | 111 | ||
49 | /** Call syscall function sys_ipc_wait_for_call */ |
112 | /** Call syscall function sys_ipc_wait_for_call */ |
50 | static inline ipc_callid_t _ipc_wait_for_call(ipc_data_t *data, int flags) |
113 | static inline ipc_callid_t _ipc_wait_for_call(ipc_data_t *data, int flags) |
51 | { |
114 | { |
52 | return __SYSCALL2(SYS_IPC_WAIT, (sysarg_t)data, flags); |
115 | return __SYSCALL2(SYS_IPC_WAIT, (sysarg_t)data, flags); |
53 | } |
116 | } |
54 | 117 | ||
55 | /** Wait for IPC call and return |
118 | /** Wait for IPC call and return |
56 | * |
119 | * |
57 | * - dispatch ASYNC reoutines in the background |
120 | * - dispatch ASYNC reoutines in the background |
58 | */ |
121 | */ |
59 | int ipc_wait_for_call(ipc_data_t *data, int flags) |
122 | int ipc_wait_for_call(ipc_data_t *data, int flags) |
60 | { |
123 | { |
61 | ipc_callid_t callid; |
124 | ipc_callid_t callid; |
62 | 125 | ||
- | 126 | do { |
|
- | 127 | /* Try to dispatch non-dispatched async calls */ |
|
63 | callid = _ipc_wait_for_call(data, flags); |
128 | callid = _ipc_wait_for_call(data, flags); |
- | 129 | if (callid & IPC_CALLID_ANSWERED) { |
|
64 | /* TODO: Handle async replies etc.. */ |
130 | /* TODO: Call async answer handler */ |
- | 131 | } |
|
- | 132 | } while (callid & IPC_CALLID_ANSWERED); |
|
65 | return callid; |
133 | return callid; |
66 | } |
134 | } |
67 | 135 |