mbox.h 12 KB

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