topology.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_POWERPC_TOPOLOGY_H
  3. #define _ASM_POWERPC_TOPOLOGY_H
  4. #ifdef __KERNEL__
  5. struct device;
  6. struct device_node;
  7. struct drmem_lmb;
  8. #ifdef CONFIG_NUMA
  9. /*
  10. * If zone_reclaim_mode is enabled, a RECLAIM_DISTANCE of 10 will mean that
  11. * all zones on all nodes will be eligible for zone_reclaim().
  12. */
  13. #define RECLAIM_DISTANCE 10
  14. #include <asm/mmzone.h>
  15. #define cpumask_of_node(node) ((node) == -1 ? \
  16. cpu_all_mask : \
  17. node_to_cpumask_map[node])
  18. struct pci_bus;
  19. #ifdef CONFIG_PCI
  20. extern int pcibus_to_node(struct pci_bus *bus);
  21. #else
  22. static inline int pcibus_to_node(struct pci_bus *bus)
  23. {
  24. return -1;
  25. }
  26. #endif
  27. #define cpumask_of_pcibus(bus) (pcibus_to_node(bus) == -1 ? \
  28. cpu_all_mask : \
  29. cpumask_of_node(pcibus_to_node(bus)))
  30. int cpu_relative_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc);
  31. extern int __node_distance(int, int);
  32. #define node_distance(a, b) __node_distance(a, b)
  33. extern void __init dump_numa_cpu_topology(void);
  34. extern int sysfs_add_device_to_node(struct device *dev, int nid);
  35. extern void sysfs_remove_device_from_node(struct device *dev, int nid);
  36. static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node)
  37. {
  38. numa_cpu_lookup_table[cpu] = node;
  39. }
  40. static inline int early_cpu_to_node(int cpu)
  41. {
  42. int nid;
  43. nid = numa_cpu_lookup_table[cpu];
  44. /*
  45. * Fall back to node 0 if nid is unset (it should be, except bugs).
  46. * This allows callers to safely do NODE_DATA(early_cpu_to_node(cpu)).
  47. */
  48. return (nid < 0) ? 0 : nid;
  49. }
  50. int of_drconf_to_nid_single(struct drmem_lmb *lmb);
  51. void update_numa_distance(struct device_node *node);
  52. extern void map_cpu_to_node(int cpu, int node);
  53. #ifdef CONFIG_HOTPLUG_CPU
  54. extern void unmap_cpu_from_node(unsigned long cpu);
  55. #endif /* CONFIG_HOTPLUG_CPU */
  56. #else
  57. static inline int early_cpu_to_node(int cpu) { return 0; }
  58. static inline void dump_numa_cpu_topology(void) {}
  59. static inline int sysfs_add_device_to_node(struct device *dev, int nid)
  60. {
  61. return 0;
  62. }
  63. static inline void sysfs_remove_device_from_node(struct device *dev,
  64. int nid)
  65. {
  66. }
  67. static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node) {}
  68. static inline int cpu_relative_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc)
  69. {
  70. return 0;
  71. }
  72. static inline int of_drconf_to_nid_single(struct drmem_lmb *lmb)
  73. {
  74. return first_online_node;
  75. }
  76. static inline void update_numa_distance(struct device_node *node) {}
  77. #ifdef CONFIG_SMP
  78. static inline void map_cpu_to_node(int cpu, int node) {}
  79. #ifdef CONFIG_HOTPLUG_CPU
  80. static inline void unmap_cpu_from_node(unsigned long cpu) {}
  81. #endif /* CONFIG_HOTPLUG_CPU */
  82. #endif /* CONFIG_SMP */
  83. #endif /* CONFIG_NUMA */
  84. #if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)
  85. void find_and_update_cpu_nid(int cpu);
  86. extern int cpu_to_coregroup_id(int cpu);
  87. #else
  88. static inline void find_and_update_cpu_nid(int cpu) {}
  89. static inline int cpu_to_coregroup_id(int cpu)
  90. {
  91. #ifdef CONFIG_SMP
  92. return cpu_to_core_id(cpu);
  93. #else
  94. return 0;
  95. #endif
  96. }
  97. #endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */
  98. #include <asm-generic/topology.h>
  99. #ifdef CONFIG_SMP
  100. #include <asm/cputable.h>
  101. #ifdef CONFIG_PPC64
  102. #include <asm/smp.h>
  103. #define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu))
  104. #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
  105. #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
  106. #define topology_core_id(cpu) (cpu_to_core_id(cpu))
  107. #endif
  108. #endif
  109. #endif /* __KERNEL__ */
  110. #endif /* _ASM_POWERPC_TOPOLOGY_H */