sm.c 1.1 KB

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