mbox.h 12 KB

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