snvs.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2021 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef SNVS_H
  8. #define SNVS_H
  9. #ifndef __ASSEMBLER__
  10. #include <endian.h>
  11. #include <stdbool.h>
  12. #include <lib/mmio.h>
  13. struct snvs_regs {
  14. uint32_t reserved1;
  15. uint32_t hp_com; /* 0x04 SNVS_HP Command Register */
  16. uint32_t reserved2[3];
  17. uint32_t hp_stat; /* 0x14 SNVS_HP Status Register */
  18. };
  19. #ifdef NXP_SNVS_BE
  20. #define snvs_read32(a) bswap32(mmio_read_32((uintptr_t)(a)))
  21. #define snvs_write32(a, v) mmio_write_32((uintptr_t)(a), bswap32((v)))
  22. #elif defined(NXP_SNVS_LE)
  23. #define snvs_read32(a) mmio_read_32((uintptr_t)(a))
  24. #define snvs_write32(a, v) mmio_write_32((uintptr_t)(a), (v))
  25. #else
  26. #error Please define CCSR SNVS register endianness
  27. #endif
  28. void snvs_init(uintptr_t nxp_snvs_addr);
  29. uint32_t get_snvs_state(void);
  30. void transition_snvs_non_secure(void);
  31. void transition_snvs_soft_fail(void);
  32. uint32_t transition_snvs_trusted(void);
  33. uint32_t transition_snvs_secure(void);
  34. uint32_t snvs_read_lp_gpr_bit(uint32_t offset, uint32_t bit_pos);
  35. void snvs_write_lp_gpr_bit(uint32_t offset, uint32_t bit_pos, bool flag_val);
  36. void snvs_disable_zeroize_lp_gpr(void);
  37. #if defined(NXP_NV_SW_MAINT_LAST_EXEC_DATA) && defined(NXP_COINED_BB)
  38. uint32_t snvs_read_app_data(void);
  39. uint32_t snvs_read_app_data_bit(uint32_t bit_pos);
  40. void snvs_clear_app_data(void);
  41. void snvs_write_app_data_bit(uint32_t bit_pos);
  42. #endif
  43. #endif /* __ASSEMBLER__ */
  44. /* SSM_ST field in SNVS status reg */
  45. #define HPSTS_CHECK_SSM_ST 0x900 /* SNVS is in check state */
  46. #define HPSTS_NON_SECURE_SSM_ST 0xb00 /* SNVS is in non secure state */
  47. #define HPSTS_TRUST_SSM_ST 0xd00 /* SNVS is in trusted state */
  48. #define HPSTS_SECURE_SSM_ST 0xf00 /* SNVS is in secure state */
  49. #define HPSTS_SOFT_FAIL_SSM_ST 0x300 /* SNVS is in soft fail state */
  50. #define HPSTS_MASK_SSM_ST 0xf00 /* SSM_ST field mask in SNVS reg */
  51. /* SNVS register bits */
  52. #define HPCOM_SW_SV 0x100 /* Security Violation bit */
  53. #define HPCOM_SW_FSV 0x200 /* Fatal Security Violation bit */
  54. #define HPCOM_SSM_ST 0x1 /* SSM_ST field in SNVS command reg */
  55. #define HPCOM_SSM_ST_DIS 0x2 /* Disable Secure to Trusted State */
  56. #define HPCOM_SSM_SFNS_DIS 0x4 /* Disable Soft Fail to Non-Secure */
  57. #define NXP_LP_GPR0_OFFSET 0x90
  58. #define NXP_LPCR_OFFSET 0x38
  59. #define NXP_GPR_Z_DIS_BIT 24
  60. #ifdef NXP_COINED_BB
  61. #ifndef NXP_APP_DATA_LP_GPR_OFFSET
  62. #define NXP_APP_DATA_LP_GPR_OFFSET NXP_LP_GPR0_OFFSET
  63. #endif
  64. #define NXP_LPGPR_ZEROTH_BIT 0
  65. #endif /* NXP_COINED_BB */
  66. #endif /* SNVS_H */