blob: dded857c3ad50abbe650f12a1ebb435e6f8d7614 [file] [log] [blame]
Stephen Warren88077282013-01-29 16:37:36 +00001/*
2 * (C) Copyright 2012 Stephen Warren
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Stephen Warren88077282013-01-29 16:37:36 +00005 */
6
7#ifndef _BCM2835_MBOX_H
8#define _BCM2835_MBOX_H
9
10#include <linux/compiler.h>
11
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
41#define BCM2835_MBOX_PHYSADDR 0x2000b880
42
43struct bcm2835_mbox_regs {
44 u32 read;
45 u32 rsvd0[5];
46 u32 status;
47 u32 config;
48 u32 write;
49};
50
51#define BCM2835_MBOX_STATUS_WR_FULL 0x80000000
52#define BCM2835_MBOX_STATUS_RD_EMPTY 0x40000000
53
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))
60
61/* Property mailbox buffer structures */
62
63#define BCM2835_MBOX_PROP_CHAN 8
64
65/* All message buffers must start with this header */
66struct bcm2835_mbox_hdr {
67 u32 buf_size;
68 u32 code;
69};
70
71#define BCM2835_MBOX_REQ_CODE 0
72#define BCM2835_MBOX_RESP_CODE_SUCCESS 0x80000000
73
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; \
78 (_m_)->end_tag = 0; \
79 }
80
81/*
82 * A message buffer contains a list of tags. Each tag must also start with
83 * a standardized header.
84 */
85struct bcm2835_mbox_tag_hdr {
86 u32 tag;
87 u32 val_buf_size;
88 u32 val_len;
89};
90
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); \
95 }
96
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; \
101 }
102
103/* When responding, the VC sets this bit in val_len to indicate a response */
104#define BCM2835_MBOX_TAG_VAL_LEN_RESPONSE 0x80000000
105
106/*
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,
113 *
114 * struct msg {
115 * struct bcm2835_mbox_hdr hdr;
116 * struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
117 * ... perhaps other tags here ...
118 * u32 end_tag;
119 * };
120 */
121
122#define BCM2835_MBOX_TAG_GET_ARM_MEMORY 0x00010005
123
124struct bcm2835_mbox_tag_get_arm_mem {
125 struct bcm2835_mbox_tag_hdr tag_hdr;
126 union {
127 struct {
128 } req;
129 struct {
130 u32 mem_base;
131 u32 mem_size;
132 } resp;
133 } body;
134};
135
Stephen Warrenf66f2aa2014-01-13 19:50:11 -0700136#define BCM2835_MBOX_POWER_DEVID_SDHCI 0
137#define BCM2835_MBOX_POWER_DEVID_UART0 1
138#define BCM2835_MBOX_POWER_DEVID_UART1 2
139#define BCM2835_MBOX_POWER_DEVID_USB_HCD 3
140#define BCM2835_MBOX_POWER_DEVID_I2C0 4
141#define BCM2835_MBOX_POWER_DEVID_I2C1 5
142#define BCM2835_MBOX_POWER_DEVID_I2C2 6
143#define BCM2835_MBOX_POWER_DEVID_SPI 7
144#define BCM2835_MBOX_POWER_DEVID_CCP2TX 8
145
Stephen Warren5e77a742014-02-05 20:42:25 -0700146#define BCM2835_MBOX_POWER_STATE_RESP_ON (1 << 0)
Stephen Warrenf66f2aa2014-01-13 19:50:11 -0700147/* Device doesn't exist */
148#define BCM2835_MBOX_POWER_STATE_RESP_NODEV (1 << 1)
149
150#define BCM2835_MBOX_TAG_GET_POWER_STATE 0x00020001
151
152struct bcm2835_mbox_tag_get_power_state {
153 struct bcm2835_mbox_tag_hdr tag_hdr;
154 union {
155 struct {
156 u32 device_id;
157 } req;
158 struct {
159 u32 device_id;
160 u32 state;
161 } resp;
162 } body;
163};
164
165#define BCM2835_MBOX_TAG_SET_POWER_STATE 0x00028001
166
167#define BCM2835_MBOX_SET_POWER_STATE_REQ_ON (1 << 0)
168#define BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT (1 << 1)
169
170struct bcm2835_mbox_tag_set_power_state {
171 struct bcm2835_mbox_tag_hdr tag_hdr;
172 union {
173 struct {
174 u32 device_id;
175 u32 state;
176 } req;
177 struct {
178 u32 device_id;
179 u32 state;
180 } resp;
181 } body;
182};
183
Stephen Warren131a1e62013-01-29 16:37:42 +0000184#define BCM2835_MBOX_TAG_GET_CLOCK_RATE 0x00030002
185
186#define BCM2835_MBOX_CLOCK_ID_EMMC 1
187#define BCM2835_MBOX_CLOCK_ID_UART 2
188#define BCM2835_MBOX_CLOCK_ID_ARM 3
189#define BCM2835_MBOX_CLOCK_ID_CORE 4
190#define BCM2835_MBOX_CLOCK_ID_V3D 5
191#define BCM2835_MBOX_CLOCK_ID_H264 6
192#define BCM2835_MBOX_CLOCK_ID_ISP 7
193#define BCM2835_MBOX_CLOCK_ID_SDRAM 8
194#define BCM2835_MBOX_CLOCK_ID_PIXEL 9
195#define BCM2835_MBOX_CLOCK_ID_PWM 10
196
197struct bcm2835_mbox_tag_get_clock_rate {
198 struct bcm2835_mbox_tag_hdr tag_hdr;
199 union {
200 struct {
201 u32 clock_id;
202 } req;
203 struct {
204 u32 clock_id;
205 u32 rate_hz;
206 } resp;
207 } body;
208};
209
Stephen Warren88077282013-01-29 16:37:36 +0000210#define BCM2835_MBOX_TAG_ALLOCATE_BUFFER 0x00040001
211
212struct bcm2835_mbox_tag_allocate_buffer {
213 struct bcm2835_mbox_tag_hdr tag_hdr;
214 union {
215 struct {
216 u32 alignment;
217 } req;
218 struct {
219 u32 fb_address;
220 u32 fb_size;
221 } resp;
222 } body;
223};
224
225#define BCM2835_MBOX_TAG_RELEASE_BUFFER 0x00048001
226
227struct bcm2835_mbox_tag_release_buffer {
228 struct bcm2835_mbox_tag_hdr tag_hdr;
229 union {
230 struct {
231 } req;
232 struct {
233 } resp;
234 } body;
235};
236
237#define BCM2835_MBOX_TAG_BLANK_SCREEN 0x00040002
238
239struct bcm2835_mbox_tag_blank_screen {
240 struct bcm2835_mbox_tag_hdr tag_hdr;
241 union {
242 struct {
243 /* bit 0 means on, other bots reserved */
244 u32 state;
245 } req;
246 struct {
247 u32 state;
248 } resp;
249 } body;
250};
251
252/* Physical means output signal */
253#define BCM2835_MBOX_TAG_GET_PHYSICAL_W_H 0x00040003
254#define BCM2835_MBOX_TAG_TEST_PHYSICAL_W_H 0x00044003
255#define BCM2835_MBOX_TAG_SET_PHYSICAL_W_H 0x00048003
256
257struct bcm2835_mbox_tag_physical_w_h {
258 struct bcm2835_mbox_tag_hdr tag_hdr;
259 union {
260 /* req not used for get */
261 struct {
262 u32 width;
263 u32 height;
264 } req;
265 struct {
266 u32 width;
267 u32 height;
268 } resp;
269 } body;
270};
271
272/* Virtual means display buffer */
273#define BCM2835_MBOX_TAG_GET_VIRTUAL_W_H 0x00040004
274#define BCM2835_MBOX_TAG_TEST_VIRTUAL_W_H 0x00044004
275#define BCM2835_MBOX_TAG_SET_VIRTUAL_W_H 0x00048004
276
277struct bcm2835_mbox_tag_virtual_w_h {
278 struct bcm2835_mbox_tag_hdr tag_hdr;
279 union {
280 /* req not used for get */
281 struct {
282 u32 width;
283 u32 height;
284 } req;
285 struct {
286 u32 width;
287 u32 height;
288 } resp;
289 } body;
290};
291
292#define BCM2835_MBOX_TAG_GET_DEPTH 0x00040005
293#define BCM2835_MBOX_TAG_TEST_DEPTH 0x00044005
294#define BCM2835_MBOX_TAG_SET_DEPTH 0x00048005
295
296struct bcm2835_mbox_tag_depth {
297 struct bcm2835_mbox_tag_hdr tag_hdr;
298 union {
299 /* req not used for get */
300 struct {
301 u32 bpp;
302 } req;
303 struct {
304 u32 bpp;
305 } resp;
306 } body;
307};
308
309#define BCM2835_MBOX_TAG_GET_PIXEL_ORDER 0x00040006
310#define BCM2835_MBOX_TAG_TEST_PIXEL_ORDER 0x00044005
311#define BCM2835_MBOX_TAG_SET_PIXEL_ORDER 0x00048006
312
313#define BCM2835_MBOX_PIXEL_ORDER_BGR 0
314#define BCM2835_MBOX_PIXEL_ORDER_RGB 1
315
316struct bcm2835_mbox_tag_pixel_order {
317 struct bcm2835_mbox_tag_hdr tag_hdr;
318 union {
319 /* req not used for get */
320 struct {
321 u32 order;
322 } req;
323 struct {
324 u32 order;
325 } resp;
326 } body;
327};
328
329#define BCM2835_MBOX_TAG_GET_ALPHA_MODE 0x00040007
330#define BCM2835_MBOX_TAG_TEST_ALPHA_MODE 0x00044007
331#define BCM2835_MBOX_TAG_SET_ALPHA_MODE 0x00048007
332
333#define BCM2835_MBOX_ALPHA_MODE_0_OPAQUE 0
334#define BCM2835_MBOX_ALPHA_MODE_0_TRANSPARENT 1
335#define BCM2835_MBOX_ALPHA_MODE_IGNORED 2
336
337struct bcm2835_mbox_tag_alpha_mode {
338 struct bcm2835_mbox_tag_hdr tag_hdr;
339 union {
340 /* req not used for get */
341 struct {
342 u32 alpha;
343 } req;
344 struct {
345 u32 alpha;
346 } resp;
347 } body;
348};
349
350#define BCM2835_MBOX_TAG_GET_PITCH 0x00040008
351
352struct bcm2835_mbox_tag_pitch {
353 struct bcm2835_mbox_tag_hdr tag_hdr;
354 union {
355 struct {
356 } req;
357 struct {
358 u32 pitch;
359 } resp;
360 } body;
361};
362
363/* Offset of display window within buffer */
364#define BCM2835_MBOX_TAG_GET_VIRTUAL_OFFSET 0x00040009
365#define BCM2835_MBOX_TAG_TEST_VIRTUAL_OFFSET 0x00044009
366#define BCM2835_MBOX_TAG_SET_VIRTUAL_OFFSET 0x00048009
367
368struct bcm2835_mbox_tag_virtual_offset {
369 struct bcm2835_mbox_tag_hdr tag_hdr;
370 union {
371 /* req not used for get */
372 struct {
373 u32 x;
374 u32 y;
375 } req;
376 struct {
377 u32 x;
378 u32 y;
379 } resp;
380 } body;
381};
382
383#define BCM2835_MBOX_TAG_GET_OVERSCAN 0x0004000a
384#define BCM2835_MBOX_TAG_TEST_OVERSCAN 0x0004400a
385#define BCM2835_MBOX_TAG_SET_OVERSCAN 0x0004800a
386
387struct bcm2835_mbox_tag_overscan {
388 struct bcm2835_mbox_tag_hdr tag_hdr;
389 union {
390 /* req not used for get */
391 struct {
392 u32 top;
393 u32 bottom;
394 u32 left;
395 u32 right;
396 } req;
397 struct {
398 u32 top;
399 u32 bottom;
400 u32 left;
Andre Heidere2788af2013-10-22 22:27:20 +0200401 u32 right;
Stephen Warren88077282013-01-29 16:37:36 +0000402 } resp;
403 } body;
404};
405
406#define BCM2835_MBOX_TAG_GET_PALETTE 0x0004000b
407
408struct bcm2835_mbox_tag_get_palette {
409 struct bcm2835_mbox_tag_hdr tag_hdr;
410 union {
411 struct {
412 } req;
413 struct {
414 u32 data[1024];
415 } resp;
416 } body;
417};
418
419#define BCM2835_MBOX_TAG_TEST_PALETTE 0x0004400b
420
421struct bcm2835_mbox_tag_test_palette {
422 struct bcm2835_mbox_tag_hdr tag_hdr;
423 union {
424 struct {
425 u32 offset;
426 u32 num_entries;
427 u32 data[256];
428 } req;
429 struct {
430 u32 is_invalid;
431 } resp;
432 } body;
433};
434
435#define BCM2835_MBOX_TAG_SET_PALETTE 0x0004800b
436
437struct bcm2835_mbox_tag_set_palette {
438 struct bcm2835_mbox_tag_hdr tag_hdr;
439 union {
440 struct {
441 u32 offset;
442 u32 num_entries;
443 u32 data[256];
444 } req;
445 struct {
446 u32 is_invalid;
447 } resp;
448 } body;
449};
450
451/*
452 * Pass a raw u32 message to the VC, and receive a raw u32 back.
453 *
454 * Returns 0 for success, any other value for error.
455 */
456int bcm2835_mbox_call_raw(u32 chan, u32 send, u32 *recv);
457
458/*
459 * Pass a complete property-style buffer to the VC, and wait until it has
460 * been processed.
461 *
462 * This function expects a pointer to the mbox_hdr structure in an attempt
463 * to ensure some degree of type safety. However, some number of tags and
464 * a termination value are expected to immediately follow the header in
465 * memory, as required by the property protocol.
466 *
467 * Returns 0 for success, any other value for error.
468 */
469int bcm2835_mbox_call_prop(u32 chan, struct bcm2835_mbox_hdr *buffer);
470
471#endif