xref: /kvm-unit-tests/lib/s390x/hardware.h (revision c315f52b88b967cfb4cd58f3b4e1987378c47f3b)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Functions to retrieve information about the host system.
4  *
5  * Copyright (c) 2020 Red Hat Inc
6  * Copyright 2022 IBM Corp.
7  *
8  * Authors:
9  *  Claudio Imbrenda <imbrenda@linux.ibm.com>
10  */
11 
12 #ifndef _S390X_HARDWARE_H_
13 #define _S390X_HARDWARE_H_
14 #include <asm/arch_def.h>
15 
16 #define MACHINE_Z15	0x8561
17 #define MACHINE_Z15T02	0x8562
18 
19 enum s390_host {
20 	HOST_IS_UNKNOWN,
21 	HOST_IS_LPAR,
22 	HOST_IS_KVM,
23 	HOST_IS_TCG
24 };
25 
26 enum s390_host detect_host(void);
27 
get_machine_id(void)28 static inline uint16_t get_machine_id(void)
29 {
30 	return stidp() >> 16;
31 }
32 
host_is_tcg(void)33 static inline bool host_is_tcg(void)
34 {
35 	return detect_host() == HOST_IS_TCG;
36 }
37 
host_is_kvm(void)38 static inline bool host_is_kvm(void)
39 {
40 	return detect_host() == HOST_IS_KVM;
41 }
42 
host_is_lpar(void)43 static inline bool host_is_lpar(void)
44 {
45 	return detect_host() == HOST_IS_LPAR;
46 }
47 
host_is_qemu(void)48 static inline bool host_is_qemu(void)
49 {
50 	return host_is_tcg() || host_is_kvm();
51 }
52 
machine_is_z15(void)53 static inline bool machine_is_z15(void)
54 {
55 	uint16_t machine = get_machine_id();
56 
57 	return machine == MACHINE_Z15 || machine == MACHINE_Z15T02;
58 }
59 
60 #endif  /* _S390X_HARDWARE_H_ */
61