2 * Intel Multiprocessor Specification 1.1 and 1.4
3 * compliant MP-table parsing routines.
5 * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
6 * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
9 * Erich Boleyn : MP v1.4 and additional changes.
10 * Alan Cox : Added EBDA scanning
11 * Ingo Molnar : various cleanups and rewrites
12 * Maciej W. Rozycki: Bits for default MP configurations
13 * Paul Diefenbaugh: Added full ACPI support
18 #include <lwk/bootmem.h>
19 #include <lwk/cpuinfo.h>
20 #include <lwk/params.h>
22 #include <arch/mpspec.h>
23 #include <arch/proto.h>
24 #include <arch/io_apic.h>
27 * Points to the MP table, once and if it is found.
28 * This gets initialized by find_mp_table().
30 static struct intel_mp_floating *mpf_found;
33 * Physical CPU ID of the bootstrap CPU (the BP).
35 unsigned int __initdata boot_phys_cpu_id = -1U;
38 * The number of CPUs in the system.
40 unsigned int __initdata num_cpus = 0;
43 * Map of all CPUs present.
44 * Bits set represent physical CPU IDs present.
46 physid_mask_t phys_cpu_present_map = PHYSID_MASK_NONE;
49 * Version information for every Local APIC in the system.
50 * The array is indexed by APIC ID.
52 unsigned char apic_version[MAX_APICS];
57 static int mp_current_pci_id = 0;
58 unsigned char mp_bus_id_to_type [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
59 int mp_bus_id_to_pci_bus [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
62 * MP IO APIC information
65 struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS];
70 int mp_irq_entries = 0;
71 struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
74 /* TODO: move these */
78 * Computes the checksum of an MP configuration block.
81 mpf_checksum(unsigned char *mp, int len)
90 * Parses an MP table CPU entry.
93 MP_processor_info(struct mpc_config_processor *m)
100 if (!(m->mpc_cpuflag & CPU_ENABLED))
101 panic("A disabled CPU was encountered\n");
103 /* Count the new CPU */
104 if (++num_cpus > NR_CPUS)
105 panic("NR_CPUS limit of %i reached.\n", NR_CPUS);
108 * Determine if this is the bootstrap processor...
109 * the one responsible for booting the other CPUs.
111 is_bp = (m->mpc_cpuflag & CPU_BOOTPROCESSOR);
114 * Assign a logical CPU ID.
115 * The bootstrap CPU is always assigned logical ID 0.
116 * All other CPUs are assigned the lowest ID available.
121 cpus_complement(tmp_map, cpu_present_map);
122 cpu = first_cpu(tmp_map);
125 /* Validate APIC version, fixing up if necessary. */
126 ver = m->mpc_apicver;
128 printk(KERN_ERR "BIOS bug, APIC version is 0 for PhysCPU#%d! "
129 "fixing up to 0x10. (tell your hw vendor)\n",
134 /* Remember the APIC's version */
135 apic_version[m->mpc_apicid] = ver;
137 /* Add the CPU to the map of physical CPU IDs present. */
138 physid_set(m->mpc_apicid, phys_cpu_present_map);
140 /* Remember the physical CPU ID of the bootstrap CPU. */
142 boot_phys_cpu_id = m->mpc_apicid;
144 /* Add the CPU to the map of logical CPU IDs present. */
145 cpu_set(cpu, cpu_present_map);
147 /* Store ID information. */
148 cpu_info[cpu].logical_id = cpu;
149 cpu_info[cpu].physical_id = m->mpc_apicid;
150 cpu_info[cpu].arch.apic_id = m->mpc_apicid;
153 "Physical CPU #%d -> Logical CPU #%d, %d:%d APIC version %d%s\n",
156 (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
157 (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
159 is_bp ? " (Bootstrap CPU)" : "");
163 * Parses an MP table BUS entry.
166 MP_bus_info(struct mpc_config_bus *m)
170 memcpy(str, m->mpc_bustype, 6);
172 printk(KERN_DEBUG "Bus #%d is %s\n", m->mpc_busid, str);
174 if (strncmp(str, "ISA", 3) == 0) {
175 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
176 } else if (strncmp(str, "EISA", 4) == 0) {
177 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
178 } else if (strncmp(str, "PCI", 3) == 0) {
179 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
180 mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
182 } else if (strncmp(str, "MCA", 3) == 0) {
183 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
185 printk(KERN_ERR "Unknown bustype %s\n", str);
190 * Parses an MP table BUS entry.
193 MP_ioapic_info(struct mpc_config_ioapic *m)
195 if (!(m->mpc_flags & MPC_APIC_USABLE)) {
196 printk(KERN_DEBUG "Encountered unusable APIC, ignoring it.\n");
200 printk(KERN_DEBUG "I/O APIC #%d Version %d at 0x%X\n",
201 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
202 if (nr_ioapics >= MAX_IO_APICS) {
203 printk(KERN_ERR "Max # of I/O APICs (%d) exceeded (found %d).\n",
204 MAX_IO_APICS, nr_ioapics);
205 panic("Recompile kernel with bigger MAX_IO_APICS!.\n");
207 if (!m->mpc_apicaddr) {
208 printk(KERN_ERR "WARNING: bogus zero I/O APIC address"
209 " found in MP table, skipping!\n");
212 mp_ioapics[nr_ioapics] = *m;
215 ioapic_id[ioapic_num] = m->mpc_apicid;
216 ioapic_phys_addr[ioapic_num] = m->mpc_apicaddr;
221 * Parses an MP table IRQ source entry.
224 MP_intsrc_info(struct mpc_config_intsrc *m)
226 mp_irqs [mp_irq_entries] = *m;
228 "Int: type %d, pol %d, trig %d, bus %d,"
229 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
230 m->mpc_irqtype, m->mpc_irqflag & 3,
231 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
232 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
233 if (++mp_irq_entries >= MAX_IRQ_SOURCES)
234 panic("Max # of irq sources exceeded!!\n");
238 * Parses an MP table LINT entry.
241 MP_lintsrc_info (struct mpc_config_lintsrc *m)
244 "Lint: type %d, pol %d, trig %d, bus %d,"
245 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
246 m->mpc_irqtype, m->mpc_irqflag & 3,
247 (m->mpc_irqflag >> 2) &3, m->mpc_srcbusid,
248 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
250 * Well it seems all SMP boards in existence
251 * use ExtINT/LVT1 == LINT0 and
252 * NMI/LVT2 == LINT1 - the following check
253 * will show us if this assumptions is false.
254 * Until then we do not have to add baggage.
256 if ((m->mpc_irqtype == mp_ExtINT) &&
257 (m->mpc_destapiclint != 0))
259 if ((m->mpc_irqtype == mp_NMI) &&
260 (m->mpc_destapiclint != 1))
265 * Parses the input MP table, storing various bits of information in global
266 * variables as it goes.
269 read_mpc(struct mp_config_table *mpc)
272 int count=sizeof(*mpc);
273 unsigned char *mpt=((unsigned char *)mpc)+count;
275 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
276 printk(KERN_ERR "SMP mptable: bad signature [%c%c%c%c]!\n",
277 mpc->mpc_signature[0],
278 mpc->mpc_signature[1],
279 mpc->mpc_signature[2],
280 mpc->mpc_signature[3]);
283 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
284 printk(KERN_ERR "SMP mptable: checksum error!\n");
287 if (mpc->mpc_spec!=0x01 && mpc->mpc_spec!=0x04) {
288 printk(KERN_ERR "SMP mptable: bad table version (%d)!\n",
292 if (!mpc->mpc_lapic) {
293 printk(KERN_ERR "SMP mptable: null local APIC address!\n");
296 memcpy(str, mpc->mpc_oem, 8);
298 printk(KERN_DEBUG " OEM ID: %s\n", str);
300 memcpy(str, mpc->mpc_productid, 12);
302 printk(KERN_DEBUG " Product ID: %s\n", str);
304 printk(KERN_DEBUG " APIC at: 0x%X\n", mpc->mpc_lapic);
306 /* Save the local APIC address, it might be non-default. */
307 lapic_phys_addr = mpc->mpc_lapic;
309 /* Now process all of the configuration blocks in the table. */
310 while (count < mpc->mpc_length) {
314 struct mpc_config_processor *m=
315 (struct mpc_config_processor *)mpt;
316 MP_processor_info(m);
323 struct mpc_config_bus *m=
324 (struct mpc_config_bus *)mpt;
332 struct mpc_config_ioapic *m=
333 (struct mpc_config_ioapic *)mpt;
341 struct mpc_config_intsrc *m=
342 (struct mpc_config_intsrc *)mpt;
351 struct mpc_config_lintsrc *m=
352 (struct mpc_config_lintsrc *)mpt;
360 //clustered_apic_check();
362 printk(KERN_ERR "SMP mptable: no CPUs registered!\n");
367 * Determines the multiprocessor configuration.
368 * The configuration information is stored in global variables so nothing is
369 * returned. find_mp_config() must be called before this function.
374 struct intel_mp_floating *mpf = mpf_found;
376 printk(KERN_WARNING "Assuming 1 CPU.\n");
378 /* Assign the only CPU logical=physical ID 0 */
379 cpu_set(0, cpu_present_map);
380 physid_set(0, phys_cpu_present_map);
381 cpu_info[0].logical_id = 0;
382 cpu_info[0].physical_id = 0;
383 cpu_info[0].arch.apic_id = 0;
387 printk(KERN_DEBUG "Intel MultiProcessor Specification v1.%d\n",
388 mpf->mpf_specification);
389 if (mpf->mpf_feature2 & (1<<7)) {
390 printk(KERN_DEBUG " IMCR and PIC compatibility mode.\n");
393 printk(KERN_DEBUG " Virtual Wire compatibility mode.\n");
398 * We don't support the default MP configuration.
399 * All supported multi-CPU systems must provide a full MP table.
401 if (mpf->mpf_feature1 != 0)
403 if (!mpf->mpf_physptr)
407 * Set this early so we don't allocate CPU0 if the
408 * MADT list doesn't list the bootstrap processor first.
409 * The bootstrap processor has to be logical ID 0... which
410 * we are reserving here.
412 cpu_set(0, cpu_present_map);
415 * Parse the MP configuration
417 if (read_mpc(phys_to_virt(mpf->mpf_physptr)))
418 panic("BIOS bug, MP table errors detected! (tell your hw vendor)\n");
422 * Scans a region of memory for the MP table.
425 scan(unsigned long base, unsigned long length)
427 unsigned int *bp = phys_to_virt(base);
428 struct intel_mp_floating *mpf;
430 printk(KERN_DEBUG "Scan for MP table from 0x%p for %ld bytes\n",
434 mpf = (struct intel_mp_floating *)bp;
435 if ((*bp == SMP_MAGIC_IDENT) &&
436 (mpf->mpf_length == 1) &&
437 !mpf_checksum((unsigned char *)bp, 16) &&
438 ((mpf->mpf_specification == 1)
439 || (mpf->mpf_specification == 4)) ) {
441 reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE);
442 if (mpf->mpf_physptr)
443 reserve_bootmem(mpf->mpf_physptr, PAGE_SIZE);
445 printk(KERN_DEBUG "Found MP table at: 0x%p\n", mpf);
455 * Locates the MP table, if there is one.
456 * This does not parse the MP table... get_mp_config() does that.
462 * 1) Scan the bottom 1K for a signature
463 * 2) Scan the top 1K of base RAM
464 * 3) Scan the 64K of bios
466 if (scan(0x0,0x400) ||
467 scan(639*0x400,0x400) ||
468 scan(0xF0000,0x10000))
472 * If it is an MP machine we should know now.
474 * If not, make a final effort and scan the
475 * Extended BIOS Data Area.
477 * NOTE! There are Linux loaders that will corrupt the EBDA
478 * area, and as such this kind of MP config may be less
479 * trustworthy, simply because the MP table may have been
480 * stomped on during early boot. These loaders are buggy and
483 if (scan(ebda_addr, 0x1000)) {
484 printk(KERN_WARNING "MP table found in EBDA\n");
488 /* If we have come this far, we did not find an MP table */
489 printk(KERN_DEBUG "No MP table found.\n");