xref: /kvm-unit-tests/lib/s390x/hardware.h (revision c604fa931a1cb70c3649ac1b7223178fc79eab6a)
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 
28 static inline uint16_t get_machine_id(void)
29 {
30 	return stidp() >> 16;
31 }
32 
33 static inline bool host_is_tcg(void)
34 {
35 	return detect_host() == HOST_IS_TCG;
36 }
37 
38 static inline bool host_is_kvm(void)
39 {
40 	return detect_host() == HOST_IS_KVM;
41 }
42 
43 static inline bool host_is_lpar(void)
44 {
45 	return detect_host() == HOST_IS_LPAR;
46 }
47 
48 static inline bool host_is_qemu(void)
49 {
50 	return host_is_tcg() || host_is_kvm();
51 }
52 
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