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>
43 #include "acpi_sdt_var.h"
44 #include "acpi_sci_var.h"
46 #define FADT_VPRINTF(fmt, arg...) \
49 kprintf("ACPI FADT: " fmt , ##arg); \
52 /* Fixed ACPI Description Table */
54 struct acpi_sdth fadt_hdr;
55 uint32_t fadt_fw_ctrl;
59 uint16_t fadt_sci_int;
60 uint32_t fadt_smi_cmd;
62 uint8_t fadt_acpi_dis;
68 struct acpi_sci_mode {
69 enum intr_trigger sci_trig;
70 enum intr_polarity sci_pola;
73 static int acpi_sci_irq = -1;
74 static enum intr_trigger acpi_sci_trig = INTR_TRIGGER_CONFORM;
75 static enum intr_polarity acpi_sci_pola = INTR_POLARITY_CONFORM;
77 static const struct acpi_sci_mode acpi_sci_modes[] = {
79 * NOTE: Order is critical
81 { INTR_TRIGGER_LEVEL, INTR_POLARITY_LOW },
82 { INTR_TRIGGER_LEVEL, INTR_POLARITY_HIGH },
83 { INTR_TRIGGER_EDGE, INTR_POLARITY_HIGH },
84 { INTR_TRIGGER_EDGE, INTR_POLARITY_LOW },
86 /* Required last entry */
87 { INTR_TRIGGER_CONFORM, INTR_POLARITY_CONFORM }
93 struct acpi_fadt *fadt;
94 vm_paddr_t fadt_paddr;
95 enum intr_trigger trig;
96 enum intr_polarity pola;
100 fadt_paddr = sdt_search(ACPI_FADT_SIG);
101 if (fadt_paddr == 0) {
102 kprintf("fadt_probe: can't locate FADT\n");
106 fadt = sdt_sdth_map(fadt_paddr);
107 KKASSERT(fadt != NULL);
110 * FADT in ACPI specification 1.0 - 4.0
112 if (fadt->fadt_hdr.sdth_rev < 1 || fadt->fadt_hdr.sdth_rev > 4) {
113 kprintf("fadt_probe: unsupported FADT revision %d\n",
114 fadt->fadt_hdr.sdth_rev);
118 if (fadt->fadt_hdr.sdth_len < sizeof(*fadt)) {
119 kprintf("fadt_probe: invalid FADT length %u\n",
120 fadt->fadt_hdr.sdth_len);
124 kgetenv_int("hw.acpi.sci.enabled", &enabled);
128 acpi_sci_irq = fadt->fadt_sci_int;
130 env = kgetenv("hw.acpi.sci.trigger");
134 trig = INTR_TRIGGER_CONFORM;
135 if (strcmp(env, "edge") == 0)
136 trig = INTR_TRIGGER_EDGE;
137 else if (strcmp(env, "level") == 0)
138 trig = INTR_TRIGGER_LEVEL;
142 if (trig == INTR_TRIGGER_CONFORM)
145 env = kgetenv("hw.acpi.sci.polarity");
149 pola = INTR_POLARITY_CONFORM;
150 if (strcmp(env, "high") == 0)
151 pola = INTR_POLARITY_HIGH;
152 else if (strcmp(env, "low") == 0)
153 pola = INTR_POLARITY_LOW;
157 if (pola == INTR_POLARITY_CONFORM)
160 acpi_sci_trig = trig;
161 acpi_sci_pola = pola;
163 if (acpi_sci_irq >= 0) {
164 FADT_VPRINTF("SCI irq %d, %s/%s\n", acpi_sci_irq,
165 intr_str_trigger(acpi_sci_trig),
166 intr_str_polarity(acpi_sci_pola));
168 FADT_VPRINTF("SCI is disabled\n");
170 sdt_sdth_unmap(&fadt->fadt_hdr);
172 SYSINIT(fadt_probe, SI_BOOT2_PRESMP, SI_ORDER_SECOND, fadt_probe, 0);
175 acpi_sci_dummy_intr(void *dummy __unused, void *frame __unused)
180 acpi_sci_config(void)
182 const struct acpi_sci_mode *mode;
184 if (acpi_sci_irq < 0)
187 if (acpi_sci_trig != INTR_TRIGGER_CONFORM) {
188 KKASSERT(acpi_sci_pola != INTR_POLARITY_CONFORM);
189 machintr_intr_config(acpi_sci_irq,
190 acpi_sci_trig, acpi_sci_pola);
194 kprintf("ACPI FADT: SCI testing interrupt mode ...\n");
195 for (mode = acpi_sci_modes; mode->sci_trig != INTR_TRIGGER_CONFORM;
200 FADT_VPRINTF("SCI testing %s/%s\n",
201 intr_str_trigger(mode->sci_trig),
202 intr_str_polarity(mode->sci_pola));
204 last_cnt = get_interrupt_counter(acpi_sci_irq);
206 machintr_intr_config(acpi_sci_irq,
207 mode->sci_trig, mode->sci_pola);
209 sci_desc = register_int(acpi_sci_irq,
210 acpi_sci_dummy_intr, NULL, "sci", NULL,
211 INTR_EXCL | INTR_CLOCK |
212 INTR_NOPOLL | INTR_MPSAFE | INTR_NOENTROPY);
216 unregister_int(sci_desc);
218 if (get_interrupt_counter(acpi_sci_irq) - last_cnt < 20) {
219 acpi_sci_trig = mode->sci_trig;
220 acpi_sci_pola = mode->sci_pola;
222 kprintf("ACPI FADT: SCI select %s/%s\n",
223 intr_str_trigger(acpi_sci_trig),
224 intr_str_polarity(acpi_sci_pola));
229 kprintf("ACPI FADT: no suitable interrupt mode for SCI, disable\n");
234 acpi_sci_enabled(void)
236 if (acpi_sci_irq >= 0)
243 acpi_sci_pci_shariable(void)
245 if (acpi_sci_irq >= 0 &&
246 acpi_sci_trig == INTR_TRIGGER_LEVEL &&
247 acpi_sci_pola == INTR_POLARITY_LOW)