xref: /openbmc/qemu/include/hw/s390x/cpu-topology.h (revision f4f54b58)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * CPU Topology
4  *
5  * Copyright IBM Corp. 2022, 2023
6  * Author(s): Pierre Morel <pmorel@linux.ibm.com>
7  *
8  */
9 #ifndef HW_S390X_CPU_TOPOLOGY_H
10 #define HW_S390X_CPU_TOPOLOGY_H
11 
12 #ifndef CONFIG_USER_ONLY
13 
14 #include "qemu/queue.h"
15 #include "hw/boards.h"
16 #include "qapi/qapi-types-machine-target.h"
17 
18 #define S390_TOPOLOGY_CPU_IFL   0x03
19 
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;
31 
32 typedef struct S390TopologyEntry {
33     QTAILQ_ENTRY(S390TopologyEntry) next;
34     S390TopologyId id;
35     uint64_t mask;
36 } S390TopologyEntry;
37 
38 typedef struct S390Topology {
39     uint8_t *cores_per_socket;
40     CpuS390Polarization polarization;
41 } S390Topology;
42 
43 typedef QTAILQ_HEAD(, S390TopologyEntry) S390TopologyList;
44 
45 #ifdef CONFIG_KVM
46 bool s390_has_topology(void);
47 void s390_topology_setup_cpu(MachineState *ms, S390CPU *cpu, Error **errp);
48 #else
49 static inline bool s390_has_topology(void)
50 {
51     return false;
52 }
53 static inline void s390_topology_setup_cpu(MachineState *ms,
54                                            S390CPU *cpu,
55                                            Error **errp) {}
56 #endif
57 
58 extern S390Topology s390_topology;
59 
60 static inline int s390_std_socket(int n, CpuTopology *smp)
61 {
62     return (n / smp->cores) % smp->sockets;
63 }
64 
65 static inline int s390_std_book(int n, CpuTopology *smp)
66 {
67     return (n / (smp->cores * smp->sockets)) % smp->books;
68 }
69 
70 static inline int s390_std_drawer(int n, CpuTopology *smp)
71 {
72     return (n / (smp->cores * smp->sockets * smp->books)) % smp->drawers;
73 }
74 
75 #endif /* CONFIG_USER_ONLY */
76 
77 #endif
78