Subversion Repositories HelenOS

Rev

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

Rev 2105 Rev 2106
Line 45... Line 45...
45
#else
45
#else
46
# define IPC_MAX_ASYNC_CALLS  4000
46
# define IPC_MAX_ASYNC_CALLS  4000
47
#endif
47
#endif
48
 
48
 
49
/* Flags for calls */
49
/* Flags for calls */
-
 
50
 
-
 
51
/** This is answer to a call */
50
#define IPC_CALL_ANSWERED       (1<<0) /**< This is answer to a call */
52
#define IPC_CALL_ANSWERED   (1 << 0)
51
#define IPC_CALL_STATIC_ALLOC   (1<<1) /**< This call will not be freed on error */
53
/** This call will not be freed on error */
-
 
54
#define IPC_CALL_STATIC_ALLOC   (1 << 1)
52
#define IPC_CALL_DISCARD_ANSWER (1<<2) /**< Answer will not be passed to userspace, will be discarded */
55
/** Answer will not be passed to userspace, will be discarded */
-
 
56
#define IPC_CALL_DISCARD_ANSWER (1 << 2)
-
 
57
/** Call was forwarded */
53
#define IPC_CALL_FORWARDED      (1<<3) /**< Call was forwarded */
58
#define IPC_CALL_FORWARDED  (1 << 3)
54
#define IPC_CALL_CONN_ME_TO     (1<<4) /**< Identify connect_me_to answer */
59
/** Identify connect_me_to answer */
-
 
60
#define IPC_CALL_CONN_ME_TO (1 << 4)
55
#define IPC_CALL_NOTIF          (1<<5) /**< Interrupt notification */
61
/** Interrupt notification */
-
 
62
#define IPC_CALL_NOTIF      (1 << 5)
56
 
63
 
57
/* Flags of callid (the addresses are aligned at least to 4,
64
/* Flags of callid (the addresses are aligned at least to 4,
58
 * that is why we can use bottom 2 bits of the call address
65
 * that is why we can use bottom 2 bits of the call address
59
 */
66
 */
60
#define IPC_CALLID_ANSWERED       1 /**< Type of this msg is 'answer' */
67
/** Type of this msg is 'answer' */
-
 
68
#define IPC_CALLID_ANSWERED 1
61
#define IPC_CALLID_NOTIFICATION   2 /**< Type of this msg is 'notification' */
69
/** Type of this msg is 'notification' */
-
 
70
#define IPC_CALLID_NOTIFICATION 2
62
 
71
 
63
/* Return values from IPC_ASYNC */
72
/* Return values from IPC_ASYNC */
64
#define IPC_CALLRET_FATAL         -1
73
#define IPC_CALLRET_FATAL   -1
65
#define IPC_CALLRET_TEMPORARY     -2
74
#define IPC_CALLRET_TEMPORARY   -2
66
 
75
 
67
 
76
 
68
/* Macros for manipulating calling data */
77
/* Macros for manipulating calling data */
69
#define IPC_SET_RETVAL(data, retval)   ((data).args[0] = (retval))
78
#define IPC_SET_RETVAL(data, retval)    ((data).args[0] = (retval))
70
#define IPC_SET_METHOD(data, val)   ((data).args[0] = (val))
79
#define IPC_SET_METHOD(data, val)   ((data).args[0] = (val))
71
#define IPC_SET_ARG1(data, val)   ((data).args[1] = (val))
80
#define IPC_SET_ARG1(data, val)     ((data).args[1] = (val))
72
#define IPC_SET_ARG2(data, val)   ((data).args[2] = (val))
81
#define IPC_SET_ARG2(data, val)     ((data).args[2] = (val))
73
#define IPC_SET_ARG3(data, val)   ((data).args[3] = (val))
82
#define IPC_SET_ARG3(data, val)     ((data).args[3] = (val))
74
 
83
 
75
#define IPC_GET_METHOD(data)           ((data).args[0])
84
#define IPC_GET_METHOD(data)        ((data).args[0])
76
#define IPC_GET_RETVAL(data)           ((data).args[0])
85
#define IPC_GET_RETVAL(data)        ((data).args[0])
77
 
86
 
78
#define IPC_GET_ARG1(data)              ((data).args[1])
87
#define IPC_GET_ARG1(data)      ((data).args[1])
79
#define IPC_GET_ARG2(data)              ((data).args[2])
88
#define IPC_GET_ARG2(data)      ((data).args[2])
80
#define IPC_GET_ARG3(data)              ((data).args[3])
89
#define IPC_GET_ARG3(data)      ((data).args[3])
81
 
90
 
82
/* Well known phone descriptors */
91
/* Well known phone descriptors */
83
#define PHONE_NS              0
92
#define PHONE_NS    0
84
 
93
 
85
/* System-specific methods - only through special syscalls
94
/* System-specific methods - only through special syscalls
86
 * These methods have special behaviour
95
 * These methods have special behaviour
87
 */
96
 */
88
/** Protocol for CONNECT - TO - ME
97
/** Protocol for CONNECT - TO - ME
Line 164... Line 173...
164
 
173
 
165
struct answerbox;
174
struct answerbox;
166
struct task;
175
struct task;
167
 
176
 
168
typedef enum {
177
typedef enum {
169
    IPC_PHONE_FREE = 0,     /**< Phone is free and can be allocated */
178
    /** Phone is free and can be allocated */
-
 
179
    IPC_PHONE_FREE = 0,
170
    IPC_PHONE_CONNECTING,   /**< Phone is connecting somewhere */
180
    /** Phone is connecting somewhere */
-
 
181
    IPC_PHONE_CONNECTING,
171
    IPC_PHONE_CONNECTED,    /**< Phone is connected */
182
    /** Phone is connected */
-
 
183
    IPC_PHONE_CONNECTED,
172
    IPC_PHONE_HUNGUP,   /**< Phone is hung up, waiting for answers to come */
184
    /** Phone is hung up, waiting for answers to come */
-
 
185
    IPC_PHONE_HUNGUP,
173
    IPC_PHONE_SLAMMED       /**< Phone was hungup from server */
186
    /** Phone was hungup from server */
-
 
187
    IPC_PHONE_SLAMMED
174
} ipc_phone_state_t;
188
} ipc_phone_state_t;
175
 
189
 
176
/** Structure identifying phone (in TASK structure) */
190
/** Structure identifying phone (in TASK structure) */
177
typedef struct {
191
typedef struct {
178
    SPINLOCK_DECLARE(lock);
192
    SPINLOCK_DECLARE(lock);
Line 187... Line 201...
187
 
201
 
188
    struct task *task;
202
    struct task *task;
189
 
203
 
190
    waitq_t wq;
204
    waitq_t wq;
191
 
205
 
192
    link_t connected_phones;    /**< Phones connected to this answerbox */
206
    /** Phones connected to this answerbox */
-
 
207
    link_t connected_phones;
193
    link_t calls;           /**< Received calls */
208
    /** Received calls */
-
 
209
    link_t calls;          
194
    link_t dispatched_calls;    /* Should be hash table in the future */
210
    link_t dispatched_calls;    /* Should be hash table in the future */
195
 
211
 
196
    link_t answers;         /**< Answered calls */
212
    /** Answered calls */
-
 
213
    link_t answers;
197
 
214
 
198
    SPINLOCK_DECLARE(irq_lock);
215
    SPINLOCK_DECLARE(irq_lock);
199
    link_t irq_notifs;          /**< Notifications from IRQ handlers */
216
    /** Notifications from IRQ handlers */
-
 
217
    link_t irq_notifs;
200
    link_t irq_head;        /**< IRQs with notifications to this answerbox. */
218
    /** IRQs with notifications to this answerbox. */
-
 
219
    link_t irq_head;
201
} answerbox_t;
220
} answerbox_t;
202
 
221
 
203
typedef struct {
222
typedef struct {
204
    unative_t args[IPC_CALL_LEN];
223
    unative_t args[IPC_CALL_LEN];
205
    phone_t *phone;
224
    phone_t *phone;
Line 215... Line 234...
215
    /* The caller box is different from sender->answerbox
234
    /* The caller box is different from sender->answerbox
216
     * for synchronous calls
235
     * for synchronous calls
217
     */
236
     */
218
    answerbox_t *callerbox;
237
    answerbox_t *callerbox;
219
 
238
 
220
    unative_t priv; /**< Private data to internal IPC */
239
    /** Private data to internal IPC */
-
 
240
    unative_t priv;
221
 
241
 
222
    ipc_data_t data;  /**< Data passed from/to userspace */
242
    /** Data passed from/to userspace */
-
 
243
    ipc_data_t data;
223
} call_t;
244
} call_t;
224
 
245
 
225
extern void ipc_init(void);
246
extern void ipc_init(void);
226
extern call_t * ipc_wait_for_call(answerbox_t *box, uint32_t usec, int flags);
247
extern call_t * ipc_wait_for_call(answerbox_t *box, uint32_t usec, int flags);
227
extern void ipc_answer(answerbox_t *box, call_t *request);
248
extern void ipc_answer(answerbox_t *box, call_t *request);