bmi.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _BMI_H_
  18. #define _BMI_H_
  19. #include "core.h"
  20. /*
  21. * Bootloader Messaging Interface (BMI)
  22. *
  23. * BMI is a very simple messaging interface used during initialization
  24. * to read memory, write memory, execute code, and to define an
  25. * application entry PC.
  26. *
  27. * It is used to download an application to QCA988x, to provide
  28. * patches to code that is already resident on QCA988x, and generally
  29. * to examine and modify state. The Host has an opportunity to use
  30. * BMI only once during bootup. Once the Host issues a BMI_DONE
  31. * command, this opportunity ends.
  32. *
  33. * The Host writes BMI requests to mailbox0, and reads BMI responses
  34. * from mailbox0. BMI requests all begin with a command
  35. * (see below for specific commands), and are followed by
  36. * command-specific data.
  37. *
  38. * Flow control:
  39. * The Host can only issue a command once the Target gives it a
  40. * "BMI Command Credit", using AR8K Counter #4. As soon as the
  41. * Target has completed a command, it issues another BMI Command
  42. * Credit (so the Host can issue the next command).
  43. *
  44. * BMI handles all required Target-side cache flushing.
  45. */
  46. /* Maximum data size used for BMI transfers */
  47. #define BMI_MAX_DATA_SIZE 256
  48. /* len = cmd + addr + length */
  49. #define BMI_MAX_CMDBUF_SIZE (BMI_MAX_DATA_SIZE + \
  50. sizeof(u32) + \
  51. sizeof(u32) + \
  52. sizeof(u32))
  53. /* BMI Commands */
  54. enum bmi_cmd_id {
  55. BMI_NO_COMMAND = 0,
  56. BMI_DONE = 1,
  57. BMI_READ_MEMORY = 2,
  58. BMI_WRITE_MEMORY = 3,
  59. BMI_EXECUTE = 4,
  60. BMI_SET_APP_START = 5,
  61. BMI_READ_SOC_REGISTER = 6,
  62. BMI_READ_SOC_WORD = 6,
  63. BMI_WRITE_SOC_REGISTER = 7,
  64. BMI_WRITE_SOC_WORD = 7,
  65. BMI_GET_TARGET_ID = 8,
  66. BMI_GET_TARGET_INFO = 8,
  67. BMI_ROMPATCH_INSTALL = 9,
  68. BMI_ROMPATCH_UNINSTALL = 10,
  69. BMI_ROMPATCH_ACTIVATE = 11,
  70. BMI_ROMPATCH_DEACTIVATE = 12,
  71. BMI_LZ_STREAM_START = 13, /* should be followed by LZ_DATA */
  72. BMI_LZ_DATA = 14,
  73. BMI_NVRAM_PROCESS = 15,
  74. };
  75. #define BMI_NVRAM_SEG_NAME_SZ 16
  76. struct bmi_cmd {
  77. __le32 id; /* enum bmi_cmd_id */
  78. union {
  79. struct {
  80. } done;
  81. struct {
  82. __le32 addr;
  83. __le32 len;
  84. } read_mem;
  85. struct {
  86. __le32 addr;
  87. __le32 len;
  88. u8 payload[0];
  89. } write_mem;
  90. struct {
  91. __le32 addr;
  92. __le32 param;
  93. } execute;
  94. struct {
  95. __le32 addr;
  96. } set_app_start;
  97. struct {
  98. __le32 addr;
  99. } read_soc_reg;
  100. struct {
  101. __le32 addr;
  102. __le32 value;
  103. } write_soc_reg;
  104. struct {
  105. } get_target_info;
  106. struct {
  107. __le32 rom_addr;
  108. __le32 ram_addr; /* or value */
  109. __le32 size;
  110. __le32 activate; /* 0=install, but dont activate */
  111. } rompatch_install;
  112. struct {
  113. __le32 patch_id;
  114. } rompatch_uninstall;
  115. struct {
  116. __le32 count;
  117. __le32 patch_ids[0]; /* length of @count */
  118. } rompatch_activate;
  119. struct {
  120. __le32 count;
  121. __le32 patch_ids[0]; /* length of @count */
  122. } rompatch_deactivate;
  123. struct {
  124. __le32 addr;
  125. } lz_start;
  126. struct {
  127. __le32 len; /* max BMI_MAX_DATA_SIZE */
  128. u8 payload[0]; /* length of @len */
  129. } lz_data;
  130. struct {
  131. u8 name[BMI_NVRAM_SEG_NAME_SZ];
  132. } nvram_process;
  133. u8 payload[BMI_MAX_CMDBUF_SIZE];
  134. };
  135. } __packed;
  136. union bmi_resp {
  137. struct {
  138. u8 payload[0];
  139. } read_mem;
  140. struct {
  141. __le32 result;
  142. } execute;
  143. struct {
  144. __le32 value;
  145. } read_soc_reg;
  146. struct {
  147. __le32 len;
  148. __le32 version;
  149. __le32 type;
  150. } get_target_info;
  151. struct {
  152. __le32 patch_id;
  153. } rompatch_install;
  154. struct {
  155. __le32 patch_id;
  156. } rompatch_uninstall;
  157. struct {
  158. /* 0 = nothing executed
  159. * otherwise = NVRAM segment return value */
  160. __le32 result;
  161. } nvram_process;
  162. u8 payload[BMI_MAX_CMDBUF_SIZE];
  163. } __packed;
  164. struct bmi_target_info {
  165. u32 version;
  166. u32 type;
  167. };
  168. /* in msec */
  169. #define BMI_COMMUNICATION_TIMEOUT_HZ (1*HZ)
  170. #define BMI_CE_NUM_TO_TARG 0
  171. #define BMI_CE_NUM_TO_HOST 1
  172. void ath10k_bmi_start(struct ath10k *ar);
  173. int ath10k_bmi_done(struct ath10k *ar);
  174. int ath10k_bmi_get_target_info(struct ath10k *ar,
  175. struct bmi_target_info *target_info);
  176. int ath10k_bmi_read_memory(struct ath10k *ar, u32 address,
  177. void *buffer, u32 length);
  178. int ath10k_bmi_write_memory(struct ath10k *ar, u32 address,
  179. const void *buffer, u32 length);
  180. #define ath10k_bmi_read32(ar, item, val) \
  181. ({ \
  182. int ret; \
  183. u32 addr; \
  184. __le32 tmp; \
  185. \
  186. addr = host_interest_item_address(HI_ITEM(item)); \
  187. ret = ath10k_bmi_read_memory(ar, addr, (u8 *)&tmp, 4); \
  188. *val = __le32_to_cpu(tmp); \
  189. ret; \
  190. })
  191. #define ath10k_bmi_write32(ar, item, val) \
  192. ({ \
  193. int ret; \
  194. u32 address; \
  195. __le32 v = __cpu_to_le32(val); \
  196. \
  197. address = host_interest_item_address(HI_ITEM(item)); \
  198. ret = ath10k_bmi_write_memory(ar, address, \
  199. (u8 *)&v, sizeof(v)); \
  200. ret; \
  201. })
  202. int ath10k_bmi_execute(struct ath10k *ar, u32 address, u32 *param);
  203. int ath10k_bmi_lz_stream_start(struct ath10k *ar, u32 address);
  204. int ath10k_bmi_lz_data(struct ath10k *ar, const void *buffer, u32 length);
  205. int ath10k_bmi_fast_download(struct ath10k *ar, u32 address,
  206. const void *buffer, u32 length);
  207. #endif /* _BMI_H_ */