acr_r352.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. #ifndef __NVKM_SECBOOT_ACR_R352_H__
  23. #define __NVKM_SECBOOT_ACR_R352_H__
  24. #include "acr.h"
  25. #include "ls_ucode.h"
  26. struct ls_ucode_img;
  27. #define ACR_R352_MAX_APPS 8
  28. /*
  29. *
  30. * LS blob structures
  31. *
  32. */
  33. /**
  34. * struct acr_r352_lsf_lsb_header - LS firmware header
  35. * @signature: signature to verify the firmware against
  36. * @ucode_off: offset of the ucode blob in the WPR region. The ucode
  37. * blob contains the bootloader, code and data of the
  38. * LS falcon
  39. * @ucode_size: size of the ucode blob, including bootloader
  40. * @data_size: size of the ucode blob data
  41. * @bl_code_size: size of the bootloader code
  42. * @bl_imem_off: offset in imem of the bootloader
  43. * @bl_data_off: offset of the bootloader data in WPR region
  44. * @bl_data_size: size of the bootloader data
  45. * @app_code_off: offset of the app code relative to ucode_off
  46. * @app_code_size: size of the app code
  47. * @app_data_off: offset of the app data relative to ucode_off
  48. * @app_data_size: size of the app data
  49. * @flags: flags for the secure bootloader
  50. *
  51. * This structure is written into the WPR region for each managed falcon. Each
  52. * instance is referenced by the lsb_offset member of the corresponding
  53. * lsf_wpr_header.
  54. */
  55. struct acr_r352_lsf_lsb_header {
  56. /**
  57. * LS falcon signatures
  58. * @prd_keys: signature to use in production mode
  59. * @dgb_keys: signature to use in debug mode
  60. * @b_prd_present: whether the production key is present
  61. * @b_dgb_present: whether the debug key is present
  62. * @falcon_id: ID of the falcon the ucode applies to
  63. */
  64. struct {
  65. u8 prd_keys[2][16];
  66. u8 dbg_keys[2][16];
  67. u32 b_prd_present;
  68. u32 b_dbg_present;
  69. u32 falcon_id;
  70. } signature;
  71. u32 ucode_off;
  72. u32 ucode_size;
  73. u32 data_size;
  74. u32 bl_code_size;
  75. u32 bl_imem_off;
  76. u32 bl_data_off;
  77. u32 bl_data_size;
  78. u32 app_code_off;
  79. u32 app_code_size;
  80. u32 app_data_off;
  81. u32 app_data_size;
  82. u32 flags;
  83. #define LSF_FLAG_LOAD_CODE_AT_0 1
  84. #define LSF_FLAG_DMACTL_REQ_CTX 4
  85. #define LSF_FLAG_FORCE_PRIV_LOAD 8
  86. };
  87. /**
  88. * struct acr_r352_lsf_wpr_header - LS blob WPR Header
  89. * @falcon_id: LS falcon ID
  90. * @lsb_offset: offset of the lsb_lsf_header in the WPR region
  91. * @bootstrap_owner: secure falcon reponsible for bootstrapping the LS falcon
  92. * @lazy_bootstrap: skip bootstrapping by ACR
  93. * @status: bootstrapping status
  94. *
  95. * An array of these is written at the beginning of the WPR region, one for
  96. * each managed falcon. The array is terminated by an instance which falcon_id
  97. * is LSF_FALCON_ID_INVALID.
  98. */
  99. struct acr_r352_lsf_wpr_header {
  100. u32 falcon_id;
  101. u32 lsb_offset;
  102. u32 bootstrap_owner;
  103. u32 lazy_bootstrap;
  104. u32 status;
  105. #define LSF_IMAGE_STATUS_NONE 0
  106. #define LSF_IMAGE_STATUS_COPY 1
  107. #define LSF_IMAGE_STATUS_VALIDATION_CODE_FAILED 2
  108. #define LSF_IMAGE_STATUS_VALIDATION_DATA_FAILED 3
  109. #define LSF_IMAGE_STATUS_VALIDATION_DONE 4
  110. #define LSF_IMAGE_STATUS_VALIDATION_SKIPPED 5
  111. #define LSF_IMAGE_STATUS_BOOTSTRAP_READY 6
  112. };
  113. /**
  114. * struct ls_ucode_img_r352 - ucode image augmented with r352 headers
  115. */
  116. struct ls_ucode_img_r352 {
  117. struct ls_ucode_img base;
  118. struct acr_r352_lsf_wpr_header wpr_header;
  119. struct acr_r352_lsf_lsb_header lsb_header;
  120. };
  121. #define ls_ucode_img_r352(i) container_of(i, struct ls_ucode_img_r352, base)
  122. /*
  123. * HS blob structures
  124. */
  125. struct hsf_load_header_app {
  126. u32 sec_code_off;
  127. u32 sec_code_size;
  128. };
  129. /**
  130. * struct hsf_load_header - HS firmware load header
  131. */
  132. struct hsf_load_header {
  133. u32 non_sec_code_off;
  134. u32 non_sec_code_size;
  135. u32 data_dma_base;
  136. u32 data_size;
  137. u32 num_apps;
  138. struct hsf_load_header_app app[0];
  139. };
  140. /**
  141. * struct acr_r352_ls_func - manages a single LS firmware
  142. *
  143. * @load: load the external firmware into a ls_ucode_img
  144. * @generate_bl_desc: function called on a block of bl_desc_size to generate the
  145. * proper bootloader descriptor for this LS firmware
  146. * @bl_desc_size: size of the bootloader descriptor
  147. * @lhdr_flags: LS flags
  148. */
  149. struct acr_r352_ls_func {
  150. int (*load)(const struct nvkm_subdev *, struct ls_ucode_img *);
  151. void (*generate_bl_desc)(const struct nvkm_acr *,
  152. const struct ls_ucode_img *, u64, void *);
  153. u32 bl_desc_size;
  154. u32 lhdr_flags;
  155. };
  156. struct acr_r352;
  157. /**
  158. * struct acr_r352_func - manages nuances between ACR versions
  159. *
  160. * @generate_hs_bl_desc: function called on a block of bl_desc_size to generate
  161. * the proper HS bootloader descriptor
  162. * @hs_bl_desc_size: size of the HS bootloader descriptor
  163. */
  164. struct acr_r352_func {
  165. void (*generate_hs_bl_desc)(const struct hsf_load_header *, void *,
  166. u64);
  167. u32 hs_bl_desc_size;
  168. struct ls_ucode_img *(*ls_ucode_img_load)(const struct acr_r352 *,
  169. enum nvkm_secboot_falcon);
  170. int (*ls_fill_headers)(struct acr_r352 *, struct list_head *);
  171. int (*ls_write_wpr)(struct acr_r352 *, struct list_head *,
  172. struct nvkm_gpuobj *, u32);
  173. const struct acr_r352_ls_func *ls_func[NVKM_SECBOOT_FALCON_END];
  174. };
  175. /**
  176. * struct acr_r352 - ACR data for driver release 352 (and beyond)
  177. */
  178. struct acr_r352 {
  179. struct nvkm_acr base;
  180. const struct acr_r352_func *func;
  181. /*
  182. * HS FW - lock WPR region (dGPU only) and load LS FWs
  183. * on Tegra the HS FW copies the LS blob into the fixed WPR instead
  184. */
  185. struct nvkm_gpuobj *load_blob;
  186. struct {
  187. struct hsf_load_header load_bl_header;
  188. struct hsf_load_header_app __load_apps[ACR_R352_MAX_APPS];
  189. };
  190. /* HS FW - unlock WPR region (dGPU only) */
  191. struct nvkm_gpuobj *unload_blob;
  192. struct {
  193. struct hsf_load_header unload_bl_header;
  194. struct hsf_load_header_app __unload_apps[ACR_R352_MAX_APPS];
  195. };
  196. /* HS bootloader */
  197. void *hsbl_blob;
  198. /* LS FWs, to be loaded by the HS ACR */
  199. struct nvkm_gpuobj *ls_blob;
  200. /* Firmware already loaded? */
  201. bool firmware_ok;
  202. /* Falcons to lazy-bootstrap */
  203. u32 lazy_bootstrap;
  204. /* To keep track of the state of all managed falcons */
  205. enum {
  206. /* In non-secure state, no firmware loaded, no privileges*/
  207. NON_SECURE = 0,
  208. /* In low-secure mode and ready to be started */
  209. RESET,
  210. /* In low-secure mode and running */
  211. RUNNING,
  212. } falcon_state[NVKM_SECBOOT_FALCON_END];
  213. };
  214. #define acr_r352(acr) container_of(acr, struct acr_r352, base)
  215. struct nvkm_acr *acr_r352_new_(const struct acr_r352_func *,
  216. enum nvkm_secboot_falcon, unsigned long);
  217. struct ls_ucode_img *acr_r352_ls_ucode_img_load(const struct acr_r352 *,
  218. enum nvkm_secboot_falcon);
  219. int acr_r352_ls_fill_headers(struct acr_r352 *, struct list_head *);
  220. int acr_r352_ls_write_wpr(struct acr_r352 *, struct list_head *,
  221. struct nvkm_gpuobj *, u32);
  222. #endif