flounder: making const pointers in receiving handlers, using CONST_CAST as a temporar...
[barrelfish] / lib / bulk_transfer / backends / sm / bulk_sm_impl.h
1 /*
2  * Copyright (c) 2009, 2010, 2011, 2012, ETH Zurich.
3  * All rights reserved.
4  *
5  * This file is distributed under the terms in the attached LICENSE file.
6  * If you do not find this file, copies can be found by writing to:
7  * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8  */
9
10 #ifndef BULK_SM_IMPL_H
11 #define BULK_SM_IMPL_H
12
13 #include <barrelfish/barrelfish.h>
14
15 #include <bulk_transfer/bulk_transfer.h>
16 #include <bulk_transfer/bulk_sm.h>
17
18 #define VOID2CHANNEL(a)    ((struct bulk_channel*)(a))
19 #define CHANNEL_EP(c)      ((struct bulk_sm_endpoint_descriptor*)(c)->ep)
20 #define CHANNEL_DATA(c)    ((struct bulk_sm_impl_data*)(c)->impl_data)
21 #define CHANNEL_BINDING(c) (CHANNEL_DATA(c)->b)
22
23 // Flounder call/receive handler ------------------------------------------
24
25 void bulk_sm_channel_negotiate_rx_call(
26         struct bulk_ctrl_binding  *b,
27         enum bulk_ctrl_role_t     role,
28         enum bulk_ctrl_trust_t    trust);
29
30 void bulk_sm_channel_negotiate_rx_reply(
31         struct bulk_ctrl_binding  *b,
32         uint64_t                   error,
33         enum bulk_ctrl_direction_t match_direction,
34         enum bulk_ctrl_role_t      match_role,
35         uint64_t                   meta_size);
36
37 void bulk_sm_assign_pool_rx_call(
38         struct bulk_ctrl_binding *b,
39         bulk_ctrl_pool_t         pool,
40         uint64_t                 id);
41
42 void bulk_sm_assign_pool_rx_response(
43         struct bulk_ctrl_binding *b,
44         uint64_t                 error,
45         uint64_t                 id);
46
47
48 void bulk_sm_move_rx_call(
49         struct bulk_ctrl_binding *b,
50         bulk_ctrl_poolid_t       poolid,
51         uint32_t                 bufferid,
52         uint32_t                 tid,
53         struct capref            cap,
54         const uint8_t            *meta,
55         size_t                   metasize);
56
57 void bulk_sm_move_trusted_rx_call(
58         struct bulk_ctrl_binding *b,
59         bulk_ctrl_poolid_t       poolid,
60         uint32_t                 bufferid,
61         uint32_t                 tid,
62         const uint8_t            *meta,
63         size_t                   metasize);
64
65 void bulk_sm_move_rx_response(
66         struct bulk_ctrl_binding *b,
67         bulk_ctrl_error_t        error,
68         uint32_t                 tid);
69
70 void bulk_sm_copy_rx_call(
71         struct bulk_ctrl_binding *b,
72         bulk_ctrl_poolid_t       poolid,
73         uint32_t                 bufferid,
74         uint32_t                 tid,
75         struct capref            cap,
76         const uint8_t            *meta,
77         size_t                   metasize);
78
79 void bulk_sm_copy_trusted_rx_call(
80         struct bulk_ctrl_binding *b,
81         bulk_ctrl_poolid_t       poolid,
82         uint32_t                 bufferid,
83         uint32_t                 tid,
84         const uint8_t            *meta,
85         size_t                   metasize);
86
87 void bulk_sm_copy_rx_response(
88         struct bulk_ctrl_binding *b,
89         bulk_ctrl_error_t        error,
90         uint32_t                 tid);
91
92 void bulk_sm_pass_rx_call(
93         struct bulk_ctrl_binding *b,
94         bulk_ctrl_poolid_t       poolid,
95         uint32_t                 bufferid,
96         uint32_t                 tid,
97         struct capref            cap,
98         const uint8_t            *meta,
99         size_t                   metasize);
100
101 void bulk_sm_pass_trusted_rx_call(
102         struct bulk_ctrl_binding *b,
103         bulk_ctrl_poolid_t       poolid,
104         uint32_t                 bufferid,
105         uint32_t                 tid,
106         const uint8_t            *meta,
107         size_t                   metasize);
108
109 void bulk_sm_pass_rx_response(
110         struct bulk_ctrl_binding *b,
111         bulk_ctrl_error_t        error,
112         uint32_t                 tid);
113
114 void bulk_sm_release_rx_call(
115         struct bulk_ctrl_binding *b,
116         bulk_ctrl_poolid_t       poolid,
117         uint32_t                 bufferid,
118         uint32_t                 tid);
119
120 void bulk_sm_release_rx_response(
121         struct bulk_ctrl_binding *b,
122         bulk_ctrl_error_t        error,
123         uint32_t                 tid);
124
125 // Flounder generic callbacks ---------------------------------------------
126
127 //printing handler for asynchronous errors
128 void bulk_sm_error_handler_debug(struct bulk_ctrl_binding *_binding, errval_t err);
129
130 /**
131  * Callback for use with flounder. Prints to string provided by (void *a).
132  */
133 void bulk_sm_flounder_msg_sent_debug_cb(void *a);
134
135 /**
136  * Function used as generic send that preserves fifo order.
137  * enqueues the message and registers resend handler if necessary
138  *
139  * @param channel: Channel of interest. Is used as argument for the callback.
140  * @param send_fn: send function to be called. this should be a very simple
141  *                  function that just reads arg, tries to send it and
142  *                  returns the error code.
143  */
144 void bulk_sm_flounder_send_fifo_msg(struct bulk_channel *channel,
145                                  errval_t (*send_fn)(void *arg));
146
147 void bulk_sm_flounder_send_fifo_msg_with_arg(struct bulk_channel *channel,
148                                  errval_t (*send_fn)(void *arg),
149                                  void *arg);
150
151
152
153 // Flounder type conversion helpers ---------------------------------------
154
155 static inline enum bulk_channel_direction flounder2bulk_direction(
156         enum bulk_ctrl_direction_t direction)
157 {
158     return ((direction == bulk_ctrl_SOURCE) ? BULK_DIRECTION_TX :
159                                               BULK_DIRECTION_RX );
160 }
161
162 static inline enum bulk_channel_role flounder2bulk_role(
163         enum bulk_ctrl_role_t role)
164 {
165     return ((role == bulk_ctrl_GENERIC) ? BULK_ROLE_GENERIC :
166             (role == bulk_ctrl_MASTER)  ? BULK_ROLE_MASTER  :
167                                           BULK_ROLE_SLAVE   );
168 }
169
170 static inline enum bulk_trust_level flounder2bulk_trust(
171         enum bulk_ctrl_trust_t trust)
172 {
173     return ((trust == bulk_ctrl_NONE) ? BULK_TRUST_NONE :
174             (trust == bulk_ctrl_HALF) ? BULK_TRUST_HALF :
175                                         BULK_TRUST_FULL );
176 }
177
178 static inline enum bulk_ctrl_direction_t bulk2flounder_direction(
179         enum bulk_channel_direction direction)
180 {
181     return ((direction == BULK_DIRECTION_TX) ? bulk_ctrl_SOURCE :
182                                                bulk_ctrl_SINK );
183 }
184
185 static inline enum bulk_ctrl_role_t bulk2flounder_role(
186         enum bulk_channel_role role)
187 {
188     return ((role == BULK_ROLE_GENERIC) ? bulk_ctrl_GENERIC :
189             (role == BULK_ROLE_MASTER)  ? bulk_ctrl_MASTER  :
190                                           bulk_ctrl_SLAVE   );
191 }
192
193 static inline enum bulk_ctrl_trust_t bulk2flounder_trust(
194         enum bulk_trust_level trust)
195 {
196     assert(trust != BULK_TRUST_UNINITIALIZED); // what to do with that?
197
198     return ((trust == BULK_TRUST_NONE) ? bulk_ctrl_NONE :
199             (trust == BULK_TRUST_HALF) ? bulk_ctrl_HALF :
200                                          bulk_ctrl_FULL );
201 }
202
203 /**
204  * Allocates and initializes a new bulk_pool struct based on flounder data.
205  *
206  * @param: pool   Pointer where created and allocated pool is stored, by value.
207  * @param: f_pool Flounder data to create pool from.
208  */
209 errval_t create_pool_from_flounder(struct bulk_pool       **pool,
210                                    const bulk_ctrl_pool_t *f_pool);
211
212 /**
213  * Creates a flounder pool struct from a bulk_pool.
214  *
215  * @param: pool   Pool to be represented
216  * @param: f_pool Pointer to unused flounder pool.
217  */
218 void generate_pool_for_flounder(const struct bulk_pool *pool,
219                                 bulk_ctrl_pool_t       *f_pool);
220
221
222 /**
223  * sets the fields of a bulk_pool_id struct from a flounder poolid struct.
224  * does not allocate any new memory.
225  *
226  */
227 void fill_pool_id_from_flounder(struct bulk_pool_id         *poolid,
228                                 const bulk_ctrl_poolid_t  *f_poolid);
229
230 /**
231  * sets the fields of a flounder poolid struct from a bulk_pool_id struct.
232  * does not allocate any new memory.
233  */
234 void fill_pool_id_for_flounder(const struct bulk_pool_id    *poolid,
235                                bulk_ctrl_poolid_t  *f_poolid);
236
237 #endif // BULK_SM_IMPL_H