acr_r375.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) 2017, 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_r367.h"
  23. #include <engine/falcon.h>
  24. #include <core/msgqueue.h>
  25. #include <subdev/pmu.h>
  26. /*
  27. * r375 ACR: similar to r367, but with a unified bootloader descriptor
  28. * structure for GR and PMU falcons.
  29. */
  30. /* Same as acr_r361_flcn_bl_desc, plus argc/argv */
  31. struct acr_r375_flcn_bl_desc {
  32. u32 reserved[4];
  33. u32 signature[4];
  34. u32 ctx_dma;
  35. struct flcn_u64 code_dma_base;
  36. u32 non_sec_code_off;
  37. u32 non_sec_code_size;
  38. u32 sec_code_off;
  39. u32 sec_code_size;
  40. u32 code_entry_point;
  41. struct flcn_u64 data_dma_base;
  42. u32 data_size;
  43. u32 argc;
  44. u32 argv;
  45. };
  46. static void
  47. acr_r375_generate_flcn_bl_desc(const struct nvkm_acr *acr,
  48. const struct ls_ucode_img *img, u64 wpr_addr,
  49. void *_desc)
  50. {
  51. struct acr_r375_flcn_bl_desc *desc = _desc;
  52. const struct ls_ucode_img_desc *pdesc = &img->ucode_desc;
  53. u64 base, addr_code, addr_data;
  54. base = wpr_addr + img->ucode_off + pdesc->app_start_offset;
  55. addr_code = base + pdesc->app_resident_code_offset;
  56. addr_data = base + pdesc->app_resident_data_offset;
  57. desc->ctx_dma = FALCON_DMAIDX_UCODE;
  58. desc->code_dma_base = u64_to_flcn64(addr_code);
  59. desc->non_sec_code_off = pdesc->app_resident_code_offset;
  60. desc->non_sec_code_size = pdesc->app_resident_code_size;
  61. desc->code_entry_point = pdesc->app_imem_entry;
  62. desc->data_dma_base = u64_to_flcn64(addr_data);
  63. desc->data_size = pdesc->app_resident_data_size;
  64. }
  65. static void
  66. acr_r375_generate_hs_bl_desc(const struct hsf_load_header *hdr, void *_bl_desc,
  67. u64 offset)
  68. {
  69. struct acr_r375_flcn_bl_desc *bl_desc = _bl_desc;
  70. bl_desc->ctx_dma = FALCON_DMAIDX_VIRT;
  71. bl_desc->non_sec_code_off = hdr->non_sec_code_off;
  72. bl_desc->non_sec_code_size = hdr->non_sec_code_size;
  73. bl_desc->sec_code_off = hsf_load_header_app_off(hdr, 0);
  74. bl_desc->sec_code_size = hsf_load_header_app_size(hdr, 0);
  75. bl_desc->code_entry_point = 0;
  76. bl_desc->code_dma_base = u64_to_flcn64(offset);
  77. bl_desc->data_dma_base = u64_to_flcn64(offset + hdr->data_dma_base);
  78. bl_desc->data_size = hdr->data_size;
  79. }
  80. const struct acr_r352_ls_func
  81. acr_r375_ls_fecs_func = {
  82. .load = acr_ls_ucode_load_fecs,
  83. .generate_bl_desc = acr_r375_generate_flcn_bl_desc,
  84. .bl_desc_size = sizeof(struct acr_r375_flcn_bl_desc),
  85. };
  86. const struct acr_r352_ls_func
  87. acr_r375_ls_gpccs_func = {
  88. .load = acr_ls_ucode_load_gpccs,
  89. .generate_bl_desc = acr_r375_generate_flcn_bl_desc,
  90. .bl_desc_size = sizeof(struct acr_r375_flcn_bl_desc),
  91. /* GPCCS will be loaded using PRI */
  92. .lhdr_flags = LSF_FLAG_FORCE_PRIV_LOAD,
  93. };
  94. static void
  95. acr_r375_generate_pmu_bl_desc(const struct nvkm_acr *acr,
  96. const struct ls_ucode_img *img, u64 wpr_addr,
  97. void *_desc)
  98. {
  99. const struct ls_ucode_img_desc *pdesc = &img->ucode_desc;
  100. const struct nvkm_pmu *pmu = acr->subdev->device->pmu;
  101. struct acr_r375_flcn_bl_desc *desc = _desc;
  102. u64 base, addr_code, addr_data;
  103. u32 addr_args;
  104. base = wpr_addr + img->ucode_off + pdesc->app_start_offset;
  105. addr_code = base + pdesc->app_resident_code_offset;
  106. addr_data = base + pdesc->app_resident_data_offset;
  107. addr_args = pmu->falcon->data.limit;
  108. addr_args -= NVKM_MSGQUEUE_CMDLINE_SIZE;
  109. desc->ctx_dma = FALCON_DMAIDX_UCODE;
  110. desc->code_dma_base = u64_to_flcn64(addr_code);
  111. desc->non_sec_code_off = pdesc->app_resident_code_offset;
  112. desc->non_sec_code_size = pdesc->app_resident_code_size;
  113. desc->code_entry_point = pdesc->app_imem_entry;
  114. desc->data_dma_base = u64_to_flcn64(addr_data);
  115. desc->data_size = pdesc->app_resident_data_size;
  116. desc->argc = 1;
  117. desc->argv = addr_args;
  118. }
  119. const struct acr_r352_ls_func
  120. acr_r375_ls_pmu_func = {
  121. .load = acr_ls_ucode_load_pmu,
  122. .generate_bl_desc = acr_r375_generate_pmu_bl_desc,
  123. .bl_desc_size = sizeof(struct acr_r375_flcn_bl_desc),
  124. .post_run = acr_ls_pmu_post_run,
  125. };
  126. const struct acr_r352_func
  127. acr_r375_func = {
  128. .fixup_hs_desc = acr_r367_fixup_hs_desc,
  129. .generate_hs_bl_desc = acr_r375_generate_hs_bl_desc,
  130. .hs_bl_desc_size = sizeof(struct acr_r375_flcn_bl_desc),
  131. .shadow_blob = true,
  132. .ls_ucode_img_load = acr_r367_ls_ucode_img_load,
  133. .ls_fill_headers = acr_r367_ls_fill_headers,
  134. .ls_write_wpr = acr_r367_ls_write_wpr,
  135. .ls_func = {
  136. [NVKM_SECBOOT_FALCON_FECS] = &acr_r375_ls_fecs_func,
  137. [NVKM_SECBOOT_FALCON_GPCCS] = &acr_r375_ls_gpccs_func,
  138. [NVKM_SECBOOT_FALCON_PMU] = &acr_r375_ls_pmu_func,
  139. },
  140. };
  141. struct nvkm_acr *
  142. acr_r375_new(enum nvkm_secboot_falcon boot_falcon,
  143. unsigned long managed_falcons)
  144. {
  145. return acr_r352_new_(&acr_r375_func, boot_falcon, managed_falcons);
  146. }