acr_r361.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_r352.h"
  23. #include <engine/falcon.h>
  24. /**
  25. * struct acr_r361_flcn_bl_desc - DMEM bootloader descriptor
  26. * @signature: 16B signature for secure code. 0s if no secure code
  27. * @ctx_dma: DMA context to be used by BL while loading code/data
  28. * @code_dma_base: 256B-aligned Physical FB Address where code is located
  29. * (falcon's $xcbase register)
  30. * @non_sec_code_off: offset from code_dma_base where the non-secure code is
  31. * located. The offset must be multiple of 256 to help perf
  32. * @non_sec_code_size: the size of the nonSecure code part.
  33. * @sec_code_off: offset from code_dma_base where the secure code is
  34. * located. The offset must be multiple of 256 to help perf
  35. * @sec_code_size: offset from code_dma_base where the secure code is
  36. * located. The offset must be multiple of 256 to help perf
  37. * @code_entry_point: code entry point which will be invoked by BL after
  38. * code is loaded.
  39. * @data_dma_base: 256B aligned Physical FB Address where data is located.
  40. * (falcon's $xdbase register)
  41. * @data_size: size of data block. Should be multiple of 256B
  42. *
  43. * Structure used by the bootloader to load the rest of the code. This has
  44. * to be filled by host and copied into DMEM at offset provided in the
  45. * hsflcn_bl_desc.bl_desc_dmem_load_off.
  46. */
  47. struct acr_r361_flcn_bl_desc {
  48. u32 reserved[4];
  49. u32 signature[4];
  50. u32 ctx_dma;
  51. struct flcn_u64 code_dma_base;
  52. u32 non_sec_code_off;
  53. u32 non_sec_code_size;
  54. u32 sec_code_off;
  55. u32 sec_code_size;
  56. u32 code_entry_point;
  57. struct flcn_u64 data_dma_base;
  58. u32 data_size;
  59. };
  60. static void
  61. acr_r361_generate_flcn_bl_desc(const struct nvkm_acr *acr,
  62. const struct ls_ucode_img *_img, u64 wpr_addr,
  63. void *_desc)
  64. {
  65. struct ls_ucode_img_r352 *img = ls_ucode_img_r352(_img);
  66. struct acr_r361_flcn_bl_desc *desc = _desc;
  67. const struct ls_ucode_img_desc *pdesc = &img->base.ucode_desc;
  68. u64 base, addr_code, addr_data;
  69. base = wpr_addr + img->lsb_header.ucode_off + pdesc->app_start_offset;
  70. addr_code = base + pdesc->app_resident_code_offset;
  71. addr_data = base + pdesc->app_resident_data_offset;
  72. desc->ctx_dma = FALCON_DMAIDX_UCODE;
  73. desc->code_dma_base = u64_to_flcn64(addr_code);
  74. desc->non_sec_code_off = pdesc->app_resident_code_offset;
  75. desc->non_sec_code_size = pdesc->app_resident_code_size;
  76. desc->code_entry_point = pdesc->app_imem_entry;
  77. desc->data_dma_base = u64_to_flcn64(addr_data);
  78. desc->data_size = pdesc->app_resident_data_size;
  79. }
  80. static void
  81. acr_r361_generate_hs_bl_desc(const struct hsf_load_header *hdr, void *_bl_desc,
  82. u64 offset)
  83. {
  84. struct acr_r361_flcn_bl_desc *bl_desc = _bl_desc;
  85. bl_desc->ctx_dma = FALCON_DMAIDX_VIRT;
  86. bl_desc->code_dma_base = u64_to_flcn64(offset);
  87. bl_desc->non_sec_code_off = hdr->non_sec_code_off;
  88. bl_desc->non_sec_code_size = hdr->non_sec_code_size;
  89. bl_desc->sec_code_off = hdr->app[0].sec_code_off;
  90. bl_desc->sec_code_size = hdr->app[0].sec_code_size;
  91. bl_desc->code_entry_point = 0;
  92. bl_desc->data_dma_base = u64_to_flcn64(offset + hdr->data_dma_base);
  93. bl_desc->data_size = hdr->data_size;
  94. }
  95. const struct acr_r352_ls_func
  96. acr_r361_ls_fecs_func = {
  97. .load = acr_ls_ucode_load_fecs,
  98. .generate_bl_desc = acr_r361_generate_flcn_bl_desc,
  99. .bl_desc_size = sizeof(struct acr_r361_flcn_bl_desc),
  100. };
  101. const struct acr_r352_ls_func
  102. acr_r361_ls_gpccs_func = {
  103. .load = acr_ls_ucode_load_gpccs,
  104. .generate_bl_desc = acr_r361_generate_flcn_bl_desc,
  105. .bl_desc_size = sizeof(struct acr_r361_flcn_bl_desc),
  106. /* GPCCS will be loaded using PRI */
  107. .lhdr_flags = LSF_FLAG_FORCE_PRIV_LOAD,
  108. };
  109. const struct acr_r352_func
  110. acr_r361_func = {
  111. .generate_hs_bl_desc = acr_r361_generate_hs_bl_desc,
  112. .hs_bl_desc_size = sizeof(struct acr_r361_flcn_bl_desc),
  113. .ls_ucode_img_load = acr_r352_ls_ucode_img_load,
  114. .ls_fill_headers = acr_r352_ls_fill_headers,
  115. .ls_write_wpr = acr_r352_ls_write_wpr,
  116. .ls_func = {
  117. [NVKM_SECBOOT_FALCON_FECS] = &acr_r361_ls_fecs_func,
  118. [NVKM_SECBOOT_FALCON_GPCCS] = &acr_r361_ls_gpccs_func,
  119. },
  120. };
  121. struct nvkm_acr *
  122. acr_r361_new(unsigned long managed_falcons)
  123. {
  124. return acr_r352_new_(&acr_r361_func, NVKM_SECBOOT_FALCON_PMU,
  125. managed_falcons);
  126. }