smc_api.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020 Intel Corporation <www.intel.com>
  4. *
  5. */
  6. #include <common.h>
  7. #include <asm/ptrace.h>
  8. #include <asm/system.h>
  9. #include <linux/intel-smc.h>
  10. int invoke_smc(u32 func_id, u64 *args, int arg_len, u64 *ret_arg, int ret_len)
  11. {
  12. struct pt_regs regs;
  13. memset(&regs, 0, sizeof(regs));
  14. regs.regs[0] = func_id;
  15. if (args)
  16. memcpy(&regs.regs[1], args, arg_len * sizeof(*args));
  17. smc_call(&regs);
  18. if (ret_arg)
  19. memcpy(ret_arg, &regs.regs[1], ret_len * sizeof(*ret_arg));
  20. return regs.regs[0];
  21. }
  22. int smc_send_mailbox(u32 cmd, u32 len, u32 *arg, u8 urgent, u32 *resp_buf_len,
  23. u32 *resp_buf)
  24. {
  25. int ret;
  26. u64 args[6];
  27. u64 resp[3];
  28. args[0] = cmd;
  29. args[1] = (u64)arg;
  30. args[2] = len;
  31. args[3] = urgent;
  32. args[4] = (u64)resp_buf;
  33. if (resp_buf_len)
  34. args[5] = *resp_buf_len;
  35. else
  36. args[5] = 0;
  37. ret = invoke_smc(INTEL_SIP_SMC_MBOX_SEND_CMD, args, ARRAY_SIZE(args),
  38. resp, ARRAY_SIZE(resp));
  39. if (ret == INTEL_SIP_SMC_STATUS_OK && resp_buf && resp_buf_len) {
  40. if (!resp[0])
  41. *resp_buf_len = resp[1];
  42. }
  43. return (int)resp[0];
  44. }