cpu_psci.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include <rthw.h>
  10. #include <rtthread.h>
  11. #include <stdint.h>
  12. #ifdef RT_USING_SMP
  13. #define DBG_TAG "libcpu.aarch64.cpu_psci"
  14. #define DBG_LVL DBG_INFO
  15. #include <rtdbg.h>
  16. #include "cpu_ops_common.h"
  17. #include "cpu.h"
  18. #include "errno.h"
  19. #include "psci.h"
  20. #include "psci_api.h"
  21. static int (*_psci_init)(void) = psci_init;
  22. static int __call_method_init()
  23. {
  24. int (*init)(void) = _psci_init;
  25. _psci_init = RT_NULL;
  26. return init();
  27. }
  28. /** return 0 on success, otherwise failed */
  29. #define _call_method_init() ((_psci_init) ? __call_method_init() : 0);
  30. static int cpu_psci_cpu_init(rt_uint32_t cpuid)
  31. {
  32. // init psci only once
  33. return _call_method_init();
  34. }
  35. static int cpu_psci_cpu_boot(rt_uint32_t cpuid)
  36. {
  37. rt_uint64_t secondary_entry_pa = get_secondary_entry_pa();
  38. if (!secondary_entry_pa)
  39. return -1;
  40. if (!psci_ops.cpu_on) {
  41. LOG_E("Uninitialized psci operation");
  42. return -1;
  43. }
  44. return psci_ops.cpu_on(cpuid_to_hwid(cpuid), secondary_entry_pa);
  45. }
  46. static void cpu_psci_cpu_shutdown()
  47. {
  48. psci_ops.cpu_off(cpuid_to_hwid(rt_hw_cpu_id()));
  49. }
  50. struct cpu_ops_t cpu_ops_psci = {
  51. .method = "psci",
  52. .cpu_boot = cpu_psci_cpu_boot,
  53. .cpu_init = cpu_psci_cpu_init,
  54. .cpu_shutdown = cpu_psci_cpu_shutdown,
  55. };
  56. #endif /* RT_USING_SMP */