mbox.h 5.6 KB

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