blob: 2f7e1ea5089e9830b0b963c71c2eb5ecde7bdaac [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_POWERPC_TOPOLOGY_H
3#define _ASM_POWERPC_TOPOLOGY_H
4#ifdef __KERNEL__
5
6
7struct device;
8struct device_node;
9
10#ifdef CONFIG_NUMA
11
12/*
13 * If zone_reclaim_mode is enabled, a RECLAIM_DISTANCE of 10 will mean that
14 * all zones on all nodes will be eligible for zone_reclaim().
15 */
16#define RECLAIM_DISTANCE 10
17
18#include <asm/mmzone.h>
19
20#define cpumask_of_node(node) ((node) == -1 ? \
21 cpu_all_mask : \
22 node_to_cpumask_map[node])
23
24struct pci_bus;
25#ifdef CONFIG_PCI
26extern int pcibus_to_node(struct pci_bus *bus);
27#else
28static inline int pcibus_to_node(struct pci_bus *bus)
29{
30 return -1;
31}
32#endif
33
34#define cpumask_of_pcibus(bus) (pcibus_to_node(bus) == -1 ? \
35 cpu_all_mask : \
36 cpumask_of_node(pcibus_to_node(bus)))
37
David Brazdil0f672f62019-12-10 10:32:29 +000038extern int cpu_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000039extern int __node_distance(int, int);
40#define node_distance(a, b) __node_distance(a, b)
41
42extern void __init dump_numa_cpu_topology(void);
43
44extern int sysfs_add_device_to_node(struct device *dev, int nid);
45extern void sysfs_remove_device_from_node(struct device *dev, int nid);
46extern int numa_update_cpu_topology(bool cpus_locked);
47
48static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node)
49{
50 numa_cpu_lookup_table[cpu] = node;
51}
52
53static inline int early_cpu_to_node(int cpu)
54{
55 int nid;
56
57 nid = numa_cpu_lookup_table[cpu];
58
59 /*
60 * Fall back to node 0 if nid is unset (it should be, except bugs).
61 * This allows callers to safely do NODE_DATA(early_cpu_to_node(cpu)).
62 */
63 return (nid < 0) ? 0 : nid;
64}
65#else
66
67static inline int early_cpu_to_node(int cpu) { return 0; }
68
69static inline void dump_numa_cpu_topology(void) {}
70
71static inline int sysfs_add_device_to_node(struct device *dev, int nid)
72{
73 return 0;
74}
75
76static inline void sysfs_remove_device_from_node(struct device *dev,
77 int nid)
78{
79}
80
81static inline int numa_update_cpu_topology(bool cpus_locked)
82{
83 return 0;
84}
85
86static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node) {}
87
David Brazdil0f672f62019-12-10 10:32:29 +000088static inline int cpu_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc)
89{
90 return 0;
91}
92
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000093#endif /* CONFIG_NUMA */
94
95#if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)
96extern int start_topology_update(void);
97extern int stop_topology_update(void);
98extern int prrn_is_enabled(void);
99extern int find_and_online_cpu_nid(int cpu);
100extern int timed_topology_update(int nsecs);
101extern void __init shared_proc_topology_init(void);
102#else
103static inline int start_topology_update(void)
104{
105 return 0;
106}
107static inline int stop_topology_update(void)
108{
109 return 0;
110}
111static inline int prrn_is_enabled(void)
112{
113 return 0;
114}
115static inline int find_and_online_cpu_nid(int cpu)
116{
117 return 0;
118}
119static inline int timed_topology_update(int nsecs)
120{
121 return 0;
122}
123
124#ifdef CONFIG_SMP
125static inline void shared_proc_topology_init(void) {}
126#endif
127#endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */
128
129#include <asm-generic/topology.h>
130
131#ifdef CONFIG_SMP
132#include <asm/cputable.h>
133
134#ifdef CONFIG_PPC64
135#include <asm/smp.h>
136
137#define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu))
138#define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
139#define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
140#define topology_core_id(cpu) (cpu_to_core_id(cpu))
David Brazdil0f672f62019-12-10 10:32:29 +0000141
142int dlpar_cpu_readd(int cpu);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000143#endif
144#endif
145
146#endif /* __KERNEL__ */
147#endif /* _ASM_POWERPC_TOPOLOGY_H */