acr_r361.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #include "acr_r361.h"
  23. #include <engine/falcon.h>
  24. #include <core/msgqueue.h>
  25. #include <subdev/pmu.h>
  26. #include <engine/sec2.h>
  27. static void
  28. acr_r361_generate_flcn_bl_desc(const struct nvkm_acr *acr,
  29. const struct ls_ucode_img *img, u64 wpr_addr,
  30. void *_desc)
  31. {
  32. struct acr_r361_flcn_bl_desc *desc = _desc;
  33. const struct ls_ucode_img_desc *pdesc = &img->ucode_desc;
  34. u64 base, addr_code, addr_data;
  35. base = wpr_addr + img->ucode_off + pdesc->app_start_offset;
  36. addr_code = base + pdesc->app_resident_code_offset;
  37. addr_data = base + pdesc->app_resident_data_offset;
  38. desc->ctx_dma = FALCON_DMAIDX_UCODE;
  39. desc->code_dma_base = u64_to_flcn64(addr_code);
  40. desc->non_sec_code_off = pdesc->app_resident_code_offset;
  41. desc->non_sec_code_size = pdesc->app_resident_code_size;
  42. desc->code_entry_point = pdesc->app_imem_entry;
  43. desc->data_dma_base = u64_to_flcn64(addr_data);
  44. desc->data_size = pdesc->app_resident_data_size;
  45. }
  46. void
  47. acr_r361_generate_hs_bl_desc(const struct hsf_load_header *hdr, void *_bl_desc,
  48. u64 offset)
  49. {
  50. struct acr_r361_flcn_bl_desc *bl_desc = _bl_desc;
  51. bl_desc->ctx_dma = FALCON_DMAIDX_VIRT;
  52. bl_desc->code_dma_base = u64_to_flcn64(offset);
  53. bl_desc->non_sec_code_off = hdr->non_sec_code_off;
  54. bl_desc->non_sec_code_size = hdr->non_sec_code_size;
  55. bl_desc->sec_code_off = hsf_load_header_app_off(hdr, 0);
  56. bl_desc->sec_code_size = hsf_load_header_app_size(hdr, 0);
  57. bl_desc->code_entry_point = 0;
  58. bl_desc->data_dma_base = u64_to_flcn64(offset + hdr->data_dma_base);
  59. bl_desc->data_size = hdr->data_size;
  60. }
  61. const struct acr_r352_ls_func
  62. acr_r361_ls_fecs_func = {
  63. .load = acr_ls_ucode_load_fecs,
  64. .generate_bl_desc = acr_r361_generate_flcn_bl_desc,
  65. .bl_desc_size = sizeof(struct acr_r361_flcn_bl_desc),
  66. };
  67. const struct acr_r352_ls_func
  68. acr_r361_ls_gpccs_func = {
  69. .load = acr_ls_ucode_load_gpccs,
  70. .generate_bl_desc = acr_r361_generate_flcn_bl_desc,
  71. .bl_desc_size = sizeof(struct acr_r361_flcn_bl_desc),
  72. /* GPCCS will be loaded using PRI */
  73. .lhdr_flags = LSF_FLAG_FORCE_PRIV_LOAD,
  74. };
  75. struct acr_r361_pmu_bl_desc {
  76. u32 reserved;
  77. u32 dma_idx;
  78. struct flcn_u64 code_dma_base;
  79. u32 total_code_size;
  80. u32 code_size_to_load;
  81. u32 code_entry_point;
  82. struct flcn_u64 data_dma_base;
  83. u32 data_size;
  84. struct flcn_u64 overlay_dma_base;
  85. u32 argc;
  86. u32 argv;
  87. };
  88. static void
  89. acr_r361_generate_pmu_bl_desc(const struct nvkm_acr *acr,
  90. const struct ls_ucode_img *img, u64 wpr_addr,
  91. void *_desc)
  92. {
  93. const struct ls_ucode_img_desc *pdesc = &img->ucode_desc;
  94. const struct nvkm_pmu *pmu = acr->subdev->device->pmu;
  95. struct acr_r361_pmu_bl_desc *desc = _desc;
  96. u64 base, addr_code, addr_data;
  97. u32 addr_args;
  98. base = wpr_addr + img->ucode_off + pdesc->app_start_offset;
  99. addr_code = base + pdesc->app_resident_code_offset;
  100. addr_data = base + pdesc->app_resident_data_offset;
  101. addr_args = pmu->falcon->data.limit;
  102. addr_args -= NVKM_MSGQUEUE_CMDLINE_SIZE;
  103. desc->dma_idx = FALCON_DMAIDX_UCODE;
  104. desc->code_dma_base = u64_to_flcn64(addr_code);
  105. desc->total_code_size = pdesc->app_size;
  106. desc->code_size_to_load = pdesc->app_resident_code_size;
  107. desc->code_entry_point = pdesc->app_imem_entry;
  108. desc->data_dma_base = u64_to_flcn64(addr_data);
  109. desc->data_size = pdesc->app_resident_data_size;
  110. desc->overlay_dma_base = u64_to_flcn64(addr_code);
  111. desc->argc = 1;
  112. desc->argv = addr_args;
  113. }
  114. const struct acr_r352_ls_func
  115. acr_r361_ls_pmu_func = {
  116. .load = acr_ls_ucode_load_pmu,
  117. .generate_bl_desc = acr_r361_generate_pmu_bl_desc,
  118. .bl_desc_size = sizeof(struct acr_r361_pmu_bl_desc),
  119. .post_run = acr_ls_pmu_post_run,
  120. };
  121. static void
  122. acr_r361_generate_sec2_bl_desc(const struct nvkm_acr *acr,
  123. const struct ls_ucode_img *img, u64 wpr_addr,
  124. void *_desc)
  125. {
  126. const struct ls_ucode_img_desc *pdesc = &img->ucode_desc;
  127. const struct nvkm_sec2 *sec = acr->subdev->device->sec2;
  128. struct acr_r361_pmu_bl_desc *desc = _desc;
  129. u64 base, addr_code, addr_data;
  130. u32 addr_args;
  131. base = wpr_addr + img->ucode_off + pdesc->app_start_offset;
  132. /* For some reason we should not add app_resident_code_offset here */
  133. addr_code = base;
  134. addr_data = base + pdesc->app_resident_data_offset;
  135. addr_args = sec->falcon->data.limit;
  136. addr_args -= NVKM_MSGQUEUE_CMDLINE_SIZE;
  137. desc->dma_idx = FALCON_SEC2_DMAIDX_UCODE;
  138. desc->code_dma_base = u64_to_flcn64(addr_code);
  139. desc->total_code_size = pdesc->app_size;
  140. desc->code_size_to_load = pdesc->app_resident_code_size;
  141. desc->code_entry_point = pdesc->app_imem_entry;
  142. desc->data_dma_base = u64_to_flcn64(addr_data);
  143. desc->data_size = pdesc->app_resident_data_size;
  144. desc->overlay_dma_base = u64_to_flcn64(addr_code);
  145. desc->argc = 1;
  146. /* args are stored at the beginning of EMEM */
  147. desc->argv = 0x01000000;
  148. }
  149. const struct acr_r352_ls_func
  150. acr_r361_ls_sec2_func = {
  151. .load = acr_ls_ucode_load_sec2,
  152. .generate_bl_desc = acr_r361_generate_sec2_bl_desc,
  153. .bl_desc_size = sizeof(struct acr_r361_pmu_bl_desc),
  154. .post_run = acr_ls_sec2_post_run,
  155. };
  156. const struct acr_r352_func
  157. acr_r361_func = {
  158. .fixup_hs_desc = acr_r352_fixup_hs_desc,
  159. .generate_hs_bl_desc = acr_r361_generate_hs_bl_desc,
  160. .hs_bl_desc_size = sizeof(struct acr_r361_flcn_bl_desc),
  161. .ls_ucode_img_load = acr_r352_ls_ucode_img_load,
  162. .ls_fill_headers = acr_r352_ls_fill_headers,
  163. .ls_write_wpr = acr_r352_ls_write_wpr,
  164. .ls_func = {
  165. [NVKM_SECBOOT_FALCON_FECS] = &acr_r361_ls_fecs_func,
  166. [NVKM_SECBOOT_FALCON_GPCCS] = &acr_r361_ls_gpccs_func,
  167. [NVKM_SECBOOT_FALCON_PMU] = &acr_r361_ls_pmu_func,
  168. [NVKM_SECBOOT_FALCON_SEC2] = &acr_r361_ls_sec2_func,
  169. },
  170. };
  171. struct nvkm_acr *
  172. acr_r361_new(unsigned long managed_falcons)
  173. {
  174. return acr_r352_new_(&acr_r361_func, NVKM_SECBOOT_FALCON_PMU,
  175. managed_falcons);
  176. }