/*1* This program is free software; you can redistribute it and/or modify2* it under the terms of the GNU General Public License as published by3* the Free Software Foundation; either version 2 of the License, or4* (at your option) any later version.5*6* This program is distributed in the hope that it will be useful,7* but WITHOUT ANY WARRANTY; without even the implied warranty of8* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9* GNU General Public License for more details.10*11* You should have received a copy of the GNU General Public License12* along with this program; if not, write to the Free Software13* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA14*15* ia64 kernel NUMA specific stuff16*17* Copyright (C) 2002 Erich Focht <[email protected]>18* Copyright (C) 2004 Silicon Graphics, Inc.19* Jesse Barnes <[email protected]>20*/21#include <linux/topology.h>22#include <linux/module.h>23#include <asm/processor.h>24#include <asm/smp.h>2526u16 cpu_to_node_map[NR_CPUS] __cacheline_aligned;27EXPORT_SYMBOL(cpu_to_node_map);2829cpumask_t node_to_cpu_mask[MAX_NUMNODES] __cacheline_aligned;30EXPORT_SYMBOL(node_to_cpu_mask);3132void __cpuinit map_cpu_to_node(int cpu, int nid)33{34int oldnid;35if (nid < 0) { /* just initialize by zero */36cpu_to_node_map[cpu] = 0;37return;38}39/* sanity check first */40oldnid = cpu_to_node_map[cpu];41if (cpu_isset(cpu, node_to_cpu_mask[oldnid])) {42return; /* nothing to do */43}44/* we don't have cpu-driven node hot add yet...45In usual case, node is created from SRAT at boot time. */46if (!node_online(nid))47nid = first_online_node;48cpu_to_node_map[cpu] = nid;49cpu_set(cpu, node_to_cpu_mask[nid]);50return;51}5253void __cpuinit unmap_cpu_from_node(int cpu, int nid)54{55WARN_ON(!cpu_isset(cpu, node_to_cpu_mask[nid]));56WARN_ON(cpu_to_node_map[cpu] != nid);57cpu_to_node_map[cpu] = 0;58cpu_clear(cpu, node_to_cpu_mask[nid]);59}606162/**63* build_cpu_to_node_map - setup cpu to node and node to cpumask arrays64*65* Build cpu to node mapping and initialize the per node cpu masks using66* info from the node_cpuid array handed to us by ACPI.67*/68void __init build_cpu_to_node_map(void)69{70int cpu, i, node;7172for(node=0; node < MAX_NUMNODES; node++)73cpus_clear(node_to_cpu_mask[node]);7475for_each_possible_early_cpu(cpu) {76node = -1;77for (i = 0; i < NR_CPUS; ++i)78if (cpu_physical_id(cpu) == node_cpuid[i].phys_id) {79node = node_cpuid[i].nid;80break;81}82map_cpu_to_node(cpu, node);83}84}858687