Path: blob/main/sys/contrib/vchiq/interface/vchi/connections/connection.h
48531 views
/**1* Copyright (c) 2010-2012 Broadcom. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions, and the following disclaimer,8* without modification.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. The names of the above-listed copyright holders may not be used13* to endorse or promote products derived from this software without14* specific prior written permission.15*16* ALTERNATIVELY, this software may be distributed under the terms of the17* GNU General Public License ("GPL") version 2, as published by the Free18* Software Foundation.19*20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS21* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,22* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR23* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR24* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,25* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,26* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR27* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF28* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING29* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS30* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*/3233#ifndef CONNECTION_H_34#define CONNECTION_H_3536#include "interface/vchi/vchi_cfg_internal.h"37#include "interface/vchi/vchi_common.h"38#include "interface/vchi/message_drivers/message.h"3940/******************************************************************************41Global defs42*****************************************************************************/4344// Opaque handle for a connection / service pair45typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;4647// opaque handle to the connection state information48typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;4950typedef struct vchi_connection_t VCHI_CONNECTION_T;515253/******************************************************************************54API55*****************************************************************************/5657// Routine to init a connection with a particular low level driver58typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,59const VCHI_MESSAGE_DRIVER_T * driver );6061// Routine to control CRC enabling at a connection level62typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,63VCHI_CRC_CONTROL_T control );6465// Routine to create a service66typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,67int32_t service_id,68uint32_t rx_fifo_size,69uint32_t tx_fifo_size,70int server,71VCHI_CALLBACK_T callback,72void *callback_param,73int32_t want_crc,74int32_t want_unaligned_bulk_rx,75int32_t want_unaligned_bulk_tx,76VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );7778// Routine to close a service79typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );8081// Routine to queue a message82typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,83const void *data,84uint32_t data_size,85VCHI_FLAGS_T flags,86void *msg_handle );8788// scatter-gather (vector) message queueing89typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,90VCHI_MSG_VECTOR_T *vector,91uint32_t count,92VCHI_FLAGS_T flags,93void *msg_handle );9495// Routine to dequeue a message96typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,97void *data,98uint32_t max_data_size_to_read,99uint32_t *actual_msg_size,100VCHI_FLAGS_T flags );101102// Routine to peek at a message103typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,104void **data,105uint32_t *msg_size,106VCHI_FLAGS_T flags );107108// Routine to hold a message109typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,110void **data,111uint32_t *msg_size,112VCHI_FLAGS_T flags,113void **message_handle );114115// Routine to initialise a received message iterator116typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,117VCHI_MSG_ITER_T *iter,118VCHI_FLAGS_T flags );119120// Routine to release a held message121typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,122void *message_handle );123124// Routine to get info on a held message125typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,126void *message_handle,127void **data,128int32_t *msg_size,129uint32_t *tx_timestamp,130uint32_t *rx_timestamp );131132// Routine to check whether the iterator has a next message133typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,134const VCHI_MSG_ITER_T *iter );135136// Routine to advance the iterator137typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,138VCHI_MSG_ITER_T *iter,139void **data,140uint32_t *msg_size );141142// Routine to remove the last message returned by the iterator143typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,144VCHI_MSG_ITER_T *iter );145146// Routine to hold the last message returned by the iterator147typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,148VCHI_MSG_ITER_T *iter,149void **msg_handle );150151// Routine to transmit bulk data152typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,153const void *data_src,154uint32_t data_size,155VCHI_FLAGS_T flags,156void *bulk_handle );157158// Routine to receive data159typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,160void *data_dst,161uint32_t data_size,162VCHI_FLAGS_T flags,163void *bulk_handle );164165// Routine to report if a server is available166typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );167168// Routine to report the number of RX slots available169typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );170171// Routine to report the RX slot size172typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );173174// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO175typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,176int32_t service,177uint32_t length,178MESSAGE_TX_CHANNEL_T channel,179uint32_t channel_params,180uint32_t data_length,181uint32_t data_offset);182183// Callback to inform a service that a Xon or Xoff message has been received184typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);185186// Callback to inform a service that a server available reply message has been received187typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);188189// Callback to indicate that bulk auxiliary messages have arrived190typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);191192// Callback to indicate that bulk auxiliary messages have arrived193typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);194195// Callback with all the connection info you require196typedef 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);197198// Callback to inform of a disconnect199typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);200201// Callback to inform of a power control request202typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);203204// allocate memory suitably aligned for this connection205typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);206207// free memory allocated by buffer_allocate208typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);209210211/******************************************************************************212System driver struct213*****************************************************************************/214215struct opaque_vchi_connection_api_t216{217// Routine to init the connection218VCHI_CONNECTION_INIT_T init;219220// Connection-level CRC control221VCHI_CONNECTION_CRC_CONTROL_T crc_control;222223// Routine to connect to or create service224VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;225226// Routine to disconnect from a service227VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;228229// Routine to queue a message230VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;231232// scatter-gather (vector) message queue233VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;234235// Routine to dequeue a message236VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;237238// Routine to peek at a message239VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;240241// Routine to hold a message242VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;243244// Routine to initialise a received message iterator245VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;246247// Routine to release a message248VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;249250// Routine to get information on a held message251VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;252253// Routine to check for next message on iterator254VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;255256// Routine to get next message on iterator257VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;258259// Routine to remove the last message returned by iterator260VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;261262// Routine to hold the last message returned by iterator263VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;264265// Routine to transmit bulk data266VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;267268// Routine to receive data269VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;270271// Routine to report the available servers272VCHI_CONNECTION_SERVER_PRESENT server_present;273274// Routine to report the number of RX slots available275VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;276277// Routine to report the RX slot size278VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;279280// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO281VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;282283// Callback to inform a service that a Xon or Xoff message has been received284VCHI_CONNECTION_FLOW_CONTROL flow_control;285286// Callback to inform a service that a server available reply message has been received287VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;288289// Callback to indicate that bulk auxiliary messages have arrived290VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;291292// Callback to indicate that a bulk auxiliary message has been transmitted293VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;294295// Callback to provide information about the connection296VCHI_CONNECTION_INFO connection_info;297298// Callback to notify that peer has requested disconnect299VCHI_CONNECTION_DISCONNECT disconnect;300301// Callback to notify that peer has requested power change302VCHI_CONNECTION_POWER_CONTROL power_control;303304// allocate memory suitably aligned for this connection305VCHI_BUFFER_ALLOCATE buffer_allocate;306307// free memory allocated by buffer_allocate308VCHI_BUFFER_FREE buffer_free;309310};311312struct vchi_connection_t {313const VCHI_CONNECTION_API_T *api;314VCHI_CONNECTION_STATE_T *state;315#ifdef VCHI_COARSE_LOCKING316struct semaphore sem;317#endif318};319320321#endif /* CONNECTION_H_ */322323/****************************** End of file **********************************/324325326