topology.h 3.0 KB

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