Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / include / hw / s390x / cpu-topology.h
blob9283c948e3a6c472a6391ed371c76acc08cff3ec
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * CPU Topology
5 * Copyright IBM Corp. 2022, 2023
6 * Author(s): Pierre Morel <pmorel@linux.ibm.com>
8 */
9 #ifndef HW_S390X_CPU_TOPOLOGY_H
10 #define HW_S390X_CPU_TOPOLOGY_H
12 #ifndef CONFIG_USER_ONLY
14 #include "qemu/queue.h"
15 #include "hw/boards.h"
16 #include "qapi/qapi-types-machine-target.h"
18 #define S390_TOPOLOGY_CPU_IFL 0x03
20 typedef struct S390TopologyId {
21 uint8_t sentinel;
22 uint8_t drawer;
23 uint8_t book;
24 uint8_t socket;
25 uint8_t type;
26 uint8_t vertical:1;
27 uint8_t entitlement:2;
28 uint8_t dedicated;
29 uint8_t origin;
30 } S390TopologyId;
32 typedef struct S390TopologyEntry {
33 QTAILQ_ENTRY(S390TopologyEntry) next;
34 S390TopologyId id;
35 uint64_t mask;
36 } S390TopologyEntry;
38 typedef struct S390Topology {
39 uint8_t *cores_per_socket;
40 S390CpuPolarization polarization;
41 } S390Topology;
43 typedef QTAILQ_HEAD(, S390TopologyEntry) S390TopologyList;
45 #ifdef CONFIG_KVM
46 bool s390_has_topology(void);
47 void s390_topology_setup_cpu(MachineState *ms, S390CPU *cpu, Error **errp);
48 void s390_topology_reset(void);
49 #else
50 static inline bool s390_has_topology(void)
52 return false;
54 static inline void s390_topology_setup_cpu(MachineState *ms,
55 S390CPU *cpu,
56 Error **errp) {}
57 static inline void s390_topology_reset(void)
59 /* Unreachable, CPU topology not implemented for TCG */
60 g_assert_not_reached();
62 #endif
64 extern S390Topology s390_topology;
66 static inline int s390_std_socket(int n, CpuTopology *smp)
68 return (n / smp->cores) % smp->sockets;
71 static inline int s390_std_book(int n, CpuTopology *smp)
73 return (n / (smp->cores * smp->sockets)) % smp->books;
76 static inline int s390_std_drawer(int n, CpuTopology *smp)
78 return (n / (smp->cores * smp->sockets * smp->books)) % smp->drawers;
81 #endif /* CONFIG_USER_ONLY */
83 #endif