priv.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Copyright (c) 2015, 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_PRIV_H__
  23. #define __NVKM_SECBOOT_PRIV_H__
  24. #include <subdev/secboot.h>
  25. #include <subdev/mmu.h>
  26. struct nvkm_secboot_func {
  27. int (*init)(struct nvkm_secboot *);
  28. int (*fini)(struct nvkm_secboot *, bool suspend);
  29. void *(*dtor)(struct nvkm_secboot *);
  30. int (*reset)(struct nvkm_secboot *, enum nvkm_secboot_falcon);
  31. int (*start)(struct nvkm_secboot *, enum nvkm_secboot_falcon);
  32. /* ID of the falcon that will perform secure boot */
  33. enum nvkm_secboot_falcon boot_falcon;
  34. /* Bit-mask of IDs of managed falcons */
  35. unsigned long managed_falcons;
  36. };
  37. int nvkm_secboot_ctor(const struct nvkm_secboot_func *, struct nvkm_device *,
  38. int index, struct nvkm_secboot *);
  39. int nvkm_secboot_falcon_reset(struct nvkm_secboot *);
  40. int nvkm_secboot_falcon_run(struct nvkm_secboot *);
  41. struct flcn_u64 {
  42. u32 lo;
  43. u32 hi;
  44. };
  45. static inline u64 flcn64_to_u64(const struct flcn_u64 f)
  46. {
  47. return ((u64)f.hi) << 32 | f.lo;
  48. }
  49. /**
  50. * struct gm200_flcn_bl_desc - DMEM bootloader descriptor
  51. * @signature: 16B signature for secure code. 0s if no secure code
  52. * @ctx_dma: DMA context to be used by BL while loading code/data
  53. * @code_dma_base: 256B-aligned Physical FB Address where code is located
  54. * (falcon's $xcbase register)
  55. * @non_sec_code_off: offset from code_dma_base where the non-secure code is
  56. * located. The offset must be multiple of 256 to help perf
  57. * @non_sec_code_size: the size of the nonSecure code part.
  58. * @sec_code_off: offset from code_dma_base where the secure code is
  59. * located. The offset must be multiple of 256 to help perf
  60. * @sec_code_size: offset from code_dma_base where the secure code is
  61. * located. The offset must be multiple of 256 to help perf
  62. * @code_entry_point: code entry point which will be invoked by BL after
  63. * code is loaded.
  64. * @data_dma_base: 256B aligned Physical FB Address where data is located.
  65. * (falcon's $xdbase register)
  66. * @data_size: size of data block. Should be multiple of 256B
  67. *
  68. * Structure used by the bootloader to load the rest of the code. This has
  69. * to be filled by host and copied into DMEM at offset provided in the
  70. * hsflcn_bl_desc.bl_desc_dmem_load_off.
  71. */
  72. struct gm200_flcn_bl_desc {
  73. u32 reserved[4];
  74. u32 signature[4];
  75. u32 ctx_dma;
  76. struct flcn_u64 code_dma_base;
  77. u32 non_sec_code_off;
  78. u32 non_sec_code_size;
  79. u32 sec_code_off;
  80. u32 sec_code_size;
  81. u32 code_entry_point;
  82. struct flcn_u64 data_dma_base;
  83. u32 data_size;
  84. };
  85. /**
  86. * struct hsflcn_acr_desc - data section of the HS firmware
  87. *
  88. * This header is to be copied at the beginning of DMEM by the HS bootloader.
  89. *
  90. * @signature: signature of ACR ucode
  91. * @wpr_region_id: region ID holding the WPR header and its details
  92. * @wpr_offset: offset from the WPR region holding the wpr header
  93. * @regions: region descriptors
  94. * @nonwpr_ucode_blob_size: size of LS blob
  95. * @nonwpr_ucode_blob_start: FB location of LS blob is
  96. */
  97. struct hsflcn_acr_desc {
  98. union {
  99. u8 reserved_dmem[0x200];
  100. u32 signatures[4];
  101. } ucode_reserved_space;
  102. u32 wpr_region_id;
  103. u32 wpr_offset;
  104. u32 mmu_mem_range;
  105. #define FLCN_ACR_MAX_REGIONS 2
  106. struct {
  107. u32 no_regions;
  108. struct {
  109. u32 start_addr;
  110. u32 end_addr;
  111. u32 region_id;
  112. u32 read_mask;
  113. u32 write_mask;
  114. u32 client_mask;
  115. } region_props[FLCN_ACR_MAX_REGIONS];
  116. } regions;
  117. u32 ucode_blob_size;
  118. u64 ucode_blob_base __aligned(8);
  119. struct {
  120. u32 vpr_enabled;
  121. u32 vpr_start;
  122. u32 vpr_end;
  123. u32 hdcp_policies;
  124. } vpr_desc;
  125. };
  126. /**
  127. * Contains the whole secure boot state, allowing it to be performed as needed
  128. * @wpr_addr: physical address of the WPR region
  129. * @wpr_size: size in bytes of the WPR region
  130. * @ls_blob: LS blob of all the LS firmwares, signatures, bootloaders
  131. * @ls_blob_size: size of the LS blob
  132. * @ls_blob_nb_regions: number of LS firmwares that will be loaded
  133. * @acr_blob: HS blob
  134. * @acr_blob_vma: mapping of the HS blob into the secure falcon's VM
  135. * @acr_bl_desc: bootloader descriptor of the HS blob
  136. * @hsbl_blob: HS blob bootloader
  137. * @inst: instance block for HS falcon
  138. * @pgd: page directory for the HS falcon
  139. * @vm: address space used by the HS falcon
  140. * @falcon_state: current state of the managed falcons
  141. * @firmware_ok: whether the firmware blobs have been created
  142. */
  143. struct gm200_secboot {
  144. struct nvkm_secboot base;
  145. const struct gm200_secboot_func *func;
  146. /*
  147. * Address and size of the WPR region. On dGPU this will be the
  148. * address of the LS blob. On Tegra this is a fixed region set by the
  149. * bootloader
  150. */
  151. u64 wpr_addr;
  152. u32 wpr_size;
  153. /*
  154. * HS FW - lock WPR region (dGPU only) and load LS FWs
  155. * on Tegra the HS FW copies the LS blob into the fixed WPR instead
  156. */
  157. struct nvkm_gpuobj *acr_load_blob;
  158. struct gm200_flcn_bl_desc acr_load_bl_desc;
  159. /* HS FW - unlock WPR region (dGPU only) */
  160. struct nvkm_gpuobj *acr_unload_blob;
  161. struct gm200_flcn_bl_desc acr_unload_bl_desc;
  162. /* HS bootloader */
  163. void *hsbl_blob;
  164. /* LS FWs, to be loaded by the HS ACR */
  165. struct nvkm_gpuobj *ls_blob;
  166. /* Instance block & address space used for HS FW execution */
  167. struct nvkm_gpuobj *inst;
  168. struct nvkm_gpuobj *pgd;
  169. struct nvkm_vm *vm;
  170. /* To keep track of the state of all managed falcons */
  171. enum {
  172. /* In non-secure state, no firmware loaded, no privileges*/
  173. NON_SECURE = 0,
  174. /* In low-secure mode and ready to be started */
  175. RESET,
  176. /* In low-secure mode and running */
  177. RUNNING,
  178. } falcon_state[NVKM_SECBOOT_FALCON_END];
  179. bool firmware_ok;
  180. };
  181. #define gm200_secboot(sb) container_of(sb, struct gm200_secboot, base)
  182. /**
  183. * Contains functions we wish to abstract between GM200-like implementations
  184. * @bl_desc_size: size of the BL descriptor used by this chip.
  185. * @fixup_bl_desc: hook that generates the proper BL descriptor format from
  186. * the generic GM200 format into a data array of size
  187. * bl_desc_size
  188. * @fixup_hs_desc: hook that twiddles the HS descriptor before it is used
  189. * @prepare_blobs: prepares the various blobs needed for secure booting
  190. */
  191. struct gm200_secboot_func {
  192. /*
  193. * Size of the bootloader descriptor for this chip. A block of this
  194. * size is allocated before booting a falcon and the fixup_bl_desc
  195. * callback is called on it
  196. */
  197. u32 bl_desc_size;
  198. void (*fixup_bl_desc)(const struct gm200_flcn_bl_desc *, void *);
  199. /*
  200. * Chip-specific modifications of the HS descriptor can be done here.
  201. * On dGPU this is used to fill the information about the WPR region
  202. * we want the HS FW to set up.
  203. */
  204. void (*fixup_hs_desc)(struct gm200_secboot *, struct hsflcn_acr_desc *);
  205. int (*prepare_blobs)(struct gm200_secboot *);
  206. };
  207. int gm200_secboot_init(struct nvkm_secboot *);
  208. void *gm200_secboot_dtor(struct nvkm_secboot *);
  209. int gm200_secboot_reset(struct nvkm_secboot *, u32);
  210. int gm200_secboot_start(struct nvkm_secboot *, u32);
  211. int gm20x_secboot_prepare_blobs(struct gm200_secboot *);
  212. #endif