xref: /qemu/include/hw/s390x/cpu-topology.h (revision 3d6e75f4)
1c809bbc8SPierre Morel /* SPDX-License-Identifier: GPL-2.0-or-later */
2c809bbc8SPierre Morel /*
3c809bbc8SPierre Morel  * CPU Topology
4c809bbc8SPierre Morel  *
5c809bbc8SPierre Morel  * Copyright IBM Corp. 2022, 2023
6c809bbc8SPierre Morel  * Author(s): Pierre Morel <pmorel@linux.ibm.com>
7c809bbc8SPierre Morel  *
8c809bbc8SPierre Morel  */
9c809bbc8SPierre Morel #ifndef HW_S390X_CPU_TOPOLOGY_H
10c809bbc8SPierre Morel #define HW_S390X_CPU_TOPOLOGY_H
11c809bbc8SPierre Morel 
12c809bbc8SPierre Morel #ifndef CONFIG_USER_ONLY
13c809bbc8SPierre Morel 
14c809bbc8SPierre Morel #include "qemu/queue.h"
15c809bbc8SPierre Morel #include "hw/boards.h"
16c809bbc8SPierre Morel #include "qapi/qapi-types-machine-target.h"
17c809bbc8SPierre Morel 
18f4f54b58SPierre Morel #define S390_TOPOLOGY_CPU_IFL   0x03
19f4f54b58SPierre Morel 
20f4f54b58SPierre Morel typedef struct S390TopologyId {
21f4f54b58SPierre Morel     uint8_t sentinel;
22f4f54b58SPierre Morel     uint8_t drawer;
23f4f54b58SPierre Morel     uint8_t book;
24f4f54b58SPierre Morel     uint8_t socket;
25f4f54b58SPierre Morel     uint8_t type;
26f4f54b58SPierre Morel     uint8_t vertical:1;
27f4f54b58SPierre Morel     uint8_t entitlement:2;
28f4f54b58SPierre Morel     uint8_t dedicated;
29f4f54b58SPierre Morel     uint8_t origin;
30f4f54b58SPierre Morel } S390TopologyId;
31f4f54b58SPierre Morel 
32f4f54b58SPierre Morel typedef struct S390TopologyEntry {
33f4f54b58SPierre Morel     QTAILQ_ENTRY(S390TopologyEntry) next;
34f4f54b58SPierre Morel     S390TopologyId id;
35f4f54b58SPierre Morel     uint64_t mask;
36f4f54b58SPierre Morel } S390TopologyEntry;
37f4f54b58SPierre Morel 
38c809bbc8SPierre Morel typedef struct S390Topology {
39c809bbc8SPierre Morel     uint8_t *cores_per_socket;
40f4f54b58SPierre Morel     CpuS390Polarization polarization;
41c809bbc8SPierre Morel } S390Topology;
42c809bbc8SPierre Morel 
43f4f54b58SPierre Morel typedef QTAILQ_HEAD(, S390TopologyEntry) S390TopologyList;
44f4f54b58SPierre Morel 
45c809bbc8SPierre Morel #ifdef CONFIG_KVM
46c809bbc8SPierre Morel bool s390_has_topology(void);
47c809bbc8SPierre Morel void s390_topology_setup_cpu(MachineState *ms, S390CPU *cpu, Error **errp);
483d6e75f4SPierre Morel void s390_topology_reset(void);
49c809bbc8SPierre Morel #else
s390_has_topology(void)50c809bbc8SPierre Morel static inline bool s390_has_topology(void)
51c809bbc8SPierre Morel {
52c809bbc8SPierre Morel     return false;
53c809bbc8SPierre Morel }
s390_topology_setup_cpu(MachineState * ms,S390CPU * cpu,Error ** errp)54c809bbc8SPierre Morel static inline void s390_topology_setup_cpu(MachineState *ms,
55c809bbc8SPierre Morel                                            S390CPU *cpu,
56c809bbc8SPierre Morel                                            Error **errp) {}
s390_topology_reset(void)573d6e75f4SPierre Morel static inline void s390_topology_reset(void)
583d6e75f4SPierre Morel {
593d6e75f4SPierre Morel     /* Unreachable, CPU topology not implemented for TCG */
603d6e75f4SPierre Morel     assert(false);
613d6e75f4SPierre Morel }
62c809bbc8SPierre Morel #endif
63c809bbc8SPierre Morel 
64c809bbc8SPierre Morel extern S390Topology s390_topology;
65c809bbc8SPierre Morel 
s390_std_socket(int n,CpuTopology * smp)66c809bbc8SPierre Morel static inline int s390_std_socket(int n, CpuTopology *smp)
67c809bbc8SPierre Morel {
68c809bbc8SPierre Morel     return (n / smp->cores) % smp->sockets;
69c809bbc8SPierre Morel }
70c809bbc8SPierre Morel 
s390_std_book(int n,CpuTopology * smp)71c809bbc8SPierre Morel static inline int s390_std_book(int n, CpuTopology *smp)
72c809bbc8SPierre Morel {
73c809bbc8SPierre Morel     return (n / (smp->cores * smp->sockets)) % smp->books;
74c809bbc8SPierre Morel }
75c809bbc8SPierre Morel 
s390_std_drawer(int n,CpuTopology * smp)76c809bbc8SPierre Morel static inline int s390_std_drawer(int n, CpuTopology *smp)
77c809bbc8SPierre Morel {
78c809bbc8SPierre Morel     return (n / (smp->cores * smp->sockets * smp->books)) % smp->drawers;
79c809bbc8SPierre Morel }
80c809bbc8SPierre Morel 
81c809bbc8SPierre Morel #endif /* CONFIG_USER_ONLY */
82c809bbc8SPierre Morel 
83c809bbc8SPierre Morel #endif
84