Sync usage with man page.
[netbsd-mini2440.git] / sys / dev / acpi / acpi_madt.c
blob08625d7f5f251789304c24d69d2af03480972293
1 /* $NetBSD: acpi_madt.c,v 1.18 2007/12/09 20:27:53 jmcneill Exp $ */
3 /*
4 * Copyright (c) 2003 Wasabi Systems, Inc.
5 * All rights reserved.
7 * Written by Frank van der Linden for Wasabi Systems, Inc.
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.
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.
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: acpi_madt.c,v 1.18 2007/12/09 20:27:53 jmcneill Exp $");
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>
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>
53 #ifdef ACPI_MADT_DEBUG
54 static void acpi_madt_print(void);
55 static ACPI_STATUS acpi_madt_print_entry(ACPI_SUBTABLE_HEADER *, void *);
56 static void acpi_print_lapic(ACPI_MADT_LOCAL_APIC *);
57 static void acpi_print_ioapic(ACPI_MADT_IO_APIC *);
58 static void acpi_print_intsrc_ovr(ACPI_MADT_INTERRUPT_OVERRIDE *);
59 static void acpi_print_intsrc_nmi(ACPI_MADT_NMI_SOURCE *);
60 static void acpi_print_lapic_nmi(ACPI_MADT_LOCAL_APIC_NMI *);
61 static void acpi_print_lapic_ovr(ACPI_MADT_LOCAL_APIC_OVERRIDE *);
62 static void acpi_print_iosapic(ACPI_MADT_IO_SAPIC *);
63 static void acpi_print_local_sapic(ACPI_MADT_LOCAL_SAPIC *);
64 static void acpi_print_platint(ACPI_MADT_INTERRUPT_SOURCE *);
65 #endif
67 static ACPI_TABLE_HEADER *madt_header;
69 ACPI_STATUS
70 acpi_madt_map(void)
72 ACPI_STATUS rv;
74 if (madt_header != NULL)
75 return AE_ALREADY_EXISTS;
77 rv = AcpiGetTable(ACPI_SIG_MADT, 1, &madt_header);
79 if (ACPI_FAILURE(rv))
80 return rv;
82 #ifdef ACPI_MADT_DEBUG
83 acpi_madt_print();
84 #endif
86 return AE_OK;
89 void
90 acpi_madt_unmap(void)
92 madt_header = NULL;
95 #ifdef ACPI_MADT_DEBUG
97 static void
98 acpi_print_lapic(ACPI_MADT_LOCAL_APIC *p)
100 printf("lapic: processor id %u apid %u enabled: %s\n",
101 p->ProcessorId, p->Id,
102 (p->LapicFlags & ACPI_MADT_ENABLED) ? "yes" : "no");
105 static void
106 acpi_print_ioapic(ACPI_MADT_IO_APIC *p)
108 printf("ioapic: apid %u address 0x%x vector base 0x%x\n",
109 p->Id, p->Address, p->GlobalIrqBase);
112 static void
113 acpi_print_intsrc_ovr(ACPI_MADT_INTERRUPT_OVERRIDE *p)
115 printf("int override: bus %u src int %u global int %u\n",
116 p->Bus, p->SourceIrq, p->GlobalIrq);
119 static void
120 acpi_print_intsrc_nmi(ACPI_MADT_NMI_SOURCE *p)
122 printf("ioapic NMI: int %u\n", p->GlobalIrq);
125 static void
126 acpi_print_lapic_nmi(ACPI_MADT_LOCAL_APIC_NMI *p)
128 printf("lapic NMI: cpu id %u input %u\n", p->ProcessorId, p->Lint);
131 static void
132 acpi_print_lapic_ovr(ACPI_MADT_LOCAL_APIC_OVERRIDE *p)
134 printf("lapic addr override: 0x%llx\n", (unsigned long long)p->Address);
137 static void
138 acpi_print_iosapic(ACPI_MADT_IO_SAPIC *p)
140 printf("iosapic: sapid %u address 0x%llx int vector base 0x%x\n",
141 p->Id, (unsigned long long)p->Address, p->GlobalIrqBase);
144 static void
145 acpi_print_local_sapic(ACPI_MADT_LOCAL_SAPIC *p)
147 printf("local sapic: cpu id %u sapid %u sapeid %u enabled: %s\n",
148 p->ProcessorId, p->Id, p->Eid,
149 (p->LapicFlags & ACPI_MADT_ENABLED) ? "yes" : "no");
152 static void
153 acpi_print_platint(ACPI_MADT_INTERRUPT_SOURCE *p)
155 printf("platform int: type %u cpu id %u cpu eid %u vector %u int %u%s\n",
156 p->Type, p->Id, p->Eid, p->IoSapicVector, p->GlobalIrq,
157 (p->Flags & ACPI_MADT_CPEI_OVERRIDE) ? " CPEI" : "");
160 #endif
162 void
163 acpi_madt_walk(ACPI_STATUS (*func)(ACPI_SUBTABLE_HEADER *, void *), void *aux)
165 char *madtend, *where;
166 ACPI_SUBTABLE_HEADER *hdrp;
168 madtend = (char *)madt_header + madt_header->Length;
169 where = (char *)madt_header + sizeof (ACPI_TABLE_MADT);
170 while (where < madtend) {
171 hdrp = (ACPI_SUBTABLE_HEADER *)where;
172 if (ACPI_FAILURE(func(hdrp, aux)))
173 break;
174 where += hdrp->Length;
178 #ifdef ACPI_MADT_DEBUG
179 static void
180 acpi_madt_print(void)
182 ACPI_TABLE_MADT *ap;
184 ap = (ACPI_TABLE_MADT *)madt_header;
185 printf("\n\nACPI MADT table:\n");
186 /* printf("default local APIC address: %x\n", ap->LocalApicAddress); */
187 printf("system dual 8259%s present\n",
188 (ap->Flags & ACPI_MADT_PCAT_COMPAT) ? "" : " not");
189 printf("entries:\n");
191 acpi_madt_walk(acpi_madt_print_entry, NULL);
194 static ACPI_STATUS
195 acpi_madt_print_entry(ACPI_SUBTABLE_HEADER *hdrp, void *aux)
197 switch (hdrp->Type) {
198 case ACPI_MADT_TYPE_LOCAL_APIC:
199 acpi_print_lapic((void *)hdrp);
200 break;
201 case ACPI_MADT_TYPE_IO_APIC:
202 acpi_print_ioapic((void *)hdrp);
203 break;
204 case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
205 acpi_print_intsrc_ovr((void *)hdrp);
206 break;
207 case ACPI_MADT_TYPE_NMI_SOURCE:
208 acpi_print_intsrc_nmi((void *)hdrp);
209 break;
210 case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
211 acpi_print_lapic_nmi((void *)hdrp);
212 break;
213 case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
214 acpi_print_lapic_ovr((void *)hdrp);
215 break;
216 case ACPI_MADT_TYPE_IO_SAPIC:
217 acpi_print_iosapic((void *)hdrp);
218 break;
219 case ACPI_MADT_TYPE_LOCAL_SAPIC:
220 acpi_print_local_sapic((void *)hdrp);
221 break;
222 case ACPI_MADT_TYPE_INTERRUPT_SOURCE:
223 acpi_print_platint((void *)hdrp);
224 break;
225 default:
226 printf("Unknown MADT entry type %d\n", hdrp->Type);
227 break;
229 return AE_OK;
231 #endif