2 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
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.
34 #ifndef _VCHI_MESSAGE_H_
35 #define _VCHI_MESSAGE_H_
37 #include <linux/kernel.h>
38 #include <linux/types.h>
39 #include <linux/semaphore.h>
41 #include "interface/vchi/vchi_cfg_internal.h"
42 #include "interface/vchi/vchi_common.h"
45 typedef enum message_event_type {
48 MESSAGE_EVENT_MESSAGE,
49 MESSAGE_EVENT_SLOT_COMPLETE,
50 MESSAGE_EVENT_RX_BULK_PAUSED,
51 MESSAGE_EVENT_RX_BULK_COMPLETE,
52 MESSAGE_EVENT_TX_COMPLETE,
53 MESSAGE_EVENT_MSG_DISCARDED
54 } MESSAGE_EVENT_TYPE_T;
56 typedef enum vchi_msg_flags
58 VCHI_MSG_FLAGS_NONE = 0x0,
59 VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
62 typedef enum message_tx_channel
64 MESSAGE_TX_CHANNEL_MESSAGE = 0,
65 MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
66 } MESSAGE_TX_CHANNEL_T;
68 // Macros used for cycling through bulk channels
69 #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)
70 #define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
72 typedef enum message_rx_channel
74 MESSAGE_RX_CHANNEL_MESSAGE = 0,
75 MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
76 } MESSAGE_RX_CHANNEL_T;
78 // Message receive slot information
79 typedef struct rx_msg_slot_info {
81 struct rx_msg_slot_info *next;
82 //struct slot_info *prev;
83 #if !defined VCHI_COARSE_LOCKING
87 uint8_t *addr; // base address of slot
88 uint32_t len; // length of slot in bytes
90 uint32_t write_ptr; // hardware causes this to advance
91 uint32_t read_ptr; // this module does the reading
92 int active; // is this slot in the hardware dma fifo?
93 uint32_t msgs_parsed; // count how many messages are in this slot
94 uint32_t msgs_released; // how many messages have been released
95 void *state; // connection state information
96 uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
99 // The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
100 // In particular, it mustn't use addr and len - they're the client buffer, but the message
101 // driver will be tasked with sending the aligned core section.
102 typedef struct rx_bulk_slotinfo_t {
103 struct rx_bulk_slotinfo_t *next;
105 struct semaphore *blocking;
111 // needed for the callback
115 } RX_BULK_SLOTINFO_T;
118 /* ----------------------------------------------------------------------
119 * each connection driver will have a pool of the following struct.
121 * the pool will be managed by vchi_qman_*
122 * this means there will be multiple queues (single linked lists)
123 * a given struct message_info will be on exactly one of these queues
125 * -------------------------------------------------------------------- */
126 typedef struct rx_message_info {
128 struct message_info *next;
129 //struct message_info *prev;
133 RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
134 uint32_t tx_timestamp;
135 uint32_t rx_timestamp;
140 MESSAGE_EVENT_TYPE_T type;
144 void *addr; // address of message
145 uint16_t slot_delta; // whether this message indicated slot delta
146 uint32_t len; // length of message
147 RX_MSG_SLOTINFO_T *slot; // slot this message is in
148 int32_t service; // service id this message is destined for
149 uint32_t tx_timestamp; // timestamp from the header
150 uint32_t rx_timestamp; // timestamp when we parsed it
153 // FIXME: cleanup slot reporting...
154 RX_MSG_SLOTINFO_T *rx_msg;
155 RX_BULK_SLOTINFO_T *rx_bulk;
157 MESSAGE_TX_CHANNEL_T tx_channel;
163 typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
166 VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
167 } VCHI_MESSAGE_DRIVER_OPEN_T;
170 // handle to this instance of message driver (as returned by ->open)
171 typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
173 struct opaque_vchi_message_driver_t {
174 VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
175 int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
176 int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
177 int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
178 int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
179 int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
180 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)
181 void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
182 int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
183 int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
184 *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
186 int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
187 int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
188 void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
189 void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
190 int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
191 int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
193 int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
194 uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
195 int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
196 int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
197 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 );
198 void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
202 #endif // _VCHI_MESSAGE_H_
204 /****************************** End of file ***********************************/