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/interrupt.h>
38 #include <sys/kernel.h>
39 #include <sys/machintr.h>
40 #include <sys/systm.h>
41 #include <sys/thread2.h>
43 #include <contrib/dev/acpica/source/include/acpi.h>
45 #include "acpi_sdt_var.h"
46 #include "acpi_sci_var.h"
48 #define FADT_VPRINTF(fmt, arg...) \
51 kprintf("ACPI FADT: " fmt , ##arg); \
54 struct acpi_sci_mode {
55 enum intr_trigger sci_trig;
56 enum intr_polarity sci_pola;
59 static int acpi_sci_irq = -1;
60 static enum intr_trigger acpi_sci_trig = INTR_TRIGGER_CONFORM;
61 static enum intr_polarity acpi_sci_pola = INTR_POLARITY_CONFORM;
62 static const struct acpi_sci_mode *acpi_sci_mode1 = NULL;
64 static const struct acpi_sci_mode acpi_sci_modes[] = {
66 * NOTE: Order is critical
68 { INTR_TRIGGER_LEVEL, INTR_POLARITY_LOW },
69 { INTR_TRIGGER_LEVEL, INTR_POLARITY_HIGH },
70 { INTR_TRIGGER_EDGE, INTR_POLARITY_HIGH },
71 { INTR_TRIGGER_EDGE, INTR_POLARITY_LOW },
73 /* Required last entry */
74 { INTR_TRIGGER_CONFORM, INTR_POLARITY_CONFORM }
80 ACPI_TABLE_FADT *fadt;
81 vm_paddr_t fadt_paddr;
82 enum intr_trigger trig;
83 enum intr_polarity pola;
87 fadt_paddr = sdt_search(ACPI_SIG_FADT);
88 if (fadt_paddr == 0) {
89 kprintf("fadt_probe: can't locate FADT\n");
93 fadt = sdt_sdth_map(fadt_paddr);
94 KKASSERT(fadt != NULL);
97 * FADT in ACPI specification 1.0 - 6.0
99 if (fadt->Header.Revision < 1 || fadt->Header.Revision > 6) {
100 kprintf("fadt_probe: unknown FADT revision %d\n",
101 fadt->Header.Revision);
104 if (fadt->Header.Length < ACPI_FADT_V1_SIZE) {
105 kprintf("fadt_probe: invalid FADT length %u (< %u)\n",
106 fadt->Header.Length, ACPI_FADT_V1_SIZE);
110 kgetenv_int("hw.acpi.sci.enabled", &enabled);
114 acpi_sci_irq = fadt->SciInterrupt;
116 env = kgetenv("hw.acpi.sci.trigger");
120 trig = INTR_TRIGGER_CONFORM;
121 if (strcmp(env, "edge") == 0)
122 trig = INTR_TRIGGER_EDGE;
123 else if (strcmp(env, "level") == 0)
124 trig = INTR_TRIGGER_LEVEL;
128 if (trig == INTR_TRIGGER_CONFORM)
131 env = kgetenv("hw.acpi.sci.polarity");
135 pola = INTR_POLARITY_CONFORM;
136 if (strcmp(env, "high") == 0)
137 pola = INTR_POLARITY_HIGH;
138 else if (strcmp(env, "low") == 0)
139 pola = INTR_POLARITY_LOW;
143 if (pola == INTR_POLARITY_CONFORM)
146 acpi_sci_trig = trig;
147 acpi_sci_pola = pola;
149 if (acpi_sci_irq >= 0) {
150 FADT_VPRINTF("SCI irq %d, %s/%s\n", acpi_sci_irq,
151 intr_str_trigger(acpi_sci_trig),
152 intr_str_polarity(acpi_sci_pola));
154 FADT_VPRINTF("SCI is disabled\n");
156 sdt_sdth_unmap(&fadt->Header);
158 SYSINIT(fadt_probe, SI_BOOT2_PRESMP, SI_ORDER_SECOND, fadt_probe, 0);
161 acpi_sci_dummy_intr(void *dummy __unused, void *frame __unused)
166 acpi_sci_test(const struct acpi_sci_mode *mode)
171 FADT_VPRINTF("SCI testing %s/%s\n",
172 intr_str_trigger(mode->sci_trig),
173 intr_str_polarity(mode->sci_pola));
175 last_cnt = get_interrupt_counter(acpi_sci_irq, 0);
177 machintr_legacy_intr_config(acpi_sci_irq,
178 mode->sci_trig, mode->sci_pola);
180 sci_desc = register_int(acpi_sci_irq,
181 acpi_sci_dummy_intr, NULL, "sci", NULL,
182 INTR_EXCL | INTR_CLOCK |
183 INTR_NOPOLL | INTR_MPSAFE | INTR_NOENTROPY, 0);
187 unregister_int(sci_desc, 0);
189 if (get_interrupt_counter(acpi_sci_irq, 0) - last_cnt < 20) {
190 acpi_sci_trig = mode->sci_trig;
191 acpi_sci_pola = mode->sci_pola;
193 kprintf("ACPI FADT: SCI select %s/%s\n",
194 intr_str_trigger(acpi_sci_trig),
195 intr_str_polarity(acpi_sci_pola));
202 acpi_sci_config(void)
204 const struct acpi_sci_mode *mode;
206 KKASSERT(mycpuid == 0);
208 if (machintr_legacy_intr_find(acpi_sci_irq,
209 INTR_TRIGGER_CONFORM, INTR_POLARITY_CONFORM) < 0) {
210 kprintf("ACPI FADT: SCI irq %d is invalid, disable\n",
216 if (acpi_sci_irq < 0)
219 if (acpi_sci_trig != INTR_TRIGGER_CONFORM) {
220 KKASSERT(acpi_sci_pola != INTR_POLARITY_CONFORM);
221 machintr_legacy_intr_config(acpi_sci_irq,
222 acpi_sci_trig, acpi_sci_pola);
226 kprintf("ACPI FADT: SCI testing interrupt mode ...\n");
227 if (acpi_sci_mode1 != NULL) {
228 if (acpi_sci_test(acpi_sci_mode1))
231 for (mode = acpi_sci_modes; mode->sci_trig != INTR_TRIGGER_CONFORM;
233 if (mode == acpi_sci_mode1)
235 if (acpi_sci_test(mode))
239 kprintf("ACPI FADT: no suitable interrupt mode for SCI, disable\n");
244 acpi_sci_enabled(void)
246 if (acpi_sci_irq >= 0)
253 acpi_sci_pci_shareable(void)
255 if (acpi_sci_irq >= 0 &&
256 acpi_sci_trig == INTR_TRIGGER_LEVEL &&
257 acpi_sci_pola == INTR_POLARITY_LOW)
270 acpi_sci_setmode1(enum intr_trigger trig, enum intr_polarity pola)
272 const struct acpi_sci_mode *mode;
274 for (mode = acpi_sci_modes; mode->sci_trig != INTR_TRIGGER_CONFORM;
276 if (mode->sci_trig == trig && mode->sci_pola == pola) {
277 acpi_sci_mode1 = mode;