acpi: Parse FADT to extract SCI IRQ number
[dragonfly.git] / sys / platform / pc32 / acpica5 / acpi_fadt.c
CommitLineData
05ba9093
SZ
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/bus.h>
37#include <sys/kernel.h>
38#include <sys/systm.h>
39
40#include <machine/pmap.h>
41#include <machine/smp.h>
42#include <machine/md_var.h>
43#include <machine/specialreg.h>
44#include <machine_base/apic/mpapic.h>
45
46#include "acpi_sdt.h"
47#include "acpi_sdt_var.h"
48
49#define FADT_VPRINTF(fmt, arg...) \
50do { \
51 if (bootverbose) \
52 kprintf("ACPI FADT: " fmt , ##arg); \
53} while (0)
54
55/* Fixed ACPI Description Table */
56struct acpi_fadt {
57 struct acpi_sdth fadt_hdr;
58 uint32_t fadt_fw_ctrl;
59 uint32_t fadt_dsdt;
60 uint8_t fadt_rsvd1;
61 uint8_t fadt_pm_prof;
62 uint16_t fadt_sci_int;
63 uint32_t fadt_smi_cmd;
64 uint8_t fadt_acpi_en;
65 uint8_t fadt_acpi_dis;
66 uint8_t fadt_s4bios;
67 uint8_t fadt_pstate;
68 /* More ... */
69} __packed;
70
71static int acpi_sci_irq = -1;
72
73static void
74fadt_probe(void)
75{
76 struct acpi_fadt *fadt;
77 vm_paddr_t fadt_paddr;
78
79 fadt_paddr = sdt_search(ACPI_FADT_SIG);
80 if (fadt_paddr == 0) {
81 kprintf("fadt_probe: can't locate FADT\n");
82 return;
83 }
84
85 fadt = sdt_sdth_map(fadt_paddr);
86 KKASSERT(fadt != NULL);
87
88 /*
89 * FADT in ACPI specification 1.0 - 4.0
90 */
91 if (fadt->fadt_hdr.sdth_rev < 1 || fadt->fadt_hdr.sdth_rev > 4) {
92 kprintf("fadt_probe: unsupported FADT revision %d\n",
93 fadt->fadt_hdr.sdth_rev);
94 goto back;
95 }
96
97 if (fadt->fadt_hdr.sdth_len < sizeof(*fadt)) {
98 kprintf("fadt_probe: invalid FADT length %u\n",
99 fadt->fadt_hdr.sdth_len);
100 goto back;
101 }
102
103 acpi_sci_irq = fadt->fadt_sci_int;
104 kprintf("ACPI FADT: SCI irq %d\n", acpi_sci_irq);
105
106back:
107 sdt_sdth_unmap(&fadt->fadt_hdr);
108}
109SYSINIT(fadt_probe, SI_BOOT2_PRESMP, SI_ORDER_SECOND, fadt_probe, 0);