2 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions, and the following disclaimer,
9 * without modification.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the above-listed copyright holders may not be used
14 * to endorse or promote products derived from this software without
15 * specific prior written permission.
17 * ALTERNATIVELY, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2, as published by the Free
19 * Software Foundation.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <linux/kernel.h>
38 #include <linux/types.h>
39 #include <linux/semaphore.h>
41 #include "interface/vchi/vchi_cfg_internal.h"
42 #include "interface/vchi/vchi_common.h"
43 #include "interface/vchi/message_drivers/message.h"
45 /******************************************************************************
47 *****************************************************************************/
49 // Opaque handle for a connection / service pair
50 typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
52 // opaque handle to the connection state information
53 typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
55 typedef struct vchi_connection_t VCHI_CONNECTION_T;
58 /******************************************************************************
60 *****************************************************************************/
62 // Routine to init a connection with a particular low level driver
63 typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
64 const VCHI_MESSAGE_DRIVER_T * driver );
66 // Routine to control CRC enabling at a connection level
67 typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
68 VCHI_CRC_CONTROL_T control );
70 // Routine to create a service
71 typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
73 uint32_t rx_fifo_size,
74 uint32_t tx_fifo_size,
76 VCHI_CALLBACK_T callback,
79 int32_t want_unaligned_bulk_rx,
80 int32_t want_unaligned_bulk_tx,
81 VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
83 // Routine to close a service
84 typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
86 // Routine to queue a message
87 typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
93 // scatter-gather (vector) message queueing
94 typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
95 VCHI_MSG_VECTOR_T *vector,
100 // Routine to dequeue a message
101 typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
103 uint32_t max_data_size_to_read,
104 uint32_t *actual_msg_size,
105 VCHI_FLAGS_T flags );
107 // Routine to peek at a message
108 typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
111 VCHI_FLAGS_T flags );
113 // Routine to hold a message
114 typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
118 void **message_handle );
120 // Routine to initialise a received message iterator
121 typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
122 VCHI_MSG_ITER_T *iter,
123 VCHI_FLAGS_T flags );
125 // Routine to release a held message
126 typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
127 void *message_handle );
129 // Routine to get info on a held message
130 typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
131 void *message_handle,
134 uint32_t *tx_timestamp,
135 uint32_t *rx_timestamp );
137 // Routine to check whether the iterator has a next message
138 typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
139 const VCHI_MSG_ITER_T *iter );
141 // Routine to advance the iterator
142 typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
143 VCHI_MSG_ITER_T *iter,
145 uint32_t *msg_size );
147 // Routine to remove the last message returned by the iterator
148 typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
149 VCHI_MSG_ITER_T *iter );
151 // Routine to hold the last message returned by the iterator
152 typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
153 VCHI_MSG_ITER_T *iter,
156 // Routine to transmit bulk data
157 typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
158 const void *data_src,
163 // Routine to receive data
164 typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
170 // Routine to report if a server is available
171 typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
173 // Routine to report the number of RX slots available
174 typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
176 // Routine to report the RX slot size
177 typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
179 // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
180 typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
183 MESSAGE_TX_CHANNEL_T channel,
184 uint32_t channel_params,
185 uint32_t data_length,
186 uint32_t data_offset);
188 // Callback to inform a service that a Xon or Xoff message has been received
189 typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
191 // Callback to inform a service that a server available reply message has been received
192 typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
194 // Callback to indicate that bulk auxiliary messages have arrived
195 typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
197 // Callback to indicate that bulk auxiliary messages have arrived
198 typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
200 // Callback with all the connection info you require
201 typedef void (*VCHI_CONNECTION_INFO)(VCHI_CONNECTION_STATE_T *state, uint32_t protocol_version, uint32_t slot_size, uint32_t num_slots, uint32_t min_bulk_size);
203 // Callback to inform of a disconnect
204 typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
206 // Callback to inform of a power control request
207 typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
209 // allocate memory suitably aligned for this connection
210 typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
212 // free memory allocated by buffer_allocate
213 typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
216 /******************************************************************************
218 *****************************************************************************/
220 struct opaque_vchi_connection_api_t {
221 // Routine to init the connection
222 VCHI_CONNECTION_INIT_T init;
224 // Connection-level CRC control
225 VCHI_CONNECTION_CRC_CONTROL_T crc_control;
227 // Routine to connect to or create service
228 VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
230 // Routine to disconnect from a service
231 VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
233 // Routine to queue a message
234 VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
236 // scatter-gather (vector) message queue
237 VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
239 // Routine to dequeue a message
240 VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
242 // Routine to peek at a message
243 VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
245 // Routine to hold a message
246 VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
248 // Routine to initialise a received message iterator
249 VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
251 // Routine to release a message
252 VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
254 // Routine to get information on a held message
255 VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
257 // Routine to check for next message on iterator
258 VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
260 // Routine to get next message on iterator
261 VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
263 // Routine to remove the last message returned by iterator
264 VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
266 // Routine to hold the last message returned by iterator
267 VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
269 // Routine to transmit bulk data
270 VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
272 // Routine to receive data
273 VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
275 // Routine to report the available servers
276 VCHI_CONNECTION_SERVER_PRESENT server_present;
278 // Routine to report the number of RX slots available
279 VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
281 // Routine to report the RX slot size
282 VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
284 // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
285 VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
287 // Callback to inform a service that a Xon or Xoff message has been received
288 VCHI_CONNECTION_FLOW_CONTROL flow_control;
290 // Callback to inform a service that a server available reply message has been received
291 VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
293 // Callback to indicate that bulk auxiliary messages have arrived
294 VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
296 // Callback to indicate that a bulk auxiliary message has been transmitted
297 VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
299 // Callback to provide information about the connection
300 VCHI_CONNECTION_INFO connection_info;
302 // Callback to notify that peer has requested disconnect
303 VCHI_CONNECTION_DISCONNECT disconnect;
305 // Callback to notify that peer has requested power change
306 VCHI_CONNECTION_POWER_CONTROL power_control;
308 // allocate memory suitably aligned for this connection
309 VCHI_BUFFER_ALLOCATE buffer_allocate;
311 // free memory allocated by buffer_allocate
312 VCHI_BUFFER_FREE buffer_free;
316 struct vchi_connection_t {
317 const VCHI_CONNECTION_API_T *api;
318 VCHI_CONNECTION_STATE_T *state;
319 #ifdef VCHI_COARSE_LOCKING
320 struct semaphore sem;
325 #endif /* CONNECTION_H_ */
327 /****************************** End of file **********************************/