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