gm20b.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 "priv.h"
  23. #include <core/gpuobj.h>
  24. /*
  25. * The BL header format used by GM20B's firmware is slightly different
  26. * from the one of GM200. Fix the differences here.
  27. */
  28. struct gm20b_flcn_bl_desc {
  29. u32 reserved[4];
  30. u32 signature[4];
  31. u32 ctx_dma;
  32. u32 code_dma_base;
  33. u32 non_sec_code_off;
  34. u32 non_sec_code_size;
  35. u32 sec_code_off;
  36. u32 sec_code_size;
  37. u32 code_entry_point;
  38. u32 data_dma_base;
  39. u32 data_size;
  40. };
  41. static int
  42. gm20b_secboot_prepare_blobs(struct gm200_secboot *gsb)
  43. {
  44. struct nvkm_subdev *subdev = &gsb->base.subdev;
  45. int acr_size;
  46. int ret;
  47. ret = gm20x_secboot_prepare_blobs(gsb);
  48. if (ret)
  49. return ret;
  50. acr_size = gsb->acr_load_blob->size;
  51. /*
  52. * On Tegra the WPR region is set by the bootloader. It is illegal for
  53. * the HS blob to be larger than this region.
  54. */
  55. if (acr_size > gsb->wpr_size) {
  56. nvkm_error(subdev, "WPR region too small for FW blob!\n");
  57. nvkm_error(subdev, "required: %dB\n", acr_size);
  58. nvkm_error(subdev, "WPR size: %dB\n", gsb->wpr_size);
  59. return -ENOSPC;
  60. }
  61. return 0;
  62. }
  63. /**
  64. * gm20b_secboot_fixup_bl_desc - adapt BL descriptor to format used by GM20B FW
  65. *
  66. * There is only a slight format difference (DMA addresses being 32-bits and
  67. * 256B-aligned) to address.
  68. */
  69. static void
  70. gm20b_secboot_fixup_bl_desc(const struct gm200_flcn_bl_desc *desc, void *ret)
  71. {
  72. struct gm20b_flcn_bl_desc *gdesc = ret;
  73. u64 addr;
  74. memcpy(gdesc->reserved, desc->reserved, sizeof(gdesc->reserved));
  75. memcpy(gdesc->signature, desc->signature, sizeof(gdesc->signature));
  76. gdesc->ctx_dma = desc->ctx_dma;
  77. addr = desc->code_dma_base.hi;
  78. addr <<= 32;
  79. addr |= desc->code_dma_base.lo;
  80. gdesc->code_dma_base = lower_32_bits(addr >> 8);
  81. gdesc->non_sec_code_off = desc->non_sec_code_off;
  82. gdesc->non_sec_code_size = desc->non_sec_code_size;
  83. gdesc->sec_code_off = desc->sec_code_off;
  84. gdesc->sec_code_size = desc->sec_code_size;
  85. gdesc->code_entry_point = desc->code_entry_point;
  86. addr = desc->data_dma_base.hi;
  87. addr <<= 32;
  88. addr |= desc->data_dma_base.lo;
  89. gdesc->data_dma_base = lower_32_bits(addr >> 8);
  90. gdesc->data_size = desc->data_size;
  91. }
  92. static void
  93. gm20b_secboot_fixup_hs_desc(struct gm200_secboot *gsb,
  94. struct hsflcn_acr_desc *desc)
  95. {
  96. desc->ucode_blob_base = gsb->ls_blob->addr;
  97. desc->ucode_blob_size = gsb->ls_blob->size;
  98. desc->wpr_offset = 0;
  99. }
  100. static const struct gm200_secboot_func
  101. gm20b_secboot_func = {
  102. .bl_desc_size = sizeof(struct gm20b_flcn_bl_desc),
  103. .fixup_bl_desc = gm20b_secboot_fixup_bl_desc,
  104. .fixup_hs_desc = gm20b_secboot_fixup_hs_desc,
  105. .prepare_blobs = gm20b_secboot_prepare_blobs,
  106. };
  107. #ifdef CONFIG_ARCH_TEGRA
  108. #define TEGRA_MC_BASE 0x70019000
  109. #define MC_SECURITY_CARVEOUT2_CFG0 0xc58
  110. #define MC_SECURITY_CARVEOUT2_BOM_0 0xc5c
  111. #define MC_SECURITY_CARVEOUT2_BOM_HI_0 0xc60
  112. #define MC_SECURITY_CARVEOUT2_SIZE_128K 0xc64
  113. #define TEGRA_MC_SECURITY_CARVEOUT_CFG_LOCKED (1 << 1)
  114. /**
  115. * sb_tegra_read_wpr() - read the WPR registers on Tegra
  116. *
  117. * On dGPU, we can manage the WPR region ourselves, but on Tegra the WPR region
  118. * is reserved from system memory by the bootloader and irreversibly locked.
  119. * This function reads the address and size of the pre-configured WPR region.
  120. */
  121. static int
  122. gm20b_tegra_read_wpr(struct gm200_secboot *gsb)
  123. {
  124. struct nvkm_secboot *sb = &gsb->base;
  125. void __iomem *mc;
  126. u32 cfg;
  127. mc = ioremap(TEGRA_MC_BASE, 0xd00);
  128. if (!mc) {
  129. nvkm_error(&sb->subdev, "Cannot map Tegra MC registers\n");
  130. return PTR_ERR(mc);
  131. }
  132. gsb->wpr_addr = ioread32_native(mc + MC_SECURITY_CARVEOUT2_BOM_0) |
  133. ((u64)ioread32_native(mc + MC_SECURITY_CARVEOUT2_BOM_HI_0) << 32);
  134. gsb->wpr_size = ioread32_native(mc + MC_SECURITY_CARVEOUT2_SIZE_128K)
  135. << 17;
  136. cfg = ioread32_native(mc + MC_SECURITY_CARVEOUT2_CFG0);
  137. iounmap(mc);
  138. /* Check that WPR settings are valid */
  139. if (gsb->wpr_size == 0) {
  140. nvkm_error(&sb->subdev, "WPR region is empty\n");
  141. return -EINVAL;
  142. }
  143. if (!(cfg & TEGRA_MC_SECURITY_CARVEOUT_CFG_LOCKED)) {
  144. nvkm_error(&sb->subdev, "WPR region not locked\n");
  145. return -EINVAL;
  146. }
  147. return 0;
  148. }
  149. #else
  150. static int
  151. gm20b_tegra_read_wpr(struct gm200_secboot *gsb)
  152. {
  153. nvkm_error(&gsb->base.subdev, "Tegra support not compiled in\n");
  154. return -EINVAL;
  155. }
  156. #endif
  157. static int
  158. gm20b_secboot_init(struct nvkm_secboot *sb)
  159. {
  160. struct gm200_secboot *gsb = gm200_secboot(sb);
  161. int ret;
  162. ret = gm20b_tegra_read_wpr(gsb);
  163. if (ret)
  164. return ret;
  165. return gm200_secboot_init(sb);
  166. }
  167. static const struct nvkm_secboot_func
  168. gm20b_secboot = {
  169. .dtor = gm200_secboot_dtor,
  170. .init = gm20b_secboot_init,
  171. .reset = gm200_secboot_reset,
  172. .start = gm200_secboot_start,
  173. .managed_falcons = BIT(NVKM_SECBOOT_FALCON_FECS),
  174. .boot_falcon = NVKM_SECBOOT_FALCON_PMU,
  175. };
  176. int
  177. gm20b_secboot_new(struct nvkm_device *device, int index,
  178. struct nvkm_secboot **psb)
  179. {
  180. int ret;
  181. struct gm200_secboot *gsb;
  182. gsb = kzalloc(sizeof(*gsb), GFP_KERNEL);
  183. if (!gsb) {
  184. psb = NULL;
  185. return -ENOMEM;
  186. }
  187. *psb = &gsb->base;
  188. ret = nvkm_secboot_ctor(&gm20b_secboot, device, index, &gsb->base);
  189. if (ret)
  190. return ret;
  191. gsb->func = &gm20b_secboot_func;
  192. return 0;
  193. }
  194. MODULE_FIRMWARE("nvidia/gm20b/acr/bl.bin");
  195. MODULE_FIRMWARE("nvidia/gm20b/acr/ucode_load.bin");
  196. MODULE_FIRMWARE("nvidia/gm20b/gr/fecs_bl.bin");
  197. MODULE_FIRMWARE("nvidia/gm20b/gr/fecs_inst.bin");
  198. MODULE_FIRMWARE("nvidia/gm20b/gr/fecs_data.bin");
  199. MODULE_FIRMWARE("nvidia/gm20b/gr/fecs_sig.bin");
  200. MODULE_FIRMWARE("nvidia/gm20b/gr/gpccs_inst.bin");
  201. MODULE_FIRMWARE("nvidia/gm20b/gr/gpccs_data.bin");
  202. MODULE_FIRMWARE("nvidia/gm20b/gr/sw_ctx.bin");
  203. MODULE_FIRMWARE("nvidia/gm20b/gr/sw_nonctx.bin");
  204. MODULE_FIRMWARE("nvidia/gm20b/gr/sw_bundle_init.bin");
  205. MODULE_FIRMWARE("nvidia/gm20b/gr/sw_method_init.bin");