bmi_msg.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. * Copyright (c) 2012, 2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #ifndef __BMI_MSG_H__
  27. #define __BMI_MSG_H__
  28. #ifndef ATH_TARGET
  29. #include "athstartpack.h"
  30. #endif
  31. /*
  32. * Bootloader Messaging Interface (BMI)
  33. *
  34. * BMI is a very simple messaging interface used during initialization
  35. * to read memory, write memory, execute code, and to define an
  36. * application entry PC.
  37. *
  38. * It is used to download an application to AR6K, to provide
  39. * patches to code that is already resident on AR6K, and generally
  40. * to examine and modify state. The Host has an opportunity to use
  41. * BMI only once during bootup. Once the Host issues a BMI_DONE
  42. * command, this opportunity ends.
  43. *
  44. * The Host writes BMI requests to mailbox0, and reads BMI responses
  45. * from mailbox0. BMI requests all begin with a command
  46. * (see below for specific commands), and are followed by
  47. * command-specific data.
  48. *
  49. * Flow control:
  50. * The Host can only issue a command once the Target gives it a
  51. * "BMI Command Credit", using AR6K Counter #4. As soon as the
  52. * Target has completed a command, it issues another BMI Command
  53. * Credit (so the Host can issue the next command).
  54. *
  55. * BMI handles all required Target-side cache flushing.
  56. */
  57. /* Maximum data size used for BMI transfers */
  58. #define BMI_DATASZ_MAX 256
  59. /* BMI Commands */
  60. #define BMI_NO_COMMAND 0
  61. #define BMI_DONE 1
  62. /*
  63. * Semantics: Host is done using BMI
  64. * Request format:
  65. * A_UINT32 command (BMI_DONE)
  66. * Response format: none
  67. */
  68. #define BMI_READ_MEMORY 2
  69. /*
  70. * Semantics: Host reads AR6K memory
  71. * Request format:
  72. * A_UINT32 command (BMI_READ_MEMORY)
  73. * A_UINT32 address
  74. * A_UINT32 length, at most BMI_DATASZ_MAX
  75. * Response format:
  76. * A_UINT8 data[length]
  77. */
  78. #define BMI_WRITE_MEMORY 3
  79. /*
  80. * Semantics: Host writes AR6K memory
  81. * Request format:
  82. * A_UINT32 command (BMI_WRITE_MEMORY)
  83. * A_UINT32 address
  84. * A_UINT32 length, at most BMI_DATASZ_MAX
  85. * A_UINT8 data[length]
  86. * Response format: none
  87. */
  88. /*
  89. * Capbility to write "segmented files" is provided for two reasons
  90. * 1) backwards compatibility for certain situations where Hosts
  91. * have limited flexibility
  92. * 2) because it's darn convenient.
  93. *
  94. * A segmented file consists of a file header followed by an arbitrary number
  95. * of segments. Each segment contains segment metadata -- a Target address and
  96. * a length -- followed by "length" bytes of data. A segmented file ends with
  97. * a segment that specifies length=BMI_SGMTFILE_DONE. When a segmented file
  98. * is sent to the Target, firmware writes each segment to the specified address.
  99. *
  100. * Special cases:
  101. * 1) If a segment's metadata indicates length=BMI_SGMTFILE_EXEC, then the
  102. * specified address is used as a function entry point for a brief function
  103. * with prototype "(void *)(void)". That function is called immediately.
  104. * After execution of the function completes, firmware continues with the
  105. * next segment. No data is expected when length=BMI_SGMTFILE_EXEC.
  106. *
  107. * 2) If a segment's metadata indicates length=BMI_SGMTFILE_BEGINADDR, then
  108. * the specified address is established as the application start address
  109. * so that a subsequent BMI_DONE jumps there.
  110. *
  111. * 3) If a segment's metadata indicates length=BMI_SGMTFILE_BDDATA, then
  112. * the specified address is used as the (possibly compressed) length of board
  113. * data, which is loaded into the proper Target address as specified by
  114. * hi_board_data. In addition, the hi_board_data_initialized flag is set.
  115. *
  116. * A segmented file is sent to the Target using a sequence of 1 or more
  117. * BMI_WRITE_MEMORY commands. The first such command must have
  118. * address=BMI_SEGMENTED_WRITE_ADDR. Subsequent BMI_WRITE_MEMORY commands
  119. * can use an arbitrary address. In each BMI_WRITE_MEMORY command, the
  120. * length specifies the number of data bytes transmitted (except for the
  121. * special cases listed above).
  122. *
  123. * Alternatively, a segmented file may be sent to the Target using a
  124. * BMI_LZ_STREAM_START command with address=BMI_SEGMENTED_WRITE_ADDR
  125. * followed by a series of BMI_LZ_DATA commands that each send the next portion
  126. * of the segmented file.
  127. *
  128. * The data segments may be lz77 compressed. In this case, the segmented file
  129. * header flag, BMI_SGMTFILE_FLAG_COMPRESS, must be set. Note that segmented
  130. * file METAdata is never compressed; only the data segments themselves are
  131. * compressed. There is no way to mix compressed and uncompressed data segments
  132. * in a single segmented file. Compressed (or uncompressed) segments are handled
  133. * by both BMI_WRITE_MEMORY and by BMI_LZ_DATA commands. (Compression is an
  134. * attribute of the segmented file rather than of the command used to transmit
  135. * it.)
  136. */
  137. #define BMI_SEGMENTED_WRITE_ADDR 0x1234
  138. /* File header for a segmented file */
  139. struct bmi_segmented_file_header {
  140. A_UINT32 magic_num;
  141. A_UINT32 file_flags;
  142. };
  143. #define BMI_SGMTFILE_MAGIC_NUM 0x544d4753 /* "SGMT" */
  144. #define BMI_SGMTFILE_FLAG_COMPRESS 1
  145. /* Metadata for a segmented file segment */
  146. struct bmi_segmented_metadata {
  147. A_UINT32 addr;
  148. A_UINT32 length;
  149. };
  150. /* Special values for bmi_segmented_metadata.length (all have high bit set) */
  151. #define BMI_SGMTFILE_DONE 0xffffffff /* end of segmented data */
  152. #define BMI_SGMTFILE_BDDATA 0xfffffffe /* Board Data segment */
  153. #define BMI_SGMTFILE_BEGINADDR 0xfffffffd /* set beginning address */
  154. #define BMI_SGMTFILE_EXEC 0xfffffffc /* immediate function execution */
  155. #define BMI_EXECUTE 4
  156. /*
  157. * Semantics: Causes AR6K to execute code
  158. * Request format:
  159. * A_UINT32 command (BMI_EXECUTE)
  160. * A_UINT32 address
  161. * A_UINT32 parameter
  162. * Response format:
  163. * A_UINT32 return value
  164. */
  165. /*
  166. * Note: In order to support the segmented file feature
  167. * (see BMI_WRITE_MEMORY), when the address specified in a
  168. * BMI_EXECUTE command matches (same physical address)
  169. * BMI_SEGMENTED_WRITE_ADDR, it is ignored. Instead, execution
  170. * begins at the address specified by hi_app_start.
  171. */
  172. #define BMI_SET_APP_START 5
  173. /*
  174. * Semantics: Set Target application starting address
  175. * Request format:
  176. * A_UINT32 command (BMI_SET_APP_START)
  177. * A_UINT32 address
  178. * Response format: none
  179. */
  180. #define BMI_READ_SOC_REGISTER 6
  181. #define BMI_READ_SOC_WORD 6
  182. /*
  183. * Semantics: Read a 32-bit Target SOC word.
  184. * Request format:
  185. * A_UINT32 command (BMI_READ_REGISTER)
  186. * A_UINT32 address
  187. * Response format:
  188. * A_UINT32 value
  189. */
  190. #define BMI_WRITE_SOC_REGISTER 7
  191. #define BMI_WRITE_SOC_WORD 7
  192. /*
  193. * Semantics: Write a 32-bit Target SOC word.
  194. * Request format:
  195. * A_UINT32 command (BMI_WRITE_REGISTER)
  196. * A_UINT32 address
  197. * A_UINT32 value
  198. *
  199. * Response format: none
  200. */
  201. #define BMI_GET_TARGET_ID 8
  202. #define BMI_GET_TARGET_INFO 8
  203. /*
  204. * Semantics: Fetch the 4-byte Target information
  205. * Request format:
  206. * A_UINT32 command (BMI_GET_TARGET_ID/INFO)
  207. *
  208. * Response format1 (old firmware):
  209. * A_UINT32 TargetVersionID
  210. *
  211. * Response format2 (intermediate firmware, during transition):
  212. * A_UINT32 TARGET_VERSION_SENTINAL
  213. * struct bmi_target_info;
  214. *
  215. * Response format3 (newest firmware)
  216. * struct bmi_target_info;
  217. */
  218. PREPACK struct bmi_target_info {
  219. A_UINT32 target_info_byte_count; /* size of this structure */
  220. A_UINT32 target_ver; /* Target Version ID */
  221. A_UINT32 target_type; /* Target type */
  222. } POSTPACK;
  223. #define TARGET_VERSION_SENTINAL 0xffffffff
  224. #define TARGET_TYPE_UNKNOWN 0
  225. #define TARGET_TYPE_AR6001 1
  226. #define TARGET_TYPE_AR6002 2
  227. #define TARGET_TYPE_AR6003 3
  228. #define TARGET_TYPE_AR6004 5
  229. #define TARGET_TYPE_AR6006 6
  230. #define TARGET_TYPE_AR9888 7
  231. #define TARGET_TYPE_AR6320 8
  232. #define TARGET_TYPE_AR900B 9
  233. /* For attach Peregrine 2.0 board target_reg_tbl only */
  234. #define TARGET_TYPE_AR9888V2 10
  235. /* For attach Rome1.0 target_reg_tbl only*/
  236. #define TARGET_TYPE_AR6320V1 11
  237. /* For Rome2.0/2.1 target_reg_tbl ID*/
  238. #define TARGET_TYPE_AR6320V2 12
  239. /* For Rome3.0 target_reg_tbl ID*/
  240. #define TARGET_TYPE_AR6320V3 13
  241. /* For Tufello1.0 target_reg_tbl ID*/
  242. #define TARGET_TYPE_QCA9377V1 14
  243. #define TARGET_TYPE_QCA9984 15 /* cascade */
  244. #define TARGET_TYPE_IPQ4019 16 /* dakota */
  245. #define TARGET_TYPE_QCA9888 17 /* besra */
  246. #define BMI_ROMPATCH_INSTALL 9
  247. /*
  248. * Semantics: Install a ROM Patch.
  249. * Request format:
  250. * A_UINT32 command (BMI_ROMPATCH_INSTALL)
  251. * A_UINT32 Target ROM Address
  252. * A_UINT32 Target RAM Address or Value (depending on Target Type)
  253. * A_UINT32 Size, in bytes
  254. * A_UINT32 Activate? 1-->activate;
  255. * 0-->install but do not activate
  256. * Response format:
  257. * A_UINT32 PatchID
  258. */
  259. #define BMI_ROMPATCH_UNINSTALL 10
  260. /*
  261. * Semantics: Uninstall a previously-installed ROM Patch,
  262. * automatically deactivating, if necessary.
  263. * Request format:
  264. * A_UINT32 command (BMI_ROMPATCH_UNINSTALL)
  265. * A_UINT32 PatchID
  266. *
  267. * Response format: none
  268. */
  269. #define BMI_ROMPATCH_ACTIVATE 11
  270. /*
  271. * Semantics: Activate a list of previously-installed ROM Patches.
  272. * Request format:
  273. * A_UINT32 command (BMI_ROMPATCH_ACTIVATE)
  274. * A_UINT32 rompatch_count
  275. * A_UINT32 PatchID[rompatch_count]
  276. *
  277. * Response format: none
  278. */
  279. #define BMI_ROMPATCH_DEACTIVATE 12
  280. /*
  281. * Semantics: Deactivate a list of active ROM Patches.
  282. * Request format:
  283. * A_UINT32 command (BMI_ROMPATCH_DEACTIVATE)
  284. * A_UINT32 rompatch_count
  285. * A_UINT32 PatchID[rompatch_count]
  286. *
  287. * Response format: none
  288. */
  289. #define BMI_LZ_STREAM_START 13
  290. /*
  291. * Semantics: Begin an LZ-compressed stream of input
  292. * which is to be uncompressed by the Target to an
  293. * output buffer at address. The output buffer must
  294. * be sufficiently large to hold the uncompressed
  295. * output from the compressed input stream. This BMI
  296. * command should be followed by a series of 1 or more
  297. * BMI_LZ_DATA commands.
  298. * A_UINT32 command (BMI_LZ_STREAM_START)
  299. * A_UINT32 address
  300. * Note: Not supported on all versions of ROM firmware.
  301. */
  302. #define BMI_LZ_DATA 14
  303. /*
  304. * Semantics: Host writes AR6K memory with LZ-compressed
  305. * data which is uncompressed by the Target. This command
  306. * must be preceded by a BMI_LZ_STREAM_START command. A series
  307. * of BMI_LZ_DATA commands are considered part of a single
  308. * input stream until another BMI_LZ_STREAM_START is issued.
  309. * Request format:
  310. * A_UINT32 command (BMI_LZ_DATA)
  311. * A_UINT32 length (of compressed data),
  312. * at most BMI_DATASZ_MAX
  313. * A_UINT8 CompressedData[length]
  314. * Response format: none
  315. * Note: Not supported on all versions of ROM firmware.
  316. */
  317. #define BMI_NVRAM_PROCESS 15
  318. #define BMI_NVRAM_SEG_NAME_SZ 16
  319. /*
  320. * Semantics: Cause Target to search NVRAM (if any) for a
  321. * segment with the specified name and process it according
  322. * to NVRAM metadata.
  323. * Request format:
  324. * A_UINT32 command (BMI_NVRAM_PROCESS)
  325. * A_UCHAR name[BMI_NVRAM_SEG_NAME_SZ] name (LE format)
  326. * Response format:
  327. * A_UINT32 0, if nothing was executed;
  328. * otherwise the value returned from the
  329. * last NVRAM segment that was executed
  330. */
  331. #define BMI_SIGN_STREAM_START 17
  332. /*
  333. * Semantics: Trigger target start/end binary signature verification
  334. * flow.
  335. * Request format:
  336. * A_UINT32 command (BMI_SIGN_STREAM_START)
  337. * A_UINT32 address
  338. * A_UINT32 length, at most BMI_DATASZ_MAX
  339. * A_UINT8 data[length]
  340. * Response format: none
  341. */
  342. #ifndef ATH_TARGET
  343. #include "athendpack.h"
  344. #endif
  345. /* TBDXXX: Need a better place for these */
  346. #define BMI_CE_NUM_TO_TARG 0
  347. #define BMI_CE_NUM_TO_HOST 1
  348. #endif /* __BMI_MSG_H__ */