1 1.1 jmcneill /** 2 1.1 jmcneill * Copyright (c) 2010-2012 Broadcom. All rights reserved. 3 1.1 jmcneill * 4 1.1 jmcneill * Redistribution and use in source and binary forms, with or without 5 1.1 jmcneill * modification, are permitted provided that the following conditions 6 1.1 jmcneill * are met: 7 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright 8 1.1 jmcneill * notice, this list of conditions, and the following disclaimer, 9 1.1 jmcneill * without modification. 10 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright 11 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the 12 1.1 jmcneill * documentation and/or other materials provided with the distribution. 13 1.1 jmcneill * 3. The names of the above-listed copyright holders may not be used 14 1.1 jmcneill * to endorse or promote products derived from this software without 15 1.1 jmcneill * specific prior written permission. 16 1.1 jmcneill * 17 1.1 jmcneill * ALTERNATIVELY, this software may be distributed under the terms of the 18 1.1 jmcneill * GNU General Public License ("GPL") version 2, as published by the Free 19 1.1 jmcneill * Software Foundation. 20 1.1 jmcneill * 21 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 22 1.1 jmcneill * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 23 1.1 jmcneill * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 1.1 jmcneill * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 25 1.1 jmcneill * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 1.1 jmcneill * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 1.1 jmcneill * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 1.1 jmcneill * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 1.1 jmcneill * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 1.1 jmcneill * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 1.1 jmcneill * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 1.1 jmcneill */ 33 1.1 jmcneill 34 1.1 jmcneill #ifndef _VCHI_MESSAGE_H_ 35 1.1 jmcneill #define _VCHI_MESSAGE_H_ 36 1.1 jmcneill 37 1.1 jmcneill #include "interface/vchi/vchi_cfg_internal.h" 38 1.1 jmcneill #include "interface/vchi/vchi_common.h" 39 1.1 jmcneill 40 1.1 jmcneill 41 1.1 jmcneill typedef enum message_event_type { 42 1.1 jmcneill MESSAGE_EVENT_NONE, 43 1.1 jmcneill MESSAGE_EVENT_NOP, 44 1.1 jmcneill MESSAGE_EVENT_MESSAGE, 45 1.1 jmcneill MESSAGE_EVENT_SLOT_COMPLETE, 46 1.1 jmcneill MESSAGE_EVENT_RX_BULK_PAUSED, 47 1.1 jmcneill MESSAGE_EVENT_RX_BULK_COMPLETE, 48 1.1 jmcneill MESSAGE_EVENT_TX_COMPLETE, 49 1.1 jmcneill MESSAGE_EVENT_MSG_DISCARDED 50 1.1 jmcneill } MESSAGE_EVENT_TYPE_T; 51 1.1 jmcneill 52 1.1 jmcneill typedef enum vchi_msg_flags 53 1.1 jmcneill { 54 1.1 jmcneill VCHI_MSG_FLAGS_NONE = 0x0, 55 1.1 jmcneill VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1 56 1.1 jmcneill } VCHI_MSG_FLAGS_T; 57 1.1 jmcneill 58 1.1 jmcneill typedef enum message_tx_channel 59 1.1 jmcneill { 60 1.1 jmcneill MESSAGE_TX_CHANNEL_MESSAGE = 0, 61 1.1 jmcneill MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards 62 1.1 jmcneill } MESSAGE_TX_CHANNEL_T; 63 1.1 jmcneill 64 1.1 jmcneill // Macros used for cycling through bulk channels 65 1.1 jmcneill #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) 66 1.1 jmcneill #define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION) 67 1.1 jmcneill 68 1.1 jmcneill typedef enum message_rx_channel 69 1.1 jmcneill { 70 1.1 jmcneill MESSAGE_RX_CHANNEL_MESSAGE = 0, 71 1.1 jmcneill MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards 72 1.1 jmcneill } MESSAGE_RX_CHANNEL_T; 73 1.1 jmcneill 74 1.1 jmcneill // Message receive slot information 75 1.1 jmcneill typedef struct rx_msg_slot_info { 76 1.1 jmcneill 77 1.1 jmcneill struct rx_msg_slot_info *next; 78 1.1 jmcneill //struct slot_info *prev; 79 1.1 jmcneill #if !defined VCHI_COARSE_LOCKING 80 1.1 jmcneill struct semaphore sem; 81 1.1 jmcneill #endif 82 1.1 jmcneill 83 1.1 jmcneill uint8_t *addr; // base address of slot 84 1.1 jmcneill uint32_t len; // length of slot in bytes 85 1.1 jmcneill 86 1.1 jmcneill uint32_t write_ptr; // hardware causes this to advance 87 1.1 jmcneill uint32_t read_ptr; // this module does the reading 88 1.1 jmcneill int active; // is this slot in the hardware dma fifo? 89 1.1 jmcneill uint32_t msgs_parsed; // count how many messages are in this slot 90 1.1 jmcneill uint32_t msgs_released; // how many messages have been released 91 1.1 jmcneill void *state; // connection state information 92 1.1 jmcneill uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services 93 1.1 jmcneill } RX_MSG_SLOTINFO_T; 94 1.1 jmcneill 95 1.1 jmcneill // The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out. 96 1.1 jmcneill // In particular, it mustn't use addr and len - they're the client buffer, but the message 97 1.1 jmcneill // driver will be tasked with sending the aligned core section. 98 1.1 jmcneill typedef struct rx_bulk_slotinfo_t { 99 1.1 jmcneill struct rx_bulk_slotinfo_t *next; 100 1.1 jmcneill 101 1.1 jmcneill struct semaphore *blocking; 102 1.1 jmcneill 103 1.1 jmcneill // needed by DMA 104 1.1 jmcneill void *addr; 105 1.1 jmcneill uint32_t len; 106 1.1 jmcneill 107 1.1 jmcneill // needed for the callback 108 1.1 jmcneill void *service; 109 1.1 jmcneill void *handle; 110 1.1 jmcneill VCHI_FLAGS_T flags; 111 1.1 jmcneill } RX_BULK_SLOTINFO_T; 112 1.1 jmcneill 113 1.1 jmcneill 114 1.1 jmcneill /* ---------------------------------------------------------------------- 115 1.1 jmcneill * each connection driver will have a pool of the following struct. 116 1.1 jmcneill * 117 1.1 jmcneill * the pool will be managed by vchi_qman_* 118 1.1 jmcneill * this means there will be multiple queues (single linked lists) 119 1.1 jmcneill * a given struct message_info will be on exactly one of these queues 120 1.1 jmcneill * at any one time 121 1.1 jmcneill * -------------------------------------------------------------------- */ 122 1.1 jmcneill typedef struct rx_message_info { 123 1.1 jmcneill 124 1.1 jmcneill struct message_info *next; 125 1.1 jmcneill //struct message_info *prev; 126 1.1 jmcneill 127 1.1 jmcneill uint8_t *addr; 128 1.1 jmcneill uint32_t len; 129 1.1 jmcneill RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message 130 1.1 jmcneill uint32_t tx_timestamp; 131 1.1 jmcneill uint32_t rx_timestamp; 132 1.1 jmcneill 133 1.1 jmcneill } RX_MESSAGE_INFO_T; 134 1.1 jmcneill 135 1.1 jmcneill typedef struct { 136 1.1 jmcneill MESSAGE_EVENT_TYPE_T type; 137 1.1 jmcneill 138 1.1 jmcneill struct { 139 1.1 jmcneill // for messages 140 1.1 jmcneill void *addr; // address of message 141 1.1 jmcneill uint16_t slot_delta; // whether this message indicated slot delta 142 1.1 jmcneill uint32_t len; // length of message 143 1.1 jmcneill RX_MSG_SLOTINFO_T *slot; // slot this message is in 144 1.1 jmcneill int32_t service; // service id this message is destined for 145 1.1 jmcneill uint32_t tx_timestamp; // timestamp from the header 146 1.1 jmcneill uint32_t rx_timestamp; // timestamp when we parsed it 147 1.1 jmcneill } message; 148 1.1 jmcneill 149 1.1 jmcneill // FIXME: cleanup slot reporting... 150 1.1 jmcneill RX_MSG_SLOTINFO_T *rx_msg; 151 1.1 jmcneill RX_BULK_SLOTINFO_T *rx_bulk; 152 1.1 jmcneill void *tx_handle; 153 1.1 jmcneill MESSAGE_TX_CHANNEL_T tx_channel; 154 1.1 jmcneill 155 1.1 jmcneill } MESSAGE_EVENT_T; 156 1.1 jmcneill 157 1.1 jmcneill 158 1.1 jmcneill // callbacks 159 1.1 jmcneill typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state ); 160 1.1 jmcneill 161 1.1 jmcneill typedef struct { 162 1.1 jmcneill VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback; 163 1.1 jmcneill } VCHI_MESSAGE_DRIVER_OPEN_T; 164 1.1 jmcneill 165 1.1 jmcneill 166 1.1 jmcneill // handle to this instance of message driver (as returned by ->open) 167 1.1 jmcneill typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T; 168 1.1 jmcneill 169 1.1 jmcneill struct opaque_vchi_message_driver_t { 170 1.1 jmcneill VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state ); 171 1.1 jmcneill int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle ); 172 1.1 jmcneill int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle ); 173 1.1 jmcneill int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable ); 174 1.1 jmcneill int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message 175 1.1 jmcneill int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk) 176 1.1 jmcneill 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) 177 1.1 jmcneill void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver 178 1.1 jmcneill int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle ); 179 1.1 jmcneill int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void 180 1.1 jmcneill *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial ); 181 1.1 jmcneill 182 1.1 jmcneill int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count ); 183 1.1 jmcneill int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length ); 184 1.1 jmcneill void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length ); 185 1.1 jmcneill void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address ); 186 1.1 jmcneill int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size ); 187 1.1 jmcneill int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size ); 188 1.1 jmcneill 189 1.1 jmcneill int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel ); 190 1.1 jmcneill uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel ); 191 1.1 jmcneill int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel ); 192 1.1 jmcneill int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel ); 193 1.1 jmcneill 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 ); 194 1.1 jmcneill void (*debug)( VCHI_MDRIVER_HANDLE_T *handle ); 195 1.1 jmcneill }; 196 1.1 jmcneill 197 1.1 jmcneill 198 1.1 jmcneill #endif // _VCHI_MESSAGE_H_ 199 1.1 jmcneill 200 1.1 jmcneill /****************************** End of file ***********************************/ 201