Introduce lapic enumerators, which is used to probe and config lapics
[dragonfly.git] / sys / platform / pc32 / i386 / mp_madt.c
1 /*
2  * Copyright (c) 2009 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Sepherosa Ziehau <sepherosa@gmail.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
38
39 #include <machine/pmap.h>
40 #include <machine/smp.h>
41 #include <machine/md_var.h>
42 #include <machine/specialreg.h>
43 #include <machine_base/apic/mpapic.h>
44
45 #define ACPI_RSDP_EBDA_MAPSZ    1024
46 #define ACPI_RSDP_BIOS_MAPSZ    0x20000
47 #define ACPI_RSDP_BIOS_MAPADDR  0xe0000
48
49 #define ACPI_RSDP_ALIGN         16
50
51 #define ACPI_RSDP_SIGLEN        8
52 #define ACPI_RSDP_SIG           "RSD PTR "
53
54 #define ACPI_SDTH_SIGLEN        4
55 #define ACPI_RSDT_SIG           "RSDT"
56 #define ACPI_XSDT_SIG           "XSDT"
57 #define ACPI_MADT_SIG           "APIC"
58
59 /* Root System Description Pointer */
60 struct acpi_rsdp {
61         uint8_t                 rsdp_sig[ACPI_RSDP_SIGLEN];
62         uint8_t                 rsdp_cksum;
63         uint8_t                 rsdp_oem_id[6];
64         uint8_t                 rsdp_rev;
65         uint32_t                rsdp_rsdt;
66         uint32_t                rsdp_len;
67         uint64_t                rsdp_xsdt;
68         uint8_t                 rsdp_ext_cksum;
69         uint8_t                 rsdp_rsvd[3];
70 } __packed;
71
72 /* System Description Table Header */
73 struct acpi_sdth {
74         uint8_t                 sdth_sig[ACPI_SDTH_SIGLEN];
75         uint32_t                sdth_len;
76         uint8_t                 sdth_rev;
77         uint8_t                 sdth_cksum;
78         uint8_t                 sdth_oem_id[6];
79         uint8_t                 sdth_oem_tbid[8];
80         uint32_t                sdth_oem_rev;
81         uint32_t                sdth_crt_id;
82         uint32_t                sdth_crt_rev;
83 } __packed;
84
85 /* Extended System Description Table */
86 struct acpi_xsdt {
87         struct acpi_sdth        xsdt_hdr;
88         uint64_t                xsdt_ents[1];
89 } __packed;
90
91 /* Root System Description Table */
92 struct acpi_rsdt {
93         struct acpi_sdth        rsdt_hdr;
94         uint32_t                rsdt_ents[1];
95 } __packed;
96
97 /* Multiple APIC Description Table */
98 struct acpi_madt {
99         struct acpi_sdth        madt_hdr;
100         uint32_t                madt_lapic_addr;
101         uint32_t                madt_flags;
102         uint8_t                 madt_ents[1];
103 } __packed;
104
105 /* Common parts of MADT APIC structure */
106 struct acpi_madt_ent {
107         uint8_t                 me_type;        /* MADT_ENT_ */
108         uint8_t                 me_len;
109 } __packed;
110
111 #define MADT_ENT_LAPIC          0
112 #define MADT_ENT_IOAPIC         1
113 #define MADT_ENT_LAPIC_ADDR     5
114
115 /* MADT Processor Local APIC */
116 struct acpi_madt_lapic {
117         struct acpi_madt_ent    ml_hdr;
118         uint8_t                 ml_cpu_id;
119         uint8_t                 ml_apic_id;
120         uint32_t                ml_flags;       /* MADT_LAPIC_ */
121 } __packed;
122
123 #define MADT_LAPIC_ENABLED      0x1
124
125 /* MADT I/O APIC */
126 struct acpi_madt_ioapic {
127         struct acpi_madt_ent    mio_hdr;
128         uint8_t                 mio_apic_id;
129         uint8_t                 mio_reserved;
130         uint32_t                mio_addr;
131         uint32_t                mio_gsi_base;
132 } __packed;
133
134 /* MADT Local APIC Address Override */
135 struct acpi_madt_lapic_addr {
136         struct acpi_madt_ent    mla_hdr;
137         uint16_t                mla_reserved;
138         uint64_t                mla_lapic_addr;
139 } __packed;
140
141 struct madt_lapic_enumerator {
142         struct lapic_enumerator enumerator;
143         vm_paddr_t              madt_paddr;
144 };
145
146 typedef vm_paddr_t              (*madt_search_t)(vm_paddr_t);
147 typedef int                     (*madt_iter_t)(void *,
148                                     const struct acpi_madt_ent *);
149
150 static const struct acpi_rsdp   *madt_rsdp_search(const uint8_t *, int);
151 static void                     *madt_sdth_map(vm_paddr_t);
152 static void                     madt_sdth_unmap(struct acpi_sdth *);
153 static vm_paddr_t               madt_search_xsdt(vm_paddr_t);
154 static vm_paddr_t               madt_search_rsdt(vm_paddr_t);
155 static int                      madt_check(vm_paddr_t);
156 static int                      madt_iterate_entries(struct acpi_madt *,
157                                     madt_iter_t, void *);
158
159 static vm_paddr_t               madt_probe(void);
160 static vm_offset_t              madt_pass1(vm_paddr_t);
161 static int                      madt_pass2(vm_paddr_t, int);
162
163 static void                     madt_lapic_enumerate(struct lapic_enumerator *);
164 static int                      madt_lapic_probe(struct lapic_enumerator *);
165
166 extern u_long   ebda_addr;
167
168 static vm_paddr_t
169 madt_probe(void)
170 {
171         const struct acpi_rsdp *rsdp;
172         madt_search_t search;
173         vm_paddr_t search_paddr, madt_paddr;
174         vm_size_t mapsz;
175         uint8_t *ptr;
176
177         if (ebda_addr != 0) {
178                 mapsz = ACPI_RSDP_EBDA_MAPSZ;
179                 ptr = pmap_mapdev(ebda_addr, mapsz);
180
181                 rsdp = madt_rsdp_search(ptr, mapsz);
182                 if (rsdp == NULL) {
183                         kprintf("madt: RSDP not in EBDA\n");
184                         pmap_unmapdev((vm_offset_t)ptr, mapsz);
185
186                         ptr = NULL;
187                         mapsz = 0;
188                 } else {
189                         kprintf("madt: RSDP in EBDA\n");
190                         goto found_rsdp;
191                 }
192         }
193
194         mapsz = ACPI_RSDP_BIOS_MAPSZ;
195         ptr = pmap_mapdev(ACPI_RSDP_BIOS_MAPADDR, mapsz);
196
197         rsdp = madt_rsdp_search(ptr, mapsz);
198         if (rsdp == NULL) {
199                 kprintf("madt_probe: no RSDP\n");
200                 pmap_unmapdev((vm_offset_t)ptr, mapsz);
201                 return 0;
202         } else {
203                 kprintf("madt: RSDP in BIOS mem\n");
204         }
205
206 found_rsdp:
207         if (rsdp->rsdp_rev != 2) {
208                 search_paddr = rsdp->rsdp_rsdt;
209                 search = madt_search_rsdt;
210         } else {
211                 search_paddr = rsdp->rsdp_xsdt;
212                 search = madt_search_xsdt;
213         }
214         pmap_unmapdev((vm_offset_t)ptr, mapsz);
215
216         madt_paddr = search(search_paddr);
217         if (madt_paddr == 0) {
218                 kprintf("madt_probe: can't locate MADT\n");
219                 return 0;
220         }
221
222         /* Preliminary checks */
223         if (madt_check(madt_paddr))
224                 return 0;
225         return madt_paddr;
226 }
227
228 static const struct acpi_rsdp *
229 madt_rsdp_search(const uint8_t *target, int size)
230 {
231         const struct acpi_rsdp *rsdp;
232         int i;
233
234         KKASSERT(size > sizeof(*rsdp));
235
236         for (i = 0; i < size - sizeof(*rsdp); i += ACPI_RSDP_ALIGN) {
237                 rsdp = (const struct acpi_rsdp *)&target[i];
238                 if (memcmp(rsdp->rsdp_sig, ACPI_RSDP_SIG,
239                            ACPI_RSDP_SIGLEN) == 0)
240                         return rsdp;
241         }
242         return NULL;
243 }
244
245 static void *
246 madt_sdth_map(vm_paddr_t paddr)
247 {
248         struct acpi_sdth *sdth;
249         vm_size_t mapsz;
250
251         sdth = pmap_mapdev(paddr, sizeof(*sdth));
252         mapsz = sdth->sdth_len;
253         pmap_unmapdev((vm_offset_t)sdth, sizeof(*sdth));
254
255         if (mapsz < sizeof(*sdth))
256                 return NULL;
257
258         return pmap_mapdev(paddr, mapsz);
259 }
260
261 static void
262 madt_sdth_unmap(struct acpi_sdth *sdth)
263 {
264         pmap_unmapdev((vm_offset_t)sdth, sdth->sdth_len);
265 }
266
267 static vm_paddr_t
268 madt_search_xsdt(vm_paddr_t xsdt_paddr)
269 {
270         struct acpi_xsdt *xsdt;
271         vm_paddr_t madt_paddr = 0;
272         int i, nent;
273
274         if (xsdt_paddr == 0) {
275                 kprintf("madt_search_xsdt: XSDT paddr == 0\n");
276                 return 0;
277         }
278
279         xsdt = madt_sdth_map(xsdt_paddr);
280         if (xsdt == NULL) {
281                 kprintf("madt_search_xsdt: can't map XSDT\n");
282                 return 0;
283         }
284
285         if (memcmp(xsdt->xsdt_hdr.sdth_sig, ACPI_XSDT_SIG,
286                    ACPI_SDTH_SIGLEN) != 0) {
287                 kprintf("madt_search_xsdt: not XSDT\n");
288                 goto back;
289         }
290
291         if (xsdt->xsdt_hdr.sdth_rev != 1) {
292                 kprintf("madt_search_xsdt: unsupported XSDT revision %d\n",
293                         xsdt->xsdt_hdr.sdth_rev);
294                 goto back;
295         }
296
297         nent = (xsdt->xsdt_hdr.sdth_len - sizeof(xsdt->xsdt_hdr)) /
298                sizeof(xsdt->xsdt_ents[0]);
299         for (i = 0; i < nent; ++i) {
300                 struct acpi_sdth *sdth;
301
302                 if (xsdt->xsdt_ents[i] == 0)
303                         continue;
304
305                 sdth = madt_sdth_map(xsdt->xsdt_ents[i]);
306                 if (sdth != NULL) {
307                         int ret;
308
309                         ret = memcmp(sdth->sdth_sig, ACPI_MADT_SIG,
310                                      ACPI_SDTH_SIGLEN);
311                         madt_sdth_unmap(sdth);
312
313                         if (ret == 0) {
314                                 kprintf("madt: MADT in XSDT\n");
315                                 madt_paddr = xsdt->xsdt_ents[i];
316                                 break;
317                         }
318                 }
319         }
320 back:
321         madt_sdth_unmap(&xsdt->xsdt_hdr);
322         return madt_paddr;
323 }
324
325 static vm_paddr_t
326 madt_search_rsdt(vm_paddr_t rsdt_paddr)
327 {
328         struct acpi_rsdt *rsdt;
329         vm_paddr_t madt_paddr = 0;
330         int i, nent;
331
332         if (rsdt_paddr == 0) {
333                 kprintf("madt_search_rsdt: RSDT paddr == 0\n");
334                 return 0;
335         }
336
337         rsdt = madt_sdth_map(rsdt_paddr);
338         if (rsdt == NULL) {
339                 kprintf("madt_search_rsdt: can't map RSDT\n");
340                 return 0;
341         }
342
343         if (memcmp(rsdt->rsdt_hdr.sdth_sig, ACPI_RSDT_SIG,
344                    ACPI_SDTH_SIGLEN) != 0) {
345                 kprintf("madt_search_rsdt: not RSDT\n");
346                 goto back;
347         }
348
349         if (rsdt->rsdt_hdr.sdth_rev != 1) {
350                 kprintf("madt_search_rsdt: unsupported RSDT revision %d\n",
351                         rsdt->rsdt_hdr.sdth_rev);
352                 goto back;
353         }
354
355         nent = (rsdt->rsdt_hdr.sdth_len - sizeof(rsdt->rsdt_hdr)) /
356                sizeof(rsdt->rsdt_ents[0]);
357         for (i = 0; i < nent; ++i) {
358                 struct acpi_sdth *sdth;
359
360                 if (rsdt->rsdt_ents[i] == 0)
361                         continue;
362
363                 sdth = madt_sdth_map(rsdt->rsdt_ents[i]);
364                 if (sdth != NULL) {
365                         int ret;
366
367                         ret = memcmp(sdth->sdth_sig, ACPI_MADT_SIG,
368                                      ACPI_SDTH_SIGLEN);
369                         madt_sdth_unmap(sdth);
370
371                         if (ret == 0) {
372                                 kprintf("madt: MADT in RSDT\n");
373                                 madt_paddr = rsdt->rsdt_ents[i];
374                                 break;
375                         }
376                 }
377         }
378 back:
379         madt_sdth_unmap(&rsdt->rsdt_hdr);
380         return madt_paddr;
381 }
382
383 static int
384 madt_pass1_callback(void *xarg, const struct acpi_madt_ent *ent)
385 {
386         const struct acpi_madt_lapic_addr *lapic_addr_ent;
387         uint64_t *addr64 = xarg;
388
389         if (ent->me_type != MADT_ENT_LAPIC_ADDR)
390                 return 0;
391         if (ent->me_len < sizeof(*lapic_addr_ent)) {
392                 kprintf("madt_pass1: invalid LAPIC address override length\n");
393                 return 0;
394         }
395         lapic_addr_ent = (const struct acpi_madt_lapic_addr *)ent;
396
397         *addr64 = lapic_addr_ent->mla_lapic_addr;
398         return 0;
399 }
400
401 static vm_offset_t
402 madt_pass1(vm_paddr_t madt_paddr)
403 {
404         struct acpi_madt *madt;
405         vm_offset_t lapic_addr;
406         uint64_t lapic_addr64;
407         int error;
408
409         KKASSERT(madt_paddr != 0);
410
411         madt = madt_sdth_map(madt_paddr);
412         KKASSERT(madt != NULL);
413
414         kprintf("madt: LAPIC address 0x%08x, flags %#x\n",
415                 madt->madt_lapic_addr, madt->madt_flags);
416         lapic_addr = madt->madt_lapic_addr;
417
418         lapic_addr64 = 0;
419         error = madt_iterate_entries(madt, madt_pass1_callback, &lapic_addr64);
420         if (error)
421                 panic("madt_iterate_entries(pass1) failed\n");
422
423         if (lapic_addr64 != 0) {
424                 kprintf("Warning: 64bits lapic address 0x%llx\n", lapic_addr64);
425                 /* XXX vm_offset_t is 32bits on i386 */
426                 lapic_addr = lapic_addr64;
427         }
428
429         madt_sdth_unmap(&madt->madt_hdr);
430
431         return lapic_addr;
432 }
433
434 struct madt_pass2_cbarg {
435         int     cpu;
436         int     bsp_found;
437         int     bsp_apic_id;
438 };
439
440 static int
441 madt_pass2_callback(void *xarg, const struct acpi_madt_ent *ent)
442 {
443         const struct acpi_madt_lapic *lapic_ent;
444         struct madt_pass2_cbarg *arg = xarg;
445
446         if (ent->me_type != MADT_ENT_LAPIC)
447                 return 0;
448
449         lapic_ent = (const struct acpi_madt_lapic *)ent;
450         if (lapic_ent->ml_flags & MADT_LAPIC_ENABLED) {
451                 kprintf("madt: cpu_id %d, apic_id %d\n",
452                         lapic_ent->ml_cpu_id, lapic_ent->ml_apic_id);
453                 if (lapic_ent->ml_apic_id == arg->bsp_apic_id) {
454                         mp_set_cpuids(0, lapic_ent->ml_apic_id);
455                         arg->bsp_found = 1;
456                 } else {
457                         mp_set_cpuids(arg->cpu, lapic_ent->ml_apic_id);
458                         arg->cpu++;
459                 }
460         }
461         return 0;
462 }
463
464 static int
465 madt_pass2(vm_paddr_t madt_paddr, int bsp_apic_id)
466 {
467         struct acpi_madt *madt;
468         struct madt_pass2_cbarg arg;
469         int error;
470
471         kprintf("madt: BSP apic id %d\n", bsp_apic_id);
472
473         KKASSERT(madt_paddr != 0);
474
475         madt = madt_sdth_map(madt_paddr);
476         KKASSERT(madt != NULL);
477
478         bzero(&arg, sizeof(arg));
479         arg.cpu = 1;
480         arg.bsp_apic_id = bsp_apic_id;
481
482         error = madt_iterate_entries(madt, madt_pass2_callback, &arg);
483         if (error)
484                 panic("madt_iterate_entries(pass2) failed\n");
485
486         KKASSERT(arg.bsp_found);
487         KKASSERT(arg.cpu > 1);
488         mp_naps = arg.cpu - 1; /* exclude BSP */
489
490         madt_sdth_unmap(&madt->madt_hdr);
491
492         return 0;
493 }
494
495 struct madt_check_cbarg {
496         int     cpu_count;
497         int     bsp_found;
498         int     bsp_apic_id;
499 };
500
501 static int
502 madt_check_callback(void *xarg, const struct acpi_madt_ent *ent)
503 {
504         struct madt_check_cbarg *arg = xarg;
505         const struct acpi_madt_lapic *lapic_ent;
506
507         if (ent->me_type != MADT_ENT_LAPIC)
508                 return 0;
509         lapic_ent = (const struct acpi_madt_lapic *)ent;
510
511         if (lapic_ent->ml_flags & MADT_LAPIC_ENABLED) {
512                 arg->cpu_count++;
513                 if (lapic_ent->ml_apic_id == arg->bsp_apic_id) {
514                         if (arg->bsp_found) {
515                                 kprintf("madt_check: more than one BSP?\n");
516                                 return EINVAL;
517                         }
518                         arg->bsp_found = 1;
519                 }
520         }
521         return 0;
522 }
523
524 static int
525 madt_check(vm_paddr_t madt_paddr)
526 {
527         struct madt_check_cbarg arg;
528         struct acpi_madt *madt;
529         int error = 0;
530
531         KKASSERT(madt_paddr != 0);
532
533         madt = madt_sdth_map(madt_paddr);
534         KKASSERT(madt != NULL);
535
536         if (madt->madt_hdr.sdth_rev != 1 && madt->madt_hdr.sdth_rev != 2) {
537                 kprintf("madt_check: unsupported MADT revision %d\n",
538                         madt->madt_hdr.sdth_rev);
539                 error = EOPNOTSUPP;
540                 goto back;
541         }
542
543         if (madt->madt_hdr.sdth_len <
544             sizeof(*madt) - sizeof(madt->madt_ents)) {
545                 kprintf("madt_check: invalid MADT length %u\n",
546                         madt->madt_hdr.sdth_len);
547                 error = EINVAL;
548                 goto back;
549         }
550
551         bzero(&arg, sizeof(arg));
552         arg.bsp_apic_id = (cpu_procinfo & CPUID_LOCAL_APIC_ID) >> 24;
553
554         error = madt_iterate_entries(madt, madt_check_callback, &arg);
555         if (!error) {
556                 if (arg.cpu_count <= 1) {
557                         kprintf("madt_check: less than 2 CPUs is found\n");
558                         error = EOPNOTSUPP;
559                 } else if (!arg.bsp_found) {
560                         kprintf("madt_check: no BSP\n");
561                         error = EINVAL;
562                 }
563         }
564 back:
565         madt_sdth_unmap(&madt->madt_hdr);
566         return error;
567 }
568
569 static int
570 madt_iterate_entries(struct acpi_madt *madt, madt_iter_t func, void *arg)
571 {
572         int size, cur, error;
573
574         size = madt->madt_hdr.sdth_len -
575                (sizeof(*madt) - sizeof(madt->madt_ents));
576         cur = 0;
577         error = 0;
578
579         while (size - cur > sizeof(struct acpi_madt_ent)) {
580                 const struct acpi_madt_ent *ent;
581
582                 ent = (const struct acpi_madt_ent *)&madt->madt_ents[cur];
583                 if (ent->me_len < sizeof(*ent)) {
584                         kprintf("madt_iterate_entries: invalid MADT "
585                                 "entry len %d\n", ent->me_len);
586                         error = EINVAL;
587                         break;
588                 }
589                 if (ent->me_len > (size - cur)) {
590                         kprintf("madt_iterate_entries: invalid MADT "
591                                 "entry len %d, > table length\n", ent->me_len);
592                         error = EINVAL;
593                         break;
594                 }
595
596                 cur += ent->me_len;
597
598                 /*
599                  * Only Local APIC and I/O APIC are defined in
600                  * ACPI specification 1.0 - 3.0
601                  */
602                 switch (ent->me_type) {
603                 case MADT_ENT_LAPIC:
604                         if (ent->me_len < sizeof(struct acpi_madt_lapic)) {
605                                 kprintf("madt_iterate_entries: invalid MADT "
606                                         "lapic entry len %d\n", ent->me_len);
607                                 error = EINVAL;
608                         }
609                         break;
610
611                 case MADT_ENT_IOAPIC:
612                         if (ent->me_len < sizeof(struct acpi_madt_ioapic)) {
613                                 kprintf("madt_iterate_entries: invalid MADT "
614                                         "ioapic entry len %d\n", ent->me_len);
615                                 error = EINVAL;
616                         }
617                         break;
618                 }
619                 if (error)
620                         break;
621
622                 error = func(arg, ent);
623                 if (error)
624                         break;
625         }
626         return error;
627 }
628
629 static int
630 madt_lapic_probe(struct lapic_enumerator *e)
631 {
632         vm_paddr_t madt_paddr;
633
634         madt_paddr = madt_probe();
635         if (madt_paddr == 0)
636                 return ENXIO;
637
638         ((struct madt_lapic_enumerator *)e)->madt_paddr = madt_paddr;
639         return 0;
640 }
641
642 static void
643 madt_lapic_enumerate(struct lapic_enumerator *e)
644 {
645         vm_paddr_t madt_paddr;
646         vm_offset_t lapic_addr;
647         int bsp_apic_id;
648
649         madt_paddr = ((struct madt_lapic_enumerator *)e)->madt_paddr;
650         KKASSERT(madt_paddr != 0);
651
652         lapic_addr = madt_pass1(madt_paddr);
653         if (lapic_addr == 0)
654                 panic("madt_lapic_enumerate no local apic\n");
655
656         bsp_apic_id = (cpu_procinfo & CPUID_LOCAL_APIC_ID) >> 24;
657         if (madt_pass2(madt_paddr, bsp_apic_id))
658                 panic("mp_enable: madt_pass2 failed\n");
659
660         lapic_init(lapic_addr);
661 }
662
663 static struct madt_lapic_enumerator     madt_lapic_enumerator = {
664         .enumerator = {
665                 .lapic_prio = LAPIC_ENUM_PRIO_MADT,
666                 .lapic_probe = madt_lapic_probe,
667                 .lapic_enumerate = madt_lapic_enumerate
668         }
669 };
670
671 static void
672 madt_apic_register(void)
673 {
674         int prio;
675
676         prio = LAPIC_ENUM_PRIO_MADT;
677         kgetenv_int("hw.madt_lapic_prio", &prio);
678         madt_lapic_enumerator.enumerator.lapic_prio = prio;
679
680         lapic_enumerator_register(&madt_lapic_enumerator.enumerator);
681 }
682 SYSINIT(madt, SI_BOOT2_PRESMP, SI_ORDER_ANY, madt_apic_register, 0);