Fix format specifiers not correct for 32-bit
[helenos.git] / kernel / generic / include / ipc / ipc.h
blobb0d2cd8a58db39af40480969f14c4a380349efc2
1 /*
2 * Copyright (c) 2006 Ondrej Palkovsky
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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 kernel_generic_ipc
30 * @{
32 /** @file
35 #ifndef KERN_IPC_H_
36 #define KERN_IPC_H_
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>
43 #include <typedefs.h>
44 #include <mm/slab.h>
45 #include <cap/cap.h>
47 struct answerbox;
48 struct task;
49 struct call;
51 typedef enum {
52 /** Phone is free and can be allocated */
53 IPC_PHONE_FREE = 0,
54 /** Phone is connecting somewhere */
55 IPC_PHONE_CONNECTING,
56 /** Phone is connected */
57 IPC_PHONE_CONNECTED,
58 /** Phone is hung up, waiting for answers to come */
59 IPC_PHONE_HUNGUP,
60 /** Phone was hungup from server */
61 IPC_PHONE_SLAMMED
62 } ipc_phone_state_t;
64 /** Structure identifying phone (in TASK structure) */
65 typedef struct phone {
66 mutex_t lock;
67 link_t link;
68 struct task *caller;
69 struct answerbox *callee;
70 /* A call prepared for hangup ahead of time, so that it cannot fail. */
71 struct call *hangup_call;
72 ipc_phone_state_t state;
73 atomic_size_t active_calls;
74 /** User-defined label */
75 sysarg_t label;
76 kobject_t *kobject;
77 } phone_t;
79 typedef struct answerbox {
80 IRQ_SPINLOCK_DECLARE(lock);
82 /** Answerbox is active until it enters cleanup. */
83 bool active;
85 struct task *task;
87 waitq_t wq;
89 /**
90 * Number of answers the answerbox is expecting to eventually arrive.
92 atomic_size_t active_calls;
94 /** Phones connected to this answerbox. */
95 list_t connected_phones;
96 /** Received calls. */
97 list_t calls;
98 list_t dispatched_calls; /* Should be hash table in the future */
100 /** Answered calls. */
101 list_t answers;
103 IRQ_SPINLOCK_DECLARE(irq_lock);
105 /** Notifications from IRQ handlers. */
106 list_t irq_notifs;
107 } answerbox_t;
109 typedef struct call {
110 kobject_t *kobject;
113 * Task link.
114 * Valid only when the call is not forgotten.
115 * Protected by the task's active_calls_lock.
117 link_t ta_link;
119 /** Answerbox link. */
120 link_t ab_link;
122 unsigned int flags;
124 /** Protects the forget member. */
125 SPINLOCK_DECLARE(forget_lock);
128 * True if the caller 'forgot' this call and donated it to the callee.
129 * Forgotten calls are discarded upon answering (the answer is not
130 * delivered) and answered calls cannot be forgotten. Forgotten calls
131 * also do not figure on the task's active call list.
133 * We keep this separate from the flags so that it is not necessary
134 * to take a lock when accessing them.
136 bool forget;
138 /** True if the call is in the active list. */
139 bool active;
142 * Identification of the caller.
143 * Valid only when the call is not forgotten.
145 struct task *sender;
148 * Answerbox that will receive the answer.
149 * This will most of the times be the sender's answerbox,
150 * but we allow for useful exceptions.
152 answerbox_t *callerbox;
154 /** Phone which was used to send the call. */
155 phone_t *caller_phone;
157 /** Private data to internal IPC. */
158 sysarg_t priv;
160 /** Data passed from/to userspace. */
161 ipc_data_t data;
163 /** Method as it was sent in the request. */
164 sysarg_t request_method;
166 /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
167 uint8_t *buffer;
168 } call_t;
170 extern slab_cache_t *phone_cache;
172 extern answerbox_t *ipc_box_0;
174 extern kobject_ops_t call_kobject_ops;
176 extern void ipc_init(void);
178 extern call_t *ipc_call_alloc(void);
180 extern errno_t ipc_call_sync(phone_t *, call_t *);
181 extern errno_t ipc_call(phone_t *, call_t *);
182 extern errno_t ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int, call_t **);
183 extern errno_t ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
184 extern void ipc_answer(answerbox_t *, call_t *);
185 extern void _ipc_answer_free_call(call_t *, bool);
187 extern void ipc_phone_init(phone_t *, struct task *);
188 extern bool ipc_phone_connect(phone_t *, answerbox_t *);
189 extern errno_t ipc_phone_hangup(phone_t *);
191 extern void ipc_answerbox_init(answerbox_t *, struct task *);
193 extern void ipc_cleanup(void);
194 extern void ipc_backsend_err(phone_t *, call_t *, errno_t);
195 extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
196 extern void ipc_cleanup_call_list(answerbox_t *, list_t *);
198 extern void ipc_print_task(task_id_t);
200 #endif
202 /** @}