xref: /openbmc/qemu/include/hw/s390x/cpu-topology.h (revision fa3673e4)
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 void s390_topology_reset(void);
49 #else
50 static inline bool s390_has_topology(void)
51 {
52     return false;
53 }
54 static inline void s390_topology_setup_cpu(MachineState *ms,
55                                            S390CPU *cpu,
56                                            Error **errp) {}
57 static inline void s390_topology_reset(void)
58 {
59     /* Unreachable, CPU topology not implemented for TCG */
60     assert(false);
61 }
62 #endif
63 
64 extern S390Topology s390_topology;
65 
66 static inline int s390_std_socket(int n, CpuTopology *smp)
67 {
68     return (n / smp->cores) % smp->sockets;
69 }
70 
71 static inline int s390_std_book(int n, CpuTopology *smp)
72 {
73     return (n / (smp->cores * smp->sockets)) % smp->books;
74 }
75 
76 static inline int s390_std_drawer(int n, CpuTopology *smp)
77 {
78     return (n / (smp->cores * smp->sockets * smp->books)) % smp->drawers;
79 }
80 
81 #endif /* CONFIG_USER_ONLY */
82 
83 #endif
84