blob: 16b077801a5f97125f48cc9d597580cef7f8f65d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
jdl@freescale.comdd56fdf2005-09-07 15:59:48 -05002#ifndef _ASM_POWERPC_TOPOLOGY_H
3#define _ASM_POWERPC_TOPOLOGY_H
Arnd Bergmann88ced032005-12-16 22:43:46 +01004#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Kay Sievers8a25a2f2011-12-21 14:29:42 -08007struct device;
Jeremy Kerr953039c2006-05-01 12:16:12 -07008struct device_node;
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#ifdef CONFIG_NUMA
11
Anton Blanchard27f10902010-02-18 12:29:23 +000012/*
Mel Gorman4f9b16a2014-06-04 16:07:14 -070013 * 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().
Anton Blanchard27f10902010-02-18 12:29:23 +000015 */
16#define RECLAIM_DISTANCE 10
17
jdl@freescale.comdd56fdf2005-09-07 15:59:48 -050018#include <asm/mmzone.h>
19
Anton Blanchardc81b8122010-01-05 18:55:10 +000020#define cpumask_of_node(node) ((node) == -1 ? \
21 cpu_all_mask : \
Anton Blanchard25863de2010-04-26 15:32:43 +000022 node_to_cpumask_map[node])
Rusty Russell86c6f2742008-12-26 22:23:39 +103023
Anton Blanchard357518f2006-06-10 20:53:06 +100024struct pci_bus;
Arnd Bergmann11faa652006-11-27 19:19:00 +010025#ifdef CONFIG_PCI
Anton Blanchard357518f2006-06-10 20:53:06 +100026extern int pcibus_to_node(struct pci_bus *bus);
Arnd Bergmann11faa652006-11-27 19:19:00 +010027#else
28static inline int pcibus_to_node(struct pci_bus *bus)
29{
30 return -1;
31}
32#endif
Anton Blanchard357518f2006-06-10 20:53:06 +100033
Rusty Russell86c6f2742008-12-26 22:23:39 +103034#define cpumask_of_pcibus(bus) (pcibus_to_node(bus) == -1 ? \
35 cpu_all_mask : \
36 cpumask_of_node(pcibus_to_node(bus)))
37
Anton Blanchard41eab6f2010-05-16 20:22:31 +000038extern int __node_distance(int, int);
39#define node_distance(a, b) __node_distance(a, b)
40
Anton Blanchard4b703a22005-12-13 06:56:47 +110041extern void __init dump_numa_cpu_topology(void);
42
Kay Sievers8a25a2f2011-12-21 14:29:42 -080043extern int sysfs_add_device_to_node(struct device *dev, int nid);
44extern void sysfs_remove_device_from_node(struct device *dev, int nid);
Thiago Jung Bauermann3e401f72017-06-20 19:08:30 -030045extern int numa_update_cpu_topology(bool cpus_locked);
Jeremy Kerr953039c2006-05-01 12:16:12 -070046
Nathan Fontenot1d9a0902018-01-26 13:41:59 -060047static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node)
48{
49 numa_cpu_lookup_table[cpu] = node;
50}
51
Michael Ellermanba4a6482017-06-06 20:23:57 +100052static inline int early_cpu_to_node(int cpu)
53{
54 int nid;
55
56 nid = numa_cpu_lookup_table[cpu];
57
58 /*
59 * Fall back to node 0 if nid is unset (it should be, except bugs).
60 * This allows callers to safely do NODE_DATA(early_cpu_to_node(cpu)).
61 */
62 return (nid < 0) ? 0 : nid;
63}
Jesse Larrew39bf9902010-12-17 22:07:47 +000064#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Michael Ellermanba4a6482017-06-06 20:23:57 +100066static inline int early_cpu_to_node(int cpu) { return 0; }
67
Anton Blanchard4b703a22005-12-13 06:56:47 +110068static inline void dump_numa_cpu_topology(void) {}
69
Kay Sievers8a25a2f2011-12-21 14:29:42 -080070static inline int sysfs_add_device_to_node(struct device *dev, int nid)
Jeremy Kerr953039c2006-05-01 12:16:12 -070071{
72 return 0;
73}
74
Kay Sievers8a25a2f2011-12-21 14:29:42 -080075static inline void sysfs_remove_device_from_node(struct device *dev,
Jeremy Kerr953039c2006-05-01 12:16:12 -070076 int nid)
77{
78}
Thiago Jung Bauermann3e401f72017-06-20 19:08:30 -030079
80static inline int numa_update_cpu_topology(bool cpus_locked)
81{
82 return 0;
83}
Corentin Labbec1e150c2018-02-14 12:17:47 +000084
85static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node) {}
86
Mike Travisaa6b5442008-03-31 08:41:55 -070087#endif /* CONFIG_NUMA */
Jeremy Kerr953039c2006-05-01 12:16:12 -070088
Benjamin Herrenschmidt5d7d8072011-01-12 10:56:29 +110089#if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)
90extern int start_topology_update(void);
91extern int stop_topology_update(void);
Nathan Fontenote04fa612013-04-24 06:07:39 +000092extern int prrn_is_enabled(void);
Guenter Roeck82343482018-02-12 14:34:08 -080093extern int find_and_online_cpu_nid(int cpu);
Michael Ellerman6c0a8f62018-05-08 14:59:56 +100094extern int timed_topology_update(int nsecs);
Benjamin Herrenschmidt5d7d8072011-01-12 10:56:29 +110095#else
96static inline int start_topology_update(void)
97{
98 return 0;
99}
100static inline int stop_topology_update(void)
101{
102 return 0;
103}
Nathan Fontenote04fa612013-04-24 06:07:39 +0000104static inline int prrn_is_enabled(void)
105{
106 return 0;
107}
Guenter Roeck82343482018-02-12 14:34:08 -0800108static inline int find_and_online_cpu_nid(int cpu)
109{
110 return 0;
111}
Michael Ellerman6c0a8f62018-05-08 14:59:56 +1000112static inline int timed_topology_update(int nsecs)
113{
114 return 0;
115}
Benjamin Herrenschmidt5d7d8072011-01-12 10:56:29 +1100116#endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#include <asm-generic/topology.h>
119
Siddha, Suresh B5c45bf22006-06-27 02:54:42 -0700120#ifdef CONFIG_SMP
121#include <asm/cputable.h>
Stephen Rothwell056f4fa2006-11-13 14:51:46 +1100122
123#ifdef CONFIG_PPC64
124#include <asm/smp.h>
125
Vasant Hegde15863ff2013-08-12 17:35:57 +0530126#define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu))
Bartosz Golaszewski06931e62015-05-26 15:11:28 +0200127#define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
Anton Blanchardcc1ba8e2010-04-26 15:32:41 +0000128#define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
Nathan Lynche9efed32008-07-27 15:24:54 +1000129#define topology_core_id(cpu) (cpu_to_core_id(cpu))
Stephen Rothwell056f4fa2006-11-13 14:51:46 +1100130#endif
Siddha, Suresh B5c45bf22006-06-27 02:54:42 -0700131#endif
132
Arnd Bergmann88ced032005-12-16 22:43:46 +0100133#endif /* __KERNEL__ */
jdl@freescale.comdd56fdf2005-09-07 15:59:48 -0500134#endif /* _ASM_POWERPC_TOPOLOGY_H */