From c38fdc4908aa64819e17fd6fb7ce66bda2c56bdc Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Fri, 30 Dec 2016 13:25:20 +1100 Subject: [PATCH] cpu: Add iterators for "present" CPUs Some code path want to look at all the CPUs that are "present", which means they have been enabled by HB/Cronus and can be accessed via XSCOMs, even if they haven't called in yet. Signed-off-by: Benjamin Herrenschmidt Signed-off-by: Stewart Smith --- core/cpu.c | 14 ++++++++++++++ include/cpu.h | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/core/cpu.c b/core/cpu.c index 5d76adfc8205..c7e650dad48a 100644 --- a/core/cpu.c +++ b/core/cpu.c @@ -494,6 +494,20 @@ struct cpu_thread *first_available_cpu(void) return next_available_cpu(NULL); } +struct cpu_thread *next_present_cpu(struct cpu_thread *cpu) +{ + do { + cpu = next_cpu(cpu); + } while(cpu && !cpu_is_present(cpu)); + + return cpu; +} + +struct cpu_thread *first_present_cpu(void) +{ + return next_present_cpu(NULL); +} + u8 get_available_nr_cores_in_chip(u32 chip_id) { struct cpu_thread *core; diff --git a/include/cpu.h b/include/cpu.h index f649a13e6231..1e147aa861ab 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -165,6 +165,11 @@ extern struct cpu_thread *next_cpu(struct cpu_thread *cpu); * this API standpoint. */ +static inline bool cpu_is_present(struct cpu_thread *cpu) +{ + return cpu->state >= cpu_state_present; +} + static inline bool cpu_is_available(struct cpu_thread *cpu) { return cpu->state == cpu_state_active || @@ -173,6 +178,8 @@ static inline bool cpu_is_available(struct cpu_thread *cpu) extern struct cpu_thread *first_available_cpu(void); extern struct cpu_thread *next_available_cpu(struct cpu_thread *cpu); +extern struct cpu_thread *first_present_cpu(void); +extern struct cpu_thread *next_present_cpu(struct cpu_thread *cpu); #define for_each_cpu(cpu) \ for (cpu = first_cpu(); cpu; cpu = next_cpu(cpu)) @@ -180,6 +187,9 @@ extern struct cpu_thread *next_available_cpu(struct cpu_thread *cpu); #define for_each_available_cpu(cpu) \ for (cpu = first_available_cpu(); cpu; cpu = next_available_cpu(cpu)) +#define for_each_present_cpu(cpu) \ + for (cpu = first_present_cpu(); cpu; cpu = next_present_cpu(cpu)) + extern struct cpu_thread *first_available_core_in_chip(u32 chip_id); extern struct cpu_thread *next_available_core_in_chip(struct cpu_thread *cpu, u32 chip_id); extern u8 get_available_nr_cores_in_chip(u32 chip_id);