imx8m_caam.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2019-2022 NXP. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <lib/mmio.h>
  8. #include <imx8m_caam.h>
  9. #define HAB_JR0_DID U(0x8011)
  10. void imx8m_caam_init(void)
  11. {
  12. uint32_t sm_cmd;
  13. /* Dealloc part 0 and 2 with current DID */
  14. sm_cmd = (0 << SMC_PART_SHIFT | SMC_CMD_DEALLOC_PART);
  15. mmio_write_32(SM_CMD, sm_cmd);
  16. sm_cmd = (2 << SMC_PART_SHIFT | SMC_CMD_DEALLOC_PART);
  17. mmio_write_32(SM_CMD, sm_cmd);
  18. /* config CAAM JRaMID set MID to Cortex A */
  19. if (mmio_read_32(CAAM_JR0MID) == HAB_JR0_DID) {
  20. NOTICE("Do not release JR0 to NS as it can be used by HAB\n");
  21. } else {
  22. mmio_write_32(CAAM_JR0MID, CAAM_NS_MID);
  23. }
  24. mmio_write_32(CAAM_JR1MID, CAAM_NS_MID);
  25. mmio_write_32(CAAM_JR2MID, CAAM_NS_MID);
  26. /* Alloc partition 0 writing SMPO and SMAGs */
  27. mmio_write_32(SM_P0_PERM, 0xff);
  28. mmio_write_32(SM_P0_SMAG2, 0xffffffff);
  29. mmio_write_32(SM_P0_SMAG1, 0xffffffff);
  30. /* Allocate page 0 and 1 to partition 0 with DID set */
  31. sm_cmd = (0 << SMC_PAGE_SHIFT | 0 << SMC_PART_SHIFT |
  32. SMC_CMD_ALLOC_PAGE);
  33. mmio_write_32(SM_CMD, sm_cmd);
  34. sm_cmd = (1 << SMC_PAGE_SHIFT | 0 << SMC_PART_SHIFT |
  35. SMC_CMD_ALLOC_PAGE);
  36. mmio_write_32(SM_CMD, sm_cmd);
  37. }