1/**
2 * \file
3 * \brief Unidirectional bulk data transfer via shared memory
4 */
5
6/*
7 * Copyright (c) 2009, 2010, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef BULK_SM_H
16#define BULK_SM_H
17
18#include <bulk_transfer/bulk_transfer.h>
19
20#include <if/bulk_ctrl_defs.h>
21
22// Shared memory specific structs -----------------------------------------
23
24enum bulk_sm_endpoint_state {
25    BULK_EPSTATE_CREATED,      ///< dummy endpoint after creation
26    BULK_EPSTATE_IREF_EXPORTED ///< endpoint's bulk_ctrl is exported on the ep's iref
27};
28
29struct bulk_sm_endpoint_descriptor {
30    /* generic part */
31    struct bulk_endpoint_descriptor ep_generic; ///< generic endpoint part
32
33    /* start of implementation specific part */
34    volatile enum bulk_sm_endpoint_state state;
35    iref_t                               iref;
36    errval_t                             err;
37};
38
39struct bulk_sm_resend_item {
40    struct bulk_sm_resend_item *next;
41    struct event_closure       event;
42};
43
44struct bulk_sm_impl_data {
45    struct bulk_ctrl_binding    *b;
46    struct bulk_sm_pending_msg  *root;
47    struct thread_mutex         mutex;//used for changes to pending_msg
48    //TODO: remove binding stuff from here, use pending message system instead
49    errval_t                    bind_error;
50    struct bulk_continuation    bind_cont;
51
52    // resending of flounder messages
53    struct thread_mutex         resend_lock;
54    struct bulk_sm_resend_item  *resend_closure;
55};
56
57// Shared memory implementation callbacks ---------------------------------
58
59errval_t bulk_sm_channel_create(struct bulk_channel *channel);
60
61errval_t bulk_sm_channel_bind(struct bulk_channel     *channel,
62                              struct bulk_continuation cont);
63
64errval_t bulk_sm_channel_destroy(struct bulk_channel *channel);
65
66errval_t bulk_sm_assign_pool(struct bulk_channel      *channel,
67                             struct bulk_pool         *pool,
68                             struct bulk_continuation cont);
69
70errval_t bulk_sm_remove_pool(struct bulk_channel      *channel,
71                             struct bulk_pool         *pool,
72                             struct bulk_continuation cont);
73
74errval_t bulk_sm_move(struct bulk_channel      *channel,
75                      struct bulk_buffer       *buffer,
76                      void                     *meta,
77                      struct bulk_continuation cont);
78
79errval_t bulk_sm_copy(struct bulk_channel      *channel,
80                      struct bulk_buffer       *buffer,
81                      void                     *meta,
82                      struct bulk_continuation cont);
83
84errval_t bulk_sm_release(struct bulk_channel      *channel,
85                         struct bulk_buffer       *buffer,
86                         struct bulk_continuation cont);
87
88errval_t bulk_sm_pass(struct bulk_channel      *channel,
89                      struct bulk_buffer       *buffer,
90                      void                     *meta,
91                      struct bulk_continuation cont);
92
93struct bulk_implementation *bulk_sm_get_implementation(void);
94
95// Shared memory support functions ----------------------------------------
96
97/**
98 * Creates a new bulk endpoint which uses the shared memory backend
99 *
100 * @param ep_desc   memory location to create the endpoint in
101 *
102 * This function is intended to be used by the creator. (exporting side)
103 */
104errval_t bulk_sm_ep_create(struct bulk_sm_endpoint_descriptor *ep_desc);
105
106/**
107 * Creates a new bulk endpoint which uses the shared memory backend
108 *
109 * @param ep_desc       memory location to create the endpoint in
110 * @param remote_iref   the iref of the exported service on the other side
111 *
112 * This function is intended to be used by the binding side
113 */
114errval_t bulk_sm_ep_create_remote(struct bulk_sm_endpoint_descriptor *ep_desc,
115                                  iref_t remote_iref);
116
117// Helpers to deal with multiple waitsets (each channel requires one) -----
118
119/**
120 * List of waitsets to dispatch.
121 */
122struct bulk_sm_ws_item {
123    struct bulk_sm_ws_item *next;
124    struct waitset         *ws;   ///< waitset to dispatch. may be NULL.
125};
126
127/**
128 * Dispatches events on a list of waitsets, non-blocking.
129 * @returns: LIB_ERR_NO_EVENT if no event dispatched.
130 */
131errval_t bulk_sm_multiple_event_dispatch_non_block(struct bulk_sm_ws_item *item);
132
133/**
134 * Dispatches events on on a list of waitsets. Retruns if events dispatched.
135 */
136errval_t bulk_sm_multiple_event_dispatch(struct bulk_sm_ws_item *item);
137
138#endif /* BULK_SM_H */
139