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