2 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Sepherosa Ziehau <sepherosa@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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
35 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/machintr.h>
39 #include <sys/systm.h>
41 #include <machine/pmap.h>
42 #include <machine/smp.h>
43 #include <machine/md_var.h>
44 #include <machine/specialreg.h>
45 #include <machine_base/apic/mpapic.h>
48 #include "acpi_sdt_var.h"
49 #include "acpi_sci_var.h"
51 #define FADT_VPRINTF(fmt, arg...) \
54 kprintf("ACPI FADT: " fmt , ##arg); \
57 /* Fixed ACPI Description Table */
59 struct acpi_sdth fadt_hdr;
60 uint32_t fadt_fw_ctrl;
64 uint16_t fadt_sci_int;
65 uint32_t fadt_smi_cmd;
67 uint8_t fadt_acpi_dis;
73 static int acpi_sci_mode_detect = 0;
74 static int acpi_sci_irq = -1;
75 static enum intr_trigger acpi_sci_trig = INTR_TRIGGER_CONFORM;
76 static enum intr_polarity acpi_sci_pola = INTR_POLARITY_CONFORM;
81 struct acpi_fadt *fadt;
82 vm_paddr_t fadt_paddr;
83 enum intr_trigger trig;
84 enum intr_polarity pola;
88 fadt_paddr = sdt_search(ACPI_FADT_SIG);
89 if (fadt_paddr == 0) {
90 kprintf("fadt_probe: can't locate FADT\n");
94 fadt = sdt_sdth_map(fadt_paddr);
95 KKASSERT(fadt != NULL);
98 * FADT in ACPI specification 1.0 - 4.0
100 if (fadt->fadt_hdr.sdth_rev < 1 || fadt->fadt_hdr.sdth_rev > 4) {
101 kprintf("fadt_probe: unsupported FADT revision %d\n",
102 fadt->fadt_hdr.sdth_rev);
106 if (fadt->fadt_hdr.sdth_len < sizeof(*fadt)) {
107 kprintf("fadt_probe: invalid FADT length %u\n",
108 fadt->fadt_hdr.sdth_len);
112 kgetenv_int("hw.acpi.sci.enabled", &enabled);
116 acpi_sci_irq = fadt->fadt_sci_int;
118 env = kgetenv("hw.acpi.sci.trigger");
122 trig = INTR_TRIGGER_CONFORM;
123 if (strcmp(env, "edge") == 0)
124 trig = INTR_TRIGGER_EDGE;
125 else if (strcmp(env, "level") == 0)
126 trig = INTR_TRIGGER_LEVEL;
130 if (trig == INTR_TRIGGER_CONFORM)
133 env = kgetenv("hw.acpi.sci.polarity");
137 pola = INTR_POLARITY_CONFORM;
138 if (strcmp(env, "high") == 0)
139 pola = INTR_POLARITY_HIGH;
140 else if (strcmp(env, "low") == 0)
141 pola = INTR_POLARITY_LOW;
145 if (pola == INTR_POLARITY_CONFORM)
148 acpi_sci_trig = trig;
149 acpi_sci_pola = pola;
151 if (acpi_sci_irq >= 0) {
152 FADT_VPRINTF("SCI irq %d, %s/%s\n", acpi_sci_irq,
153 intr_str_trigger(acpi_sci_trig),
154 intr_str_polarity(acpi_sci_pola));
156 FADT_VPRINTF("SCI is disabled\n");
158 sdt_sdth_unmap(&fadt->fadt_hdr);
160 SYSINIT(fadt_probe, SI_BOOT2_PRESMP, SI_ORDER_SECOND, fadt_probe, 0);
163 acpi_sci_config(void)
165 KKASSERT(acpi_sci_irq >= 0);
167 if (acpi_sci_trig != INTR_TRIGGER_CONFORM) {
168 KKASSERT(acpi_sci_pola != INTR_POLARITY_CONFORM);
169 machintr_intr_config(acpi_sci_irq,
170 acpi_sci_trig, acpi_sci_pola);
174 if (!acpi_sci_mode_detect) {
177 * DO NOT configure SCI according to ACPI specification
178 * as level/low. There are so many broken BIOSes that
179 * could generate SCI as level/high, which will cause
180 * interrupt storm on IRQ 9 if we by default configure
181 * SCI as level/low; or BIOSes will generate SCI using
182 * edge trigger, which may cause spurious interrupt
183 * storm on IRQ 7 if 8259 used. So to be safe, we just
184 * configure SCI as edge/high at the cost that power
185 * button may not work at all.
187 acpi_sci_trig = INTR_TRIGGER_EDGE;
188 acpi_sci_pola = INTR_POLARITY_HIGH;
190 machintr_intr_config(acpi_sci_irq,
191 acpi_sci_trig, acpi_sci_pola);
194 /* TODO SCI mode detect */
198 acpi_sci_enabled(void)
200 if (acpi_sci_irq >= 0)
207 acpi_sci_pci_shariable(void)
209 if (acpi_sci_irq >= 0 &&
210 acpi_sci_trig == INTR_TRIGGER_LEVEL &&
211 acpi_sci_pola == INTR_POLARITY_LOW)