Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / ia64 / acpi / madt.c
blob41784edd4f3d5bbc558aff96e06c4057a4b35ac5
1 /* $NetBSD: madt.c,v 1.1 2009/07/20 04:41:36 kiyohara Exp $ */
2 /*-
3 * Copyright (c) 2001 Doug Rabson
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
27 * $FreeBSD: src/sys/ia64/acpica/madt.c,v 1.20 2007/03/22 18:16:42 jkim Exp $
30 #include <sys/param.h>
31 #include <sys/reboot.h>
33 #include <machine/md_var.h>
35 #include <dev/acpi/acpica.h>
36 #include <dev/acpi/acpivar.h>
37 #include <actables.h>
40 extern uint64_t ia64_lapic_address;
42 struct sapic *sapic_create(int, int, uint64_t);
44 static void
45 print_entry(ACPI_SUBTABLE_HEADER *entry)
48 switch (entry->Type) {
49 case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE: {
50 ACPI_MADT_INTERRUPT_OVERRIDE *iso =
51 (ACPI_MADT_INTERRUPT_OVERRIDE *)entry;
52 printf("\tInterrupt source override entry\n");
53 printf("\t\tBus=%u, Source=%u, Irq=0x%x\n", iso->Bus,
54 iso->SourceIrq, iso->GlobalIrq);
55 break;
58 case ACPI_MADT_TYPE_IO_APIC:
59 printf("\tI/O APIC entry\n");
60 break;
62 case ACPI_MADT_TYPE_IO_SAPIC: {
63 ACPI_MADT_IO_SAPIC *sapic = (ACPI_MADT_IO_SAPIC *)entry;
64 printf("\tI/O SAPIC entry\n");
65 printf("\t\tId=0x%x, InterruptBase=0x%x, Address=0x%lx\n",
66 sapic->Id, sapic->GlobalIrqBase, sapic->Address);
67 break;
70 case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
71 printf("\tLocal APIC NMI entry\n");
72 break;
74 case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE: {
75 ACPI_MADT_LOCAL_APIC_OVERRIDE *lapic =
76 (ACPI_MADT_LOCAL_APIC_OVERRIDE *)entry;
77 printf("\tLocal APIC override entry\n");
78 printf("\t\tLocal APIC address=0x%jx\n", lapic->Address);
79 break;
82 case ACPI_MADT_TYPE_LOCAL_SAPIC: {
83 ACPI_MADT_LOCAL_SAPIC *sapic = (ACPI_MADT_LOCAL_SAPIC *)entry;
84 printf("\tLocal SAPIC entry\n");
85 printf("\t\tProcessorId=0x%x, Id=0x%x, Eid=0x%x",
86 sapic->ProcessorId, sapic->Id, sapic->Eid);
87 if (!(sapic->LapicFlags & ACPI_MADT_ENABLED))
88 printf(" (disabled)");
89 printf("\n");
90 break;
93 case ACPI_MADT_TYPE_NMI_SOURCE:
94 printf("\tNMI entry\n");
95 break;
97 case ACPI_MADT_TYPE_INTERRUPT_SOURCE: {
98 ACPI_MADT_INTERRUPT_SOURCE *pis =
99 (ACPI_MADT_INTERRUPT_SOURCE *)entry;
100 printf("\tPlatform interrupt entry\n");
101 printf("\t\tPolarity=%u, TriggerMode=%u, Id=0x%x, "
102 "Eid=0x%x, Vector=0x%x, Irq=%d\n",
103 pis->IntiFlags & ACPI_MADT_POLARITY_MASK,
104 (pis->IntiFlags & ACPI_MADT_TRIGGER_MASK) >> 2,
105 pis->Id, pis->Eid, pis->IoSapicVector, pis->GlobalIrq);
106 break;
109 case ACPI_MADT_TYPE_LOCAL_APIC:
110 printf("\tLocal APIC entry\n");
111 break;
113 default:
114 printf("\tUnknown type %d entry\n", entry->Type);
115 break;
119 void
120 ia64_probe_sapics(void)
122 ACPI_PHYSICAL_ADDRESS rsdp_ptr;
123 ACPI_SUBTABLE_HEADER *entry;
124 ACPI_TABLE_MADT *table;
125 ACPI_TABLE_RSDP *rsdp;
126 ACPI_TABLE_XSDT *xsdt;
127 char *end, *p;
128 int t, tables;
129 extern int has_i8259;
131 if ((rsdp_ptr = AcpiOsGetRootPointer()) == 0)
132 return;
134 rsdp = (ACPI_TABLE_RSDP *)IA64_PHYS_TO_RR7(rsdp_ptr);
135 xsdt = (ACPI_TABLE_XSDT *)IA64_PHYS_TO_RR7(rsdp->XsdtPhysicalAddress);
137 tables = (UINT64 *)((char *)xsdt + xsdt->Header.Length) -
138 xsdt->TableOffsetEntry;
140 for (t = 0; t < tables; t++) {
141 table = (ACPI_TABLE_MADT *)
142 IA64_PHYS_TO_RR7(xsdt->TableOffsetEntry[t]);
144 if (bootverbose)
145 printf("Table '%c%c%c%c' at %p\n",
146 table->Header.Signature[0],
147 table->Header.Signature[1],
148 table->Header.Signature[2],
149 table->Header.Signature[3], table);
151 if (strncmp(table->Header.Signature, ACPI_SIG_MADT,
152 ACPI_NAME_SIZE) != 0 ||
153 ACPI_FAILURE(AcpiTbChecksum((void *)table,
154 table->Header.Length)))
155 continue;
157 /* Save the address of the processor interrupt block. */
158 if (bootverbose)
159 printf("\tLocal APIC address=0x%x\n", table->Address);
160 ia64_lapic_address = table->Address;
162 if (table->Flags & ACPI_MADT_PCAT_COMPAT)
163 has_i8259 = 1;
165 end = (char *)table + table->Header.Length;
166 p = (char *)(table + 1);
167 while (p < end) {
168 entry = (ACPI_SUBTABLE_HEADER *)p;
170 if (bootverbose)
171 print_entry(entry);
173 switch (entry->Type) {
174 case ACPI_MADT_TYPE_IO_SAPIC:
176 ACPI_MADT_IO_SAPIC *sapic =
177 (ACPI_MADT_IO_SAPIC *)entry;
179 sapic_create(sapic->Id, sapic->GlobalIrqBase,
180 sapic->Address);
181 break;
184 case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
186 ACPI_MADT_LOCAL_APIC_OVERRIDE *lapic =
187 (ACPI_MADT_LOCAL_APIC_OVERRIDE *)entry;
189 ia64_lapic_address = lapic->Address;
190 break;
193 #ifdef MULTIPROCESSOR
194 case ACPI_MADT_TYPE_LOCAL_SAPIC:
196 ACPI_MADT_LOCAL_SAPIC *sapic =
197 (ACPI_MADT_LOCAL_SAPIC *)entry;
199 if (sapic->LapicFlags & ACPI_MADT_ENABLED)
200 cpu_mp_add(sapic->ProcessorId,
201 sapic->Id, sapic->Eid);
202 break;
204 #endif
206 default:
207 break;
210 p += entry->Length;
216 * Count the number of local SAPIC entries in the APIC table. Every enabled
217 * entry corresponds to a processor.
220 ia64_count_cpus(void)
222 ACPI_PHYSICAL_ADDRESS rsdp_ptr;
223 ACPI_MADT_LOCAL_SAPIC *entry;
224 ACPI_TABLE_MADT *table;
225 ACPI_TABLE_RSDP *rsdp;
226 ACPI_TABLE_XSDT *xsdt;
227 char *end, *p;
228 int cpus, t, tables;
230 if ((rsdp_ptr = AcpiOsGetRootPointer()) == 0)
231 return 0;
233 rsdp = (ACPI_TABLE_RSDP *)IA64_PHYS_TO_RR7(rsdp_ptr);
234 xsdt = (ACPI_TABLE_XSDT *)IA64_PHYS_TO_RR7(rsdp->XsdtPhysicalAddress);
236 tables = (UINT64 *)((char *)xsdt + xsdt->Header.Length) -
237 xsdt->TableOffsetEntry;
239 cpus = 0;
241 for (t = 0; t < tables; t++) {
242 table = (ACPI_TABLE_MADT *)
243 IA64_PHYS_TO_RR7(xsdt->TableOffsetEntry[t]);
245 if (strncmp(table->Header.Signature, ACPI_SIG_MADT,
246 ACPI_NAME_SIZE) != 0 ||
247 ACPI_FAILURE(AcpiTbChecksum((void *)table,
248 table->Header.Length)))
249 continue;
251 end = (char *)table + table->Header.Length;
252 p = (char *)(table + 1);
253 while (p < end) {
254 entry = (ACPI_MADT_LOCAL_SAPIC *)p;
256 if (entry->Header.Type == ACPI_MADT_TYPE_LOCAL_SAPIC &&
257 (entry->LapicFlags & ACPI_MADT_ENABLED))
258 cpus++;
260 p += entry->Header.Length;
264 return cpus;