Path: blob/main/sys/contrib/vchiq/interface/vchi/message_drivers/message.h
48529 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 _VCHI_MESSAGE_H_34#define _VCHI_MESSAGE_H_3536#include "interface/vchi/vchi_cfg_internal.h"37#include "interface/vchi/vchi_common.h"383940typedef enum message_event_type {41MESSAGE_EVENT_NONE,42MESSAGE_EVENT_NOP,43MESSAGE_EVENT_MESSAGE,44MESSAGE_EVENT_SLOT_COMPLETE,45MESSAGE_EVENT_RX_BULK_PAUSED,46MESSAGE_EVENT_RX_BULK_COMPLETE,47MESSAGE_EVENT_TX_COMPLETE,48MESSAGE_EVENT_MSG_DISCARDED49} MESSAGE_EVENT_TYPE_T;5051typedef enum vchi_msg_flags52{53VCHI_MSG_FLAGS_NONE = 0x0,54VCHI_MSG_FLAGS_TERMINATE_DMA = 0x155} VCHI_MSG_FLAGS_T;5657typedef enum message_tx_channel58{59MESSAGE_TX_CHANNEL_MESSAGE = 0,60MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards61} MESSAGE_TX_CHANNEL_T;6263// Macros used for cycling through bulk channels64#define MESSAGE_TX_CHANNEL_BULK_PREV(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION-1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)65#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)6667typedef enum message_rx_channel68{69MESSAGE_RX_CHANNEL_MESSAGE = 0,70MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards71} MESSAGE_RX_CHANNEL_T;7273// Message receive slot information74typedef struct rx_msg_slot_info {7576struct rx_msg_slot_info *next;77//struct slot_info *prev;78#if !defined VCHI_COARSE_LOCKING79struct semaphore sem;80#endif8182uint8_t *addr; // base address of slot83uint32_t len; // length of slot in bytes8485uint32_t write_ptr; // hardware causes this to advance86uint32_t read_ptr; // this module does the reading87int active; // is this slot in the hardware dma fifo?88uint32_t msgs_parsed; // count how many messages are in this slot89uint32_t msgs_released; // how many messages have been released90void *state; // connection state information91uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services92} RX_MSG_SLOTINFO_T;9394// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.95// In particular, it mustn't use addr and len - they're the client buffer, but the message96// driver will be tasked with sending the aligned core section.97typedef struct rx_bulk_slotinfo_t {98struct rx_bulk_slotinfo_t *next;99100struct semaphore *blocking;101102// needed by DMA103void *addr;104uint32_t len;105106// needed for the callback107void *service;108void *handle;109VCHI_FLAGS_T flags;110} RX_BULK_SLOTINFO_T;111112113/* ----------------------------------------------------------------------114* each connection driver will have a pool of the following struct.115*116* the pool will be managed by vchi_qman_*117* this means there will be multiple queues (single linked lists)118* a given struct message_info will be on exactly one of these queues119* at any one time120* -------------------------------------------------------------------- */121typedef struct rx_message_info {122123struct message_info *next;124//struct message_info *prev;125126uint8_t *addr;127uint32_t len;128RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message129uint32_t tx_timestamp;130uint32_t rx_timestamp;131132} RX_MESSAGE_INFO_T;133134typedef struct {135MESSAGE_EVENT_TYPE_T type;136137struct {138// for messages139void *addr; // address of message140uint16_t slot_delta; // whether this message indicated slot delta141uint32_t len; // length of message142RX_MSG_SLOTINFO_T *slot; // slot this message is in143int32_t service; // service id this message is destined for144uint32_t tx_timestamp; // timestamp from the header145uint32_t rx_timestamp; // timestamp when we parsed it146} message;147148// FIXME: cleanup slot reporting...149RX_MSG_SLOTINFO_T *rx_msg;150RX_BULK_SLOTINFO_T *rx_bulk;151void *tx_handle;152MESSAGE_TX_CHANNEL_T tx_channel;153154} MESSAGE_EVENT_T;155156157// callbacks158typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );159160typedef struct {161VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;162} VCHI_MESSAGE_DRIVER_OPEN_T;163164165// handle to this instance of message driver (as returned by ->open)166typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;167168struct opaque_vchi_message_driver_t {169VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );170int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );171int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );172int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );173int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message174int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)175int32_t (*send)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel, const void *data, uint32_t len, VCHI_MSG_FLAGS_T flags, void *send_handle ); // tx (message & bulk)176void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver177int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );178int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void179*address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );180181int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );182int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );183void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );184void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );185int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );186int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );187188int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );189uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );190int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );191int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );192void (*form_bulk_aux)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel, const void *data, uint32_t len, uint32_t chunk_size, const void **aux_data, int32_t *aux_len );193void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );194};195196197#endif // _VCHI_MESSAGE_H_198199/****************************** End of file ***********************************/200201202