srat.c 4.4 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;
107 108
	if (acpi_srat_revision >= 2)
		pxm |= *((unsigned int*)pa->proximity_domain_hi) << 8;
L
Linus Torvalds 已提交
109 110 111 112 113 114
	node = setup_node(pxm);
	if (node < 0) {
		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
		bad_srat();
		return;
	}
115

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

	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;
	}

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

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

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

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

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

	if (numa_add_memblk(node, start, end) < 0) {
L
Linus Torvalds 已提交
170 171 172
		bad_srat();
		return;
	}
173

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

void __init acpi_numa_arch_fixup(void) {}

180 181 182 183 184 185 186 187 188
int __init x86_acpi_numa_init(void)
{
	int ret;

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