Skip to content

Commit 449e056

Browse files
committed
ARM: cpuidle: Add a cpuidle ops structure to be used for DT
The current state of the different cpuidle drivers is the different PM operations are passed via the platform_data using the platform driver paradigm. This approach allowed to split the low level PM code from the arch specific and the generic cpuidle code. Unfortunately there are complaints about this approach as, in the context of the single kernel image, we have multiple drivers loaded in memory for nothing and the platform driver is not adequate for cpuidle. This patch provides a common interface via cpuidle ops for all new cpuidle driver and a definition for the device tree. It will allow with the next patches to a have a common definition with ARM64 and share the same cpuidle driver. The code is optimized to use the __init section intensively in order to reduce the memory footprint after the driver is initialized and unify the function names with ARM64. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Acked-by: Kevin Hilman <khilman@linaro.org> Acked-by: Rob Herring <robherring2@gmail.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Tested-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
1 parent eeebc3b commit 449e056

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

arch/arm/include/asm/cpuidle.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,25 @@ static inline int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
2727
*/
2828
#define ARM_CPUIDLE_WFI_STATE ARM_CPUIDLE_WFI_STATE_PWR(UINT_MAX)
2929

30+
struct device_node;
31+
32+
struct cpuidle_ops {
33+
int (*suspend)(int cpu, unsigned long arg);
34+
int (*init)(struct device_node *, int cpu);
35+
};
36+
37+
struct of_cpuidle_method {
38+
const char *method;
39+
struct cpuidle_ops *ops;
40+
};
41+
42+
#define CPUIDLE_METHOD_OF_DECLARE(name, _method, _ops) \
43+
static const struct of_cpuidle_method __cpuidle_method_of_table_##name \
44+
__used __section(__cpuidle_method_of_table) \
45+
= { .method = _method, .ops = _ops }
46+
47+
extern int arm_cpuidle_suspend(int index);
48+
49+
extern int arm_cpuidle_init(int cpu);
50+
3051
#endif

arch/arm/kernel/cpuidle.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,84 @@
1010
*/
1111

1212
#include <linux/cpuidle.h>
13+
#include <linux/of.h>
14+
#include <linux/of_device.h>
1315
#include <asm/cpuidle.h>
1416

17+
extern struct of_cpuidle_method __cpuidle_method_of_table[];
18+
19+
static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel
20+
__used __section(__cpuidle_method_of_table_end);
21+
22+
static struct cpuidle_ops cpuidle_ops[NR_CPUS];
23+
1524
int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
1625
struct cpuidle_driver *drv, int index)
1726
{
1827
cpu_do_idle();
1928

2029
return index;
2130
}
31+
32+
int arm_cpuidle_suspend(int index)
33+
{
34+
int ret = -EOPNOTSUPP;
35+
int cpu = smp_processor_id();
36+
37+
if (cpuidle_ops[cpu].suspend)
38+
ret = cpuidle_ops[cpu].suspend(cpu, index);
39+
40+
return ret;
41+
}
42+
43+
static struct cpuidle_ops *__init arm_cpuidle_get_ops(const char *method)
44+
{
45+
struct of_cpuidle_method *m = __cpuidle_method_of_table;
46+
47+
for (; m->method; m++)
48+
if (!strcmp(m->method, method))
49+
return m->ops;
50+
51+
return NULL;
52+
}
53+
54+
static int __init arm_cpuidle_read_ops(struct device_node *dn, int cpu)
55+
{
56+
const char *enable_method;
57+
struct cpuidle_ops *ops;
58+
59+
enable_method = of_get_property(dn, "enable-method", NULL);
60+
if (!enable_method)
61+
return -ENOENT;
62+
63+
ops = arm_cpuidle_get_ops(enable_method);
64+
if (!ops) {
65+
pr_warn("%s: unsupported enable-method property: %s\n",
66+
dn->full_name, enable_method);
67+
return -EOPNOTSUPP;
68+
}
69+
70+
cpuidle_ops[cpu] = *ops; /* structure copy */
71+
72+
pr_notice("cpuidle: enable-method property '%s'"
73+
" found operations\n", enable_method);
74+
75+
return 0;
76+
}
77+
78+
int __init arm_cpuidle_init(int cpu)
79+
{
80+
struct device_node *cpu_node = of_cpu_device_node_get(cpu);
81+
int ret;
82+
83+
if (!cpu_node)
84+
return -ENODEV;
85+
86+
ret = arm_cpuidle_read_ops(cpu_node, cpu);
87+
if (!ret && cpuidle_ops[cpu].init)
88+
ret = cpuidle_ops[cpu].init(cpu_node, cpu);
89+
90+
of_node_put(cpu_node);
91+
92+
return ret;
93+
}

arch/arm64/include/asm/cpuidle.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ static inline int cpu_suspend(unsigned long arg)
1717
return -EOPNOTSUPP;
1818
}
1919
#endif
20-
20+
static inline int arm_cpuidle_suspend(int index)
21+
{
22+
return cpu_suspend(index);
23+
}
2124
#endif

include/asm-generic/vmlinux.lds.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
#define IOMMU_OF_TABLES() OF_TABLE(CONFIG_OF_IOMMU, iommu)
168168
#define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem)
169169
#define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method)
170+
#define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method)
170171
#define EARLYCON_OF_TABLES() OF_TABLE(CONFIG_SERIAL_EARLYCON, earlycon)
171172

172173
#define KERNEL_DTB() \
@@ -501,6 +502,7 @@
501502
CLKSRC_OF_TABLES() \
502503
IOMMU_OF_TABLES() \
503504
CPU_METHOD_OF_TABLES() \
505+
CPUIDLE_METHOD_OF_TABLES() \
504506
KERNEL_DTB() \
505507
IRQCHIP_OF_MATCH_TABLE() \
506508
EARLYCON_OF_TABLES()

0 commit comments

Comments
 (0)