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 _VCHI_MESSAGE_H_ 35 #define _VCHI_MESSAGE_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 44 typedef enum message_event_type { 45 MESSAGE_EVENT_NONE, 46 MESSAGE_EVENT_NOP, 47 MESSAGE_EVENT_MESSAGE, 48 MESSAGE_EVENT_SLOT_COMPLETE, 49 MESSAGE_EVENT_RX_BULK_PAUSED, 50 MESSAGE_EVENT_RX_BULK_COMPLETE, 51 MESSAGE_EVENT_TX_COMPLETE, 52 MESSAGE_EVENT_MSG_DISCARDED 53 } MESSAGE_EVENT_TYPE_T; 54 55 typedef enum vchi_msg_flags { 56 VCHI_MSG_FLAGS_NONE = 0x0, 57 VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1 58 } VCHI_MSG_FLAGS_T; 59 60 typedef enum message_tx_channel { 61 MESSAGE_TX_CHANNEL_MESSAGE = 0, 62 MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards 63 } MESSAGE_TX_CHANNEL_T; 64 65 // Macros used for cycling through bulk channels 66 #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) 67 #define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION) 68 69 typedef enum message_rx_channel { 70 MESSAGE_RX_CHANNEL_MESSAGE = 0, 71 MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards 72 } MESSAGE_RX_CHANNEL_T; 73 74 // Message receive slot information 75 typedef struct rx_msg_slot_info { 76 77 struct rx_msg_slot_info *next; 78 //struct slot_info *prev; 79 #if !defined VCHI_COARSE_LOCKING 80 struct semaphore sem; 81 #endif 82 83 uint8_t *addr; // base address of slot 84 uint32_t len; // length of slot in bytes 85 86 uint32_t write_ptr; // hardware causes this to advance 87 uint32_t read_ptr; // this module does the reading 88 int active; // is this slot in the hardware dma fifo? 89 uint32_t msgs_parsed; // count how many messages are in this slot 90 uint32_t msgs_released; // how many messages have been released 91 void *state; // connection state information 92 uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services 93 } RX_MSG_SLOTINFO_T; 94 95 // The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out. 96 // In particular, it mustn't use addr and len - they're the client buffer, but the message 97 // driver will be tasked with sending the aligned core section. 98 typedef struct rx_bulk_slotinfo_t { 99 struct rx_bulk_slotinfo_t *next; 100 101 struct semaphore *blocking; 102 103 // needed by DMA 104 void *addr; 105 uint32_t len; 106 107 // needed for the callback 108 void *service; 109 void *handle; 110 VCHI_FLAGS_T flags; 111 } RX_BULK_SLOTINFO_T; 112 113 /* ---------------------------------------------------------------------- 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 queues 119 * at any one time 120 * -------------------------------------------------------------------- */ 121 typedef struct rx_message_info { 122 123 struct message_info *next; 124 //struct message_info *prev; 125 126 uint8_t *addr; 127 uint32_t len; 128 RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message 129 uint32_t tx_timestamp; 130 uint32_t rx_timestamp; 131 132 } RX_MESSAGE_INFO_T; 133 134 typedef struct { 135 MESSAGE_EVENT_TYPE_T type; 136 137 struct { 138 // for messages 139 void *addr; // address of message 140 uint16_t slot_delta; // whether this message indicated slot delta 141 uint32_t len; // length of message 142 RX_MSG_SLOTINFO_T *slot; // slot this message is in 143 int32_t service; // service id this message is destined for 144 uint32_t tx_timestamp; // timestamp from the header 145 uint32_t rx_timestamp; // timestamp when we parsed it 146 } message; 147 148 // FIXME: cleanup slot reporting... 149 RX_MSG_SLOTINFO_T *rx_msg; 150 RX_BULK_SLOTINFO_T *rx_bulk; 151 void *tx_handle; 152 MESSAGE_TX_CHANNEL_T tx_channel; 153 154 } MESSAGE_EVENT_T; 155 156 // callbacks 157 typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state ); 158 159 typedef struct { 160 VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback; 161 } VCHI_MESSAGE_DRIVER_OPEN_T; 162 163 // handle to this instance of message driver (as returned by ->open) 164 typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T; 165 166 struct opaque_vchi_message_driver_t { 167 VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state ); 168 int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle ); 169 int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle ); 170 int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable ); 171 int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message 172 int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk) 173 int32_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) 174 void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver 175 int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle ); 176 int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void 177 *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial ); 178 179 int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count ); 180 int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length ); 181 void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length ); 182 void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address ); 183 int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size ); 184 int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size ); 185 186 int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel ); 187 uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel ); 188 int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel ); 189 int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel ); 190 void (*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 ); 191 void (*debug)( VCHI_MDRIVER_HANDLE_T *handle ); 192 }; 193 194 #endif // _VCHI_MESSAGE_H_ 195 196 /****************************** End of file ***********************************/ 197