xref: /freebsd/sys/x86/acpica/srat.c (revision 941646f5ec5d89c10dbc9a0ff3b412b52ae74002)
1dd540b46SJohn Baldwin /*-
2dd540b46SJohn Baldwin  * Copyright (c) 2010 Advanced Computing Technologies LLC
3dd540b46SJohn Baldwin  * Written by: John H. Baldwin <jhb@FreeBSD.org>
4dd540b46SJohn Baldwin  * All rights reserved.
5dd540b46SJohn Baldwin  *
6dd540b46SJohn Baldwin  * Redistribution and use in source and binary forms, with or without
7dd540b46SJohn Baldwin  * modification, are permitted provided that the following conditions
8dd540b46SJohn Baldwin  * are met:
9dd540b46SJohn Baldwin  * 1. Redistributions of source code must retain the above copyright
10dd540b46SJohn Baldwin  *    notice, this list of conditions and the following disclaimer.
11dd540b46SJohn Baldwin  * 2. Redistributions in binary form must reproduce the above copyright
12dd540b46SJohn Baldwin  *    notice, this list of conditions and the following disclaimer in the
13dd540b46SJohn Baldwin  *    documentation and/or other materials provided with the distribution.
14dd540b46SJohn Baldwin  *
15dd540b46SJohn Baldwin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16dd540b46SJohn Baldwin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17dd540b46SJohn Baldwin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18dd540b46SJohn Baldwin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19dd540b46SJohn Baldwin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20dd540b46SJohn Baldwin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21dd540b46SJohn Baldwin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22dd540b46SJohn Baldwin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23dd540b46SJohn Baldwin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24dd540b46SJohn Baldwin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25dd540b46SJohn Baldwin  * SUCH DAMAGE.
26dd540b46SJohn Baldwin  */
27dd540b46SJohn Baldwin 
28dd540b46SJohn Baldwin #include <sys/cdefs.h>
29dd540b46SJohn Baldwin __FBSDID("$FreeBSD$");
30dd540b46SJohn Baldwin 
31dd540b46SJohn Baldwin #include <sys/param.h>
32dd540b46SJohn Baldwin #include <sys/bus.h>
33dd540b46SJohn Baldwin #include <sys/kernel.h>
34dd540b46SJohn Baldwin #include <sys/smp.h>
35dd540b46SJohn Baldwin #include <vm/vm.h>
36dd540b46SJohn Baldwin #include <vm/pmap.h>
37dd540b46SJohn Baldwin #include <vm/vm_param.h>
38dd540b46SJohn Baldwin #include <vm/vm_phys.h>
39dd540b46SJohn Baldwin 
40dd540b46SJohn Baldwin #include <contrib/dev/acpica/include/acpi.h>
41dd540b46SJohn Baldwin #include <contrib/dev/acpica/include/actables.h>
42dd540b46SJohn Baldwin 
43dd540b46SJohn Baldwin #include <machine/intr_machdep.h>
44dd540b46SJohn Baldwin #include <machine/apicvar.h>
45dd540b46SJohn Baldwin 
46dd540b46SJohn Baldwin #include <dev/acpica/acpivar.h>
47dd540b46SJohn Baldwin 
48*941646f5SAttilio Rao #if MAXMEMDOM > 1
49dd540b46SJohn Baldwin struct cpu_info {
50dd540b46SJohn Baldwin 	int enabled:1;
51dd540b46SJohn Baldwin 	int has_memory:1;
52dd540b46SJohn Baldwin 	int domain;
53dd540b46SJohn Baldwin } cpus[MAX_APIC_ID + 1];
54dd540b46SJohn Baldwin 
55dd540b46SJohn Baldwin struct mem_affinity mem_info[VM_PHYSSEG_MAX + 1];
56dd540b46SJohn Baldwin int num_mem;
57dd540b46SJohn Baldwin 
58dd540b46SJohn Baldwin static ACPI_TABLE_SRAT *srat;
59dd540b46SJohn Baldwin static vm_paddr_t srat_physaddr;
60dd540b46SJohn Baldwin 
61dd540b46SJohn Baldwin static void	srat_walk_table(acpi_subtable_handler *handler, void *arg);
62dd540b46SJohn Baldwin 
634d99cfb3SJohn Baldwin /*
644d99cfb3SJohn Baldwin  * Returns true if a memory range overlaps with at least one range in
654d99cfb3SJohn Baldwin  * phys_avail[].
664d99cfb3SJohn Baldwin  */
674d99cfb3SJohn Baldwin static int
684d99cfb3SJohn Baldwin overlaps_phys_avail(vm_paddr_t start, vm_paddr_t end)
694d99cfb3SJohn Baldwin {
704d99cfb3SJohn Baldwin 	int i;
714d99cfb3SJohn Baldwin 
724d99cfb3SJohn Baldwin 	for (i = 0; phys_avail[i] != 0 && phys_avail[i + 1] != 0; i += 2) {
734d99cfb3SJohn Baldwin 		if (phys_avail[i + 1] < start)
744d99cfb3SJohn Baldwin 			continue;
754d99cfb3SJohn Baldwin 		if (phys_avail[i] < end)
764d99cfb3SJohn Baldwin 			return (1);
774d99cfb3SJohn Baldwin 		break;
784d99cfb3SJohn Baldwin 	}
794d99cfb3SJohn Baldwin 	return (0);
804d99cfb3SJohn Baldwin 
814d99cfb3SJohn Baldwin }
824d99cfb3SJohn Baldwin 
83dd540b46SJohn Baldwin static void
84dd540b46SJohn Baldwin srat_parse_entry(ACPI_SUBTABLE_HEADER *entry, void *arg)
85dd540b46SJohn Baldwin {
86dd540b46SJohn Baldwin 	ACPI_SRAT_CPU_AFFINITY *cpu;
87dd540b46SJohn Baldwin 	ACPI_SRAT_X2APIC_CPU_AFFINITY *x2apic;
88dd540b46SJohn Baldwin 	ACPI_SRAT_MEM_AFFINITY *mem;
89dd540b46SJohn Baldwin 	int domain, i, slot;
90dd540b46SJohn Baldwin 
91dd540b46SJohn Baldwin 	switch (entry->Type) {
92dd540b46SJohn Baldwin 	case ACPI_SRAT_TYPE_CPU_AFFINITY:
93dd540b46SJohn Baldwin 		cpu = (ACPI_SRAT_CPU_AFFINITY *)entry;
94dd540b46SJohn Baldwin 		domain = cpu->ProximityDomainLo |
95dd540b46SJohn Baldwin 		    cpu->ProximityDomainHi[0] << 8 |
96dd540b46SJohn Baldwin 		    cpu->ProximityDomainHi[1] << 16 |
97dd540b46SJohn Baldwin 		    cpu->ProximityDomainHi[2] << 24;
98dd540b46SJohn Baldwin 		if (bootverbose)
99dd540b46SJohn Baldwin 			printf("SRAT: Found CPU APIC ID %u domain %d: %s\n",
100dd540b46SJohn Baldwin 			    cpu->ApicId, domain,
101dd540b46SJohn Baldwin 			    (cpu->Flags & ACPI_SRAT_CPU_ENABLED) ?
102dd540b46SJohn Baldwin 			    "enabled" : "disabled");
103dd540b46SJohn Baldwin 		if (!(cpu->Flags & ACPI_SRAT_CPU_ENABLED))
104dd540b46SJohn Baldwin 			break;
105dd540b46SJohn Baldwin 		KASSERT(!cpus[cpu->ApicId].enabled,
106dd540b46SJohn Baldwin 		    ("Duplicate local APIC ID %u", cpu->ApicId));
107dd540b46SJohn Baldwin 		cpus[cpu->ApicId].domain = domain;
108dd540b46SJohn Baldwin 		cpus[cpu->ApicId].enabled = 1;
109dd540b46SJohn Baldwin 		break;
110dd540b46SJohn Baldwin 	case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY:
111dd540b46SJohn Baldwin 		x2apic = (ACPI_SRAT_X2APIC_CPU_AFFINITY *)entry;
112dd540b46SJohn Baldwin 		if (bootverbose)
113dd540b46SJohn Baldwin 			printf("SRAT: Found CPU APIC ID %u domain %d: %s\n",
114dd540b46SJohn Baldwin 			    x2apic->ApicId, x2apic->ProximityDomain,
115dd540b46SJohn Baldwin 			    (x2apic->Flags & ACPI_SRAT_CPU_ENABLED) ?
116dd540b46SJohn Baldwin 			    "enabled" : "disabled");
117dd540b46SJohn Baldwin 		if (!(x2apic->Flags & ACPI_SRAT_CPU_ENABLED))
118dd540b46SJohn Baldwin 			break;
119dd540b46SJohn Baldwin 		KASSERT(!cpus[x2apic->ApicId].enabled,
120dd540b46SJohn Baldwin 		    ("Duplicate local APIC ID %u", x2apic->ApicId));
121dd540b46SJohn Baldwin 		cpus[x2apic->ApicId].domain = x2apic->ProximityDomain;
122dd540b46SJohn Baldwin 		cpus[x2apic->ApicId].enabled = 1;
123dd540b46SJohn Baldwin 		break;
124dd540b46SJohn Baldwin 	case ACPI_SRAT_TYPE_MEMORY_AFFINITY:
125dd540b46SJohn Baldwin 		mem = (ACPI_SRAT_MEM_AFFINITY *)entry;
126dd540b46SJohn Baldwin 		if (bootverbose)
127dd540b46SJohn Baldwin 			printf(
128dd540b46SJohn Baldwin 		    "SRAT: Found memory domain %d addr %jx len %jx: %s\n",
129dd540b46SJohn Baldwin 			    mem->ProximityDomain, (uintmax_t)mem->BaseAddress,
130dd540b46SJohn Baldwin 			    (uintmax_t)mem->Length,
131dd540b46SJohn Baldwin 			    (mem->Flags & ACPI_SRAT_MEM_ENABLED) ?
132dd540b46SJohn Baldwin 			    "enabled" : "disabled");
133dd540b46SJohn Baldwin 		if (!(mem->Flags & ACPI_SRAT_MEM_ENABLED))
134dd540b46SJohn Baldwin 			break;
1354d99cfb3SJohn Baldwin 		if (!overlaps_phys_avail(mem->BaseAddress,
1364d99cfb3SJohn Baldwin 		    mem->BaseAddress + mem->Length)) {
1374d99cfb3SJohn Baldwin 			printf("SRAT: Ignoring memory at addr %jx\n",
1384d99cfb3SJohn Baldwin 			    (uintmax_t)mem->BaseAddress);
1394d99cfb3SJohn Baldwin 			break;
1404d99cfb3SJohn Baldwin 		}
141dd540b46SJohn Baldwin 		if (num_mem == VM_PHYSSEG_MAX) {
142dd540b46SJohn Baldwin 			printf("SRAT: Too many memory regions\n");
143dd540b46SJohn Baldwin 			*(int *)arg = ENXIO;
144dd540b46SJohn Baldwin 			break;
145dd540b46SJohn Baldwin 		}
146dd540b46SJohn Baldwin 		slot = num_mem;
147dd540b46SJohn Baldwin 		for (i = 0; i < num_mem; i++) {
148dd540b46SJohn Baldwin 			if (mem_info[i].end <= mem->BaseAddress)
149dd540b46SJohn Baldwin 				continue;
150dd540b46SJohn Baldwin 			if (mem_info[i].start <
151dd540b46SJohn Baldwin 			    (mem->BaseAddress + mem->Length)) {
152dd540b46SJohn Baldwin 				printf("SRAT: Overlapping memory entries\n");
153dd540b46SJohn Baldwin 				*(int *)arg = ENXIO;
154dd540b46SJohn Baldwin 				return;
155dd540b46SJohn Baldwin 			}
156dd540b46SJohn Baldwin 			slot = i;
157dd540b46SJohn Baldwin 		}
158dd540b46SJohn Baldwin 		for (i = num_mem; i > slot; i--)
159dd540b46SJohn Baldwin 			mem_info[i] = mem_info[i - 1];
160dd540b46SJohn Baldwin 		mem_info[slot].start = mem->BaseAddress;
161dd540b46SJohn Baldwin 		mem_info[slot].end = mem->BaseAddress + mem->Length;
162dd540b46SJohn Baldwin 		mem_info[slot].domain = mem->ProximityDomain;
163dd540b46SJohn Baldwin 		num_mem++;
164dd540b46SJohn Baldwin 		break;
165dd540b46SJohn Baldwin 	}
166dd540b46SJohn Baldwin }
167dd540b46SJohn Baldwin 
168dd540b46SJohn Baldwin /*
169dd540b46SJohn Baldwin  * Ensure each memory domain has at least one CPU and that each CPU
170dd540b46SJohn Baldwin  * has at least one memory domain.
171dd540b46SJohn Baldwin  */
172dd540b46SJohn Baldwin static int
173dd540b46SJohn Baldwin check_domains(void)
174dd540b46SJohn Baldwin {
175dd540b46SJohn Baldwin 	int found, i, j;
176dd540b46SJohn Baldwin 
177dd540b46SJohn Baldwin 	for (i = 0; i < num_mem; i++) {
178dd540b46SJohn Baldwin 		found = 0;
179dd540b46SJohn Baldwin 		for (j = 0; j <= MAX_APIC_ID; j++)
1806676877bSJohn Baldwin 			if (cpus[j].enabled &&
1816676877bSJohn Baldwin 			    cpus[j].domain == mem_info[i].domain) {
182dd540b46SJohn Baldwin 				cpus[j].has_memory = 1;
183dd540b46SJohn Baldwin 				found++;
184dd540b46SJohn Baldwin 			}
185dd540b46SJohn Baldwin 		if (!found) {
186dd540b46SJohn Baldwin 			printf("SRAT: No CPU found for memory domain %d\n",
187dd540b46SJohn Baldwin 			    mem_info[i].domain);
188dd540b46SJohn Baldwin 			return (ENXIO);
189dd540b46SJohn Baldwin 		}
190dd540b46SJohn Baldwin 	}
191dd540b46SJohn Baldwin 	for (i = 0; i <= MAX_APIC_ID; i++)
192dd540b46SJohn Baldwin 		if (cpus[i].enabled && !cpus[i].has_memory) {
193dd540b46SJohn Baldwin 			printf("SRAT: No memory found for CPU %d\n", i);
194dd540b46SJohn Baldwin 			return (ENXIO);
195dd540b46SJohn Baldwin 		}
196dd540b46SJohn Baldwin 	return (0);
197dd540b46SJohn Baldwin }
198dd540b46SJohn Baldwin 
199dd540b46SJohn Baldwin /*
200dd540b46SJohn Baldwin  * Check that the SRAT memory regions cover all of the regions in
201dd540b46SJohn Baldwin  * phys_avail[].
202dd540b46SJohn Baldwin  */
203dd540b46SJohn Baldwin static int
204dd540b46SJohn Baldwin check_phys_avail(void)
205dd540b46SJohn Baldwin {
206dd540b46SJohn Baldwin 	vm_paddr_t address;
207dd540b46SJohn Baldwin 	int i, j;
208dd540b46SJohn Baldwin 
209dd540b46SJohn Baldwin 	/* j is the current offset into phys_avail[]. */
210dd540b46SJohn Baldwin 	address = phys_avail[0];
211dd540b46SJohn Baldwin 	j = 0;
212dd540b46SJohn Baldwin 	for (i = 0; i < num_mem; i++) {
213dd540b46SJohn Baldwin 		/*
214dd540b46SJohn Baldwin 		 * Consume as many phys_avail[] entries as fit in this
215dd540b46SJohn Baldwin 		 * region.
216dd540b46SJohn Baldwin 		 */
217dd540b46SJohn Baldwin 		while (address >= mem_info[i].start &&
218dd540b46SJohn Baldwin 		    address <= mem_info[i].end) {
219dd540b46SJohn Baldwin 			/*
220dd540b46SJohn Baldwin 			 * If we cover the rest of this phys_avail[] entry,
221dd540b46SJohn Baldwin 			 * advance to the next entry.
222dd540b46SJohn Baldwin 			 */
223dd540b46SJohn Baldwin 			if (phys_avail[j + 1] <= mem_info[i].end) {
224dd540b46SJohn Baldwin 				j += 2;
225dd540b46SJohn Baldwin 				if (phys_avail[j] == 0 &&
226dd540b46SJohn Baldwin 				    phys_avail[j + 1] == 0) {
227dd540b46SJohn Baldwin 					return (0);
228dd540b46SJohn Baldwin 				}
229dd540b46SJohn Baldwin 				address = phys_avail[j];
230dd540b46SJohn Baldwin 			} else
231dd540b46SJohn Baldwin 				address = mem_info[i].end + 1;
232dd540b46SJohn Baldwin 		}
233dd540b46SJohn Baldwin 	}
234dd540b46SJohn Baldwin 	printf("SRAT: No memory region found for %jx - %jx\n",
235dd540b46SJohn Baldwin 	    (uintmax_t)phys_avail[j], (uintmax_t)phys_avail[j + 1]);
236dd540b46SJohn Baldwin 	return (ENXIO);
237dd540b46SJohn Baldwin }
238dd540b46SJohn Baldwin 
239dd540b46SJohn Baldwin /*
240dd540b46SJohn Baldwin  * Renumber the memory domains to be compact and zero-based if not
24128990874SJohn Baldwin  * already.  Returns an error if there are too many domains.
242dd540b46SJohn Baldwin  */
24328990874SJohn Baldwin static int
244dd540b46SJohn Baldwin renumber_domains(void)
245dd540b46SJohn Baldwin {
246dd540b46SJohn Baldwin 	int domains[VM_PHYSSEG_MAX];
247dd540b46SJohn Baldwin 	int ndomain, i, j, slot;
248dd540b46SJohn Baldwin 
249dd540b46SJohn Baldwin 	/* Enumerate all the domains. */
250dd540b46SJohn Baldwin 	ndomain = 0;
251dd540b46SJohn Baldwin 	for (i = 0; i < num_mem; i++) {
252dd540b46SJohn Baldwin 		/* See if this domain is already known. */
253dd540b46SJohn Baldwin 		for (j = 0; j < ndomain; j++) {
254dd540b46SJohn Baldwin 			if (domains[j] >= mem_info[i].domain)
255dd540b46SJohn Baldwin 				break;
256dd540b46SJohn Baldwin 		}
257dd540b46SJohn Baldwin 		if (j < ndomain && domains[j] == mem_info[i].domain)
258dd540b46SJohn Baldwin 			continue;
259dd540b46SJohn Baldwin 
260dd540b46SJohn Baldwin 		/* Insert the new domain at slot 'j'. */
261dd540b46SJohn Baldwin 		slot = j;
262dd540b46SJohn Baldwin 		for (j = ndomain; j > slot; j--)
263dd540b46SJohn Baldwin 			domains[j] = domains[j - 1];
264dd540b46SJohn Baldwin 		domains[slot] = mem_info[i].domain;
26528990874SJohn Baldwin 		ndomain++;
266*941646f5SAttilio Rao 		if (ndomain > MAXMEMDOM) {
26728990874SJohn Baldwin 			printf("SRAT: Too many memory domains\n");
26828990874SJohn Baldwin 			return (EFBIG);
26928990874SJohn Baldwin 		}
270dd540b46SJohn Baldwin 	}
271dd540b46SJohn Baldwin 
272dd540b46SJohn Baldwin 	/* Renumber each domain to its index in the sorted 'domains' list. */
273dd540b46SJohn Baldwin 	for (i = 0; i < ndomain; i++) {
274dd540b46SJohn Baldwin 		/*
275dd540b46SJohn Baldwin 		 * If the domain is already the right value, no need
276dd540b46SJohn Baldwin 		 * to renumber.
277dd540b46SJohn Baldwin 		 */
278dd540b46SJohn Baldwin 		if (domains[i] == i)
279dd540b46SJohn Baldwin 			continue;
280dd540b46SJohn Baldwin 
281dd540b46SJohn Baldwin 		/* Walk the cpu[] and mem_info[] arrays to renumber. */
282dd540b46SJohn Baldwin 		for (j = 0; j < num_mem; j++)
283dd540b46SJohn Baldwin 			if (mem_info[j].domain == domains[i])
284dd540b46SJohn Baldwin 				mem_info[j].domain = i;
285dd540b46SJohn Baldwin 		for (j = 0; j <= MAX_APIC_ID; j++)
286dd540b46SJohn Baldwin 			if (cpus[j].enabled && cpus[j].domain == domains[i])
287dd540b46SJohn Baldwin 				cpus[j].domain = i;
288dd540b46SJohn Baldwin 	}
28928990874SJohn Baldwin 	return (0);
290dd540b46SJohn Baldwin }
291dd540b46SJohn Baldwin 
292dd540b46SJohn Baldwin /*
293dd540b46SJohn Baldwin  * Look for an ACPI System Resource Affinity Table ("SRAT")
294dd540b46SJohn Baldwin  */
295dd540b46SJohn Baldwin static void
296dd540b46SJohn Baldwin parse_srat(void *dummy)
297dd540b46SJohn Baldwin {
298dd540b46SJohn Baldwin 	int error;
299dd540b46SJohn Baldwin 
300dd540b46SJohn Baldwin 	if (resource_disabled("srat", 0))
301dd540b46SJohn Baldwin 		return;
302dd540b46SJohn Baldwin 
303dd540b46SJohn Baldwin 	srat_physaddr = acpi_find_table(ACPI_SIG_SRAT);
304dd540b46SJohn Baldwin 	if (srat_physaddr == 0)
305dd540b46SJohn Baldwin 		return;
306dd540b46SJohn Baldwin 
307dd540b46SJohn Baldwin 	/*
308dd540b46SJohn Baldwin 	 * Make a pass over the table to populate the cpus[] and
309dd540b46SJohn Baldwin 	 * mem_info[] tables.
310dd540b46SJohn Baldwin 	 */
311dd540b46SJohn Baldwin 	srat = acpi_map_table(srat_physaddr, ACPI_SIG_SRAT);
312dd540b46SJohn Baldwin 	error = 0;
313dd540b46SJohn Baldwin 	srat_walk_table(srat_parse_entry, &error);
314dd540b46SJohn Baldwin 	acpi_unmap_table(srat);
315dd540b46SJohn Baldwin 	srat = NULL;
31628990874SJohn Baldwin 	if (error || check_domains() != 0 || check_phys_avail() != 0 ||
31728990874SJohn Baldwin 	    renumber_domains() != 0) {
318dd540b46SJohn Baldwin 		srat_physaddr = 0;
319dd540b46SJohn Baldwin 		return;
320dd540b46SJohn Baldwin 	}
321dd540b46SJohn Baldwin 
322dd540b46SJohn Baldwin 	/* Point vm_phys at our memory affinity table. */
323dd540b46SJohn Baldwin 	mem_affinity = mem_info;
324dd540b46SJohn Baldwin }
325dd540b46SJohn Baldwin SYSINIT(parse_srat, SI_SUB_VM - 1, SI_ORDER_FIRST, parse_srat, NULL);
326dd540b46SJohn Baldwin 
327dd540b46SJohn Baldwin static void
328dd540b46SJohn Baldwin srat_walk_table(acpi_subtable_handler *handler, void *arg)
329dd540b46SJohn Baldwin {
330dd540b46SJohn Baldwin 
331dd540b46SJohn Baldwin 	acpi_walk_subtables(srat + 1, (char *)srat + srat->Header.Length,
332dd540b46SJohn Baldwin 	    handler, arg);
333dd540b46SJohn Baldwin }
334dd540b46SJohn Baldwin 
335dd540b46SJohn Baldwin /*
336dd540b46SJohn Baldwin  * Setup per-CPU ACPI IDs.
337dd540b46SJohn Baldwin  */
338dd540b46SJohn Baldwin static void
339dd540b46SJohn Baldwin srat_set_cpus(void *dummy)
340dd540b46SJohn Baldwin {
341dd540b46SJohn Baldwin 	struct cpu_info *cpu;
342dd540b46SJohn Baldwin 	struct pcpu *pc;
343dd540b46SJohn Baldwin 	u_int i;
344dd540b46SJohn Baldwin 
345dd540b46SJohn Baldwin 	if (srat_physaddr == 0)
346dd540b46SJohn Baldwin 		return;
347dd540b46SJohn Baldwin 	for (i = 0; i < MAXCPU; i++) {
348dd540b46SJohn Baldwin 		if (CPU_ABSENT(i))
349dd540b46SJohn Baldwin 			continue;
350dd540b46SJohn Baldwin 		pc = pcpu_find(i);
351dd540b46SJohn Baldwin 		KASSERT(pc != NULL, ("no pcpu data for CPU %u", i));
352dd540b46SJohn Baldwin 		cpu = &cpus[pc->pc_apic_id];
353dd540b46SJohn Baldwin 		if (!cpu->enabled)
354dd540b46SJohn Baldwin 			panic("SRAT: CPU with APIC ID %u is not known",
355dd540b46SJohn Baldwin 			    pc->pc_apic_id);
356dd540b46SJohn Baldwin 		pc->pc_domain = cpu->domain;
357dd540b46SJohn Baldwin 		if (bootverbose)
358dd540b46SJohn Baldwin 			printf("SRAT: CPU %u has memory domain %d\n", i,
359dd540b46SJohn Baldwin 			    cpu->domain);
360dd540b46SJohn Baldwin 	}
361dd540b46SJohn Baldwin }
362dd540b46SJohn Baldwin SYSINIT(srat_set_cpus, SI_SUB_CPU, SI_ORDER_ANY, srat_set_cpus, NULL);
363*941646f5SAttilio Rao #endif /* MAXMEMDOM > 1 */
364