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 {
57 VCHI_MSG_FLAGS_NONE = 0x0,
58 VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
61 typedef enum message_tx_channel {
62 MESSAGE_TX_CHANNEL_MESSAGE = 0,
63 MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
64 } MESSAGE_TX_CHANNEL_T;
66 // Macros used for cycling through bulk channels
67 #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)
68 #define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
70 typedef enum message_rx_channel {
71 MESSAGE_RX_CHANNEL_MESSAGE = 0,
72 MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
73 } MESSAGE_RX_CHANNEL_T;
75 // Message receive slot information
76 typedef struct rx_msg_slot_info {
78 struct rx_msg_slot_info *next;
79 //struct slot_info *prev;
80 #if !defined VCHI_COARSE_LOCKING
84 uint8_t *addr; // base address of slot
85 uint32_t len; // length of slot in bytes
87 uint32_t write_ptr; // hardware causes this to advance
88 uint32_t read_ptr; // this module does the reading
89 int active; // is this slot in the hardware dma fifo?
90 uint32_t msgs_parsed; // count how many messages are in this slot
91 uint32_t msgs_released; // how many messages have been released
92 void *state; // connection state information
93 uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
96 // The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
97 // In particular, it mustn't use addr and len - they're the client buffer, but the message
98 // driver will be tasked with sending the aligned core section.
99 typedef struct rx_bulk_slotinfo_t {
100 struct rx_bulk_slotinfo_t *next;
102 struct semaphore *blocking;
108 // needed for the callback
112 } RX_BULK_SLOTINFO_T;
115 /* ----------------------------------------------------------------------
116 * each connection driver will have a pool of the following struct.
118 * the pool will be managed by vchi_qman_*
119 * this means there will be multiple queues (single linked lists)
120 * a given struct message_info will be on exactly one of these queues
122 * -------------------------------------------------------------------- */
123 typedef struct rx_message_info {
125 struct message_info *next;
126 //struct message_info *prev;
130 RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
131 uint32_t tx_timestamp;
132 uint32_t rx_timestamp;
137 MESSAGE_EVENT_TYPE_T type;
141 void *addr; // address of message
142 uint16_t slot_delta; // whether this message indicated slot delta
143 uint32_t len; // length of message
144 RX_MSG_SLOTINFO_T *slot; // slot this message is in
145 int32_t service; // service id this message is destined for
146 uint32_t tx_timestamp; // timestamp from the header
147 uint32_t rx_timestamp; // timestamp when we parsed it
150 // FIXME: cleanup slot reporting...
151 RX_MSG_SLOTINFO_T *rx_msg;
152 RX_BULK_SLOTINFO_T *rx_bulk;
154 MESSAGE_TX_CHANNEL_T tx_channel;
160 typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
163 VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
164 } VCHI_MESSAGE_DRIVER_OPEN_T;
167 // handle to this instance of message driver (as returned by ->open)
168 typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
170 struct opaque_vchi_message_driver_t {
171 VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
172 int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
173 int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
174 int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
175 int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
176 int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
177 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)
178 void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
179 int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
180 int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
181 *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
183 int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
184 int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
185 void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
186 void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
187 int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
188 int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
190 int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
191 uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
192 int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
193 int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
194 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 );
195 void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
199 #endif // _VCHI_MESSAGE_H_
201 /****************************** End of file ***********************************/