vcprop.h revision 1.19 1 1.19 rin /* $NetBSD: vcprop.h,v 1.19 2020/12/01 04:14:31 rin Exp $ */
2 1.1 skrll
3 1.1 skrll /*-
4 1.1 skrll * Copyright (c) 2012 The NetBSD Foundation, Inc.
5 1.1 skrll * All rights reserved.
6 1.1 skrll *
7 1.1 skrll * This code is derived from software contributed to The NetBSD Foundation
8 1.1 skrll * by Nick Hudson
9 1.1 skrll *
10 1.1 skrll * Redistribution and use in source and binary forms, with or without
11 1.1 skrll * modification, are permitted provided that the following conditions
12 1.1 skrll * are met:
13 1.1 skrll * 1. Redistributions of source code must retain the above copyright
14 1.1 skrll * notice, this list of conditions and the following disclaimer.
15 1.1 skrll * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 skrll * notice, this list of conditions and the following disclaimer in the
17 1.1 skrll * documentation and/or other materials provided with the distribution.
18 1.1 skrll *
19 1.1 skrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 skrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 skrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 skrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 skrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 skrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 skrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 skrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 skrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 skrll * POSSIBILITY OF SUCH DAMAGE.
30 1.1 skrll */
31 1.1 skrll
32 1.1 skrll /*
33 1.1 skrll * Mailbox property interface
34 1.1 skrll */
35 1.1 skrll
36 1.1 skrll #ifndef _EVBARM_RPI_VCPROP_H_
37 1.1 skrll #define _EVBARM_RPI_VCPROP_H_
38 1.1 skrll
39 1.9 jmcneill #include "opt_vcprop.h"
40 1.9 jmcneill
41 1.19 rin #include <sys/endian.h>
42 1.19 rin
43 1.1 skrll struct vcprop_tag {
44 1.1 skrll uint32_t vpt_tag;
45 1.1 skrll #define VCPROPTAG_NULL 0x00000000
46 1.1 skrll #define VCPROPTAG_GET_FIRMWAREREV 0x00000001
47 1.1 skrll #define VCPROPTAG_GET_BOARDMODEL 0x00010001
48 1.1 skrll #define VCPROPTAG_GET_BOARDREVISION 0x00010002
49 1.1 skrll #define VCPROPTAG_GET_MACADDRESS 0x00010003
50 1.1 skrll #define VCPROPTAG_GET_BOARDSERIAL 0x00010004
51 1.1 skrll #define VCPROPTAG_GET_ARMMEMORY 0x00010005
52 1.1 skrll #define VCPROPTAG_GET_VCMEMORY 0x00010006
53 1.1 skrll #define VCPROPTAG_GET_CLOCKS 0x00010007
54 1.2 skrll
55 1.3 jmcneill #define VCPROPTAG_GET_POWERSTATE 0x00020001
56 1.3 jmcneill #define VCPROPTAG_GET_POWERTIMING 0x00020002
57 1.3 jmcneill #define VCPROPTAG_SET_POWERSTATE 0x00028001
58 1.3 jmcneill
59 1.2 skrll #define VCPROPTAG_GET_CLOCKSTATE 0x00030001
60 1.2 skrll #define VCPROPTAG_SET_CLOCKSTATE 0x00038001
61 1.2 skrll #define VCPROPTAG_GET_CLOCKRATE 0x00030002
62 1.2 skrll #define VCPROPTAG_SET_CLOCKRATE 0x00038002
63 1.4 jmcneill #define VCPROPTAG_GET_MIN_CLOCKRATE 0x00030007
64 1.4 jmcneill #define VCPROPTAG_GET_MAX_CLOCKRATE 0x00030004
65 1.15 mlelstv #define VCPROPTAG_GET_TURBO 0x00030009
66 1.15 mlelstv #define VCPROPTAG_SET_TURBO 0x00038009
67 1.3 jmcneill
68 1.3 jmcneill #define VCPROPTAG_GET_VOLTAGE 0x00030003
69 1.3 jmcneill #define VCPROPTAG_SET_VOLTAGE 0x00038003
70 1.3 jmcneill #define VCPROPTAG_GET_MIN_VOLTAGE 0x00030008
71 1.3 jmcneill #define VCPROPTAG_GET_MAX_VOLTAGE 0x00030005
72 1.3 jmcneill
73 1.3 jmcneill #define VCPROPTAG_GET_TEMPERATURE 0x00030006
74 1.3 jmcneill #define VCPROPTAG_GET_MAX_TEMPERATURE 0x0003000a
75 1.3 jmcneill
76 1.1 skrll #define VCPROPTAG_GET_CMDLINE 0x00050001
77 1.1 skrll #define VCPROPTAG_GET_DMACHAN 0x00060001
78 1.5 jmcneill
79 1.5 jmcneill #define VCPROPTAG_ALLOCATE_BUFFER 0x00040001
80 1.7 jmcneill #define VCPROPTAG_BLANK_SCREEN 0x00040002
81 1.5 jmcneill #define VCPROPTAG_GET_FB_RES 0x00040003
82 1.6 jmcneill #define VCPROPTAG_SET_FB_RES 0x00048003
83 1.7 jmcneill #define VCPROPTAG_GET_FB_VRES 0x00040004
84 1.7 jmcneill #define VCPROPTAG_SET_FB_VRES 0x00048004
85 1.5 jmcneill #define VCPROPTAG_GET_FB_DEPTH 0x00040005
86 1.6 jmcneill #define VCPROPTAG_SET_FB_DEPTH 0x00048005
87 1.5 jmcneill #define VCPROPTAG_GET_FB_PIXEL_ORDER 0x00040006
88 1.6 jmcneill #define VCPROPTAG_SET_FB_PIXEL_ORDER 0x00048006
89 1.7 jmcneill #define VCPROPTAG_GET_FB_ALPHA_MODE 0x00040007
90 1.7 jmcneill #define VCPROPTAG_SET_FB_ALPHA_MODE 0x00048007
91 1.5 jmcneill #define VCPROPTAG_GET_FB_PITCH 0x00040008
92 1.5 jmcneill
93 1.5 jmcneill #define VCPROPTAG_GET_EDID_BLOCK 0x00030020
94 1.5 jmcneill
95 1.11 macallan #define VCPROPTAG_ALLOCMEM 0x0003000c
96 1.11 macallan #define VCPROPTAG_LOCKMEM 0x0003000d
97 1.11 macallan #define VCPROPTAG_UNLOCKMEM 0x0003000e
98 1.11 macallan #define VCPROPTAG_RELEASEMEM 0x0003000f
99 1.15 mlelstv #define VCPROPTAG_EXECUTE_CODE 0x00030010
100 1.15 mlelstv #define VCPROPTAG_EXECUTE_QPU 0x00030011
101 1.15 mlelstv #define VCPROPTAG_SET_ENABLE_QPU 0x00030012
102 1.15 mlelstv #define VCPROPTAG_GET_DISPMANX_HANDLE 0x00030014
103 1.11 macallan
104 1.12 macallan #define VCPROPTAG_SET_CURSOR_INFO 0x00008010
105 1.12 macallan #define VCPROPTAG_SET_CURSOR_STATE 0x00008011
106 1.5 jmcneill
107 1.1 skrll uint32_t vpt_len;
108 1.1 skrll uint32_t vpt_rcode;
109 1.1 skrll #define VCPROPTAG_REQUEST (0U << 31)
110 1.1 skrll #define VCPROPTAG_RESPONSE (1U << 31)
111 1.1 skrll
112 1.1 skrll };
113 1.1 skrll
114 1.1 skrll #define VCPROPTAG_LEN(x) (sizeof((x)) - sizeof(struct vcprop_tag))
115 1.1 skrll
116 1.1 skrll struct vcprop_memory {
117 1.1 skrll uint32_t base;
118 1.1 skrll uint32_t size;
119 1.1 skrll };
120 1.1 skrll
121 1.1 skrll #define VCPROP_MAXMEMBLOCKS 4
122 1.1 skrll struct vcprop_tag_memory {
123 1.1 skrll struct vcprop_tag tag;
124 1.1 skrll struct vcprop_memory mem[VCPROP_MAXMEMBLOCKS];
125 1.1 skrll };
126 1.1 skrll
127 1.1 skrll struct vcprop_tag_fwrev {
128 1.1 skrll struct vcprop_tag tag;
129 1.1 skrll uint32_t rev;
130 1.1 skrll };
131 1.1 skrll
132 1.1 skrll struct vcprop_tag_boardmodel {
133 1.1 skrll struct vcprop_tag tag;
134 1.1 skrll uint32_t model;
135 1.18 rin };
136 1.1 skrll
137 1.1 skrll struct vcprop_tag_boardrev {
138 1.1 skrll struct vcprop_tag tag;
139 1.1 skrll uint32_t rev;
140 1.18 rin };
141 1.1 skrll
142 1.16 jmcneill #define VCPROP_REV_PCBREV __BITS(3,0)
143 1.16 jmcneill #define VCPROP_REV_MODEL __BITS(11,4)
144 1.16 jmcneill #define RPI_MODEL_A 0
145 1.16 jmcneill #define RPI_MODEL_B 1
146 1.16 jmcneill #define RPI_MODEL_A_PLUS 2
147 1.16 jmcneill #define RPI_MODEL_B_PLUS 3
148 1.16 jmcneill #define RPI_MODEL_B_PI2 4
149 1.16 jmcneill #define RPI_MODEL_ALPHA 5
150 1.16 jmcneill #define RPI_MODEL_COMPUTE 6
151 1.16 jmcneill #define RPI_MODEL_ZERO 7
152 1.16 jmcneill #define RPI_MODEL_B_PI3 8
153 1.16 jmcneill #define RPI_MODEL_COMPUTE_PI3 9
154 1.16 jmcneill #define RPI_MODEL_ZERO_W 10
155 1.16 jmcneill #define VCPROP_REV_PROCESSOR __BITS(15,12)
156 1.16 jmcneill #define RPI_PROCESSOR_BCM2835 0
157 1.16 jmcneill #define RPI_PROCESSOR_BCM2836 1
158 1.16 jmcneill #define RPI_PROCESSOR_BCM2837 2
159 1.16 jmcneill #define VCPROP_REV_MANUF __BITS(19,16)
160 1.16 jmcneill #define VCPROP_REV_MEMSIZE __BITS(22,20)
161 1.16 jmcneill #define VCPROP_REV_ENCFLAG __BIT(23)
162 1.16 jmcneill #define VCPROP_REV_WARRANTY __BITS(25,24)
163 1.16 jmcneill
164 1.1 skrll struct vcprop_tag_macaddr {
165 1.1 skrll struct vcprop_tag tag;
166 1.1 skrll uint64_t addr;
167 1.8 skrll } __packed;
168 1.1 skrll
169 1.1 skrll struct vcprop_tag_boardserial {
170 1.1 skrll struct vcprop_tag tag;
171 1.1 skrll uint64_t sn;
172 1.8 skrll } __packed;
173 1.1 skrll
174 1.2 skrll #define VCPROP_CLK_EMMC 1
175 1.2 skrll #define VCPROP_CLK_UART 2
176 1.2 skrll #define VCPROP_CLK_ARM 3
177 1.2 skrll #define VCPROP_CLK_CORE 4
178 1.2 skrll #define VCPROP_CLK_V3D 5
179 1.2 skrll #define VCPROP_CLK_H264 6
180 1.2 skrll #define VCPROP_CLK_ISP 7
181 1.2 skrll #define VCPROP_CLK_SDRAM 8
182 1.2 skrll #define VCPROP_CLK_PIXEL 9
183 1.2 skrll #define VCPROP_CLK_PWM 10
184 1.17 skrll #define VCPROP_CLK_EMMC2 12
185 1.2 skrll
186 1.1 skrll struct vcprop_clock {
187 1.1 skrll uint32_t pclk;
188 1.1 skrll uint32_t cclk;
189 1.1 skrll };
190 1.1 skrll
191 1.1 skrll #define VCPROP_MAXCLOCKS 16
192 1.1 skrll struct vcprop_tag_clock {
193 1.1 skrll struct vcprop_tag tag;
194 1.1 skrll struct vcprop_clock clk[VCPROP_MAXCLOCKS];
195 1.1 skrll };
196 1.1 skrll
197 1.9 jmcneill #ifndef VCPROP_MAXCMDLINE
198 1.9 jmcneill #define VCPROP_MAXCMDLINE 1024
199 1.9 jmcneill #endif
200 1.1 skrll struct vcprop_tag_cmdline {
201 1.1 skrll struct vcprop_tag tag;
202 1.1 skrll uint8_t cmdline[VCPROP_MAXCMDLINE];
203 1.1 skrll };
204 1.1 skrll
205 1.1 skrll struct vcprop_tag_dmachan {
206 1.1 skrll struct vcprop_tag tag;
207 1.1 skrll uint32_t mask;
208 1.1 skrll };
209 1.1 skrll
210 1.2 skrll struct vcprop_tag_clockstate {
211 1.2 skrll struct vcprop_tag tag;
212 1.2 skrll uint32_t id;
213 1.2 skrll uint32_t state;
214 1.2 skrll };
215 1.2 skrll
216 1.2 skrll struct vcprop_tag_clockrate {
217 1.2 skrll struct vcprop_tag tag;
218 1.2 skrll uint32_t id;
219 1.2 skrll uint32_t rate;
220 1.14 skrll uint32_t noturbo;
221 1.2 skrll };
222 1.2 skrll
223 1.3 jmcneill #define VCPROP_VOLTAGE_CORE 1
224 1.3 jmcneill #define VCPROP_VOLTAGE_SDRAM_C 2
225 1.3 jmcneill #define VCPROP_VOLTAGE_SDRAM_P 3
226 1.3 jmcneill #define VCPROP_VOLTAGE_SDRAM_I 4
227 1.3 jmcneill
228 1.3 jmcneill struct vcprop_tag_voltage {
229 1.3 jmcneill struct vcprop_tag tag;
230 1.3 jmcneill uint32_t id;
231 1.3 jmcneill uint32_t value;
232 1.3 jmcneill };
233 1.3 jmcneill
234 1.3 jmcneill #define VCPROP_TEMP_SOC 0
235 1.3 jmcneill
236 1.3 jmcneill struct vcprop_tag_temperature {
237 1.3 jmcneill struct vcprop_tag tag;
238 1.3 jmcneill uint32_t id;
239 1.3 jmcneill uint32_t value;
240 1.3 jmcneill };
241 1.3 jmcneill
242 1.3 jmcneill #define VCPROP_POWER_SDCARD 0
243 1.3 jmcneill #define VCPROP_POWER_UART0 1
244 1.3 jmcneill #define VCPROP_POWER_UART1 2
245 1.3 jmcneill #define VCPROP_POWER_USB 3
246 1.3 jmcneill #define VCPROP_POWER_I2C0 4
247 1.3 jmcneill #define VCPROP_POWER_I2C1 5
248 1.3 jmcneill #define VCPROP_POWER_I2C2 6
249 1.3 jmcneill #define VCPROP_POWER_SPI 7
250 1.3 jmcneill #define VCPROP_POWER_CCP2TX 8
251 1.3 jmcneill
252 1.3 jmcneill struct vcprop_tag_powertiming {
253 1.3 jmcneill struct vcprop_tag tag;
254 1.3 jmcneill uint32_t id;
255 1.3 jmcneill uint32_t waitusec;
256 1.3 jmcneill };
257 1.3 jmcneill
258 1.3 jmcneill struct vcprop_tag_powerstate {
259 1.3 jmcneill struct vcprop_tag tag;
260 1.3 jmcneill uint32_t id;
261 1.3 jmcneill uint32_t state;
262 1.3 jmcneill };
263 1.3 jmcneill
264 1.5 jmcneill struct vcprop_tag_allocbuf {
265 1.5 jmcneill struct vcprop_tag tag;
266 1.5 jmcneill uint32_t address; /* alignment for request */
267 1.5 jmcneill uint32_t size;
268 1.5 jmcneill };
269 1.5 jmcneill
270 1.7 jmcneill #define VCPROP_BLANK_OFF 0
271 1.7 jmcneill #define VCPROP_BLANK_ON 1
272 1.7 jmcneill
273 1.7 jmcneill struct vcprop_tag_blankscreen {
274 1.7 jmcneill struct vcprop_tag tag;
275 1.7 jmcneill uint32_t state;
276 1.7 jmcneill };
277 1.7 jmcneill
278 1.5 jmcneill struct vcprop_tag_fbres {
279 1.5 jmcneill struct vcprop_tag tag;
280 1.5 jmcneill uint32_t width;
281 1.5 jmcneill uint32_t height;
282 1.5 jmcneill };
283 1.5 jmcneill
284 1.5 jmcneill struct vcprop_tag_fbdepth {
285 1.5 jmcneill struct vcprop_tag tag;
286 1.5 jmcneill uint32_t bpp;
287 1.5 jmcneill };
288 1.5 jmcneill
289 1.5 jmcneill #define VCPROP_PIXEL_BGR 0
290 1.5 jmcneill #define VCPROP_PIXEL_RGB 1
291 1.5 jmcneill
292 1.5 jmcneill struct vcprop_tag_fbpixelorder {
293 1.5 jmcneill struct vcprop_tag tag;
294 1.5 jmcneill uint32_t state;
295 1.5 jmcneill };
296 1.5 jmcneill
297 1.5 jmcneill struct vcprop_tag_fbpitch {
298 1.5 jmcneill struct vcprop_tag tag;
299 1.5 jmcneill uint32_t linebytes;
300 1.5 jmcneill };
301 1.5 jmcneill
302 1.7 jmcneill #define VCPROP_ALPHA_ENABLED 0
303 1.7 jmcneill #define VCPROP_ALPHA_REVERSED 1
304 1.7 jmcneill #define VCPROP_ALPHA_IGNORED 2
305 1.7 jmcneill
306 1.7 jmcneill struct vcprop_tag_fbalpha {
307 1.7 jmcneill struct vcprop_tag tag;
308 1.7 jmcneill uint32_t state;
309 1.7 jmcneill };
310 1.7 jmcneill
311 1.5 jmcneill struct vcprop_tag_edidblock {
312 1.5 jmcneill struct vcprop_tag tag;
313 1.5 jmcneill uint32_t blockno;
314 1.5 jmcneill uint32_t status;
315 1.5 jmcneill uint8_t data[128];
316 1.5 jmcneill };
317 1.5 jmcneill
318 1.10 macallan struct vcprop_tag_cursorinfo {
319 1.10 macallan struct vcprop_tag tag;
320 1.10 macallan uint32_t width;
321 1.10 macallan uint32_t height;
322 1.13 macallan uint32_t format;
323 1.11 macallan uint32_t pixels; /* bus address in VC memory */
324 1.10 macallan uint32_t hotspot_x;
325 1.10 macallan uint32_t hotspot_y;
326 1.10 macallan };
327 1.10 macallan
328 1.10 macallan struct vcprop_tag_cursorstate {
329 1.10 macallan struct vcprop_tag tag;
330 1.10 macallan uint32_t enable; /* 1 - visible */
331 1.10 macallan uint32_t x;
332 1.10 macallan uint32_t y;
333 1.10 macallan uint32_t flags; /* 0 - display coord. 1 - fb coord. */
334 1.10 macallan };
335 1.10 macallan
336 1.11 macallan struct vcprop_tag_allocmem {
337 1.11 macallan struct vcprop_tag tag;
338 1.11 macallan uint32_t size; /* handle returned here */
339 1.11 macallan uint32_t align;
340 1.11 macallan uint32_t flags;
341 1.11 macallan /*
342 1.11 macallan * flag definitions from
343 1.11 macallan * https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
344 1.11 macallan */
345 1.11 macallan #define MEM_FLAG_DISCARDABLE (1 << 0) /* can be resized to 0 at any time. Use for cached data */
346 1.11 macallan #define MEM_FLAG_NORMAL (0 << 2) /* normal allocating alias. Don't use from ARM */
347 1.11 macallan #define MEM_FLAG_DIRECT (1 << 2) /* 0xC alias uncached */
348 1.11 macallan #define MEM_FLAG_COHERENT (2 << 2) /* 0x8 alias. Non-allocating in L2 but coherent */
349 1.11 macallan #define MEM_FLAG_L1_NONALLOCATING (MEM_FLAG_DIRECT | MEM_FLAG_COHERENT) /* Allocating in L2 */
350 1.11 macallan #define MEM_FLAG_ZERO (1 << 4) /* initialise buffer to all zeros */
351 1.11 macallan #define MEM_FLAG_NO_INIT (1 << 5) /* don't initialise (default is initialise to all ones */
352 1.11 macallan #define MEM_FLAG_HINT_PERMALOCK (1 << 6) /* Likely to be locked for long periods of time. */
353 1.11 macallan };
354 1.11 macallan
355 1.11 macallan /* also for unlock and release */
356 1.11 macallan struct vcprop_tag_lockmem {
357 1.11 macallan struct vcprop_tag tag;
358 1.11 macallan uint32_t handle; /* bus address returned here */
359 1.11 macallan };
360 1.11 macallan
361 1.1 skrll struct vcprop_buffer_hdr {
362 1.1 skrll uint32_t vpb_len;
363 1.1 skrll uint32_t vpb_rcode;
364 1.1 skrll #define VCPROP_PROCESS_REQUEST 0
365 1.1 skrll #define VCPROP_REQ_SUCCESS (1U << 31)
366 1.1 skrll #define VCPROP_REQ_EPARSE (1U << 0)
367 1.1 skrll };
368 1.1 skrll
369 1.1 skrll static inline bool
370 1.1 skrll vcprop_buffer_success_p(struct vcprop_buffer_hdr *vpbh)
371 1.1 skrll {
372 1.1 skrll
373 1.19 rin return le32toh(vpbh->vpb_rcode) & VCPROP_REQ_SUCCESS;
374 1.1 skrll }
375 1.1 skrll
376 1.1 skrll static inline bool
377 1.1 skrll vcprop_tag_success_p(struct vcprop_tag *vpbt)
378 1.1 skrll {
379 1.1 skrll
380 1.19 rin return le32toh(vpbt->vpt_rcode) & VCPROPTAG_RESPONSE;
381 1.1 skrll }
382 1.1 skrll
383 1.1 skrll static inline size_t
384 1.1 skrll vcprop_tag_resplen(struct vcprop_tag *vpbt)
385 1.1 skrll {
386 1.1 skrll
387 1.19 rin return le32toh(vpbt->vpt_rcode) & ~VCPROPTAG_RESPONSE;
388 1.1 skrll }
389 1.1 skrll
390 1.1 skrll #endif /* _EVBARM_RPI_VCPROP_H_ */
391 1.13 macallan
392 1.13 macallan uint32_t rpi_alloc_mem(uint32_t, uint32_t, uint32_t);
393 1.13 macallan bus_addr_t rpi_lock_mem(uint32_t);
394 1.13 macallan int rpi_unlock_mem(uint32_t);
395 1.13 macallan int rpi_release_mem(uint32_t);
396 1.13 macallan
397 1.13 macallan int rpi_fb_set_video(int);
398 1.13 macallan
399 1.13 macallan int rpi_fb_movecursor(int, int, int);
400 1.13 macallan int rpi_fb_initcursor(bus_addr_t, int, int);
401