blob: 3beeb030cd78e9bbcababbf4de178c588fbe0eee [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;
Olivier Deprez157378f2022-04-04 15:47:50 +02009struct drmem_lmb;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000010
11#ifdef CONFIG_NUMA
12
13/*
14 * If zone_reclaim_mode is enabled, a RECLAIM_DISTANCE of 10 will mean that
15 * all zones on all nodes will be eligible for zone_reclaim().
16 */
17#define RECLAIM_DISTANCE 10
18
19#include <asm/mmzone.h>
20
21#define cpumask_of_node(node) ((node) == -1 ? \
22 cpu_all_mask : \
23 node_to_cpumask_map[node])
24
25struct pci_bus;
26#ifdef CONFIG_PCI
27extern int pcibus_to_node(struct pci_bus *bus);
28#else
29static inline int pcibus_to_node(struct pci_bus *bus)
30{
31 return -1;
32}
33#endif
34
35#define cpumask_of_pcibus(bus) (pcibus_to_node(bus) == -1 ? \
36 cpu_all_mask : \
37 cpumask_of_node(pcibus_to_node(bus)))
38
David Brazdil0f672f62019-12-10 10:32:29 +000039extern int cpu_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000040extern int __node_distance(int, int);
41#define node_distance(a, b) __node_distance(a, b)
42
43extern void __init dump_numa_cpu_topology(void);
44
45extern int sysfs_add_device_to_node(struct device *dev, int nid);
46extern void sysfs_remove_device_from_node(struct device *dev, int nid);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000047
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}
Olivier Deprez157378f2022-04-04 15:47:50 +020065
66int of_drconf_to_nid_single(struct drmem_lmb *lmb);
67
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000068#else
69
70static inline int early_cpu_to_node(int cpu) { return 0; }
71
72static inline void dump_numa_cpu_topology(void) {}
73
74static inline int sysfs_add_device_to_node(struct device *dev, int nid)
75{
76 return 0;
77}
78
79static inline void sysfs_remove_device_from_node(struct device *dev,
80 int nid)
81{
82}
83
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000084static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node) {}
85
David Brazdil0f672f62019-12-10 10:32:29 +000086static inline int cpu_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc)
87{
88 return 0;
89}
90
Olivier Deprez157378f2022-04-04 15:47:50 +020091static inline int of_drconf_to_nid_single(struct drmem_lmb *lmb)
92{
93 return first_online_node;
94}
95
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000096#endif /* CONFIG_NUMA */
97
98#if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000099extern int find_and_online_cpu_nid(int cpu);
Olivier Deprez157378f2022-04-04 15:47:50 +0200100extern int cpu_to_coregroup_id(int cpu);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000101#else
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000102static inline int find_and_online_cpu_nid(int cpu)
103{
104 return 0;
105}
Olivier Deprez157378f2022-04-04 15:47:50 +0200106
107static inline int cpu_to_coregroup_id(int cpu)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000108{
Olivier Deprez157378f2022-04-04 15:47:50 +0200109#ifdef CONFIG_SMP
110 return cpu_to_core_id(cpu);
111#else
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000112 return 0;
Olivier Deprez157378f2022-04-04 15:47:50 +0200113#endif
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000114}
115
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000116#endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */
117
118#include <asm-generic/topology.h>
119
120#ifdef CONFIG_SMP
121#include <asm/cputable.h>
122
123#ifdef CONFIG_PPC64
124#include <asm/smp.h>
125
126#define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu))
Olivier Deprez157378f2022-04-04 15:47:50 +0200127
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000128#define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
Olivier Deprez157378f2022-04-04 15:47:50 +0200129#define topology_core_cpumask(cpu) (cpu_cpu_mask(cpu))
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000130#define topology_core_id(cpu) (cpu_to_core_id(cpu))
David Brazdil0f672f62019-12-10 10:32:29 +0000131
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000132#endif
133#endif
134
135#endif /* __KERNEL__ */
136#endif /* _ASM_POWERPC_TOPOLOGY_H */