sm.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. *
  6. * Secure monitor calls.
  7. */
  8. #include <common.h>
  9. #include <asm/arch/gxbb.h>
  10. #include <linux/kernel.h>
  11. #define FN_GET_SHARE_MEM_INPUT_BASE 0x82000020
  12. #define FN_GET_SHARE_MEM_OUTPUT_BASE 0x82000021
  13. #define FN_EFUSE_READ 0x82000030
  14. #define FN_EFUSE_WRITE 0x82000031
  15. static void *shmem_input;
  16. static void *shmem_output;
  17. static void meson_init_shmem(void)
  18. {
  19. struct pt_regs regs;
  20. if (shmem_input && shmem_output)
  21. return;
  22. regs.regs[0] = FN_GET_SHARE_MEM_INPUT_BASE;
  23. smc_call(&regs);
  24. shmem_input = (void *)regs.regs[0];
  25. regs.regs[0] = FN_GET_SHARE_MEM_OUTPUT_BASE;
  26. smc_call(&regs);
  27. shmem_output = (void *)regs.regs[0];
  28. debug("Secure Monitor shmem: 0x%p 0x%p\n", shmem_input, shmem_output);
  29. }
  30. ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size)
  31. {
  32. struct pt_regs regs;
  33. meson_init_shmem();
  34. regs.regs[0] = FN_EFUSE_READ;
  35. regs.regs[1] = offset;
  36. regs.regs[2] = size;
  37. smc_call(&regs);
  38. if (regs.regs[0] == 0)
  39. return -1;
  40. memcpy(buffer, shmem_output, min(size, regs.regs[0]));
  41. return regs.regs[0];
  42. }