srat.c 4.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * ACPI 3.0 based NUMA setup
 * Copyright 2004 Andi Kleen, SuSE Labs.
 *
 * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
 *
 * Called from acpi_numa_init while reading the SRAT and SLIT tables.
 * Assumes all memory regions belonging to a single proximity domain
 * are in one chunk. Holes between them will be included in the node.
 */

#include <linux/kernel.h>
#include <linux/acpi.h>
#include <linux/mmzone.h>
#include <linux/bitmap.h>
#include <linux/module.h>
#include <linux/topology.h>
18
#include <linux/bootmem.h>
19
#include <linux/memblock.h>
20
#include <linux/mm.h>
L
Linus Torvalds 已提交
21 22
#include <asm/proto.h>
#include <asm/numa.h>
23
#include <asm/e820.h>
I
Ingo Molnar 已提交
24
#include <asm/apic.h>
I
Ingo Molnar 已提交
25
#include <asm/uv/uv.h>
L
Linus Torvalds 已提交
26

A
Andi Kleen 已提交
27 28
int acpi_numa __initdata;

L
Linus Torvalds 已提交
29 30
static __init int setup_node(int pxm)
{
31
	return acpi_map_pxm_to_node(pxm);
L
Linus Torvalds 已提交
32 33 34 35 36 37 38 39 40 41
}

static __init void bad_srat(void)
{
	printk(KERN_ERR "SRAT: SRAT not used.\n");
	acpi_numa = -1;
}

static __init inline int srat_disabled(void)
{
42
	return acpi_numa < 0;
L
Linus Torvalds 已提交
43 44 45 46 47
}

/* Callback for SLIT parsing */
void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
{
48
	int i, j;
Y
Yinghai Lu 已提交
49

50 51 52 53
	for (i = 0; i < slit->locality_count; i++)
		for (j = 0; j < slit->locality_count; j++)
			numa_set_distance(pxm_to_node(i), pxm_to_node(j),
				slit->entry[slit->locality_count * i + j]);
L
Linus Torvalds 已提交
54 55
}

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
/* Callback for Proximity Domain -> x2APIC mapping */
void __init
acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
{
	int pxm, node;
	int apic_id;

	if (srat_disabled())
		return;
	if (pa->header.length < sizeof(struct acpi_srat_x2apic_cpu_affinity)) {
		bad_srat();
		return;
	}
	if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
		return;
	pxm = pa->proximity_domain;
	node = setup_node(pxm);
	if (node < 0) {
		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
		bad_srat();
		return;
	}

	apic_id = pa->apic_id;
80 81 82 83
	if (apic_id >= MAX_LOCAL_APIC) {
		printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
		return;
	}
84
	set_apicid_to_node(apic_id, node);
85
	node_set(node, numa_nodes_parsed);
86
	acpi_numa = 1;
87
	printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n",
88 89 90
	       pxm, apic_id, node);
}

L
Linus Torvalds 已提交
91 92
/* Callback for Proximity Domain -> LAPIC mapping */
void __init
93
acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
L
Linus Torvalds 已提交
94 95
{
	int pxm, node;
96 97
	int apic_id;

98 99
	if (srat_disabled())
		return;
100
	if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) {
101
		bad_srat();
102 103
		return;
	}
104
	if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
L
Linus Torvalds 已提交
105
		return;
106
	pxm = pa->proximity_domain_lo;
L
Linus Torvalds 已提交
107 108 109 110 111 112
	node = setup_node(pxm);
	if (node < 0) {
		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
		bad_srat();
		return;
	}
113

114
	if (get_uv_system_type() >= UV_X2APIC)
J
Jack Steiner 已提交
115 116 117
		apic_id = (pa->apic_id << 8) | pa->local_sapic_eid;
	else
		apic_id = pa->apic_id;
118 119 120 121 122 123

	if (apic_id >= MAX_LOCAL_APIC) {
		printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
		return;
	}

124
	set_apicid_to_node(apic_id, node);
125
	node_set(node, numa_nodes_parsed);
L
Linus Torvalds 已提交
126
	acpi_numa = 1;
127
	printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u\n",
128
	       pxm, apic_id, node);
L
Linus Torvalds 已提交
129 130
}

131
#ifdef CONFIG_MEMORY_HOTPLUG
132 133 134 135
static inline int save_add_info(void) {return 1;}
#else
static inline int save_add_info(void) {return 0;}
#endif
136

L
Linus Torvalds 已提交
137 138
/* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
void __init
139
acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
L
Linus Torvalds 已提交
140
{
T
Tejun Heo 已提交
141
	u64 start, end;
L
Linus Torvalds 已提交
142 143
	int node, pxm;

144
	if (srat_disabled())
L
Linus Torvalds 已提交
145
		return;
146
	if (ma->header.length != sizeof(struct acpi_srat_mem_affinity)) {
147 148 149
		bad_srat();
		return;
	}
150
	if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0)
151
		return;
152 153

	if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && !save_add_info())
154
		return;
155 156
	start = ma->base_address;
	end = start + ma->length;
L
Linus Torvalds 已提交
157 158 159 160 161 162 163
	pxm = ma->proximity_domain;
	node = setup_node(pxm);
	if (node < 0) {
		printk(KERN_ERR "SRAT: Too many proximity domains.\n");
		bad_srat();
		return;
	}
164 165

	if (numa_add_memblk(node, start, end) < 0) {
L
Linus Torvalds 已提交
166 167 168
		bad_srat();
		return;
	}
169

T
Tejun Heo 已提交
170
	printk(KERN_INFO "SRAT: Node %u PXM %u %Lx-%Lx\n", node, pxm,
171
	       start, end);
L
Linus Torvalds 已提交
172 173 174 175
}

void __init acpi_numa_arch_fixup(void) {}

176 177 178 179 180 181 182 183 184
int __init x86_acpi_numa_init(void)
{
	int ret;

	ret = acpi_numa_init();
	if (ret < 0)
		return ret;
	return srat_disabled() ? -EINVAL : 0;
}