cpu-topology.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #ifndef CONFIG_USER_ONLY
  12. #include "qemu/queue.h"
  13. #include "hw/boards.h"
  14. #include "qapi/qapi-types-machine-target.h"
  15. #define S390_TOPOLOGY_CPU_IFL 0x03
  16. typedef struct S390TopologyId {
  17. uint8_t sentinel;
  18. uint8_t drawer;
  19. uint8_t book;
  20. uint8_t socket;
  21. uint8_t type;
  22. uint8_t vertical:1;
  23. uint8_t entitlement:2;
  24. uint8_t dedicated;
  25. uint8_t origin;
  26. } S390TopologyId;
  27. typedef struct S390TopologyEntry {
  28. QTAILQ_ENTRY(S390TopologyEntry) next;
  29. S390TopologyId id;
  30. uint64_t mask;
  31. } S390TopologyEntry;
  32. typedef struct S390Topology {
  33. uint8_t *cores_per_socket;
  34. S390CpuPolarization polarization;
  35. } S390Topology;
  36. typedef QTAILQ_HEAD(, S390TopologyEntry) S390TopologyList;
  37. #ifdef CONFIG_KVM
  38. bool s390_has_topology(void);
  39. void s390_topology_setup_cpu(MachineState *ms, S390CPU *cpu, Error **errp);
  40. void s390_topology_reset(void);
  41. #else
  42. static inline bool s390_has_topology(void)
  43. {
  44. return false;
  45. }
  46. static inline void s390_topology_setup_cpu(MachineState *ms,
  47. S390CPU *cpu,
  48. Error **errp) {}
  49. static inline void s390_topology_reset(void)
  50. {
  51. /* Unreachable, CPU topology not implemented for TCG */
  52. g_assert_not_reached();
  53. }
  54. #endif
  55. extern S390Topology s390_topology;
  56. static inline int s390_std_socket(int n, CpuTopology *smp)
  57. {
  58. return (n / smp->cores) % smp->sockets;
  59. }
  60. static inline int s390_std_book(int n, CpuTopology *smp)
  61. {
  62. return (n / (smp->cores * smp->sockets)) % smp->books;
  63. }
  64. static inline int s390_std_drawer(int n, CpuTopology *smp)
  65. {
  66. return (n / (smp->cores * smp->sockets * smp->books)) % smp->drawers;
  67. }
  68. #endif /* CONFIG_USER_ONLY */
  69. #endif