From: Lokesh Vutla <
lokes...@ti.com>
Introduce cpu_id_last() api in order to find the
last cpu in the system's cpu set.
Signed-off-by: Lokesh Vutla <
lokes...@ti.com>
---
hypervisor/control.c | 17 +++++++++++++++++
hypervisor/include/jailhouse/control.h | 1 +
2 files changed, 18 insertions(+)
diff --git a/hypervisor/control.c b/hypervisor/control.c
index 52ef8733..a8921b72 100644
--- a/hypervisor/control.c
+++ b/hypervisor/control.c
@@ -72,6 +72,23 @@ bool cpu_id_valid(unsigned long cpu_id)
test_bit(cpu_id, system_cpu_set));
}
+/**
+ * Check if the CPU ID is the last CPU in the system's CPU set.
+ * @param cpu_id CPU ID to identify if it is the last
+ *
+ * @return True if CPU ID is the last cpu else false.
+ */
+bool cpu_id_last(unsigned long cpu_id)
+{
+ const unsigned long *system_cpu_set =
+ jailhouse_cell_cpu_set(&system_config->root_cell);
+ unsigned long cpu_mask;
+
+ cpu_mask = (1UL << (cpu_id % BITS_PER_LONG)) - 1;
+
+ return (~cpu_mask & *system_cpu_set) == (cpu_mask + 1);
+}
+
/*
* Suspend all CPUs assigned to the cell except the one executing
* the function (if it is in the cell's CPU set) to prevent races.
diff --git a/hypervisor/include/jailhouse/control.h b/hypervisor/include/jailhouse/control.h
index 274dc642..ce00b88a 100644
--- a/hypervisor/include/jailhouse/control.h
+++ b/hypervisor/include/jailhouse/control.h
@@ -118,6 +118,7 @@ static inline bool cell_owns_cpu(struct cell *cell, unsigned int cpu_id)
}
bool cpu_id_valid(unsigned long cpu_id);
+bool cpu_id_last(unsigned long cpu_id);
int cell_init(struct cell *cell);
--
2.16.2