1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*-
* Copyright (c) 2001 Doug Rabson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include "acpi.h"
#include <contrib/dev/acpica/actables.h>
#include <machine/md_var.h>
extern u_int64_t ia64_lapic_address;
struct sapic *sapic_create(int, int, u_int64_t);
static void
print_entry(APIC_HEADER *entry)
{
switch (entry->Type) {
case APIC_XRUPT_OVERRIDE: {
MADT_INTERRUPT_OVERRIDE *iso =
(MADT_INTERRUPT_OVERRIDE *)entry;
printf("\tInterrupt source override entry\n");
printf("\t\tBus=%d, Source=%d, Irq=0x%x\n", iso->Bus,
iso->Source, iso->Interrupt);
break;
}
case APIC_IO:
printf("\tI/O APIC entry\n");
break;
case APIC_IO_SAPIC: {
MADT_IO_SAPIC *sapic = (MADT_IO_SAPIC *)entry;
printf("\tI/O SAPIC entry\n");
printf("\t\tId=0x%x, InterruptBase=0x%x, Address=0x%lx\n",
sapic->IoSapicId, sapic->InterruptBase, sapic->Address);
break;
}
case APIC_LOCAL_NMI:
printf("\tLocal APIC NMI entry\n");
break;
case APIC_ADDRESS_OVERRIDE: {
MADT_ADDRESS_OVERRIDE *lapic = (MADT_ADDRESS_OVERRIDE *)entry;
printf("\tLocal APIC override entry\n");
printf("\t\tLocal APIC address=0x%jx\n", lapic->Address);
break;
}
case APIC_LOCAL_SAPIC: {
MADT_LOCAL_SAPIC *sapic = (MADT_LOCAL_SAPIC *)entry;
printf("\tLocal SAPIC entry\n");
printf("\t\tProcessorId=0x%x, Id=0x%x, Eid=0x%x",
sapic->ProcessorId, sapic->LocalSapicId,
sapic->LocalSapicEid);
if (!sapic->ProcessorEnabled)
printf(" (disabled)");
printf("\n");
break;
}
case APIC_NMI:
printf("\tNMI entry\n");
break;
case APIC_XRUPT_SOURCE: {
MADT_INTERRUPT_SOURCE *pis = (MADT_INTERRUPT_SOURCE *)entry;
printf("\tPlatform interrupt entry\n");
printf("\t\tPolarity=%d, TriggerMode=%d, Id=0x%x, "
"Eid=0x%x, Vector=0x%x, Irq=%d\n",
pis->Polarity, pis->TriggerMode, pis->ProcessorId,
pis->ProcessorEid, pis->IoSapicVector, pis->Interrupt);
break;
}
case APIC_PROCESSOR:
printf("\tLocal APIC entry\n");
break;
default:
printf("\tUnknown type %d entry\n", entry->Type);
break;
}
}
void
ia64_probe_sapics(void)
{
ACPI_POINTER rsdp_ptr;
APIC_HEADER *entry;
MULTIPLE_APIC_TABLE *table;
RSDP_DESCRIPTOR *rsdp;
XSDT_DESCRIPTOR *xsdt;
char *end, *p;
int t, tables;
if (AcpiOsGetRootPointer(ACPI_LOGICAL_ADDRESSING, &rsdp_ptr) != AE_OK)
return;
rsdp = (RSDP_DESCRIPTOR *)IA64_PHYS_TO_RR7(rsdp_ptr.Pointer.Physical);
xsdt = (XSDT_DESCRIPTOR *)IA64_PHYS_TO_RR7(rsdp->XsdtPhysicalAddress);
tables = (UINT64 *)((char *)xsdt + xsdt->Length) -
xsdt->TableOffsetEntry;
for (t = 0; t < tables; t++) {
table = (MULTIPLE_APIC_TABLE *)
IA64_PHYS_TO_RR7(xsdt->TableOffsetEntry[t]);
if (bootverbose)
printf("Table '%c%c%c%c' at %p\n",
table->Signature[0], table->Signature[1],
table->Signature[2], table->Signature[3], table);
if (strncmp(table->Signature, APIC_SIG, 4) != 0 ||
ACPI_FAILURE(AcpiTbVerifyTableChecksum((void *)table)))
continue;
/* Save the address of the processor interrupt block. */
if (bootverbose)
printf("\tLocal APIC address=0x%x\n",
table->LocalApicAddress);
ia64_lapic_address = table->LocalApicAddress;
end = (char *)table + table->Length;
p = (char *)(table + 1);
while (p < end) {
entry = (APIC_HEADER *)p;
if (bootverbose)
print_entry(entry);
switch (entry->Type) {
case APIC_IO_SAPIC: {
MADT_IO_SAPIC *sapic = (MADT_IO_SAPIC *)entry;
sapic_create(sapic->IoSapicId,
sapic->InterruptBase, sapic->Address);
break;
}
case APIC_ADDRESS_OVERRIDE: {
MADT_ADDRESS_OVERRIDE *lapic =
(MADT_ADDRESS_OVERRIDE*)entry;
ia64_lapic_address = lapic->Address;
break;
}
#ifdef SMP
case APIC_LOCAL_SAPIC: {
MADT_LOCAL_SAPIC *sapic =
(MADT_LOCAL_SAPIC *)entry;
if (sapic->ProcessorEnabled)
cpu_mp_add(sapic->ProcessorId,
sapic->LocalSapicId,
sapic->LocalSapicEid);
break;
}
#endif
default:
break;
}
p += entry->Length;
}
}
}
/*
* Count the number of local SAPIC entries in the APIC table. Every enabled
* entry corresponds to a processor.
*/
int
ia64_count_cpus(void)
{
ACPI_POINTER rsdp_ptr;
MULTIPLE_APIC_TABLE *table;
MADT_LOCAL_SAPIC *entry;
RSDP_DESCRIPTOR *rsdp;
XSDT_DESCRIPTOR *xsdt;
char *end, *p;
int cpus, t, tables;
if (AcpiOsGetRootPointer(ACPI_LOGICAL_ADDRESSING, &rsdp_ptr) != AE_OK)
return (0);
rsdp = (RSDP_DESCRIPTOR *)IA64_PHYS_TO_RR7(rsdp_ptr.Pointer.Physical);
xsdt = (XSDT_DESCRIPTOR *)IA64_PHYS_TO_RR7(rsdp->XsdtPhysicalAddress);
tables = (UINT64 *)((char *)xsdt + xsdt->Length) -
xsdt->TableOffsetEntry;
cpus = 0;
for (t = 0; t < tables; t++) {
table = (MULTIPLE_APIC_TABLE *)
IA64_PHYS_TO_RR7(xsdt->TableOffsetEntry[t]);
if (strncmp(table->Signature, APIC_SIG, 4) != 0 ||
ACPI_FAILURE(AcpiTbVerifyTableChecksum((void *)table)))
continue;
end = (char *)table + table->Length;
p = (char *)(table + 1);
while (p < end) {
entry = (MADT_LOCAL_SAPIC *)p;
if (entry->Type == APIC_LOCAL_SAPIC &&
entry->ProcessorEnabled)
cpus++;
p += entry->Length;
}
}
return (cpus);
}
|