xref: /freebsd/sys/contrib/vchiq/interface/vchi/vchi_cfg.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
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_CFG_H_
35 #define VCHI_CFG_H_
36 
37 /****************************************************************************************
38  * Defines in this first section are part of the VCHI API and may be examined by VCHI
39  * services.
40  ***************************************************************************************/
41 
42 /* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
43 /* Really determined by the message driver, and should be available from a run-time call. */
44 #ifndef VCHI_BULK_ALIGN
45 #   if __VCCOREVER__ >= 0x04000000
46 #       define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
47 #   else
48 #       define VCHI_BULK_ALIGN 16
49 #   endif
50 #endif
51 
52 /* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
53 /* May be less than or greater than VCHI_BULK_ALIGN */
54 /* Really determined by the message driver, and should be available from a run-time call. */
55 #ifndef VCHI_BULK_GRANULARITY
56 #   if __VCCOREVER__ >= 0x04000000
57 #       define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
58 #   else
59 #       define VCHI_BULK_GRANULARITY 16
60 #   endif
61 #endif
62 
63 /* The largest possible message to be queued with vchi_msg_queue. */
64 #ifndef VCHI_MAX_MSG_SIZE
65 #   if defined VCHI_LOCAL_HOST_PORT
66 #       define VCHI_MAX_MSG_SIZE     16384         // makes file transfers fast, but should they be using bulk?
67 #   else
68 #       define VCHI_MAX_MSG_SIZE      4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
69 #   endif
70 #endif
71 
72 /******************************************************************************************
73  * Defines below are system configuration options, and should not be used by VCHI services.
74  *****************************************************************************************/
75 
76 /* How many connections can we support? A localhost implementation uses 2 connections,
77  * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
78  * driver. */
79 #ifndef VCHI_MAX_NUM_CONNECTIONS
80 #   define VCHI_MAX_NUM_CONNECTIONS 3
81 #endif
82 
83 /* How many services can we open per connection? Extending this doesn't cost processing time, just a small
84  * amount of static memory. */
85 #ifndef VCHI_MAX_SERVICES_PER_CONNECTION
86 #  define VCHI_MAX_SERVICES_PER_CONNECTION 36
87 #endif
88 
89 /* Adjust if using a message driver that supports more logical TX channels */
90 #ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
91 #   define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
92 #endif
93 
94 /* Adjust if using a message driver that supports more logical RX channels */
95 #ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
96 #   define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
97 #endif
98 
99 /* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
100  * receive queue space, less message headers. */
101 #ifndef VCHI_NUM_READ_SLOTS
102 #  if defined(VCHI_LOCAL_HOST_PORT)
103 #     define VCHI_NUM_READ_SLOTS 4
104 #  else
105 #     define VCHI_NUM_READ_SLOTS 48
106 #  endif
107 #endif
108 
109 /* Do we utilise overrun facility for receive message slots? Can aid peer transmit
110  * performance. Only define on VideoCore end, talking to host.
111  */
112 //#define VCHI_MSG_RX_OVERRUN
113 
114 /* How many transmit slots do we use. Generally don't need many, as the hardware driver
115  * underneath VCHI will usually have its own buffering. */
116 #ifndef VCHI_NUM_WRITE_SLOTS
117 #  define VCHI_NUM_WRITE_SLOTS 4
118 #endif
119 
120 /* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
121  * then it's taking up too much buffer space, and the peer service will be told to stop
122  * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
123  * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
124  * is too high. */
125 #ifndef VCHI_XOFF_THRESHOLD
126 #  define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
127 #endif
128 
129 /* After we've sent an XOFF, the peer will be told to resume transmission once the local
130  * service has dequeued/released enough messages that it's now occupying
131  * VCHI_XON_THRESHOLD slots or fewer. */
132 #ifndef VCHI_XON_THRESHOLD
133 #  define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
134 #endif
135 
136 /* A size below which a bulk transfer omits the handshake completely and always goes
137  * via the message channel, if bulk auxiliary is being sent on that service. (The user
138  * can guarantee this by enabling unaligned transmits).
139  * Not API. */
140 #ifndef VCHI_MIN_BULK_SIZE
141 #  define VCHI_MIN_BULK_SIZE    ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
142 #endif
143 
144 /* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
145  * speed and latency; the smaller the chunk size the better change of messages and other
146  * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
147  * break transmissions into chunks.
148  */
149 #ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
150 #  define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
151 #endif
152 
153 /* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
154  * with multiple-line frames. Only use if the receiver can cope. */
155 #ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
156 #  define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
157 #endif
158 
159 /* How many TX messages can we have pending in our transmit slots. Once exhausted,
160  * vchi_msg_queue will be blocked. */
161 #ifndef VCHI_TX_MSG_QUEUE_SIZE
162 #  define VCHI_TX_MSG_QUEUE_SIZE           256
163 #endif
164 
165 /* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
166  * will be suspended until older messages are dequeued/released. */
167 #ifndef VCHI_RX_MSG_QUEUE_SIZE
168 #  define VCHI_RX_MSG_QUEUE_SIZE           256
169 #endif
170 
171 /* Really should be able to cope if we run out of received message descriptors, by
172  * suspending parsing as the comment above says, but we don't. This sweeps the issue
173  * under the carpet. */
174 #if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
175 #  undef VCHI_RX_MSG_QUEUE_SIZE
176 #  define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
177 #endif
178 
179 /* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
180  * will be blocked. */
181 #ifndef VCHI_TX_BULK_QUEUE_SIZE
182 #  define VCHI_TX_BULK_QUEUE_SIZE           64
183 #endif
184 
185 /* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
186  * will be blocked. */
187 #ifndef VCHI_RX_BULK_QUEUE_SIZE
188 #  define VCHI_RX_BULK_QUEUE_SIZE           64
189 #endif
190 
191 /* A limit on how many outstanding bulk requests we expect the peer to give us. If
192  * the peer asks for more than this, VCHI will fail and assert. The number is determined
193  * by the peer's hardware - it's the number of outstanding requests that can be queued
194  * on all bulk channels. VC3's MPHI peripheral allows 16. */
195 #ifndef VCHI_MAX_PEER_BULK_REQUESTS
196 #  define VCHI_MAX_PEER_BULK_REQUESTS       32
197 #endif
198 
199 /* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
200  * transmitter on and off.
201  */
202 /*#define VCHI_CCP2TX_MANUAL_POWER*/
203 
204 #ifndef VCHI_CCP2TX_MANUAL_POWER
205 
206 /* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
207  * negative for no IDLE.
208  */
209 #  ifndef VCHI_CCP2TX_IDLE_TIMEOUT
210 #    define VCHI_CCP2TX_IDLE_TIMEOUT        5
211 #  endif
212 
213 /* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
214  * negative for no OFF.
215  */
216 #  ifndef VCHI_CCP2TX_OFF_TIMEOUT
217 #    define VCHI_CCP2TX_OFF_TIMEOUT         1000
218 #  endif
219 
220 #endif /* VCHI_CCP2TX_MANUAL_POWER */
221 
222 #endif /* VCHI_CFG_H_ */
223 
224 /****************************** End of file **********************************/
225