msm8916_pm.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2021-2022, Stephan Gerhold <stephan@gerhold.net>
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <arch.h>
  8. #include <arch_helpers.h>
  9. #include <common/debug.h>
  10. #include <drivers/arm/cci.h>
  11. #include <drivers/arm/gicv2.h>
  12. #include <drivers/delay_timer.h>
  13. #include <lib/mmio.h>
  14. #include <lib/psci/psci.h>
  15. #include <plat/common/platform.h>
  16. #include <msm8916_mmap.h>
  17. #include "msm8916_pm.h"
  18. /*
  19. * On platforms with two clusters the index of the APCS memory region is swapped
  20. * compared to the MPIDR cluster affinity level: APCS cluster 0 manages CPUs
  21. * with cluster affinity level 1, while APCS cluster 1 manages CPUs with level 0.
  22. *
  23. * On platforms with a single cluster there is only one APCS memory region.
  24. */
  25. #if PLATFORM_CLUSTER_COUNT == 2
  26. #define MPIDR_APCS_CLUSTER(mpidr) !MPIDR_AFFLVL1_VAL(mpidr)
  27. #else
  28. #define MPIDR_APCS_CLUSTER(mpidr) 0
  29. #endif
  30. #define CLUSTER_PWR_STATE(state) ((state)->pwr_domain_state[MPIDR_AFFLVL1])
  31. static int msm8916_pwr_domain_on(u_register_t mpidr)
  32. {
  33. /* Should be never called on single-core platforms */
  34. if (PLATFORM_CORE_COUNT == 1) {
  35. assert(false);
  36. return PSCI_E_ALREADY_ON;
  37. }
  38. /* Power on L2 cache and secondary CPU core for the first time */
  39. if (PLATFORM_CLUSTER_COUNT > 1) {
  40. msm8916_l2_boot(APCS_GLB(MPIDR_APCS_CLUSTER(mpidr)));
  41. }
  42. msm8916_cpu_boot(APCS_ALIAS_ACS(MPIDR_APCS_CLUSTER(mpidr),
  43. MPIDR_AFFLVL0_VAL(mpidr)));
  44. return PSCI_E_SUCCESS;
  45. }
  46. static void msm8916_pwr_domain_on_finish(const psci_power_state_t *target_state)
  47. {
  48. /* Should be never called on single-core platforms */
  49. if (PLATFORM_CORE_COUNT == 1) {
  50. assert(false);
  51. return;
  52. }
  53. if (PLATFORM_CLUSTER_COUNT > 1 &&
  54. CLUSTER_PWR_STATE(target_state) == PLAT_MAX_OFF_STATE) {
  55. cci_enable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr_el1()));
  56. }
  57. gicv2_pcpu_distif_init();
  58. gicv2_cpuif_enable();
  59. }
  60. static void __dead2 msm8916_system_reset(void)
  61. {
  62. mmio_write_32(MPM_PS_HOLD, 0);
  63. mdelay(1000);
  64. ERROR("PSCI: System reset failed\n");
  65. panic();
  66. }
  67. static const plat_psci_ops_t msm8916_psci_ops = {
  68. .pwr_domain_on = msm8916_pwr_domain_on,
  69. .pwr_domain_on_finish = msm8916_pwr_domain_on_finish,
  70. .system_off = msm8916_system_reset,
  71. .system_reset = msm8916_system_reset,
  72. };
  73. /* Defined and used in msm8916_helpers.S */
  74. extern uintptr_t msm8916_entry_point;
  75. int plat_setup_psci_ops(uintptr_t sec_entrypoint,
  76. const plat_psci_ops_t **psci_ops)
  77. {
  78. /*
  79. * The entry point is read with caches off (and even from two different
  80. * physical addresses when read through the "boot remapper"), so make
  81. * sure it is flushed to memory.
  82. */
  83. msm8916_entry_point = sec_entrypoint;
  84. flush_dcache_range((uintptr_t)&msm8916_entry_point, sizeof(uintptr_t));
  85. *psci_ops = &msm8916_psci_ops;
  86. return 0;
  87. }