mbox.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 "board.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. MBOX_TAG_HARDWARE_GET_MODEL = 0x00010001,
  58. MBOX_TAG_HARDWARE_GET_REV = 0x00010002,
  59. MBOX_TAG_HARDWARE_GET_MAC_ADDRESS = 0x00010003,
  60. MBOX_TAG_HARDWARE_GET_SERIAL = 0x00010004,
  61. MBOX_TAG_HARDWARE_GET_ARM_MEMORY = 0x00010005,
  62. MBOX_TAG_HARDWARE_GET_VC_MEMORY = 0x00010006,
  63. MBOX_TAG_HARDWARE_GET_CLOCKS = 0x00010007,
  64. };
  65. /*
  66. * raspi clock
  67. */
  68. enum {
  69. MBOX_TAG_CLOCK_GET_TURBO = 0x00030009,
  70. MBOX_TAG_CLOCK_SET_TURBO = 0x00038009,
  71. MBOX_TAG_CLOCK_GET_STATE = 0x00030001,
  72. MBOX_TAG_CLOCK_SET_STATE = 0x00038001,
  73. MBOX_TAG_CLOCK_GET_RATE = 0x00030002,
  74. MBOX_TAG_CLOCK_SET_RATE = 0x00038002,
  75. MBOX_TAG_CLOCK_GET_MAX_RATE = 0x00030004,
  76. MBOX_TAG_CLOCK_GET_MIN_RATE = 0x00030007,
  77. };
  78. /*
  79. * raspi power
  80. */
  81. enum {
  82. MBOX_TAG_POWER_GET_STATE = 0x00020001,
  83. MBOX_TAG_POWER_SET_STATE = 0x00028001,
  84. };
  85. /*
  86. * raspi temperature
  87. */
  88. enum {
  89. MBOX_TAG_TEMP_GET = 0x00030006,
  90. MBOX_TAG_TEMP_GET_MAX = 0x0003000A,
  91. };
  92. /*
  93. * raspi Memory
  94. */
  95. enum {
  96. MBOX_TAG_ALLOCATE_MEMORY = 0x0003000C, // Memory: Allocates Contiguous Memory On The GPU (Response: Handle)
  97. MBOX_TAG_LOCK_MEMORY = 0x0003000D, // Memory: Unlock Buffer (Response: Status)
  98. MBOX_TAG_UNLOCK_MEMORY = 0x0003000E, // Memory: Unlock Buffer (Response: Status)
  99. MBOX_TAG_RELEASE_MEMORY = 0x0003000F, // Memory: Free The Memory Buffer (Response: Status)
  100. MBOX_TAG_EXECUTE_CODE = 0x00030010, // Memory: Calls The Function At Given (Bus) Address And With Arguments Given
  101. };
  102. /*
  103. * raspi GPU
  104. */
  105. enum {
  106. 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)
  107. MBOX_TAG_ENABLE_QPU = 0x00030012, // QPU: Enables The QPU (Response: Enable State)
  108. };
  109. /*
  110. * raspi HDMI
  111. */
  112. #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))
  113. /*
  114. * raspi NOTIFY
  115. */
  116. #define MBOX_TAG_NOTIFY_REBOOT 0x00030048
  117. #define MBOX_TAG_NOTIFY_XHCI_RESET 0x00030058
  118. /*
  119. * touch
  120. */
  121. #define MBOX_TAG_GET_TOUCHBUF (0x0004000F)
  122. #define MBOX_ADDR 0x08000000
  123. #define RES_CLK_ID (0x000000000)
  124. #define EMMC_CLK_ID (0x000000001)
  125. #define UART_CLK_ID (0x000000002)
  126. #define ARM_CLK_ID (0x000000003)
  127. #define CORE_CLK_ID (0x000000004)
  128. #define V3D_CLK_ID (0x000000005)
  129. #define H264_CLK_ID (0x000000006)
  130. #define ISP_CLK_ID (0x000000007)
  131. #define SDRAM_CLK_ID (0x000000008)
  132. #define PIXEL_CLK_ID (0x000000009)
  133. #define PWM_CLK_ID (0x00000000a)
  134. int mbox_call(unsigned char ch, int mmu_enable);
  135. int bcm271x_mbox_get_touch(void);
  136. int bcm271x_notify_reboot(void);
  137. int bcm271x_notify_xhci_reset(void);
  138. int bcm271x_gpu_enable(void);
  139. int bcm271x_mbox_hardware_get_model(void);
  140. int bcm271x_mbox_hardware_get_revison(void);
  141. int bcm271x_mbox_hardware_get_mac_address(uint8_t * mac);
  142. int bcm271x_mbox_hardware_get_serial(rt_uint64_t* sn);
  143. int bcm271x_mbox_hardware_get_arm_memory(rt_uint32_t * base, rt_uint32_t * size);
  144. int bcm271x_mbox_hardware_get_vc_memory(rt_uint32_t * base, rt_uint32_t * size);
  145. int bcm271x_mbox_clock_get_turbo(void);
  146. int bcm271x_mbox_clock_set_turbo(int level);
  147. int bcm271x_mbox_clock_get_state(int id);
  148. int bcm271x_mbox_clock_set_state(int id, int state);
  149. int bcm271x_mbox_clock_get_rate(int id);
  150. int bcm271x_mbox_clock_set_rate(int id, int rate);
  151. int bcm271x_mbox_clock_get_max_rate(int id);
  152. int bcm271x_mbox_clock_get_min_rate(int id);
  153. int bcm271x_mbox_power_get_state(int id);
  154. int bcm271x_mbox_power_set_state(int id, int state);
  155. int bcm271x_mbox_temp_get(void);
  156. int bcm271x_mbox_temp_get_max(void);
  157. #endif