From: Yasunori Goto Consolidate the various arch-specific implementations of pxm_to_node() and node_to_pxm() into a single generic version. Signed-off-by: Yasunori Goto Cc: "Luck, Tony" Cc: Andi Kleen Cc: Dave Hansen Cc: "Brown, Len" Signed-off-by: Andrew Morton --- arch/i386/Kconfig | 6 +++ arch/i386/kernel/srat.c | 19 +---------- arch/ia64/hp/common/sba_iommu.c | 2 - arch/ia64/kernel/acpi.c | 24 +++++---------- arch/ia64/pci/pci.c | 2 - arch/ia64/sn/kernel/setup.c | 4 +- arch/x86_64/mm/srat.c | 31 ------------------- drivers/acpi/Kconfig | 2 - drivers/acpi/numa.c | 48 ++++++++++++++++++++++++++++++ include/acpi/acpi_numa.h | 23 ++++++++++++++ include/asm-x86_64/numa.h | 1 include/linux/acpi.h | 9 +++++ asm-ia64/acpi.h | 0 13 files changed, 102 insertions(+), 69 deletions(-) diff -puN drivers/acpi/numa.c~unify-pxm_to_node-and-node_to_pxm drivers/acpi/numa.c --- devel/drivers/acpi/numa.c~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/drivers/acpi/numa.c 2006-05-11 15:18:53.000000000 -0700 @@ -36,12 +36,60 @@ #define _COMPONENT ACPI_NUMA ACPI_MODULE_NAME("numa") +static nodemask_t nodes_found_map = NODE_MASK_NONE; +#define PXM_INVAL -1 +#define NID_INVAL -1 + +/* maps to convert between proximity domain and logical node ID */ +int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS] + = { [0 ... MAX_PXM_DOMAINS - 1] = NID_INVAL }; +int __cpuinitdata node_to_pxm_map[MAX_NUMNODES] + = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL }; + extern int __init acpi_table_parse_madt_family(enum acpi_table_id id, unsigned long madt_size, int entry_id, acpi_madt_entry_handler handler, unsigned int max_entries); +int __cpuinit pxm_to_node(int pxm) +{ + if (pxm < 0) + return NID_INVAL; + return pxm_to_node_map[pxm]; +} + +int __cpuinit node_to_pxm(int node) +{ + if (node < 0) + return PXM_INVAL; + return node_to_pxm_map[node]; +} + +int __cpuinit acpi_map_pxm_to_node(int pxm) +{ + int node = pxm_to_node_map[pxm]; + + if (node < 0){ + if (nodes_weight(nodes_found_map) >= MAX_NUMNODES) + return NID_INVAL; + node = first_unset_node(nodes_found_map); + pxm_to_node_map[pxm] = node; + node_to_pxm_map[node] = pxm; + node_set(node, nodes_found_map); + } + + return node; +} + +void __cpuinit acpi_unmap_pxm_to_node(int node) +{ + int pxm = node_to_pxm_map[node]; + pxm_to_node_map[pxm] = NID_INVAL; + node_to_pxm_map[node] = PXM_INVAL; + node_clear(node, nodes_found_map); +} + void __init acpi_table_print_srat_entry(acpi_table_entry_header * header) { diff -puN /dev/null include/acpi/acpi_numa.h --- /dev/null 2003-09-15 06:40:47.000000000 -0700 +++ devel-akpm/include/acpi/acpi_numa.h 2006-05-11 15:18:53.000000000 -0700 @@ -0,0 +1,23 @@ +#ifndef __ACPI_NUMA_H +#define __ACPI_NUMA_H + +#ifdef CONFIG_ACPI_NUMA +#include + +/* Proximity bitmap length */ +#if MAX_NUMNODES > 256 +#define MAX_PXM_DOMAINS MAX_NUMNODES +#else +#define MAX_PXM_DOMAINS (256) /* Old pxm spec is defined 8 bit */ +#endif + +extern int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS]; +extern int __cpuinitdata node_to_pxm_map[MAX_NUMNODES]; + +extern int __cpuinit pxm_to_node(int); +extern int __cpuinit node_to_pxm(int); +extern int __cpuinit acpi_map_pxm_to_node(int); +extern void __cpuinit acpi_unmap_pxm_to_node(int); + +#endif /* CONFIG_ACPI_NUMA */ +#endif /* __ACP_NUMA_H */ diff -puN include/linux/acpi.h~unify-pxm_to_node-and-node_to_pxm include/linux/acpi.h --- devel/include/linux/acpi.h~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/include/linux/acpi.h 2006-05-11 15:18:53.000000000 -0700 @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -407,10 +408,18 @@ void acpi_table_print_madt_entry (acpi_t void acpi_table_print_srat_entry (acpi_table_entry_header *srat); /* the following four functions are architecture-dependent */ +#ifdef CONFIG_HAVE_ARCH_PARSE_SRAT +#define NR_NODE_MEMBLKS MAX_NUMNODES +#define acpi_numa_slit_init(slit) do {} while (0) +#define acpi_numa_processor_affinity_init(pa) do {} while (0) +#define acpi_numa_memory_affinity_init(ma) do {} while (0) +#define acpi_numa_arch_fixup() do {} while (0) +#else void acpi_numa_slit_init (struct acpi_table_slit *slit); void acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa); void acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma); void acpi_numa_arch_fixup(void); +#endif #ifdef CONFIG_ACPI_HOTPLUG_CPU /* Arch dependent functions for cpu hotplug support */ diff -puN arch/ia64/hp/common/sba_iommu.c~unify-pxm_to_node-and-node_to_pxm arch/ia64/hp/common/sba_iommu.c --- devel/arch/ia64/hp/common/sba_iommu.c~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/arch/ia64/hp/common/sba_iommu.c 2006-05-11 15:18:53.000000000 -0700 @@ -1958,7 +1958,7 @@ sba_map_ioc_to_node(struct ioc *ioc, acp if (pxm < 0) return; - node = pxm_to_nid_map[pxm]; + node = pxm_to_node(pxm); if (node >= MAX_NUMNODES || !node_online(node)) return; diff -puN arch/ia64/kernel/acpi.c~unify-pxm_to_node-and-node_to_pxm arch/ia64/kernel/acpi.c --- devel/arch/ia64/kernel/acpi.c~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/arch/ia64/kernel/acpi.c 2006-05-11 15:18:53.000000000 -0700 @@ -415,9 +415,6 @@ static int __initdata srat_num_cpus; /* static u32 __devinitdata pxm_flag[PXM_FLAG_LEN]; #define pxm_bit_set(bit) (set_bit(bit,(void *)pxm_flag)) #define pxm_bit_test(bit) (test_bit(bit,(void *)pxm_flag)) -/* maps to convert between proximity domain and logical node ID */ -int __devinitdata pxm_to_nid_map[MAX_PXM_DOMAINS]; -int __initdata nid_to_pxm_map[MAX_NUMNODES]; static struct acpi_table_slit __initdata *slit_table; static int get_processor_proximity_domain(struct acpi_table_processor_affinity *pa) @@ -533,22 +530,17 @@ void __init acpi_numa_arch_fixup(void) * MCD - This can probably be dropped now. No need for pxm ID to node ID * mapping with sparse node numbering iff MAX_PXM_DOMAINS <= MAX_NUMNODES. */ - /* calculate total number of nodes in system from PXM bitmap */ - memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map)); - memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map)); nodes_clear(node_online_map); for (i = 0; i < MAX_PXM_DOMAINS; i++) { if (pxm_bit_test(i)) { - int nid = num_online_nodes(); - pxm_to_nid_map[i] = nid; - nid_to_pxm_map[nid] = i; + int nid = acpi_map_pxm_to_node(i); node_set_online(nid); } } /* set logical node id in memory chunk structure */ for (i = 0; i < num_node_memblks; i++) - node_memblk[i].nid = pxm_to_nid_map[node_memblk[i].nid]; + node_memblk[i].nid = pxm_to_node(node_memblk[i].nid); /* assign memory bank numbers for each chunk on each node */ for_each_online_node(i) { @@ -562,7 +554,7 @@ void __init acpi_numa_arch_fixup(void) /* set logical node id in cpu structure */ for (i = 0; i < srat_num_cpus; i++) - node_cpuid[i].nid = pxm_to_nid_map[node_cpuid[i].nid]; + node_cpuid[i].nid = pxm_to_node(node_cpuid[i].nid); printk(KERN_INFO "Number of logical nodes in system = %d\n", num_online_nodes()); @@ -575,11 +567,11 @@ void __init acpi_numa_arch_fixup(void) for (i = 0; i < slit_table->localities; i++) { if (!pxm_bit_test(i)) continue; - node_from = pxm_to_nid_map[i]; + node_from = pxm_to_node(i); for (j = 0; j < slit_table->localities; j++) { if (!pxm_bit_test(j)) continue; - node_to = pxm_to_nid_map[j]; + node_to = pxm_to_node(j); node_distance(node_from, node_to) = slit_table->entry[i * slit_table->localities + j]; } @@ -785,9 +777,9 @@ int acpi_map_cpu2node(acpi_handle handle /* * Assuming that the container driver would have set the proximity - * domain and would have initialized pxm_to_nid_map[pxm_id] && pxm_flag + * domain and would have initialized pxm_to_node(pxm_id) && pxm_flag */ - node_cpuid[cpu].nid = (pxm_id < 0) ? 0 : pxm_to_nid_map[pxm_id]; + node_cpuid[cpu].nid = (pxm_id < 0) ? 0 : pxm_to_node(pxm_id); node_cpuid[cpu].phys_id = physid; #endif @@ -966,7 +958,7 @@ acpi_map_iosapic(acpi_handle handle, u32 if (pxm < 0) return AE_OK; - node = pxm_to_nid_map[pxm]; + node = pxm_to_node(pxm); if (node >= MAX_NUMNODES || !node_online(node) || cpus_empty(node_to_cpumask(node))) diff -puN arch/ia64/pci/pci.c~unify-pxm_to_node-and-node_to_pxm arch/ia64/pci/pci.c --- devel/arch/ia64/pci/pci.c~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/arch/ia64/pci/pci.c 2006-05-11 15:18:53.000000000 -0700 @@ -352,7 +352,7 @@ pci_acpi_scan_root(struct acpi_device *d pxm = acpi_get_pxm(controller->acpi_handle); #ifdef CONFIG_NUMA if (pxm >= 0) - controller->node = pxm_to_nid_map[pxm]; + controller->node = pxm_to_node(pxm); #endif acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_window, diff -puN arch/ia64/sn/kernel/setup.c~unify-pxm_to_node-and-node_to_pxm arch/ia64/sn/kernel/setup.c --- devel/arch/ia64/sn/kernel/setup.c~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/arch/ia64/sn/kernel/setup.c 2006-05-11 15:18:53.000000000 -0700 @@ -139,7 +139,7 @@ static int __init pxm_to_nasid(int pxm) int i; int nid; - nid = pxm_to_nid_map[pxm]; + nid = pxm_to_node(pxm); for (i = 0; i < num_node_memblks; i++) { if (node_memblk[i].nid == nid) { return NASID_GET(node_memblk[i].start_paddr); @@ -704,7 +704,7 @@ void __init build_cnode_tables(void) * cnode == node for all C & M bricks. */ for_each_online_node(node) { - nasid = pxm_to_nasid(nid_to_pxm_map[node]); + nasid = pxm_to_nasid(node_to_pxm(node)); sn_cnodeid_to_nasid[node] = nasid; physical_node_map[nasid] = node; } diff -puN include/asm-ia64/acpi.h~unify-pxm_to_node-and-node_to_pxm include/asm-ia64/acpi.h diff -puN arch/x86_64/mm/srat.c~unify-pxm_to_node-and-node_to_pxm arch/x86_64/mm/srat.c --- devel/arch/x86_64/mm/srat.c~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/arch/x86_64/mm/srat.c 2006-05-11 15:18:53.000000000 -0700 @@ -41,27 +41,9 @@ static u8 pxm2node[256] = { [0 ... 255] from BIOS bugs. */ #define NODE_MIN_SIZE (4*1024*1024) -static int node_to_pxm(int n); - -int pxm_to_node(int pxm) -{ - if ((unsigned)pxm >= 256) - return -1; - /* Extend 0xff to (int)-1 */ - return (signed char)pxm2node[pxm]; -} - static __init int setup_node(int pxm) { - unsigned node = pxm2node[pxm]; - if (node == 0xff) { - if (nodes_weight(nodes_found) >= MAX_NUMNODES) - return -1; - node = first_unset_node(nodes_found); - node_set(node, nodes_found); - pxm2node[pxm] = node; - } - return pxm2node[pxm]; + return acpi_map_pxm_to_node(pxm); } static __init int conflicting_nodes(unsigned long start, unsigned long end) @@ -434,17 +416,6 @@ int __init acpi_scan_nodes(unsigned long return 0; } -static int node_to_pxm(int n) -{ - int i; - if (pxm2node[n] == n) - return n; - for (i = 0; i < 256; i++) - if (pxm2node[i] == n) - return i; - return 0; -} - void __init srat_reserve_add_area(int nodeid) { if (found_add_area && nodes_add[nodeid].end) { diff -puN include/asm-x86_64/numa.h~unify-pxm_to_node-and-node_to_pxm include/asm-x86_64/numa.h --- devel/include/asm-x86_64/numa.h~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/include/asm-x86_64/numa.h 2006-05-11 15:18:53.000000000 -0700 @@ -8,7 +8,6 @@ struct bootnode { }; extern int compute_hash_shift(struct bootnode *nodes, int numnodes); -extern int pxm_to_node(int nid); #define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT)) diff -puN arch/i386/Kconfig~unify-pxm_to_node-and-node_to_pxm arch/i386/Kconfig --- devel/arch/i386/Kconfig~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/arch/i386/Kconfig 2006-05-11 15:18:53.000000000 -0700 @@ -172,6 +172,12 @@ config ACPI_SRAT bool default y depends on NUMA && (X86_SUMMIT || X86_GENERICARCH) + select ACPI_NUMA + +config HAVE_ARCH_PARSE_SRAT + bool + default y + depends on ACPI_SRAT config X86_SUMMIT_NUMA bool diff -puN arch/i386/kernel/srat.c~unify-pxm_to_node-and-node_to_pxm arch/i386/kernel/srat.c --- devel/arch/i386/kernel/srat.c~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/arch/i386/kernel/srat.c 2006-05-11 15:18:53.000000000 -0700 @@ -39,7 +39,6 @@ #define NODE_ARRAY_OFFSET(x) ((x) % 8) /* 8 bits/char */ #define BMAP_SET(bmap, bit) ((bmap)[NODE_ARRAY_INDEX(bit)] |= 1 << NODE_ARRAY_OFFSET(bit)) #define BMAP_TEST(bmap, bit) ((bmap)[NODE_ARRAY_INDEX(bit)] & (1 << NODE_ARRAY_OFFSET(bit))) -#define MAX_PXM_DOMAINS 256 /* 1 byte and no promises about values */ /* bitmap length; _PXM is at most 255 */ #define PXM_BITMAP_LEN (MAX_PXM_DOMAINS / 8) static u8 pxm_bitmap[PXM_BITMAP_LEN]; /* bitmap of proximity domains */ @@ -167,19 +166,11 @@ static __init void node_read_chunk(int n node_end_pfn[nid] = memory_chunk->end_pfn; } -static u8 pxm_to_nid_map[MAX_PXM_DOMAINS];/* _PXM to logical node ID map */ - -int pxm_to_node(int pxm) -{ - return pxm_to_nid_map[pxm]; -} - /* Parse the ACPI Static Resource Affinity Table */ static int __init acpi20_parse_srat(struct acpi_table_srat *sratp) { u8 *start, *end, *p; int i, j, nid; - u8 nid_to_pxm_map[MAX_NUMNODES];/* logical node ID to _PXM map */ start = (u8 *)(&(sratp->reserved) + 1); /* skip header */ p = start; @@ -188,10 +179,6 @@ static int __init acpi20_parse_srat(stru memset(pxm_bitmap, 0, sizeof(pxm_bitmap)); /* init proximity domain bitmap */ memset(node_memory_chunk, 0, sizeof(node_memory_chunk)); - /* -1 in these maps means not available */ - memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map)); - memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map)); - num_memory_chunks = 0; while (p < end) { switch (*p) { @@ -231,9 +218,7 @@ static int __init acpi20_parse_srat(stru nodes_clear(node_online_map); for (i = 0; i < MAX_PXM_DOMAINS; i++) { if (BMAP_TEST(pxm_bitmap, i)) { - nid = num_online_nodes(); - pxm_to_nid_map[i] = nid; - nid_to_pxm_map[nid] = i; + int nid = acpi_map_pxm_to_node(i); node_set_online(nid); } } @@ -241,7 +226,7 @@ static int __init acpi20_parse_srat(stru /* set cnode id in memory chunk structure */ for (i = 0; i < num_memory_chunks; i++) - node_memory_chunk[i].nid = pxm_to_nid_map[node_memory_chunk[i].pxm]; + node_memory_chunk[i].nid = pxm_to_node(node_memory_chunk[i].pxm); printk("pxm bitmap: "); for (i = 0; i < sizeof(pxm_bitmap); i++) { diff -puN drivers/acpi/Kconfig~unify-pxm_to_node-and-node_to_pxm drivers/acpi/Kconfig --- devel/drivers/acpi/Kconfig~unify-pxm_to_node-and-node_to_pxm 2006-05-11 15:18:53.000000000 -0700 +++ devel-akpm/drivers/acpi/Kconfig 2006-05-11 15:18:53.000000000 -0700 @@ -168,7 +168,7 @@ config ACPI_THERMAL config ACPI_NUMA bool "NUMA support" depends on NUMA - depends on (IA64 || X86_64) + depends on (X86 || IA64) default y if IA64_GENERIC || IA64_SGI_SN2 config ACPI_ASUS _