mbox.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-09-10 bigmagic first version
  9. */
  10. #ifndef __MBOX_H__
  11. #define __MBOX_H__
  12. #include <rtthread.h>
  13. #include <stdint.h>
  14. // https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
  15. // https://github.com/hermanhermitage/videocoreiv
  16. /* a properly aligned buffer */
  17. extern volatile unsigned int *mbox;
  18. #define MBOX_REQUEST 0
  19. /* channels */
  20. #define MBOX_CH_POWER 0
  21. #define MBOX_CH_FB 1
  22. #define MBOX_CH_VUART 2
  23. #define MBOX_CH_VCHIQ 3
  24. #define MBOX_CH_LEDS 4
  25. #define MBOX_CH_BTNS 5
  26. #define MBOX_CH_TOUCH 6
  27. #define MBOX_CH_COUNT 7
  28. #define MBOX_CH_PROP 8
  29. /* tags */
  30. #define MBOX_TAG_SETPOWER 0x28001
  31. #define MBOX_TAG_SETCLKRATE 0x38002
  32. #define MBOX_GET_MAC_ADDRESS 0x10003
  33. #define MBOX_TAG_LAST 0
  34. #define MMIO_BASE 0xFE000000
  35. #define VIDEOCORE_MBOX (MMIO_BASE+0x0000B880)
  36. #define MBOX_READ ((volatile unsigned int*)(VIDEOCORE_MBOX+0x0))
  37. #define MBOX_POLL ((volatile unsigned int*)(VIDEOCORE_MBOX+0x10))
  38. #define MBOX_SENDER ((volatile unsigned int*)(VIDEOCORE_MBOX+0x14))
  39. #define MBOX_STATUS ((volatile unsigned int*)(VIDEOCORE_MBOX+0x18))
  40. #define MBOX_CONFIG ((volatile unsigned int*)(VIDEOCORE_MBOX+0x1C))
  41. #define MBOX_WRITE ((volatile unsigned int*)(VIDEOCORE_MBOX+0x20))
  42. #define MBOX_RESPONSE 0x80000000
  43. #define MBOX_FULL 0x80000000
  44. #define MBOX_EMPTY 0x40000000
  45. #define DEVICE_ID_SD_CARD (0)
  46. #define DEVICE_ID_USB_HCD (3)
  47. #define POWER_STATE_OFF (0 << 0)
  48. #define POWER_STATE_ON (1 << 0)
  49. #define POWER_STATE_WAIT (1 << 1)
  50. #define POWER_STATE_NO_DEVICE (1 << 1) // in response
  51. #define MMU_ENABLE (1)
  52. #define MMU_DISABLE (0)
  53. /*
  54. * raspi hardware info
  55. */
  56. enum
  57. {
  58. MBOX_TAG_HARDWARE_GET_MODEL = 0x00010001,
  59. MBOX_TAG_HARDWARE_GET_REV = 0x00010002,
  60. MBOX_TAG_HARDWARE_GET_MAC_ADDRESS = 0x00010003,
  61. MBOX_TAG_HARDWARE_GET_SERIAL = 0x00010004,
  62. MBOX_TAG_HARDWARE_GET_ARM_MEMORY = 0x00010005,
  63. MBOX_TAG_HARDWARE_GET_VC_MEMORY = 0x00010006,
  64. MBOX_TAG_HARDWARE_GET_CLOCKS = 0x00010007,
  65. };
  66. /*
  67. * raspi clock
  68. */
  69. enum
  70. {
  71. MBOX_TAG_CLOCK_GET_TURBO = 0x00030009,
  72. MBOX_TAG_CLOCK_SET_TURBO = 0x00038009,
  73. MBOX_TAG_CLOCK_GET_STATE = 0x00030001,
  74. MBOX_TAG_CLOCK_SET_STATE = 0x00038001,
  75. MBOX_TAG_CLOCK_GET_RATE = 0x00030002,
  76. MBOX_TAG_CLOCK_SET_RATE = 0x00038002,
  77. MBOX_TAG_CLOCK_GET_MAX_RATE = 0x00030004,
  78. MBOX_TAG_CLOCK_GET_MIN_RATE = 0x00030007,
  79. };
  80. /*
  81. * raspi power
  82. */
  83. enum
  84. {
  85. MBOX_TAG_POWER_GET_STATE = 0x00020001,
  86. MBOX_TAG_POWER_SET_STATE = 0x00028001,
  87. };
  88. /*
  89. * raspi temperature
  90. */
  91. enum
  92. {
  93. MBOX_TAG_TEMP_GET = 0x00030006,
  94. MBOX_TAG_TEMP_GET_MAX = 0x0003000A,
  95. };
  96. /*
  97. * raspi Memory
  98. */
  99. enum
  100. {
  101. MBOX_TAG_ALLOCATE_MEMORY = 0x0003000C, // Memory: Allocates Contiguous Memory On The GPU (Response: Handle)
  102. MBOX_TAG_LOCK_MEMORY = 0x0003000D, // Memory: Unlock Buffer (Response: Status)
  103. MBOX_TAG_UNLOCK_MEMORY = 0x0003000E, // Memory: Unlock Buffer (Response: Status)
  104. MBOX_TAG_RELEASE_MEMORY = 0x0003000F, // Memory: Free The Memory Buffer (Response: Status)
  105. MBOX_TAG_EXECUTE_CODE = 0x00030010, // Memory: Calls The Function At Given (Bus) Address And With Arguments Given
  106. };
  107. /*
  108. * raspi GPU
  109. */
  110. enum
  111. {
  112. MBOX_TAG_EXECUTE_QPU = 0x00030011, // QPU: Calls The QPU Function At Given (Bus) Address And With Arguments Given
  113. // (Response: Number Of QPUs, Control, No Flush, Timeout In ms)
  114. MBOX_TAG_ENABLE_QPU = 0x00030012, // QPU: Enables The QPU (Response: Enable State)
  115. };
  116. /*
  117. * raspi HDMI
  118. */
  119. #define MBOX_TAG_GET_EDID_BLOCK 0x00030020 // HDMI: Read Specificed EDID Block From Attached HDMI/DVI Device
  120. // (Response: Block Number, Status, EDID Block (128 Bytes))
  121. /*
  122. * raspi NOTIFY
  123. */
  124. #define MBOX_TAG_NOTIFY_REBOOT 0x00030048
  125. #define MBOX_TAG_NOTIFY_XHCI_RESET 0x00030058
  126. /*
  127. * touch
  128. */
  129. #define MBOX_TAG_GET_TOUCHBUF (0x0004000F)
  130. #define MBOX_ADDR 0x08000000
  131. #define RES_CLK_ID (0x000000000)
  132. #define EMMC_CLK_ID (0x000000001)
  133. #define UART_CLK_ID (0x000000002)
  134. #define ARM_CLK_ID (0x000000003)
  135. #define CORE_CLK_ID (0x000000004)
  136. #define V3D_CLK_ID (0x000000005)
  137. #define H264_CLK_ID (0x000000006)
  138. #define ISP_CLK_ID (0x000000007)
  139. #define SDRAM_CLK_ID (0x000000008)
  140. #define PIXEL_CLK_ID (0x000000009)
  141. #define PWM_CLK_ID (0x00000000a)
  142. int mbox_call(unsigned char ch, int mmu_enable);
  143. int bcm271x_mbox_poweroff_devices(int id);
  144. int bcm271x_mbox_get_touch(void);
  145. int bcm271x_notify_reboot(void);
  146. int bcm271x_notify_xhci_reset(void);
  147. int bcm271x_gpu_enable(void);
  148. int bcm271x_mbox_hardware_get_model(void);
  149. int bcm271x_mbox_hardware_get_revison(void);
  150. int bcm271x_mbox_hardware_get_mac_address(uint8_t *mac);
  151. int bcm271x_mbox_hardware_get_serial(rt_uint64_t *sn);
  152. int bcm271x_mbox_hardware_get_arm_memory(rt_uint32_t *base, rt_uint32_t *size);
  153. int bcm271x_mbox_hardware_get_vc_memory(rt_uint32_t *base, rt_uint32_t *size);
  154. int bcm271x_mbox_clock_get_turbo(void);
  155. int bcm271x_mbox_clock_set_turbo(int level);
  156. int bcm271x_mbox_clock_get_state(int id);
  157. int bcm271x_mbox_clock_set_state(int id, int state);
  158. int bcm271x_mbox_clock_get_rate(int id);
  159. int bcm271x_mbox_clock_set_rate(int id, int rate);
  160. int bcm271x_mbox_clock_get_max_rate(int id);
  161. int bcm271x_mbox_clock_get_min_rate(int id);
  162. int bcm271x_mbox_power_get_state(int id);
  163. int bcm271x_mbox_power_set_state(int id, int state);
  164. int bcm271x_mbox_temp_get(void);
  165. int bcm271x_mbox_temp_get_max(void);
  166. #endif