summaryrefslogtreecommitdiff
path: root/arch/x86/include/asm/mp.h
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-07-17 08:48:21 -0600
committerBin Meng <bmeng.cn@gmail.com>2020-07-20 09:46:46 +0800
commit0538d6833cc61722ee506fab4609d9c1cf010491 (patch)
treee2f8957f458a8c32a4f6581e648281f9fc533353 /arch/x86/include/asm/mp.h
parent99a573fb326faf5a7bff50e4f9875f2066728d95 (diff)
x86: mp: Add iterators for CPUs
It is convenient to iterate through the CPUs performing work on each one and processing the result. Add a few iterator functions which handle this. These can be used by any client code. It can call mp_run_on_cpus() on each CPU that is returned, handling them one at a time. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'arch/x86/include/asm/mp.h')
-rw-r--r--arch/x86/include/asm/mp.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/arch/x86/include/asm/mp.h b/arch/x86/include/asm/mp.h
index f9d6c8e6bf..9379826b6b 100644
--- a/arch/x86/include/asm/mp.h
+++ b/arch/x86/include/asm/mp.h
@@ -118,6 +118,33 @@ int mp_run_on_cpus(int cpu_select, mp_run_func func, void *arg);
* @return 0 if OK, -ve on error
*/
int mp_park_aps(void);
+
+/**
+ * mp_first_cpu() - Get the first CPU to process, from a selection
+ *
+ * This is used to iterate through selected CPUs. Call this function first, then
+ * call mp_next_cpu() repeatedly (with the same @cpu_select) until it returns
+ * -EFBIG.
+ *
+ * @cpu_select: Selected CPUs (either a CPU number or MP_SELECT_...)
+ * @return next CPU number to run on (e.g. 0)
+ */
+int mp_first_cpu(int cpu_select);
+
+/**
+ * mp_next_cpu() - Get the next CPU to process, from a selection
+ *
+ * This is used to iterate through selected CPUs. After first calling
+ * mp_first_cpu() once, call this function repeatedly until it returns -EFBIG.
+ *
+ * The value of @cpu_select must be the same for all calls and must match the
+ * value passed to mp_first_cpu(), otherwise the behaviour is undefined.
+ *
+ * @cpu_select: Selected CPUs (either a CPU number or MP_SELECT_...)
+ * @prev_cpu: Previous value returned by mp_first_cpu()/mp_next_cpu()
+ * @return next CPU number to run on (e.g. 0)
+ */
+int mp_next_cpu(int cpu_select, int prev_cpu);
#else
static inline int mp_run_on_cpus(int cpu_select, mp_run_func func, void *arg)
{
@@ -134,6 +161,21 @@ static inline int mp_park_aps(void)
return 0;
}
+static inline int mp_first_cpu(int cpu_select)
+{
+ /* We cannot run on any APs, nor a selected CPU */
+ return cpu_select == MP_SELECT_APS ? -EFBIG : MP_SELECT_BSP;
+}
+
+static inline int mp_next_cpu(int cpu_select, int prev_cpu)
+{
+ /*
+ * When MP is not enabled, there is only one CPU and we did it in
+ * mp_first_cpu()
+ */
+ return -EFBIG;
+}
+
#endif
#endif /* _X86_MP_H_ */