psci_mem_protect.c 1012 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2017-2018, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <limits.h>
  8. #include <lib/utils.h>
  9. #include "psci_private.h"
  10. u_register_t psci_mem_protect(unsigned int enable)
  11. {
  12. int val;
  13. assert(psci_plat_pm_ops->read_mem_protect != NULL);
  14. assert(psci_plat_pm_ops->write_mem_protect != NULL);
  15. if (psci_plat_pm_ops->read_mem_protect(&val) < 0)
  16. return (u_register_t) PSCI_E_NOT_SUPPORTED;
  17. if (psci_plat_pm_ops->write_mem_protect(enable) < 0)
  18. return (u_register_t) PSCI_E_NOT_SUPPORTED;
  19. return (val != 0) ? 1U : 0U;
  20. }
  21. u_register_t psci_mem_chk_range(uintptr_t base, u_register_t length)
  22. {
  23. int ret;
  24. assert(psci_plat_pm_ops->mem_protect_chk != NULL);
  25. if ((length == 0U) || check_uptr_overflow(base, length - 1U))
  26. return (u_register_t) PSCI_E_DENIED;
  27. ret = psci_plat_pm_ops->mem_protect_chk(base, length);
  28. return (ret < 0) ?
  29. (u_register_t) PSCI_E_DENIED : (u_register_t) PSCI_E_SUCCESS;
  30. }