[kvm-unit-tests PATCH v2 5/5] lib: s390x: stidp wrapper and move get_machine_id

Claudio Imbrenda
2022-03-31T16:04:41Z

Refactor get_machine_id in arch_def.h into a simple wrapper around
stidp, add back get_machine_id in hardware.h using the stidp wrapper.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
---
lib/s390x/asm/arch_def.h | 4 +---
lib/s390x/hardware.h | 5 +++++
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h
index 8d860ccf..bab3c374 100644
--- a/lib/s390x/asm/arch_def.h
+++ b/lib/s390x/asm/arch_def.h
@@ -219,13 +219,11 @@ static inline unsigned short stap(void)
return cpu_address;
}

-static inline uint16_t get_machine_id(void)
+static inline uint64_t stidp(void)
{
uint64_t cpuid;

asm volatile("stidp %0" : "=Q" (cpuid));
- cpuid = cpuid >> 16;
- cpuid &= 0xffff;

return cpuid;
}
diff --git a/lib/s390x/hardware.h b/lib/s390x/hardware.h
index af20be18..01eeb261 100644
--- a/lib/s390x/hardware.h
+++ b/lib/s390x/hardware.h
@@ -25,6 +25,11 @@ enum s390_host {

enum s390_host detect_host(void);

+static inline uint16_t get_machine_id(void)
+{
+ return stidp() >> 16;
+}
+
static inline bool host_is_tcg(void)
{
return detect_host() == HOST_IS_TCG;
--
2.34.1