Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+99 -1
+21
arch/arm/include/asm/cpuidle.h
··· 27 27 */ 28 28 #define ARM_CPUIDLE_WFI_STATE ARM_CPUIDLE_WFI_STATE_PWR(UINT_MAX) 29 29 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 + 30 51 #endif
+72
arch/arm/kernel/cpuidle.c
··· 10 10 */ 11 11 12 12 #include <linux/cpuidle.h> 13 + #include <linux/of.h> 14 + #include <linux/of_device.h> 13 15 #include <asm/cpuidle.h> 16 + 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]; 14 23 15 24 int arm_cpuidle_simple_enter(struct cpuidle_device *dev, 16 25 struct cpuidle_driver *drv, int index) ··· 27 18 cpu_do_idle(); 28 19 29 20 return index; 21 + } 22 + 23 + int arm_cpuidle_suspend(int index) 24 + { 25 + int ret = -EOPNOTSUPP; 26 + int cpu = smp_processor_id(); 27 + 28 + if (cpuidle_ops[cpu].suspend) 29 + ret = cpuidle_ops[cpu].suspend(cpu, index); 30 + 31 + return ret; 32 + } 33 + 34 + static struct cpuidle_ops *__init arm_cpuidle_get_ops(const char *method) 35 + { 36 + struct of_cpuidle_method *m = __cpuidle_method_of_table; 37 + 38 + for (; m->method; m++) 39 + if (!strcmp(m->method, method)) 40 + return m->ops; 41 + 42 + return NULL; 43 + } 44 + 45 + static int __init arm_cpuidle_read_ops(struct device_node *dn, int cpu) 46 + { 47 + const char *enable_method; 48 + struct cpuidle_ops *ops; 49 + 50 + enable_method = of_get_property(dn, "enable-method", NULL); 51 + if (!enable_method) 52 + return -ENOENT; 53 + 54 + ops = arm_cpuidle_get_ops(enable_method); 55 + if (!ops) { 56 + pr_warn("%s: unsupported enable-method property: %s\n", 57 + dn->full_name, enable_method); 58 + return -EOPNOTSUPP; 59 + } 60 + 61 + cpuidle_ops[cpu] = *ops; /* structure copy */ 62 + 63 + pr_notice("cpuidle: enable-method property '%s'" 64 + " found operations\n", enable_method); 65 + 66 + return 0; 67 + } 68 + 69 + int __init arm_cpuidle_init(int cpu) 70 + { 71 + struct device_node *cpu_node = of_cpu_device_node_get(cpu); 72 + int ret; 73 + 74 + if (!cpu_node) 75 + return -ENODEV; 76 + 77 + ret = arm_cpuidle_read_ops(cpu_node, cpu); 78 + if (!ret && cpuidle_ops[cpu].init) 79 + ret = cpuidle_ops[cpu].init(cpu_node, cpu); 80 + 81 + of_node_put(cpu_node); 82 + 83 + return ret; 30 84 }
+4 -1
arch/arm64/include/asm/cpuidle.h
··· 17 17 return -EOPNOTSUPP; 18 18 } 19 19 #endif 20 - 20 + static inline int arm_cpuidle_suspend(int index) 21 + { 22 + return cpu_suspend(index); 23 + } 21 24 #endif
+2
include/asm-generic/vmlinux.lds.h
··· 167 167 #define IOMMU_OF_TABLES() OF_TABLE(CONFIG_OF_IOMMU, iommu) 168 168 #define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem) 169 169 #define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method) 170 + #define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method) 170 171 #define EARLYCON_OF_TABLES() OF_TABLE(CONFIG_SERIAL_EARLYCON, earlycon) 171 172 172 173 #define KERNEL_DTB() \ ··· 502 501 CLKSRC_OF_TABLES() \ 503 502 IOMMU_OF_TABLES() \ 504 503 CPU_METHOD_OF_TABLES() \ 504 + CPUIDLE_METHOD_OF_TABLES() \ 505 505 KERNEL_DTB() \ 506 506 IRQCHIP_OF_MATCH_TABLE() \ 507 507 EARLYCON_OF_TABLES()