1 /* $NetBSD: acpi_madt.c,v 1.12 2004/03/24 13:02:23 kochi Exp $ */
2
3 /*
4 * Copyright (c) 2003 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Frank van der Linden for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: acpi_madt.c,v 1.12 2004/03/24 13:02:23 kochi Exp $");
40
41 #include <sys/param.h>
42 #include <sys/ioctl.h>
43 #include <sys/systm.h>
44 #include <sys/conf.h>
45 #include <sys/errno.h>
46 #include <sys/malloc.h>
47
48 #include <dev/acpi/acpica.h>
49 #include <dev/acpi/acpireg.h>
50 #include <dev/acpi/acpivar.h>
51 #include <dev/acpi/acpi_madt.h>
52
53 #ifdef ACPI_MADT_DEBUG
54 static void acpi_madt_print(void);
55 static ACPI_STATUS acpi_madt_print_entry(APIC_HEADER *, void *);
56 static void acpi_print_apic_proc(MADT_PROCESSOR_APIC *);
57 static void acpi_print_ioapic(MADT_IO_APIC *);
58 static void acpi_print_intsrc_ovr(MADT_INTERRUPT_OVERRIDE *);
59 static void acpi_print_intsrc_nmi(MADT_NMI_SOURCE *);
60 static void acpi_print_lapic_nmi(MADT_LOCAL_APIC_NMI *);
61 static void acpi_print_lapic_addr_ovr(MADT_ADDRESS_OVERRIDE *);
62 static void acpi_print_iosapic(MADT_IO_SAPIC *);
63 static void acpi_print_local_sapic(MADT_LOCAL_SAPIC *);
64 static void acpi_print_platint(MADT_INTERRUPT_SOURCE *);
65 #endif
66
67 static ACPI_TABLE_HEADER *madt_header;
68
69 ACPI_STATUS
70 acpi_madt_map(void)
71 {
72 ACPI_STATUS rv;
73
74 if (madt_header != NULL)
75 return AE_ALREADY_EXISTS;
76
77 rv = AcpiGetFirmwareTable(APIC_SIG, 1, ACPI_LOGICAL_ADDRESSING,
78 &madt_header);
79
80 if (ACPI_FAILURE(rv))
81 return rv;
82
83 #ifdef ACPI_MADT_DEBUG
84 acpi_madt_print();
85 #endif
86
87 return AE_OK;
88 }
89
90 void
91 acpi_madt_unmap(void)
92 {
93 AcpiOsUnmapMemory(madt_header, madt_header->Length);
94 madt_header = NULL;
95 }
96
97 #ifdef ACPI_MADT_DEBUG
98
99 static void
100 acpi_print_apic_proc(MADT_PROCESSOR_APIC *p)
101 {
102 printf("processor: id %u apid %u enabled: %s\n",
103 p->ProcessorId, p->LocalApicId,
104 p->ProcessorEnabled ? "yes" : "no");
105 }
106
107 static void
108 acpi_print_ioapic(MADT_IO_APIC *p)
109 {
110 printf("ioapic: apid %u address %x vector base %x\n",
111 p->IoApicId, p->Address, p->Interrupt);
112 }
113
114 static void
115 acpi_print_intsrc_ovr(MADT_INTERRUPT_OVERRIDE *p)
116 {
117 printf("int override: bus %u irq %u int %u\n",
118 p->Bus, p->Source, p->Interrupt);
119 }
120
121 static void
122 acpi_print_intsrc_nmi(MADT_NMI_SOURCE *p)
123 {
124 printf("ioapic NMI: int %u\n", p->Interrupt);
125 }
126
127 static void
128 acpi_print_lapic_nmi(MADT_LOCAL_APIC_NMI *p)
129 {
130 printf("lapic NMI: apid %u input %u\n", p->ProcessorId, p->Lint);
131 }
132
133 static void
134 acpi_print_lapic_addr_ovr(MADT_ADDRESS_OVERRIDE *p)
135 {
136 printf("lapic addr override: %llx\n", (unsigned long long)p->Address);
137 }
138
139 static void
140 acpi_print_iosapic(MADT_IO_SAPIC *p)
141 {
142 printf("iosapic: sapid %u address %llx vector base %x\n",
143 p->IoSapicId, p->Address, p->InterruptBase);
144 }
145
146 static void
147 acpi_print_local_sapic(MADT_LOCAL_SAPIC *p)
148 {
149 printf("local sapic: CPU %u sapid %u sapeid %u enabled: %s\n",
150 p->ProcessorId, p->LocalSapicId, p->LocalSapicEid,
151 p->ProcessorEnabled ? "yes" : "no");
152 }
153
154 static void
155 acpi_print_platint(MADT_INTERRUPT_SOURCE *p)
156 {
157 printf("platform int: type %u apid %u apeid %u\n",
158 p->InterruptType, p->ProcessorId, p->ProcessorEid);
159 }
160
161 #endif
162
163 void
164 acpi_madt_walk(ACPI_STATUS (*func)(APIC_HEADER *, void *), void *aux)
165 {
166 char *madtend, *where;
167 APIC_HEADER *hdrp;
168
169 madtend = (char *)madt_header + madt_header->Length;
170 where = (char *)madt_header + sizeof (MULTIPLE_APIC_TABLE);
171 while (where < madtend) {
172 hdrp = (APIC_HEADER *)where;
173 if (func(hdrp, aux) != AE_OK)
174 break;
175 where += hdrp->Length;
176 }
177 }
178
179 #ifdef ACPI_MADT_DEBUG
180 void
181 acpi_madt_print(void)
182 {
183 MULTIPLE_APIC_TABLE *ap;
184
185 ap = (MULTIPLE_APIC_TABLE *)madt_header;
186 printf("\n\nACPI MADT table:\n");
187 printf("default local APIC address: %x\n", ap->LocalApicAddress);
188 printf("system dual 8259%s present\n",
189 ap->PCATCompat ? "" : " not");
190 printf("entries:\n");
191
192 acpi_madt_walk(acpi_madt_print_entry, NULL);
193 }
194
195 static ACPI_STATUS
196 acpi_madt_print_entry(APIC_HEADER *hdrp, void *aux)
197 {
198 switch (hdrp->Type) {
199 case APIC_PROCESSOR:
200 acpi_print_apic_proc((void *)hdrp);
201 break;
202 case APIC_IO:
203 acpi_print_ioapic((void *)hdrp);
204 break;
205 case APIC_XRUPT_OVERRIDE:
206 acpi_print_intsrc_ovr((void *)hdrp);
207 break;
208 case APIC_NMI:
209 acpi_print_intsrc_nmi((void *)hdrp);
210 break;
211 case APIC_LOCAL_NMI:
212 acpi_print_lapic_nmi((void *)hdrp);
213 break;
214 case APIC_ADDRESS_OVERRIDE:
215 acpi_print_lapic_addr_ovr((void *)hdrp);
216 break;
217 case APIC_IO_SAPIC:
218 acpi_print_iosapic((void *)hdrp);
219 break;
220 case APIC_LOCAL_SAPIC:
221 acpi_print_local_sapic((void *)hdrp);
222 break;
223 case APIC_XRUPT_SOURCE:
224 acpi_print_platint((void *)hdrp);
225 break;
226 default:
227 printf("Unknown MADT entry type %d\n", hdrp->Type);
228 break;
229 }
230 return AE_OK;
231 }
232 #endif
Cache object: 2fa0b6a54f9873b845b190a0eb99256c
|