Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/vchiq/interface/vchi/message_drivers/message.h
48529 views
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 "interface/vchi/vchi_cfg_internal.h"
38
#include "interface/vchi/vchi_common.h"
39
40
41
typedef enum message_event_type {
42
MESSAGE_EVENT_NONE,
43
MESSAGE_EVENT_NOP,
44
MESSAGE_EVENT_MESSAGE,
45
MESSAGE_EVENT_SLOT_COMPLETE,
46
MESSAGE_EVENT_RX_BULK_PAUSED,
47
MESSAGE_EVENT_RX_BULK_COMPLETE,
48
MESSAGE_EVENT_TX_COMPLETE,
49
MESSAGE_EVENT_MSG_DISCARDED
50
} MESSAGE_EVENT_TYPE_T;
51
52
typedef enum vchi_msg_flags
53
{
54
VCHI_MSG_FLAGS_NONE = 0x0,
55
VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
56
} VCHI_MSG_FLAGS_T;
57
58
typedef enum message_tx_channel
59
{
60
MESSAGE_TX_CHANNEL_MESSAGE = 0,
61
MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
62
} MESSAGE_TX_CHANNEL_T;
63
64
// Macros used for cycling through bulk channels
65
#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
#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
68
typedef enum message_rx_channel
69
{
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
/* ----------------------------------------------------------------------
115
* each connection driver will have a pool of the following struct.
116
*
117
* the pool will be managed by vchi_qman_*
118
* this means there will be multiple queues (single linked lists)
119
* a given struct message_info will be on exactly one of these queues
120
* at any one time
121
* -------------------------------------------------------------------- */
122
typedef struct rx_message_info {
123
124
struct message_info *next;
125
//struct message_info *prev;
126
127
uint8_t *addr;
128
uint32_t len;
129
RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
130
uint32_t tx_timestamp;
131
uint32_t rx_timestamp;
132
133
} RX_MESSAGE_INFO_T;
134
135
typedef struct {
136
MESSAGE_EVENT_TYPE_T type;
137
138
struct {
139
// for messages
140
void *addr; // address of message
141
uint16_t slot_delta; // whether this message indicated slot delta
142
uint32_t len; // length of message
143
RX_MSG_SLOTINFO_T *slot; // slot this message is in
144
int32_t service; // service id this message is destined for
145
uint32_t tx_timestamp; // timestamp from the header
146
uint32_t rx_timestamp; // timestamp when we parsed it
147
} message;
148
149
// FIXME: cleanup slot reporting...
150
RX_MSG_SLOTINFO_T *rx_msg;
151
RX_BULK_SLOTINFO_T *rx_bulk;
152
void *tx_handle;
153
MESSAGE_TX_CHANNEL_T tx_channel;
154
155
} MESSAGE_EVENT_T;
156
157
158
// callbacks
159
typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
160
161
typedef struct {
162
VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
163
} VCHI_MESSAGE_DRIVER_OPEN_T;
164
165
166
// handle to this instance of message driver (as returned by ->open)
167
typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
168
169
struct opaque_vchi_message_driver_t {
170
VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
171
int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
172
int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
173
int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
174
int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
175
int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
176
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
void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
178
int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
179
int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
180
*address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
181
182
int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
183
int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
184
void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
185
void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
186
int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
187
int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
188
189
int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
190
uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
191
int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
192
int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
193
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
void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
195
};
196
197
198
#endif // _VCHI_MESSAGE_H_
199
200
/****************************** End of file ***********************************/
201
202