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;
73 * Map the SRAT if it exists
75 srat_paddr = sdt_search(ACPI_SIG_SRAT);
76 if (srat_paddr == 0) {
77 kprintf("srat_probe: can't locate SRAT\n");
81 srat = sdt_sdth_map(srat_paddr);
82 KKASSERT(srat != NULL);
84 if (srat->Header.Length < sizeof(*srat)) {
85 kprintf("acpi: invalid SRAT length %u\n",
93 for (mem = (srat_entry_t *)(srat + 1);
94 (char *)mem < (char *)srat + srat->Header.Length;
95 mem = (srat_entry_t *)((char *)mem + mem->head.Length)) {
97 * Mem scan memory affinity only
99 if (mem->head.Type != ACPI_SRAT_TYPE_MEMORY_AFFINITY)
101 if ((mem->mem.Flags & ACPI_SRAT_MEM_ENABLED) == 0)
104 kprintf("MemAffinity %016jx,%ldMB Prox=%u ",
105 mem->mem.BaseAddress,
106 mem->mem.Length / (1024 * 1024),
107 mem->mem.ProximityDomain);
110 * Look for associated cpu affinity
113 mem->mem.ProximityDomain != cpu->cpu.ProximityDomainLo) {
114 for (cpu = (srat_entry_t *)(srat + 1);
115 (char *)cpu < (char *)srat + srat->Header.Length;
116 cpu = (srat_entry_t *)((char *)cpu +
118 if (cpu->head.Type !=
119 ACPI_SRAT_TYPE_CPU_AFFINITY)
121 if ((cpu->cpu.Flags &
122 ACPI_SRAT_CPU_USE_AFFINITY) == 0)
124 if (mem->mem.ProximityDomain ==
125 cpu->cpu.ProximityDomainLo) {
129 if ((char *)cpu >= (char *)srat + srat->Header.Length)
133 kprintf("CpuApicId %02x Socket %d\n",
135 get_chip_ID_from_APICID(cpu->cpu.ApicId));
136 vm_numa_organize(mem->mem.BaseAddress,
138 get_chip_ID_from_APICID(cpu->cpu.ApicId));
140 kprintf("(not found)\n");
145 sdt_sdth_unmap(&srat->Header);
148 SYSINIT(srat_probe, SI_BOOT2_NUMA, SI_ORDER_FIRST, srat_probe, 0);