2 * Copyright (c) 2006 Ondrej Palkovsky
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 /** @addtogroup genericipc
38 #include <synch/spinlock.h>
39 #include <synch/mutex.h>
40 #include <synch/waitq.h>
41 #include <abi/ipc/ipc.h>
42 #include <abi/proc/task.h>
51 /** Phone is free and can be allocated */
53 /** Phone is connecting somewhere */
55 /** Phone is connected */
57 /** Phone is hung up, waiting for answers to come */
59 /** Phone was hungup from server */
63 /** Structure identifying phone (in TASK structure) */
64 typedef struct phone
{
68 struct answerbox
*callee
;
69 ipc_phone_state_t state
;
70 atomic_t active_calls
;
74 typedef struct answerbox
{
75 IRQ_SPINLOCK_DECLARE(lock
);
77 /** Answerbox is active until it enters cleanup. */
84 /** Phones connected to this answerbox. */
85 list_t connected_phones
;
86 /** Received calls. */
88 list_t dispatched_calls
; /* Should be hash table in the future */
90 /** Answered calls. */
93 IRQ_SPINLOCK_DECLARE(irq_lock
);
95 /** Notifications from IRQ handlers. */
100 sysarg_t args
[IPC_CALL_LEN
];
102 * Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME,
103 * or the task which answered the call.
106 /** Phone which made or last masqueraded this call. */
113 * Valid only when the call is not forgotten.
114 * Protected by the task's active_calls_lock.
120 /** Answerbox link. */
125 /** Protects the forget member. */
126 SPINLOCK_DECLARE(forget_lock
);
129 * True if the caller 'forgot' this call and donated it to the callee.
130 * Forgotten calls are discarded upon answering (the answer is not
131 * delivered) and answered calls cannot be forgotten. Forgotten calls
132 * also do not figure on the task's active call list.
134 * We keep this separate from the flags so that it is not necessary
135 * to take a lock when accessing them.
139 /** True if the call is in the active list. */
143 * Identification of the caller.
144 * Valid only when the call is not forgotten.
149 * Answerbox that will receive the answer.
150 * This will most of the times be the sender's answerbox,
151 * but we allow for useful exceptions.
153 answerbox_t
*callerbox
;
155 /** Phone which was used to send the call. */
156 phone_t
*caller_phone
;
158 /** Private data to internal IPC. */
161 /** Data passed from/to userspace. */
164 /** Method as it was sent in the request. */
165 sysarg_t request_method
;
167 /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
171 extern slab_cache_t
*phone_slab
;
173 extern answerbox_t
*ipc_phone_0
;
175 extern void ipc_init(void);
177 extern call_t
*ipc_call_alloc(unsigned int);
178 extern void ipc_call_free(call_t
*);
179 extern void ipc_call_hold(call_t
*);
180 extern void ipc_call_release(call_t
*);
182 extern int ipc_call_sync(phone_t
*, call_t
*);
183 extern int ipc_call(phone_t
*, call_t
*);
184 extern call_t
*ipc_wait_for_call(answerbox_t
*, uint32_t, unsigned int);
185 extern int ipc_forward(call_t
*, phone_t
*, answerbox_t
*, unsigned int);
186 extern void ipc_answer(answerbox_t
*, call_t
*);
187 extern void _ipc_answer_free_call(call_t
*, bool);
189 extern void ipc_phone_init(phone_t
*, struct task
*);
190 extern bool ipc_phone_connect(phone_t
*, answerbox_t
*);
191 extern int ipc_phone_hangup(phone_t
*);
193 extern void ipc_answerbox_init(answerbox_t
*, struct task
*);
195 extern void ipc_cleanup(void);
196 extern void ipc_backsend_err(phone_t
*, call_t
*, sysarg_t
);
197 extern void ipc_answerbox_slam_phones(answerbox_t
*, bool);
198 extern void ipc_cleanup_call_list(answerbox_t
*, list_t
*);
200 extern void ipc_print_task(task_id_t
);