acr_r352.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #include "hs_ucode.h"
  27. struct ls_ucode_img;
  28. #define ACR_R352_MAX_APPS 8
  29. #define LSF_FLAG_LOAD_CODE_AT_0 1
  30. #define LSF_FLAG_DMACTL_REQ_CTX 4
  31. #define LSF_FLAG_FORCE_PRIV_LOAD 8
  32. static inline u32
  33. hsf_load_header_app_off(const struct hsf_load_header *hdr, u32 app)
  34. {
  35. return hdr->apps[app];
  36. }
  37. static inline u32
  38. hsf_load_header_app_size(const struct hsf_load_header *hdr, u32 app)
  39. {
  40. return hdr->apps[hdr->num_apps + app];
  41. }
  42. /**
  43. * struct acr_r352_ls_func - manages a single LS firmware
  44. *
  45. * @load: load the external firmware into a ls_ucode_img
  46. * @generate_bl_desc: function called on a block of bl_desc_size to generate the
  47. * proper bootloader descriptor for this LS firmware
  48. * @bl_desc_size: size of the bootloader descriptor
  49. * @post_run: hook called right after the ACR is executed
  50. * @lhdr_flags: LS flags
  51. */
  52. struct acr_r352_ls_func {
  53. int (*load)(const struct nvkm_secboot *, struct ls_ucode_img *);
  54. void (*generate_bl_desc)(const struct nvkm_acr *,
  55. const struct ls_ucode_img *, u64, void *);
  56. u32 bl_desc_size;
  57. int (*post_run)(const struct nvkm_acr *, const struct nvkm_secboot *);
  58. u32 lhdr_flags;
  59. };
  60. struct acr_r352;
  61. /**
  62. * struct acr_r352_func - manages nuances between ACR versions
  63. *
  64. * @generate_hs_bl_desc: function called on a block of bl_desc_size to generate
  65. * the proper HS bootloader descriptor
  66. * @hs_bl_desc_size: size of the HS bootloader descriptor
  67. */
  68. struct acr_r352_func {
  69. void (*generate_hs_bl_desc)(const struct hsf_load_header *, void *,
  70. u64);
  71. void (*fixup_hs_desc)(struct acr_r352 *, struct nvkm_secboot *, void *);
  72. u32 hs_bl_desc_size;
  73. bool shadow_blob;
  74. struct ls_ucode_img *(*ls_ucode_img_load)(const struct acr_r352 *,
  75. const struct nvkm_secboot *,
  76. enum nvkm_secboot_falcon);
  77. int (*ls_fill_headers)(struct acr_r352 *, struct list_head *);
  78. int (*ls_write_wpr)(struct acr_r352 *, struct list_head *,
  79. struct nvkm_gpuobj *, u64);
  80. const struct acr_r352_ls_func *ls_func[NVKM_SECBOOT_FALCON_END];
  81. };
  82. /**
  83. * struct acr_r352 - ACR data for driver release 352 (and beyond)
  84. */
  85. struct acr_r352 {
  86. struct nvkm_acr base;
  87. const struct acr_r352_func *func;
  88. /*
  89. * HS FW - lock WPR region (dGPU only) and load LS FWs
  90. * on Tegra the HS FW copies the LS blob into the fixed WPR instead
  91. */
  92. struct nvkm_gpuobj *load_blob;
  93. struct {
  94. struct hsf_load_header load_bl_header;
  95. u32 __load_apps[ACR_R352_MAX_APPS * 2];
  96. };
  97. /* HS FW - unlock WPR region (dGPU only) */
  98. struct nvkm_gpuobj *unload_blob;
  99. struct {
  100. struct hsf_load_header unload_bl_header;
  101. u32 __unload_apps[ACR_R352_MAX_APPS * 2];
  102. };
  103. /* HS bootloader */
  104. void *hsbl_blob;
  105. /* HS bootloader for unload blob, if using a different falcon */
  106. void *hsbl_unload_blob;
  107. /* LS FWs, to be loaded by the HS ACR */
  108. struct nvkm_gpuobj *ls_blob;
  109. /* Firmware already loaded? */
  110. bool firmware_ok;
  111. /* Falcons to lazy-bootstrap */
  112. u32 lazy_bootstrap;
  113. /* To keep track of the state of all managed falcons */
  114. enum {
  115. /* In non-secure state, no firmware loaded, no privileges*/
  116. NON_SECURE = 0,
  117. /* In low-secure mode and ready to be started */
  118. RESET,
  119. /* In low-secure mode and running */
  120. RUNNING,
  121. } falcon_state[NVKM_SECBOOT_FALCON_END];
  122. };
  123. #define acr_r352(acr) container_of(acr, struct acr_r352, base)
  124. struct nvkm_acr *acr_r352_new_(const struct acr_r352_func *,
  125. enum nvkm_secboot_falcon, unsigned long);
  126. struct ls_ucode_img *acr_r352_ls_ucode_img_load(const struct acr_r352 *,
  127. const struct nvkm_secboot *,
  128. enum nvkm_secboot_falcon);
  129. int acr_r352_ls_fill_headers(struct acr_r352 *, struct list_head *);
  130. int acr_r352_ls_write_wpr(struct acr_r352 *, struct list_head *,
  131. struct nvkm_gpuobj *, u64);
  132. void acr_r352_fixup_hs_desc(struct acr_r352 *, struct nvkm_secboot *, void *);
  133. #endif