This helps to find out on which CPU we are currently running on.

Signed-off-by: Ralf Ramsauer <[email protected]>
---
 inmates/lib/arm-common/include/inmate.h | 10 ++++++++++
 inmates/lib/arm/include/asm/sysregs.h   |  3 +++
 inmates/lib/arm64/include/asm/sysregs.h |  2 ++
 3 files changed, 15 insertions(+)

diff --git a/inmates/lib/arm-common/include/inmate.h 
b/inmates/lib/arm-common/include/inmate.h
index e4c256d2..6611b311 100644
--- a/inmates/lib/arm-common/include/inmate.h
+++ b/inmates/lib/arm-common/include/inmate.h
@@ -39,6 +39,8 @@
 #ifndef _JAILHOUSE_INMATE_H
 #define _JAILHOUSE_INMATE_H
 
+#include <asm/sysregs.h>
+
 typedef signed char s8;
 typedef unsigned char u8;
 
@@ -76,6 +78,14 @@ static inline void mmio_write32(void *address, u32 value)
        *(volatile u32 *)address = value;
 }
 
+static inline unsigned long cpu_id(void)
+{
+       unsigned long mpidr;
+
+       arm_read_sysreg(MPIDR_EL1, mpidr);
+       return mpidr & MPIDR_CPUID_MASK;
+}
+
 typedef void (*irq_handler_t)(unsigned int);
 void gic_setup(irq_handler_t handler, void *irq_stack);
 void gic_enable_irq(unsigned int irq);
diff --git a/inmates/lib/arm/include/asm/sysregs.h 
b/inmates/lib/arm/include/asm/sysregs.h
index 7c285923..73b191fe 100644
--- a/inmates/lib/arm/include/asm/sysregs.h
+++ b/inmates/lib/arm/include/asm/sysregs.h
@@ -45,6 +45,9 @@
 #define CNTV_CTL_EL0   SYSREG_32(0, c14, c3, 1)
 #define CNTPCT_EL0     SYSREG_64(0, c14)
 
+#define MPIDR_EL1              SYSREG_32(0, c0, c0, 5)
+#define  MPIDR_CPUID_MASK      0x00ffffff
+
 #define SYSREG_32(...) 32, __VA_ARGS__
 #define SYSREG_64(...) 64, __VA_ARGS__
 
diff --git a/inmates/lib/arm64/include/asm/sysregs.h 
b/inmates/lib/arm64/include/asm/sysregs.h
index d1f120c7..2961d4fb 100644
--- a/inmates/lib/arm64/include/asm/sysregs.h
+++ b/inmates/lib/arm64/include/asm/sysregs.h
@@ -39,6 +39,8 @@
 /* The following definitions are inspired by
  * hypervisor/arch/arm64/include/asm/sysregs.h */
 
+#define MPIDR_CPUID_MASK    0xff00ffffff
+
 #ifndef __ASSEMBLY__
 
 #define arm_write_sysreg(sysreg, val) \
-- 
2.14.1

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to