sec.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. err = fdt_setprop_u32(blob, crypto_node, "fsl,num-channels",
  57. sec_rev_prop_list[sec_idx].num_channels);
  58. if (err < 0)
  59. printf("WARNING: could not set crypto property: %s\n",
  60. fdt_strerror(err));
  61. err = fdt_setprop_u32(blob, crypto_node, "fsl,descriptor-types-mask",
  62. sec_rev_prop_list[sec_idx].descriptor_types_mask);
  63. if (err < 0)
  64. printf("WARNING: could not set crypto property: %s\n",
  65. fdt_strerror(err));
  66. err = fdt_setprop_u32(blob, crypto_node, "fsl,exec-units-mask",
  67. sec_rev_prop_list[sec_idx].exec_units_mask);
  68. if (err < 0)
  69. printf("WARNING: could not set crypto property: %s\n",
  70. fdt_strerror(err));
  71. err = fdt_setprop_u32(blob, crypto_node, "fsl,channel-fifo-len",
  72. sec_rev_prop_list[sec_idx].channel_fifo_len);
  73. if (err < 0)
  74. printf("WARNING: could not set crypto property: %s\n",
  75. fdt_strerror(err));
  76. val = 0;
  77. while (sec_idx >= 0) {
  78. p = compat_strlist + val;
  79. val += sprintf(p, "fsl,sec%d.%d",
  80. (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8,
  81. sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1;
  82. sec_idx--;
  83. }
  84. err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist,
  85. val);
  86. if (err < 0)
  87. printf("WARNING: could not set crypto property: %s\n",
  88. fdt_strerror(err));
  89. }
  90. #elif CONFIG_SYS_FSL_SEC_COMPAT >= 4 /* SEC4 */
  91. static u8 caam_get_era(void)
  92. {
  93. static const struct {
  94. u16 ip_id;
  95. u8 maj_rev;
  96. u8 era;
  97. } caam_eras[] = {
  98. {0x0A10, 1, 1},
  99. {0x0A10, 2, 2},
  100. {0x0A12, 1, 3},
  101. {0x0A14, 1, 3},
  102. {0x0A14, 2, 4},
  103. {0x0A16, 1, 4},
  104. {0x0A10, 3, 4},
  105. {0x0A11, 1, 4},
  106. {0x0A18, 1, 4},
  107. {0x0A11, 2, 5},
  108. {0x0A12, 2, 5},
  109. {0x0A13, 1, 5},
  110. {0x0A1C, 1, 5}
  111. };
  112. ccsr_sec_t __iomem *sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
  113. u32 secvid_ms = sec_in32(&sec->secvid_ms);
  114. u32 ccbvid = sec_in32(&sec->ccbvid);
  115. u16 ip_id = (secvid_ms & SEC_SECVID_MS_IPID_MASK) >>
  116. SEC_SECVID_MS_IPID_SHIFT;
  117. u8 maj_rev = (secvid_ms & SEC_SECVID_MS_MAJ_REV_MASK) >>
  118. SEC_SECVID_MS_MAJ_REV_SHIFT;
  119. u8 era = (ccbvid & SEC_CCBVID_ERA_MASK) >> SEC_CCBVID_ERA_SHIFT;
  120. int i;
  121. if (era) /* This is '0' prior to CAAM ERA-6 */
  122. return era;
  123. for (i = 0; i < ARRAY_SIZE(caam_eras); i++)
  124. if (caam_eras[i].ip_id == ip_id &&
  125. caam_eras[i].maj_rev == maj_rev)
  126. return caam_eras[i].era;
  127. return 0;
  128. }
  129. static void fdt_fixup_crypto_era(void *blob, u32 era)
  130. {
  131. int err;
  132. int crypto_node;
  133. crypto_node = fdt_path_offset(blob, "crypto");
  134. if (crypto_node < 0) {
  135. printf("WARNING: Missing crypto node\n");
  136. return;
  137. }
  138. err = fdt_setprop_u32(blob, crypto_node, "fsl,sec-era", era);
  139. if (err < 0) {
  140. printf("ERROR: could not set fsl,sec-era property: %s\n",
  141. fdt_strerror(err));
  142. }
  143. }
  144. void fdt_fixup_crypto_node(void *blob, int sec_rev)
  145. {
  146. u8 era;
  147. if (!sec_rev) {
  148. fdt_del_node_and_alias(blob, "crypto");
  149. return;
  150. }
  151. /* Add SEC ERA information in compatible */
  152. era = caam_get_era();
  153. if (era) {
  154. fdt_fixup_crypto_era(blob, era);
  155. } else {
  156. printf("WARNING: Unable to get ERA for CAAM rev: %d\n",
  157. sec_rev);
  158. }
  159. }
  160. #endif