powerpc/pseries: Update numa.c to use updated firmware_has_feature()
[firefly-linux-kernel-4.4.55.git] / arch / powerpc / mm / numa.c
1 /*
2  * pSeries NUMA support
3  *
4  * Copyright (C) 2002 Anton Blanchard <anton@au.ibm.com>, IBM
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11 #include <linux/threads.h>
12 #include <linux/bootmem.h>
13 #include <linux/init.h>
14 #include <linux/mm.h>
15 #include <linux/mmzone.h>
16 #include <linux/export.h>
17 #include <linux/nodemask.h>
18 #include <linux/cpu.h>
19 #include <linux/notifier.h>
20 #include <linux/memblock.h>
21 #include <linux/of.h>
22 #include <linux/pfn.h>
23 #include <linux/cpuset.h>
24 #include <linux/node.h>
25 #include <asm/sparsemem.h>
26 #include <asm/prom.h>
27 #include <asm/smp.h>
28 #include <asm/firmware.h>
29 #include <asm/paca.h>
30 #include <asm/hvcall.h>
31 #include <asm/setup.h>
32
33 static int numa_enabled = 1;
34
35 static char *cmdline __initdata;
36
37 static int numa_debug;
38 #define dbg(args...) if (numa_debug) { printk(KERN_INFO args); }
39
40 int numa_cpu_lookup_table[NR_CPUS];
41 cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
42 struct pglist_data *node_data[MAX_NUMNODES];
43
44 EXPORT_SYMBOL(numa_cpu_lookup_table);
45 EXPORT_SYMBOL(node_to_cpumask_map);
46 EXPORT_SYMBOL(node_data);
47
48 static int min_common_depth;
49 static int n_mem_addr_cells, n_mem_size_cells;
50 static int form1_affinity;
51
52 #define MAX_DISTANCE_REF_POINTS 4
53 static int distance_ref_points_depth;
54 static const unsigned int *distance_ref_points;
55 static int distance_lookup_table[MAX_NUMNODES][MAX_DISTANCE_REF_POINTS];
56
57 /*
58  * Allocate node_to_cpumask_map based on number of available nodes
59  * Requires node_possible_map to be valid.
60  *
61  * Note: cpumask_of_node() is not valid until after this is done.
62  */
63 static void __init setup_node_to_cpumask_map(void)
64 {
65         unsigned int node, num = 0;
66
67         /* setup nr_node_ids if not done yet */
68         if (nr_node_ids == MAX_NUMNODES) {
69                 for_each_node_mask(node, node_possible_map)
70                         num = node;
71                 nr_node_ids = num + 1;
72         }
73
74         /* allocate the map */
75         for (node = 0; node < nr_node_ids; node++)
76                 alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
77
78         /* cpumask_of_node() will now work */
79         dbg("Node to cpumask map for %d nodes\n", nr_node_ids);
80 }
81
82 static int __init fake_numa_create_new_node(unsigned long end_pfn,
83                                                 unsigned int *nid)
84 {
85         unsigned long long mem;
86         char *p = cmdline;
87         static unsigned int fake_nid;
88         static unsigned long long curr_boundary;
89
90         /*
91          * Modify node id, iff we started creating NUMA nodes
92          * We want to continue from where we left of the last time
93          */
94         if (fake_nid)
95                 *nid = fake_nid;
96         /*
97          * In case there are no more arguments to parse, the
98          * node_id should be the same as the last fake node id
99          * (we've handled this above).
100          */
101         if (!p)
102                 return 0;
103
104         mem = memparse(p, &p);
105         if (!mem)
106                 return 0;
107
108         if (mem < curr_boundary)
109                 return 0;
110
111         curr_boundary = mem;
112
113         if ((end_pfn << PAGE_SHIFT) > mem) {
114                 /*
115                  * Skip commas and spaces
116                  */
117                 while (*p == ',' || *p == ' ' || *p == '\t')
118                         p++;
119
120                 cmdline = p;
121                 fake_nid++;
122                 *nid = fake_nid;
123                 dbg("created new fake_node with id %d\n", fake_nid);
124                 return 1;
125         }
126         return 0;
127 }
128
129 /*
130  * get_node_active_region - Return active region containing pfn
131  * Active range returned is empty if none found.
132  * @pfn: The page to return the region for
133  * @node_ar: Returned set to the active region containing @pfn
134  */
135 static void __init get_node_active_region(unsigned long pfn,
136                                           struct node_active_region *node_ar)
137 {
138         unsigned long start_pfn, end_pfn;
139         int i, nid;
140
141         for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) {
142                 if (pfn >= start_pfn && pfn < end_pfn) {
143                         node_ar->nid = nid;
144                         node_ar->start_pfn = start_pfn;
145                         node_ar->end_pfn = end_pfn;
146                         break;
147                 }
148         }
149 }
150
151 static void map_cpu_to_node(int cpu, int node)
152 {
153         numa_cpu_lookup_table[cpu] = node;
154
155         dbg("adding cpu %d to node %d\n", cpu, node);
156
157         if (!(cpumask_test_cpu(cpu, node_to_cpumask_map[node])))
158                 cpumask_set_cpu(cpu, node_to_cpumask_map[node]);
159 }
160
161 #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PPC_SPLPAR)
162 static void unmap_cpu_from_node(unsigned long cpu)
163 {
164         int node = numa_cpu_lookup_table[cpu];
165
166         dbg("removing cpu %lu from node %d\n", cpu, node);
167
168         if (cpumask_test_cpu(cpu, node_to_cpumask_map[node])) {
169                 cpumask_clear_cpu(cpu, node_to_cpumask_map[node]);
170         } else {
171                 printk(KERN_ERR "WARNING: cpu %lu not found in node %d\n",
172                        cpu, node);
173         }
174 }
175 #endif /* CONFIG_HOTPLUG_CPU || CONFIG_PPC_SPLPAR */
176
177 /* must hold reference to node during call */
178 static const int *of_get_associativity(struct device_node *dev)
179 {
180         return of_get_property(dev, "ibm,associativity", NULL);
181 }
182
183 /*
184  * Returns the property linux,drconf-usable-memory if
185  * it exists (the property exists only in kexec/kdump kernels,
186  * added by kexec-tools)
187  */
188 static const u32 *of_get_usable_memory(struct device_node *memory)
189 {
190         const u32 *prop;
191         u32 len;
192         prop = of_get_property(memory, "linux,drconf-usable-memory", &len);
193         if (!prop || len < sizeof(unsigned int))
194                 return 0;
195         return prop;
196 }
197
198 int __node_distance(int a, int b)
199 {
200         int i;
201         int distance = LOCAL_DISTANCE;
202
203         if (!form1_affinity)
204                 return ((a == b) ? LOCAL_DISTANCE : REMOTE_DISTANCE);
205
206         for (i = 0; i < distance_ref_points_depth; i++) {
207                 if (distance_lookup_table[a][i] == distance_lookup_table[b][i])
208                         break;
209
210                 /* Double the distance for each NUMA level */
211                 distance *= 2;
212         }
213
214         return distance;
215 }
216
217 static void initialize_distance_lookup_table(int nid,
218                 const unsigned int *associativity)
219 {
220         int i;
221
222         if (!form1_affinity)
223                 return;
224
225         for (i = 0; i < distance_ref_points_depth; i++) {
226                 distance_lookup_table[nid][i] =
227                         associativity[distance_ref_points[i]];
228         }
229 }
230
231 /* Returns nid in the range [0..MAX_NUMNODES-1], or -1 if no useful numa
232  * info is found.
233  */
234 static int associativity_to_nid(const unsigned int *associativity)
235 {
236         int nid = -1;
237
238         if (min_common_depth == -1)
239                 goto out;
240
241         if (associativity[0] >= min_common_depth)
242                 nid = associativity[min_common_depth];
243
244         /* POWER4 LPAR uses 0xffff as invalid node */
245         if (nid == 0xffff || nid >= MAX_NUMNODES)
246                 nid = -1;
247
248         if (nid > 0 && associativity[0] >= distance_ref_points_depth)
249                 initialize_distance_lookup_table(nid, associativity);
250
251 out:
252         return nid;
253 }
254
255 /* Returns the nid associated with the given device tree node,
256  * or -1 if not found.
257  */
258 static int of_node_to_nid_single(struct device_node *device)
259 {
260         int nid = -1;
261         const unsigned int *tmp;
262
263         tmp = of_get_associativity(device);
264         if (tmp)
265                 nid = associativity_to_nid(tmp);
266         return nid;
267 }
268
269 /* Walk the device tree upwards, looking for an associativity id */
270 int of_node_to_nid(struct device_node *device)
271 {
272         struct device_node *tmp;
273         int nid = -1;
274
275         of_node_get(device);
276         while (device) {
277                 nid = of_node_to_nid_single(device);
278                 if (nid != -1)
279                         break;
280
281                 tmp = device;
282                 device = of_get_parent(tmp);
283                 of_node_put(tmp);
284         }
285         of_node_put(device);
286
287         return nid;
288 }
289 EXPORT_SYMBOL_GPL(of_node_to_nid);
290
291 static int __init find_min_common_depth(void)
292 {
293         int depth;
294         struct device_node *root;
295
296         if (firmware_has_feature(FW_FEATURE_OPAL))
297                 root = of_find_node_by_path("/ibm,opal");
298         else
299                 root = of_find_node_by_path("/rtas");
300         if (!root)
301                 root = of_find_node_by_path("/");
302
303         /*
304          * This property is a set of 32-bit integers, each representing
305          * an index into the ibm,associativity nodes.
306          *
307          * With form 0 affinity the first integer is for an SMP configuration
308          * (should be all 0's) and the second is for a normal NUMA
309          * configuration. We have only one level of NUMA.
310          *
311          * With form 1 affinity the first integer is the most significant
312          * NUMA boundary and the following are progressively less significant
313          * boundaries. There can be more than one level of NUMA.
314          */
315         distance_ref_points = of_get_property(root,
316                                         "ibm,associativity-reference-points",
317                                         &distance_ref_points_depth);
318
319         if (!distance_ref_points) {
320                 dbg("NUMA: ibm,associativity-reference-points not found.\n");
321                 goto err;
322         }
323
324         distance_ref_points_depth /= sizeof(int);
325
326         if (firmware_has_feature(FW_FEATURE_OPAL) ||
327             firmware_has_feature(FW_FEATURE_TYPE1_AFFINITY)) {
328                 dbg("Using form 1 affinity\n");
329                 form1_affinity = 1;
330         }
331
332         if (form1_affinity) {
333                 depth = distance_ref_points[0];
334         } else {
335                 if (distance_ref_points_depth < 2) {
336                         printk(KERN_WARNING "NUMA: "
337                                 "short ibm,associativity-reference-points\n");
338                         goto err;
339                 }
340
341                 depth = distance_ref_points[1];
342         }
343
344         /*
345          * Warn and cap if the hardware supports more than
346          * MAX_DISTANCE_REF_POINTS domains.
347          */
348         if (distance_ref_points_depth > MAX_DISTANCE_REF_POINTS) {
349                 printk(KERN_WARNING "NUMA: distance array capped at "
350                         "%d entries\n", MAX_DISTANCE_REF_POINTS);
351                 distance_ref_points_depth = MAX_DISTANCE_REF_POINTS;
352         }
353
354         of_node_put(root);
355         return depth;
356
357 err:
358         of_node_put(root);
359         return -1;
360 }
361
362 static void __init get_n_mem_cells(int *n_addr_cells, int *n_size_cells)
363 {
364         struct device_node *memory = NULL;
365
366         memory = of_find_node_by_type(memory, "memory");
367         if (!memory)
368                 panic("numa.c: No memory nodes found!");
369
370         *n_addr_cells = of_n_addr_cells(memory);
371         *n_size_cells = of_n_size_cells(memory);
372         of_node_put(memory);
373 }
374
375 static unsigned long read_n_cells(int n, const unsigned int **buf)
376 {
377         unsigned long result = 0;
378
379         while (n--) {
380                 result = (result << 32) | **buf;
381                 (*buf)++;
382         }
383         return result;
384 }
385
386 /*
387  * Read the next memblock list entry from the ibm,dynamic-memory property
388  * and return the information in the provided of_drconf_cell structure.
389  */
390 static void read_drconf_cell(struct of_drconf_cell *drmem, const u32 **cellp)
391 {
392         const u32 *cp;
393
394         drmem->base_addr = read_n_cells(n_mem_addr_cells, cellp);
395
396         cp = *cellp;
397         drmem->drc_index = cp[0];
398         drmem->reserved = cp[1];
399         drmem->aa_index = cp[2];
400         drmem->flags = cp[3];
401
402         *cellp = cp + 4;
403 }
404
405 /*
406  * Retrieve and validate the ibm,dynamic-memory property of the device tree.
407  *
408  * The layout of the ibm,dynamic-memory property is a number N of memblock
409  * list entries followed by N memblock list entries.  Each memblock list entry
410  * contains information as laid out in the of_drconf_cell struct above.
411  */
412 static int of_get_drconf_memory(struct device_node *memory, const u32 **dm)
413 {
414         const u32 *prop;
415         u32 len, entries;
416
417         prop = of_get_property(memory, "ibm,dynamic-memory", &len);
418         if (!prop || len < sizeof(unsigned int))
419                 return 0;
420
421         entries = *prop++;
422
423         /* Now that we know the number of entries, revalidate the size
424          * of the property read in to ensure we have everything
425          */
426         if (len < (entries * (n_mem_addr_cells + 4) + 1) * sizeof(unsigned int))
427                 return 0;
428
429         *dm = prop;
430         return entries;
431 }
432
433 /*
434  * Retrieve and validate the ibm,lmb-size property for drconf memory
435  * from the device tree.
436  */
437 static u64 of_get_lmb_size(struct device_node *memory)
438 {
439         const u32 *prop;
440         u32 len;
441
442         prop = of_get_property(memory, "ibm,lmb-size", &len);
443         if (!prop || len < sizeof(unsigned int))
444                 return 0;
445
446         return read_n_cells(n_mem_size_cells, &prop);
447 }
448
449 struct assoc_arrays {
450         u32     n_arrays;
451         u32     array_sz;
452         const u32 *arrays;
453 };
454
455 /*
456  * Retrieve and validate the list of associativity arrays for drconf
457  * memory from the ibm,associativity-lookup-arrays property of the
458  * device tree..
459  *
460  * The layout of the ibm,associativity-lookup-arrays property is a number N
461  * indicating the number of associativity arrays, followed by a number M
462  * indicating the size of each associativity array, followed by a list
463  * of N associativity arrays.
464  */
465 static int of_get_assoc_arrays(struct device_node *memory,
466                                struct assoc_arrays *aa)
467 {
468         const u32 *prop;
469         u32 len;
470
471         prop = of_get_property(memory, "ibm,associativity-lookup-arrays", &len);
472         if (!prop || len < 2 * sizeof(unsigned int))
473                 return -1;
474
475         aa->n_arrays = *prop++;
476         aa->array_sz = *prop++;
477
478         /* Now that we know the number of arrays and size of each array,
479          * revalidate the size of the property read in.
480          */
481         if (len < (aa->n_arrays * aa->array_sz + 2) * sizeof(unsigned int))
482                 return -1;
483
484         aa->arrays = prop;
485         return 0;
486 }
487
488 /*
489  * This is like of_node_to_nid_single() for memory represented in the
490  * ibm,dynamic-reconfiguration-memory node.
491  */
492 static int of_drconf_to_nid_single(struct of_drconf_cell *drmem,
493                                    struct assoc_arrays *aa)
494 {
495         int default_nid = 0;
496         int nid = default_nid;
497         int index;
498
499         if (min_common_depth > 0 && min_common_depth <= aa->array_sz &&
500             !(drmem->flags & DRCONF_MEM_AI_INVALID) &&
501             drmem->aa_index < aa->n_arrays) {
502                 index = drmem->aa_index * aa->array_sz + min_common_depth - 1;
503                 nid = aa->arrays[index];
504
505                 if (nid == 0xffff || nid >= MAX_NUMNODES)
506                         nid = default_nid;
507         }
508
509         return nid;
510 }
511
512 /*
513  * Figure out to which domain a cpu belongs and stick it there.
514  * Return the id of the domain used.
515  */
516 static int __cpuinit numa_setup_cpu(unsigned long lcpu)
517 {
518         int nid = 0;
519         struct device_node *cpu = of_get_cpu_node(lcpu, NULL);
520
521         if (!cpu) {
522                 WARN_ON(1);
523                 goto out;
524         }
525
526         nid = of_node_to_nid_single(cpu);
527
528         if (nid < 0 || !node_online(nid))
529                 nid = first_online_node;
530 out:
531         map_cpu_to_node(lcpu, nid);
532
533         of_node_put(cpu);
534
535         return nid;
536 }
537
538 static int __cpuinit cpu_numa_callback(struct notifier_block *nfb,
539                              unsigned long action,
540                              void *hcpu)
541 {
542         unsigned long lcpu = (unsigned long)hcpu;
543         int ret = NOTIFY_DONE;
544
545         switch (action) {
546         case CPU_UP_PREPARE:
547         case CPU_UP_PREPARE_FROZEN:
548                 numa_setup_cpu(lcpu);
549                 ret = NOTIFY_OK;
550                 break;
551 #ifdef CONFIG_HOTPLUG_CPU
552         case CPU_DEAD:
553         case CPU_DEAD_FROZEN:
554         case CPU_UP_CANCELED:
555         case CPU_UP_CANCELED_FROZEN:
556                 unmap_cpu_from_node(lcpu);
557                 break;
558                 ret = NOTIFY_OK;
559 #endif
560         }
561         return ret;
562 }
563
564 /*
565  * Check and possibly modify a memory region to enforce the memory limit.
566  *
567  * Returns the size the region should have to enforce the memory limit.
568  * This will either be the original value of size, a truncated value,
569  * or zero. If the returned value of size is 0 the region should be
570  * discarded as it lies wholly above the memory limit.
571  */
572 static unsigned long __init numa_enforce_memory_limit(unsigned long start,
573                                                       unsigned long size)
574 {
575         /*
576          * We use memblock_end_of_DRAM() in here instead of memory_limit because
577          * we've already adjusted it for the limit and it takes care of
578          * having memory holes below the limit.  Also, in the case of
579          * iommu_is_off, memory_limit is not set but is implicitly enforced.
580          */
581
582         if (start + size <= memblock_end_of_DRAM())
583                 return size;
584
585         if (start >= memblock_end_of_DRAM())
586                 return 0;
587
588         return memblock_end_of_DRAM() - start;
589 }
590
591 /*
592  * Reads the counter for a given entry in
593  * linux,drconf-usable-memory property
594  */
595 static inline int __init read_usm_ranges(const u32 **usm)
596 {
597         /*
598          * For each lmb in ibm,dynamic-memory a corresponding
599          * entry in linux,drconf-usable-memory property contains
600          * a counter followed by that many (base, size) duple.
601          * read the counter from linux,drconf-usable-memory
602          */
603         return read_n_cells(n_mem_size_cells, usm);
604 }
605
606 /*
607  * Extract NUMA information from the ibm,dynamic-reconfiguration-memory
608  * node.  This assumes n_mem_{addr,size}_cells have been set.
609  */
610 static void __init parse_drconf_memory(struct device_node *memory)
611 {
612         const u32 *uninitialized_var(dm), *usm;
613         unsigned int n, rc, ranges, is_kexec_kdump = 0;
614         unsigned long lmb_size, base, size, sz;
615         int nid;
616         struct assoc_arrays aa = { .arrays = NULL };
617
618         n = of_get_drconf_memory(memory, &dm);
619         if (!n)
620                 return;
621
622         lmb_size = of_get_lmb_size(memory);
623         if (!lmb_size)
624                 return;
625
626         rc = of_get_assoc_arrays(memory, &aa);
627         if (rc)
628                 return;
629
630         /* check if this is a kexec/kdump kernel */
631         usm = of_get_usable_memory(memory);
632         if (usm != NULL)
633                 is_kexec_kdump = 1;
634
635         for (; n != 0; --n) {
636                 struct of_drconf_cell drmem;
637
638                 read_drconf_cell(&drmem, &dm);
639
640                 /* skip this block if the reserved bit is set in flags (0x80)
641                    or if the block is not assigned to this partition (0x8) */
642                 if ((drmem.flags & DRCONF_MEM_RESERVED)
643                     || !(drmem.flags & DRCONF_MEM_ASSIGNED))
644                         continue;
645
646                 base = drmem.base_addr;
647                 size = lmb_size;
648                 ranges = 1;
649
650                 if (is_kexec_kdump) {
651                         ranges = read_usm_ranges(&usm);
652                         if (!ranges) /* there are no (base, size) duple */
653                                 continue;
654                 }
655                 do {
656                         if (is_kexec_kdump) {
657                                 base = read_n_cells(n_mem_addr_cells, &usm);
658                                 size = read_n_cells(n_mem_size_cells, &usm);
659                         }
660                         nid = of_drconf_to_nid_single(&drmem, &aa);
661                         fake_numa_create_new_node(
662                                 ((base + size) >> PAGE_SHIFT),
663                                            &nid);
664                         node_set_online(nid);
665                         sz = numa_enforce_memory_limit(base, size);
666                         if (sz)
667                                 memblock_set_node(base, sz, nid);
668                 } while (--ranges);
669         }
670 }
671
672 static int __init parse_numa_properties(void)
673 {
674         struct device_node *memory;
675         int default_nid = 0;
676         unsigned long i;
677
678         if (numa_enabled == 0) {
679                 printk(KERN_WARNING "NUMA disabled by user\n");
680                 return -1;
681         }
682
683         min_common_depth = find_min_common_depth();
684
685         if (min_common_depth < 0)
686                 return min_common_depth;
687
688         dbg("NUMA associativity depth for CPU/Memory: %d\n", min_common_depth);
689
690         /*
691          * Even though we connect cpus to numa domains later in SMP
692          * init, we need to know the node ids now. This is because
693          * each node to be onlined must have NODE_DATA etc backing it.
694          */
695         for_each_present_cpu(i) {
696                 struct device_node *cpu;
697                 int nid;
698
699                 cpu = of_get_cpu_node(i, NULL);
700                 BUG_ON(!cpu);
701                 nid = of_node_to_nid_single(cpu);
702                 of_node_put(cpu);
703
704                 /*
705                  * Don't fall back to default_nid yet -- we will plug
706                  * cpus into nodes once the memory scan has discovered
707                  * the topology.
708                  */
709                 if (nid < 0)
710                         continue;
711                 node_set_online(nid);
712         }
713
714         get_n_mem_cells(&n_mem_addr_cells, &n_mem_size_cells);
715
716         for_each_node_by_type(memory, "memory") {
717                 unsigned long start;
718                 unsigned long size;
719                 int nid;
720                 int ranges;
721                 const unsigned int *memcell_buf;
722                 unsigned int len;
723
724                 memcell_buf = of_get_property(memory,
725                         "linux,usable-memory", &len);
726                 if (!memcell_buf || len <= 0)
727                         memcell_buf = of_get_property(memory, "reg", &len);
728                 if (!memcell_buf || len <= 0)
729                         continue;
730
731                 /* ranges in cell */
732                 ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);
733 new_range:
734                 /* these are order-sensitive, and modify the buffer pointer */
735                 start = read_n_cells(n_mem_addr_cells, &memcell_buf);
736                 size = read_n_cells(n_mem_size_cells, &memcell_buf);
737
738                 /*
739                  * Assumption: either all memory nodes or none will
740                  * have associativity properties.  If none, then
741                  * everything goes to default_nid.
742                  */
743                 nid = of_node_to_nid_single(memory);
744                 if (nid < 0)
745                         nid = default_nid;
746
747                 fake_numa_create_new_node(((start + size) >> PAGE_SHIFT), &nid);
748                 node_set_online(nid);
749
750                 if (!(size = numa_enforce_memory_limit(start, size))) {
751                         if (--ranges)
752                                 goto new_range;
753                         else
754                                 continue;
755                 }
756
757                 memblock_set_node(start, size, nid);
758
759                 if (--ranges)
760                         goto new_range;
761         }
762
763         /*
764          * Now do the same thing for each MEMBLOCK listed in the
765          * ibm,dynamic-memory property in the
766          * ibm,dynamic-reconfiguration-memory node.
767          */
768         memory = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
769         if (memory)
770                 parse_drconf_memory(memory);
771
772         return 0;
773 }
774
775 static void __init setup_nonnuma(void)
776 {
777         unsigned long top_of_ram = memblock_end_of_DRAM();
778         unsigned long total_ram = memblock_phys_mem_size();
779         unsigned long start_pfn, end_pfn;
780         unsigned int nid = 0;
781         struct memblock_region *reg;
782
783         printk(KERN_DEBUG "Top of RAM: 0x%lx, Total RAM: 0x%lx\n",
784                top_of_ram, total_ram);
785         printk(KERN_DEBUG "Memory hole size: %ldMB\n",
786                (top_of_ram - total_ram) >> 20);
787
788         for_each_memblock(memory, reg) {
789                 start_pfn = memblock_region_memory_base_pfn(reg);
790                 end_pfn = memblock_region_memory_end_pfn(reg);
791
792                 fake_numa_create_new_node(end_pfn, &nid);
793                 memblock_set_node(PFN_PHYS(start_pfn),
794                                   PFN_PHYS(end_pfn - start_pfn), nid);
795                 node_set_online(nid);
796         }
797 }
798
799 void __init dump_numa_cpu_topology(void)
800 {
801         unsigned int node;
802         unsigned int cpu, count;
803
804         if (min_common_depth == -1 || !numa_enabled)
805                 return;
806
807         for_each_online_node(node) {
808                 printk(KERN_DEBUG "Node %d CPUs:", node);
809
810                 count = 0;
811                 /*
812                  * If we used a CPU iterator here we would miss printing
813                  * the holes in the cpumap.
814                  */
815                 for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
816                         if (cpumask_test_cpu(cpu,
817                                         node_to_cpumask_map[node])) {
818                                 if (count == 0)
819                                         printk(" %u", cpu);
820                                 ++count;
821                         } else {
822                                 if (count > 1)
823                                         printk("-%u", cpu - 1);
824                                 count = 0;
825                         }
826                 }
827
828                 if (count > 1)
829                         printk("-%u", nr_cpu_ids - 1);
830                 printk("\n");
831         }
832 }
833
834 static void __init dump_numa_memory_topology(void)
835 {
836         unsigned int node;
837         unsigned int count;
838
839         if (min_common_depth == -1 || !numa_enabled)
840                 return;
841
842         for_each_online_node(node) {
843                 unsigned long i;
844
845                 printk(KERN_DEBUG "Node %d Memory:", node);
846
847                 count = 0;
848
849                 for (i = 0; i < memblock_end_of_DRAM();
850                      i += (1 << SECTION_SIZE_BITS)) {
851                         if (early_pfn_to_nid(i >> PAGE_SHIFT) == node) {
852                                 if (count == 0)
853                                         printk(" 0x%lx", i);
854                                 ++count;
855                         } else {
856                                 if (count > 0)
857                                         printk("-0x%lx", i);
858                                 count = 0;
859                         }
860                 }
861
862                 if (count > 0)
863                         printk("-0x%lx", i);
864                 printk("\n");
865         }
866 }
867
868 /*
869  * Allocate some memory, satisfying the memblock or bootmem allocator where
870  * required. nid is the preferred node and end is the physical address of
871  * the highest address in the node.
872  *
873  * Returns the virtual address of the memory.
874  */
875 static void __init *careful_zallocation(int nid, unsigned long size,
876                                        unsigned long align,
877                                        unsigned long end_pfn)
878 {
879         void *ret;
880         int new_nid;
881         unsigned long ret_paddr;
882
883         ret_paddr = __memblock_alloc_base(size, align, end_pfn << PAGE_SHIFT);
884
885         /* retry over all memory */
886         if (!ret_paddr)
887                 ret_paddr = __memblock_alloc_base(size, align, memblock_end_of_DRAM());
888
889         if (!ret_paddr)
890                 panic("numa.c: cannot allocate %lu bytes for node %d",
891                       size, nid);
892
893         ret = __va(ret_paddr);
894
895         /*
896          * We initialize the nodes in numeric order: 0, 1, 2...
897          * and hand over control from the MEMBLOCK allocator to the
898          * bootmem allocator.  If this function is called for
899          * node 5, then we know that all nodes <5 are using the
900          * bootmem allocator instead of the MEMBLOCK allocator.
901          *
902          * So, check the nid from which this allocation came
903          * and double check to see if we need to use bootmem
904          * instead of the MEMBLOCK.  We don't free the MEMBLOCK memory
905          * since it would be useless.
906          */
907         new_nid = early_pfn_to_nid(ret_paddr >> PAGE_SHIFT);
908         if (new_nid < nid) {
909                 ret = __alloc_bootmem_node(NODE_DATA(new_nid),
910                                 size, align, 0);
911
912                 dbg("alloc_bootmem %p %lx\n", ret, size);
913         }
914
915         memset(ret, 0, size);
916         return ret;
917 }
918
919 static struct notifier_block __cpuinitdata ppc64_numa_nb = {
920         .notifier_call = cpu_numa_callback,
921         .priority = 1 /* Must run before sched domains notifier. */
922 };
923
924 static void __init mark_reserved_regions_for_nid(int nid)
925 {
926         struct pglist_data *node = NODE_DATA(nid);
927         struct memblock_region *reg;
928
929         for_each_memblock(reserved, reg) {
930                 unsigned long physbase = reg->base;
931                 unsigned long size = reg->size;
932                 unsigned long start_pfn = physbase >> PAGE_SHIFT;
933                 unsigned long end_pfn = PFN_UP(physbase + size);
934                 struct node_active_region node_ar;
935                 unsigned long node_end_pfn = node->node_start_pfn +
936                                              node->node_spanned_pages;
937
938                 /*
939                  * Check to make sure that this memblock.reserved area is
940                  * within the bounds of the node that we care about.
941                  * Checking the nid of the start and end points is not
942                  * sufficient because the reserved area could span the
943                  * entire node.
944                  */
945                 if (end_pfn <= node->node_start_pfn ||
946                     start_pfn >= node_end_pfn)
947                         continue;
948
949                 get_node_active_region(start_pfn, &node_ar);
950                 while (start_pfn < end_pfn &&
951                         node_ar.start_pfn < node_ar.end_pfn) {
952                         unsigned long reserve_size = size;
953                         /*
954                          * if reserved region extends past active region
955                          * then trim size to active region
956                          */
957                         if (end_pfn > node_ar.end_pfn)
958                                 reserve_size = (node_ar.end_pfn << PAGE_SHIFT)
959                                         - physbase;
960                         /*
961                          * Only worry about *this* node, others may not
962                          * yet have valid NODE_DATA().
963                          */
964                         if (node_ar.nid == nid) {
965                                 dbg("reserve_bootmem %lx %lx nid=%d\n",
966                                         physbase, reserve_size, node_ar.nid);
967                                 reserve_bootmem_node(NODE_DATA(node_ar.nid),
968                                                 physbase, reserve_size,
969                                                 BOOTMEM_DEFAULT);
970                         }
971                         /*
972                          * if reserved region is contained in the active region
973                          * then done.
974                          */
975                         if (end_pfn <= node_ar.end_pfn)
976                                 break;
977
978                         /*
979                          * reserved region extends past the active region
980                          *   get next active region that contains this
981                          *   reserved region
982                          */
983                         start_pfn = node_ar.end_pfn;
984                         physbase = start_pfn << PAGE_SHIFT;
985                         size = size - reserve_size;
986                         get_node_active_region(start_pfn, &node_ar);
987                 }
988         }
989 }
990
991
992 void __init do_init_bootmem(void)
993 {
994         int nid;
995
996         min_low_pfn = 0;
997         max_low_pfn = memblock_end_of_DRAM() >> PAGE_SHIFT;
998         max_pfn = max_low_pfn;
999
1000         if (parse_numa_properties())
1001                 setup_nonnuma();
1002         else
1003                 dump_numa_memory_topology();
1004
1005         for_each_online_node(nid) {
1006                 unsigned long start_pfn, end_pfn;
1007                 void *bootmem_vaddr;
1008                 unsigned long bootmap_pages;
1009
1010                 get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
1011
1012                 /*
1013                  * Allocate the node structure node local if possible
1014                  *
1015                  * Be careful moving this around, as it relies on all
1016                  * previous nodes' bootmem to be initialized and have
1017                  * all reserved areas marked.
1018                  */
1019                 NODE_DATA(nid) = careful_zallocation(nid,
1020                                         sizeof(struct pglist_data),
1021                                         SMP_CACHE_BYTES, end_pfn);
1022
1023                 dbg("node %d\n", nid);
1024                 dbg("NODE_DATA() = %p\n", NODE_DATA(nid));
1025
1026                 NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
1027                 NODE_DATA(nid)->node_start_pfn = start_pfn;
1028                 NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
1029
1030                 if (NODE_DATA(nid)->node_spanned_pages == 0)
1031                         continue;
1032
1033                 dbg("start_paddr = %lx\n", start_pfn << PAGE_SHIFT);
1034                 dbg("end_paddr = %lx\n", end_pfn << PAGE_SHIFT);
1035
1036                 bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
1037                 bootmem_vaddr = careful_zallocation(nid,
1038                                         bootmap_pages << PAGE_SHIFT,
1039                                         PAGE_SIZE, end_pfn);
1040
1041                 dbg("bootmap_vaddr = %p\n", bootmem_vaddr);
1042
1043                 init_bootmem_node(NODE_DATA(nid),
1044                                   __pa(bootmem_vaddr) >> PAGE_SHIFT,
1045                                   start_pfn, end_pfn);
1046
1047                 free_bootmem_with_active_regions(nid, end_pfn);
1048                 /*
1049                  * Be very careful about moving this around.  Future
1050                  * calls to careful_zallocation() depend on this getting
1051                  * done correctly.
1052                  */
1053                 mark_reserved_regions_for_nid(nid);
1054                 sparse_memory_present_with_active_regions(nid);
1055         }
1056
1057         init_bootmem_done = 1;
1058
1059         /*
1060          * Now bootmem is initialised we can create the node to cpumask
1061          * lookup tables and setup the cpu callback to populate them.
1062          */
1063         setup_node_to_cpumask_map();
1064
1065         register_cpu_notifier(&ppc64_numa_nb);
1066         cpu_numa_callback(&ppc64_numa_nb, CPU_UP_PREPARE,
1067                           (void *)(unsigned long)boot_cpuid);
1068 }
1069
1070 void __init paging_init(void)
1071 {
1072         unsigned long max_zone_pfns[MAX_NR_ZONES];
1073         memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
1074         max_zone_pfns[ZONE_DMA] = memblock_end_of_DRAM() >> PAGE_SHIFT;
1075         free_area_init_nodes(max_zone_pfns);
1076 }
1077
1078 static int __init early_numa(char *p)
1079 {
1080         if (!p)
1081                 return 0;
1082
1083         if (strstr(p, "off"))
1084                 numa_enabled = 0;
1085
1086         if (strstr(p, "debug"))
1087                 numa_debug = 1;
1088
1089         p = strstr(p, "fake=");
1090         if (p)
1091                 cmdline = p + strlen("fake=");
1092
1093         return 0;
1094 }
1095 early_param("numa", early_numa);
1096
1097 #ifdef CONFIG_MEMORY_HOTPLUG
1098 /*
1099  * Find the node associated with a hot added memory section for
1100  * memory represented in the device tree by the property
1101  * ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory.
1102  */
1103 static int hot_add_drconf_scn_to_nid(struct device_node *memory,
1104                                      unsigned long scn_addr)
1105 {
1106         const u32 *dm;
1107         unsigned int drconf_cell_cnt, rc;
1108         unsigned long lmb_size;
1109         struct assoc_arrays aa;
1110         int nid = -1;
1111
1112         drconf_cell_cnt = of_get_drconf_memory(memory, &dm);
1113         if (!drconf_cell_cnt)
1114                 return -1;
1115
1116         lmb_size = of_get_lmb_size(memory);
1117         if (!lmb_size)
1118                 return -1;
1119
1120         rc = of_get_assoc_arrays(memory, &aa);
1121         if (rc)
1122                 return -1;
1123
1124         for (; drconf_cell_cnt != 0; --drconf_cell_cnt) {
1125                 struct of_drconf_cell drmem;
1126
1127                 read_drconf_cell(&drmem, &dm);
1128
1129                 /* skip this block if it is reserved or not assigned to
1130                  * this partition */
1131                 if ((drmem.flags & DRCONF_MEM_RESERVED)
1132                     || !(drmem.flags & DRCONF_MEM_ASSIGNED))
1133                         continue;
1134
1135                 if ((scn_addr < drmem.base_addr)
1136                     || (scn_addr >= (drmem.base_addr + lmb_size)))
1137                         continue;
1138
1139                 nid = of_drconf_to_nid_single(&drmem, &aa);
1140                 break;
1141         }
1142
1143         return nid;
1144 }
1145
1146 /*
1147  * Find the node associated with a hot added memory section for memory
1148  * represented in the device tree as a node (i.e. memory@XXXX) for
1149  * each memblock.
1150  */
1151 int hot_add_node_scn_to_nid(unsigned long scn_addr)
1152 {
1153         struct device_node *memory;
1154         int nid = -1;
1155
1156         for_each_node_by_type(memory, "memory") {
1157                 unsigned long start, size;
1158                 int ranges;
1159                 const unsigned int *memcell_buf;
1160                 unsigned int len;
1161
1162                 memcell_buf = of_get_property(memory, "reg", &len);
1163                 if (!memcell_buf || len <= 0)
1164                         continue;
1165
1166                 /* ranges in cell */
1167                 ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);
1168
1169                 while (ranges--) {
1170                         start = read_n_cells(n_mem_addr_cells, &memcell_buf);
1171                         size = read_n_cells(n_mem_size_cells, &memcell_buf);
1172
1173                         if ((scn_addr < start) || (scn_addr >= (start + size)))
1174                                 continue;
1175
1176                         nid = of_node_to_nid_single(memory);
1177                         break;
1178                 }
1179
1180                 if (nid >= 0)
1181                         break;
1182         }
1183
1184         of_node_put(memory);
1185
1186         return nid;
1187 }
1188
1189 /*
1190  * Find the node associated with a hot added memory section.  Section
1191  * corresponds to a SPARSEMEM section, not an MEMBLOCK.  It is assumed that
1192  * sections are fully contained within a single MEMBLOCK.
1193  */
1194 int hot_add_scn_to_nid(unsigned long scn_addr)
1195 {
1196         struct device_node *memory = NULL;
1197         int nid, found = 0;
1198
1199         if (!numa_enabled || (min_common_depth < 0))
1200                 return first_online_node;
1201
1202         memory = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
1203         if (memory) {
1204                 nid = hot_add_drconf_scn_to_nid(memory, scn_addr);
1205                 of_node_put(memory);
1206         } else {
1207                 nid = hot_add_node_scn_to_nid(scn_addr);
1208         }
1209
1210         if (nid < 0 || !node_online(nid))
1211                 nid = first_online_node;
1212
1213         if (NODE_DATA(nid)->node_spanned_pages)
1214                 return nid;
1215
1216         for_each_online_node(nid) {
1217                 if (NODE_DATA(nid)->node_spanned_pages) {
1218                         found = 1;
1219                         break;
1220                 }
1221         }
1222
1223         BUG_ON(!found);
1224         return nid;
1225 }
1226
1227 static u64 hot_add_drconf_memory_max(void)
1228 {
1229         struct device_node *memory = NULL;
1230         unsigned int drconf_cell_cnt = 0;
1231         u64 lmb_size = 0;
1232         const u32 *dm = 0;
1233
1234         memory = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
1235         if (memory) {
1236                 drconf_cell_cnt = of_get_drconf_memory(memory, &dm);
1237                 lmb_size = of_get_lmb_size(memory);
1238                 of_node_put(memory);
1239         }
1240         return lmb_size * drconf_cell_cnt;
1241 }
1242
1243 /*
1244  * memory_hotplug_max - return max address of memory that may be added
1245  *
1246  * This is currently only used on systems that support drconfig memory
1247  * hotplug.
1248  */
1249 u64 memory_hotplug_max(void)
1250 {
1251         return max(hot_add_drconf_memory_max(), memblock_end_of_DRAM());
1252 }
1253 #endif /* CONFIG_MEMORY_HOTPLUG */
1254
1255 /* Virtual Processor Home Node (VPHN) support */
1256 #ifdef CONFIG_PPC_SPLPAR
1257 static u8 vphn_cpu_change_counts[NR_CPUS][MAX_DISTANCE_REF_POINTS];
1258 static cpumask_t cpu_associativity_changes_mask;
1259 static int vphn_enabled;
1260 static void set_topology_timer(void);
1261
1262 /*
1263  * Store the current values of the associativity change counters in the
1264  * hypervisor.
1265  */
1266 static void setup_cpu_associativity_change_counters(void)
1267 {
1268         int cpu;
1269
1270         /* The VPHN feature supports a maximum of 8 reference points */
1271         BUILD_BUG_ON(MAX_DISTANCE_REF_POINTS > 8);
1272
1273         for_each_possible_cpu(cpu) {
1274                 int i;
1275                 u8 *counts = vphn_cpu_change_counts[cpu];
1276                 volatile u8 *hypervisor_counts = lppaca[cpu].vphn_assoc_counts;
1277
1278                 for (i = 0; i < distance_ref_points_depth; i++)
1279                         counts[i] = hypervisor_counts[i];
1280         }
1281 }
1282
1283 /*
1284  * The hypervisor maintains a set of 8 associativity change counters in
1285  * the VPA of each cpu that correspond to the associativity levels in the
1286  * ibm,associativity-reference-points property. When an associativity
1287  * level changes, the corresponding counter is incremented.
1288  *
1289  * Set a bit in cpu_associativity_changes_mask for each cpu whose home
1290  * node associativity levels have changed.
1291  *
1292  * Returns the number of cpus with unhandled associativity changes.
1293  */
1294 static int update_cpu_associativity_changes_mask(void)
1295 {
1296         int cpu, nr_cpus = 0;
1297         cpumask_t *changes = &cpu_associativity_changes_mask;
1298
1299         cpumask_clear(changes);
1300
1301         for_each_possible_cpu(cpu) {
1302                 int i, changed = 0;
1303                 u8 *counts = vphn_cpu_change_counts[cpu];
1304                 volatile u8 *hypervisor_counts = lppaca[cpu].vphn_assoc_counts;
1305
1306                 for (i = 0; i < distance_ref_points_depth; i++) {
1307                         if (hypervisor_counts[i] != counts[i]) {
1308                                 counts[i] = hypervisor_counts[i];
1309                                 changed = 1;
1310                         }
1311                 }
1312                 if (changed) {
1313                         cpumask_set_cpu(cpu, changes);
1314                         nr_cpus++;
1315                 }
1316         }
1317
1318         return nr_cpus;
1319 }
1320
1321 /*
1322  * 6 64-bit registers unpacked into 12 32-bit associativity values. To form
1323  * the complete property we have to add the length in the first cell.
1324  */
1325 #define VPHN_ASSOC_BUFSIZE (6*sizeof(u64)/sizeof(u32) + 1)
1326
1327 /*
1328  * Convert the associativity domain numbers returned from the hypervisor
1329  * to the sequence they would appear in the ibm,associativity property.
1330  */
1331 static int vphn_unpack_associativity(const long *packed, unsigned int *unpacked)
1332 {
1333         int i, nr_assoc_doms = 0;
1334         const u16 *field = (const u16*) packed;
1335
1336 #define VPHN_FIELD_UNUSED       (0xffff)
1337 #define VPHN_FIELD_MSB          (0x8000)
1338 #define VPHN_FIELD_MASK         (~VPHN_FIELD_MSB)
1339
1340         for (i = 1; i < VPHN_ASSOC_BUFSIZE; i++) {
1341                 if (*field == VPHN_FIELD_UNUSED) {
1342                         /* All significant fields processed, and remaining
1343                          * fields contain the reserved value of all 1's.
1344                          * Just store them.
1345                          */
1346                         unpacked[i] = *((u32*)field);
1347                         field += 2;
1348                 } else if (*field & VPHN_FIELD_MSB) {
1349                         /* Data is in the lower 15 bits of this field */
1350                         unpacked[i] = *field & VPHN_FIELD_MASK;
1351                         field++;
1352                         nr_assoc_doms++;
1353                 } else {
1354                         /* Data is in the lower 15 bits of this field
1355                          * concatenated with the next 16 bit field
1356                          */
1357                         unpacked[i] = *((u32*)field);
1358                         field += 2;
1359                         nr_assoc_doms++;
1360                 }
1361         }
1362
1363         /* The first cell contains the length of the property */
1364         unpacked[0] = nr_assoc_doms;
1365
1366         return nr_assoc_doms;
1367 }
1368
1369 /*
1370  * Retrieve the new associativity information for a virtual processor's
1371  * home node.
1372  */
1373 static long hcall_vphn(unsigned long cpu, unsigned int *associativity)
1374 {
1375         long rc;
1376         long retbuf[PLPAR_HCALL9_BUFSIZE] = {0};
1377         u64 flags = 1;
1378         int hwcpu = get_hard_smp_processor_id(cpu);
1379
1380         rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, retbuf, flags, hwcpu);
1381         vphn_unpack_associativity(retbuf, associativity);
1382
1383         return rc;
1384 }
1385
1386 static long vphn_get_associativity(unsigned long cpu,
1387                                         unsigned int *associativity)
1388 {
1389         long rc;
1390
1391         rc = hcall_vphn(cpu, associativity);
1392
1393         switch (rc) {
1394         case H_FUNCTION:
1395                 printk(KERN_INFO
1396                         "VPHN is not supported. Disabling polling...\n");
1397                 stop_topology_update();
1398                 break;
1399         case H_HARDWARE:
1400                 printk(KERN_ERR
1401                         "hcall_vphn() experienced a hardware fault "
1402                         "preventing VPHN. Disabling polling...\n");
1403                 stop_topology_update();
1404         }
1405
1406         return rc;
1407 }
1408
1409 /*
1410  * Update the node maps and sysfs entries for each cpu whose home node
1411  * has changed. Returns 1 when the topology has changed, and 0 otherwise.
1412  */
1413 int arch_update_cpu_topology(void)
1414 {
1415         int cpu, nid, old_nid, changed = 0;
1416         unsigned int associativity[VPHN_ASSOC_BUFSIZE] = {0};
1417         struct device *dev;
1418
1419         for_each_cpu(cpu,&cpu_associativity_changes_mask) {
1420                 vphn_get_associativity(cpu, associativity);
1421                 nid = associativity_to_nid(associativity);
1422
1423                 if (nid < 0 || !node_online(nid))
1424                         nid = first_online_node;
1425
1426                 old_nid = numa_cpu_lookup_table[cpu];
1427
1428                 /* Disable hotplug while we update the cpu
1429                  * masks and sysfs.
1430                  */
1431                 get_online_cpus();
1432                 unregister_cpu_under_node(cpu, old_nid);
1433                 unmap_cpu_from_node(cpu);
1434                 map_cpu_to_node(cpu, nid);
1435                 register_cpu_under_node(cpu, nid);
1436                 put_online_cpus();
1437
1438                 dev = get_cpu_device(cpu);
1439                 if (dev)
1440                         kobject_uevent(&dev->kobj, KOBJ_CHANGE);
1441                 changed = 1;
1442         }
1443
1444         return changed;
1445 }
1446
1447 static void topology_work_fn(struct work_struct *work)
1448 {
1449         rebuild_sched_domains();
1450 }
1451 static DECLARE_WORK(topology_work, topology_work_fn);
1452
1453 void topology_schedule_update(void)
1454 {
1455         schedule_work(&topology_work);
1456 }
1457
1458 static void topology_timer_fn(unsigned long ignored)
1459 {
1460         if (!vphn_enabled)
1461                 return;
1462         if (update_cpu_associativity_changes_mask() > 0)
1463                 topology_schedule_update();
1464         set_topology_timer();
1465 }
1466 static struct timer_list topology_timer =
1467         TIMER_INITIALIZER(topology_timer_fn, 0, 0);
1468
1469 static void set_topology_timer(void)
1470 {
1471         topology_timer.data = 0;
1472         topology_timer.expires = jiffies + 60 * HZ;
1473         add_timer(&topology_timer);
1474 }
1475
1476 /*
1477  * Start polling for VPHN associativity changes.
1478  */
1479 int start_topology_update(void)
1480 {
1481         int rc = 0;
1482
1483         /* Disabled until races with load balancing are fixed */
1484         if (0 && firmware_has_feature(FW_FEATURE_VPHN) &&
1485             get_lppaca()->shared_proc) {
1486                 vphn_enabled = 1;
1487                 setup_cpu_associativity_change_counters();
1488                 init_timer_deferrable(&topology_timer);
1489                 set_topology_timer();
1490                 rc = 1;
1491         }
1492
1493         return rc;
1494 }
1495 __initcall(start_topology_update);
1496
1497 /*
1498  * Disable polling for VPHN associativity changes.
1499  */
1500 int stop_topology_update(void)
1501 {
1502         vphn_enabled = 0;
1503         return del_timer_sync(&topology_timer);
1504 }
1505 #endif /* CONFIG_PPC_SPLPAR */