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