cpuidle.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 <[email protected]>
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/cpuidle.h>
  10. #include <linux/cpu_pm.h>
  11. #include <linux/of.h>
  12. #include <linux/of_device.h>
  13. #include <linux/psci.h>
  14. #ifdef CONFIG_ACPI
  15. #include <acpi/processor.h>
  16. #define ARM64_LPI_IS_RETENTION_STATE(arch_flags) (!(arch_flags))
  17. static int psci_acpi_cpu_init_idle(unsigned int cpu)
  18. {
  19. int i, count;
  20. struct acpi_lpi_state *lpi;
  21. struct acpi_processor *pr = per_cpu(processors, cpu);
  22. if (unlikely(!pr || !pr->flags.has_lpi))
  23. return -EINVAL;
  24. /*
  25. * If the PSCI cpu_suspend function hook has not been initialized
  26. * idle states must not be enabled, so bail out
  27. */
  28. if (!psci_ops.cpu_suspend)
  29. return -EOPNOTSUPP;
  30. count = pr->power.count - 1;
  31. if (count <= 0)
  32. return -ENODEV;
  33. for (i = 0; i < count; i++) {
  34. u32 state;
  35. lpi = &pr->power.lpi_states[i + 1];
  36. /*
  37. * Only bits[31:0] represent a PSCI power_state while
  38. * bits[63:32] must be 0x0 as per ARM ACPI FFH Specification
  39. */
  40. state = lpi->address;
  41. if (!psci_power_state_is_valid(state)) {
  42. pr_warn("Invalid PSCI power state %#x\n", state);
  43. return -EINVAL;
  44. }
  45. }
  46. return 0;
  47. }
  48. int acpi_processor_ffh_lpi_probe(unsigned int cpu)
  49. {
  50. return psci_acpi_cpu_init_idle(cpu);
  51. }
  52. int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi)
  53. {
  54. u32 state = lpi->address;
  55. if (ARM64_LPI_IS_RETENTION_STATE(lpi->arch_flags))
  56. return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(psci_cpu_suspend_enter,
  57. lpi->index, state);
  58. else
  59. return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter,
  60. lpi->index, state);
  61. }
  62. #endif