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