intel-m10-bmc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Intel MAX 10 Board Management Controller chip.
  4. *
  5. * Copyright (C) 2018-2020 Intel Corporation, Inc.
  6. */
  7. #ifndef __MFD_INTEL_M10_BMC_H
  8. #define __MFD_INTEL_M10_BMC_H
  9. #include <linux/regmap.h>
  10. #define M10BMC_LEGACY_BUILD_VER 0x300468
  11. #define M10BMC_SYS_BASE 0x300800
  12. #define M10BMC_SYS_END 0x300fff
  13. #define M10BMC_FLASH_BASE 0x10000000
  14. #define M10BMC_FLASH_END 0x1fffffff
  15. #define M10BMC_MEM_END M10BMC_FLASH_END
  16. #define M10BMC_STAGING_BASE 0x18000000
  17. #define M10BMC_STAGING_SIZE 0x3800000
  18. /* Register offset of system registers */
  19. #define NIOS2_FW_VERSION 0x0
  20. #define M10BMC_MAC_LOW 0x10
  21. #define M10BMC_MAC_BYTE4 GENMASK(7, 0)
  22. #define M10BMC_MAC_BYTE3 GENMASK(15, 8)
  23. #define M10BMC_MAC_BYTE2 GENMASK(23, 16)
  24. #define M10BMC_MAC_BYTE1 GENMASK(31, 24)
  25. #define M10BMC_MAC_HIGH 0x14
  26. #define M10BMC_MAC_BYTE6 GENMASK(7, 0)
  27. #define M10BMC_MAC_BYTE5 GENMASK(15, 8)
  28. #define M10BMC_MAC_COUNT GENMASK(23, 16)
  29. #define M10BMC_TEST_REG 0x3c
  30. #define M10BMC_BUILD_VER 0x68
  31. #define M10BMC_VER_MAJOR_MSK GENMASK(23, 16)
  32. #define M10BMC_VER_PCB_INFO_MSK GENMASK(31, 24)
  33. #define M10BMC_VER_LEGACY_INVALID 0xffffffff
  34. /* Secure update doorbell register, in system register region */
  35. #define M10BMC_DOORBELL 0x400
  36. /* Authorization Result register, in system register region */
  37. #define M10BMC_AUTH_RESULT 0x404
  38. /* Doorbell register fields */
  39. #define DRBL_RSU_REQUEST BIT(0)
  40. #define DRBL_RSU_PROGRESS GENMASK(7, 4)
  41. #define DRBL_HOST_STATUS GENMASK(11, 8)
  42. #define DRBL_RSU_STATUS GENMASK(23, 16)
  43. #define DRBL_PKVL_EEPROM_LOAD_SEC BIT(24)
  44. #define DRBL_PKVL1_POLL_EN BIT(25)
  45. #define DRBL_PKVL2_POLL_EN BIT(26)
  46. #define DRBL_CONFIG_SEL BIT(28)
  47. #define DRBL_REBOOT_REQ BIT(29)
  48. #define DRBL_REBOOT_DISABLED BIT(30)
  49. /* Progress states */
  50. #define RSU_PROG_IDLE 0x0
  51. #define RSU_PROG_PREPARE 0x1
  52. #define RSU_PROG_READY 0x3
  53. #define RSU_PROG_AUTHENTICATING 0x4
  54. #define RSU_PROG_COPYING 0x5
  55. #define RSU_PROG_UPDATE_CANCEL 0x6
  56. #define RSU_PROG_PROGRAM_KEY_HASH 0x7
  57. #define RSU_PROG_RSU_DONE 0x8
  58. #define RSU_PROG_PKVL_PROM_DONE 0x9
  59. /* Device and error states */
  60. #define RSU_STAT_NORMAL 0x0
  61. #define RSU_STAT_TIMEOUT 0x1
  62. #define RSU_STAT_AUTH_FAIL 0x2
  63. #define RSU_STAT_COPY_FAIL 0x3
  64. #define RSU_STAT_FATAL 0x4
  65. #define RSU_STAT_PKVL_REJECT 0x5
  66. #define RSU_STAT_NON_INC 0x6
  67. #define RSU_STAT_ERASE_FAIL 0x7
  68. #define RSU_STAT_WEAROUT 0x8
  69. #define RSU_STAT_NIOS_OK 0x80
  70. #define RSU_STAT_USER_OK 0x81
  71. #define RSU_STAT_FACTORY_OK 0x82
  72. #define RSU_STAT_USER_FAIL 0x83
  73. #define RSU_STAT_FACTORY_FAIL 0x84
  74. #define RSU_STAT_NIOS_FLASH_ERR 0x85
  75. #define RSU_STAT_FPGA_FLASH_ERR 0x86
  76. #define HOST_STATUS_IDLE 0x0
  77. #define HOST_STATUS_WRITE_DONE 0x1
  78. #define HOST_STATUS_ABORT_RSU 0x2
  79. #define rsu_prog(doorbell) FIELD_GET(DRBL_RSU_PROGRESS, doorbell)
  80. #define rsu_stat(doorbell) FIELD_GET(DRBL_RSU_STATUS, doorbell)
  81. /* interval 100ms and timeout 5s */
  82. #define NIOS_HANDSHAKE_INTERVAL_US (100 * 1000)
  83. #define NIOS_HANDSHAKE_TIMEOUT_US (5 * 1000 * 1000)
  84. /* RSU PREP Timeout (2 minutes) to erase flash staging area */
  85. #define RSU_PREP_INTERVAL_MS 100
  86. #define RSU_PREP_TIMEOUT_MS (2 * 60 * 1000)
  87. /* RSU Complete Timeout (40 minutes) for full flash update */
  88. #define RSU_COMPLETE_INTERVAL_MS 1000
  89. #define RSU_COMPLETE_TIMEOUT_MS (40 * 60 * 1000)
  90. /* Addresses for security related data in FLASH */
  91. #define BMC_REH_ADDR 0x17ffc004
  92. #define BMC_PROG_ADDR 0x17ffc000
  93. #define BMC_PROG_MAGIC 0x5746
  94. #define SR_REH_ADDR 0x17ffd004
  95. #define SR_PROG_ADDR 0x17ffd000
  96. #define SR_PROG_MAGIC 0x5253
  97. #define PR_REH_ADDR 0x17ffe004
  98. #define PR_PROG_ADDR 0x17ffe000
  99. #define PR_PROG_MAGIC 0x5250
  100. /* Address of 4KB inverted bit vector containing staging area FLASH count */
  101. #define STAGING_FLASH_COUNT 0x17ffb000
  102. /**
  103. * struct intel_m10bmc - Intel MAX 10 BMC parent driver data structure
  104. * @dev: this device
  105. * @regmap: the regmap used to access registers by m10bmc itself
  106. */
  107. struct intel_m10bmc {
  108. struct device *dev;
  109. struct regmap *regmap;
  110. };
  111. /*
  112. * register access helper functions.
  113. *
  114. * m10bmc_raw_read - read m10bmc register per addr
  115. * m10bmc_sys_read - read m10bmc system register per offset
  116. */
  117. static inline int
  118. m10bmc_raw_read(struct intel_m10bmc *m10bmc, unsigned int addr,
  119. unsigned int *val)
  120. {
  121. int ret;
  122. ret = regmap_read(m10bmc->regmap, addr, val);
  123. if (ret)
  124. dev_err(m10bmc->dev, "fail to read raw reg %x: %d\n",
  125. addr, ret);
  126. return ret;
  127. }
  128. /*
  129. * The base of the system registers could be configured by HW developers, and
  130. * in HW SPEC, the base is not added to the addresses of the system registers.
  131. *
  132. * This macro helps to simplify the accessing of the system registers. And if
  133. * the base is reconfigured in HW, SW developers could simply change the
  134. * M10BMC_SYS_BASE accordingly.
  135. */
  136. #define m10bmc_sys_read(m10bmc, offset, val) \
  137. m10bmc_raw_read(m10bmc, M10BMC_SYS_BASE + (offset), val)
  138. #endif /* __MFD_INTEL_M10_BMC_H */