2 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Sepherosa Ziehau <sepherosa@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/systm.h>
39 #include <vm/vm_page.h>
42 #include "acpi_sdt_var.h"
43 #include "acpi_sci_var.h"
47 #define MADT_VPRINTF(fmt, arg...) \
50 kprintf("ACPI MADT: " fmt , ##arg); \
53 #define MADT_INT_BUS_ISA 0
55 typedef union srat_entry
{
56 ACPI_SUBTABLE_HEADER head
;
57 ACPI_SRAT_CPU_AFFINITY cpu
;
58 ACPI_SRAT_MEM_AFFINITY mem
;
59 ACPI_SRAT_X2APIC_CPU_AFFINITY x2apic
;
60 ACPI_SRAT_GICC_AFFINITY gicc
;
66 vm_paddr_t srat_paddr
;
67 ACPI_TABLE_SRAT
*srat
;
75 * Allow NUMA to be disabled by either setting kern.numa_disable
76 * to 1 or by setting hw.acpi.srat.enabled to 0.
78 kgetenv_int("kern.numa_disable", &disabled
);
79 kgetenv_int("hw.acpi.srat.enabled", &enabled
);
80 if (disabled
|| enabled
== 0)
84 * Map the SRAT if it exists
86 srat_paddr
= sdt_search(ACPI_SIG_SRAT
);
87 if (srat_paddr
== 0) {
88 kprintf("srat_probe: can't locate SRAT\n");
92 srat
= sdt_sdth_map(srat_paddr
);
93 KKASSERT(srat
!= NULL
);
95 if (srat
->Header
.Length
< sizeof(*srat
)) {
96 kprintf("acpi: invalid SRAT length %u\n",
104 for (mem
= (srat_entry_t
*)(srat
+ 1);
105 (char *)mem
< (char *)srat
+ srat
->Header
.Length
;
106 mem
= (srat_entry_t
*)((char *)mem
+ mem
->head
.Length
)) {
108 * Mem scan memory affinity only
110 if (mem
->head
.Type
!= ACPI_SRAT_TYPE_MEMORY_AFFINITY
)
112 if ((mem
->mem
.Flags
& ACPI_SRAT_MEM_ENABLED
) == 0)
115 kprintf("MemAffinity %016jx,%ldMB Prox=%u ",
116 mem
->mem
.BaseAddress
,
117 mem
->mem
.Length
/ (1024 * 1024),
118 mem
->mem
.ProximityDomain
);
121 * Look for associated cpu affinity
124 mem
->mem
.ProximityDomain
!= cpu
->cpu
.ProximityDomainLo
) {
125 for (cpu
= (srat_entry_t
*)(srat
+ 1);
126 (char *)cpu
< (char *)srat
+ srat
->Header
.Length
;
127 cpu
= (srat_entry_t
*)((char *)cpu
+
129 if (cpu
->head
.Type
!=
130 ACPI_SRAT_TYPE_CPU_AFFINITY
)
132 if ((cpu
->cpu
.Flags
&
133 ACPI_SRAT_CPU_USE_AFFINITY
) == 0)
135 if (mem
->mem
.ProximityDomain
==
136 cpu
->cpu
.ProximityDomainLo
) {
140 if ((char *)cpu
>= (char *)srat
+ srat
->Header
.Length
)
144 kprintf("CpuApicId %02x Socket %d\n",
146 get_chip_ID_from_APICID(cpu
->cpu
.ApicId
));
147 vm_numa_organize(mem
->mem
.BaseAddress
,
149 get_chip_ID_from_APICID(cpu
->cpu
.ApicId
));
151 kprintf("(not found)\n");
156 sdt_sdth_unmap(&srat
->Header
);
159 SYSINIT(srat_probe
, SI_BOOT2_NUMA
, SI_ORDER_FIRST
, srat_probe
, 0);