reset.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. *
  6. */
  7. #include <linux/gunyah/gh_rm_drv.h>
  8. #include "reset.h"
  9. /**
  10. * gh_arch_validate_vm_exited_notif: Validate the arch specific exit
  11. * reason and provide a generic reason for further use.
  12. * @buff_size: Size of the buffer containing the exit reason
  13. * @hdr_size: Size of the header
  14. * @vm_exited_payload: Struct of exit_reason
  15. *
  16. * If the exit reason is not valid or has an incorrect size, -EINVAL is
  17. * returned, 0 otherwise and also provides a generic reason for exit
  18. * which can be used by drivers.
  19. */
  20. int gh_arch_validate_vm_exited_notif(size_t payload_size,
  21. struct gh_rm_notif_vm_exited_payload *vm_exited_payload)
  22. {
  23. switch (vm_exited_payload->exit_type) {
  24. case GH_RM_VM_EXIT_TYPE_PSCI_SYSTEM_RESET2:
  25. if (payload_size !=
  26. sizeof(*vm_exited_payload) + sizeof(struct gh_vm_exit_reason_psci_sys_reset2)) {
  27. pr_err("%s: Invalid size for type PSCI_SYSTEM_RESET2: %u\n",
  28. __func__, payload_size);
  29. return -EINVAL;
  30. }
  31. vm_exited_payload->exit_type = GH_RM_VM_EXIT_TYPE_SYSTEM_RESET;
  32. fallthrough;
  33. case GH_RM_VM_EXIT_TYPE_PSCI_SYSTEM_RESET:
  34. vm_exited_payload->exit_type = GH_RM_VM_EXIT_TYPE_SYSTEM_RESET;
  35. break;
  36. case GH_RM_VM_EXIT_TYPE_PSCI_SYSTEM_OFF:
  37. vm_exited_payload->exit_type = GH_RM_VM_EXIT_TYPE_SYSTEM_OFF;
  38. break;
  39. default:
  40. return -EINVAL;
  41. }
  42. return 0;
  43. }
  44. EXPORT_SYMBOL(gh_arch_validate_vm_exited_notif);