blob: 1e4718d83d1c288928ae818a506071978bb5495d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Stephen Warren91ea2882013-01-29 16:37:36 +00002/*
Stephen Warren8780f222015-02-16 12:16:14 -07003 * (C) Copyright 2012,2015 Stephen Warren
Stephen Warren91ea2882013-01-29 16:37:36 +00004 */
5
6#ifndef _BCM2835_MBOX_H
7#define _BCM2835_MBOX_H
8
9#include <linux/compiler.h>
10
11/*
12 * The BCM2835 SoC contains (at least) two CPUs; the VideoCore (a/k/a "GPU")
13 * and the ARM CPU. The ARM CPU is often thought of as the main CPU.
14 * However, the VideoCore actually controls the initial SoC boot, and hides
15 * much of the hardware behind a protocol. This protocol is transported
16 * using the SoC's mailbox hardware module.
17 *
18 * The mailbox hardware supports passing 32-bit values back and forth.
19 * Presumably by software convention of the firmware, the bottom 4 bits of the
20 * value are used to indicate a logical channel, and the upper 28 bits are the
21 * actual payload. Various channels exist using these simple raw messages. See
22 * https://github.com/raspberrypi/firmware/wiki/Mailboxes for a list. As an
23 * example, the messages on the power management channel are a bitmask of
24 * devices whose power should be enabled.
25 *
26 * The property mailbox channel passes messages that contain the (16-byte
27 * aligned) ARM physical address of a memory buffer. This buffer is passed to
28 * the VC for processing, is modified in-place by the VC, and the address then
29 * passed back to the ARM CPU as the response mailbox message to indicate
30 * request completion. The buffers have a generic and extensible format; each
31 * buffer contains a standard header, a list of "tags", and a terminating zero
32 * entry. Each tag contains an ID indicating its type, and length fields for
33 * generic parsing. With some limitations, an arbitrary set of tags may be
34 * combined together into a single message buffer. This file defines structs
35 * representing the header and many individual tag layouts and IDs.
36 */
37
38/* Raw mailbox HW */
39
Matthias Brugger64eb0122019-07-24 15:39:05 +010040#define BCM2835_MBOX_PHYSADDR (CONFIG_BCM283x_BASE + 0x0000b880)
Stephen Warren91ea2882013-01-29 16:37:36 +000041
42struct bcm2835_mbox_regs {
43 u32 read;
44 u32 rsvd0[5];
Fabian Vogtbcf941f2019-07-16 13:09:47 +020045 u32 mail0_status;
46 u32 mail0_config;
Stephen Warren91ea2882013-01-29 16:37:36 +000047 u32 write;
Fabian Vogtbcf941f2019-07-16 13:09:47 +020048 u32 rsvd1[5];
49 u32 mail1_status;
50 u32 mail1_config;
Stephen Warren91ea2882013-01-29 16:37:36 +000051};
52
53#define BCM2835_MBOX_STATUS_WR_FULL 0x80000000
54#define BCM2835_MBOX_STATUS_RD_EMPTY 0x40000000
55
56/* Lower 4-bits are channel ID */
57#define BCM2835_CHAN_MASK 0xf
58#define BCM2835_MBOX_PACK(chan, data) (((data) & (~BCM2835_CHAN_MASK)) | \
59 (chan & BCM2835_CHAN_MASK))
60#define BCM2835_MBOX_UNPACK_CHAN(val) ((val) & BCM2835_CHAN_MASK)
61#define BCM2835_MBOX_UNPACK_DATA(val) ((val) & (~BCM2835_CHAN_MASK))
62
63/* Property mailbox buffer structures */
64
65#define BCM2835_MBOX_PROP_CHAN 8
66
67/* All message buffers must start with this header */
68struct bcm2835_mbox_hdr {
69 u32 buf_size;
70 u32 code;
71};
72
73#define BCM2835_MBOX_REQ_CODE 0
74#define BCM2835_MBOX_RESP_CODE_SUCCESS 0x80000000
75
76#define BCM2835_MBOX_INIT_HDR(_m_) { \
77 memset((_m_), 0, sizeof(*(_m_))); \
78 (_m_)->hdr.buf_size = sizeof(*(_m_)); \
79 (_m_)->hdr.code = 0; \
80 (_m_)->end_tag = 0; \
81 }
82
83/*
84 * A message buffer contains a list of tags. Each tag must also start with
85 * a standardized header.
86 */
87struct bcm2835_mbox_tag_hdr {
88 u32 tag;
89 u32 val_buf_size;
90 u32 val_len;
91};
92
93#define BCM2835_MBOX_INIT_TAG(_t_, _id_) { \
94 (_t_)->tag_hdr.tag = BCM2835_MBOX_TAG_##_id_; \
95 (_t_)->tag_hdr.val_buf_size = sizeof((_t_)->body); \
96 (_t_)->tag_hdr.val_len = sizeof((_t_)->body.req); \
97 }
98
99#define BCM2835_MBOX_INIT_TAG_NO_REQ(_t_, _id_) { \
100 (_t_)->tag_hdr.tag = BCM2835_MBOX_TAG_##_id_; \
101 (_t_)->tag_hdr.val_buf_size = sizeof((_t_)->body); \
102 (_t_)->tag_hdr.val_len = 0; \
103 }
104
105/* When responding, the VC sets this bit in val_len to indicate a response */
106#define BCM2835_MBOX_TAG_VAL_LEN_RESPONSE 0x80000000
107
108/*
109 * Below we define the ID and struct for many possible tags. This header only
110 * defines individual tag structs, not entire message structs, since in
111 * general an arbitrary set of tags may be combined into a single message.
112 * Clients of the mbox API are expected to define their own overall message
113 * structures by combining the header, a set of tags, and a terminating
114 * entry. For example,
115 *
116 * struct msg {
117 * struct bcm2835_mbox_hdr hdr;
118 * struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
119 * ... perhaps other tags here ...
120 * u32 end_tag;
121 * };
122 */
123
Stephen Warrencd210c12014-11-18 21:40:21 -0700124#define BCM2835_MBOX_TAG_GET_BOARD_REV 0x00010002
125
Stephen Warrencd210c12014-11-18 21:40:21 -0700126struct bcm2835_mbox_tag_get_board_rev {
127 struct bcm2835_mbox_tag_hdr tag_hdr;
128 union {
129 struct {
130 } req;
131 struct {
132 u32 rev;
133 } resp;
134 } body;
135};
136
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600137#define BCM2835_MBOX_TAG_GET_MAC_ADDRESS 0x00010003
138
139struct bcm2835_mbox_tag_get_mac_address {
140 struct bcm2835_mbox_tag_hdr tag_hdr;
141 union {
142 struct {
143 } req;
144 struct {
145 u8 mac[6];
146 u8 pad[2];
147 } resp;
148 } body;
149};
150
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100151#define BCM2835_MBOX_TAG_GET_BOARD_SERIAL 0x00010004
152
153struct bcm2835_mbox_tag_get_board_serial {
154 struct bcm2835_mbox_tag_hdr tag_hdr;
155 union {
156 struct __packed {
157 u64 serial;
158 } resp;
159 } body;
160};
161
Stephen Warren91ea2882013-01-29 16:37:36 +0000162#define BCM2835_MBOX_TAG_GET_ARM_MEMORY 0x00010005
163
164struct bcm2835_mbox_tag_get_arm_mem {
165 struct bcm2835_mbox_tag_hdr tag_hdr;
166 union {
167 struct {
168 } req;
169 struct {
170 u32 mem_base;
171 u32 mem_size;
172 } resp;
173 } body;
174};
175
Stephen Warren8672d202014-01-13 19:50:11 -0700176#define BCM2835_MBOX_POWER_DEVID_SDHCI 0
177#define BCM2835_MBOX_POWER_DEVID_UART0 1
178#define BCM2835_MBOX_POWER_DEVID_UART1 2
179#define BCM2835_MBOX_POWER_DEVID_USB_HCD 3
180#define BCM2835_MBOX_POWER_DEVID_I2C0 4
181#define BCM2835_MBOX_POWER_DEVID_I2C1 5
182#define BCM2835_MBOX_POWER_DEVID_I2C2 6
183#define BCM2835_MBOX_POWER_DEVID_SPI 7
184#define BCM2835_MBOX_POWER_DEVID_CCP2TX 8
185
Stephen Warren41523682014-02-05 20:42:25 -0700186#define BCM2835_MBOX_POWER_STATE_RESP_ON (1 << 0)
Stephen Warren8672d202014-01-13 19:50:11 -0700187/* Device doesn't exist */
188#define BCM2835_MBOX_POWER_STATE_RESP_NODEV (1 << 1)
189
190#define BCM2835_MBOX_TAG_GET_POWER_STATE 0x00020001
191
192struct bcm2835_mbox_tag_get_power_state {
193 struct bcm2835_mbox_tag_hdr tag_hdr;
194 union {
195 struct {
196 u32 device_id;
197 } req;
198 struct {
199 u32 device_id;
200 u32 state;
201 } resp;
202 } body;
203};
204
205#define BCM2835_MBOX_TAG_SET_POWER_STATE 0x00028001
206
207#define BCM2835_MBOX_SET_POWER_STATE_REQ_ON (1 << 0)
208#define BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT (1 << 1)
209
210struct bcm2835_mbox_tag_set_power_state {
211 struct bcm2835_mbox_tag_hdr tag_hdr;
212 union {
213 struct {
214 u32 device_id;
215 u32 state;
216 } req;
217 struct {
218 u32 device_id;
219 u32 state;
220 } resp;
221 } body;
222};
223
Stephen Warrenc4ab9712013-01-29 16:37:42 +0000224#define BCM2835_MBOX_TAG_GET_CLOCK_RATE 0x00030002
225
226#define BCM2835_MBOX_CLOCK_ID_EMMC 1
227#define BCM2835_MBOX_CLOCK_ID_UART 2
228#define BCM2835_MBOX_CLOCK_ID_ARM 3
229#define BCM2835_MBOX_CLOCK_ID_CORE 4
230#define BCM2835_MBOX_CLOCK_ID_V3D 5
231#define BCM2835_MBOX_CLOCK_ID_H264 6
232#define BCM2835_MBOX_CLOCK_ID_ISP 7
233#define BCM2835_MBOX_CLOCK_ID_SDRAM 8
234#define BCM2835_MBOX_CLOCK_ID_PIXEL 9
235#define BCM2835_MBOX_CLOCK_ID_PWM 10
236
237struct bcm2835_mbox_tag_get_clock_rate {
238 struct bcm2835_mbox_tag_hdr tag_hdr;
239 union {
240 struct {
241 u32 clock_id;
242 } req;
243 struct {
244 u32 clock_id;
245 u32 rate_hz;
246 } resp;
247 } body;
248};
249
Stephen Warren91ea2882013-01-29 16:37:36 +0000250#define BCM2835_MBOX_TAG_ALLOCATE_BUFFER 0x00040001
251
252struct bcm2835_mbox_tag_allocate_buffer {
253 struct bcm2835_mbox_tag_hdr tag_hdr;
254 union {
255 struct {
256 u32 alignment;
257 } req;
258 struct {
259 u32 fb_address;
260 u32 fb_size;
261 } resp;
262 } body;
263};
264
265#define BCM2835_MBOX_TAG_RELEASE_BUFFER 0x00048001
266
267struct bcm2835_mbox_tag_release_buffer {
268 struct bcm2835_mbox_tag_hdr tag_hdr;
269 union {
270 struct {
271 } req;
272 struct {
273 } resp;
274 } body;
275};
276
277#define BCM2835_MBOX_TAG_BLANK_SCREEN 0x00040002
278
279struct bcm2835_mbox_tag_blank_screen {
280 struct bcm2835_mbox_tag_hdr tag_hdr;
281 union {
282 struct {
283 /* bit 0 means on, other bots reserved */
284 u32 state;
285 } req;
286 struct {
287 u32 state;
288 } resp;
289 } body;
290};
291
292/* Physical means output signal */
293#define BCM2835_MBOX_TAG_GET_PHYSICAL_W_H 0x00040003
294#define BCM2835_MBOX_TAG_TEST_PHYSICAL_W_H 0x00044003
295#define BCM2835_MBOX_TAG_SET_PHYSICAL_W_H 0x00048003
296
297struct bcm2835_mbox_tag_physical_w_h {
298 struct bcm2835_mbox_tag_hdr tag_hdr;
299 union {
300 /* req not used for get */
301 struct {
302 u32 width;
303 u32 height;
304 } req;
305 struct {
306 u32 width;
307 u32 height;
308 } resp;
309 } body;
310};
311
312/* Virtual means display buffer */
313#define BCM2835_MBOX_TAG_GET_VIRTUAL_W_H 0x00040004
314#define BCM2835_MBOX_TAG_TEST_VIRTUAL_W_H 0x00044004
315#define BCM2835_MBOX_TAG_SET_VIRTUAL_W_H 0x00048004
316
317struct bcm2835_mbox_tag_virtual_w_h {
318 struct bcm2835_mbox_tag_hdr tag_hdr;
319 union {
320 /* req not used for get */
321 struct {
322 u32 width;
323 u32 height;
324 } req;
325 struct {
326 u32 width;
327 u32 height;
328 } resp;
329 } body;
330};
331
332#define BCM2835_MBOX_TAG_GET_DEPTH 0x00040005
333#define BCM2835_MBOX_TAG_TEST_DEPTH 0x00044005
334#define BCM2835_MBOX_TAG_SET_DEPTH 0x00048005
335
336struct bcm2835_mbox_tag_depth {
337 struct bcm2835_mbox_tag_hdr tag_hdr;
338 union {
339 /* req not used for get */
340 struct {
341 u32 bpp;
342 } req;
343 struct {
344 u32 bpp;
345 } resp;
346 } body;
347};
348
349#define BCM2835_MBOX_TAG_GET_PIXEL_ORDER 0x00040006
Berkus Decker879258f2019-01-13 20:30:40 +0100350#define BCM2835_MBOX_TAG_TEST_PIXEL_ORDER 0x00044006
Stephen Warren91ea2882013-01-29 16:37:36 +0000351#define BCM2835_MBOX_TAG_SET_PIXEL_ORDER 0x00048006
352
353#define BCM2835_MBOX_PIXEL_ORDER_BGR 0
354#define BCM2835_MBOX_PIXEL_ORDER_RGB 1
355
356struct bcm2835_mbox_tag_pixel_order {
357 struct bcm2835_mbox_tag_hdr tag_hdr;
358 union {
359 /* req not used for get */
360 struct {
361 u32 order;
362 } req;
363 struct {
364 u32 order;
365 } resp;
366 } body;
367};
368
369#define BCM2835_MBOX_TAG_GET_ALPHA_MODE 0x00040007
370#define BCM2835_MBOX_TAG_TEST_ALPHA_MODE 0x00044007
371#define BCM2835_MBOX_TAG_SET_ALPHA_MODE 0x00048007
372
373#define BCM2835_MBOX_ALPHA_MODE_0_OPAQUE 0
374#define BCM2835_MBOX_ALPHA_MODE_0_TRANSPARENT 1
375#define BCM2835_MBOX_ALPHA_MODE_IGNORED 2
376
377struct bcm2835_mbox_tag_alpha_mode {
378 struct bcm2835_mbox_tag_hdr tag_hdr;
379 union {
380 /* req not used for get */
381 struct {
382 u32 alpha;
383 } req;
384 struct {
385 u32 alpha;
386 } resp;
387 } body;
388};
389
390#define BCM2835_MBOX_TAG_GET_PITCH 0x00040008
391
392struct bcm2835_mbox_tag_pitch {
393 struct bcm2835_mbox_tag_hdr tag_hdr;
394 union {
395 struct {
396 } req;
397 struct {
398 u32 pitch;
399 } resp;
400 } body;
401};
402
403/* Offset of display window within buffer */
404#define BCM2835_MBOX_TAG_GET_VIRTUAL_OFFSET 0x00040009
405#define BCM2835_MBOX_TAG_TEST_VIRTUAL_OFFSET 0x00044009
406#define BCM2835_MBOX_TAG_SET_VIRTUAL_OFFSET 0x00048009
407
408struct bcm2835_mbox_tag_virtual_offset {
409 struct bcm2835_mbox_tag_hdr tag_hdr;
410 union {
411 /* req not used for get */
412 struct {
413 u32 x;
414 u32 y;
415 } req;
416 struct {
417 u32 x;
418 u32 y;
419 } resp;
420 } body;
421};
422
423#define BCM2835_MBOX_TAG_GET_OVERSCAN 0x0004000a
424#define BCM2835_MBOX_TAG_TEST_OVERSCAN 0x0004400a
425#define BCM2835_MBOX_TAG_SET_OVERSCAN 0x0004800a
426
427struct bcm2835_mbox_tag_overscan {
428 struct bcm2835_mbox_tag_hdr tag_hdr;
429 union {
430 /* req not used for get */
431 struct {
432 u32 top;
433 u32 bottom;
434 u32 left;
435 u32 right;
436 } req;
437 struct {
438 u32 top;
439 u32 bottom;
440 u32 left;
Andre Heider952ad9e2013-10-22 22:27:20 +0200441 u32 right;
Stephen Warren91ea2882013-01-29 16:37:36 +0000442 } resp;
443 } body;
444};
445
446#define BCM2835_MBOX_TAG_GET_PALETTE 0x0004000b
447
448struct bcm2835_mbox_tag_get_palette {
449 struct bcm2835_mbox_tag_hdr tag_hdr;
450 union {
451 struct {
452 } req;
453 struct {
454 u32 data[1024];
455 } resp;
456 } body;
457};
458
459#define BCM2835_MBOX_TAG_TEST_PALETTE 0x0004400b
460
461struct bcm2835_mbox_tag_test_palette {
462 struct bcm2835_mbox_tag_hdr tag_hdr;
463 union {
464 struct {
465 u32 offset;
466 u32 num_entries;
467 u32 data[256];
468 } req;
469 struct {
470 u32 is_invalid;
471 } resp;
472 } body;
473};
474
475#define BCM2835_MBOX_TAG_SET_PALETTE 0x0004800b
476
477struct bcm2835_mbox_tag_set_palette {
478 struct bcm2835_mbox_tag_hdr tag_hdr;
479 union {
480 struct {
481 u32 offset;
482 u32 num_entries;
483 u32 data[256];
484 } req;
485 struct {
486 u32 is_invalid;
487 } resp;
488 } body;
489};
490
491/*
492 * Pass a raw u32 message to the VC, and receive a raw u32 back.
493 *
494 * Returns 0 for success, any other value for error.
495 */
496int bcm2835_mbox_call_raw(u32 chan, u32 send, u32 *recv);
497
498/*
499 * Pass a complete property-style buffer to the VC, and wait until it has
500 * been processed.
501 *
502 * This function expects a pointer to the mbox_hdr structure in an attempt
503 * to ensure some degree of type safety. However, some number of tags and
504 * a termination value are expected to immediately follow the header in
505 * memory, as required by the property protocol.
506 *
Alexander Steinfbeb89d2015-07-24 09:22:13 +0200507 * Each struct bcm2835_mbox_hdr passed must be allocated with
508 * ALLOC_CACHE_ALIGN_BUFFER(x, y, z) to ensure proper cache flush/invalidate.
509 *
Stephen Warren91ea2882013-01-29 16:37:36 +0000510 * Returns 0 for success, any other value for error.
511 */
512int bcm2835_mbox_call_prop(u32 chan, struct bcm2835_mbox_hdr *buffer);
513
514#endif