cpuidle.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ARM64 CPU idle arch support
  4. *
  5. * Copyright (C) 2014 ARM Ltd.
  6. * Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/cpuidle.h>
  10. #include <linux/cpu_pm.h>
  11. #include <linux/psci.h>
  12. #include <acpi/processor.h>
  13. #define ARM64_LPI_IS_RETENTION_STATE(arch_flags) (!(arch_flags))
  14. static int psci_acpi_cpu_init_idle(unsigned int cpu)
  15. {
  16. int i, count;
  17. struct acpi_lpi_state *lpi;
  18. struct acpi_processor *pr = per_cpu(processors, cpu);
  19. if (unlikely(!pr || !pr->flags.has_lpi))
  20. return -EINVAL;
  21. /*
  22. * If the PSCI cpu_suspend function hook has not been initialized
  23. * idle states must not be enabled, so bail out
  24. */
  25. if (!psci_ops.cpu_suspend)
  26. return -EOPNOTSUPP;
  27. count = pr->power.count - 1;
  28. if (count <= 0)
  29. return -ENODEV;
  30. for (i = 0; i < count; i++) {
  31. u32 state;
  32. lpi = &pr->power.lpi_states[i + 1];
  33. /*
  34. * Only bits[31:0] represent a PSCI power_state while
  35. * bits[63:32] must be 0x0 as per ARM ACPI FFH Specification
  36. */
  37. state = lpi->address;
  38. if (!psci_power_state_is_valid(state)) {
  39. pr_warn("Invalid PSCI power state %#x\n", state);
  40. return -EINVAL;
  41. }
  42. }
  43. return 0;
  44. }
  45. int acpi_processor_ffh_lpi_probe(unsigned int cpu)
  46. {
  47. return psci_acpi_cpu_init_idle(cpu);
  48. }
  49. __cpuidle int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi)
  50. {
  51. u32 state = lpi->address;
  52. if (ARM64_LPI_IS_RETENTION_STATE(lpi->arch_flags))
  53. return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM_RCU(psci_cpu_suspend_enter,
  54. lpi->index, state);
  55. else
  56. return CPU_PM_CPU_IDLE_ENTER_PARAM_RCU(psci_cpu_suspend_enter,
  57. lpi->index, state);
  58. }