2 * (C) Copyright 2012 Stephen Warren
4 * SPDX-License-Identifier: GPL-2.0+
7 #ifndef _BCM2835_MBOX_H
8 #define _BCM2835_MBOX_H
10 #include <linux/compiler.h>
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.
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.
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.
41 #define BCM2835_MBOX_PHYSADDR 0x2000b880
43 struct bcm2835_mbox_regs {
51 #define BCM2835_MBOX_STATUS_WR_FULL 0x80000000
52 #define BCM2835_MBOX_STATUS_RD_EMPTY 0x40000000
54 /* Lower 4-bits are channel ID */
55 #define BCM2835_CHAN_MASK 0xf
56 #define BCM2835_MBOX_PACK(chan, data) (((data) & (~BCM2835_CHAN_MASK)) | \
57 (chan & BCM2835_CHAN_MASK))
58 #define BCM2835_MBOX_UNPACK_CHAN(val) ((val) & BCM2835_CHAN_MASK)
59 #define BCM2835_MBOX_UNPACK_DATA(val) ((val) & (~BCM2835_CHAN_MASK))
61 /* Property mailbox buffer structures */
63 #define BCM2835_MBOX_PROP_CHAN 8
65 /* All message buffers must start with this header */
66 struct bcm2835_mbox_hdr {
71 #define BCM2835_MBOX_REQ_CODE 0
72 #define BCM2835_MBOX_RESP_CODE_SUCCESS 0x80000000
74 #define BCM2835_MBOX_INIT_HDR(_m_) { \
75 memset((_m_), 0, sizeof(*(_m_))); \
76 (_m_)->hdr.buf_size = sizeof(*(_m_)); \
77 (_m_)->hdr.code = 0; \
82 * A message buffer contains a list of tags. Each tag must also start with
83 * a standardized header.
85 struct bcm2835_mbox_tag_hdr {
91 #define BCM2835_MBOX_INIT_TAG(_t_, _id_) { \
92 (_t_)->tag_hdr.tag = BCM2835_MBOX_TAG_##_id_; \
93 (_t_)->tag_hdr.val_buf_size = sizeof((_t_)->body); \
94 (_t_)->tag_hdr.val_len = sizeof((_t_)->body.req); \
97 #define BCM2835_MBOX_INIT_TAG_NO_REQ(_t_, _id_) { \
98 (_t_)->tag_hdr.tag = BCM2835_MBOX_TAG_##_id_; \
99 (_t_)->tag_hdr.val_buf_size = sizeof((_t_)->body); \
100 (_t_)->tag_hdr.val_len = 0; \
103 /* When responding, the VC sets this bit in val_len to indicate a response */
104 #define BCM2835_MBOX_TAG_VAL_LEN_RESPONSE 0x80000000
107 * Below we define the ID and struct for many possible tags. This header only
108 * defines individual tag structs, not entire message structs, since in
109 * general an arbitrary set of tags may be combined into a single message.
110 * Clients of the mbox API are expected to define their own overall message
111 * structures by combining the header, a set of tags, and a terminating
112 * entry. For example,
115 * struct bcm2835_mbox_hdr hdr;
116 * struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
117 * ... perhaps other tags here ...
122 #define BCM2835_MBOX_TAG_GET_BOARD_REV 0x00010002
126 * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/
127 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=32733
128 * 0x10, 0x11 from swarren's testing
130 #define BCM2835_BOARD_REV_B_I2C0_2 0x2
131 #define BCM2835_BOARD_REV_B_I2C0_3 0x3
132 #define BCM2835_BOARD_REV_B_I2C1_4 0x4
133 #define BCM2835_BOARD_REV_B_I2C1_5 0x5
134 #define BCM2835_BOARD_REV_B_I2C1_6 0x6
135 #define BCM2835_BOARD_REV_A_7 0x7
136 #define BCM2835_BOARD_REV_A_8 0x8
137 #define BCM2835_BOARD_REV_A_9 0x9
138 #define BCM2835_BOARD_REV_B_REV2_d 0xd
139 #define BCM2835_BOARD_REV_B_REV2_e 0xe
140 #define BCM2835_BOARD_REV_B_REV2_f 0xf
141 #define BCM2835_BOARD_REV_B_PLUS 0x10
142 #define BCM2835_BOARD_REV_CM 0x11
144 struct bcm2835_mbox_tag_get_board_rev {
145 struct bcm2835_mbox_tag_hdr tag_hdr;
155 #define BCM2835_MBOX_TAG_GET_MAC_ADDRESS 0x00010003
157 struct bcm2835_mbox_tag_get_mac_address {
158 struct bcm2835_mbox_tag_hdr tag_hdr;
169 #define BCM2835_MBOX_TAG_GET_ARM_MEMORY 0x00010005
171 struct bcm2835_mbox_tag_get_arm_mem {
172 struct bcm2835_mbox_tag_hdr tag_hdr;
183 #define BCM2835_MBOX_POWER_DEVID_SDHCI 0
184 #define BCM2835_MBOX_POWER_DEVID_UART0 1
185 #define BCM2835_MBOX_POWER_DEVID_UART1 2
186 #define BCM2835_MBOX_POWER_DEVID_USB_HCD 3
187 #define BCM2835_MBOX_POWER_DEVID_I2C0 4
188 #define BCM2835_MBOX_POWER_DEVID_I2C1 5
189 #define BCM2835_MBOX_POWER_DEVID_I2C2 6
190 #define BCM2835_MBOX_POWER_DEVID_SPI 7
191 #define BCM2835_MBOX_POWER_DEVID_CCP2TX 8
193 #define BCM2835_MBOX_POWER_STATE_RESP_ON (1 << 0)
194 /* Device doesn't exist */
195 #define BCM2835_MBOX_POWER_STATE_RESP_NODEV (1 << 1)
197 #define BCM2835_MBOX_TAG_GET_POWER_STATE 0x00020001
199 struct bcm2835_mbox_tag_get_power_state {
200 struct bcm2835_mbox_tag_hdr tag_hdr;
212 #define BCM2835_MBOX_TAG_SET_POWER_STATE 0x00028001
214 #define BCM2835_MBOX_SET_POWER_STATE_REQ_ON (1 << 0)
215 #define BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT (1 << 1)
217 struct bcm2835_mbox_tag_set_power_state {
218 struct bcm2835_mbox_tag_hdr tag_hdr;
231 #define BCM2835_MBOX_TAG_GET_CLOCK_RATE 0x00030002
233 #define BCM2835_MBOX_CLOCK_ID_EMMC 1
234 #define BCM2835_MBOX_CLOCK_ID_UART 2
235 #define BCM2835_MBOX_CLOCK_ID_ARM 3
236 #define BCM2835_MBOX_CLOCK_ID_CORE 4
237 #define BCM2835_MBOX_CLOCK_ID_V3D 5
238 #define BCM2835_MBOX_CLOCK_ID_H264 6
239 #define BCM2835_MBOX_CLOCK_ID_ISP 7
240 #define BCM2835_MBOX_CLOCK_ID_SDRAM 8
241 #define BCM2835_MBOX_CLOCK_ID_PIXEL 9
242 #define BCM2835_MBOX_CLOCK_ID_PWM 10
244 struct bcm2835_mbox_tag_get_clock_rate {
245 struct bcm2835_mbox_tag_hdr tag_hdr;
257 #define BCM2835_MBOX_TAG_ALLOCATE_BUFFER 0x00040001
259 struct bcm2835_mbox_tag_allocate_buffer {
260 struct bcm2835_mbox_tag_hdr tag_hdr;
272 #define BCM2835_MBOX_TAG_RELEASE_BUFFER 0x00048001
274 struct bcm2835_mbox_tag_release_buffer {
275 struct bcm2835_mbox_tag_hdr tag_hdr;
284 #define BCM2835_MBOX_TAG_BLANK_SCREEN 0x00040002
286 struct bcm2835_mbox_tag_blank_screen {
287 struct bcm2835_mbox_tag_hdr tag_hdr;
290 /* bit 0 means on, other bots reserved */
299 /* Physical means output signal */
300 #define BCM2835_MBOX_TAG_GET_PHYSICAL_W_H 0x00040003
301 #define BCM2835_MBOX_TAG_TEST_PHYSICAL_W_H 0x00044003
302 #define BCM2835_MBOX_TAG_SET_PHYSICAL_W_H 0x00048003
304 struct bcm2835_mbox_tag_physical_w_h {
305 struct bcm2835_mbox_tag_hdr tag_hdr;
307 /* req not used for get */
319 /* Virtual means display buffer */
320 #define BCM2835_MBOX_TAG_GET_VIRTUAL_W_H 0x00040004
321 #define BCM2835_MBOX_TAG_TEST_VIRTUAL_W_H 0x00044004
322 #define BCM2835_MBOX_TAG_SET_VIRTUAL_W_H 0x00048004
324 struct bcm2835_mbox_tag_virtual_w_h {
325 struct bcm2835_mbox_tag_hdr tag_hdr;
327 /* req not used for get */
339 #define BCM2835_MBOX_TAG_GET_DEPTH 0x00040005
340 #define BCM2835_MBOX_TAG_TEST_DEPTH 0x00044005
341 #define BCM2835_MBOX_TAG_SET_DEPTH 0x00048005
343 struct bcm2835_mbox_tag_depth {
344 struct bcm2835_mbox_tag_hdr tag_hdr;
346 /* req not used for get */
356 #define BCM2835_MBOX_TAG_GET_PIXEL_ORDER 0x00040006
357 #define BCM2835_MBOX_TAG_TEST_PIXEL_ORDER 0x00044005
358 #define BCM2835_MBOX_TAG_SET_PIXEL_ORDER 0x00048006
360 #define BCM2835_MBOX_PIXEL_ORDER_BGR 0
361 #define BCM2835_MBOX_PIXEL_ORDER_RGB 1
363 struct bcm2835_mbox_tag_pixel_order {
364 struct bcm2835_mbox_tag_hdr tag_hdr;
366 /* req not used for get */
376 #define BCM2835_MBOX_TAG_GET_ALPHA_MODE 0x00040007
377 #define BCM2835_MBOX_TAG_TEST_ALPHA_MODE 0x00044007
378 #define BCM2835_MBOX_TAG_SET_ALPHA_MODE 0x00048007
380 #define BCM2835_MBOX_ALPHA_MODE_0_OPAQUE 0
381 #define BCM2835_MBOX_ALPHA_MODE_0_TRANSPARENT 1
382 #define BCM2835_MBOX_ALPHA_MODE_IGNORED 2
384 struct bcm2835_mbox_tag_alpha_mode {
385 struct bcm2835_mbox_tag_hdr tag_hdr;
387 /* req not used for get */
397 #define BCM2835_MBOX_TAG_GET_PITCH 0x00040008
399 struct bcm2835_mbox_tag_pitch {
400 struct bcm2835_mbox_tag_hdr tag_hdr;
410 /* Offset of display window within buffer */
411 #define BCM2835_MBOX_TAG_GET_VIRTUAL_OFFSET 0x00040009
412 #define BCM2835_MBOX_TAG_TEST_VIRTUAL_OFFSET 0x00044009
413 #define BCM2835_MBOX_TAG_SET_VIRTUAL_OFFSET 0x00048009
415 struct bcm2835_mbox_tag_virtual_offset {
416 struct bcm2835_mbox_tag_hdr tag_hdr;
418 /* req not used for get */
430 #define BCM2835_MBOX_TAG_GET_OVERSCAN 0x0004000a
431 #define BCM2835_MBOX_TAG_TEST_OVERSCAN 0x0004400a
432 #define BCM2835_MBOX_TAG_SET_OVERSCAN 0x0004800a
434 struct bcm2835_mbox_tag_overscan {
435 struct bcm2835_mbox_tag_hdr tag_hdr;
437 /* req not used for get */
453 #define BCM2835_MBOX_TAG_GET_PALETTE 0x0004000b
455 struct bcm2835_mbox_tag_get_palette {
456 struct bcm2835_mbox_tag_hdr tag_hdr;
466 #define BCM2835_MBOX_TAG_TEST_PALETTE 0x0004400b
468 struct bcm2835_mbox_tag_test_palette {
469 struct bcm2835_mbox_tag_hdr tag_hdr;
482 #define BCM2835_MBOX_TAG_SET_PALETTE 0x0004800b
484 struct bcm2835_mbox_tag_set_palette {
485 struct bcm2835_mbox_tag_hdr tag_hdr;
499 * Pass a raw u32 message to the VC, and receive a raw u32 back.
501 * Returns 0 for success, any other value for error.
503 int bcm2835_mbox_call_raw(u32 chan, u32 send, u32 *recv);
506 * Pass a complete property-style buffer to the VC, and wait until it has
509 * This function expects a pointer to the mbox_hdr structure in an attempt
510 * to ensure some degree of type safety. However, some number of tags and
511 * a termination value are expected to immediately follow the header in
512 * memory, as required by the property protocol.
514 * Returns 0 for success, any other value for error.
516 int bcm2835_mbox_call_prop(u32 chan, struct bcm2835_mbox_hdr *buffer);