1 /** 2 * Copyright (c) 2010-2012 Broadcom. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 16 * 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. 20 * 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. 32 */ 33 34 #ifndef CONNECTION_H_ 35 #define CONNECTION_H_ 36 37 #include <linux/kernel.h> 38 #include <linux/types.h> 39 #include <linux/semaphore.h> 40 41 #include "interface/vchi/vchi_cfg_internal.h" 42 #include "interface/vchi/vchi_common.h" 43 #include "interface/vchi/message_drivers/message.h" 44 45 /****************************************************************************** 46 Global defs 47 *****************************************************************************/ 48 49 // Opaque handle for a connection / service pair 50 typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T; 51 52 // opaque handle to the connection state information 53 typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T; 54 55 typedef struct vchi_connection_t VCHI_CONNECTION_T; 56 57 /****************************************************************************** 58 API 59 *****************************************************************************/ 60 61 // Routine to init a connection with a particular low level driver 62 typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection, 63 const VCHI_MESSAGE_DRIVER_T * driver ); 64 65 // Routine to control CRC enabling at a connection level 66 typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle, 67 VCHI_CRC_CONTROL_T control ); 68 69 // Routine to create a service 70 typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle, 71 int32_t service_id, 72 uint32_t rx_fifo_size, 73 uint32_t tx_fifo_size, 74 int server, 75 VCHI_CALLBACK_T callback, 76 void *callback_param, 77 int32_t want_crc, 78 int32_t want_unaligned_bulk_rx, 79 int32_t want_unaligned_bulk_tx, 80 VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle ); 81 82 // Routine to close a service 83 typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle ); 84 85 // Routine to queue a message 86 typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, 87 const void *data, 88 uint32_t data_size, 89 VCHI_FLAGS_T flags, 90 void *msg_handle ); 91 92 // scatter-gather (vector) message queueing 93 typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, 94 VCHI_MSG_VECTOR_T *vector, 95 uint32_t count, 96 VCHI_FLAGS_T flags, 97 void *msg_handle ); 98 99 // Routine to dequeue a message 100 typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, 101 void *data, 102 uint32_t max_data_size_to_read, 103 uint32_t *actual_msg_size, 104 VCHI_FLAGS_T flags ); 105 106 // Routine to peek at a message 107 typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, 108 void **data, 109 uint32_t *msg_size, 110 VCHI_FLAGS_T flags ); 111 112 // Routine to hold a message 113 typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, 114 void **data, 115 uint32_t *msg_size, 116 VCHI_FLAGS_T flags, 117 void **message_handle ); 118 119 // Routine to initialise a received message iterator 120 typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, 121 VCHI_MSG_ITER_T *iter, 122 VCHI_FLAGS_T flags ); 123 124 // Routine to release a held message 125 typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, 126 void *message_handle ); 127 128 // Routine to get info on a held message 129 typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, 130 void *message_handle, 131 void **data, 132 int32_t *msg_size, 133 uint32_t *tx_timestamp, 134 uint32_t *rx_timestamp ); 135 136 // Routine to check whether the iterator has a next message 137 typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service, 138 const VCHI_MSG_ITER_T *iter ); 139 140 // Routine to advance the iterator 141 typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service, 142 VCHI_MSG_ITER_T *iter, 143 void **data, 144 uint32_t *msg_size ); 145 146 // Routine to remove the last message returned by the iterator 147 typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service, 148 VCHI_MSG_ITER_T *iter ); 149 150 // Routine to hold the last message returned by the iterator 151 typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service, 152 VCHI_MSG_ITER_T *iter, 153 void **msg_handle ); 154 155 // Routine to transmit bulk data 156 typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, 157 const void *data_src, 158 uint32_t data_size, 159 VCHI_FLAGS_T flags, 160 void *bulk_handle ); 161 162 // Routine to receive data 163 typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, 164 void *data_dst, 165 uint32_t data_size, 166 VCHI_FLAGS_T flags, 167 void *bulk_handle ); 168 169 // Routine to report if a server is available 170 typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags ); 171 172 // Routine to report the number of RX slots available 173 typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state ); 174 175 // Routine to report the RX slot size 176 typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state ); 177 178 // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO 179 typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state, 180 int32_t service, 181 uint32_t length, 182 MESSAGE_TX_CHANNEL_T channel, 183 uint32_t channel_params, 184 uint32_t data_length, 185 uint32_t data_offset); 186 187 // Callback to inform a service that a Xon or Xoff message has been received 188 typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff); 189 190 // Callback to inform a service that a server available reply message has been received 191 typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags); 192 193 // Callback to indicate that bulk auxiliary messages have arrived 194 typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state); 195 196 // Callback to indicate that bulk auxiliary messages have arrived 197 typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle); 198 199 // Callback with all the connection info you require 200 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); 201 202 // Callback to inform of a disconnect 203 typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags); 204 205 // Callback to inform of a power control request 206 typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable); 207 208 // allocate memory suitably aligned for this connection 209 typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length); 210 211 // free memory allocated by buffer_allocate 212 typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address); 213 214 /****************************************************************************** 215 System driver struct 216 *****************************************************************************/ 217 218 struct opaque_vchi_connection_api_t { 219 // Routine to init the connection 220 VCHI_CONNECTION_INIT_T init; 221 222 // Connection-level CRC control 223 VCHI_CONNECTION_CRC_CONTROL_T crc_control; 224 225 // Routine to connect to or create service 226 VCHI_CONNECTION_SERVICE_CONNECT_T service_connect; 227 228 // Routine to disconnect from a service 229 VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect; 230 231 // Routine to queue a message 232 VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg; 233 234 // scatter-gather (vector) message queue 235 VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv; 236 237 // Routine to dequeue a message 238 VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg; 239 240 // Routine to peek at a message 241 VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg; 242 243 // Routine to hold a message 244 VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg; 245 246 // Routine to initialise a received message iterator 247 VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg; 248 249 // Routine to release a message 250 VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release; 251 252 // Routine to get information on a held message 253 VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info; 254 255 // Routine to check for next message on iterator 256 VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next; 257 258 // Routine to get next message on iterator 259 VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next; 260 261 // Routine to remove the last message returned by iterator 262 VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove; 263 264 // Routine to hold the last message returned by iterator 265 VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold; 266 267 // Routine to transmit bulk data 268 VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit; 269 270 // Routine to receive data 271 VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive; 272 273 // Routine to report the available servers 274 VCHI_CONNECTION_SERVER_PRESENT server_present; 275 276 // Routine to report the number of RX slots available 277 VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available; 278 279 // Routine to report the RX slot size 280 VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size; 281 282 // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO 283 VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added; 284 285 // Callback to inform a service that a Xon or Xoff message has been received 286 VCHI_CONNECTION_FLOW_CONTROL flow_control; 287 288 // Callback to inform a service that a server available reply message has been received 289 VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply; 290 291 // Callback to indicate that bulk auxiliary messages have arrived 292 VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received; 293 294 // Callback to indicate that a bulk auxiliary message has been transmitted 295 VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted; 296 297 // Callback to provide information about the connection 298 VCHI_CONNECTION_INFO connection_info; 299 300 // Callback to notify that peer has requested disconnect 301 VCHI_CONNECTION_DISCONNECT disconnect; 302 303 // Callback to notify that peer has requested power change 304 VCHI_CONNECTION_POWER_CONTROL power_control; 305 306 // allocate memory suitably aligned for this connection 307 VCHI_BUFFER_ALLOCATE buffer_allocate; 308 309 // free memory allocated by buffer_allocate 310 VCHI_BUFFER_FREE buffer_free; 311 312 }; 313 314 struct vchi_connection_t { 315 const VCHI_CONNECTION_API_T *api; 316 VCHI_CONNECTION_STATE_T *state; 317 #ifdef VCHI_COARSE_LOCKING 318 struct semaphore sem; 319 #endif 320 }; 321 322 #endif /* CONNECTION_H_ */ 323 324 /****************************** End of file **********************************/ 325