blob: f8928035584cddd42d0533dd9af1c9c30d4fda36 [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
Stephen Warren9d5990b2016-03-16 21:40:56 -060040#ifndef CONFIG_BCM2835
Stephen Warren8780f222015-02-16 12:16:14 -070041#define BCM2835_MBOX_PHYSADDR 0x3f00b880
42#else
Stephen Warren91ea2882013-01-29 16:37:36 +000043#define BCM2835_MBOX_PHYSADDR 0x2000b880
Stephen Warren8780f222015-02-16 12:16:14 -070044#endif
Stephen Warren91ea2882013-01-29 16:37:36 +000045
46struct bcm2835_mbox_regs {
47 u32 read;
48 u32 rsvd0[5];
Fabian Vogtbcf941f2019-07-16 13:09:47 +020049 u32 mail0_status;
50 u32 mail0_config;
Stephen Warren91ea2882013-01-29 16:37:36 +000051 u32 write;
Fabian Vogtbcf941f2019-07-16 13:09:47 +020052 u32 rsvd1[5];
53 u32 mail1_status;
54 u32 mail1_config;
Stephen Warren91ea2882013-01-29 16:37:36 +000055};
56
57#define BCM2835_MBOX_STATUS_WR_FULL 0x80000000
58#define BCM2835_MBOX_STATUS_RD_EMPTY 0x40000000
59
60/* Lower 4-bits are channel ID */
61#define BCM2835_CHAN_MASK 0xf
62#define BCM2835_MBOX_PACK(chan, data) (((data) & (~BCM2835_CHAN_MASK)) | \
63 (chan & BCM2835_CHAN_MASK))
64#define BCM2835_MBOX_UNPACK_CHAN(val) ((val) & BCM2835_CHAN_MASK)
65#define BCM2835_MBOX_UNPACK_DATA(val) ((val) & (~BCM2835_CHAN_MASK))
66
67/* Property mailbox buffer structures */
68
69#define BCM2835_MBOX_PROP_CHAN 8
70
71/* All message buffers must start with this header */
72struct bcm2835_mbox_hdr {
73 u32 buf_size;
74 u32 code;
75};
76
77#define BCM2835_MBOX_REQ_CODE 0
78#define BCM2835_MBOX_RESP_CODE_SUCCESS 0x80000000
79
80#define BCM2835_MBOX_INIT_HDR(_m_) { \
81 memset((_m_), 0, sizeof(*(_m_))); \
82 (_m_)->hdr.buf_size = sizeof(*(_m_)); \
83 (_m_)->hdr.code = 0; \
84 (_m_)->end_tag = 0; \
85 }
86
87/*
88 * A message buffer contains a list of tags. Each tag must also start with
89 * a standardized header.
90 */
91struct bcm2835_mbox_tag_hdr {
92 u32 tag;
93 u32 val_buf_size;
94 u32 val_len;
95};
96
97#define BCM2835_MBOX_INIT_TAG(_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 = sizeof((_t_)->body.req); \
101 }
102
103#define BCM2835_MBOX_INIT_TAG_NO_REQ(_t_, _id_) { \
104 (_t_)->tag_hdr.tag = BCM2835_MBOX_TAG_##_id_; \
105 (_t_)->tag_hdr.val_buf_size = sizeof((_t_)->body); \
106 (_t_)->tag_hdr.val_len = 0; \
107 }
108
109/* When responding, the VC sets this bit in val_len to indicate a response */
110#define BCM2835_MBOX_TAG_VAL_LEN_RESPONSE 0x80000000
111
112/*
113 * Below we define the ID and struct for many possible tags. This header only
114 * defines individual tag structs, not entire message structs, since in
115 * general an arbitrary set of tags may be combined into a single message.
116 * Clients of the mbox API are expected to define their own overall message
117 * structures by combining the header, a set of tags, and a terminating
118 * entry. For example,
119 *
120 * struct msg {
121 * struct bcm2835_mbox_hdr hdr;
122 * struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
123 * ... perhaps other tags here ...
124 * u32 end_tag;
125 * };
126 */
127
Stephen Warrencd210c12014-11-18 21:40:21 -0700128#define BCM2835_MBOX_TAG_GET_BOARD_REV 0x00010002
129
Stephen Warrencd210c12014-11-18 21:40:21 -0700130struct bcm2835_mbox_tag_get_board_rev {
131 struct bcm2835_mbox_tag_hdr tag_hdr;
132 union {
133 struct {
134 } req;
135 struct {
136 u32 rev;
137 } resp;
138 } body;
139};
140
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600141#define BCM2835_MBOX_TAG_GET_MAC_ADDRESS 0x00010003
142
143struct bcm2835_mbox_tag_get_mac_address {
144 struct bcm2835_mbox_tag_hdr tag_hdr;
145 union {
146 struct {
147 } req;
148 struct {
149 u8 mac[6];
150 u8 pad[2];
151 } resp;
152 } body;
153};
154
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100155#define BCM2835_MBOX_TAG_GET_BOARD_SERIAL 0x00010004
156
157struct bcm2835_mbox_tag_get_board_serial {
158 struct bcm2835_mbox_tag_hdr tag_hdr;
159 union {
160 struct __packed {
161 u64 serial;
162 } resp;
163 } body;
164};
165
Stephen Warren91ea2882013-01-29 16:37:36 +0000166#define BCM2835_MBOX_TAG_GET_ARM_MEMORY 0x00010005
167
168struct bcm2835_mbox_tag_get_arm_mem {
169 struct bcm2835_mbox_tag_hdr tag_hdr;
170 union {
171 struct {
172 } req;
173 struct {
174 u32 mem_base;
175 u32 mem_size;
176 } resp;
177 } body;
178};
179
Stephen Warren8672d202014-01-13 19:50:11 -0700180#define BCM2835_MBOX_POWER_DEVID_SDHCI 0
181#define BCM2835_MBOX_POWER_DEVID_UART0 1
182#define BCM2835_MBOX_POWER_DEVID_UART1 2
183#define BCM2835_MBOX_POWER_DEVID_USB_HCD 3
184#define BCM2835_MBOX_POWER_DEVID_I2C0 4
185#define BCM2835_MBOX_POWER_DEVID_I2C1 5
186#define BCM2835_MBOX_POWER_DEVID_I2C2 6
187#define BCM2835_MBOX_POWER_DEVID_SPI 7
188#define BCM2835_MBOX_POWER_DEVID_CCP2TX 8
189
Stephen Warren41523682014-02-05 20:42:25 -0700190#define BCM2835_MBOX_POWER_STATE_RESP_ON (1 << 0)
Stephen Warren8672d202014-01-13 19:50:11 -0700191/* Device doesn't exist */
192#define BCM2835_MBOX_POWER_STATE_RESP_NODEV (1 << 1)
193
194#define BCM2835_MBOX_TAG_GET_POWER_STATE 0x00020001
195
196struct bcm2835_mbox_tag_get_power_state {
197 struct bcm2835_mbox_tag_hdr tag_hdr;
198 union {
199 struct {
200 u32 device_id;
201 } req;
202 struct {
203 u32 device_id;
204 u32 state;
205 } resp;
206 } body;
207};
208
209#define BCM2835_MBOX_TAG_SET_POWER_STATE 0x00028001
210
211#define BCM2835_MBOX_SET_POWER_STATE_REQ_ON (1 << 0)
212#define BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT (1 << 1)
213
214struct bcm2835_mbox_tag_set_power_state {
215 struct bcm2835_mbox_tag_hdr tag_hdr;
216 union {
217 struct {
218 u32 device_id;
219 u32 state;
220 } req;
221 struct {
222 u32 device_id;
223 u32 state;
224 } resp;
225 } body;
226};
227
Stephen Warrenc4ab9712013-01-29 16:37:42 +0000228#define BCM2835_MBOX_TAG_GET_CLOCK_RATE 0x00030002
229
230#define BCM2835_MBOX_CLOCK_ID_EMMC 1
231#define BCM2835_MBOX_CLOCK_ID_UART 2
232#define BCM2835_MBOX_CLOCK_ID_ARM 3
233#define BCM2835_MBOX_CLOCK_ID_CORE 4
234#define BCM2835_MBOX_CLOCK_ID_V3D 5
235#define BCM2835_MBOX_CLOCK_ID_H264 6
236#define BCM2835_MBOX_CLOCK_ID_ISP 7
237#define BCM2835_MBOX_CLOCK_ID_SDRAM 8
238#define BCM2835_MBOX_CLOCK_ID_PIXEL 9
239#define BCM2835_MBOX_CLOCK_ID_PWM 10
240
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
Stephen Warren91ea2882013-01-29 16:37:36 +0000254#define BCM2835_MBOX_TAG_ALLOCATE_BUFFER 0x00040001
255
256struct bcm2835_mbox_tag_allocate_buffer {
257 struct bcm2835_mbox_tag_hdr tag_hdr;
258 union {
259 struct {
260 u32 alignment;
261 } req;
262 struct {
263 u32 fb_address;
264 u32 fb_size;
265 } resp;
266 } body;
267};
268
269#define BCM2835_MBOX_TAG_RELEASE_BUFFER 0x00048001
270
271struct bcm2835_mbox_tag_release_buffer {
272 struct bcm2835_mbox_tag_hdr tag_hdr;
273 union {
274 struct {
275 } req;
276 struct {
277 } resp;
278 } body;
279};
280
281#define BCM2835_MBOX_TAG_BLANK_SCREEN 0x00040002
282
283struct bcm2835_mbox_tag_blank_screen {
284 struct bcm2835_mbox_tag_hdr tag_hdr;
285 union {
286 struct {
287 /* bit 0 means on, other bots reserved */
288 u32 state;
289 } req;
290 struct {
291 u32 state;
292 } resp;
293 } body;
294};
295
296/* Physical means output signal */
297#define BCM2835_MBOX_TAG_GET_PHYSICAL_W_H 0x00040003
298#define BCM2835_MBOX_TAG_TEST_PHYSICAL_W_H 0x00044003
299#define BCM2835_MBOX_TAG_SET_PHYSICAL_W_H 0x00048003
300
301struct bcm2835_mbox_tag_physical_w_h {
302 struct bcm2835_mbox_tag_hdr tag_hdr;
303 union {
304 /* req not used for get */
305 struct {
306 u32 width;
307 u32 height;
308 } req;
309 struct {
310 u32 width;
311 u32 height;
312 } resp;
313 } body;
314};
315
316/* Virtual means display buffer */
317#define BCM2835_MBOX_TAG_GET_VIRTUAL_W_H 0x00040004
318#define BCM2835_MBOX_TAG_TEST_VIRTUAL_W_H 0x00044004
319#define BCM2835_MBOX_TAG_SET_VIRTUAL_W_H 0x00048004
320
321struct bcm2835_mbox_tag_virtual_w_h {
322 struct bcm2835_mbox_tag_hdr tag_hdr;
323 union {
324 /* req not used for get */
325 struct {
326 u32 width;
327 u32 height;
328 } req;
329 struct {
330 u32 width;
331 u32 height;
332 } resp;
333 } body;
334};
335
336#define BCM2835_MBOX_TAG_GET_DEPTH 0x00040005
337#define BCM2835_MBOX_TAG_TEST_DEPTH 0x00044005
338#define BCM2835_MBOX_TAG_SET_DEPTH 0x00048005
339
340struct bcm2835_mbox_tag_depth {
341 struct bcm2835_mbox_tag_hdr tag_hdr;
342 union {
343 /* req not used for get */
344 struct {
345 u32 bpp;
346 } req;
347 struct {
348 u32 bpp;
349 } resp;
350 } body;
351};
352
353#define BCM2835_MBOX_TAG_GET_PIXEL_ORDER 0x00040006
Berkus Decker879258f2019-01-13 20:30:40 +0100354#define BCM2835_MBOX_TAG_TEST_PIXEL_ORDER 0x00044006
Stephen Warren91ea2882013-01-29 16:37:36 +0000355#define BCM2835_MBOX_TAG_SET_PIXEL_ORDER 0x00048006
356
357#define BCM2835_MBOX_PIXEL_ORDER_BGR 0
358#define BCM2835_MBOX_PIXEL_ORDER_RGB 1
359
360struct bcm2835_mbox_tag_pixel_order {
361 struct bcm2835_mbox_tag_hdr tag_hdr;
362 union {
363 /* req not used for get */
364 struct {
365 u32 order;
366 } req;
367 struct {
368 u32 order;
369 } resp;
370 } body;
371};
372
373#define BCM2835_MBOX_TAG_GET_ALPHA_MODE 0x00040007
374#define BCM2835_MBOX_TAG_TEST_ALPHA_MODE 0x00044007
375#define BCM2835_MBOX_TAG_SET_ALPHA_MODE 0x00048007
376
377#define BCM2835_MBOX_ALPHA_MODE_0_OPAQUE 0
378#define BCM2835_MBOX_ALPHA_MODE_0_TRANSPARENT 1
379#define BCM2835_MBOX_ALPHA_MODE_IGNORED 2
380
381struct bcm2835_mbox_tag_alpha_mode {
382 struct bcm2835_mbox_tag_hdr tag_hdr;
383 union {
384 /* req not used for get */
385 struct {
386 u32 alpha;
387 } req;
388 struct {
389 u32 alpha;
390 } resp;
391 } body;
392};
393
394#define BCM2835_MBOX_TAG_GET_PITCH 0x00040008
395
396struct bcm2835_mbox_tag_pitch {
397 struct bcm2835_mbox_tag_hdr tag_hdr;
398 union {
399 struct {
400 } req;
401 struct {
402 u32 pitch;
403 } resp;
404 } body;
405};
406
407/* Offset of display window within buffer */
408#define BCM2835_MBOX_TAG_GET_VIRTUAL_OFFSET 0x00040009
409#define BCM2835_MBOX_TAG_TEST_VIRTUAL_OFFSET 0x00044009
410#define BCM2835_MBOX_TAG_SET_VIRTUAL_OFFSET 0x00048009
411
412struct bcm2835_mbox_tag_virtual_offset {
413 struct bcm2835_mbox_tag_hdr tag_hdr;
414 union {
415 /* req not used for get */
416 struct {
417 u32 x;
418 u32 y;
419 } req;
420 struct {
421 u32 x;
422 u32 y;
423 } resp;
424 } body;
425};
426
427#define BCM2835_MBOX_TAG_GET_OVERSCAN 0x0004000a
428#define BCM2835_MBOX_TAG_TEST_OVERSCAN 0x0004400a
429#define BCM2835_MBOX_TAG_SET_OVERSCAN 0x0004800a
430
431struct bcm2835_mbox_tag_overscan {
432 struct bcm2835_mbox_tag_hdr tag_hdr;
433 union {
434 /* req not used for get */
435 struct {
436 u32 top;
437 u32 bottom;
438 u32 left;
439 u32 right;
440 } req;
441 struct {
442 u32 top;
443 u32 bottom;
444 u32 left;
Andre Heider952ad9e2013-10-22 22:27:20 +0200445 u32 right;
Stephen Warren91ea2882013-01-29 16:37:36 +0000446 } resp;
447 } body;
448};
449
450#define BCM2835_MBOX_TAG_GET_PALETTE 0x0004000b
451
452struct bcm2835_mbox_tag_get_palette {
453 struct bcm2835_mbox_tag_hdr tag_hdr;
454 union {
455 struct {
456 } req;
457 struct {
458 u32 data[1024];
459 } resp;
460 } body;
461};
462
463#define BCM2835_MBOX_TAG_TEST_PALETTE 0x0004400b
464
465struct bcm2835_mbox_tag_test_palette {
466 struct bcm2835_mbox_tag_hdr tag_hdr;
467 union {
468 struct {
469 u32 offset;
470 u32 num_entries;
471 u32 data[256];
472 } req;
473 struct {
474 u32 is_invalid;
475 } resp;
476 } body;
477};
478
479#define BCM2835_MBOX_TAG_SET_PALETTE 0x0004800b
480
481struct bcm2835_mbox_tag_set_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/*
496 * Pass a raw u32 message to the VC, and receive a raw u32 back.
497 *
498 * Returns 0 for success, any other value for error.
499 */
500int bcm2835_mbox_call_raw(u32 chan, u32 send, u32 *recv);
501
502/*
503 * Pass a complete property-style buffer to the VC, and wait until it has
504 * been processed.
505 *
506 * This function expects a pointer to the mbox_hdr structure in an attempt
507 * to ensure some degree of type safety. However, some number of tags and
508 * a termination value are expected to immediately follow the header in
509 * memory, as required by the property protocol.
510 *
Alexander Steinfbeb89d2015-07-24 09:22:13 +0200511 * Each struct bcm2835_mbox_hdr passed must be allocated with
512 * ALLOC_CACHE_ALIGN_BUFFER(x, y, z) to ensure proper cache flush/invalidate.
513 *
Stephen Warren91ea2882013-01-29 16:37:36 +0000514 * Returns 0 for success, any other value for error.
515 */
516int bcm2835_mbox_call_prop(u32 chan, struct bcm2835_mbox_hdr *buffer);
517
518#endif