sec.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright 2014 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <libfdt.h>
  8. #include <fdt_support.h>
  9. #if CONFIG_SYS_FSL_SEC_COMPAT == 2 || CONFIG_SYS_FSL_SEC_COMPAT >= 4
  10. #include <fsl_sec.h>
  11. #endif
  12. /*
  13. * update crypto node properties to a specified revision of the SEC
  14. * called with sec_rev == 0 if not on an E processor
  15. */
  16. #if CONFIG_SYS_FSL_SEC_COMPAT == 2 /* SEC 2.x/3.x */
  17. void fdt_fixup_crypto_node(void *blob, int sec_rev)
  18. {
  19. static const struct sec_rev_prop {
  20. u32 sec_rev;
  21. u32 num_channels;
  22. u32 channel_fifo_len;
  23. u32 exec_units_mask;
  24. u32 descriptor_types_mask;
  25. } sec_rev_prop_list[] = {
  26. { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */
  27. { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */
  28. { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */
  29. { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */
  30. { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */
  31. { 0x0301, 4, 24, 0xbfe, 0x03ab0ebf }, /* SEC 3.1 */
  32. { 0x0303, 4, 24, 0x97c, 0x03a30abf }, /* SEC 3.3 */
  33. };
  34. static char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) *
  35. sizeof("fsl,secX.Y")];
  36. int crypto_node, sec_idx, err;
  37. char *p;
  38. u32 val;
  39. /* locate crypto node based on lowest common compatible */
  40. crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0");
  41. if (crypto_node == -FDT_ERR_NOTFOUND)
  42. return;
  43. /* delete it if not on an E-processor */
  44. if (crypto_node > 0 && !sec_rev) {
  45. fdt_del_node(blob, crypto_node);
  46. return;
  47. }
  48. /* else we got called for possible uprev */
  49. for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++)
  50. if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev)
  51. break;
  52. if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) {
  53. puts("warning: unknown SEC revision number\n");
  54. return;
  55. }
  56. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels);
  57. err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4);
  58. if (err < 0)
  59. printf("WARNING: could not set crypto property: %s\n",
  60. fdt_strerror(err));
  61. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask);
  62. err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask",
  63. &val, 4);
  64. if (err < 0)
  65. printf("WARNING: could not set crypto property: %s\n",
  66. fdt_strerror(err));
  67. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask);
  68. err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4);
  69. if (err < 0)
  70. printf("WARNING: could not set crypto property: %s\n",
  71. fdt_strerror(err));
  72. val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len);
  73. err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4);
  74. if (err < 0)
  75. printf("WARNING: could not set crypto property: %s\n",
  76. fdt_strerror(err));
  77. val = 0;
  78. while (sec_idx >= 0) {
  79. p = compat_strlist + val;
  80. val += sprintf(p, "fsl,sec%d.%d",
  81. (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
  82. sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
  83. sec_idx--;
  84. }
  85. err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist,
  86. val);
  87. if (err < 0)
  88. printf("WARNING: could not set crypto property: %s\n",
  89. fdt_strerror(err));
  90. }
  91. #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
  92. static u8 caam_get_era(void)
  93. {
  94. static const struct {
  95. u16 ip_id;
  96. u8 maj_rev;
  97. u8 era;
  98. } caam_eras[] = {
  99. {0x0A10, 1, 1},
  100. {0x0A10, 2, 2},
  101. {0x0A12, 1, 3},
  102. {0x0A14, 1, 3},
  103. {0x0A14, 2, 4},
  104. {0x0A16, 1, 4},
  105. {0x0A10, 3, 4},
  106. {0x0A11, 1, 4},
  107. {0x0A18, 1, 4},
  108. {0x0A11, 2, 5},
  109. {0x0A12, 2, 5},
  110. {0x0A13, 1, 5},
  111. {0x0A1C, 1, 5}
  112. };
  113. ccsr_sec_t __iomem *sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
  114. u32 secvid_ms = sec_in32(&sec->secvid_ms);
  115. u32 ccbvid = sec_in32(&sec->ccbvid);
  116. u16 ip_id = (secvid_ms & SEC_SECVID_MS_IPID_MASK) >>
  117. SEC_SECVID_MS_IPID_SHIFT;
  118. u8 maj_rev = (secvid_ms & SEC_SECVID_MS_MAJ_REV_MASK) >>
  119. SEC_SECVID_MS_MAJ_REV_SHIFT;
  120. u8 era = (ccbvid & SEC_CCBVID_ERA_MASK) >> SEC_CCBVID_ERA_SHIFT;
  121. int i;
  122. if (era) /* This is '0' prior to CAAM ERA-6 */
  123. return era;
  124. for (i = 0; i < ARRAY_SIZE(caam_eras); i++)
  125. if (caam_eras[i].ip_id == ip_id &&
  126. caam_eras[i].maj_rev == maj_rev)
  127. return caam_eras[i].era;
  128. return 0;
  129. }
  130. static void fdt_fixup_crypto_era(void *blob, u32 era)
  131. {
  132. int err;
  133. int crypto_node;
  134. crypto_node = fdt_path_offset(blob, "crypto");
  135. if (crypto_node < 0) {
  136. printf("WARNING: Missing crypto node\n");
  137. return;
  138. }
  139. err = fdt_setprop(blob, crypto_node, "fsl,sec-era", &era,
  140. sizeof(era));
  141. if (err < 0) {
  142. printf("ERROR: could not set fsl,sec-era property: %s\n",
  143. fdt_strerror(err));
  144. }
  145. }
  146. void fdt_fixup_crypto_node(void *blob, int sec_rev)
  147. {
  148. u8 era;
  149. if (!sec_rev) {
  150. fdt_del_node_and_alias(blob, "crypto");
  151. return;
  152. }
  153. /* Add SEC ERA information in compatible */
  154. era = caam_get_era();
  155. if (era) {
  156. fdt_fixup_crypto_era(blob, era);
  157. } else {
  158. printf("WARNING: Unable to get ERA for CAAM rev: %d\n",
  159. sec_rev);
  160. }
  161. }
  162. #endif